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

OverlayDisplayAdapter

public final class OverlayDisplayAdapter extends DisplayAdapter
A display adapter that uses overlay windows to simulate secondary displays for development purposes. Use Development Settings to enable one or more overlay displays.

This object has two different handlers (which may be the same) which must not get confused. The main handler is used to posting messages to the display manager service as usual. The UI handler is only used by the {@link OverlayDisplayWindow}.

Display adapters are guarded by the {@link DisplayManagerService.SyncRoot} lock.

Fields Summary
static final String
TAG
static final boolean
DEBUG
private static final int
MIN_WIDTH
private static final int
MIN_HEIGHT
private static final int
MAX_WIDTH
private static final int
MAX_HEIGHT
private static final Pattern
SETTING_PATTERN
private static final String
UNIQUE_ID_PREFIX
private final android.os.Handler
mUiHandler
private final ArrayList
mOverlays
private String
mCurrentOverlaySetting
Constructors Summary
public OverlayDisplayAdapter(DisplayManagerService.SyncRoot syncRoot, android.content.Context context, android.os.Handler handler, Listener listener, android.os.Handler uiHandler)


    // Called with SyncRoot lock held.
      
                    
        super(syncRoot, context, handler, listener, TAG);
        mUiHandler = uiHandler;
    
Methods Summary
private static intchooseOverlayGravity(int overlayNumber)

        switch (overlayNumber) {
            case 1:
                return Gravity.TOP | Gravity.LEFT;
            case 2:
                return Gravity.BOTTOM | Gravity.RIGHT;
            case 3:
                return Gravity.TOP | Gravity.RIGHT;
            case 4:
            default:
                return Gravity.BOTTOM | Gravity.LEFT;
        }
    
public voiddumpLocked(java.io.PrintWriter pw)

        super.dumpLocked(pw);

        pw.println("mCurrentOverlaySetting=" + mCurrentOverlaySetting);
        pw.println("mOverlays: size=" + mOverlays.size());
        for (OverlayDisplayHandle overlay : mOverlays) {
            overlay.dumpLocked(pw);
        }
    
public voidregisterLocked()

        super.registerLocked();

        getHandler().post(new Runnable() {
            @Override
            public void run() {
                getContext().getContentResolver().registerContentObserver(
                        Settings.Global.getUriFor(Settings.Global.OVERLAY_DISPLAY_DEVICES),
                        true, new ContentObserver(getHandler()) {
                            @Override
                            public void onChange(boolean selfChange) {
                                updateOverlayDisplayDevices();
                            }
                        });

                updateOverlayDisplayDevices();
            }
        });
    
private voidupdateOverlayDisplayDevices()

        synchronized (getSyncRoot()) {
            updateOverlayDisplayDevicesLocked();
        }
    
private voidupdateOverlayDisplayDevicesLocked()

        String value = Settings.Global.getString(getContext().getContentResolver(),
                Settings.Global.OVERLAY_DISPLAY_DEVICES);
        if (value == null) {
            value = "";
        }

        if (value.equals(mCurrentOverlaySetting)) {
            return;
        }
        mCurrentOverlaySetting = value;

        if (!mOverlays.isEmpty()) {
            Slog.i(TAG, "Dismissing all overlay display devices.");
            for (OverlayDisplayHandle overlay : mOverlays) {
                overlay.dismissLocked();
            }
            mOverlays.clear();
        }

        int count = 0;
        for (String part : value.split(";")) {
            Matcher matcher = SETTING_PATTERN.matcher(part);
            if (matcher.matches()) {
                if (count >= 4) {
                    Slog.w(TAG, "Too many overlay display devices specified: " + value);
                    break;
                }
                try {
                    int width = Integer.parseInt(matcher.group(1), 10);
                    int height = Integer.parseInt(matcher.group(2), 10);
                    int densityDpi = Integer.parseInt(matcher.group(3), 10);
                    String flagString = matcher.group(4);
                    if (width >= MIN_WIDTH && width <= MAX_WIDTH
                            && height >= MIN_HEIGHT && height <= MAX_HEIGHT
                            && densityDpi >= DisplayMetrics.DENSITY_LOW
                            && densityDpi <= DisplayMetrics.DENSITY_XXHIGH) {
                        int number = ++count;
                        String name = getContext().getResources().getString(
                                com.android.internal.R.string.display_manager_overlay_display_name,
                                number);
                        int gravity = chooseOverlayGravity(number);
                        boolean secure = flagString != null && flagString.contains(",secure");

                        Slog.i(TAG, "Showing overlay display device #" + number
                                + ": name=" + name + ", width=" + width + ", height=" + height
                                + ", densityDpi=" + densityDpi + ", secure=" + secure);

                        mOverlays.add(new OverlayDisplayHandle(name,
                                width, height, densityDpi, gravity, secure, number));
                        continue;
                    }
                } catch (NumberFormatException ex) {
                }
            } else if (part.isEmpty()) {
                continue;
            }
            Slog.w(TAG, "Malformed overlay display devices setting: " + value);
        }