From 86192734d73f0944ce5e0f8b5afca26fa5f9812e Mon Sep 17 00:00:00 2001 From: luanqian Date: Thu, 22 Dec 2016 14:45:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[Fix]=20=E9=83=A8=E5=88=864.2.1&4.2.2?= =?UTF-8?q?=E5=81=B6=E7=8E=B0crash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rexxar/utils/WebViewCompatUtils.java | 64 +++++++++++++++++++ .../douban/rexxar/view/RexxarWebViewCore.java | 2 + 2 files changed, 66 insertions(+) create mode 100644 core/src/main/java/com/douban/rexxar/utils/WebViewCompatUtils.java diff --git a/core/src/main/java/com/douban/rexxar/utils/WebViewCompatUtils.java b/core/src/main/java/com/douban/rexxar/utils/WebViewCompatUtils.java new file mode 100644 index 0000000..89d5285 --- /dev/null +++ b/core/src/main/java/com/douban/rexxar/utils/WebViewCompatUtils.java @@ -0,0 +1,64 @@ +package com.douban.rexxar.utils; + +import android.content.Context; +import android.os.Build; +import android.view.accessibility.AccessibilityManager; +import android.webkit.WebSettings; + +import java.lang.reflect.Method; + +/** + * Created by luanqian on 16/12/22. + */ + +public class WebViewCompatUtils { + + /** + * fix bug: NPE in android.webkit.AccessibilityInjector$TextToSpeechWrapper (Android 4.2.1) + * see: https://code.google.com/p/android/issues/detail?id=40944 + * + * @param context + * @param webSettings + */ + public static void enableJavaScriptForWebView(Context context, WebSettings webSettings) { + if (null == webSettings) { + return; + } + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) { + disableAccessibility(context); + } + try { + webSettings.setJavaScriptEnabled(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * m:lorss + * 关闭辅助功能,针对4.2.1和4.2.2 崩溃问题 + * java.lang.NullPointerException + * at android.webkit.AccessibilityInjector$TextToSpeechWrapper$1.onInit(AccessibilityInjector.java:753) + * ... ... + * at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:321) + */ + private static void disableAccessibility(Context context) { + if (Build.VERSION.SDK_INT == 17/*4.2 (Build.VERSION_CODES.JELLY_BEAN_MR1)*/) { + if (context != null) { + try { + AccessibilityManager am = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); + if (!am.isEnabled()) { + //Not need to disable accessibility + return; + } + + Method setState = am.getClass().getDeclaredMethod("setState", int.class); + setState.setAccessible(true); + setState.invoke(am, 0);/**{@link AccessibilityManager#STATE_FLAG_ACCESSIBILITY_ENABLED}*/ + } catch (Exception ignored) { + ignored.printStackTrace(); + } + } + } + } +} diff --git a/core/src/main/java/com/douban/rexxar/view/RexxarWebViewCore.java b/core/src/main/java/com/douban/rexxar/view/RexxarWebViewCore.java index 46ceefd..3b49755 100644 --- a/core/src/main/java/com/douban/rexxar/view/RexxarWebViewCore.java +++ b/core/src/main/java/com/douban/rexxar/view/RexxarWebViewCore.java @@ -26,6 +26,7 @@ import com.douban.rexxar.route.RouteManager; import com.douban.rexxar.utils.LogUtils; import com.douban.rexxar.utils.Utils; +import com.douban.rexxar.utils.WebViewCompatUtils; import java.io.IOException; @@ -177,6 +178,7 @@ private void setup() { @SuppressLint("SetJavaScriptEnabled") protected void setupWebSettings(WebSettings ws) { ws.setAppCacheEnabled(true); + WebViewCompatUtils.enableJavaScriptForWebView(getContext(), ws); ws.setJavaScriptEnabled(true); ws.setGeolocationEnabled(true); ws.setBuiltInZoomControls(true); From 55de8d04fc1aa25d47f9258c98a8468f6e3d6f84 Mon Sep 17 00:00:00 2001 From: luanqian Date: Thu, 22 Dec 2016 14:46:06 +0800 Subject: [PATCH 2/2] update to 0.1.7 --- README.md | 2 +- core/gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d0fcc76..e50e66b 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Demo 中使用 github 的 raw 文件服务提供一个简单的路由表文件 r #### gradle ```groovy - compile 'com.douban.rexxar:core:0.1.6' + compile 'com.douban.rexxar:core:0.1.7' ``` diff --git a/core/gradle.properties b/core/gradle.properties index 4409f28..0867f03 100644 --- a/core/gradle.properties +++ b/core/gradle.properties @@ -1,5 +1,5 @@ PROJ_GROUP=com.douban.rexxar -PROJ_VERSION=0.1.6 +PROJ_VERSION=0.1.7 PROJ_NAME=rexxar-android PROJ_WEBSITEURL=https://github.com/douban/rexxar-android PROJ_ISSUETRACKERURL=https://github.com/douban/rexxar-android/issues