Merge "Fix crashes running android.appsecurity.cts.EphemeralTest"
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 9381fa2..5005ea7 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -4289,7 +4289,8 @@
}
// posted from app A on behalf of app A
if (isCallerSameApp(targetPkg, callingUid, userId)
- && TextUtils.equals(callingPkg, targetPkg)) {
+ && (TextUtils.equals(callingPkg, targetPkg)
+ || isCallerSameApp(callingPkg, callingUid, userId))) {
return callingUid;
}
@@ -4306,7 +4307,8 @@
return targetUid;
}
- throw new SecurityException("Caller " + callingUid + " cannot post for pkg " + targetPkg);
+ throw new SecurityException("Caller " + callingPkg + ":" + callingUid
+ + " cannot post for pkg " + targetPkg + " in user " + userId);
}
/**
@@ -4326,7 +4328,7 @@
if (!isSystemNotification && !isNotificationFromListener) {
synchronized (mNotificationLock) {
if (mNotificationsByKey.get(r.sbn.getKey()) == null
- && isCallerInstantApp(pkg, callingUid, r.getUserId())) {
+ && isCallerInstantApp(pkg, Binder.getCallingUid(), userId)) {
// Ephemeral apps have some special constraints for notifications.
// They are not allowed to create new notifications however they are allowed to
// update notifications created by the system (e.g. a foreground service
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index b0d942c..58aae2b 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -3448,17 +3448,14 @@
}
@Test
- public void testResolveNotificationUid_sameAppWrongPkg() throws Exception {
+ public void testResolveNotificationUid_sameAppDiffPackage() throws Exception {
ApplicationInfo info = new ApplicationInfo();
info.uid = Binder.getCallingUid();
- when(mPackageManager.getApplicationInfo(anyString(), anyInt(), anyInt())).thenReturn(info);
+ when(mPackageManager.getApplicationInfo(anyString(), anyInt(), eq(0))).thenReturn(info);
- try {
- mService.resolveNotificationUid("caller", "other", info.uid, 0);
- fail("Incorrect pkg didn't throw security exception");
- } catch (SecurityException e) {
- // yay
- }
+ int actualUid = mService.resolveNotificationUid("caller", "callerAlso", info.uid, 0);
+
+ assertEquals(info.uid, actualUid);
}
@Test