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

Commit 07940ef1 authored by Evan Severson's avatar Evan Severson Committed by Android (Google) Code Review
Browse files

Merge "Revoke one-time permission with a reason" into rvc-dev

parents e1b040e8 97cff1c2
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -1387,6 +1387,19 @@ public final class AppPermissionGroup implements Comparable<AppPermissionGroup>
     *                                     caller has to make sure to kill the app if needed.
     */
    public void persistChanges(boolean mayKillBecauseOfAppOpsChange) {
        persistChanges(mayKillBecauseOfAppOpsChange, null);
    }


    /**
     * If the changes to this group were delayed, persist them to the platform.
     *
     * @param mayKillBecauseOfAppOpsChange If the app these permissions belong to may be killed if
     *                                     app ops change. If this is set to {@code false} the
     *                                     caller has to make sure to kill the app if needed.
     * @param revokeReason If any permissions are getting revoked, the reason for revoking them.
     */
    public void persistChanges(boolean mayKillBecauseOfAppOpsChange, String revokeReason) {
        int uid = mPackageInfo.applicationInfo.uid;

        int numPermissions = mPermissions.size();
@@ -1404,8 +1417,13 @@ public final class AppPermissionGroup implements Comparable<AppPermissionGroup>
                            uid) == PERMISSION_GRANTED;

                    if (isCurrentlyGranted) {
                        if (revokeReason == null) {
                            mPackageManager.revokeRuntimePermission(mPackageInfo.packageName,
                                    permission.getName(), mUserHandle);
                        } else {
                            mPackageManager.revokeRuntimePermission(mPackageInfo.packageName,
                                    permission.getName(), mUserHandle, revokeReason);
                        }
                    }
                }
            }
+3 −3
Original line number Diff line number Diff line
@@ -74,7 +74,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
@@ -92,6 +91,7 @@ import kotlinx.coroutines.GlobalScope;
 */
public final class PermissionControllerServiceImpl extends PermissionControllerLifecycleService {
    private static final String LOG_TAG = PermissionControllerServiceImpl.class.getSimpleName();
    public static final String ONE_TIME_PERMISSION_REVOKED_REASON = "one-time permission revoked";
    private static final int MAX_RETRY_ATTEMPTS = 3;
    private static final long RETRY_DELAY_MS = 500;

@@ -629,14 +629,14 @@ public final class PermissionControllerServiceImpl extends PermissionControllerL
                groups.add(group);
            }
        }
        long requestId = new Random().nextLong();
        long requestId = Utils.getValidSessionId();
        for (AppPermissionGroup group : groups) {
            if (group.areRuntimePermissionsGranted()) {
                logOneTimeSessionRevoke(packageName, uid, group, requestId);
                group.revokeRuntimePermissions(false);
            }
            group.setUserSet(false);
            group.persistChanges(false);
            group.persistChanges(false, ONE_TIME_PERMISSION_REVOKED_REASON);
        }
    }