赞
踩
这个问题一直困惑了我几个月,我当时就很崩溃了,因为该加的东西一样没少加,而且同样的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,然后打印的日志一直报下面的错误:
- 01-01 06:37:41.322 W/InstallStaging( 2110): Error staging apk from content URI
- 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
- 01-01 06:37:41.322 W/InstallStaging( 2110): at android.os.Parcel.readException(Parcel.java:2005)
- 01-01 06:37:41.322 W/InstallStaging( 2110): at android.os.Parcel.readException(Parcel.java:1951)
- 01-01 06:37:41.322 W/InstallStaging( 2110): at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:4793)
- 01-01 06:37:41.322 W/InstallStaging( 2110): at android.app.ActivityThread.acquireProvider(ActivityThread.java:5863)
- 01-01 06:37:41.322 W/InstallStaging( 2110): at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2527)
- 01-01 06:37:41.322 W/InstallStaging( 2110): at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1780)
- 01-01 06:37:41.322 W/InstallStaging( 2110): at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1394)
- 01-01 06:37:41.322 W/InstallStaging( 2110): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1247)
- 01-01 06:37:41.322 W/InstallStaging( 2110): at android.content.ContentResolver.openInputStream(ContentResolver.java:967)
- 01-01 06:37:41.322 W/InstallStaging( 2110): at com.android.packageinstaller.InstallStaging$StagingAsyncTask.doInBackground(InstallStaging.java:180)
- 01-01 06:37:41.322 W/InstallStaging( 2110): at com.android.packageinstaller.InstallStaging$StagingAsyncTask.doInBackground(InstallStaging.java:174)
- 01-01 06:37:41.322 W/InstallStaging( 2110): at android.os.AsyncTask$2.call(AsyncTask.java:333)
- 01-01 06:37:41.322 W/InstallStaging( 2110): at java.util.concurrent.FutureTask.run(FutureTask.java:266)
- 01-01 06:37:41.322 W/InstallStaging( 2110): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
- 01-01 06:37:41.322 W/InstallStaging( 2110): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
- 01-01 06:37:41.322 W/InstallStaging( 2110): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
- 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报错,简直是打开了新世界的大门,拯救我于水火之中!
- E/wificond( 433): Failed to get BSSID from scan result packet
- 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
- 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
- 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
- --------- 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)
- // Bail early if system is trying to hand out permissions directly; it
- // must always grant permissions on behalf of someone explicit.
- final int callingAppId = UserHandle.getAppId(callingUid);
- if ((callingAppId == SYSTEM_UID) || (callingAppId == ROOT_UID)) {
- if ("com.android.settings.files".equals(grantUri.uri.getAuthority())) {
- // Exempted authority for cropping user photos in Settings app
- } else {
- Slog.w(TAG, "For security reasons, the system cannot issue a Uri permission"
- + " grant to " + grantUri + "; use startActivityAsCaller() instead");
- return -1;
- }
- }
可以看到,只要是SYSTEM_UID 或者root_uid,只有com.android.settings.files这个FileProvider才有权限
要不然其他报名的统统都是直接返回-1;所以才会报Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord
解决办法很简单,我们只要把我们app里面的FileProvider也排除掉就好了。
- if ((callingAppId == SYSTEM_UID) || (callingAppId == ROOT_UID)) {
- if ("com.android.settings.files".equals(grantUri.uri.getAuthority())
- || "com.xxx.xxx.fileprovider".equals(grantUri.uri.getAuthority())) {
- // Exempted authority for cropping user photos in Settings app
- } else {
- Slog.w(TAG, "For security reasons, the system cannot issue a Uri permission"
- + " grant to " + grantUri + "; use startActivityAsCaller() instead");
- return -1;
- }
- }
好了重新编译一下代码,完美安装app!!!!!!!!!!!!!!!!!!!!!!!!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。