For security reasons, WebView is not allowed in privileged processes报错解决

 

For security reasons, WebView is not allowed in privileged processes报错解决

  455人阅读  评论(7)  收藏  举报

http://blog.csdn.net/liyuxi45/article/details/53034076

之前在做项目时,客户提供的apk合入过程中启动报错,查看log发现报错时有exception,如下:

For security reasons, WebView is not allowed in privileged processes。

搜索源码,在frameworks/base/core/Java/Android/webkit/WebViewFactory.java中找到了这条log语句。

[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. static WebViewFactoryProvider getProvider() {  
  2.     synchronized (sProviderLock) {  
  3.         // For now the main purpose of this function (and the factory abstraction) is to keep  
  4.         // us honest and minimize usage of WebView internals when binding the proxy.  
  5.         if (sProviderInstance != nullreturn sProviderInstance;  
  6.   
  7.         final int uid = android.os.Process.myUid();  
  8.         if (uid == android.os.Process.ROOT_UID || uid == android.os.Process.SYSTEM_UID) {  
  9.             throw new UnsupportedOperationException(  
  10.                     "For security reasons, WebView is not allowed in privileged processes");  
  11.         }  
  12.   
  13.         Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.getProvider()");  
  14.         try {  
  15.             Class<WebViewFactoryProvider> providerClass = getProviderClass();  
  16.   
  17.             StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();  
  18.             Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "providerClass.newInstance()");  
  19.             try {  
  20.                 sProviderInstance = providerClass.getConstructor(WebViewDelegate.class)  
  21.                         .newInstance(new WebViewDelegate());  
  22.                 if (DEBUG) Log.v(LOGTAG, "Loaded provider: " + sProviderInstance);  
  23.                 return sProviderInstance;  
  24.             } catch (Exception e) {  
  25.                 Log.e(LOGTAG, "error instantiating provider", e);  
  26.                 throw new AndroidRuntimeException(e);  
  27.             } finally {  
  28.                 Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);  
  29.                 StrictMode.setThreadPolicy(oldPolicy);  
  30.             }  
  31.         } finally {  
  32.             Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);  
  33.         }  
  34.     }  
  35. }  

可以看到是因为该app的uid是ROOT_UID或者SYSTEM_UID并且该app直接或者间接调用了WebViewFactory类的getProvider方法。

之前KK的源码中并没有这个保护条件,但是5.1的源码中就有了。所以保证不影响其它功能的情况下,在app中去掉root或者system uid就可以了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值