diff options
| author | 2023-06-09 23:27:42 +0000 | |
|---|---|---|
| committer | 2023-06-09 23:27:42 +0000 | |
| commit | 5da5d626c1edfab371085096416b9ea795ae6b4d (patch) | |
| tree | 6715db624af302be294bc53a8cf50b9634fa1827 | |
| parent | db0d2f829cd83d6b0e75fde4140c389f02441ef5 (diff) | |
| parent | c41de7f08f0968d760f038622cf2c065e1fcecf2 (diff) | |
Merge "Query DeviceConfig flag for Notification WakeLocks" into udc-dev am: a8c332201f am: c41de7f08f
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23636739
Change-Id: Ia8be2da52e30adee87ef24cbacdbe4d9ee6f7d14
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
3 files changed, 26 insertions, 2 deletions
diff --git a/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java b/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java index 4cb592eedfdc..9ffccb34f44d 100644 --- a/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java +++ b/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java @@ -118,6 +118,9 @@ public final class SystemUiDeviceConfigFlags { */ public static final String NAS_DEFAULT_SERVICE = "nas_default_service"; + /** (boolean) Whether notify() calls to NMS should acquire and hold WakeLocks. */ + public static final String NOTIFY_WAKELOCK = "nms_notify_wakelock"; + // Flags related to media notifications /** diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 498bc4c3605d..7c3ff7ef39a9 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -6598,7 +6598,10 @@ public class NotificationManagerService extends SystemService { } private PostNotificationTracker acquireWakeLockForPost(String pkg, int uid) { - if (mFlagResolver.isEnabled(WAKE_LOCK_FOR_POSTING_NOTIFICATION)) { + if (mFlagResolver.isEnabled(WAKE_LOCK_FOR_POSTING_NOTIFICATION) + && Binder.withCleanCallingIdentity( + () -> DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI, + SystemUiDeviceConfigFlags.NOTIFY_WAKELOCK, false))) { // The package probably doesn't have WAKE_LOCK permission and should not require it. return Binder.withCleanCallingIdentity(() -> { WakeLock wakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, 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 4debbb4d38c1..eaf483869be4 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -588,6 +588,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { return wl; }); mTestFlagResolver.setFlagOverride(WAKE_LOCK_FOR_POSTING_NOTIFICATION, true); + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI, + SystemUiDeviceConfigFlags.NOTIFY_WAKELOCK, "true", false); // apps allowed as convos mService.setStringArrayResourceValue(PKG_O); @@ -1931,8 +1933,24 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } @Test - public void enqueueNotification_wakeLockFlagOff_noWakeLock() throws Exception { + public void enqueueNotification_wakeLockSystemPropertyOff_noWakeLock() throws Exception { mTestFlagResolver.setFlagOverride(WAKE_LOCK_FOR_POSTING_NOTIFICATION, false); + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI, + SystemUiDeviceConfigFlags.NOTIFY_WAKELOCK, "true", false); + + mBinderService.enqueueNotificationWithTag(PKG, PKG, + "enqueueNotification_setsWakeLockWorkSource", 0, + generateNotificationRecord(null).getNotification(), 0); + waitForIdle(); + + verifyZeroInteractions(mPowerManager); + } + + @Test + public void enqueueNotification_wakeLockDeviceConfigOff_noWakeLock() throws Exception { + mTestFlagResolver.setFlagOverride(WAKE_LOCK_FOR_POSTING_NOTIFICATION, true); + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_SYSTEMUI, + SystemUiDeviceConfigFlags.NOTIFY_WAKELOCK, "false", false); mBinderService.enqueueNotificationWithTag(PKG, PKG, "enqueueNotification_setsWakeLockWorkSource", 0, |