-
-
Notifications
You must be signed in to change notification settings - Fork 5
Add HTA-side implementation of sync-interrupted scenario (HT-508). Also replace deprecated AsyncTask. #13
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
base: master
Are you sure you want to change the base?
Conversation
…stead of hardcoding "success". Replace deprecated AsyncTask. Added handling for the HttpRequest from HT which now can have either "sync_success" or "sync_interrupted". Formerly the user would see a success message in either case. Now, however, when a sync is cancelled the user will see a message indicating that sync did not complete. Replaced AsyncTask (which is deprecated) with Executors and Handlers. This still contains debug output from the investigation activities. A future commit (very soon, hopefully) will remove this in PR preparation.
…Also replace deprecated AsyncTask code. Formerly HT sent HTA "sync_success" regardless of whether 'mergeCompleted' was True. Now the False case leads to HTA receiving "sync_interrupted" and HTA informs the user that sync did not complete successfully. Also, deprecated class 'AsyncTask' is replaced with 'Executors' and 'Handlers'.
tombogle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tombogle reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @wmergenthal)
app/src/main/java/org/sil/hearthis/AcceptNotificationHandler.java line 43 at r1 (raw file):
// // NOTE: like several things in HearThisAndroid, HttpRequest is deprecated. It will be // replaced with something more appropriate, hopefully soon.
Options:
-
Use
HttpURLConnection(built-in JDK/Android)
→ Standard replacement for most simple request/response work.-
Pros: No external dependency.
-
Cons: Verbose API; no built-in high-level features.
-
-
Use
OkHttp(square.github.io/okhttp)
→ De facto standard for Android networking.-
Pros: Clean API, better performance, supports HTTP/2, widely adopted.
-
Cons: Adds dependency, but well worth it in most apps.
-
app/src/main/java/org/sil/hearthis/AcceptNotificationHandler.java line 49 at r1 (raw file):
String s2 = s1.substring(s1.indexOf(' ') + 1, s1.lastIndexOf(' ')); String status = s2.substring(s2.indexOf('=') + 1);
This logic could be done in a less cryptic way:
String s1 = request.getRequestLine().getUri(); // avoid toString() if possible
URI uri = new URI(s1);
String query = uri.getQuery(); // e.g., "status=123&foo=bar"
String status = null;
for (String param : query.split("&")) {
String[] pair = param.split("=");
if (pair.length == 2 && pair[0].equals("status")) {
status = pair[1];
break;
}
}
Alternatively, it could be done very simply with a regular expression. But using URI is probably safer and makes the intent clear.
app/src/main/java/org/sil/hearthis/SyncActivity.java line 166 at r1 (raw file):
socket.send(packet); } catch (UnknownHostException e) { e.printStackTrace();
In the case of an exception, is there anything else we need to do to give feedback to the user and/or prevent the HTA app from getting stuck in a bad state?
app/src/main/java/org/sil/hearthis/SyncActivity.java line 280 at r1 (raw file):
setProgress(getString(R.string.sync_interrupted)); } else { // Should never happen. Not sure what to do here, if anything...
For the sake of future proofing, we should probably handle any unexpected message by letting the use know that they are probably using a version of HTA that is not fully compatible with HT desktop. Then probably we should treat it similar to the "interrupted" case, since we probably can't safely assume it was completed successfully.
Instead of raw string objects, use a URI object for status extraction from the HttpRequest from HT. Resulting logic is longer but clearer.
Treat similarly to when sync is interrupted. Show the user a non-success message and suggest that they verify that HT/HTA versions are close enough that HTA knows about all possible HT sync statuses.
|
|
||
| if (status == null) { | ||
| // Something went wrong. Make sure the user sees a non-success message. | ||
| status = "sync_interrupted"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should display a different message in the case where we get an unexpected status message. I assume the processing should be the same (since we can't possibly know how else to interpret the unexpected message), but if this ever happens, we could give the user some indication that we got an unexpected message and suggest they check for an update. We could even include in the query (from HT) an indication of the minimum version of HTA known to handle the particular status message. Then if we ever get an unexpected status and it includes a version number as well, we could tell the user the minimum version of HTA that is compatible with the version of HT they are using. The HTA code would then look something like this:
String status = null;
String minHtaVersion = null;
try {
String s1 = request.getRequestLine().getUri();
URI uri = new URI(s1);
String query = uri.getQuery();
if (query != null) {
for (String param : query.split("&")) {
String[] pair = param.split("=", 2); // limit=2 in case value contains '='
if (pair.length == 2) {
if (pair[0].equals("message")) {
status = pair[1];
} else if (pair[0].equals("minHtaVersion")) {
minHtaVersion = pair[1];
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (status == null || isUnexpectedStatus(status)) {
if (minHtaVersion != null) {
showError("Unexpected sync status received. This version of HearThis for Android appears to be incompatible with your version of HearThis. Please update HearThis for Android to at least version " + minHtaVersion + ".");
} else {
showError("Unexpected sync status received. Please check for updates.");
}
status = "sync_interrupted"; // Or possibly a distinct status
}
Nominal case works. Still need to test watchdog when HT fails to complete its side of sync. Debug output still present (which helps greatly understanding the mechanism).
No substantive changes. Just captures debug stmts producing the output captured in 20251001_02_HTA_sync_watchdog_all_ok.log, where watchdog is seen to work correctly for both success and fail scenarios.
Watchdog was being started too early. If the Android user was not quick to scan the QR code after getting into that mode, the watchdog could have timed out before the sync even started. Now we don't start it until Android has sent its UDP packet to PC to initiate a sync. Also, multiple watchdog shutdown() calls are now consolidated into a single one. Add comments to the new Watchdog class. Remove some dead code and improve some debug output stmts.
Without the Continue button the user can't get back to the home screen unless a subsequent sync retry is successful. To make the Continue button usable, add call to AcceptNotificationHandler like all the other spots have.
Formerly HT sent HTA "sync_success" regardless of whether 'mergeCompleted' was True. Now the False case leads to HTA receiving sync status "sync_interrupted". HTA parses the HttpRequest from HT to extract the status, then informs the user. One new string is added to HTA for the interrupt-or-cancelled case.
Also, deprecated class 'AsyncTask' is replaced with 'Executors' and 'Handlers'.
This change is