Check user states exist before package add/removal

It's possible for packages to be added/removed for a user even if they
are not yet unlocked. This could cause a NPE, so we check beforehand and
ignore if the the user states have not been initialized. This is fine
because on user unlock, we get the most up to date package data anyway.

Bug: 175829330
Test: atest AppHibernationService
Change-Id: Ia29359d38325be5a40d84237fd7fc1b5ba356c5d
This commit is contained in:
Kevin Han
2021-02-17 18:13:56 -08:00
parent c2d6240642
commit f05208818a

View File

@@ -421,6 +421,9 @@ public final class AppHibernationService extends SystemService {
private void onPackageAdded(@NonNull String packageName, int userId) {
synchronized (mLock) {
if (!mUserStates.contains(userId)) {
return;
}
UserLevelState userState = new UserLevelState();
userState.packageName = packageName;
mUserStates.get(userId).put(packageName, userState);
@@ -434,6 +437,9 @@ public final class AppHibernationService extends SystemService {
private void onPackageRemoved(@NonNull String packageName, int userId) {
synchronized (mLock) {
if (!mUserStates.contains(userId)) {
return;
}
mUserStates.get(userId).remove(packageName);
}
}