Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

134 - Improve UX of crosswalk to webview migration #162

Merged
merged 8 commits into from
Mar 17, 2021

Conversation

mrsarm
Copy link
Contributor

@mrsarm mrsarm commented Mar 11, 2021

Improve the UX after the migration restarting the app.

Issue: #134

TO DO:

Other improvements

  • Improved logging in the app (sorry if it adds noise, I started just with a few corrections and then I couldn't stop fixing it).
  • Upgrade build library com.android.tools.build:gradle 4.1.1 → 4.1.2, Android Studio marks the older version as insecure.

Medic Android Migration Fixed 2021-03-12 16-01

mrsarm added 3 commits March 11, 2021 10:31
- Remove redundant DEBUG check performed by MedicLog.* methods
- Better and more homogeneous logging messages
- Add caller reference to Medic.log
Upgrade due security concerns highlighted by Android Studio, though there is no release notes with the issues fixed in the library
@@ -78,6 +80,8 @@ public void onReceiveValue(String result) {
private PhotoGrabber photoGrabber;
private SmsSender smsSender;

private boolean isMigrationRunning = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this as a boolean it'll reset to false on restart. This may be an issue if it crashes or the user closes it. Can we store it somewhere persistent instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but solve that means make the migration process more resilient, with the ability to resume in the cases you mention, but it is out of scope I think for this ticket that only intent to improve the UI so users are not presented to the login page which cause many problems described in the ticket.

Currently, If the app crashes but the migration was finished, there won't be a problem, because the app will be restarted and with our without this patch the UI will load the CHT dashboard because a that point the cookies will be available again. If the crash happens during the migration, is likely the data will be corrupted and the user will need to reinstall the app losing the data, but again this PR cannot address that now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried about edge cases like... What if the user spawns a second instance of this Activity? What happens if two migrations run in parallel, or one after the other?

However adding some sort of persistent flag is also risky... what if it gets set to migrating = true and then the migration fails? It may never recover.

This is going to have to be tested really thoroughly to avoid bricking or corrupting phones. Are you confident this is the safest approach?

Copy link
Member

@garethbowen garethbowen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you hadn't marked this for review, but thought it might help to add my two cents earlier rather than later!

I've added a couple of suggestions inline.

Additionally, the if (DEBUG) statements are there as a slight performance boost so in production the app doesn't have to initialise and format the parameters only for them to be GCed again almost immediately. This is best practice as far as I'm aware.

@mrsarm
Copy link
Contributor Author

mrsarm commented Mar 12, 2021

Additionally, the if (DEBUG) statements are there as a slight performance boost so in production the app doesn't have to initialise and format the parameters only for them to be GCed again almost immediately. This is best practice as far as I'm aware.

@garethbowen yes actually I removed it not just to make the code more readable without so many if (DEBUG) statements but also because performance, due that the trace method already do that check, and it does not perform the string formatting if DEBUG is true. I only kept the if (DEBUG) in the cases where the formatting is done outside the trace method because it requires more complex concatenations.

@mrsarm mrsarm force-pushed the 134-imp-ux-migration branch from 38ba520 to 7c72508 Compare March 12, 2021 19:44
@mrsarm mrsarm marked this pull request as ready for review March 12, 2021 20:14
@mrsarm mrsarm requested a review from garethbowen March 12, 2021 20:14
@mrsarm
Copy link
Contributor Author

mrsarm commented Mar 12, 2021

Ready for review again, comments about the changes here: #134 (comment)

@mrsarm
Copy link
Contributor Author

mrsarm commented Mar 13, 2021

Quick test instructions

Not yet in AT but here are some observations of how to test the PR.

Because the XWalk version does not work in Android >= 10, and the Webview version is compiled to work only in Android >= 10 for now in the master branch and this branch, the way to test the PR would be install the XWalk version in an Android <10 phone, then upgrade the phone to Android >=10 and finally install the version on this PR, which is is too much for testing, and may not be an option because the device used for testing does not support Android upgrades to the version 10.

What I do for test is:

  1. Get a phone with Android <10 and >=5 (Webview doesn't work with Android 4.4).

  2. Install in the phone the unbranded XWalk version of the app using the latest available from our releases: armeabi-v7a or arm64-v8a APK.

  3. Setup the app with one of the CHT environments suggested by the app, I could reproduce the error easily with the Gamma dev environment.

  4. Log in with an offline user to sync the app and some user data.

  5. Then to be able to install the Webview version of this PR over the version installed in your phone, you need to downgrade the minimal SDK supported in your local development installation of this branch, so go to build.gradle#L164 and set a API version supported by your phone or below, eg.:

    minSdkVersion 23     // Android 6
  6. Run the unbrandedWebviewDebug flavor of the app of this branch with adb, gradle or Android Studio over the same phone where the Xwalk version was installed.

  7. You will see the app starts, and then after a few seconds the splash screen with the upgrade notification while the migration process happens, as described here in the ticket. Then instead of being presented with the login page of the CHT you should see the normal dashboard of the app, with the data already synchronized there.

Copy link
Member

@garethbowen garethbowen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The video walkthrough looks awesome. Great work!

I've left some comments inline. Because of the risk of data loss or bricking phones I'm being even more pedantic than usual...

@@ -78,6 +80,8 @@ public void onReceiveValue(String result) {
private PhotoGrabber photoGrabber;
private SmsSender smsSender;

private boolean isMigrationRunning = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried about edge cases like... What if the user spawns a second instance of this Activity? What happens if two migrations run in parallel, or one after the other?

However adding some sort of persistent flag is also risky... what if it gets set to migrating = true and then the migration fails? It may never recover.

This is going to have to be tested really thoroughly to avoid bricking or corrupting phones. Are you confident this is the safest approach?

Comment on lines 463 to 469
log(this, "onPageStarted() :: Migration process in progress, and " +
"cookies were not loaded, restarting ...");
Context context = view.getContext();
Intent intent = new Intent(context, StartupActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent);
Runtime.getRuntime().exit(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is really important, and quite difficult to understand. Consider pulling out a private function that can be named clearly. In addition it probably needs some commenting about what this is doing and why it works.

isMigrationRunning = false;
CookieManager cookieManager = CookieManager.getInstance();
String cookie = cookieManager.getCookie(appUrl);
if (cookie == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if a user's cookies have expired (or be wiped manually)? I think it'll work... migration will pick up the IndexedDB, then on restart isMigrationRunning will be false, and the user will go to the login page (as expected). Is that right? Have you tested this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I tried to install this version over a XWalk installation that has loaded the webapp but logged out, and the migration runs and then the app display the login page as expected.

Also installed the app without previous installations of Xwalk to ensure the migration process is not started. Same if it was a XWalk installation but with no data previously loaded.

Copy link
Member

@garethbowen garethbowen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Approved - the build is failing but I'll let you dig in to that.

Feel free to create a separate issue/PR for the service worker cache so we can start the AT process on this one.

@mrsarm
Copy link
Contributor Author

mrsarm commented Mar 15, 2021

Awesome!

Approved - the build is failing but I'll let you dig in to that.

Thanks @garethbowen ! Yes the build error is due an issue in the jCenter servers that are responding with a HTTP 403 error when CI tries to pull one of the dependencies. I'll try to rebuild in a few minutes.

Feel free to create a separate issue/PR for the service worker cache so we can start the AT process on this one.

Yes, going to do that to move forward with testing.

Co-authored-by: Marc Abbyad <[email protected]>
@mrsarm mrsarm merged commit 2749d4d into master Mar 17, 2021
@mrsarm mrsarm deleted the 134-imp-ux-migration branch March 29, 2021 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants