summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ady Abraham <adyabr@google.com> 2021-07-23 17:01:26 -0700
committer Ady Abraham <adyabr@google.com> 2021-08-03 10:29:35 -0700
commit32e10a7238b72537f6f9a57c94742f228ce4eb35 (patch)
tree15c28d02495969ad0a80076640b45e847fcbc9ab
parent70c0c93542e56cc44679033e2813633f69222665 (diff)
DisplayModeDirector: proximity should not vote on doze
Bug: 192699858 Test: atest DisplayModeDirectorTest Change-Id: If21a036807f0602fb5ac8a024544ddfaf1fb46ed
-rw-r--r--services/core/java/com/android/server/display/DisplayModeDirector.java81
-rw-r--r--services/tests/servicestests/src/com/android/server/display/DisplayModeDirectorTest.java48
2 files changed, 113 insertions, 16 deletions
diff --git a/services/core/java/com/android/server/display/DisplayModeDirector.java b/services/core/java/com/android/server/display/DisplayModeDirector.java
index f23ae6e2340c..186986e17c14 100644
--- a/services/core/java/com/android/server/display/DisplayModeDirector.java
+++ b/services/core/java/com/android/server/display/DisplayModeDirector.java
@@ -153,7 +153,7 @@ public class DisplayModeDirector {
updateVoteLocked(displayId, priority, vote);
}
};
- mSensorObserver = new SensorObserver(context, ballotBox);
+ mSensorObserver = new SensorObserver(context, ballotBox, injector);
mHbmObserver = new HbmObserver(injector, ballotBox, BackgroundThread.getHandler());
mDeviceConfigDisplaySettings = new DeviceConfigDisplaySettings();
mDeviceConfig = injector.getDeviceConfig();
@@ -2127,27 +2127,34 @@ public class DisplayModeDirector {
}
}
- private static class SensorObserver implements ProximityActiveListener {
- private static final String PROXIMITY_SENSOR_NAME = null;
- private static final String PROXIMITY_SENSOR_TYPE = Sensor.STRING_TYPE_PROXIMITY;
+ private final class SensorObserver implements ProximityActiveListener,
+ DisplayManager.DisplayListener {
+ private final String mProximitySensorName = null;
+ private final String mProximitySensorType = Sensor.STRING_TYPE_PROXIMITY;
private final BallotBox mBallotBox;
private final Context mContext;
+ private final Injector mInjector;
private DisplayManager mDisplayManager;
private DisplayManagerInternal mDisplayManagerInternal;
private boolean mIsProxActive = false;
+ private final SparseBooleanArray mDozeStateByDisplay;
- SensorObserver(Context context, BallotBox ballotBox) {
+ SensorObserver(Context context, BallotBox ballotBox, Injector injector) {
mContext = context;
mBallotBox = ballotBox;
+ mInjector = injector;
+ mDozeStateByDisplay = new SparseBooleanArray();
}
@Override
public void onProximityActive(boolean isActive) {
- if (mIsProxActive != isActive) {
- mIsProxActive = isActive;
- recalculateVotes();
+ synchronized (mLock) {
+ if (mIsProxActive != isActive) {
+ mIsProxActive = isActive;
+ recalculateVotesLocked();
+ }
}
}
@@ -2158,17 +2165,27 @@ public class DisplayModeDirector {
final SensorManagerInternal sensorManager =
LocalServices.getService(SensorManagerInternal.class);
sensorManager.addProximityActiveListener(BackgroundThread.getExecutor(), this);
+
+ synchronized (mLock) {
+ for (Display d : mDisplayManager.getDisplays()) {
+ mDozeStateByDisplay.put(d.getDisplayId(), mInjector.isDozeState(d));
+ }
+ }
+ mInjector.registerDisplayListener(this, BackgroundThread.getHandler(),
+ DisplayManager.EVENT_FLAG_DISPLAY_ADDED
+ | DisplayManager.EVENT_FLAG_DISPLAY_CHANGED
+ | DisplayManager.EVENT_FLAG_DISPLAY_REMOVED);
}
- private void recalculateVotes() {
+ private void recalculateVotesLocked() {
final Display[] displays = mDisplayManager.getDisplays();
for (Display d : displays) {
int displayId = d.getDisplayId();
Vote vote = null;
- if (mIsProxActive) {
+ if (mIsProxActive && !mDozeStateByDisplay.get(displayId)) {
final RefreshRateRange rate =
mDisplayManagerInternal.getRefreshRateForDisplayAndSensor(
- displayId, PROXIMITY_SENSOR_NAME, PROXIMITY_SENSOR_TYPE);
+ displayId, mProximitySensorName, mProximitySensorType);
if (rate != null) {
vote = Vote.forRefreshRates(rate.min, rate.max);
}
@@ -2180,6 +2197,41 @@ public class DisplayModeDirector {
void dumpLocked(PrintWriter pw) {
pw.println(" SensorObserver");
pw.println(" mIsProxActive=" + mIsProxActive);
+ pw.println(" mDozeStateByDisplay:");
+ for (int i = 0; i < mDozeStateByDisplay.size(); i++) {
+ final int id = mDozeStateByDisplay.keyAt(i);
+ final boolean dozed = mDozeStateByDisplay.valueAt(i);
+ pw.println(" " + id + " -> " + dozed);
+ }
+ }
+
+ @Override
+ public void onDisplayAdded(int displayId) {
+ boolean isDozeState = mInjector.isDozeState(mDisplayManager.getDisplay(displayId));
+ synchronized (mLock) {
+ mDozeStateByDisplay.put(displayId, isDozeState);
+ recalculateVotesLocked();
+ }
+ }
+
+ @Override
+ public void onDisplayChanged(int displayId) {
+ boolean wasDozeState = mDozeStateByDisplay.get(displayId);
+ synchronized (mLock) {
+ mDozeStateByDisplay.put(displayId,
+ mInjector.isDozeState(mDisplayManager.getDisplay(displayId)));
+ if (wasDozeState != mDozeStateByDisplay.get(displayId)) {
+ recalculateVotesLocked();
+ }
+ }
+ }
+
+ @Override
+ public void onDisplayRemoved(int displayId) {
+ synchronized (mLock) {
+ mDozeStateByDisplay.delete(displayId);
+ recalculateVotesLocked();
+ }
}
}
@@ -2411,6 +2463,8 @@ public class DisplayModeDirector {
Handler handler, long flags);
BrightnessInfo getBrightnessInfo(int displayId);
+
+ boolean isDozeState(Display d);
}
@VisibleForTesting
@@ -2463,6 +2517,11 @@ public class DisplayModeDirector {
return null;
}
+ @Override
+ public boolean isDozeState(Display d) {
+ return Display.isDozeState(d.getState());
+ }
+
private DisplayManager getDisplayManager() {
if (mDisplayManager == null) {
mDisplayManager = mContext.getSystemService(DisplayManager.class);
diff --git a/services/tests/servicestests/src/com/android/server/display/DisplayModeDirectorTest.java b/services/tests/servicestests/src/com/android/server/display/DisplayModeDirectorTest.java
index a205a1d167fe..1ac28abb4c2f 100644
--- a/services/tests/servicestests/src/com/android/server/display/DisplayModeDirectorTest.java
+++ b/services/tests/servicestests/src/com/android/server/display/DisplayModeDirectorTest.java
@@ -1340,11 +1340,19 @@ public class DisplayModeDirectorTest {
createDirectorFromRefreshRateArray(new float[] {60.f, 90.f}, 0);
director.start(createMockSensorManager());
- ArgumentCaptor<ProximityActiveListener> captor =
+ ArgumentCaptor<ProximityActiveListener> ProximityCaptor =
ArgumentCaptor.forClass(ProximityActiveListener.class);
verify(mSensorManagerInternalMock).addProximityActiveListener(any(Executor.class),
- captor.capture());
- ProximityActiveListener listener = captor.getValue();
+ ProximityCaptor.capture());
+ ProximityActiveListener proximityListener = ProximityCaptor.getValue();
+
+ ArgumentCaptor<DisplayListener> DisplayCaptor =
+ ArgumentCaptor.forClass(DisplayListener.class);
+ verify(mInjector).registerDisplayListener(DisplayCaptor.capture(), any(Handler.class),
+ eq(DisplayManager.EVENT_FLAG_DISPLAY_ADDED
+ | DisplayManager.EVENT_FLAG_DISPLAY_CHANGED
+ | DisplayManager.EVENT_FLAG_DISPLAY_REMOVED));
+ DisplayListener displayListener = DisplayCaptor.getValue();
// Verify that there is no proximity vote initially
Vote vote = director.getVote(DISPLAY_ID, Vote.PRIORITY_PROXIMITY);
@@ -1353,13 +1361,38 @@ public class DisplayModeDirectorTest {
when(mDisplayManagerInternalMock.getRefreshRateForDisplayAndSensor(eq(DISPLAY_ID), eq(null),
eq(Sensor.STRING_TYPE_PROXIMITY))).thenReturn(new RefreshRateRange(60, 60));
+ when(mInjector.isDozeState(any(Display.class))).thenReturn(false);
+
// Set the proximity to active and verify that we added a vote.
- listener.onProximityActive(true);
+ proximityListener.onProximityActive(true);
+ vote = director.getVote(DISPLAY_ID, Vote.PRIORITY_PROXIMITY);
+ assertVoteForRefreshRate(vote, 60.f);
+
+ // Set the display state to doze and verify that the vote is gone
+ when(mInjector.isDozeState(any(Display.class))).thenReturn(true);
+ displayListener.onDisplayAdded(DISPLAY_ID);
+ vote = director.getVote(DISPLAY_ID, Vote.PRIORITY_PROXIMITY);
+ assertNull(vote);
+
+ // Set the display state to on and verify that we added the vote back.
+ when(mInjector.isDozeState(any(Display.class))).thenReturn(false);
+ displayListener.onDisplayChanged(DISPLAY_ID);
+ vote = director.getVote(DISPLAY_ID, Vote.PRIORITY_PROXIMITY);
+ assertVoteForRefreshRate(vote, 60.f);
+
+ // Set the display state to doze and verify that the vote is gone
+ when(mInjector.isDozeState(any(Display.class))).thenReturn(true);
+ displayListener.onDisplayAdded(DISPLAY_ID);
+ vote = director.getVote(DISPLAY_ID, Vote.PRIORITY_PROXIMITY);
+ assertNull(vote);
+
+ // Remove the display to cause the doze state to be removed
+ displayListener.onDisplayRemoved(DISPLAY_ID);
vote = director.getVote(DISPLAY_ID, Vote.PRIORITY_PROXIMITY);
assertVoteForRefreshRate(vote, 60.f);
// Turn prox off and verify vote is gone.
- listener.onProximityActive(false);
+ proximityListener.onProximityActive(false);
vote = director.getVote(DISPLAY_ID, Vote.PRIORITY_PROXIMITY);
assertNull(vote);
}
@@ -1710,6 +1743,11 @@ public class DisplayModeDirectorTest {
return null;
}
+ @Override
+ public boolean isDozeState(Display d) {
+ return false;
+ }
+
void notifyPeakRefreshRateChanged() {
if (mPeakRefreshRateObserver != null) {
mPeakRefreshRateObserver.dispatchChange(false /*selfChange*/,