summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-06-03 15:49:05 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-06-03 15:49:05 +0000
commitdff28db196b0fe4e2e210f76401498c38d8a93e2 (patch)
treeca90fd9bb83c5bb2a1deeb98980d06535bd6bb74
parent4d9d7a730958debf27a8099a727da6300f88a5c2 (diff)
parentf71d6a6ec7f9a886e99d08a1c00b5328010bb382 (diff)
Merge "Guard against crashes in effects services" into main
-rw-r--r--services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java47
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java24
2 files changed, 58 insertions, 13 deletions
diff --git a/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java b/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java
index 27b85746fec2..d060f8f2d036 100644
--- a/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java
+++ b/services/core/java/com/android/server/notification/DefaultDeviceEffectsApplier.java
@@ -32,12 +32,13 @@ import android.service.notification.DeviceEffectsApplier;
import android.service.notification.ZenDeviceEffects;
import android.service.notification.ZenModeConfig;
import android.service.notification.ZenModeConfig.ConfigChangeOrigin;
+import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
/** Default implementation for {@link DeviceEffectsApplier}. */
class DefaultDeviceEffectsApplier implements DeviceEffectsApplier {
-
+ private static final String TAG = "DeviceEffectsApplier";
private static final String SUPPRESS_AMBIENT_DISPLAY_TOKEN =
"DefaultDeviceEffectsApplier:SuppressAmbientDisplay";
private static final int SATURATION_LEVEL_GRAYSCALE = 0;
@@ -75,28 +76,44 @@ class DefaultDeviceEffectsApplier implements DeviceEffectsApplier {
Binder.withCleanCallingIdentity(() -> {
if (mLastAppliedEffects.shouldSuppressAmbientDisplay()
!= effects.shouldSuppressAmbientDisplay()) {
- mPowerManager.suppressAmbientDisplay(SUPPRESS_AMBIENT_DISPLAY_TOKEN,
- effects.shouldSuppressAmbientDisplay());
+ try {
+ mPowerManager.suppressAmbientDisplay(SUPPRESS_AMBIENT_DISPLAY_TOKEN,
+ effects.shouldSuppressAmbientDisplay());
+ } catch (Exception e) {
+ Slog.e(TAG, "Could not change AOD override", e);
+ }
}
if (mLastAppliedEffects.shouldDisplayGrayscale() != effects.shouldDisplayGrayscale()) {
if (mColorDisplayManager != null) {
- mColorDisplayManager.setSaturationLevel(
- effects.shouldDisplayGrayscale() ? SATURATION_LEVEL_GRAYSCALE
- : SATURATION_LEVEL_FULL_COLOR);
+ try {
+ mColorDisplayManager.setSaturationLevel(
+ effects.shouldDisplayGrayscale() ? SATURATION_LEVEL_GRAYSCALE
+ : SATURATION_LEVEL_FULL_COLOR);
+ } catch (Exception e) {
+ Slog.e(TAG, "Could not change grayscale override", e);
+ }
}
}
if (mLastAppliedEffects.shouldDimWallpaper() != effects.shouldDimWallpaper()) {
if (mWallpaperManager != null) {
- mWallpaperManager.setWallpaperDimAmount(
- effects.shouldDimWallpaper() ? WALLPAPER_DIM_AMOUNT_DIMMED
- : WALLPAPER_DIM_AMOUNT_NORMAL);
+ try {
+ mWallpaperManager.setWallpaperDimAmount(
+ effects.shouldDimWallpaper() ? WALLPAPER_DIM_AMOUNT_DIMMED
+ : WALLPAPER_DIM_AMOUNT_NORMAL);
+ } catch (Exception e) {
+ Slog.e(TAG, "Could not change wallpaper override", e);
+ }
}
}
if (mLastAppliedEffects.shouldUseNightMode() != effects.shouldUseNightMode()) {
- updateOrScheduleNightMode(effects.shouldUseNightMode(), origin);
+ try {
+ updateOrScheduleNightMode(effects.shouldUseNightMode(), origin);
+ } catch (Exception e) {
+ Slog.e(TAG, "Could not change dark theme override", e);
+ }
}
});
@@ -131,9 +148,13 @@ class DefaultDeviceEffectsApplier implements DeviceEffectsApplier {
private void updateNightModeImmediately(boolean useNightMode) {
Binder.withCleanCallingIdentity(() -> {
- mUiModeManager.setAttentionModeThemeOverlay(
- useNightMode ? MODE_ATTENTION_THEME_OVERLAY_NIGHT
- : MODE_ATTENTION_THEME_OVERLAY_OFF);
+ try {
+ mUiModeManager.setAttentionModeThemeOverlay(
+ useNightMode ? MODE_ATTENTION_THEME_OVERLAY_NIGHT
+ : MODE_ATTENTION_THEME_OVERLAY_OFF);
+ } catch (Exception e) {
+ Slog.e(TAG, "Could not change wallpaper override", e);
+ }
});
}
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 bfbc81ccfe39..4bea95f61c1f 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/DefaultDeviceEffectsApplierTest.java
@@ -25,10 +25,12 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -322,4 +324,26 @@ public class DefaultDeviceEffectsApplierTest {
argThat(filter -> Intent.ACTION_SCREEN_OFF.equals(filter.getAction(0))),
anyInt());
}
+
+ @Test
+ public void apply_servicesThrow_noCrash() {
+ mSetFlagsRule.enableFlags(android.app.Flags.FLAG_MODES_API);
+
+ doThrow(new RuntimeException()).when(mPowerManager)
+ .suppressAmbientDisplay(anyString(), anyBoolean());
+ doThrow(new RuntimeException()).when(mColorDisplayManager).setSaturationLevel(anyInt());
+ doThrow(new RuntimeException()).when(mWallpaperManager).setWallpaperDimAmount(anyFloat());
+ doThrow(new RuntimeException()).when(mUiModeManager).setAttentionModeThemeOverlay(anyInt());
+ mApplier = new DefaultDeviceEffectsApplier(mContext);
+
+ ZenDeviceEffects effects = new ZenDeviceEffects.Builder()
+ .setShouldSuppressAmbientDisplay(true)
+ .setShouldDimWallpaper(true)
+ .setShouldDisplayGrayscale(true)
+ .setShouldUseNightMode(true)
+ .build();
+ mApplier.apply(effects, UPDATE_ORIGIN_USER);
+
+ // No crashes
+ }
}