Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fa20ead1 authored by Yuri Lin's avatar Yuri Lin Committed by Android (Google) Code Review
Browse files

Merge "Add a field to ServiceRecord for FGS notification permissions."

parents a4dba4ec 844938e7
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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.
@@ -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) {
+3 −0
Original line number Diff line number Diff line
@@ -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);
}
+5 −0
Original line number Diff line number Diff line
@@ -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) {
+8 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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 {
+6 −0
Original line number Diff line number Diff line
@@ -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);