summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java10
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java44
2 files changed, 37 insertions, 17 deletions
diff --git a/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java b/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java
index 71a6b5ed0581..ab650afe68a7 100644
--- a/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java
+++ b/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java
@@ -16,7 +16,8 @@
package com.android.server.notification;
-import static android.app.UiModeManager.MODE_NIGHT_CUSTOM_TYPE_BEDTIME;
+import static android.app.UiModeManager.MODE_ATTENTION_THEME_OVERLAY_NIGHT;
+import static android.app.UiModeManager.MODE_ATTENTION_THEME_OVERLAY_OFF;
import android.app.UiModeManager;
import android.app.WallpaperManager;
@@ -128,10 +129,9 @@ class DefaultDeviceEffectsApplier implements DeviceEffectsApplier {
private void updateNightModeImmediately(boolean useNightMode) {
Binder.withCleanCallingIdentity(() -> {
- // TODO: b/314285749 - Placeholder; use real APIs when available.
- mUiModeManager.setNightModeCustomType(MODE_NIGHT_CUSTOM_TYPE_BEDTIME);
- mUiModeManager.setNightModeActivatedForCustomMode(MODE_NIGHT_CUSTOM_TYPE_BEDTIME,
- useNightMode);
+ mUiModeManager.setAttentionModeThemeOverlay(
+ useNightMode ? MODE_ATTENTION_THEME_OVERLAY_NIGHT
+ : MODE_ATTENTION_THEME_OVERLAY_OFF);
});
}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java b/services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java
index 30843d222742..3797dbb97213 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java
@@ -16,7 +16,8 @@
package com.android.server.notification;
-import static android.app.UiModeManager.MODE_NIGHT_CUSTOM_TYPE_BEDTIME;
+import static android.app.UiModeManager.MODE_ATTENTION_THEME_OVERLAY_NIGHT;
+import static android.app.UiModeManager.MODE_ATTENTION_THEME_OVERLAY_OFF;
import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_APP;
import static android.service.notification.ZenModeConfig.UPDATE_ORIGIN_USER;
@@ -121,28 +122,49 @@ public class DefaultDeviceEffectsApplierTest {
verify(mPowerManager).suppressAmbientDisplay(anyString(), eq(true));
verify(mColorDisplayManager).setSaturationLevel(eq(0));
verify(mWallpaperManager).setWallpaperDimAmount(eq(0.6f));
- verify(mUiModeManager).setNightModeActivatedForCustomMode(
- eq(MODE_NIGHT_CUSTOM_TYPE_BEDTIME), eq(true));
+ verify(mUiModeManager).setAttentionModeThemeOverlay(eq(MODE_ATTENTION_THEME_OVERLAY_NIGHT));
}
@Test
- public void apply_removesPreviouslyAppliedEffects() {
+ public void apply_removesEffects() {
mSetFlagsRule.enableFlags(android.app.Flags.FLAG_MODES_API);
ZenDeviceEffects previousEffects = new ZenDeviceEffects.Builder()
.setShouldSuppressAmbientDisplay(true)
.setShouldDimWallpaper(true)
+ .setShouldDisplayGrayscale(true)
+ .setShouldUseNightMode(true)
.build();
mApplier.apply(previousEffects, UPDATE_ORIGIN_USER);
verify(mPowerManager).suppressAmbientDisplay(anyString(), eq(true));
+ verify(mColorDisplayManager).setSaturationLevel(eq(0));
verify(mWallpaperManager).setWallpaperDimAmount(eq(0.6f));
+ verify(mUiModeManager).setAttentionModeThemeOverlay(eq(MODE_ATTENTION_THEME_OVERLAY_NIGHT));
ZenDeviceEffects noEffects = new ZenDeviceEffects.Builder().build();
mApplier.apply(noEffects, UPDATE_ORIGIN_USER);
verify(mPowerManager).suppressAmbientDisplay(anyString(), eq(false));
+ verify(mColorDisplayManager).setSaturationLevel(eq(100));
verify(mWallpaperManager).setWallpaperDimAmount(eq(0.0f));
- verifyZeroInteractions(mColorDisplayManager, mUiModeManager);
+ verify(mUiModeManager).setAttentionModeThemeOverlay(eq(MODE_ATTENTION_THEME_OVERLAY_OFF));
+ }
+
+ @Test
+ public void apply_removesOnlyPreviouslyAppliedEffects() {
+ mSetFlagsRule.enableFlags(android.app.Flags.FLAG_MODES_API);
+
+ ZenDeviceEffects previousEffects = new ZenDeviceEffects.Builder()
+ .setShouldSuppressAmbientDisplay(true)
+ .build();
+ mApplier.apply(previousEffects, UPDATE_ORIGIN_USER);
+ verify(mPowerManager).suppressAmbientDisplay(anyString(), eq(true));
+
+ ZenDeviceEffects noEffects = new ZenDeviceEffects.Builder().build();
+ mApplier.apply(noEffects, UPDATE_ORIGIN_USER);
+
+ verify(mPowerManager).suppressAmbientDisplay(anyString(), eq(false));
+ verifyZeroInteractions(mColorDisplayManager, mWallpaperManager, mUiModeManager);
}
@Test
@@ -150,6 +172,7 @@ public class DefaultDeviceEffectsApplierTest {
mSetFlagsRule.enableFlags(android.app.Flags.FLAG_MODES_API);
mContext.addMockSystemService(ColorDisplayManager.class, null);
mContext.addMockSystemService(WallpaperManager.class, null);
+ mApplier = new DefaultDeviceEffectsApplier(mContext);
ZenDeviceEffects effects = new ZenDeviceEffects.Builder()
.setShouldSuppressAmbientDisplay(true)
@@ -177,7 +200,7 @@ public class DefaultDeviceEffectsApplierTest {
verify(mWallpaperManager).setWallpaperDimAmount(eq(0.6f));
verify(mPowerManager, never()).suppressAmbientDisplay(anyString(), anyBoolean());
- verify(mUiModeManager, never()).setNightModeActivatedForCustomMode(anyInt(), anyBoolean());
+ verify(mUiModeManager, never()).setAttentionModeThemeOverlay(anyInt());
}
@Test
@@ -223,8 +246,7 @@ public class DefaultDeviceEffectsApplierTest {
screenOffReceiver.onReceive(mContext, new Intent(Intent.ACTION_SCREEN_OFF));
// So the effect is applied, and we stopped listening for this event.
- verify(mUiModeManager).setNightModeActivatedForCustomMode(
- eq(MODE_NIGHT_CUSTOM_TYPE_BEDTIME), eq(true));
+ verify(mUiModeManager).setAttentionModeThemeOverlay(eq(MODE_ATTENTION_THEME_OVERLAY_NIGHT));
verify(mContext).unregisterReceiver(eq(screenOffReceiver));
}
@@ -239,8 +261,7 @@ public class DefaultDeviceEffectsApplierTest {
origin.value());
// Effect was applied, and no broadcast receiver was registered.
- verify(mUiModeManager).setNightModeActivatedForCustomMode(
- eq(MODE_NIGHT_CUSTOM_TYPE_BEDTIME), eq(true));
+ verify(mUiModeManager).setAttentionModeThemeOverlay(eq(MODE_ATTENTION_THEME_OVERLAY_NIGHT));
verify(mContext, never()).registerReceiver(any(), any(), anyInt());
}
@@ -256,8 +277,7 @@ public class DefaultDeviceEffectsApplierTest {
origin.value());
// Effect was applied, and no broadcast receiver was registered.
- verify(mUiModeManager).setNightModeActivatedForCustomMode(
- eq(MODE_NIGHT_CUSTOM_TYPE_BEDTIME), eq(true));
+ verify(mUiModeManager).setAttentionModeThemeOverlay(eq(MODE_ATTENTION_THEME_OVERLAY_NIGHT));
verify(mContext, never()).registerReceiver(any(), any(), anyInt());
}