157157import android .util .Pair ;
158158import android .util .Slog ;
159159import android .util .SparseArray ;
160+ import android .util .SparseBooleanArray ;
160161import android .util .SparseIntArray ;
161162
162163import 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