summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-11-16 01:15:06 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-11-16 01:15:06 +0000
commitf6374942c5ed004dfe558ab09aefae7454c6cd12 (patch)
tree4ad33ac37d997cbb047c8f29f346211af1dbe54e
parent7d874ea7d35b84f56cb72461cb1590d7ac5762b9 (diff)
parentdaaab342097a54b6f775524a27c37e17e5383e0c (diff)
Merge "Refactor and make the default device effects applier public" into main
-rw-r--r--services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java99
1 files changed, 57 insertions, 42 deletions
diff --git a/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java b/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java
index 925ba1752fe2..3e96afe9bee3 100644
--- a/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java
+++ b/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java
@@ -39,9 +39,11 @@ import android.service.notification.ZenModeConfig.ConfigOrigin;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
+import com.android.internal.annotations.Keep;
/** Default implementation for {@link DeviceEffectsApplier}. */
-class DefaultDeviceEffectsApplier implements DeviceEffectsApplier {
+@Keep
+public class DefaultDeviceEffectsApplier implements DeviceEffectsApplier {
private static final String TAG = "DeviceEffectsApplier";
private static final String SUPPRESS_AMBIENT_DISPLAY_TOKEN =
"DefaultDeviceEffectsApplier:SuppressAmbientDisplay";
@@ -63,10 +65,10 @@ class DefaultDeviceEffectsApplier implements DeviceEffectsApplier {
@GuardedBy("mRegisterReceiverLock")
private boolean mIsScreenOffReceiverRegistered;
- private ZenDeviceEffects mLastAppliedEffects = new ZenDeviceEffects.Builder().build();
+ protected ZenDeviceEffects mLastAppliedEffects = new ZenDeviceEffects.Builder().build();
private boolean mPendingNightMode;
- DefaultDeviceEffectsApplier(Context context) {
+ public DefaultDeviceEffectsApplier(Context context) {
mContext = context;
mColorDisplayManager = context.getSystemService(ColorDisplayManager.class);
mKeyguardManager = context.getSystemService(KeyguardManager.class);
@@ -79,56 +81,69 @@ class DefaultDeviceEffectsApplier implements DeviceEffectsApplier {
@Override
public void apply(ZenDeviceEffects effects, @ConfigOrigin int origin) {
- Binder.withCleanCallingIdentity(() -> {
- if (mLastAppliedEffects.shouldSuppressAmbientDisplay()
- != effects.shouldSuppressAmbientDisplay()) {
- try {
- traceApplyDeviceEffect("suppressAmbientDisplay",
- effects.shouldSuppressAmbientDisplay());
- mPowerManager.suppressAmbientDisplay(SUPPRESS_AMBIENT_DISPLAY_TOKEN,
- effects.shouldSuppressAmbientDisplay());
- } catch (Exception e) {
- Slog.e(TAG, "Could not change AOD override", e);
- }
- }
+ Binder.withCleanCallingIdentity(
+ () -> {
+ maybeSuppressAmbientDisplay(effects.shouldSuppressAmbientDisplay());
+ maybeDisplayGrayscale(effects.shouldDisplayGrayscale());
+ maybeDimWallpaper(effects.shouldDimWallpaper());
+ maybeUseNightMode(effects.shouldUseNightMode(), origin);
+ });
- if (mLastAppliedEffects.shouldDisplayGrayscale() != effects.shouldDisplayGrayscale()) {
- if (mColorDisplayManager != null) {
- try {
- traceApplyDeviceEffect("displayGrayscale",
- effects.shouldDisplayGrayscale());
- mColorDisplayManager.setSaturationLevel(
- effects.shouldDisplayGrayscale() ? SATURATION_LEVEL_GRAYSCALE
- : SATURATION_LEVEL_FULL_COLOR);
- } catch (Exception e) {
- Slog.e(TAG, "Could not change grayscale override", e);
- }
- }
+ mLastAppliedEffects = effects;
+ }
+
+ protected void maybeSuppressAmbientDisplay(boolean shouldSuppressAmbientDisplay) {
+ if (mLastAppliedEffects.shouldSuppressAmbientDisplay() != shouldSuppressAmbientDisplay) {
+ try {
+ traceApplyDeviceEffect("suppressAmbientDisplay", shouldSuppressAmbientDisplay);
+ mPowerManager.suppressAmbientDisplay(
+ SUPPRESS_AMBIENT_DISPLAY_TOKEN, shouldSuppressAmbientDisplay);
+ } catch (Exception e) {
+ Slog.e(TAG, "Could not change AOD override", e);
}
+ }
+ }
- if (mLastAppliedEffects.shouldDimWallpaper() != effects.shouldDimWallpaper()) {
- if (mWallpaperManager != null) {
- try {
- traceApplyDeviceEffect("dimWallpaper", effects.shouldDimWallpaper());
- mWallpaperManager.setWallpaperDimAmount(
- effects.shouldDimWallpaper() ? WALLPAPER_DIM_AMOUNT_DIMMED
- : WALLPAPER_DIM_AMOUNT_NORMAL);
- } catch (Exception e) {
- Slog.e(TAG, "Could not change wallpaper override", e);
- }
+ protected void maybeDisplayGrayscale(boolean shouldDisplayGrayscale) {
+ if (mLastAppliedEffects.shouldDisplayGrayscale() != shouldDisplayGrayscale) {
+ if (mColorDisplayManager != null) {
+ try {
+ traceApplyDeviceEffect("displayGrayscale", shouldDisplayGrayscale);
+ mColorDisplayManager.setSaturationLevel(
+ shouldDisplayGrayscale
+ ? SATURATION_LEVEL_GRAYSCALE
+ : SATURATION_LEVEL_FULL_COLOR);
+ } catch (Exception e) {
+ Slog.e(TAG, "Could not change grayscale override", e);
}
}
+ }
+ }
- if (mLastAppliedEffects.shouldUseNightMode() != effects.shouldUseNightMode()) {
+ protected void maybeDimWallpaper(boolean shouldDimWallpaper) {
+ if (mLastAppliedEffects.shouldDimWallpaper() != shouldDimWallpaper) {
+ if (mWallpaperManager != null) {
try {
- updateOrScheduleNightMode(effects.shouldUseNightMode(), origin);
+ traceApplyDeviceEffect("dimWallpaper", shouldDimWallpaper);
+ mWallpaperManager.setWallpaperDimAmount(
+ shouldDimWallpaper
+ ? WALLPAPER_DIM_AMOUNT_DIMMED
+ : WALLPAPER_DIM_AMOUNT_NORMAL);
} catch (Exception e) {
- Slog.e(TAG, "Could not change dark theme override", e);
+ Slog.e(TAG, "Could not change wallpaper override", e);
}
}
- });
+ }
+ }
- mLastAppliedEffects = effects;
+ protected void maybeUseNightMode(boolean shouldUseNightMode, @ConfigOrigin int origin) {
+ if (mLastAppliedEffects.shouldUseNightMode() != shouldUseNightMode) {
+ try {
+ updateOrScheduleNightMode(shouldUseNightMode, origin);
+ } catch (Exception e) {
+ Slog.e(TAG, "Could not change dark theme override", e);
+ }
+ }
}
private void updateOrScheduleNightMode(boolean useNightMode, @ConfigOrigin int origin) {