Loading services/core/java/com/android/server/am/ServiceRecord.java +6 −0 Original line number Diff line number Diff line Loading @@ -174,6 +174,9 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN boolean mFgsNotificationWasDeferred; // FGS notification was shown before the FGS finishes, or it wasn't deferred in the first place. boolean mFgsNotificationShown; // Whether FGS package has permissions to show notifications. // TODO(b/194833441): Output this field to logs in ActiveServices#logFGSStateChangeLocked. boolean mFgsHasNotificationPermission; // allow the service becomes foreground service? Service started from background may not be // allowed to become a foreground service. Loading Loading @@ -968,6 +971,9 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN if (nm == null) { return; } // Record whether the package has permission to notify the user mFgsHasNotificationPermission = nm.areNotificationsEnabledForPackage( localPackageName, appUid); Notification localForegroundNoti = _foregroundNoti; try { if (localForegroundNoti.getSmallIcon() == null) { Loading services/core/java/com/android/server/notification/NotificationManagerInternal.java +3 −0 Original line number Diff line number Diff line Loading @@ -39,4 +39,7 @@ public interface NotificationManagerInternal { /** Get the number of notification channels for a given package */ int getNumNotificationChannelsForPackage(String pkg, int uid, boolean includeDeleted); /** Does the specified package/uid have permission to post notifications? */ boolean areNotificationsEnabledForPackage(String pkg, int uid); } services/core/java/com/android/server/notification/NotificationManagerService.java +5 −0 Original line number Diff line number Diff line Loading @@ -6205,6 +6205,11 @@ public class NotificationManagerService extends SystemService { return NotificationManagerService.this .getNumNotificationChannelsForPackage(pkg, uid, includeDeleted); } @Override public boolean areNotificationsEnabledForPackage(String pkg, int uid) { return areNotificationsEnabledForPackageInt(pkg, uid); } }; int getNumNotificationChannelsForPackage(String pkg, int uid, boolean includeDeleted) { Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +8 −1 Original line number Diff line number Diff line Loading @@ -182,7 +182,6 @@ import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; import android.util.AtomicFile; import android.util.Slog; import android.util.TypedXmlPullParser; import android.util.TypedXmlSerializer; import android.util.Xml; Loading Loading @@ -7173,6 +7172,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(mPermissionHelper, never()).hasPermission(anyInt()); } @Test public void testAreNotificationsEnabledForPackage_viaInternalService() throws Exception { assertEquals(mInternalService.areNotificationsEnabledForPackage( mContext.getPackageName(), mUid), mBinderService.areNotificationsEnabledForPackage(mContext.getPackageName(), mUid)); verify(mPermissionHelper, never()).hasPermission(anyInt()); } @Test public void testAreBubblesAllowedForPackage_crossUser() throws Exception { try { Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java +6 −0 Original line number Diff line number Diff line Loading @@ -535,6 +535,12 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { verify(mPermissionHelper).hasPermission(mUid + UserHandle.PER_USER_RANGE); } @Test public void testAreNotificationsEnabledForPackage_viaInternalService() { mInternalService.areNotificationsEnabledForPackage(mContext.getPackageName(), mUid); verify(mPermissionHelper).hasPermission(mUid); } @Test public void testGetPackageImportance() throws Exception { when(mPermissionHelper.hasPermission(mUid)).thenReturn(true); Loading Loading
services/core/java/com/android/server/am/ServiceRecord.java +6 −0 Original line number Diff line number Diff line Loading @@ -174,6 +174,9 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN boolean mFgsNotificationWasDeferred; // FGS notification was shown before the FGS finishes, or it wasn't deferred in the first place. boolean mFgsNotificationShown; // Whether FGS package has permissions to show notifications. // TODO(b/194833441): Output this field to logs in ActiveServices#logFGSStateChangeLocked. boolean mFgsHasNotificationPermission; // allow the service becomes foreground service? Service started from background may not be // allowed to become a foreground service. Loading Loading @@ -968,6 +971,9 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN if (nm == null) { return; } // Record whether the package has permission to notify the user mFgsHasNotificationPermission = nm.areNotificationsEnabledForPackage( localPackageName, appUid); Notification localForegroundNoti = _foregroundNoti; try { if (localForegroundNoti.getSmallIcon() == null) { Loading
services/core/java/com/android/server/notification/NotificationManagerInternal.java +3 −0 Original line number Diff line number Diff line Loading @@ -39,4 +39,7 @@ public interface NotificationManagerInternal { /** Get the number of notification channels for a given package */ int getNumNotificationChannelsForPackage(String pkg, int uid, boolean includeDeleted); /** Does the specified package/uid have permission to post notifications? */ boolean areNotificationsEnabledForPackage(String pkg, int uid); }
services/core/java/com/android/server/notification/NotificationManagerService.java +5 −0 Original line number Diff line number Diff line Loading @@ -6205,6 +6205,11 @@ public class NotificationManagerService extends SystemService { return NotificationManagerService.this .getNumNotificationChannelsForPackage(pkg, uid, includeDeleted); } @Override public boolean areNotificationsEnabledForPackage(String pkg, int uid) { return areNotificationsEnabledForPackageInt(pkg, uid); } }; int getNumNotificationChannelsForPackage(String pkg, int uid, boolean includeDeleted) { Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +8 −1 Original line number Diff line number Diff line Loading @@ -182,7 +182,6 @@ import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; import android.util.AtomicFile; import android.util.Slog; import android.util.TypedXmlPullParser; import android.util.TypedXmlSerializer; import android.util.Xml; Loading Loading @@ -7173,6 +7172,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(mPermissionHelper, never()).hasPermission(anyInt()); } @Test public void testAreNotificationsEnabledForPackage_viaInternalService() throws Exception { assertEquals(mInternalService.areNotificationsEnabledForPackage( mContext.getPackageName(), mUid), mBinderService.areNotificationsEnabledForPackage(mContext.getPackageName(), mUid)); verify(mPermissionHelper, never()).hasPermission(anyInt()); } @Test public void testAreBubblesAllowedForPackage_crossUser() throws Exception { try { Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationPermissionMigrationTest.java +6 −0 Original line number Diff line number Diff line Loading @@ -535,6 +535,12 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase { verify(mPermissionHelper).hasPermission(mUid + UserHandle.PER_USER_RANGE); } @Test public void testAreNotificationsEnabledForPackage_viaInternalService() { mInternalService.areNotificationsEnabledForPackage(mContext.getPackageName(), mUid); verify(mPermissionHelper).hasPermission(mUid); } @Test public void testGetPackageImportance() throws Exception { when(mPermissionHelper.hasPermission(mUid)).thenReturn(true); Loading