Loading core/java/android/permission/PermissionManagerInternal.java +19 −50 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package android.permission; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.os.UserHandle; /** * Internal interfaces to be used by other components within the system server. Loading @@ -28,69 +27,39 @@ import android.os.UserHandle; * * @hide */ public abstract class PermissionManagerInternal { /** * Listener for package permission state (permissions or flags) changes. */ public interface OnRuntimePermissionStateChangedListener { /** * Called when the runtime permission state (permissions or flags) changed. * * @param packageName The package for which the change happened. * @param userId the user id for which the change happened. */ @Nullable void onRuntimePermissionStateChanged(@NonNull String packageName, @UserIdInt int userId); } public interface PermissionManagerInternal { /** * Get the state of the runtime permissions as xml file. * Get the state of the runtime permissions as a blob. * * @param user The user the data should be extracted for * @param userId The user ID the data should be extracted for * * @return The state as a xml file * @return the state as a blob */ public abstract @Nullable byte[] backupRuntimePermissions(@NonNull UserHandle user); //@SystemApi(client = SystemApi.Client.SYSTEM_SERVER) @Nullable byte[] backupRuntimePermissions(@UserIdInt int userId); /** * Restore a permission state previously backed up via {@link #backupRuntimePermissions}. * <p> * If not all state can be restored, the un-restorable state will be delayed and can be * retried via {@link #restoreDelayedRuntimePermissions}. * * <p>If not all state can be restored, the un-restoreable state will be delayed and can be * re-tried via {@link #restoreDelayedRuntimePermissions}. * * @param backup The state as an xml file * @param user The user the data should be restored for * @param backup the state as a blob * @param userId the user ID the data should be restored for */ public abstract void restoreRuntimePermissions(@NonNull byte[] backup, @NonNull UserHandle user); //@SystemApi(client = SystemApi.Client.SYSTEM_SERVER) void restoreRuntimePermissions(@NonNull byte[] backup, @UserIdInt int userId); /** * Try to apply permission backup of a package that was previously not applied. * * @param packageName The package that is newly installed * @param user The user the package is installed for * @param packageName the package that is newly installed * @param userId the user ID the package is installed for * * @see #restoreRuntimePermissions */ public abstract void restoreDelayedRuntimePermissions(@NonNull String packageName, @NonNull UserHandle user); /** * Adds a listener for runtime permission state (permissions or flags) changes. * * @param listener The listener. */ public abstract void addOnRuntimePermissionStateChangedListener( @NonNull OnRuntimePermissionStateChangedListener listener); /** * Removes a listener for runtime permission state (permissions or flags) changes. * * @param listener The listener. */ public abstract void removeOnRuntimePermissionStateChangedListener( @NonNull OnRuntimePermissionStateChangedListener listener); //@SystemApi(client = SystemApi.Client.SYSTEM_SERVER) void restoreDelayedRuntimePermissions(@NonNull String packageName, @UserIdInt int userId); } core/java/com/android/server/backup/PermissionBackupHelper.java +5 −5 Original line number Diff line number Diff line Loading @@ -17,8 +17,8 @@ package com.android.server.backup; import android.annotation.NonNull; import android.annotation.UserIdInt; import android.app.backup.BlobBackupHelper; import android.os.UserHandle; import android.permission.PermissionManagerInternal; import android.util.Slog; Loading @@ -34,14 +34,14 @@ public class PermissionBackupHelper extends BlobBackupHelper { // key under which the permission-grant state blob is committed to backup private static final String KEY_PERMISSIONS = "permissions"; private final @NonNull UserHandle mUser; private final @UserIdInt int mUserId; private final @NonNull PermissionManagerInternal mPermissionManager; public PermissionBackupHelper(int userId) { super(STATE_VERSION, KEY_PERMISSIONS); mUser = UserHandle.of(userId); mUserId = userId; mPermissionManager = LocalServices.getService(PermissionManagerInternal.class); } Loading @@ -53,7 +53,7 @@ public class PermissionBackupHelper extends BlobBackupHelper { try { switch (key) { case KEY_PERMISSIONS: return mPermissionManager.backupRuntimePermissions(mUser); return mPermissionManager.backupRuntimePermissions(mUserId); default: Slog.w(TAG, "Unexpected backup key " + key); Loading @@ -72,7 +72,7 @@ public class PermissionBackupHelper extends BlobBackupHelper { try { switch (key) { case KEY_PERMISSIONS: mPermissionManager.restoreRuntimePermissions(payload, mUser); mPermissionManager.restoreRuntimePermissions(payload, mUserId); break; default: Loading services/core/java/com/android/server/pm/PackageManagerService.java +3 −4 Original line number Diff line number Diff line Loading @@ -20723,8 +20723,7 @@ public class PackageManagerService extends IPackageManager.Stub // We may also need to apply pending (restored) runtime permission grants // within these users. mPermissionManager.restoreDelayedRuntimePermissions(packageName, UserHandle.of(userId)); mPermissionManager.restoreDelayedRuntimePermissions(packageName, userId); // Persistent preferred activity might have came into effect due to this // install. Loading Loading @@ -24333,13 +24332,13 @@ public class PackageManagerService extends IPackageManager.Stub + ", convertedFromPreCreated=" + convertedFromPreCreated + ")"); } if (!convertedFromPreCreated) { mPermissionManager.onNewUserCreated(userId); mPermissionManager.onUserCreated(userId); return; } if (!readPermissionStateForUser(userId)) { // Could not read the existing permissions, re-grant them. Slog.i(TAG, "re-granting permissions for pre-created user " + userId); mPermissionManager.onNewUserCreated(userId); mPermissionManager.onUserCreated(userId); } } services/core/java/com/android/server/pm/permission/PermissionManagerService.java +34 −24 Original line number Diff line number Diff line Loading @@ -114,7 +114,6 @@ import android.permission.IPermissionManager; import android.permission.PermissionControllerManager; import android.permission.PermissionManager; import android.permission.PermissionManagerInternal; import android.permission.PermissionManagerInternal.OnRuntimePermissionStateChangedListener; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; Loading Loading @@ -151,6 +150,7 @@ import com.android.server.pm.UserManagerInternal; import com.android.server.pm.UserManagerService; import com.android.server.pm.parsing.PackageInfoUtils; import com.android.server.pm.parsing.pkg.AndroidPackage; import com.android.server.pm.permission.PermissionManagerServiceInternal.OnRuntimePermissionStateChangedListener; import com.android.server.policy.PermissionPolicyInternal; import com.android.server.policy.SoftRestrictedPermissionPolicy; Loading Loading @@ -2197,19 +2197,20 @@ public class PermissionManagerService extends IPermissionManager.Stub { * * <p>Can not be called on main thread. * * @param user The user the data should be extracted for * @param userId The user ID the data should be extracted for * * @return The state as a xml file */ private @Nullable byte[] backupRuntimePermissions(@NonNull UserHandle user) { @Nullable private byte[] backupRuntimePermissions(@UserIdInt int userId) { CompletableFuture<byte[]> backup = new CompletableFuture<>(); mPermissionControllerManager.getRuntimePermissionBackup(user, mContext.getMainExecutor(), backup::complete); mPermissionControllerManager.getRuntimePermissionBackup(UserHandle.of(userId), mContext.getMainExecutor(), backup::complete); try { return backup.get(BACKUP_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { Slog.e(TAG, "Cannot create permission backup for " + user, e); Slog.e(TAG, "Cannot create permission backup for user " + userId, e); return null; } } Loading @@ -2221,13 +2222,14 @@ public class PermissionManagerService extends IPermissionManager.Stub { * applied via {@link #restoreDelayedRuntimePermissions}. * * @param backup The state as an xml file * @param user The user the data should be restored for * @param userId The user ID the data should be restored for */ private void restoreRuntimePermissions(@NonNull byte[] backup, @NonNull UserHandle user) { private void restoreRuntimePermissions(@NonNull byte[] backup, @UserIdInt int userId) { synchronized (mLock) { mHasNoDelayedPermBackup.delete(user.getIdentifier()); mHasNoDelayedPermBackup.delete(userId); } mPermissionControllerManager.stageAndApplyRuntimePermissionsBackup(backup, user); mPermissionControllerManager.stageAndApplyRuntimePermissionsBackup(backup, UserHandle.of(userId)); } /** Loading @@ -2236,24 +2238,24 @@ public class PermissionManagerService extends IPermissionManager.Stub { * <p>Can not be called on main thread. * * @param packageName The package that is newly installed * @param user The user the package is installed for * @param userId The user ID the package is installed for * * @see #restoreRuntimePermissions */ private void restoreDelayedRuntimePermissions(@NonNull String packageName, @NonNull UserHandle user) { @UserIdInt int userId) { synchronized (mLock) { if (mHasNoDelayedPermBackup.get(user.getIdentifier(), false)) { if (mHasNoDelayedPermBackup.get(userId, false)) { return; } } mPermissionControllerManager.applyStagedRuntimePermissionBackup(packageName, user, mContext.getMainExecutor(), (hasMoreBackup) -> { mPermissionControllerManager.applyStagedRuntimePermissionBackup(packageName, UserHandle.of(userId), mContext.getMainExecutor(), (hasMoreBackup) -> { if (hasMoreBackup) { return; } synchronized (mLock) { mHasNoDelayedPermBackup.put(user.getIdentifier(), true); mHasNoDelayedPermBackup.put(userId, true); } }); } Loading Loading @@ -5058,7 +5060,7 @@ public class PermissionManagerService extends IPermissionManager.Stub { } } private class PermissionManagerServiceInternalImpl extends PermissionManagerServiceInternal { private class PermissionManagerServiceInternalImpl implements PermissionManagerServiceInternal { @Override public void systemReady() { PermissionManagerService.this.systemReady(); Loading @@ -5083,6 +5085,7 @@ public class PermissionManagerService extends IPermissionManager.Stub { } @Override public void onUserRemoved(@UserIdInt int userId) { Preconditions.checkArgumentNonNegative(userId, "userId"); PermissionManagerService.this.onUserRemoved(userId); } @NonNull Loading Loading @@ -5162,20 +5165,26 @@ public class PermissionManagerService extends IPermissionManager.Stub { return matchingPermissions; } @Nullable @Override public @Nullable byte[] backupRuntimePermissions(@NonNull UserHandle user) { return PermissionManagerService.this.backupRuntimePermissions(user); public byte[] backupRuntimePermissions(@UserIdInt int userId) { Preconditions.checkArgumentNonNegative(userId, "userId"); return PermissionManagerService.this.backupRuntimePermissions(userId); } @Override public void restoreRuntimePermissions(@NonNull byte[] backup, @NonNull UserHandle user) { PermissionManagerService.this.restoreRuntimePermissions(backup, user); public void restoreRuntimePermissions(@NonNull byte[] backup, @UserIdInt int userId) { Objects.requireNonNull(backup, "backup"); Preconditions.checkArgumentNonNegative(userId, "userId"); PermissionManagerService.this.restoreRuntimePermissions(backup, userId); } @Override public void restoreDelayedRuntimePermissions(@NonNull String packageName, @NonNull UserHandle user) { PermissionManagerService.this.restoreDelayedRuntimePermissions(packageName, user); @UserIdInt int userId) { Objects.requireNonNull(packageName, "packageName"); Preconditions.checkArgumentNonNegative(userId, "userId"); PermissionManagerService.this.restoreDelayedRuntimePermissions(packageName, userId); } @Override Loading Loading @@ -5264,7 +5273,8 @@ public class PermissionManagerService extends IPermissionManager.Stub { } @Override public void onNewUserCreated(int userId) { public void onUserCreated(@UserIdInt int userId) { Preconditions.checkArgumentNonNegative(userId, "userId"); // NOTE: This adds UPDATE_PERMISSIONS_REPLACE_PKG PermissionManagerService.this.updateAllPermissions(StorageManager.UUID_PRIVATE_INTERNAL, true, mDefaultPermissionCallback); Loading services/core/java/com/android/server/pm/permission/PermissionManagerServiceInternal.java +94 −58 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
core/java/android/permission/PermissionManagerInternal.java +19 −50 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package android.permission; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.os.UserHandle; /** * Internal interfaces to be used by other components within the system server. Loading @@ -28,69 +27,39 @@ import android.os.UserHandle; * * @hide */ public abstract class PermissionManagerInternal { /** * Listener for package permission state (permissions or flags) changes. */ public interface OnRuntimePermissionStateChangedListener { /** * Called when the runtime permission state (permissions or flags) changed. * * @param packageName The package for which the change happened. * @param userId the user id for which the change happened. */ @Nullable void onRuntimePermissionStateChanged(@NonNull String packageName, @UserIdInt int userId); } public interface PermissionManagerInternal { /** * Get the state of the runtime permissions as xml file. * Get the state of the runtime permissions as a blob. * * @param user The user the data should be extracted for * @param userId The user ID the data should be extracted for * * @return The state as a xml file * @return the state as a blob */ public abstract @Nullable byte[] backupRuntimePermissions(@NonNull UserHandle user); //@SystemApi(client = SystemApi.Client.SYSTEM_SERVER) @Nullable byte[] backupRuntimePermissions(@UserIdInt int userId); /** * Restore a permission state previously backed up via {@link #backupRuntimePermissions}. * <p> * If not all state can be restored, the un-restorable state will be delayed and can be * retried via {@link #restoreDelayedRuntimePermissions}. * * <p>If not all state can be restored, the un-restoreable state will be delayed and can be * re-tried via {@link #restoreDelayedRuntimePermissions}. * * @param backup The state as an xml file * @param user The user the data should be restored for * @param backup the state as a blob * @param userId the user ID the data should be restored for */ public abstract void restoreRuntimePermissions(@NonNull byte[] backup, @NonNull UserHandle user); //@SystemApi(client = SystemApi.Client.SYSTEM_SERVER) void restoreRuntimePermissions(@NonNull byte[] backup, @UserIdInt int userId); /** * Try to apply permission backup of a package that was previously not applied. * * @param packageName The package that is newly installed * @param user The user the package is installed for * @param packageName the package that is newly installed * @param userId the user ID the package is installed for * * @see #restoreRuntimePermissions */ public abstract void restoreDelayedRuntimePermissions(@NonNull String packageName, @NonNull UserHandle user); /** * Adds a listener for runtime permission state (permissions or flags) changes. * * @param listener The listener. */ public abstract void addOnRuntimePermissionStateChangedListener( @NonNull OnRuntimePermissionStateChangedListener listener); /** * Removes a listener for runtime permission state (permissions or flags) changes. * * @param listener The listener. */ public abstract void removeOnRuntimePermissionStateChangedListener( @NonNull OnRuntimePermissionStateChangedListener listener); //@SystemApi(client = SystemApi.Client.SYSTEM_SERVER) void restoreDelayedRuntimePermissions(@NonNull String packageName, @UserIdInt int userId); }
core/java/com/android/server/backup/PermissionBackupHelper.java +5 −5 Original line number Diff line number Diff line Loading @@ -17,8 +17,8 @@ package com.android.server.backup; import android.annotation.NonNull; import android.annotation.UserIdInt; import android.app.backup.BlobBackupHelper; import android.os.UserHandle; import android.permission.PermissionManagerInternal; import android.util.Slog; Loading @@ -34,14 +34,14 @@ public class PermissionBackupHelper extends BlobBackupHelper { // key under which the permission-grant state blob is committed to backup private static final String KEY_PERMISSIONS = "permissions"; private final @NonNull UserHandle mUser; private final @UserIdInt int mUserId; private final @NonNull PermissionManagerInternal mPermissionManager; public PermissionBackupHelper(int userId) { super(STATE_VERSION, KEY_PERMISSIONS); mUser = UserHandle.of(userId); mUserId = userId; mPermissionManager = LocalServices.getService(PermissionManagerInternal.class); } Loading @@ -53,7 +53,7 @@ public class PermissionBackupHelper extends BlobBackupHelper { try { switch (key) { case KEY_PERMISSIONS: return mPermissionManager.backupRuntimePermissions(mUser); return mPermissionManager.backupRuntimePermissions(mUserId); default: Slog.w(TAG, "Unexpected backup key " + key); Loading @@ -72,7 +72,7 @@ public class PermissionBackupHelper extends BlobBackupHelper { try { switch (key) { case KEY_PERMISSIONS: mPermissionManager.restoreRuntimePermissions(payload, mUser); mPermissionManager.restoreRuntimePermissions(payload, mUserId); break; default: Loading
services/core/java/com/android/server/pm/PackageManagerService.java +3 −4 Original line number Diff line number Diff line Loading @@ -20723,8 +20723,7 @@ public class PackageManagerService extends IPackageManager.Stub // We may also need to apply pending (restored) runtime permission grants // within these users. mPermissionManager.restoreDelayedRuntimePermissions(packageName, UserHandle.of(userId)); mPermissionManager.restoreDelayedRuntimePermissions(packageName, userId); // Persistent preferred activity might have came into effect due to this // install. Loading Loading @@ -24333,13 +24332,13 @@ public class PackageManagerService extends IPackageManager.Stub + ", convertedFromPreCreated=" + convertedFromPreCreated + ")"); } if (!convertedFromPreCreated) { mPermissionManager.onNewUserCreated(userId); mPermissionManager.onUserCreated(userId); return; } if (!readPermissionStateForUser(userId)) { // Could not read the existing permissions, re-grant them. Slog.i(TAG, "re-granting permissions for pre-created user " + userId); mPermissionManager.onNewUserCreated(userId); mPermissionManager.onUserCreated(userId); } }
services/core/java/com/android/server/pm/permission/PermissionManagerService.java +34 −24 Original line number Diff line number Diff line Loading @@ -114,7 +114,6 @@ import android.permission.IPermissionManager; import android.permission.PermissionControllerManager; import android.permission.PermissionManager; import android.permission.PermissionManagerInternal; import android.permission.PermissionManagerInternal.OnRuntimePermissionStateChangedListener; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; Loading Loading @@ -151,6 +150,7 @@ import com.android.server.pm.UserManagerInternal; import com.android.server.pm.UserManagerService; import com.android.server.pm.parsing.PackageInfoUtils; import com.android.server.pm.parsing.pkg.AndroidPackage; import com.android.server.pm.permission.PermissionManagerServiceInternal.OnRuntimePermissionStateChangedListener; import com.android.server.policy.PermissionPolicyInternal; import com.android.server.policy.SoftRestrictedPermissionPolicy; Loading Loading @@ -2197,19 +2197,20 @@ public class PermissionManagerService extends IPermissionManager.Stub { * * <p>Can not be called on main thread. * * @param user The user the data should be extracted for * @param userId The user ID the data should be extracted for * * @return The state as a xml file */ private @Nullable byte[] backupRuntimePermissions(@NonNull UserHandle user) { @Nullable private byte[] backupRuntimePermissions(@UserIdInt int userId) { CompletableFuture<byte[]> backup = new CompletableFuture<>(); mPermissionControllerManager.getRuntimePermissionBackup(user, mContext.getMainExecutor(), backup::complete); mPermissionControllerManager.getRuntimePermissionBackup(UserHandle.of(userId), mContext.getMainExecutor(), backup::complete); try { return backup.get(BACKUP_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { Slog.e(TAG, "Cannot create permission backup for " + user, e); Slog.e(TAG, "Cannot create permission backup for user " + userId, e); return null; } } Loading @@ -2221,13 +2222,14 @@ public class PermissionManagerService extends IPermissionManager.Stub { * applied via {@link #restoreDelayedRuntimePermissions}. * * @param backup The state as an xml file * @param user The user the data should be restored for * @param userId The user ID the data should be restored for */ private void restoreRuntimePermissions(@NonNull byte[] backup, @NonNull UserHandle user) { private void restoreRuntimePermissions(@NonNull byte[] backup, @UserIdInt int userId) { synchronized (mLock) { mHasNoDelayedPermBackup.delete(user.getIdentifier()); mHasNoDelayedPermBackup.delete(userId); } mPermissionControllerManager.stageAndApplyRuntimePermissionsBackup(backup, user); mPermissionControllerManager.stageAndApplyRuntimePermissionsBackup(backup, UserHandle.of(userId)); } /** Loading @@ -2236,24 +2238,24 @@ public class PermissionManagerService extends IPermissionManager.Stub { * <p>Can not be called on main thread. * * @param packageName The package that is newly installed * @param user The user the package is installed for * @param userId The user ID the package is installed for * * @see #restoreRuntimePermissions */ private void restoreDelayedRuntimePermissions(@NonNull String packageName, @NonNull UserHandle user) { @UserIdInt int userId) { synchronized (mLock) { if (mHasNoDelayedPermBackup.get(user.getIdentifier(), false)) { if (mHasNoDelayedPermBackup.get(userId, false)) { return; } } mPermissionControllerManager.applyStagedRuntimePermissionBackup(packageName, user, mContext.getMainExecutor(), (hasMoreBackup) -> { mPermissionControllerManager.applyStagedRuntimePermissionBackup(packageName, UserHandle.of(userId), mContext.getMainExecutor(), (hasMoreBackup) -> { if (hasMoreBackup) { return; } synchronized (mLock) { mHasNoDelayedPermBackup.put(user.getIdentifier(), true); mHasNoDelayedPermBackup.put(userId, true); } }); } Loading Loading @@ -5058,7 +5060,7 @@ public class PermissionManagerService extends IPermissionManager.Stub { } } private class PermissionManagerServiceInternalImpl extends PermissionManagerServiceInternal { private class PermissionManagerServiceInternalImpl implements PermissionManagerServiceInternal { @Override public void systemReady() { PermissionManagerService.this.systemReady(); Loading @@ -5083,6 +5085,7 @@ public class PermissionManagerService extends IPermissionManager.Stub { } @Override public void onUserRemoved(@UserIdInt int userId) { Preconditions.checkArgumentNonNegative(userId, "userId"); PermissionManagerService.this.onUserRemoved(userId); } @NonNull Loading Loading @@ -5162,20 +5165,26 @@ public class PermissionManagerService extends IPermissionManager.Stub { return matchingPermissions; } @Nullable @Override public @Nullable byte[] backupRuntimePermissions(@NonNull UserHandle user) { return PermissionManagerService.this.backupRuntimePermissions(user); public byte[] backupRuntimePermissions(@UserIdInt int userId) { Preconditions.checkArgumentNonNegative(userId, "userId"); return PermissionManagerService.this.backupRuntimePermissions(userId); } @Override public void restoreRuntimePermissions(@NonNull byte[] backup, @NonNull UserHandle user) { PermissionManagerService.this.restoreRuntimePermissions(backup, user); public void restoreRuntimePermissions(@NonNull byte[] backup, @UserIdInt int userId) { Objects.requireNonNull(backup, "backup"); Preconditions.checkArgumentNonNegative(userId, "userId"); PermissionManagerService.this.restoreRuntimePermissions(backup, userId); } @Override public void restoreDelayedRuntimePermissions(@NonNull String packageName, @NonNull UserHandle user) { PermissionManagerService.this.restoreDelayedRuntimePermissions(packageName, user); @UserIdInt int userId) { Objects.requireNonNull(packageName, "packageName"); Preconditions.checkArgumentNonNegative(userId, "userId"); PermissionManagerService.this.restoreDelayedRuntimePermissions(packageName, userId); } @Override Loading Loading @@ -5264,7 +5273,8 @@ public class PermissionManagerService extends IPermissionManager.Stub { } @Override public void onNewUserCreated(int userId) { public void onUserCreated(@UserIdInt int userId) { Preconditions.checkArgumentNonNegative(userId, "userId"); // NOTE: This adds UPDATE_PERMISSIONS_REPLACE_PKG PermissionManagerService.this.updateAllPermissions(StorageManager.UUID_PRIVATE_INTERNAL, true, mDefaultPermissionCallback); Loading
services/core/java/com/android/server/pm/permission/PermissionManagerServiceInternal.java +94 −58 File changed.Preview size limit exceeded, changes collapsed. Show changes