Loading services/core/java/android/content/pm/PackageManagerInternal.java +13 −0 Original line number Diff line number Diff line Loading @@ -194,6 +194,19 @@ public abstract class PackageManagerInternal { */ public abstract boolean isPermissionsReviewRequired(String packageName, int userId); /** * Gets whether a given package name belongs to the calling uid. If the calling uid is an * {@link Process#isSdkSandboxUid(int) sdk sandbox uid}, checks whether the package name is * equal to {@link PackageManager#getSdkSandboxPackageName()}. * * @param packageName The package name to check. * @param callingUid The calling uid. * @param userId The user under which to check. * @return True if the package name belongs to the calling uid. */ public abstract boolean isSameApp(String packageName, int callingUid, int userId); /** * Retrieve all of the information we know about a particular package/application. * @param filterCallingUid The results will be filtered in the context of this UID instead Loading services/core/java/com/android/server/notification/NotificationManagerService.java +2 −21 Original line number Diff line number Diff line Loading @@ -9650,27 +9650,8 @@ public class NotificationManagerService extends SystemService { if (uid == Process.ROOT_UID && ROOT_PKG.equals(pkg)) { return; } try { ApplicationInfo ai = mPackageManager.getApplicationInfo( pkg, 0, userId); if (ai == null) { throw new SecurityException("Unknown package " + pkg); } if (!UserHandle.isSameApp(ai.uid, uid)) { throw new SecurityException("Calling uid " + uid + " gave package " + pkg + " which is owned by uid " + ai.uid); } } catch (RemoteException re) { throw new SecurityException("Unknown package " + pkg + "\n" + re); } } private boolean isCallerSameApp(String pkg) { try { checkCallerIsSameApp(pkg); return true; } catch (SecurityException e) { return false; if (!mPackageManagerInternal.isSameApp(pkg, uid, userId)) { throw new SecurityException("Package " + pkg + " is not owned by uid " + uid); } } Loading services/core/java/com/android/server/pm/PackageManagerService.java +13 −0 Original line number Diff line number Diff line Loading @@ -6964,6 +6964,19 @@ public class PackageManagerService extends IPackageManager.Stub return PackageManagerService.this.getKnownPackageNamesInternal(knownPackage, userId); } @Override public boolean isSameApp(@Nullable String packageName, int callingUid, int userId) { if (packageName == null) { return false; } if (Process.isSdkSandboxUid(callingUid)) { return packageName.equals(getSdkSandboxPackageName()); } int uid = getPackageUid(packageName, 0, userId); return UserHandle.isSameApp(uid, callingUid); } @Override public boolean isResolveActivityComponent(ComponentInfo component) { return mResolveActivity.packageName.equals(component.packageName) Loading services/core/java/com/android/server/wm/ActivityTaskManagerService.java +2 −12 Original line number Diff line number Diff line Loading @@ -2232,18 +2232,8 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { * Return true if callingUid is system, or packageName belongs to that callingUid. */ private boolean isSameApp(int callingUid, @Nullable String packageName) { try { if (callingUid != 0 && callingUid != SYSTEM_UID) { if (packageName == null) { return false; } final int uid = AppGlobals.getPackageManager().getPackageUid(packageName, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, UserHandle.getUserId(callingUid)); return UserHandle.isSameApp(callingUid, uid); } } catch (RemoteException e) { // Should not happen return mPmInternal.isSameApp(packageName, callingUid, UserHandle.getUserId(callingUid)); } return true; } Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +5 −0 Original line number Diff line number Diff line Loading @@ -420,6 +420,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { return getApplicationInfo((String) args[0], mUid); }); when(mPackageManagerClient.getPackageUidAsUser(any(), anyInt())).thenReturn(mUid); when(mPackageManagerInternal.isSameApp(anyString(), anyInt(), anyInt())).thenAnswer( (Answer<Boolean>) invocation -> { Object[] args = invocation.getArguments(); return (int) args[1] == mUid; }); final LightsManager mockLightsManager = mock(LightsManager.class); when(mockLightsManager.getLight(anyInt())).thenReturn(mock(LogicalLight.class)); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL); Loading Loading
services/core/java/android/content/pm/PackageManagerInternal.java +13 −0 Original line number Diff line number Diff line Loading @@ -194,6 +194,19 @@ public abstract class PackageManagerInternal { */ public abstract boolean isPermissionsReviewRequired(String packageName, int userId); /** * Gets whether a given package name belongs to the calling uid. If the calling uid is an * {@link Process#isSdkSandboxUid(int) sdk sandbox uid}, checks whether the package name is * equal to {@link PackageManager#getSdkSandboxPackageName()}. * * @param packageName The package name to check. * @param callingUid The calling uid. * @param userId The user under which to check. * @return True if the package name belongs to the calling uid. */ public abstract boolean isSameApp(String packageName, int callingUid, int userId); /** * Retrieve all of the information we know about a particular package/application. * @param filterCallingUid The results will be filtered in the context of this UID instead Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +2 −21 Original line number Diff line number Diff line Loading @@ -9650,27 +9650,8 @@ public class NotificationManagerService extends SystemService { if (uid == Process.ROOT_UID && ROOT_PKG.equals(pkg)) { return; } try { ApplicationInfo ai = mPackageManager.getApplicationInfo( pkg, 0, userId); if (ai == null) { throw new SecurityException("Unknown package " + pkg); } if (!UserHandle.isSameApp(ai.uid, uid)) { throw new SecurityException("Calling uid " + uid + " gave package " + pkg + " which is owned by uid " + ai.uid); } } catch (RemoteException re) { throw new SecurityException("Unknown package " + pkg + "\n" + re); } } private boolean isCallerSameApp(String pkg) { try { checkCallerIsSameApp(pkg); return true; } catch (SecurityException e) { return false; if (!mPackageManagerInternal.isSameApp(pkg, uid, userId)) { throw new SecurityException("Package " + pkg + " is not owned by uid " + uid); } } Loading
services/core/java/com/android/server/pm/PackageManagerService.java +13 −0 Original line number Diff line number Diff line Loading @@ -6964,6 +6964,19 @@ public class PackageManagerService extends IPackageManager.Stub return PackageManagerService.this.getKnownPackageNamesInternal(knownPackage, userId); } @Override public boolean isSameApp(@Nullable String packageName, int callingUid, int userId) { if (packageName == null) { return false; } if (Process.isSdkSandboxUid(callingUid)) { return packageName.equals(getSdkSandboxPackageName()); } int uid = getPackageUid(packageName, 0, userId); return UserHandle.isSameApp(uid, callingUid); } @Override public boolean isResolveActivityComponent(ComponentInfo component) { return mResolveActivity.packageName.equals(component.packageName) Loading
services/core/java/com/android/server/wm/ActivityTaskManagerService.java +2 −12 Original line number Diff line number Diff line Loading @@ -2232,18 +2232,8 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { * Return true if callingUid is system, or packageName belongs to that callingUid. */ private boolean isSameApp(int callingUid, @Nullable String packageName) { try { if (callingUid != 0 && callingUid != SYSTEM_UID) { if (packageName == null) { return false; } final int uid = AppGlobals.getPackageManager().getPackageUid(packageName, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, UserHandle.getUserId(callingUid)); return UserHandle.isSameApp(callingUid, uid); } } catch (RemoteException e) { // Should not happen return mPmInternal.isSameApp(packageName, callingUid, UserHandle.getUserId(callingUid)); } return true; } Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +5 −0 Original line number Diff line number Diff line Loading @@ -420,6 +420,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { return getApplicationInfo((String) args[0], mUid); }); when(mPackageManagerClient.getPackageUidAsUser(any(), anyInt())).thenReturn(mUid); when(mPackageManagerInternal.isSameApp(anyString(), anyInt(), anyInt())).thenAnswer( (Answer<Boolean>) invocation -> { Object[] args = invocation.getArguments(); return (int) args[1] == mUid; }); final LightsManager mockLightsManager = mock(LightsManager.class); when(mockLightsManager.getLight(anyInt())).thenReturn(mock(LogicalLight.class)); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL); Loading