Android 解析软件包时出现问题 -- Error staging apk from content URI

Android Version : 8.1

使用场景 : 在Rk3288w Android 8.1 的测试设备上安装 "文件管理器" 应用程序 , 若打开***.apk文件,会出现  解析包错误  提示,即安装失败,影响使用.

 如下为ActivityManagerService.java 中的Log信息.

06-29 08:37:56.559 W/ActivityManager(  369): For security reasons, the system cannot issue a Uri permission grant to content://com.example.filetest.fileprovider/root_path/D007-6A31/Android_APK/weibo.apk [user 0]; use startActivityAsCaller() instead
06-29 08:37:56.561 E/ActivityManager(  369): getPackageFerformanceMode--ComponentInfo{com.android.packageinstaller/com.android.packageinstaller.InstallStart}----com.android.packageinstaller

最终 错误信息 的Log.

06-29 08:37:56.768 W/ActivityManager(  369): Permission Denial: opening provider androidx.core.content.FileProvider from ProcessRecord{91d037 1469:com.android.packageinstaller/u0a14} (pid=1469, uid=10014) that is not exported from UID 1000
06-29 08:37:56.759 E/hwc_rk  (  236): hwc_get_handle_layername:cann't get value from gralloc
06-29 08:37:56.768 W/InstallStaging( 1469): Error staging apk from content URI
06-29 08:37:56.768 W/InstallStaging( 1469): java.lang.SecurityException: Permission Denial: opening provider androidx.core.content.FileProvider from ProcessRecord{91d037 1469:com.android.packageinstaller/u0a14} (pid=1469, uid=10014) that is not exported from UID 1000
06-29 08:37:56.768 W/InstallStaging( 1469):     at android.os.Parcel.readException(Parcel.java:2013)
06-29 08:37:56.768 W/InstallStaging( 1469):     at android.os.Parcel.readException(Parcel.java:1959)
06-29 08:37:56.768 W/InstallStaging( 1469):     at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:4758)
06-29 08:37:56.768 W/InstallStaging( 1469):     at android.app.ActivityThread.acquireProvider(ActivityThread.java:5836)
06-29 08:37:56.768 W/InstallStaging( 1469):     at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2526)
06-29 08:37:56.768 W/InstallStaging( 1469):     at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1780)
06-29 08:37:56.768 W/InstallStaging( 1469):     at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1394)
06-29 08:37:56.768 W/InstallStaging( 1469):     at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1247)
06-29 08:37:56.768 W/InstallStaging( 1469):     at android.content.ContentResolver.openInputStream(ContentResolver.java:967)
06-29 08:37:56.768 W/InstallStaging( 1469):     at com.android.packageinstaller.InstallStaging$StagingAsyncTask.doInBackground(InstallStaging.java:180)
06-29 08:37:56.768 W/InstallStaging( 1469):     at com.android.packageinstaller.InstallStaging$StagingAsyncTask.doInBackground(InstallStaging.java:174)
06-29 08:37:56.768 W/InstallStaging( 1469):     at android.os.AsyncTask$2.call(AsyncTask.java:333)
06-29 08:37:56.768 W/InstallStaging( 1469):     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
06-29 08:37:56.768 W/InstallStaging( 1469):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
06-29 08:37:56.768 W/InstallStaging( 1469):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
06-29 08:37:56.768 W/InstallStaging( 1469):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
06-29 08:37:56.768 W/InstallStaging( 1469):     at java.lang.Thread.run(Thread.java:764)

根据Log中显示 ,主要是FileProvider权限不足以使用系统UID所导致.

结合ActivityManagerService中的Log,定位至: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())
                || "com.example.filetest.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;
            }
        }
    ****************************************************************
    }

有此可以看出来,AMS打出错误信息是因为 com.example.filetest 具有  android:sharedUserId="android.uid.system"  属性;

若按照Android 8.0 以上修改,默认拥有权限的只有   com.android.settings.files   其他均不授予权限,直接跳出方法.

故而解决办法如上,在 checkGrantUriPermissionLocked() 此方法中,添加包名,即可不跳出此方法,授予安装权限.

最后单编 framework 层 Push进机器中,问题解决.

你可能感兴趣的:(Framework,android)