FileDocCategorySizeDatePackage
DisplayManagerGlobal.javaAPI DocAndroid 5.1 API18965Thu Mar 12 22:22:10 GMT 2015android.hardware.display

DisplayManagerGlobal

public final class DisplayManagerGlobal extends Object
Manager communication with the display manager service on behalf of an application process. You're probably looking for {@link DisplayManager}.
hide

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private static final boolean
USE_CACHE
public static final int
EVENT_DISPLAY_ADDED
public static final int
EVENT_DISPLAY_CHANGED
public static final int
EVENT_DISPLAY_REMOVED
private static DisplayManagerGlobal
sInstance
private final Object
mLock
private final IDisplayManager
mDm
private DisplayManagerCallback
mCallback
private final ArrayList
mDisplayListeners
private final android.util.SparseArray
mDisplayInfoCache
private int[]
mDisplayIdCache
private int
mWifiDisplayScanNestCount
Constructors Summary
private DisplayManagerGlobal(IDisplayManager dm)


       
        mDm = dm;
    
Methods Summary
public voidconnectWifiDisplay(java.lang.String deviceAddress)

        if (deviceAddress == null) {
            throw new IllegalArgumentException("deviceAddress must not be null");
        }

        try {
            mDm.connectWifiDisplay(deviceAddress);
        } catch (RemoteException ex) {
            Log.e(TAG, "Failed to connect to Wifi display " + deviceAddress + ".", ex);
        }
    
public VirtualDisplaycreateVirtualDisplay(android.content.Context context, android.media.projection.MediaProjection projection, java.lang.String name, int width, int height, int densityDpi, android.view.Surface surface, int flags, VirtualDisplay.Callback callback, android.os.Handler handler)

        if (TextUtils.isEmpty(name)) {
            throw new IllegalArgumentException("name must be non-null and non-empty");
        }
        if (width <= 0 || height <= 0 || densityDpi <= 0) {
            throw new IllegalArgumentException("width, height, and densityDpi must be "
                    + "greater than 0");
        }

        VirtualDisplayCallback callbackWrapper = new VirtualDisplayCallback(callback, handler);
        IMediaProjection projectionToken = projection != null ? projection.getProjection() : null;
        int displayId;
        try {
            displayId = mDm.createVirtualDisplay(callbackWrapper, projectionToken,
                    context.getPackageName(), name, width, height, densityDpi, surface, flags);
        } catch (RemoteException ex) {
            Log.e(TAG, "Could not create virtual display: " + name, ex);
            return null;
        }
        if (displayId < 0) {
            Log.e(TAG, "Could not create virtual display: " + name);
            return null;
        }
        Display display = getRealDisplay(displayId);
        if (display == null) {
            Log.wtf(TAG, "Could not obtain display info for newly created "
                    + "virtual display: " + name);
            try {
                mDm.releaseVirtualDisplay(callbackWrapper);
            } catch (RemoteException ex) {
            }
            return null;
        }
        return new VirtualDisplay(this, display, callbackWrapper, surface);
    
public voiddisconnectWifiDisplay()

        try {
            mDm.disconnectWifiDisplay();
        } catch (RemoteException ex) {
            Log.e(TAG, "Failed to disconnect from Wifi display.", ex);
        }
    
private intfindDisplayListenerLocked(android.hardware.display.DisplayManager.DisplayListener listener)

        final int numListeners = mDisplayListeners.size();
        for (int i = 0; i < numListeners; i++) {
            if (mDisplayListeners.get(i).mListener == listener) {
                return i;
            }
        }
        return -1;
    
public voidforgetWifiDisplay(java.lang.String deviceAddress)

        if (deviceAddress == null) {
            throw new IllegalArgumentException("deviceAddress must not be null");
        }

        try {
            mDm.forgetWifiDisplay(deviceAddress);
        } catch (RemoteException ex) {
            Log.e(TAG, "Failed to forget Wifi display.", ex);
        }
    
public android.view.DisplaygetCompatibleDisplay(int displayId, android.view.DisplayAdjustments daj)
Gets information about a logical display. The display metrics may be adjusted to provide compatibility for legacy applications or limited screen areas.

param
displayId The logical display id.
param
daj The compatibility info and activityToken.
return
The display object, or null if there is no display with the given id.

        DisplayInfo displayInfo = getDisplayInfo(displayId);
        if (displayInfo == null) {
            return null;
        }
        return new Display(this, displayId, displayInfo, daj);
    
public int[]getDisplayIds()
Gets all currently valid logical display ids.

return
An array containing all display ids.

        try {
            synchronized (mLock) {
                if (USE_CACHE) {
                    if (mDisplayIdCache != null) {
                        return mDisplayIdCache;
                    }
                }

                int[] displayIds = mDm.getDisplayIds();
                if (USE_CACHE) {
                    mDisplayIdCache = displayIds;
                }
                registerCallbackIfNeededLocked();
                return displayIds;
            }
        } catch (RemoteException ex) {
            Log.e(TAG, "Could not get display ids from display manager.", ex);
            return new int[] { Display.DEFAULT_DISPLAY };
        }
    
public android.view.DisplayInfogetDisplayInfo(int displayId)
Get information about a particular logical display.

param
displayId The logical display id.
return
Information about the specified display, or null if it does not exist. This object belongs to an internal cache and should be treated as if it were immutable.

        try {
            synchronized (mLock) {
                DisplayInfo info;
                if (USE_CACHE) {
                    info = mDisplayInfoCache.get(displayId);
                    if (info != null) {
                        return info;
                    }
                }

                info = mDm.getDisplayInfo(displayId);
                if (info == null) {
                    return null;
                }

                if (USE_CACHE) {
                    mDisplayInfoCache.put(displayId, info);
                }
                registerCallbackIfNeededLocked();

                if (DEBUG) {
                    Log.d(TAG, "getDisplayInfo: displayId=" + displayId + ", info=" + info);
                }
                return info;
            }
        } catch (RemoteException ex) {
            Log.e(TAG, "Could not get display information from display manager.", ex);
            return null;
        }
    
public static android.hardware.display.DisplayManagerGlobalgetInstance()
Gets an instance of the display manager global singleton.

return
The display manager instance, may be null early in system startup before the display manager has been fully initialized.

        synchronized (DisplayManagerGlobal.class) {
            if (sInstance == null) {
                IBinder b = ServiceManager.getService(Context.DISPLAY_SERVICE);
                if (b != null) {
                    sInstance = new DisplayManagerGlobal(IDisplayManager.Stub.asInterface(b));
                }
            }
            return sInstance;
        }
    
public android.view.DisplaygetRealDisplay(int displayId)
Gets information about a logical display without applying any compatibility metrics.

param
displayId The logical display id.
return
The display object, or null if there is no display with the given id.

        return getCompatibleDisplay(displayId, DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS);
    
public android.view.DisplaygetRealDisplay(int displayId, android.os.IBinder token)
Gets information about a logical display without applying any compatibility metrics.

param
displayId The logical display id.
param
IBinder the activity token for this display.
return
The display object, or null if there is no display with the given id.

        return getCompatibleDisplay(displayId, new DisplayAdjustments(token));
    
public WifiDisplayStatusgetWifiDisplayStatus()

        try {
            return mDm.getWifiDisplayStatus();
        } catch (RemoteException ex) {
            Log.e(TAG, "Failed to get Wifi display status.", ex);
            return new WifiDisplayStatus();
        }
    
private voidhandleDisplayEvent(int displayId, int event)

        synchronized (mLock) {
            if (USE_CACHE) {
                mDisplayInfoCache.remove(displayId);

                if (event == EVENT_DISPLAY_ADDED || event == EVENT_DISPLAY_REMOVED) {
                    mDisplayIdCache = null;
                }
            }

            final int numListeners = mDisplayListeners.size();
            for (int i = 0; i < numListeners; i++) {
                mDisplayListeners.get(i).sendDisplayEvent(displayId, event);
            }
        }
    
public voidpauseWifiDisplay()

        try {
            mDm.pauseWifiDisplay();
        } catch (RemoteException ex) {
            Log.e(TAG, "Failed to pause Wifi display.", ex);
        }
    
private voidregisterCallbackIfNeededLocked()

        if (mCallback == null) {
            mCallback = new DisplayManagerCallback();
            try {
                mDm.registerCallback(mCallback);
            } catch (RemoteException ex) {
                Log.e(TAG, "Failed to register callback with display manager service.", ex);
                mCallback = null;
            }
        }
    
public voidregisterDisplayListener(android.hardware.display.DisplayManager.DisplayListener listener, android.os.Handler handler)

        if (listener == null) {
            throw new IllegalArgumentException("listener must not be null");
        }

        synchronized (mLock) {
            int index = findDisplayListenerLocked(listener);
            if (index < 0) {
                mDisplayListeners.add(new DisplayListenerDelegate(listener, handler));
                registerCallbackIfNeededLocked();
            }
        }
    
public voidreleaseVirtualDisplay(IVirtualDisplayCallback token)

        try {
            mDm.releaseVirtualDisplay(token);
        } catch (RemoteException ex) {
            Log.w(TAG, "Failed to release virtual display.", ex);
        }
    
public voidrenameWifiDisplay(java.lang.String deviceAddress, java.lang.String alias)

        if (deviceAddress == null) {
            throw new IllegalArgumentException("deviceAddress must not be null");
        }

        try {
            mDm.renameWifiDisplay(deviceAddress, alias);
        } catch (RemoteException ex) {
            Log.e(TAG, "Failed to rename Wifi display " + deviceAddress
                    + " with alias " + alias + ".", ex);
        }
    
public voidresizeVirtualDisplay(IVirtualDisplayCallback token, int width, int height, int densityDpi)

        try {
            mDm.resizeVirtualDisplay(token, width, height, densityDpi);
        } catch (RemoteException ex) {
            Log.w(TAG, "Failed to resize virtual display.", ex);
        }
    
public voidresumeWifiDisplay()

        try {
            mDm.resumeWifiDisplay();
        } catch (RemoteException ex) {
            Log.e(TAG, "Failed to resume Wifi display.", ex);
        }
    
public voidsetVirtualDisplaySurface(IVirtualDisplayCallback token, android.view.Surface surface)

        try {
            mDm.setVirtualDisplaySurface(token, surface);
        } catch (RemoteException ex) {
            Log.w(TAG, "Failed to set virtual display surface.", ex);
        }
    
public voidstartWifiDisplayScan()

        synchronized (mLock) {
            if (mWifiDisplayScanNestCount++ == 0) {
                registerCallbackIfNeededLocked();
                try {
                    mDm.startWifiDisplayScan();
                } catch (RemoteException ex) {
                    Log.e(TAG, "Failed to scan for Wifi displays.", ex);
                }
            }
        }
    
public voidstopWifiDisplayScan()

        synchronized (mLock) {
            if (--mWifiDisplayScanNestCount == 0) {
                try {
                    mDm.stopWifiDisplayScan();
                } catch (RemoteException ex) {
                    Log.e(TAG, "Failed to scan for Wifi displays.", ex);
                }
            } else if (mWifiDisplayScanNestCount < 0) {
                Log.wtf(TAG, "Wifi display scan nest count became negative: "
                        + mWifiDisplayScanNestCount);
                mWifiDisplayScanNestCount = 0;
            }
        }
    
public voidunregisterDisplayListener(android.hardware.display.DisplayManager.DisplayListener listener)

        if (listener == null) {
            throw new IllegalArgumentException("listener must not be null");
        }

        synchronized (mLock) {
            int index = findDisplayListenerLocked(listener);
            if (index >= 0) {
                DisplayListenerDelegate d = mDisplayListeners.get(index);
                d.clearEvents();
                mDisplayListeners.remove(index);
            }
        }