summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Hall <jessehall@google.com>2012-11-08 11:55:14 -0800
committerJesse Hall <jessehall@google.com>2012-11-14 22:55:09 -0800
commite244db42da1cb07f53a1fc921b45d498000b56e8 (patch)
treec9ccda894698e5fd14396d95d8dc02736ffcdb20
parent5756c30096f98ed59230a86350537f726276dad5 (diff)
downloadframeworks_base-e244db42da1cb07f53a1fc921b45d498000b56e8.zip
frameworks_base-e244db42da1cb07f53a1fc921b45d498000b56e8.tar.gz
frameworks_base-e244db42da1cb07f53a1fc921b45d498000b56e8.tar.bz2
Handle hotplug events as described instead of rescanning
Hotplug events say which display they're for and whether the display was connected or disconnected. Before, this info was ignored, and the event just triggered a rescan of all displays. If a display was disconnected and then reconnected quickly, the rescan would treat this as a no-op or a device property change and wouldn't turn the display on. Now the display manager attempts to update its state with the change the event describes. So a quick disconnect/connect cycle will cause the display to be turned on since the display manager will have updated its internal state to reflect the disconnect event, and will treat the connect event as a new display rather than a device property change. Bug: 7491120 Change-Id: If16268fbd0708683f6401ea72fbee9fb2c3c8d19
-rw-r--r--services/java/com/android/server/display/LocalDisplayAdapter.java57
1 files changed, 34 insertions, 23 deletions
diff --git a/services/java/com/android/server/display/LocalDisplayAdapter.java b/services/java/com/android/server/display/LocalDisplayAdapter.java
index b37d57f..ee2d617 100644
--- a/services/java/com/android/server/display/LocalDisplayAdapter.java
+++ b/services/java/com/android/server/display/LocalDisplayAdapter.java
@@ -60,31 +60,38 @@ final class LocalDisplayAdapter extends DisplayAdapter {
super.registerLocked();
mHotplugReceiver = new HotplugDisplayEventReceiver(getHandler().getLooper());
- scanDisplaysLocked();
- }
- private void scanDisplaysLocked() {
for (int builtInDisplayId : BUILT_IN_DISPLAY_IDS_TO_SCAN) {
- IBinder displayToken = Surface.getBuiltInDisplay(builtInDisplayId);
- if (displayToken != null && Surface.getDisplayInfo(displayToken, mTempPhys)) {
- LocalDisplayDevice device = mDevices.get(builtInDisplayId);
- if (device == null) {
- // Display was added.
- device = new LocalDisplayDevice(displayToken, builtInDisplayId, mTempPhys);
- mDevices.put(builtInDisplayId, device);
- sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_ADDED);
- } else if (device.updatePhysicalDisplayInfoLocked(mTempPhys)) {
- // Display properties changed.
- sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_CHANGED);
- }
- } else {
- LocalDisplayDevice device = mDevices.get(builtInDisplayId);
- if (device != null) {
- // Display was removed.
- mDevices.remove(builtInDisplayId);
- sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_REMOVED);
- }
+ tryConnectDisplayLocked(builtInDisplayId);
+ }
+ }
+
+ private void tryConnectDisplayLocked(int builtInDisplayId) {
+ IBinder displayToken = Surface.getBuiltInDisplay(builtInDisplayId);
+ if (displayToken != null && Surface.getDisplayInfo(displayToken, mTempPhys)) {
+ LocalDisplayDevice device = mDevices.get(builtInDisplayId);
+ if (device == null) {
+ // Display was added.
+ device = new LocalDisplayDevice(displayToken, builtInDisplayId, mTempPhys);
+ mDevices.put(builtInDisplayId, device);
+ sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_ADDED);
+ } else if (device.updatePhysicalDisplayInfoLocked(mTempPhys)) {
+ // Display properties changed.
+ sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_CHANGED);
}
+ } else {
+ // The display is no longer available. Ignore the attempt to add it.
+ // If it was connected but has already been disconnected, we'll get a
+ // disconnect event that will remove it from mDevices.
+ }
+ }
+
+ private void tryDisconnectDisplayLocked(int builtInDisplayId) {
+ LocalDisplayDevice device = mDevices.get(builtInDisplayId);
+ if (device != null) {
+ // Display was removed.
+ mDevices.remove(builtInDisplayId);
+ sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_REMOVED);
}
}
@@ -191,7 +198,11 @@ final class LocalDisplayAdapter extends DisplayAdapter {
@Override
public void onHotplug(long timestampNanos, int builtInDisplayId, boolean connected) {
synchronized (getSyncRoot()) {
- scanDisplaysLocked();
+ if (connected) {
+ tryConnectDisplayLocked(builtInDisplayId);
+ } else {
+ tryDisconnectDisplayLocked(builtInDisplayId);
+ }
}
}
}