mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 12:02:16 +02:00
Improve error if WebView load fails
Previously this would crash the app with no option. Normally caused by a WebView upgrade, but also visible on API 26 Nexus emulator Fixes 5794
This commit is contained in:
parent
04408c1329
commit
0f5afe5f05
@ -177,6 +177,10 @@ public class AnkiDroidApp extends MultiDexApplication {
|
||||
/** Our ACRA configurations, initialized during onCreate() */
|
||||
private CoreConfigurationBuilder acraCoreConfigBuilder;
|
||||
|
||||
/** An exception if the WebView subsystem fails to load */
|
||||
@Nullable
|
||||
private Throwable mWebViewError;
|
||||
|
||||
|
||||
@NonNull
|
||||
public static InputStream getResourceAsStream(@NonNull String name) {
|
||||
@ -278,7 +282,17 @@ public class AnkiDroidApp extends MultiDexApplication {
|
||||
NotificationChannels.setup(getApplicationContext());
|
||||
|
||||
// Configure WebView to allow file scheme pages to access cookies.
|
||||
CookieManager.setAcceptFileSchemeCookies(true);
|
||||
try {
|
||||
CookieManager.setAcceptFileSchemeCookies(true);
|
||||
} catch (Throwable e) {
|
||||
// 5794: Errors occur if the WebView fails to load
|
||||
// android.webkit.WebViewFactory.MissingWebViewPackageException.MissingWebViewPackageException
|
||||
// Error may be excessive, but I expect a UnsatisfiedLinkError to be possible here.
|
||||
this.mWebViewError = e;
|
||||
sendExceptionReport(e, "setAcceptFileSchemeCookies");
|
||||
Timber.e(e, "setAcceptFileSchemeCookies");
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare Cookies to be synchronized between RAM and permanent storage.
|
||||
CompatHelper.getCompat().prepareWebViewCookies(this.getApplicationContext());
|
||||
@ -583,6 +597,22 @@ public class AnkiDroidApp extends MultiDexApplication {
|
||||
return pref.equals(l) || "".equals(pref) && Locale.getDefault().getLanguage().equals(l);
|
||||
}
|
||||
|
||||
|
||||
public static boolean webViewFailedToLoad() {
|
||||
return getInstance().mWebViewError != null;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public static String getWebViewErrorMessage() {
|
||||
Throwable error = getInstance().mWebViewError;
|
||||
if (error == null) {
|
||||
Timber.w("getWebViewExceptionMessage called without webViewFailedToLoad check");
|
||||
return null;
|
||||
}
|
||||
return error.getLocalizedMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* A tree which logs necessary data for crash reporting.
|
||||
*
|
||||
|
@ -81,7 +81,6 @@ import android.widget.Toast;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.getbase.floatingactionbutton.FloatingActionButton;
|
||||
import com.getbase.floatingactionbutton.FloatingActionsMenu;
|
||||
import com.ichi2.anim.ActivityTransitionAnimation;
|
||||
import com.ichi2.anki.CollectionHelper.CollectionIntegrityStorageCheck;
|
||||
import com.ichi2.anki.StudyOptionsFragment.StudyOptionsListener;
|
||||
import com.ichi2.anki.analytics.UsageAnalytics;
|
||||
@ -573,6 +572,16 @@ public class DeckPicker extends NavigationDrawerActivity implements
|
||||
* @return whether or not we were successful
|
||||
*/
|
||||
private boolean firstCollectionOpen() {
|
||||
if (AnkiDroidApp.webViewFailedToLoad()) {
|
||||
new MaterialDialog.Builder(this)
|
||||
.title(R.string.ankidroid_init_failed_webview_title)
|
||||
.content(getString(R.string.ankidroid_init_failed_webview, AnkiDroidApp.getWebViewErrorMessage()))
|
||||
.positiveText(R.string.close)
|
||||
.onPositive((d, w) -> exit())
|
||||
.cancelable(false)
|
||||
.show();
|
||||
return false;
|
||||
}
|
||||
if (Permissions.hasStorageAccessPermission(this)) {
|
||||
Timber.i("User has permissions to access collection");
|
||||
// Show error dialog if collection could not be opened
|
||||
|
@ -330,4 +330,8 @@
|
||||
<!-- Deck Picker -->
|
||||
<string name="deck_picker_failed_deck_load">Failed to load deck ‘%s’</string>
|
||||
<string name="search_decks">Search decks</string>
|
||||
|
||||
|
||||
<string name="ankidroid_init_failed_webview_title">Fatal Error</string>
|
||||
<string name="ankidroid_init_failed_webview">AnkiDroid relies on the System WebView which is unavailable. This can happen if the system is installing updates. Please try again in a few minutes.\n\n%s</string>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user