VirtualDisplayAdapterpublic final class VirtualDisplayAdapter extends DisplayAdapter A display adapter that provides virtual displays on behalf of applications.
Display adapters are guarded by the {@link DisplayManagerService.SyncRoot} lock.
|
Fields Summary |
---|
static final String | TAG | static final boolean | DEBUG | private static final String | UNIQUE_ID_PREFIX | private final android.util.ArrayMap | mVirtualDisplayDevices | private android.os.Handler | mHandler |
Methods Summary |
---|
public DisplayDevice | createVirtualDisplayLocked(android.hardware.display.IVirtualDisplayCallback callback, android.media.projection.IMediaProjection projection, int ownerUid, java.lang.String ownerPackageName, java.lang.String name, int width, int height, int densityDpi, android.view.Surface surface, int flags)
boolean secure = (flags & DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE) != 0;
IBinder appToken = callback.asBinder();
IBinder displayToken = SurfaceControl.createDisplay(name, secure);
final String baseUniqueId =
UNIQUE_ID_PREFIX + ownerPackageName + "," + ownerUid + "," + name + ",";
final int uniqueIndex = getNextUniqueIndex(baseUniqueId);
VirtualDisplayDevice device = new VirtualDisplayDevice(displayToken, appToken,
ownerUid, ownerPackageName, name, width, height, densityDpi, surface, flags,
new Callback(callback, mHandler), baseUniqueId + uniqueIndex, uniqueIndex);
mVirtualDisplayDevices.put(appToken, device);
try {
if (projection != null) {
projection.registerCallback(new MediaProjectionCallback(appToken));
}
appToken.linkToDeath(device, 0);
} catch (RemoteException ex) {
mVirtualDisplayDevices.remove(appToken);
device.destroyLocked();
return null;
}
// Return the display device without actually sending the event indicating
// that it was added. The caller will handle it.
return device;
| private int | getNextUniqueIndex(java.lang.String uniqueIdPrefix)Returns the next unique index for the uniqueIdPrefix
if (mVirtualDisplayDevices.isEmpty()) {
return 0;
}
int nextUniqueIndex = 0;
Iterator<VirtualDisplayDevice> it = mVirtualDisplayDevices.values().iterator();
while (it.hasNext()) {
VirtualDisplayDevice device = it.next();
if (device.getUniqueId().startsWith(uniqueIdPrefix)
&& device.mUniqueIndex >= nextUniqueIndex) {
// Increment the next unique index to be greater than ones we have already ran
// across for displays that have the same unique Id prefix.
nextUniqueIndex = device.mUniqueIndex + 1;
}
}
return nextUniqueIndex;
| private void | handleBinderDiedLocked(android.os.IBinder appToken)
VirtualDisplayDevice device = mVirtualDisplayDevices.remove(appToken);
if (device != null) {
Slog.i(TAG, "Virtual display device released because application token died: "
+ device.mOwnerPackageName);
device.destroyLocked();
sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_REMOVED);
}
| private void | handleMediaProjectionStoppedLocked(android.os.IBinder appToken)
VirtualDisplayDevice device = mVirtualDisplayDevices.remove(appToken);
if (device != null) {
Slog.i(TAG, "Virtual display device released because media projection stopped: "
+ device.mName);
device.stopLocked();
}
| public DisplayDevice | releaseVirtualDisplayLocked(android.os.IBinder appToken)
VirtualDisplayDevice device = mVirtualDisplayDevices.remove(appToken);
if (device != null) {
device.destroyLocked();
appToken.unlinkToDeath(device, 0);
}
// Return the display device that was removed without actually sending the
// event indicating that it was removed. The caller will handle it.
return device;
| public void | resizeVirtualDisplayLocked(android.os.IBinder appToken, int width, int height, int densityDpi)
VirtualDisplayDevice device = mVirtualDisplayDevices.get(appToken);
if (device != null) {
device.resizeLocked(width, height, densityDpi);
}
| public void | setVirtualDisplaySurfaceLocked(android.os.IBinder appToken, android.view.Surface surface)
VirtualDisplayDevice device = mVirtualDisplayDevices.get(appToken);
if (device != null) {
device.setSurfaceLocked(surface);
}
|
|