FileDocCategorySizeDatePackage
VirtualDisplayAdapter.javaAPI DocAndroid 5.1 API15031Thu Mar 12 22:22:42 GMT 2015com.android.server.display

VirtualDisplayAdapter

public 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
Constructors Summary
public VirtualDisplayAdapter(DisplayManagerService.SyncRoot syncRoot, android.content.Context context, android.os.Handler handler, Listener listener)


    // Called with SyncRoot lock held.
      
                  
        super(syncRoot, context, handler, listener, TAG);
        mHandler = handler;
    
Methods Summary
public DisplayDevicecreateVirtualDisplayLocked(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 intgetNextUniqueIndex(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 voidhandleBinderDiedLocked(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 voidhandleMediaProjectionStoppedLocked(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 DisplayDevicereleaseVirtualDisplayLocked(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 voidresizeVirtualDisplayLocked(android.os.IBinder appToken, int width, int height, int densityDpi)

        VirtualDisplayDevice device = mVirtualDisplayDevices.get(appToken);
        if (device != null) {
            device.resizeLocked(width, height, densityDpi);
        }
    
public voidsetVirtualDisplaySurfaceLocked(android.os.IBinder appToken, android.view.Surface surface)

        VirtualDisplayDevice device = mVirtualDisplayDevices.get(appToken);
        if (device != null) {
            device.setSurfaceLocked(surface);
        }