Skip to content

Commit 1202c43

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Secure windows, secure surface views and secure displays." into jb-mr1-dev
2 parents 8e080d7 + f0681b3 commit 1202c43

File tree

9 files changed

+99
-17
lines changed

9 files changed

+99
-17
lines changed

api/17.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23742,6 +23742,7 @@ package android.view {
2374223742
method public deprecated int getWidth();
2374323743
method public boolean isValid();
2374423744
field public static final int DEFAULT_DISPLAY = 0; // 0x0
23745+
field public static final int FLAG_SECURE = 2; // 0x2
2374523746
field public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1; // 0x1
2374623747
}
2374723748

@@ -24788,6 +24789,7 @@ package android.view {
2478824789
ctor public SurfaceView(android.content.Context, android.util.AttributeSet, int);
2478924790
method public boolean gatherTransparentRegion(android.graphics.Region);
2479024791
method public android.view.SurfaceHolder getHolder();
24792+
method public void setSecure(boolean);
2479124793
method public void setZOrderMediaOverlay(boolean);
2479224794
method public void setZOrderOnTop(boolean);
2479324795
}

api/current.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23742,6 +23742,7 @@ package android.view {
2374223742
method public deprecated int getWidth();
2374323743
method public boolean isValid();
2374423744
field public static final int DEFAULT_DISPLAY = 0; // 0x0
23745+
field public static final int FLAG_SECURE = 2; // 0x2
2374523746
field public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1; // 0x1
2374623747
}
2374723748

@@ -24788,6 +24789,7 @@ package android.view {
2478824789
ctor public SurfaceView(android.content.Context, android.util.AttributeSet, int);
2478924790
method public boolean gatherTransparentRegion(android.graphics.Region);
2479024791
method public android.view.SurfaceHolder getHolder();
24792+
method public void setSecure(boolean);
2479124793
method public void setZOrderMediaOverlay(boolean);
2479224794
method public void setZOrderOnTop(boolean);
2479324795
}

core/java/android/view/Display.java

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,64 @@ public final class Display {
8282
* Display flag: Indicates that the display supports compositing content
8383
* that is stored in protected graphics buffers.
8484
* <p>
85+
* If this flag is set then the display device supports compositing protected buffers.
86+
* </p><p>
87+
* If this flag is not set then the display device may not support compositing
88+
* protected buffers; the user may see a blank region on the screen instead of
89+
* the protected content.
90+
* </p><p>
8591
* Secure (DRM) video decoders may allocate protected graphics buffers to request that
8692
* a hardware-protected path be provided between the video decoder and the external
8793
* display sink. If a hardware-protected path is not available, then content stored
8894
* in protected graphics buffers may not be composited.
8995
* </p><p>
90-
* If this flag is not set, then the display device does not support compositing
91-
* protected buffers; the user may see a blank region on the screen instead of
92-
* the protected content. An application can use this flag as a hint that it should
93-
* select an alternate content stream or adopt a different strategy for decoding
94-
* content that does not rely on protected buffers so as to ensure that the user
95-
* can view the content on the display as expected.
96+
* An application can use the absence of this flag as a hint that it should not use protected
97+
* buffers for this display because the content may not be visible. For example,
98+
* if the flag is not set then the application may choose not to show content on this
99+
* display, show an informative error message, select an alternate content stream
100+
* or adopt a different strategy for decoding content that does not rely on
101+
* protected buffers.
96102
* </p>
103+
*
104+
* @see #getFlags
97105
*/
98106
public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1 << 0;
99107

108+
/**
109+
* Display flag: Indicates that the display has a secure video output and
110+
* supports compositing secure surfaces.
111+
* <p>
112+
* If this flag is set then the display device has a secure video output
113+
* and is capable of showing secure surfaces. It may also be capable of
114+
* showing {@link #FLAG_SUPPORTS_PROTECTED_BUFFERS protected buffers}.
115+
* </p><p>
116+
* If this flag is not set then the display device may not have a secure video
117+
* output; the user may see a blank region on the screen instead of
118+
* the contents of secure surfaces or protected buffers.
119+
* </p><p>
120+
* Secure surfaces are used to prevent content rendered into those surfaces
121+
* by applications from appearing in screenshots or from being viewed
122+
* on non-secure displays. Protected buffers are used by secure video decoders
123+
* for a similar purpose.
124+
* </p><p>
125+
* An application creates a window with a secure surface by specifying the
126+
* {@link WindowManager.LayoutParams#FLAG_SECURE} window flag.
127+
* Likewise, an application creates a {@link SurfaceView} with a secure surface
128+
* by calling {@link SurfaceView#setSecure} before attaching the secure view to
129+
* its containing window.
130+
* </p><p>
131+
* An application can use the absence of this flag as a hint that it should not create
132+
* secure surfaces or protected buffers on this display because the content may
133+
* not be visible. For example, if the flag is not set then the application may
134+
* choose not to show content on this display, show an informative error message,
135+
* select an alternate content stream or adopt a different strategy for decoding
136+
* content that does not rely on secure surfaces or protected buffers.
137+
* </p>
138+
*
139+
* @see #getFlags
140+
*/
141+
public static final int FLAG_SECURE = 1 << 1;
142+
100143
/**
101144
* Internal method to create a display.
102145
* Applications should use {@link android.view.WindowManager#getDefaultDisplay()}
@@ -182,6 +225,7 @@ public int getLayerStack() {
182225
* @return The display flags.
183226
*
184227
* @see #FLAG_SUPPORTS_PROTECTED_BUFFERS
228+
* @see #FLAG_SECURE
185229
*/
186230
public int getFlags() {
187231
synchronized (this) {

core/java/android/view/DisplayInfo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ public String toString() {
299299

300300
private static String flagsToString(int flags) {
301301
StringBuilder result = new StringBuilder();
302+
if ((flags & Display.FLAG_SECURE) != 0) {
303+
result.append(", FLAG_SECURE");
304+
}
302305
if ((flags & Display.FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) {
303306
result.append(", FLAG_SUPPORTS_PROTECTED_BUFFERS");
304307
}

core/java/android/view/SurfaceView.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,27 @@ public void setZOrderOnTop(boolean onTop) {
385385
mLayout.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
386386
}
387387
}
388-
388+
389+
/**
390+
* Control whether the surface view's content should be treated as secure,
391+
* preventing it from appearing in screenshots or from being viewed on
392+
* non-secure displays.
393+
*
394+
* <p>Note that this must be set before the surface view's containing
395+
* window is attached to the window manager.
396+
*
397+
* <p>See {@link android.view.Display#FLAG_SECURE} for details.
398+
*
399+
* @param isSecure True if the surface view is secure.
400+
*/
401+
public void setSecure(boolean isSecure) {
402+
if (isSecure) {
403+
mLayout.flags |= WindowManager.LayoutParams.FLAG_SECURE;
404+
} else {
405+
mLayout.flags &= ~WindowManager.LayoutParams.FLAG_SECURE;
406+
}
407+
}
408+
389409
/**
390410
* Hack to allow special layering of windows. The type is one of the
391411
* types in WindowManager.LayoutParams. This is a hack so:

core/java/android/view/WindowManager.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,13 @@ public static class LayoutParams extends ViewGroup.LayoutParams
628628
@Deprecated
629629
public static final int FLAG_DITHER = 0x00001000;
630630

631-
/** Window flag: don't allow screen shots while this window is
632-
* displayed. Maps to Surface.SECURE. */
631+
/** Window flag: Treat the content of the window as secure, preventing
632+
* it from appearing in screenshots or from being viewed on non-secure
633+
* displays.
634+
*
635+
* <p>See {@link android.view.Display#FLAG_SECURE} for more details about
636+
* secure surfaces and secure displays.
637+
*/
633638
public static final int FLAG_SECURE = 0x00002000;
634639

635640
/** Window flag: a special mode where the layout parameters are used

services/java/com/android/server/display/LocalDisplayAdapter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,12 @@ public DisplayDeviceInfo getDisplayDeviceInfoLocked() {
127127
mInfo.height = mPhys.height;
128128
mInfo.refreshRate = mPhys.refreshRate;
129129

130-
// Assume that all built-in displays have secure output (eg. HDCP) and
130+
// Assume that all built-in displays that have secure output (eg. HDCP) also
131131
// support compositing from gralloc protected buffers.
132-
mInfo.flags = DisplayDeviceInfo.FLAG_SECURE
133-
| DisplayDeviceInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS;
132+
if (mPhys.secure) {
133+
mInfo.flags = DisplayDeviceInfo.FLAG_SECURE
134+
| DisplayDeviceInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS;
135+
}
134136

135137
if (mBuiltInDisplayId == Surface.BUILT_IN_DISPLAY_ID_MAIN) {
136138
mInfo.name = getContext().getResources().getString(

services/java/com/android/server/display/LogicalDisplay.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ public void updateLocked(List<DisplayDevice> devices) {
186186
if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) {
187187
mBaseDisplayInfo.flags |= Display.FLAG_SUPPORTS_PROTECTED_BUFFERS;
188188
}
189+
if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_SECURE) != 0) {
190+
mBaseDisplayInfo.flags |= Display.FLAG_SECURE;
191+
}
189192
mBaseDisplayInfo.name = deviceInfo.name;
190193
mBaseDisplayInfo.appWidth = deviceInfo.width;
191194
mBaseDisplayInfo.appHeight = deviceInfo.height;

services/java/com/android/server/display/WifiDisplayAdapter.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,19 @@ private void handleConnectLocked(WifiDisplay display,
281281
scheduleStatusChangedBroadcastLocked();
282282
}
283283

284+
boolean secure = (flags & RemoteDisplay.DISPLAY_FLAG_SECURE) != 0;
284285
int deviceFlags = 0;
285-
if ((flags & RemoteDisplay.DISPLAY_FLAG_SECURE) != 0) {
286+
if (secure) {
286287
deviceFlags |= DisplayDeviceInfo.FLAG_SECURE;
287-
}
288-
if (mSupportsProtectedBuffers) {
289-
deviceFlags |= DisplayDeviceInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS;
288+
if (mSupportsProtectedBuffers) {
289+
deviceFlags |= DisplayDeviceInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS;
290+
}
290291
}
291292

292293
float refreshRate = 60.0f; // TODO: get this for real
293294

294295
String name = display.getFriendlyDisplayName();
295-
IBinder displayToken = Surface.createDisplay(name, false);
296+
IBinder displayToken = Surface.createDisplay(name, secure);
296297
mDisplayDevice = new WifiDisplayDevice(displayToken, name, width, height,
297298
refreshRate, deviceFlags, surface);
298299
sendDisplayDeviceEventLocked(mDisplayDevice, DISPLAY_DEVICE_EVENT_ADDED);

0 commit comments

Comments
 (0)