From e9b06e6374168fab0642add3ffa2f19e9afb6ab8 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Wed, 11 Mar 2020 22:17:39 -0600 Subject: [PATCH] Pass non-null message of window op to AppOps If the window op is classified as OP_SYSTEM_ALERT_WINDOW (map to a dangerous/appop level permission), the default message will be callstack that causes overhead. Also change the window op related usages to the recommended (not deprecated) ones. Bug: 139522754 Test: atest WindowAddRemovePerfTest Change-Id: I9cf0561dd5877ee05dbb61c8ced25e2eba09b691 --- .../android/server/policy/PhoneWindowManager.java | 6 ++++-- .../java/com/android/server/wm/WindowState.java | 13 ++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index 1b5cc6a248e3e..808963123e225 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -2139,8 +2139,10 @@ 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, packageName); + // has not been allowed by the user. The reason to use "noteOp" (instead of checkOp) is to + // make sure the usage is logged. + final int mode = mAppOpsManager.noteOpNoThrow(outAppOp[0], callingUid, packageName, + null /* featureId */, "check-add"); switch (mode) { case AppOpsManager.MODE_ALLOWED: case AppOpsManager.MODE_IGNORED: diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 27f1ca025a933..c67276157773b 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -2917,8 +2917,9 @@ class WindowState extends WindowContainer implements WindowManagerP // and add the window only if the permission was granted. Therefore, if // the mode is MODE_DEFAULT we want the op to succeed as the window is // shown. - final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp, - getOwningUid(), getOwningPackage(), true); + final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp, getOwningUid(), + getOwningPackage(), true /* startIfModeDefault */, null /* featureId */, + "init-default-visibility"); if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) { setAppOpVisibilityLw(false); } @@ -2926,7 +2927,8 @@ class WindowState extends WindowContainer implements WindowManagerP void resetAppOpsState() { if (mAppOp != OP_NONE && mAppOpVisibility) { - mWmService.mAppOps.finishOp(mAppOp, getOwningUid(), getOwningPackage()); + mWmService.mAppOps.finishOp(mAppOp, getOwningUid(), getOwningPackage(), + null /* featureId */); } } @@ -2941,11 +2943,12 @@ class WindowState extends WindowContainer implements WindowManagerP // as this would mean we will get another change callback and will reconcile. int mode = mWmService.mAppOps.checkOpNoThrow(mAppOp, uid, packageName); if (mode != MODE_ALLOWED && mode != MODE_DEFAULT) { - mWmService.mAppOps.finishOp(mAppOp, uid, packageName); + mWmService.mAppOps.finishOp(mAppOp, uid, packageName, null /* featureId */); setAppOpVisibilityLw(false); } } else { - final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp, uid, packageName, true); + final int mode = mWmService.mAppOps.startOpNoThrow(mAppOp, uid, packageName, + true /* startIfModeDefault */, null /* featureId */, "attempt-to-be-visible"); if (mode == MODE_ALLOWED || mode == MODE_DEFAULT) { setAppOpVisibilityLw(true); }