summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Hall <jessehall@google.com>2013-02-08 01:29:03 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2013-02-08 01:29:03 +0000
commitfd1c028e34fc559ccccebd18979ee85ec7821dea (patch)
tree89d750b99f67fbfa65aef7b38ca039d75c7996bb
parent9434c112d1fef52ade78d7ef818daf981bf63bef (diff)
parent190fd9aecae650ace2213fdb17a647b2f5a4aa5f (diff)
downloadframeworks_base-fd1c028e34fc559ccccebd18979ee85ec7821dea.zip
frameworks_base-fd1c028e34fc559ccccebd18979ee85ec7821dea.tar.gz
frameworks_base-fd1c028e34fc559ccccebd18979ee85ec7821dea.tar.bz2
Merge "Handle hotplug events as described instead of rescanning"
-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);
+ }
}
}
}