Loading core/java/android/app/INotificationManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -193,7 +193,7 @@ interface INotificationManager void setNotificationDelegate(String callingPkg, String delegate); String getNotificationDelegate(String callingPkg); boolean canNotifyAsPackage(String callingPkg, String targetPkg); boolean canNotifyAsPackage(String callingPkg, String targetPkg, int userId); void setPrivateNotificationsAllowed(boolean allow); boolean getPrivateNotificationsAllowed(); Loading core/java/android/app/NotificationManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -627,7 +627,7 @@ public class NotificationManager { public boolean canNotifyAsPackage(@NonNull String pkg) { INotificationManager service = getService(); try { return service.canNotifyAsPackage(mContext.getPackageName(), pkg); return service.canNotifyAsPackage(mContext.getPackageName(), pkg, mContext.getUserId()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading services/core/java/com/android/server/notification/NotificationManagerService.java +7 −2 Original line number Diff line number Diff line Loading @@ -2504,15 +2504,20 @@ public class NotificationManagerService extends SystemService { } @Override public boolean canNotifyAsPackage(String callingPkg, String targetPkg) { public boolean canNotifyAsPackage(String callingPkg, String targetPkg, int userId) { checkCallerIsSameApp(callingPkg); final int callingUid = Binder.getCallingUid(); UserHandle user = UserHandle.getUserHandleForUid(callingUid); if (user.getIdentifier() != userId) { getContext().enforceCallingPermission( android.Manifest.permission.INTERACT_ACROSS_USERS, "canNotifyAsPackage for user " + userId); } try { ApplicationInfo info = mPackageManager.getApplicationInfo(targetPkg, MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE, user.getIdentifier()); userId); if (info != null) { return mPreferencesHelper.isDelegateAllowed( targetPkg, info.uid, callingPkg, callingUid); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR; import static android.content.pm.PackageManager.FEATURE_WATCH; import static android.content.pm.PackageManager.PERMISSION_DENIED; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.os.Build.VERSION_CODES.O_MR1; import static android.os.Build.VERSION_CODES.P; import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE; Loading Loading @@ -111,6 +112,7 @@ import android.testing.AndroidTestingRunner; import android.testing.TestableContext; import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.testing.TestablePermissions; import android.text.Html; import android.util.ArrayMap; import android.util.ArraySet; Loading Loading @@ -4170,6 +4172,25 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertNotNull(captor.getValue()); } @Test public void testCanNotifyAsUser_crossUser() throws Exception { // same user no problem mBinderService.canNotifyAsPackage("src", "target", mContext.getUserId()); // cross user, no permission, problem try { mBinderService.canNotifyAsPackage("src", "target", mContext.getUserId() + 1); fail("Should not be callable cross user without cross user permission"); } catch (SecurityException e) { // good } // cross user, with permission, no problem TestablePermissions perms = mContext.getTestablePermissions(); perms.setPermission(android.Manifest.permission.INTERACT_ACROSS_USERS, PERMISSION_GRANTED); mBinderService.canNotifyAsPackage("src", "target", mContext.getUserId() + 1); } @Test public void setDefaultAssistantForUser_fromConfigXml() { clearDeviceConfig(); Loading Loading
core/java/android/app/INotificationManager.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -193,7 +193,7 @@ interface INotificationManager void setNotificationDelegate(String callingPkg, String delegate); String getNotificationDelegate(String callingPkg); boolean canNotifyAsPackage(String callingPkg, String targetPkg); boolean canNotifyAsPackage(String callingPkg, String targetPkg, int userId); void setPrivateNotificationsAllowed(boolean allow); boolean getPrivateNotificationsAllowed(); Loading
core/java/android/app/NotificationManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -627,7 +627,7 @@ public class NotificationManager { public boolean canNotifyAsPackage(@NonNull String pkg) { INotificationManager service = getService(); try { return service.canNotifyAsPackage(mContext.getPackageName(), pkg); return service.canNotifyAsPackage(mContext.getPackageName(), pkg, mContext.getUserId()); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +7 −2 Original line number Diff line number Diff line Loading @@ -2504,15 +2504,20 @@ public class NotificationManagerService extends SystemService { } @Override public boolean canNotifyAsPackage(String callingPkg, String targetPkg) { public boolean canNotifyAsPackage(String callingPkg, String targetPkg, int userId) { checkCallerIsSameApp(callingPkg); final int callingUid = Binder.getCallingUid(); UserHandle user = UserHandle.getUserHandleForUid(callingUid); if (user.getIdentifier() != userId) { getContext().enforceCallingPermission( android.Manifest.permission.INTERACT_ACROSS_USERS, "canNotifyAsPackage for user " + userId); } try { ApplicationInfo info = mPackageManager.getApplicationInfo(targetPkg, MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE, user.getIdentifier()); userId); if (info != null) { return mPreferencesHelper.isDelegateAllowed( targetPkg, info.uid, callingPkg, callingUid); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR; import static android.content.pm.PackageManager.FEATURE_WATCH; import static android.content.pm.PackageManager.PERMISSION_DENIED; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.os.Build.VERSION_CODES.O_MR1; import static android.os.Build.VERSION_CODES.P; import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE; Loading Loading @@ -111,6 +112,7 @@ import android.testing.AndroidTestingRunner; import android.testing.TestableContext; import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.testing.TestablePermissions; import android.text.Html; import android.util.ArrayMap; import android.util.ArraySet; Loading Loading @@ -4170,6 +4172,25 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertNotNull(captor.getValue()); } @Test public void testCanNotifyAsUser_crossUser() throws Exception { // same user no problem mBinderService.canNotifyAsPackage("src", "target", mContext.getUserId()); // cross user, no permission, problem try { mBinderService.canNotifyAsPackage("src", "target", mContext.getUserId() + 1); fail("Should not be callable cross user without cross user permission"); } catch (SecurityException e) { // good } // cross user, with permission, no problem TestablePermissions perms = mContext.getTestablePermissions(); perms.setPermission(android.Manifest.permission.INTERACT_ACROSS_USERS, PERMISSION_GRANTED); mBinderService.canNotifyAsPackage("src", "target", mContext.getUserId() + 1); } @Test public void setDefaultAssistantForUser_fromConfigXml() { clearDeviceConfig(); Loading