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

Commit 6bb38e02 authored by Matías Hernández's avatar Matías Hernández
Browse files

Use Context/PermissionManager for NM.areNotificationsEnabled()

Instead of calling into NMS to perform the same query. The advantage is that PermissionManager caches results client-side.

Bug: 379323264
Test: CTS
Flag: android.app.nm_binder_perf_permission_check
Change-Id: I93b8491924f570cb69ef5b0972243241e66c72c1
parent 8c494386
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.app;

import static android.Manifest.permission.POST_NOTIFICATIONS;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.service.notification.Flags.notificationClassification;

import android.annotation.CallbackExecutor;
@@ -1597,6 +1599,9 @@ public class NotificationManager {
     * Returns whether notifications from the calling package are enabled.
     */
    public boolean areNotificationsEnabled() {
        if (Flags.nmBinderPerfPermissionCheck()) {
            return mContext.checkSelfPermission(POST_NOTIFICATIONS) == PERMISSION_GRANTED;
        } else {
            INotificationManager service = getService();
            try {
                return service.areNotificationsEnabled(mContext.getPackageName());
@@ -1604,6 +1609,7 @@ public class NotificationManager {
                throw e.rethrowFromSystemServer();
            }
        }
    }

    /**
     * Gets whether all notifications posted by this app can appear outside of the
+7 −0
Original line number Diff line number Diff line
@@ -276,6 +276,13 @@ flag {
  bug: "367996732"
}

flag {
  name: "nm_binder_perf_permission_check"
  namespace: "systemui"
  description: "Use PermissionManager for areNotificationsEnabled() instead of NMS"
  bug: "362981561"
}

flag {
  name: "no_sbnholder"
  namespace: "systemui"