Skip to content

Commit ccaf1e6

Browse files
chenxiaolongthestinger
authored andcommitted
Avoid auto-granting special permissions to unarchived apps
Avoid calling setNewlyInstalledInUserId() when restoring an archived app to ensure that the special permission auto-granting logic does not reset the user's previous permission state. Fixes: GrapheneOS/os-issue-tracker#5256 Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
1 parent 9e71b79 commit ccaf1e6

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

services/core/java/com/android/server/pm/InstallPackageHelper.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
import android.util.Pair;
158158
import android.util.Slog;
159159
import android.util.SparseArray;
160+
import android.util.SparseBooleanArray;
160161
import android.util.SparseIntArray;
161162

162163
import com.android.internal.annotations.GuardedBy;
@@ -2623,7 +2624,13 @@ private void updateSettingsInternalLI(AndroidPackage pkg,
26232624
}
26242625
}
26252626

2627+
final SparseBooleanArray archivedInUserIds = new SparseBooleanArray();
2628+
26262629
if (userId != UserHandle.USER_ALL) {
2630+
if (PackageArchiver.isArchived(ps.getUserStateOrDefault(userId))) {
2631+
archivedInUserIds.put(userId, true);
2632+
}
2633+
26272634
// It's implied that when a user requests installation, they want the app to
26282635
// be installed and enabled. The caller, however, can explicitly specify to
26292636
// keep the existing enabled state.
@@ -2634,6 +2641,10 @@ private void updateSettingsInternalLI(AndroidPackage pkg,
26342641
// The caller explicitly specified INSTALL_ALL_USERS flag.
26352642
// Thus, updating the settings to install the app for all users.
26362643
for (int currentUserId : allUsers) {
2644+
if (PackageArchiver.isArchived(ps.getUserStateOrDefault(currentUserId))) {
2645+
archivedInUserIds.put(currentUserId, true);
2646+
}
2647+
26372648
// If the app is already installed for the currentUser,
26382649
// keep it as installed as we might be updating the app at this place.
26392650
// If not currently installed, check if the currentUser is restricted by
@@ -2697,12 +2708,16 @@ private void updateSettingsInternalLI(AndroidPackage pkg,
26972708
if (!previousUserIds.contains(currentUserId)
26982709
&& ps.getInstalled(currentUserId)) {
26992710
ps.setInstallReason(installReason, currentUserId);
2700-
permissionParamsBuilder.setNewlyInstalledInUserId(currentUserId);
2711+
if (!archivedInUserIds.get(currentUserId, false)) {
2712+
permissionParamsBuilder.setNewlyInstalledInUserId(currentUserId);
2713+
}
27012714
}
27022715
}
27032716
} else if (!previousUserIds.contains(userId)) {
27042717
ps.setInstallReason(installReason, userId);
2705-
permissionParamsBuilder.setNewlyInstalledInUserId(userId);
2718+
if (!archivedInUserIds.get(userId, false)) {
2719+
permissionParamsBuilder.setNewlyInstalledInUserId(userId);
2720+
}
27062721
}
27072722

27082723
// TODO(b/169721400): generalize Incremental States and create a Callback object

0 commit comments

Comments
 (0)