Android O(android 8.1) SYSTEM_UID应用无法使用FileProvider

报错信息:

For security reasons, the system cannot issue a Uri permission grant to content://com.joson.adphonelauncher.fileProvider/name/DBoothLayout/AdPhoneLauncher.apk [user 0]; use startActivityAsCaller() instead
java.lang.SecurityException: Permission Denial: opening provider com.joson.adphonelauncher.MyProvider from ProcessRecord{8d253bb 1430:com.android.packageinstaller/u0a18} (pid=1430, uid=10018) that is not exported from UID 1000

原因是系统把provider给过滤了一下,最简单办法就是修改一下源码。

文件路径:

frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
在 ActivityManagerService.java  (AMS) 中的checkGrantUriPermissionLocked()方 法内的如下代码块中打印的:
// 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 if ("com.joson.adphonelauncher.fileProvider".equals(grantUri.uri.getAuthority())) {
                
            }else {
                Slog.w(TAG, "For security reasons, the system cannot issue a Uri permission"
                        + " grant to " + grantUri + "; use startActivityAsCaller() instead");
                return -1;
            }
        }

Android O(android 8.1) SYSTEM_UID应用无法使用FileProvider_第1张图片

参考:

https://blog.csdn.net/hanhan1016/article/details/79421570

https://blog.csdn.net/qq_36118367/article/details/79700198 

你可能感兴趣的:(android1)