Merge "Handle hotplug events as described instead of rescanning"
This commit is contained in:
@@ -60,31 +60,38 @@ final class LocalDisplayAdapter extends DisplayAdapter {
|
|||||||
super.registerLocked();
|
super.registerLocked();
|
||||||
|
|
||||||
mHotplugReceiver = new HotplugDisplayEventReceiver(getHandler().getLooper());
|
mHotplugReceiver = new HotplugDisplayEventReceiver(getHandler().getLooper());
|
||||||
scanDisplaysLocked();
|
|
||||||
|
for (int builtInDisplayId : BUILT_IN_DISPLAY_IDS_TO_SCAN) {
|
||||||
|
tryConnectDisplayLocked(builtInDisplayId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scanDisplaysLocked() {
|
private void tryConnectDisplayLocked(int builtInDisplayId) {
|
||||||
for (int builtInDisplayId : BUILT_IN_DISPLAY_IDS_TO_SCAN) {
|
IBinder displayToken = Surface.getBuiltInDisplay(builtInDisplayId);
|
||||||
IBinder displayToken = Surface.getBuiltInDisplay(builtInDisplayId);
|
if (displayToken != null && Surface.getDisplayInfo(displayToken, mTempPhys)) {
|
||||||
if (displayToken != null && Surface.getDisplayInfo(displayToken, mTempPhys)) {
|
LocalDisplayDevice device = mDevices.get(builtInDisplayId);
|
||||||
LocalDisplayDevice device = mDevices.get(builtInDisplayId);
|
if (device == null) {
|
||||||
if (device == null) {
|
// Display was added.
|
||||||
// Display was added.
|
device = new LocalDisplayDevice(displayToken, builtInDisplayId, mTempPhys);
|
||||||
device = new LocalDisplayDevice(displayToken, builtInDisplayId, mTempPhys);
|
mDevices.put(builtInDisplayId, device);
|
||||||
mDevices.put(builtInDisplayId, device);
|
sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_ADDED);
|
||||||
sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_ADDED);
|
} else if (device.updatePhysicalDisplayInfoLocked(mTempPhys)) {
|
||||||
} else if (device.updatePhysicalDisplayInfoLocked(mTempPhys)) {
|
// Display properties changed.
|
||||||
// Display properties changed.
|
sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} 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
|
@Override
|
||||||
public void onHotplug(long timestampNanos, int builtInDisplayId, boolean connected) {
|
public void onHotplug(long timestampNanos, int builtInDisplayId, boolean connected) {
|
||||||
synchronized (getSyncRoot()) {
|
synchronized (getSyncRoot()) {
|
||||||
scanDisplaysLocked();
|
if (connected) {
|
||||||
|
tryConnectDisplayLocked(builtInDisplayId);
|
||||||
|
} else {
|
||||||
|
tryDisconnectDisplayLocked(builtInDisplayId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user