From f5ad42f4324bfb7aa28f0967e2fcc89f55d6e91f Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Fri, 12 Jun 2015 13:59:03 -0700 Subject: [PATCH] Update surfaces secure flag on screen capture setting change Also, added 'wm screen-capture [userId] [true|false]' command. Bug: 20934462 Change-Id: I14711003d7691fc4495428c12c9ff3457cd3773c --- cmds/wm/src/com/android/commands/wm/Wm.java | 31 +++++++++++++++++-- core/java/android/view/SurfaceControl.java | 13 ++++++++ .../server/wm/WindowManagerService.java | 10 ++++++ .../server/wm/WindowStateAnimator.java | 21 +++++++++++++ 4 files changed, 72 insertions(+), 3 deletions(-) diff --git a/cmds/wm/src/com/android/commands/wm/Wm.java b/cmds/wm/src/com/android/commands/wm/Wm.java index 64f023f16abf6..fb050e545931f 100644 --- a/cmds/wm/src/com/android/commands/wm/Wm.java +++ b/cmds/wm/src/com/android/commands/wm/Wm.java @@ -54,6 +54,7 @@ public class Wm extends BaseCommand { " wm density [reset|DENSITY]\n" + " wm overscan [reset|LEFT,TOP,RIGHT,BOTTOM]\n" + " wm scaling [off|auto]\n" + + " wm screen-capture [userId] [true|false]\n" + "\n" + "wm size: return or override display size.\n" + " width and height in pixels unless suffixed with 'dp'.\n" + @@ -62,7 +63,9 @@ public class Wm extends BaseCommand { "\n" + "wm overscan: set overscan area for display.\n" + "\n" + - "wm scaling: set display scaling mode.\n" + "wm scaling: set display scaling mode.\n" + + "\n" + + "wm screen-capture: enable/disable screen capture.\n" ); } @@ -85,16 +88,39 @@ public class Wm extends BaseCommand { runDisplayOverscan(); } else if (op.equals("scaling")) { runDisplayScaling(); + } else if (op.equals("screen-capture")) { + runSetScreenCapture(); } else { showError("Error: unknown command '" + op + "'"); return; } } + private void runSetScreenCapture() throws Exception { + String userIdStr = nextArg(); + String enableStr = nextArg(); + int userId; + boolean disable; + + try { + userId = Integer.parseInt(userIdStr); + } catch (NumberFormatException e) { + System.err.println("Error: bad number " + e); + return; + } + + disable = !Boolean.parseBoolean(enableStr); + + try { + mWm.setScreenCaptureDisabled(userId, disable); + } catch (RemoteException e) { + System.err.println("Error: Can't set screen capture " + e); + } + } + private void runDisplaySize() throws Exception { String size = nextArg(); int w, h; - boolean scale = true; if (size == null) { Point initialSize = new Point(); Point baseSize = new Point(); @@ -181,7 +207,6 @@ public class Wm extends BaseCommand { private void runDisplayOverscan() throws Exception { String overscanStr = nextArgRequired(); Rect rect = new Rect(); - int density; if ("reset".equals(overscanStr)) { rect.set(0, 0, 0, 0); } else { diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index 40745292542e7..5970c3f738a08 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -453,6 +453,19 @@ public class SurfaceControl { } } + /** + * Sets the security of the surface. Setting the flag is equivalent to creating the + * Surface with the {@link #SECURE} flag. + */ + public void setSecure(boolean isSecure) { + checkNotReleased(); + if (isSecure) { + nativeSetFlags(mNativeObject, SECURE, SECURE); + } else { + nativeSetFlags(mNativeObject, 0, SECURE); + } + } + /* * set display parameters. * needs to be inside open/closeTransaction block diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index ace59970d0bfd..b285b663bd149 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -2671,6 +2671,16 @@ public class WindowManagerService extends IWindowManager.Stub synchronized(mWindowMap) { mScreenCaptureDisabled.put(userId, disabled); + // Update secure surface for all windows belonging to this user. + for (int displayNdx = mDisplayContents.size() - 1; displayNdx >= 0; --displayNdx) { + WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList(); + for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { + final WindowState win = windows.get(winNdx); + if (win.mHasSurface && userId == UserHandle.getUserId(win.mOwnerUid)) { + win.mWinAnimator.setSecureLocked(disabled); + } + } + } } } diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java index f1331e94bd42a..d818519d5dfa4 100644 --- a/services/core/java/com/android/server/wm/WindowStateAnimator.java +++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java @@ -657,6 +657,11 @@ class WindowStateAnimator { super.setOpaque(isOpaque); } + @Override + public void setSecure(boolean isSecure) { + super.setSecure(isSecure); + } + @Override public void setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { if (dsdx != mDsdx || dtdx != mDtdx || dsdy != mDsdy || dtdy != mDtdy) { @@ -1663,6 +1668,22 @@ class WindowStateAnimator { } } + void setSecureLocked(boolean isSecure) { + if (mSurfaceControl == null) { + return; + } + if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setSecureLocked"); + SurfaceControl.openTransaction(); + try { + if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "isSecure=" + isSecure, + null); + mSurfaceControl.setSecure(isSecure); + } finally { + SurfaceControl.closeTransaction(); + if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setSecureLocked"); + } + } + // This must be called while inside a transaction. boolean performShowLocked() { if (mWin.isHiddenFromUserLocked()) {