项目场景:
提示:在请求apk安装时遇到无响应:报错如下:
2022-06-10 15:35:38.305 5615-5615/com.android.packageinstaller E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.packageinstaller, PID: 5615
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.packageinstaller/com.android.packageinstaller.InstallStart}: java.lang.SecurityException: UID 10043 does not have permission to content://***.fileprovider/update/Android/data/***/files/app-release.apk [user 0]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3635)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.SecurityException: UID 10043 does not have permission to content://***.fileprovider/update/Android/data/***/files/app-release.apk [user 0]
at android.os.Parcel.createExceptionOrNull(Parcel.java:2425)
at android.os.Parcel.createException(Parcel.java:2409)
at android.os.Parcel.readException(Parcel.java:2392)
at android.os.Parcel.readException(Parcel.java:2334)
at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:2284)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1743)
at android.app.Activity.startActivityForResult(Activity.java:5404)
at android.app.Activity.startActivityForResult(Activity.java:5362)
at android.app.Activity.startActivity(Activity.java:5748)
at android.app.Activity.startActivity(Activity.java:5701)
at com.android.packageinstaller.InstallStart.onCreate(InstallStart.java:143)
at android.app.Activity.performCreate(Activity.java:8051)
at android.app.Activity.performCreate(Activity.java:8031)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3608)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3792)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.uri.UriGrantsManagerService.checkGrantUriPermissionUnlocked(UriGrantsManagerService.java:1254)
at com.android.server.uri.UriGrantsManagerService.checkGrantUriPermissionFromIntentUnlocked(UriGrantsManagerService.java:621)
at com.android.server.uri.UriGrantsManagerService.access$1000(UriGrantsManagerService.java:107)
at com.android.server.uri.UriGrantsManagerService$LocalService.checkGrantUriPermissionFromIntent(UriGrantsManagerService.java:1410)
at com.android.server.wm.ActivityStarter$Request.resolveActivity(ActivityStarter.java:534)
问题描述
在请求安装apk时遇到无法安装问题,报错提示权限不够,开始还以为是apk权限问题,检查了AndroidManifest.xml没有发现问题,外部安装权限也申请了,还是不行。接着又找了FileProvider的问题,找了半天也是没发现问题。代码都是测试过能调用安装的。最后想了下我这个aok是带有系统签名的,就干脆把系统签名删掉和 android:sharedUserId="android.uid.system"删掉就能正常安装了
解决方案:
总结:
总结下就是:com.android.packageinstaller(安装包管理器)的UID是 10043,虽然是系统自带应用,但并非拥有系统权限(系统应用的UID是 1000),故也无法通过FileProvider加Uri访问自己签名的系统应用的文件,所以报的权限问题应该是这个问题。那么举一反三,除了安装应用无法访问系统应用内部的文件外(/storage/emulated/0/Android/data/com.***/files/),其他的第三方应用应该也是如此。