Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 22d8f8d4 authored by Chad Brubaker's avatar Chad Brubaker Committed by Android (Google) Code Review
Browse files

Merge "Add temp debug logging for app ops"

parents 7a6a6273 7c6dba62
Loading
Loading
Loading
Loading
+49 −0
Original line number Diff line number Diff line
@@ -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);
    }
}