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

Commit aa240ece authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

Revert "Log mode changes to OP_RUN_ANY_IN_BACKGROUND"

Removing temporary logging after analyses are complete and offending bug
has been root caused.

Test: Manually flip the battery restriction toggle and verify that these
logs are not emitted.

Fixes: 280869337
This reverts commit 82c39c6e

Change-Id: Ib3a15113296bf388633b2490e11c359e87bc8312
parent c1fac95c
Loading
Loading
Loading
Loading
+0 −28
Original line number Diff line number Diff line
@@ -65,11 +65,9 @@ import android.os.UserManager;
import android.provider.DeviceConfig;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
import android.util.LongSparseArray;
import android.util.LongSparseLongArray;
import android.util.Pools;
import android.util.Slog;
import android.util.SparseArray;

import com.android.internal.annotations.GuardedBy;
@@ -182,8 +180,6 @@ import java.util.function.Supplier;
 */
@SystemService(Context.APP_OPS_SERVICE)
public class AppOpsManager {
    private static final String LOG_TAG = "AppOpsManager";

    /**
     * This is a subtle behavior change to {@link #startWatchingMode}.
     *
@@ -7542,7 +7538,6 @@ public class AppOpsManager {
     */
    @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES)
    public void setUidMode(int code, int uid, @Mode int mode) {
        logAnySeriousModeChanges(code, uid, null, mode);
        try {
            mService.setUidMode(code, uid, mode);
        } catch (RemoteException e) {
@@ -7563,7 +7558,6 @@ public class AppOpsManager {
    @SystemApi
    @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES)
    public void setUidMode(@NonNull String appOp, int uid, @Mode int mode) {
        logAnySeriousModeChanges(strOpToOp(appOp), uid, null, mode);
        try {
            mService.setUidMode(AppOpsManager.strOpToOp(appOp), uid, mode);
        } catch (RemoteException e) {
@@ -7599,32 +7593,11 @@ public class AppOpsManager {
        }
    }

    private void logAnySeriousModeChanges(int code, int uid, String packageName, @Mode int mode) {
        // TODO (b/280869337): Remove this once we have the required data.
        if (code != OP_RUN_ANY_IN_BACKGROUND || mode == MODE_ALLOWED) {
            return;
        }
        final StringBuilder log = new StringBuilder("Attempt to change RUN_ANY_IN_BACKGROUND to ")
                .append(modeToName(mode))
                .append(" for uid: ")
                .append(UserHandle.formatUid(uid))
                .append(" package: ")
                .append(packageName)
                .append(" by: ")
                .append(mContext.getOpPackageName());
        if (Process.myUid() == Process.SYSTEM_UID) {
            Slog.wtfStack(LOG_TAG, log.toString());
        } else {
            Log.w(LOG_TAG, log.toString());
        }
    }

    /** @hide */
    @UnsupportedAppUsage
    @TestApi
    @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES)
    public void setMode(int code, int uid, String packageName, @Mode int mode) {
        logAnySeriousModeChanges(code, uid, packageName, mode);
        try {
            mService.setMode(code, uid, packageName, mode);
        } catch (RemoteException e) {
@@ -7647,7 +7620,6 @@ public class AppOpsManager {
    @RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES)
    public void setMode(@NonNull String op, int uid, @Nullable String packageName,
            @Mode int mode) {
        logAnySeriousModeChanges(strOpToOp(op), uid, packageName, mode);
        try {
            mService.setMode(strOpToOp(op), uid, packageName, mode);
        } catch (RemoteException e) {
+0 −17
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ import static android.app.AppOpsManager.OP_RECEIVE_AMBIENT_TRIGGER_AUDIO;
import static android.app.AppOpsManager.OP_RECORD_AUDIO;
import static android.app.AppOpsManager.OP_RECORD_AUDIO_HOTWORD;
import static android.app.AppOpsManager.OP_RECORD_AUDIO_SANDBOXED;
import static android.app.AppOpsManager.OP_RUN_ANY_IN_BACKGROUND;
import static android.app.AppOpsManager.OP_VIBRATE;
import static android.app.AppOpsManager.OnOpStartedListener.START_TYPE_FAILED;
import static android.app.AppOpsManager.OnOpStartedListener.START_TYPE_STARTED;
@@ -1770,11 +1769,6 @@ public class AppOpsService extends IAppOpsService.Stub {
    @Override
    public void setUidMode(int code, int uid, int mode) {
        setUidMode(code, uid, mode, null);
        if (code == OP_RUN_ANY_IN_BACKGROUND) {
            // TODO (b/280869337): Remove this once we have the required data.
            Slog.wtfStack(TAG, "setUidMode called for RUN_ANY_IN_BACKGROUND by uid: "
                    + UserHandle.formatUid(Binder.getCallingUid()));
        }
    }

    private void setUidMode(int code, int uid, int mode,
@@ -1950,17 +1944,6 @@ public class AppOpsService extends IAppOpsService.Stub {
    @Override
    public void setMode(int code, int uid, @NonNull String packageName, int mode) {
        setMode(code, uid, packageName, mode, null);
        final int callingUid = Binder.getCallingUid();
        if (code == OP_RUN_ANY_IN_BACKGROUND && mode != MODE_ALLOWED) {
            // TODO (b/280869337): Remove this once we have the required data.
            final String callingPackage = ArrayUtils.firstOrNull(getPackagesForUid(callingUid));
            Slog.wtfStack(TAG,
                    "RUN_ANY_IN_BACKGROUND for package " + packageName + " changed to mode: "
                            + modeToName(mode) + " via setMode. Calling package: " + callingPackage
                            + ", calling uid: " + UserHandle.formatUid(callingUid)
                            + ", calling pid: " + Binder.getCallingPid()
                            + ", system pid: " + Process.myPid());
        }
    }

    void setMode(int code, int uid, @NonNull String packageName, int mode,