diff options
| author | Chad Brubaker <cbrubaker@google.com> | 2019-01-23 15:51:43 -0800 |
|---|---|---|
| committer | Chad Brubaker <cbrubaker@google.com> | 2019-01-24 12:29:53 -0800 |
| commit | 7c6dba62d133591f8d46800cd020a93a370d5d01 (patch) | |
| tree | 98f5cb0c03206f2ca39f3ee707ea89e441e937eb /core/java/android | |
| parent | 3f64d9ff803343828f4978af5e989ab0d90e8f3a (diff) | |
Add temp debug logging for app ops
To help track down potential bugs add adb commands to enable detailed
stack trace logging of calls to noteOp
Test: Manual
Bug: 123351070
Change-Id: I7817eea95a8861b3979504d16b03076beef1ac13
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/AppOpsManager.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index ab2430c7a490..364d3c9c8e5d 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -39,6 +39,7 @@ import android.os.Parcelable; import android.os.Process; import android.os.RemoteCallback; import android.os.RemoteException; +import android.os.SystemProperties; import android.os.UserManager; import android.provider.Settings; import android.util.ArrayMap; @@ -1712,6 +1713,12 @@ public class AppOpsManager { /** @hide */ public static final String KEY_HISTORICAL_OPS = "historical_ops"; + /** System properties for debug logging of noteOp call sites */ + private static final String DEBUG_LOGGING_ENABLE_PROP = "appops.logging_enabled"; + private static final String DEBUG_LOGGING_PACKAGES_PROP = "appops.logging_packages"; + private static final String DEBUG_LOGGING_OPS_PROP = "appops.logging_ops"; + private static final String DEBUG_LOGGING_TAG = "AppOpsManager"; + /** * Retrieve the op switch that controls the given operation. * @hide @@ -4469,6 +4476,7 @@ public class AppOpsManager { */ @UnsupportedAppUsage public int noteOpNoThrow(int op, int uid, String packageName) { + logNoteOpIfNeeded(op, packageName); try { return mService.noteOperation(op, uid, packageName); } catch (RemoteException e) { @@ -4834,4 +4842,45 @@ public class AppOpsManager { return AppOpsManager.MODE_DEFAULT; } + + private static void logNoteOpIfNeeded(int op, String callingPackage) { + // Check if debug logging propety is enabled. + if (!SystemProperties.getBoolean(DEBUG_LOGGING_ENABLE_PROP, false)) { + return; + } + // Check if this package should be logged. + String packages = SystemProperties.get(DEBUG_LOGGING_PACKAGES_PROP, ""); + if (!"".equals(packages) && callingPackage != null) { + boolean found = false; + for (String pkg : packages.split(",")) { + if (callingPackage.equals(pkg)) { + found = true; + break; + } + } + if (!found) { + return; + } + } + String opStr = opToName(op); + // Check if this app op should be logged + String logOps = SystemProperties.get(DEBUG_LOGGING_OPS_PROP, ""); + if (!"".equals(logOps)) { + boolean found = false; + for (String logOp : logOps.split(",")) { + if (opStr.equals(logOp)) { + found = true; + break; + } + } + if (!found) { + return; + } + } + + // Log a stack trace + Exception here = new Exception("HERE!"); + android.util.Log.i(DEBUG_LOGGING_TAG, "Note operation package= " + callingPackage + + " op= " + opStr, here); + } } |
