From fccce26e131ef466739b9a8f39f0e66fe5e4e684 Mon Sep 17 00:00:00 2001 From: Fiona Campbell Date: Wed, 19 Oct 2022 15:58:15 +0000 Subject: [PATCH] Only load default lightsensor for Brightness Tracker Previously, we were setting new light sensors each time the display changed. This meant that during transitions between displays, multiple light sensors could get loaded since we create temporary displays during transitions. This cl ensures we are only using the light sensor of the default display, since, for now, BrightnessTracker can only take one lightsensor. We also only load the brightness tracker for the default dpc, since other displays will not use this. Bug: 248261521 Test: com.android.server.display Test: dumpsys display | grep -A40 "active connections" and ensure there is only one instance of a brightness tracker connection. Change-Id: If0397af675caed0568bed06d82f7d925002c8df8 Merged-In: If0397af675caed0568bed06d82f7d925002c8df8 --- .../com/android/server/display/DisplayManagerService.java | 2 +- .../android/server/display/DisplayPowerController.java | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java index b153c1ba98e06..a00fadc89973a 100644 --- a/services/core/java/com/android/server/display/DisplayManagerService.java +++ b/services/core/java/com/android/server/display/DisplayManagerService.java @@ -2583,7 +2583,7 @@ public final class DisplayManagerService extends SystemService { // initPowerManagement has not yet been called. return; } - if (mBrightnessTracker == null) { + if (mBrightnessTracker == null && display.getDisplayIdLocked() == Display.DEFAULT_DISPLAY) { mBrightnessTracker = new BrightnessTracker(mContext, null); } diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index efd2e34144666..3e627021b56f7 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -920,7 +920,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call // Initialize all of the brightness tracking state final float brightness = convertToNits(mPowerState.getScreenBrightness()); - if (brightness >= PowerManager.BRIGHTNESS_MIN) { + if (mBrightnessTracker != null && brightness >= PowerManager.BRIGHTNESS_MIN) { mBrightnessTracker.start(brightness); } mBrightnessSettingListener = brightnessValue -> { @@ -1026,7 +1026,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } loadAmbientLightSensor(); - if (mBrightnessTracker != null) { + // BrightnessTracker should only use one light sensor, we want to use the light sensor + // from the default display and not e.g. temporary displays when switching layouts. + if (mBrightnessTracker != null && mDisplayId == Display.DEFAULT_DISPLAY) { mBrightnessTracker.setLightSensor(mLightSensor); } @@ -2434,7 +2436,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call boolean hadUserDataPoint) { final float brightnessInNits = convertToNits(brightness); if (mPowerRequest.useAutoBrightness && brightnessInNits >= 0.0f - && mAutomaticBrightnessController != null) { + && mAutomaticBrightnessController != null && mBrightnessTracker != null) { // We only want to track changes on devices that can actually map the display backlight // values into a physical brightness unit since the value provided by the API is in // nits and not using the arbitrary backlight units.