summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Matías Hernández <matiashe@google.com> 2023-06-09 17:27:12 +0200
committer Matías Hernández <matiashe@google.com> 2023-06-09 19:14:35 +0200
commit4954f095f7dac441998bb97fb23ce0a783fcfa08 (patch)
tree2e855cced7eb4bf26f3a303a10eb0406b43ab777
parent565b8127e151c69a2e910aba7db4ac67f86ea2bf (diff)
Query DeviceConfig flag for Notification WakeLocks
Wakelocks will only be used if *both* the system property and the DeviceConfig property specify so. Bug: 275044361 Test: atest NotificationManagerServiceTest Change-Id: Ia27562fac782d0b3473ee2503a87b249fd8dd4db
-rw-r--r--core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java3
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java5
-rwxr-xr-xservices/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java20
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 8135f9cd2f46..dd52de4f84c7 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 b39e8606e189..d29d9c84501d 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -6597,7 +6597,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 2a0c745a0ffc..cebc5409c795 100755
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -587,6 +587,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);
@@ -1929,8 +1931,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,