Handle user removed for PackageMonitorCallbackHelper

Currently, when a user is removed from the system, the caller doesn't
call unregister method. Even though the registerd clients are mostly
use UserHandle.ALL now but we still need to handle it correctly to
avoid leakage.

Bug: 29385425
Test: manual. Create a user and remove user to make sure the method
works as expected.

Change-Id: Ibcdcdf29d552b5b0ea6ac877ce3956a900362870
This commit is contained in:
Joanne Chung
2023-07-05 11:16:19 +00:00
parent 5ac04e358c
commit e93a6af458
2 changed files with 16 additions and 0 deletions

View File

@@ -4299,6 +4299,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService
mAppsFilter.onUserDeleted(snapshotComputer(), userId);
}
mInstantAppRegistry.onUserRemoved(userId);
mPackageMonitorCallbackHelper.onUserRemoved(userId);
}
/**

View File

@@ -68,6 +68,21 @@ class PackageMonitorCallbackHelper {
}
}
public void onUserRemoved(int userId) {
RemoteCallbackList<IRemoteCallback> callbacks;
synchronized (mLock) {
callbacks = mCallbacks;
}
int registerCount = callbacks.getRegisteredCallbackCount();
for (int i = 0; i < registerCount; i++) {
int registerUserId = (int) callbacks.getRegisteredCallbackCookie(i);
if (registerUserId == userId) {
IRemoteCallback callback = callbacks.getRegisteredCallbackItem(i);
unregisterPackageMonitorCallback(callback);
}
}
}
public void notifyPackageAddedForNewUsers(String packageName,
@AppIdInt int appId, @NonNull int[] userIds, @NonNull int[] instantUserIds,
int dataLoaderType) {