Merge "DisplayModeDirector: proximity should not vote on doze" into sc-dev am: e8310817af
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15378209 Change-Id: I8b0dd0e92e4715a2452edce9698898ee27daf2f8
This commit is contained in:
@@ -153,7 +153,7 @@ public class DisplayModeDirector {
|
|||||||
updateVoteLocked(displayId, priority, vote);
|
updateVoteLocked(displayId, priority, vote);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mSensorObserver = new SensorObserver(context, ballotBox);
|
mSensorObserver = new SensorObserver(context, ballotBox, injector);
|
||||||
mHbmObserver = new HbmObserver(injector, ballotBox, BackgroundThread.getHandler());
|
mHbmObserver = new HbmObserver(injector, ballotBox, BackgroundThread.getHandler());
|
||||||
mDeviceConfigDisplaySettings = new DeviceConfigDisplaySettings();
|
mDeviceConfigDisplaySettings = new DeviceConfigDisplaySettings();
|
||||||
mDeviceConfig = injector.getDeviceConfig();
|
mDeviceConfig = injector.getDeviceConfig();
|
||||||
@@ -2127,27 +2127,34 @@ public class DisplayModeDirector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SensorObserver implements ProximityActiveListener {
|
private final class SensorObserver implements ProximityActiveListener,
|
||||||
private static final String PROXIMITY_SENSOR_NAME = null;
|
DisplayManager.DisplayListener {
|
||||||
private static final String PROXIMITY_SENSOR_TYPE = Sensor.STRING_TYPE_PROXIMITY;
|
private final String mProximitySensorName = null;
|
||||||
|
private final String mProximitySensorType = Sensor.STRING_TYPE_PROXIMITY;
|
||||||
|
|
||||||
private final BallotBox mBallotBox;
|
private final BallotBox mBallotBox;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
private final Injector mInjector;
|
||||||
|
|
||||||
private DisplayManager mDisplayManager;
|
private DisplayManager mDisplayManager;
|
||||||
private DisplayManagerInternal mDisplayManagerInternal;
|
private DisplayManagerInternal mDisplayManagerInternal;
|
||||||
private boolean mIsProxActive = false;
|
private boolean mIsProxActive = false;
|
||||||
|
private final SparseBooleanArray mDozeStateByDisplay;
|
||||||
|
|
||||||
SensorObserver(Context context, BallotBox ballotBox) {
|
SensorObserver(Context context, BallotBox ballotBox, Injector injector) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mBallotBox = ballotBox;
|
mBallotBox = ballotBox;
|
||||||
|
mInjector = injector;
|
||||||
|
mDozeStateByDisplay = new SparseBooleanArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProximityActive(boolean isActive) {
|
public void onProximityActive(boolean isActive) {
|
||||||
|
synchronized (mLock) {
|
||||||
if (mIsProxActive != isActive) {
|
if (mIsProxActive != isActive) {
|
||||||
mIsProxActive = isActive;
|
mIsProxActive = isActive;
|
||||||
recalculateVotes();
|
recalculateVotesLocked();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2158,17 +2165,27 @@ public class DisplayModeDirector {
|
|||||||
final SensorManagerInternal sensorManager =
|
final SensorManagerInternal sensorManager =
|
||||||
LocalServices.getService(SensorManagerInternal.class);
|
LocalServices.getService(SensorManagerInternal.class);
|
||||||
sensorManager.addProximityActiveListener(BackgroundThread.getExecutor(), this);
|
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();
|
final Display[] displays = mDisplayManager.getDisplays();
|
||||||
for (Display d : displays) {
|
for (Display d : displays) {
|
||||||
int displayId = d.getDisplayId();
|
int displayId = d.getDisplayId();
|
||||||
Vote vote = null;
|
Vote vote = null;
|
||||||
if (mIsProxActive) {
|
if (mIsProxActive && !mDozeStateByDisplay.get(displayId)) {
|
||||||
final RefreshRateRange rate =
|
final RefreshRateRange rate =
|
||||||
mDisplayManagerInternal.getRefreshRateForDisplayAndSensor(
|
mDisplayManagerInternal.getRefreshRateForDisplayAndSensor(
|
||||||
displayId, PROXIMITY_SENSOR_NAME, PROXIMITY_SENSOR_TYPE);
|
displayId, mProximitySensorName, mProximitySensorType);
|
||||||
if (rate != null) {
|
if (rate != null) {
|
||||||
vote = Vote.forRefreshRates(rate.min, rate.max);
|
vote = Vote.forRefreshRates(rate.min, rate.max);
|
||||||
}
|
}
|
||||||
@@ -2180,6 +2197,41 @@ public class DisplayModeDirector {
|
|||||||
void dumpLocked(PrintWriter pw) {
|
void dumpLocked(PrintWriter pw) {
|
||||||
pw.println(" SensorObserver");
|
pw.println(" SensorObserver");
|
||||||
pw.println(" mIsProxActive=" + mIsProxActive);
|
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);
|
Handler handler, long flags);
|
||||||
|
|
||||||
BrightnessInfo getBrightnessInfo(int displayId);
|
BrightnessInfo getBrightnessInfo(int displayId);
|
||||||
|
|
||||||
|
boolean isDozeState(Display d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -2463,6 +2517,11 @@ public class DisplayModeDirector {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDozeState(Display d) {
|
||||||
|
return Display.isDozeState(d.getState());
|
||||||
|
}
|
||||||
|
|
||||||
private DisplayManager getDisplayManager() {
|
private DisplayManager getDisplayManager() {
|
||||||
if (mDisplayManager == null) {
|
if (mDisplayManager == null) {
|
||||||
mDisplayManager = mContext.getSystemService(DisplayManager.class);
|
mDisplayManager = mContext.getSystemService(DisplayManager.class);
|
||||||
|
|||||||
@@ -1340,11 +1340,19 @@ public class DisplayModeDirectorTest {
|
|||||||
createDirectorFromRefreshRateArray(new float[] {60.f, 90.f}, 0);
|
createDirectorFromRefreshRateArray(new float[] {60.f, 90.f}, 0);
|
||||||
director.start(createMockSensorManager());
|
director.start(createMockSensorManager());
|
||||||
|
|
||||||
ArgumentCaptor<ProximityActiveListener> captor =
|
ArgumentCaptor<ProximityActiveListener> ProximityCaptor =
|
||||||
ArgumentCaptor.forClass(ProximityActiveListener.class);
|
ArgumentCaptor.forClass(ProximityActiveListener.class);
|
||||||
verify(mSensorManagerInternalMock).addProximityActiveListener(any(Executor.class),
|
verify(mSensorManagerInternalMock).addProximityActiveListener(any(Executor.class),
|
||||||
captor.capture());
|
ProximityCaptor.capture());
|
||||||
ProximityActiveListener listener = captor.getValue();
|
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
|
// Verify that there is no proximity vote initially
|
||||||
Vote vote = director.getVote(DISPLAY_ID, Vote.PRIORITY_PROXIMITY);
|
Vote vote = director.getVote(DISPLAY_ID, Vote.PRIORITY_PROXIMITY);
|
||||||
@@ -1353,13 +1361,38 @@ public class DisplayModeDirectorTest {
|
|||||||
when(mDisplayManagerInternalMock.getRefreshRateForDisplayAndSensor(eq(DISPLAY_ID), eq(null),
|
when(mDisplayManagerInternalMock.getRefreshRateForDisplayAndSensor(eq(DISPLAY_ID), eq(null),
|
||||||
eq(Sensor.STRING_TYPE_PROXIMITY))).thenReturn(new RefreshRateRange(60, 60));
|
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.
|
// 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);
|
vote = director.getVote(DISPLAY_ID, Vote.PRIORITY_PROXIMITY);
|
||||||
assertVoteForRefreshRate(vote, 60.f);
|
assertVoteForRefreshRate(vote, 60.f);
|
||||||
|
|
||||||
// Turn prox off and verify vote is gone.
|
// Turn prox off and verify vote is gone.
|
||||||
listener.onProximityActive(false);
|
proximityListener.onProximityActive(false);
|
||||||
vote = director.getVote(DISPLAY_ID, Vote.PRIORITY_PROXIMITY);
|
vote = director.getVote(DISPLAY_ID, Vote.PRIORITY_PROXIMITY);
|
||||||
assertNull(vote);
|
assertNull(vote);
|
||||||
}
|
}
|
||||||
@@ -1710,6 +1743,11 @@ public class DisplayModeDirectorTest {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDozeState(Display d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void notifyPeakRefreshRateChanged() {
|
void notifyPeakRefreshRateChanged() {
|
||||||
if (mPeakRefreshRateObserver != null) {
|
if (mPeakRefreshRateObserver != null) {
|
||||||
mPeakRefreshRateObserver.dispatchChange(false /*selfChange*/,
|
mPeakRefreshRateObserver.dispatchChange(false /*selfChange*/,
|
||||||
|
|||||||
Reference in New Issue
Block a user