Move PreInstalled App List to UserCache.

Bug: 333543006
Test: atest PrivateSpaceHeaderViewTest, AlphabeticalAppsListTest
Flag: NA
Change-Id: I84233c5a6406325d9e641b72ea8455911b46f65f
This commit is contained in:
Himanshu Gupta
2024-04-21 19:05:42 +01:00
parent 568e0bff90
commit ae4631e6a3
5 changed files with 50 additions and 28 deletions

View File

@@ -24,6 +24,7 @@ import android.content.Intent;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.ArrayMap;
import androidx.annotation.AnyThread;
import androidx.annotation.NonNull;
@@ -81,6 +82,9 @@ public class UserCache implements SafeCloseable {
@NonNull
private Map<UserHandle, UserIconInfo> mUserToSerialMap;
@NonNull
private Map<UserHandle, List<String>> mUserToPreInstallAppMap;
private UserCache(Context context) {
mContext = context;
mUserToSerialMap = Collections.emptyMap();
@@ -120,6 +124,20 @@ public class UserCache implements SafeCloseable {
@WorkerThread
private void updateCache() {
mUserToSerialMap = ApiWrapper.INSTANCE.get(mContext).queryAllUsers();
mUserToPreInstallAppMap = fetchPreInstallApps();
}
@WorkerThread
private Map<UserHandle, List<String>> fetchPreInstallApps() {
Map<UserHandle, List<String>> userToPreInstallApp = new ArrayMap<>();
mUserToSerialMap.forEach((userHandle, userIconInfo) -> {
// Fetch only for private profile, as other profiles have no usages yet.
List<String> preInstallApp = userIconInfo.isPrivate()
? ApiWrapper.INSTANCE.get(mContext).getPreInstalledSystemPackages(userHandle)
: new ArrayList<>();
userToPreInstallApp.put(userHandle, preInstallApp);
});
return userToPreInstallApp;
}
/**
@@ -171,6 +189,15 @@ public class UserCache implements SafeCloseable {
return List.copyOf(mUserToSerialMap.keySet());
}
/**
* Returns the pre-installed apps for a user.
*/
@NonNull
public List<String> getPreInstallApps(UserHandle user) {
List<String> preInstallApp = mUserToPreInstallAppMap.get(user);
return preInstallApp == null ? new ArrayList<>() : preInstallApp;
}
/**
* Get a non-themed {@link UserBadgeDrawable} based on the provided {@link UserHandle}.
*/