diff --git a/core/java/android/content/ContentProvider.java b/core/java/android/content/ContentProvider.java index b4f23028325b3..5584f458501c0 100644 --- a/core/java/android/content/ContentProvider.java +++ b/core/java/android/content/ContentProvider.java @@ -18,6 +18,7 @@ package android.content; import static android.Manifest.permission.INTERACT_ACROSS_USERS; import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL; +import static android.os.Process.myUserHandle; import static android.os.Trace.TRACE_TAG_DATABASE; import android.annotation.NonNull; @@ -738,7 +739,7 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall } boolean checkUser(int pid, int uid, Context context) { - int callingUserId = UserHandle.getUserId(uid); + final int callingUserId = UserHandle.getUserId(uid); if (callingUserId == context.getUserId() || mSingleUser) { return true; @@ -765,8 +766,8 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall if (um != null && um.isCloneProfile()) { UserHandle parent = um.getProfileParent(callingUser); - if (parent != null && parent.equals(context.getUser())) { - mUsersRedirectedToOwner.put(callingUser.getIdentifier(), true); + if (parent != null && parent.equals(myUserHandle())) { + mUsersRedirectedToOwner.put(callingUserId, true); return true; } } @@ -774,7 +775,7 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall // ignore } - mUsersRedirectedToOwner.put(UserHandle.getUserId(uid), false); + mUsersRedirectedToOwner.put(callingUserId, false); return false; } diff --git a/services/core/java/com/android/server/am/ContentProviderHelper.java b/services/core/java/com/android/server/am/ContentProviderHelper.java index 3c5b872ec717a..df792ee2818d0 100644 --- a/services/core/java/com/android/server/am/ContentProviderHelper.java +++ b/services/core/java/com/android/server/am/ContentProviderHelper.java @@ -1046,6 +1046,16 @@ public class ContentProviderHelper { userId = UserHandle.getCallingUserId(); } + if (isAuthorityRedirectedForCloneProfile(authority)) { + UserManagerInternal umInternal = LocalServices.getService(UserManagerInternal.class); + UserInfo userInfo = umInternal.getUserInfo(userId); + + if (userInfo != null && userInfo.isCloneProfile()) { + userId = umInternal.getProfileParentId(userId); + checkUser = false; + } + } + ProviderInfo cpi = null; try { cpi = AppGlobals.getPackageManager().resolveContentProvider(authority, @@ -1055,17 +1065,6 @@ public class ContentProviderHelper { | PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userId); - if (cpi == null && isAuthorityRedirectedForCloneProfile(authority)) { - // This might be a provider that's running only in the system user that's - // also serving clone profiles - cpi = AppGlobals.getPackageManager().resolveContentProvider(authority, - ActivityManagerService.STOCK_PM_FLAGS - | PackageManager.GET_URI_PERMISSION_PATTERNS - | PackageManager.MATCH_DISABLED_COMPONENTS - | PackageManager.MATCH_DIRECT_BOOT_AWARE - | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, - UserHandle.USER_SYSTEM); - } } catch (RemoteException ignored) { } if (cpi == null) { @@ -1073,16 +1072,6 @@ public class ContentProviderHelper { + "; expected to find a valid ContentProvider for this authority"; } - if (isAuthorityRedirectedForCloneProfile(authority)) { - UserManagerInternal umInternal = LocalServices.getService(UserManagerInternal.class); - UserInfo userInfo = umInternal.getUserInfo(userId); - - if (userInfo != null && userInfo.isCloneProfile()) { - userId = umInternal.getProfileParentId(userId); - checkUser = false; - } - } - final int callingPid = Binder.getCallingPid(); ProcessRecord r; final String appName;