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

Commit 77a5a498 authored by Hai Zhang's avatar Hai Zhang Committed by Android (Google) Code Review
Browse files

Merge "Add warning before setting REVOKED_COMPAT for a modern app."

parents 4a15b70b 23d30a25
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ import android.hardware.camera2.CameraDevice.CAMERA_AUDIO_RESTRICTION;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -2117,10 +2118,24 @@ public class AppOpsService extends IAppOpsService.Stub {
                continue;
            }

            PackageManagerInternal packageManagerInternal = LocalServices.getService(
                    PackageManagerInternal.class);
            boolean supportsRuntimePermissions = packageManagerInternal.getUidTargetSdkVersion(uid)
                    >= Build.VERSION_CODES.M;

            UserHandle user = UserHandle.getUserHandleForUid(uid);
            boolean isRevokedCompat;
            if (permissionInfo.backgroundPermission != null) {
                boolean isBackgroundRevokedCompat = mode != AppOpsManager.MODE_ALLOWED;

                if (isBackgroundRevokedCompat && supportsRuntimePermissions) {
                    Slog.w(TAG, "setUidMode() called with a mode inconsistent with runtime"
                            + " permission state, this is discouraged and you should revoke the"
                            + " runtime permission instead: uid=" + uid + ", switchCode="
                            + switchCode + ", mode=" + mode + ", permission="
                            + permissionInfo.backgroundPermission);
                }

                long identity = Binder.clearCallingIdentity();
                try {
                    packageManager.updatePermissionFlags(permissionInfo.backgroundPermission,
@@ -2137,6 +2152,13 @@ public class AppOpsService extends IAppOpsService.Stub {
                isRevokedCompat = mode != AppOpsManager.MODE_ALLOWED;
            }

            if (isRevokedCompat && supportsRuntimePermissions) {
                Slog.w(TAG, "setUidMode() called with a mode inconsistent with runtime"
                        + " permission state, this is discouraged and you should revoke the"
                        + " runtime permission instead: uid=" + uid + ", switchCode="
                        + switchCode + ", mode=" + mode + ", permission=" + permissionName);
            }

            long identity = Binder.clearCallingIdentity();
            try {
                packageManager.updatePermissionFlags(permissionName, packageName,