Merge "Merge "Use display listener instead of Intent Action for screen status" into qt-qpr1-dev am: 28f6d34b77" into qt-qpr1-dev-plus-aosp
This commit is contained in:
committed by
Android (Google) Code Review
commit
73516727e0
@@ -680,6 +680,7 @@ public class DisplayModeDirector {
|
|||||||
@Override
|
@Override
|
||||||
public void onDisplayChanged(int displayId) {
|
public void onDisplayChanged(int displayId) {
|
||||||
updateDisplayModes(displayId);
|
updateDisplayModes(displayId);
|
||||||
|
mBrightnessObserver.onDisplayChanged(displayId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDisplayModes(int displayId) {
|
private void updateDisplayModes(int displayId) {
|
||||||
@@ -734,8 +735,6 @@ public class DisplayModeDirector {
|
|||||||
private AmbientFilter mAmbientFilter;
|
private AmbientFilter mAmbientFilter;
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private ScreenStateReceiver mScreenStateReceiver;
|
|
||||||
|
|
||||||
// Enable light sensor only when screen is on, peak refresh rate enabled and low power mode
|
// Enable light sensor only when screen is on, peak refresh rate enabled and low power mode
|
||||||
// off. After initialization, these states will be updated from the same handler thread.
|
// off. After initialization, these states will be updated from the same handler thread.
|
||||||
private boolean mScreenOn = false;
|
private boolean mScreenOn = false;
|
||||||
@@ -793,11 +792,7 @@ public class DisplayModeDirector {
|
|||||||
mSensorManager = sensorManager;
|
mSensorManager = sensorManager;
|
||||||
mLightSensor = lightSensor;
|
mLightSensor = lightSensor;
|
||||||
|
|
||||||
// Intent.ACTION_SCREEN_ON is not sticky. Check current screen status.
|
onScreenOn(isDefaultDisplayOn());
|
||||||
if (mContext.getSystemService(PowerManager.class).isInteractive()) {
|
|
||||||
onScreenOn(true);
|
|
||||||
}
|
|
||||||
mScreenStateReceiver = new ScreenStateReceiver(mContext);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -822,6 +817,12 @@ public class DisplayModeDirector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onDisplayChanged(int displayId) {
|
||||||
|
if (displayId == Display.DEFAULT_DISPLAY) {
|
||||||
|
onScreenOn(isDefaultDisplayOn());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void dumpLocked(PrintWriter pw) {
|
public void dumpLocked(PrintWriter pw) {
|
||||||
pw.println(" BrightnessObserver");
|
pw.println(" BrightnessObserver");
|
||||||
|
|
||||||
@@ -891,8 +892,6 @@ public class DisplayModeDirector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onScreenOn(boolean on) {
|
private void onScreenOn(boolean on) {
|
||||||
// Not check mShouldObserveAmbientChange because Screen status receiver is registered
|
|
||||||
// only when it is true.
|
|
||||||
if (mScreenOn != on) {
|
if (mScreenOn != on) {
|
||||||
mScreenOn = on;
|
mScreenOn = on;
|
||||||
updateSensorStatus();
|
updateSensorStatus();
|
||||||
@@ -913,6 +912,13 @@ public class DisplayModeDirector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isDefaultDisplayOn() {
|
||||||
|
final Display display = mContext.getSystemService(DisplayManager.class)
|
||||||
|
.getDisplay(Display.DEFAULT_DISPLAY);
|
||||||
|
return display.getState() != Display.STATE_OFF
|
||||||
|
&& mContext.getSystemService(PowerManager.class).isInteractive();
|
||||||
|
}
|
||||||
|
|
||||||
private final class LightSensorEventListener implements SensorEventListener {
|
private final class LightSensorEventListener implements SensorEventListener {
|
||||||
final private static int INJECT_EVENTS_INTERVAL_MS = LIGHT_SENSOR_RATE_MS;
|
final private static int INJECT_EVENTS_INTERVAL_MS = LIGHT_SENSOR_RATE_MS;
|
||||||
private float mLastSensorData;
|
private float mLastSensorData;
|
||||||
@@ -991,20 +997,5 @@ public class DisplayModeDirector {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
private final class ScreenStateReceiver extends BroadcastReceiver {
|
|
||||||
public ScreenStateReceiver(Context context) {
|
|
||||||
IntentFilter filter = new IntentFilter();
|
|
||||||
filter.addAction(Intent.ACTION_SCREEN_OFF);
|
|
||||||
filter.addAction(Intent.ACTION_SCREEN_ON);
|
|
||||||
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
|
|
||||||
context.registerReceiver(this, filter, null, mHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
onScreenOn(Intent.ACTION_SCREEN_ON.equals(intent.getAction()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user