From 314eba98b2f2755cb26ed7a268d3fe83a7626efa Mon Sep 17 00:00:00 2001 From: Siddhant Soni Date: Wed, 11 Sep 2019 05:04:50 -0700 Subject: [PATCH] Added check to handle all cases of MissingWebViewPackageException (#26189) Summary: We have been experiencing the below crashes in our Flipkart Android app: ![image](https://user-images.githubusercontent.com/16662518/63784983-2be9a100-c90d-11e9-998d-2e5085f1dec6.png) ![image](https://user-images.githubusercontent.com/16662518/63784988-3146eb80-c90d-11e9-89d4-18693b566284.png) Stack overflow thread for the issue that is causing this crash: [https://stackoverflow.com/a/56246743](https://stackoverflow.com/a/56246743) The change I have done is an enhancement on the following PR which got merged to master: [https://github.com/facebook/react-native/pull/24533](https://github.com/facebook/react-native/pull/24533) The exception handling for this crash already exists but it relies on having a specific string in the error message ("Webview not installed"). But the error message for the crashes above does not include this string. I have added a check for all the crashes involving the `MissingWebViewPackageException`. Refer the file: [https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/webkit/WebViewFactory.java#102](https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/webkit/WebViewFactory.java#102) ## Changelog [ANDROID] [Fixed] - The ReactCookieJarContainer/ForwardingCookieHandler now handles all the cases of missing WebView exceptions gracefully. Pull Request resolved: https://github.com/facebook/react-native/pull/26189 Test Plan: No new tests have been added. CI should pass. This fix was made based on the exception stacktrace. I have not spent the time to acquire one of the devices that it is happening on. Differential Revision: D17258881 Pulled By: cpojer fbshipit-source-id: 3abb061e345329214025ebab2b3a908f9cce434d --- .../react/modules/network/ForwardingCookieHandler.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/network/ForwardingCookieHandler.java b/ReactAndroid/src/main/java/com/facebook/react/modules/network/ForwardingCookieHandler.java index e4d801a789b..0a58676a6b2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/network/ForwardingCookieHandler.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/network/ForwardingCookieHandler.java @@ -184,8 +184,12 @@ public class ForwardingCookieHandler extends CookieHandler { // We cannot catch MissingWebViewPackageException as it is in a private / system API // class. This validates the exception's message to ensure we are only handling this // specific exception. - // https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/webkit/WebViewFactory.java#98 - if (message != null && message.contains("No WebView installed")) { + // https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/webkit/WebViewFactory.java#348 + if (message != null + && exception + .getClass() + .getCanonicalName() + .equals("android.webkit.WebViewFactory.MissingWebViewPackageException")) { return null; } else { throw exception;