diff options
| author | Wale Ogunwale <ogunwale@google.com> | 2014-12-01 20:26:05 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-12-01 20:26:06 +0000 |
| commit | 997e632f59b070dabf71d9e807847c0643da92ac (patch) | |
| tree | aa3acb4a9013709045a870342c39991e91d1e01a | |
| parent | 089f95f4483c95873cf0084c11cb23a0f5b32c3c (diff) | |
| parent | 361ca21acc0831a9f8bbb259bb30218c252a2aa0 (diff) | |
| download | frameworks_base-997e632f59b070dabf71d9e807847c0643da92ac.zip frameworks_base-997e632f59b070dabf71d9e807847c0643da92ac.tar.gz frameworks_base-997e632f59b070dabf71d9e807847c0643da92ac.tar.bz2 | |
Merge "Added unique id to display devices and their settings." into lmp-mr1-dev
10 files changed, 105 insertions, 26 deletions
diff --git a/core/java/android/view/DisplayInfo.java b/core/java/android/view/DisplayInfo.java index 56a05fe..9feb681 100644 --- a/core/java/android/view/DisplayInfo.java +++ b/core/java/android/view/DisplayInfo.java @@ -59,6 +59,11 @@ public final class DisplayInfo implements Parcelable { public String name; /** + * Unique identifier for the display. Shouldn't be displayed to the user. + */ + public String uniqueId; + + /** * The width of the portion of the display that is available to applications, in pixels. * Represents the size of the display minus any system decorations. */ @@ -257,7 +262,7 @@ public final class DisplayInfo implements Parcelable { && flags == other.flags && type == other.type && Objects.equal(address, other.address) - && Objects.equal(name, other.name) + && Objects.equal(uniqueId, other.uniqueId) && appWidth == other.appWidth && appHeight == other.appHeight && smallestNominalAppWidth == other.smallestNominalAppWidth @@ -293,6 +298,7 @@ public final class DisplayInfo implements Parcelable { type = other.type; address = other.address; name = other.name; + uniqueId = other.uniqueId; appWidth = other.appWidth; appHeight = other.appHeight; smallestNominalAppWidth = other.smallestNominalAppWidth; @@ -348,6 +354,7 @@ public final class DisplayInfo implements Parcelable { state = source.readInt(); ownerUid = source.readInt(); ownerPackageName = source.readString(); + uniqueId = source.readString(); } @Override @@ -380,6 +387,7 @@ public final class DisplayInfo implements Parcelable { dest.writeInt(state); dest.writeInt(ownerUid); dest.writeString(ownerPackageName); + dest.writeString(uniqueId); } @Override @@ -445,6 +453,8 @@ public final class DisplayInfo implements Parcelable { StringBuilder sb = new StringBuilder(); sb.append("DisplayInfo{\""); sb.append(name); + sb.append("\", uniqueId \""); + sb.append(uniqueId); sb.append("\", app "); sb.append(appWidth); sb.append(" x "); diff --git a/services/core/java/com/android/server/display/DisplayDevice.java b/services/core/java/com/android/server/display/DisplayDevice.java index 683212a..61631d4 100644 --- a/services/core/java/com/android/server/display/DisplayDevice.java +++ b/services/core/java/com/android/server/display/DisplayDevice.java @@ -34,6 +34,7 @@ import java.io.PrintWriter; abstract class DisplayDevice { private final DisplayAdapter mDisplayAdapter; private final IBinder mDisplayToken; + private final String mUniqueId; // The display device does not manage these properties itself, they are set by // the display manager service. The display device shouldn't really be looking at these. @@ -46,9 +47,10 @@ abstract class DisplayDevice { // within a transaction from performTraversalInTransactionLocked. private Surface mCurrentSurface; - public DisplayDevice(DisplayAdapter displayAdapter, IBinder displayToken) { + public DisplayDevice(DisplayAdapter displayAdapter, IBinder displayToken, String uniqueId) { mDisplayAdapter = displayAdapter; mDisplayToken = displayToken; + mUniqueId = uniqueId; } /** @@ -80,6 +82,13 @@ abstract class DisplayDevice { } /** + * Returns the unique id of the display device. + */ + public final String getUniqueId() { + return mUniqueId; + } + + /** * Gets information about the display device. * * The information returned should not change between calls unless the display @@ -208,6 +217,7 @@ abstract class DisplayDevice { */ public void dumpLocked(PrintWriter pw) { pw.println("mAdapter=" + mDisplayAdapter.getName()); + pw.println("mUniqueId=" + mUniqueId); pw.println("mDisplayToken=" + mDisplayToken); pw.println("mCurrentLayerStack=" + mCurrentLayerStack); pw.println("mCurrentOrientation=" + mCurrentOrientation); diff --git a/services/core/java/com/android/server/display/DisplayDeviceInfo.java b/services/core/java/com/android/server/display/DisplayDeviceInfo.java index f48428a..d1e73f0 100644 --- a/services/core/java/com/android/server/display/DisplayDeviceInfo.java +++ b/services/core/java/com/android/server/display/DisplayDeviceInfo.java @@ -104,12 +104,17 @@ final class DisplayDeviceInfo { public static final int TOUCH_EXTERNAL = 2; /** - * Gets the name of the display device, which may be derived from - * EDID or other sources. The name may be displayed to the user. + * Gets the name of the display device, which may be derived from EDID or + * other sources. The name may be localized and displayed to the user. */ public String name; /** + * Unique Id of display device. + */ + public String uniqueId; + + /** * The width of the display in its natural orientation, in pixels. * This value is not affected by display rotation. */ @@ -235,6 +240,7 @@ final class DisplayDeviceInfo { public boolean equals(DisplayDeviceInfo other) { return other != null && Objects.equal(name, other.name) + && Objects.equal(uniqueId, other.uniqueId) && width == other.width && height == other.height && refreshRate == other.refreshRate @@ -261,6 +267,7 @@ final class DisplayDeviceInfo { public void copyFrom(DisplayDeviceInfo other) { name = other.name; + uniqueId = other.uniqueId; width = other.width; height = other.height; refreshRate = other.refreshRate; @@ -285,7 +292,8 @@ final class DisplayDeviceInfo { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("DisplayDeviceInfo{\""); - sb.append(name).append("\": ").append(width).append(" x ").append(height); + sb.append(name).append("\": uniqueId=\"").append(uniqueId).append("\", "); + sb.append(width).append(" x ").append(height); sb.append(", ").append(refreshRate).append(" fps"); sb.append(", supportedRefreshRates ").append(Arrays.toString(supportedRefreshRates)); sb.append(", density ").append(densityDpi); diff --git a/services/core/java/com/android/server/display/LocalDisplayAdapter.java b/services/core/java/com/android/server/display/LocalDisplayAdapter.java index 24cf423..5ebe64d 100644 --- a/services/core/java/com/android/server/display/LocalDisplayAdapter.java +++ b/services/core/java/com/android/server/display/LocalDisplayAdapter.java @@ -41,6 +41,8 @@ import java.util.Arrays; final class LocalDisplayAdapter extends DisplayAdapter { private static final String TAG = "LocalDisplayAdapter"; + private static final String UNIQUE_ID_PREFIX = "local:"; + private static final int[] BUILT_IN_DISPLAY_IDS_TO_SCAN = new int[] { SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN, SurfaceControl.BUILT_IN_DISPLAY_ID_HDMI, @@ -140,7 +142,7 @@ final class LocalDisplayAdapter extends DisplayAdapter { public LocalDisplayDevice(IBinder displayToken, int builtInDisplayId, SurfaceControl.PhysicalDisplayInfo[] physicalDisplayInfos, int activeDisplayInfo) { - super(LocalDisplayAdapter.this, displayToken); + super(LocalDisplayAdapter.this, displayToken, UNIQUE_ID_PREFIX + builtInDisplayId); mBuiltInDisplayId = builtInDisplayId; mPhys = new SurfaceControl.PhysicalDisplayInfo( physicalDisplayInfos[activeDisplayInfo]); @@ -179,6 +181,7 @@ final class LocalDisplayAdapter extends DisplayAdapter { mInfo.appVsyncOffsetNanos = mPhys.appVsyncOffsetNanos; mInfo.presentationDeadlineNanos = mPhys.presentationDeadlineNanos; mInfo.state = mState; + mInfo.uniqueId = getUniqueId(); // Assume that all built-in displays that have secure output (eg. HDCP) also // support compositing from gralloc protected buffers. diff --git a/services/core/java/com/android/server/display/LogicalDisplay.java b/services/core/java/com/android/server/display/LogicalDisplay.java index 00ff1cf..6c57eec 100644 --- a/services/core/java/com/android/server/display/LogicalDisplay.java +++ b/services/core/java/com/android/server/display/LogicalDisplay.java @@ -118,6 +118,7 @@ final class LogicalDisplay { mInfo.copyFrom(mOverrideDisplayInfo); mInfo.layerStack = mBaseDisplayInfo.layerStack; mInfo.name = mBaseDisplayInfo.name; + mInfo.uniqueId = mBaseDisplayInfo.uniqueId; mInfo.state = mBaseDisplayInfo.state; } else { mInfo.copyFrom(mBaseDisplayInfo); @@ -208,6 +209,7 @@ final class LogicalDisplay { mBaseDisplayInfo.type = deviceInfo.type; mBaseDisplayInfo.address = deviceInfo.address; mBaseDisplayInfo.name = deviceInfo.name; + mBaseDisplayInfo.uniqueId = deviceInfo.uniqueId; mBaseDisplayInfo.appWidth = deviceInfo.width; mBaseDisplayInfo.appHeight = deviceInfo.height; mBaseDisplayInfo.logicalWidth = deviceInfo.width; diff --git a/services/core/java/com/android/server/display/OverlayDisplayAdapter.java b/services/core/java/com/android/server/display/OverlayDisplayAdapter.java index f514531..5b6f35b 100644 --- a/services/core/java/com/android/server/display/OverlayDisplayAdapter.java +++ b/services/core/java/com/android/server/display/OverlayDisplayAdapter.java @@ -61,6 +61,9 @@ final class OverlayDisplayAdapter extends DisplayAdapter { private static final Pattern SETTING_PATTERN = Pattern.compile("(\\d+)x(\\d+)/(\\d+)(,[a-z]+)*"); + // Unique id prefix for overlay displays. + private static final String UNIQUE_ID_PREFIX = "overlay:"; + private final Handler mUiHandler; private final ArrayList<OverlayDisplayHandle> mOverlays = new ArrayList<OverlayDisplayHandle>(); @@ -160,7 +163,7 @@ final class OverlayDisplayAdapter extends DisplayAdapter { + ", densityDpi=" + densityDpi + ", secure=" + secure); mOverlays.add(new OverlayDisplayHandle(name, - width, height, densityDpi, gravity, secure)); + width, height, densityDpi, gravity, secure, number)); continue; } } catch (NumberFormatException ex) { @@ -203,8 +206,8 @@ final class OverlayDisplayAdapter extends DisplayAdapter { public OverlayDisplayDevice(IBinder displayToken, String name, int width, int height, float refreshRate, long presentationDeadlineNanos, int densityDpi, boolean secure, int state, - SurfaceTexture surfaceTexture) { - super(OverlayDisplayAdapter.this, displayToken); + SurfaceTexture surfaceTexture, int number) { + super(OverlayDisplayAdapter.this, displayToken, UNIQUE_ID_PREFIX + number); mName = name; mWidth = width; mHeight = height; @@ -245,6 +248,7 @@ final class OverlayDisplayAdapter extends DisplayAdapter { if (mInfo == null) { mInfo = new DisplayDeviceInfo(); mInfo.name = mName; + mInfo.uniqueId = getUniqueId(); mInfo.width = mWidth; mInfo.height = mHeight; mInfo.refreshRate = mRefreshRate; @@ -279,18 +283,20 @@ final class OverlayDisplayAdapter extends DisplayAdapter { private final int mDensityDpi; private final int mGravity; private final boolean mSecure; + private final int mNumber; private OverlayDisplayWindow mWindow; private OverlayDisplayDevice mDevice; - public OverlayDisplayHandle(String name, - int width, int height, int densityDpi, int gravity, boolean secure) { + public OverlayDisplayHandle(String name, int width, + int height, int densityDpi, int gravity, boolean secure, int number) { mName = name; mWidth = width; mHeight = height; mDensityDpi = densityDpi; mGravity = gravity; mSecure = secure; + mNumber = number; mUiHandler.post(mShowRunnable); } @@ -308,7 +314,7 @@ final class OverlayDisplayAdapter extends DisplayAdapter { IBinder displayToken = SurfaceControl.createDisplay(mName, mSecure); mDevice = new OverlayDisplayDevice(displayToken, mName, mWidth, mHeight, refreshRate, presentationDeadlineNanos, - mDensityDpi, mSecure, state, surfaceTexture); + mDensityDpi, mSecure, state, surfaceTexture, mNumber); sendDisplayDeviceEventLocked(mDevice, DISPLAY_DEVICE_EVENT_ADDED); } @@ -343,6 +349,7 @@ final class OverlayDisplayAdapter extends DisplayAdapter { pw.println(" mDensityDpi=" + mDensityDpi); pw.println(" mGravity=" + mGravity); pw.println(" mSecure=" + mSecure); + pw.println(" mNumber=" + mNumber); // Try to dump the window state. if (mWindow != null) { diff --git a/services/core/java/com/android/server/display/VirtualDisplayAdapter.java b/services/core/java/com/android/server/display/VirtualDisplayAdapter.java index 28d5fc0..f181cd5 100644 --- a/services/core/java/com/android/server/display/VirtualDisplayAdapter.java +++ b/services/core/java/com/android/server/display/VirtualDisplayAdapter.java @@ -34,6 +34,7 @@ import android.view.Surface; import android.view.SurfaceControl; import java.io.PrintWriter; +import java.util.Iterator; /** * A display adapter that provides virtual displays on behalf of applications. @@ -45,6 +46,9 @@ final class VirtualDisplayAdapter extends DisplayAdapter { static final String TAG = "VirtualDisplayAdapter"; static final boolean DEBUG = false; + // Unique id prefix for virtual displays + private static final String UNIQUE_ID_PREFIX = "virtual:"; + private final ArrayMap<IBinder, VirtualDisplayDevice> mVirtualDisplayDevices = new ArrayMap<IBinder, VirtualDisplayDevice>(); private Handler mHandler; @@ -62,9 +66,12 @@ final class VirtualDisplayAdapter extends DisplayAdapter { 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)); + new Callback(callback, mHandler), baseUniqueId + uniqueIndex, uniqueIndex); mVirtualDisplayDevices.put(appToken, device); @@ -112,6 +119,29 @@ final class VirtualDisplayAdapter extends DisplayAdapter { return device; } + /** + * Returns the next unique index for the uniqueIdPrefix + */ + private int getNextUniqueIndex(String 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(IBinder appToken) { VirtualDisplayDevice device = mVirtualDisplayDevices.remove(appToken); if (device != null) { @@ -150,12 +180,13 @@ final class VirtualDisplayAdapter extends DisplayAdapter { private int mDisplayState; private boolean mStopped; private int mPendingChanges; + private int mUniqueIndex; public VirtualDisplayDevice(IBinder displayToken, IBinder appToken, int ownerUid, String ownerPackageName, String name, int width, int height, int densityDpi, Surface surface, int flags, - Callback callback) { - super(VirtualDisplayAdapter.this, displayToken); + Callback callback, String uniqueId, int uniqueIndex) { + super(VirtualDisplayAdapter.this, displayToken, uniqueId); mAppToken = appToken; mOwnerUid = ownerUid; mOwnerPackageName = ownerPackageName; @@ -168,6 +199,7 @@ final class VirtualDisplayAdapter extends DisplayAdapter { mCallback = callback; mDisplayState = Display.STATE_UNKNOWN; mPendingChanges |= PENDING_SURFACE_CHANGE; + mUniqueIndex = uniqueIndex; } @Override @@ -255,6 +287,7 @@ final class VirtualDisplayAdapter extends DisplayAdapter { if (mInfo == null) { mInfo = new DisplayDeviceInfo(); mInfo.name = mName; + mInfo.uniqueId = getUniqueId(); mInfo.width = mWidth; mInfo.height = mHeight; mInfo.refreshRate = 60; diff --git a/services/core/java/com/android/server/display/WifiDisplayAdapter.java b/services/core/java/com/android/server/display/WifiDisplayAdapter.java index 6b010d9..c939861 100644 --- a/services/core/java/com/android/server/display/WifiDisplayAdapter.java +++ b/services/core/java/com/android/server/display/WifiDisplayAdapter.java @@ -68,6 +68,9 @@ final class WifiDisplayAdapter extends DisplayAdapter { private static final String ACTION_DISCONNECT = "android.server.display.wfd.DISCONNECT"; + // Unique id prefix for wifi displays + private static final String DISPLAY_NAME_PREFIX = "wifi:"; + private final WifiDisplayHandler mHandler; private final PersistentDataStore mPersistentDataStore; private final boolean mSupportsProtectedBuffers; @@ -587,7 +590,7 @@ final class WifiDisplayAdapter extends DisplayAdapter { public WifiDisplayDevice(IBinder displayToken, String name, int width, int height, float refreshRate, int flags, String address, Surface surface) { - super(WifiDisplayAdapter.this, displayToken); + super(WifiDisplayAdapter.this, displayToken, DISPLAY_NAME_PREFIX + address); mName = name; mWidth = width; mHeight = height; @@ -622,6 +625,7 @@ final class WifiDisplayAdapter extends DisplayAdapter { if (mInfo == null) { mInfo = new DisplayDeviceInfo(); mInfo.name = mName; + mInfo.uniqueId = getUniqueId(); mInfo.width = mWidth; mInfo.height = mHeight; mInfo.refreshRate = mRefreshRate; diff --git a/services/core/java/com/android/server/wm/DisplaySettings.java b/services/core/java/com/android/server/wm/DisplaySettings.java index 34d1a64..ba995f2 100644 --- a/services/core/java/com/android/server/wm/DisplaySettings.java +++ b/services/core/java/com/android/server/wm/DisplaySettings.java @@ -16,7 +16,6 @@ package com.android.server.wm; -import android.content.Context; import android.graphics.Rect; import android.os.Environment; import android.util.AtomicFile; @@ -41,7 +40,6 @@ import java.util.HashMap; public class DisplaySettings { private static final String TAG = WindowManagerService.TAG; - private final Context mContext; private final AtomicFile mFile; private final HashMap<String, Entry> mEntries = new HashMap<String, Entry>(); @@ -57,15 +55,19 @@ public class DisplaySettings { } } - public DisplaySettings(Context context) { - mContext = context; + public DisplaySettings() { File dataDir = Environment.getDataDirectory(); File systemDir = new File(dataDir, "system"); mFile = new AtomicFile(new File(systemDir, "display_settings.xml")); } - public void getOverscanLocked(String name, Rect outRect) { - Entry entry = mEntries.get(name); + public void getOverscanLocked(String name, String uniqueId, Rect outRect) { + // Try to get the entry with the unique if possible. + // Else, fall back on the display name. + Entry entry; + if (uniqueId == null || (entry = mEntries.get(uniqueId)) == null) { + entry = mEntries.get(name); + } if (entry != null) { outRect.left = entry.overscanLeft; outRect.top = entry.overscanTop; @@ -110,7 +112,7 @@ public class DisplaySettings { int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { - ; + // Do nothing. } if (type != XmlPullParser.START_TAG) { diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index bcfd7f0..b628a77 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -825,7 +825,7 @@ public class WindowManagerService extends IWindowManager.Stub com.android.internal.R.bool.config_hasPermanentDpad); mInputManager = inputManager; // Must be before createDisplayContentLocked. mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class); - mDisplaySettings = new DisplaySettings(context); + mDisplaySettings = new DisplaySettings(); mDisplaySettings.readSettingsLocked(); LocalServices.addService(WindowManagerPolicy.class, mPolicy); @@ -8476,7 +8476,7 @@ public class WindowManagerService extends IWindowManager.Stub displayInfo.overscanBottom = bottom; } - mDisplaySettings.setOverscanLocked(displayInfo.name, left, top, right, bottom); + mDisplaySettings.setOverscanLocked(displayInfo.uniqueId, left, top, right, bottom); mDisplaySettings.writeSettingsLocked(); reconfigureDisplayLocked(displayContent); @@ -11458,7 +11458,7 @@ public class WindowManagerService extends IWindowManager.Stub DisplayInfo displayInfo = displayContent.getDisplayInfo(); final Rect rect = new Rect(); - mDisplaySettings.getOverscanLocked(displayInfo.name, rect); + mDisplaySettings.getOverscanLocked(displayInfo.name, displayInfo.uniqueId, rect); synchronized (displayContent.mDisplaySizeLock) { displayInfo.overscanLeft = rect.left; displayInfo.overscanTop = rect.top; |
