当前位置:   article > 正文

Android 8.1安装app包解析包错误Permission Denial: that is not exported from UID 1000

not exported from uid 1000

这个问题一直困惑了我几个月,我当时就很崩溃了,因为该加的东西一样没少加,而且同样的app,7.0可以正常运行,8.0以上却不可以!!!

<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="${applicationId}.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true"
    tools:replace="android:authorities">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths"
        tools:replace="android:resource"/>
</provider>

同时,安装未知来源权限询问也加了,但是死活就是安装不了app,然后打印的日志一直报下面的错误:

  1. 01-01 06:37:41.322 W/InstallStaging( 2110): Error staging apk from content URI
  2. 01-01 06:37:41.322 W/InstallStaging( 2110): java.lang.SecurityException: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{56d9d3c 2110:com.android.packageinstaller/u0a19} (pid=2110, uid=10019) that is not exported from UID 1000
  3. 01-01 06:37:41.322 W/InstallStaging( 2110): at android.os.Parcel.readException(Parcel.java:2005)
  4. 01-01 06:37:41.322 W/InstallStaging( 2110): at android.os.Parcel.readException(Parcel.java:1951)
  5. 01-01 06:37:41.322 W/InstallStaging( 2110): at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:4793)
  6. 01-01 06:37:41.322 W/InstallStaging( 2110): at android.app.ActivityThread.acquireProvider(ActivityThread.java:5863)
  7. 01-01 06:37:41.322 W/InstallStaging( 2110): at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2527)
  8. 01-01 06:37:41.322 W/InstallStaging( 2110): at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1780)
  9. 01-01 06:37:41.322 W/InstallStaging( 2110): at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1394)
  10. 01-01 06:37:41.322 W/InstallStaging( 2110): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1247)
  11. 01-01 06:37:41.322 W/InstallStaging( 2110): at android.content.ContentResolver.openInputStream(ContentResolver.java:967)
  12. 01-01 06:37:41.322 W/InstallStaging( 2110): at com.android.packageinstaller.InstallStaging$StagingAsyncTask.doInBackground(InstallStaging.java:180)
  13. 01-01 06:37:41.322 W/InstallStaging( 2110): at com.android.packageinstaller.InstallStaging$StagingAsyncTask.doInBackground(InstallStaging.java:174)
  14. 01-01 06:37:41.322 W/InstallStaging( 2110): at android.os.AsyncTask$2.call(AsyncTask.java:333)
  15. 01-01 06:37:41.322 W/InstallStaging( 2110): at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  16. 01-01 06:37:41.322 W/InstallStaging( 2110): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
  17. 01-01 06:37:41.322 W/InstallStaging( 2110): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
  18. 01-01 06:37:41.322 W/InstallStaging( 2110): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
  19. 01-01 06:37:41.322 W/InstallStaging( 2110): at java.lang.Thread.run(Thread.java:764)

我内心是真的崩溃的,

intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);网上都说这个东西权限不够,但是真的全都加了。报错其实很明显,就是说在安装的时候,uid=1000;是系统级别的应用!!

直到今天(2019年8月3日15:23:53),我看到另外一行log报错,简直是打开了新世界的大门,拯救我于水火之中!

  1. E/wificond( 433): Failed to get BSSID from scan result packet
  2. 01-01 06:37:41.208 W/ActivityManager( 680): For security reasons, the system cannot issue a Uri permission grant to content://xxxxxxx.fileprovider/download/QQ.apk [user 0]; use startActivityAsCaller() instead
  3. 01-01 06:37:41.209 I/ActivityManager( 680): START u0 {act=android.intent.action.VIEW dat=content://xxxxx.fileprovider/download/QQ.apk typ=application/vnd.android.package-archive flg=0x10000003 cmp=com.android.packageinstaller/.InstallStart} from uid 1000
  4. 01-01 06:37:41.211 W/ActivityManager( 680): For security reasons, the system cannot issue a Uri permission grant to content://xxxxxx.fileprovider/download/QQ.apk [user 0]; use startActivityAsCaller() instead
  5. --------- beginning of main

之前怀疑过无数的可能,百度全都是一些千篇一律的解决方式,都没有成功。

好了,如果你也是app添加了“

android:sharedUserId="android.uid.system"

那么恭喜你,这篇一定可以帮你解决你的问题

因为Android8.0对这个东西又做了一个小的改变了!!!

在Android源码中frameworks\base\services\core\java\com\android\server\am\ActivityManagerService.java

 

找到方法:

int checkGrantUriPermissionLocked(int callingUid, String targetPkg, GrantUri grantUri,
            final int modeFlags, int lastTargetUid)

  1. // Bail early if system is trying to hand out permissions directly; it
  2. // must always grant permissions on behalf of someone explicit.
  3. final int callingAppId = UserHandle.getAppId(callingUid);
  4. if ((callingAppId == SYSTEM_UID) || (callingAppId == ROOT_UID)) {
  5. if ("com.android.settings.files".equals(grantUri.uri.getAuthority())) {
  6. // Exempted authority for cropping user photos in Settings app
  7. } else {
  8. Slog.w(TAG, "For security reasons, the system cannot issue a Uri permission"
  9. + " grant to " + grantUri + "; use startActivityAsCaller() instead");
  10. return -1;
  11. }
  12. }

可以看到,只要是SYSTEM_UID 或者root_uid,只有com.android.settings.files这个FileProvider才有权限

要不然其他报名的统统都是直接返回-1;所以才会报Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord

解决办法很简单,我们只要把我们app里面的FileProvider也排除掉就好了。

  1. if ((callingAppId == SYSTEM_UID) || (callingAppId == ROOT_UID)) {
  2. if ("com.android.settings.files".equals(grantUri.uri.getAuthority())
  3. || "com.xxx.xxx.fileprovider".equals(grantUri.uri.getAuthority())) {
  4. // Exempted authority for cropping user photos in Settings app
  5. } else {
  6. Slog.w(TAG, "For security reasons, the system cannot issue a Uri permission"
  7. + " grant to " + grantUri + "; use startActivityAsCaller() instead");
  8. return -1;
  9. }
  10. }

好了重新编译一下代码,完美安装app!!!!!!!!!!!!!!!!!!!!!!!!!

 

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/188979
推荐阅读
相关标签
  

闽ICP备14008679号