Dbrant has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/340115 )
Change subject: Don't crash when system WebView is being updated.
......................................................................
Don't crash when system WebView is being updated.
This patch makes PageActivity catch exception(s) related to inflation of
the WebView, meaning that we will now handle the condition when the app is
launched at the precise moment when the system WebView is being updated.
The behavior will be to show the user a brief message and immediately
close PageActivity. (but it's better than crashing.)
Change-Id: I6b2e2821f1df1117b90a5661901063a4b488895e
---
M app/src/main/java/org/wikipedia/page/PageActivity.java
M app/src/main/res/values-qq/strings.xml
M app/src/main/res/values/strings.xml
3 files changed, 27 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia
refs/changes/15/340115/1
diff --git a/app/src/main/java/org/wikipedia/page/PageActivity.java
b/app/src/main/java/org/wikipedia/page/PageActivity.java
index 42e833d..cdce475 100644
--- a/app/src/main/java/org/wikipedia/page/PageActivity.java
+++ b/app/src/main/java/org/wikipedia/page/PageActivity.java
@@ -31,6 +31,7 @@
import android.view.View;
import android.view.WindowManager;
import android.widget.ProgressBar;
+import android.widget.Toast;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
@@ -93,12 +94,12 @@
@BindView(R.id.page_progress_bar) ProgressBar progressBar;
@BindView(R.id.page_toolbar_container) View toolbarContainerView;
@BindView(R.id.page_toolbar) Toolbar toolbar;
- private Unbinder unbinder;
+ @Nullable private Unbinder unbinder;
private PageFragment pageFragment;
private WikipediaApp app;
- private Bus bus;
+ @Nullable private Bus bus;
private EventBusMethods busMethods;
private CompatActionMode currentActionMode;
@@ -127,7 +128,22 @@
}
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
- setContentView(R.layout.activity_page);
+
+ try {
+ setContentView(R.layout.activity_page);
+ } catch (Exception e) {
+ if (e.getMessage().contains("WebView")) {
+ // If the system failed to inflate our activity because of the
WebView (which could
+ // be one of several types of exceptions), it likely means
that the system WebView
+ // is in the process of being updated. In this case, show the
user a message and
+ // bail immediately.
+ Toast.makeText(app, R.string.error_webview_updating,
Toast.LENGTH_LONG).show();
+ finish();
+ return;
+ }
+ throw e;
+ }
+
unbinder = ButterKnife.bind(this);
busMethods = new EventBusMethods();
@@ -702,7 +718,9 @@
@Override
public void onDestroy() {
- unbinder.unbind();
+ if (unbinder != null) {
+ unbinder.unbind();
+ }
unregisterBus();
super.onDestroy();
}
@@ -753,7 +771,9 @@
}
private void unregisterBus() {
- bus.unregister(busMethods);
+ if (bus != null) {
+ bus.unregister(busMethods);
+ }
bus = null;
L.d("Unregistered bus.");
}
diff --git a/app/src/main/res/values-qq/strings.xml
b/app/src/main/res/values-qq/strings.xml
index 95353d7..5edbeef 100644
--- a/app/src/main/res/values-qq/strings.xml
+++ b/app/src/main/res/values-qq/strings.xml
@@ -362,6 +362,7 @@
<string name="location_service_disabled">Message shown when trying to use
location services but they are unavailable</string>
<string name="enable_location_service">Button label for enabling location
services
{{Identical|Enable}}</string>
+ <string name="error_webview_updating">Error informing the user that the
System WebView is being updated, meaning that the app cannot be launched right
now, and that the user should try again in a moment.</string>
<string name="crash_report_dialog_title">Title of the dialog that pops up
when the app crashes, asking user to send a report</string>
<string name="crash_report_dialog_text">Text asking the user to send us a
crash report</string>
<string name="crash_report_dialog_dont_send_button">In the dialog that pops
up when the app crashes, text for button that doesn\'t send a crash report.
diff --git a/app/src/main/res/values/strings.xml
b/app/src/main/res/values/strings.xml
index 52dd73d..ecfc3f2 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -247,6 +247,7 @@
<string name="error_voice_search_not_available">Sorry, voice recognition
is not available.</string>
<string name="location_service_disabled">Location services are
disabled.</string>
<string name="enable_location_service">Enable</string>
+ <string name="error_webview_updating">The Android System WebView is
currently being updated. Please try again in a moment.</string>
<!-- Crash reporter -->
<string name="crash_report_dialog_title">Sorry, app crashed last
time</string>
--
To view, visit https://gerrit.wikimedia.org/r/340115
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b2e2821f1df1117b90a5661901063a4b488895e
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits