diff options
| author | 2020-02-17 01:22:43 +0000 | |
|---|---|---|
| committer | 2020-02-17 01:22:43 +0000 | |
| commit | c57793cee42ba2071498d2d58380244ae3b8534a (patch) | |
| tree | 885a0f034f5b915525d72203a79d6986e7807065 | |
| parent | bede106341f9b972a6b3bb44e5e23a652dd40ad7 (diff) | |
| parent | 6954347b92b7974de77782dc238adf066be141a8 (diff) | |
Merge "Refactor checkAddPermission"
4 files changed, 23 insertions, 19 deletions
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index a45a996076dc..19e6062401c0 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -45,7 +45,6 @@ import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; import static android.view.WindowManager.LayoutParams.LAST_SYSTEM_WINDOW; -import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR; import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; @@ -2058,11 +2057,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { /** {@inheritDoc} */ @Override - public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { - final int type = attrs.type; - final boolean isRoundedCornerOverlay = - (attrs.privateFlags & PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY) != 0; - + public int checkAddPermission(int type, boolean isRoundedCornerOverlay, String packageName, + int[] outAppOp) { if (isRoundedCornerOverlay && mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW) != PERMISSION_GRANTED) { return ADD_PERMISSION_DENIED; @@ -2119,7 +2115,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { ApplicationInfo appInfo; try { appInfo = mPackageManager.getApplicationInfoAsUser( - attrs.packageName, + packageName, 0 /* flags */, UserHandle.getUserId(callingUid)); } catch (PackageManager.NameNotFoundException e) { @@ -2139,7 +2135,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { // check if user has enabled this operation. SecurityException will be thrown if this app // has not been allowed by the user - final int mode = mAppOpsManager.noteOpNoThrow(outAppOp[0], callingUid, attrs.packageName); + final int mode = mAppOpsManager.noteOpNoThrow(outAppOp[0], callingUid, packageName); switch (mode) { case AppOpsManager.MODE_ALLOWED: case AppOpsManager.MODE_IGNORED: diff --git a/services/core/java/com/android/server/policy/WindowManagerPolicy.java b/services/core/java/com/android/server/policy/WindowManagerPolicy.java index 39093aec07c0..9d417c9e98e0 100644 --- a/services/core/java/com/android/server/policy/WindowManagerPolicy.java +++ b/services/core/java/com/android/server/policy/WindowManagerPolicy.java @@ -686,17 +686,25 @@ public interface WindowManagerPolicy extends WindowManagerPolicyConstants { WindowManagerFuncs windowManagerFuncs); /** - * Check permissions when adding a window. + * Check permissions when adding a window or a window token from + * {@link android.app.WindowContext}. * - * @param attrs The window's LayoutParams. + * @param type The window type + * @param isRoundedCornerOverlay {@code true} to indicate the adding window is + * round corner overlay. + * @param packageName package name * @param outAppOp First element will be filled with the app op corresponding to * this window, or OP_NONE. * * @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed; * else an error code, usually * {@link WindowManagerGlobal#ADD_PERMISSION_DENIED}, to abort the add. + * + * @see IWindowManager#addWindowTokenWithOptions(IBinder, int, int, Bundle, String) + * @see WindowManager.LayoutParams#PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY */ - public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp); + int checkAddPermission(int type, boolean isRoundedCornerOverlay, String packageName, + int[] outAppOp); /** * After the window manager has computed the current configuration based diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 1b0d177cab87..e85261d820f9 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -1336,7 +1336,10 @@ public class WindowManagerService extends IWindowManager.Stub DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel, InsetsState outInsetsState) { int[] appOp = new int[1]; - int res = mPolicy.checkAddPermission(attrs, appOp); + final boolean isRoundedCornerOverlay = (attrs.privateFlags + & PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY) != 0; + int res = mPolicy.checkAddPermission(attrs.type, isRoundedCornerOverlay, attrs.packageName, + appOp); if (res != WindowManagerGlobal.ADD_OKAY) { return res; } @@ -1410,8 +1413,6 @@ public class WindowManagerService extends IWindowManager.Stub return WindowManagerGlobal.ADD_BAD_APP_TOKEN; } final IBinder binder = attrs.token != null ? attrs.token : client.asBinder(); - final boolean isRoundedCornerOverlay = - (attrs.privateFlags & PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY) != 0; token = new WindowToken(this, binder, type, false, displayContent, session.mCanAddInternalSystemWindow, isRoundedCornerOverlay); } else if (rootType >= FIRST_APPLICATION_WINDOW @@ -2560,10 +2561,8 @@ public class WindowManagerService extends IWindowManager.Stub final boolean callerCanManageAppTokens = checkCallingPermission(MANAGE_APP_TOKENS, "addWindowToken()"); if (!callerCanManageAppTokens) { - // TODO(window-context): refactor checkAddPermission to not take attrs. - LayoutParams attrs = new LayoutParams(type); - attrs.packageName = packageName; - final int res = mPolicy.checkAddPermission(attrs, new int[1]); + final int res = mPolicy.checkAddPermission(type, false /* isRoundedCornerOverlay */, + packageName, new int[1]); if (res != ADD_OKAY) { return res; } diff --git a/services/tests/wmtests/src/com/android/server/wm/TestWindowManagerPolicy.java b/services/tests/wmtests/src/com/android/server/wm/TestWindowManagerPolicy.java index 3a689246205d..7a075a26cb31 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TestWindowManagerPolicy.java +++ b/services/tests/wmtests/src/com/android/server/wm/TestWindowManagerPolicy.java @@ -75,7 +75,8 @@ class TestWindowManagerPolicy implements WindowManagerPolicy { } @Override - public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { + public int checkAddPermission(int type, boolean isRoundedCornerOverlay, String packageName, + int[] outAppOp) { return 0; } |