Merge "Move PreInstalled App List to UserCache." into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
62a1a8a336
@@ -22,7 +22,6 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH
|
||||
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_PRIVATE_SPACE_USER_INSTALLED_APPS_COUNT;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.ImageSpan;
|
||||
@@ -362,7 +361,7 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement
|
||||
// Split of private space apps into user-installed and system apps.
|
||||
Map<Boolean, List<AppInfo>> split = mPrivateApps.stream()
|
||||
.collect(Collectors.partitioningBy(mPrivateProviderManager
|
||||
.splitIntoUserInstalledAndSystemApps()));
|
||||
.splitIntoUserInstalledAndSystemApps(mActivityContext)));
|
||||
|
||||
// TODO(b/329688630): switch to the pulled LayoutStaticSnapshot atom
|
||||
mActivityContext
|
||||
|
||||
@@ -80,9 +80,7 @@ import com.android.launcher3.views.ActivityContext;
|
||||
import com.android.launcher3.views.RecyclerViewFastScroller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
@@ -105,7 +103,6 @@ public class PrivateProfileManager extends UserProfileManager {
|
||||
}
|
||||
}
|
||||
};
|
||||
private Set<String> mPreInstalledSystemPackages = new HashSet<>();
|
||||
private Intent mAppInstallerIntent = new Intent();
|
||||
private PrivateAppsSectionDecorator mPrivateAppsSectionDecorator;
|
||||
private boolean mPrivateSpaceSettingsAvailable;
|
||||
@@ -264,8 +261,6 @@ public class PrivateProfileManager extends UserProfileManager {
|
||||
ApiWrapper apiWrapper = ApiWrapper.INSTANCE.get(appContext);
|
||||
UserHandle profileUser = getProfileUser();
|
||||
if (profileUser != null) {
|
||||
mPreInstalledSystemPackages = new HashSet<>(
|
||||
apiWrapper.getPreInstalledSystemPackages(profileUser));
|
||||
mAppInstallerIntent = apiWrapper
|
||||
.getAppMarketActivityIntent(BuildConfig.APPLICATION_ID, profileUser);
|
||||
}
|
||||
@@ -349,10 +344,12 @@ public class PrivateProfileManager extends UserProfileManager {
|
||||
* Splits private apps into user installed and system apps.
|
||||
* When the list of system apps is empty, all apps are treated as system.
|
||||
*/
|
||||
public Predicate<AppInfo> splitIntoUserInstalledAndSystemApps() {
|
||||
return appInfo -> !mPreInstalledSystemPackages.isEmpty()
|
||||
public Predicate<AppInfo> splitIntoUserInstalledAndSystemApps(Context context) {
|
||||
List<String> preInstallApps = UserCache.getInstance(context)
|
||||
.getPreInstallApps(getProfileUser());
|
||||
return appInfo -> !preInstallApps.isEmpty()
|
||||
&& (appInfo.componentName == null
|
||||
|| !(mPreInstalledSystemPackages.contains(appInfo.componentName.getPackageName())));
|
||||
|| !(preInstallApps.contains(appInfo.componentName.getPackageName())));
|
||||
}
|
||||
|
||||
/** Add Private Space Header view elements based upon {@link UserProfileState} */
|
||||
|
||||
@@ -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}.
|
||||
*/
|
||||
|
||||
@@ -98,7 +98,7 @@ public class AlphabeticalAppsListTest {
|
||||
when(mPrivateProfileManager.addPrivateSpaceHeader(any()))
|
||||
.thenAnswer(answer(this::addPrivateSpaceHeader));
|
||||
when(mPrivateProfileManager.getCurrentState()).thenReturn(STATE_ENABLED);
|
||||
when(mPrivateProfileManager.splitIntoUserInstalledAndSystemApps())
|
||||
when(mPrivateProfileManager.splitIntoUserInstalledAndSystemApps(any()))
|
||||
.thenReturn(iteminfo -> iteminfo.componentName == null
|
||||
|| !iteminfo.componentName.getPackageName()
|
||||
.equals("com.android.launcher3.tests.camera"));
|
||||
@@ -127,7 +127,7 @@ public class AlphabeticalAppsListTest {
|
||||
when(mPrivateProfileManager.addSystemAppsDivider(any()))
|
||||
.thenAnswer(answer(this::addSystemAppsDivider));
|
||||
when(mPrivateProfileManager.getCurrentState()).thenReturn(STATE_ENABLED);
|
||||
when(mPrivateProfileManager.splitIntoUserInstalledAndSystemApps())
|
||||
when(mPrivateProfileManager.splitIntoUserInstalledAndSystemApps(mContext))
|
||||
.thenReturn(iteminfo -> iteminfo.componentName == null
|
||||
|| !iteminfo.componentName.getPackageName()
|
||||
.equals("com.android.launcher3.tests.camera"));
|
||||
|
||||
@@ -71,6 +71,7 @@ import org.mockito.MockitoAnnotations;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@@ -279,10 +280,8 @@ public class PrivateSpaceHeaderViewTest {
|
||||
when(mAllAppsStore.getApps()).thenReturn(createAppInfoList());
|
||||
PrivateProfileManager privateProfileManager = spy(mPrivateProfileManager);
|
||||
when(privateProfileManager.getCurrentState()).thenReturn(STATE_ENABLED);
|
||||
when(privateProfileManager.splitIntoUserInstalledAndSystemApps())
|
||||
.thenReturn(iteminfo -> iteminfo.componentName == null
|
||||
|| !iteminfo.componentName.getPackageName()
|
||||
.equals(CAMERA_PACKAGE_NAME));
|
||||
doReturn(splitIntoUserInstalledAndSystemApps()).when(privateProfileManager)
|
||||
.splitIntoUserInstalledAndSystemApps(any());
|
||||
doReturn(0).when(privateProfileManager).addPrivateSpaceHeader(any());
|
||||
doAnswer(answer(this::addPrivateSpaceHeader)).when(privateProfileManager)
|
||||
.addPrivateSpaceHeader(any());
|
||||
@@ -316,10 +315,8 @@ public class PrivateSpaceHeaderViewTest {
|
||||
when(mAllAppsStore.getApps()).thenReturn(createAppInfoList());
|
||||
PrivateProfileManager privateProfileManager = spy(mPrivateProfileManager);
|
||||
when(privateProfileManager.getCurrentState()).thenReturn(STATE_ENABLED);
|
||||
when(privateProfileManager.splitIntoUserInstalledAndSystemApps())
|
||||
.thenReturn(iteminfo -> iteminfo.componentName == null
|
||||
|| !iteminfo.componentName.getPackageName()
|
||||
.equals(CAMERA_PACKAGE_NAME));
|
||||
doReturn(splitIntoUserInstalledAndSystemApps()).when(privateProfileManager)
|
||||
.splitIntoUserInstalledAndSystemApps(any());
|
||||
doReturn(0).when(privateProfileManager).addPrivateSpaceHeader(any());
|
||||
doAnswer(answer(this::addPrivateSpaceHeader)).when(privateProfileManager)
|
||||
.addPrivateSpaceHeader(any());
|
||||
@@ -353,10 +350,8 @@ public class PrivateSpaceHeaderViewTest {
|
||||
when(mAllAppsStore.getApps()).thenReturn(createAppInfoList());
|
||||
PrivateProfileManager privateProfileManager = spy(mPrivateProfileManager);
|
||||
when(privateProfileManager.getCurrentState()).thenReturn(STATE_ENABLED);
|
||||
when(privateProfileManager.splitIntoUserInstalledAndSystemApps())
|
||||
.thenReturn(iteminfo -> iteminfo.componentName == null
|
||||
|| !iteminfo.componentName.getPackageName()
|
||||
.equals(CAMERA_PACKAGE_NAME));
|
||||
doReturn(splitIntoUserInstalledAndSystemApps()).when(privateProfileManager)
|
||||
.splitIntoUserInstalledAndSystemApps(any());
|
||||
doReturn(0).when(privateProfileManager).addPrivateSpaceHeader(any());
|
||||
doAnswer(answer(this::addPrivateSpaceHeader)).when(privateProfileManager)
|
||||
.addPrivateSpaceHeader(any());
|
||||
@@ -390,10 +385,8 @@ public class PrivateSpaceHeaderViewTest {
|
||||
when(mAllAppsStore.getApps()).thenReturn(createAppInfoList());
|
||||
PrivateProfileManager privateProfileManager = spy(mPrivateProfileManager);
|
||||
when(privateProfileManager.getCurrentState()).thenReturn(STATE_ENABLED);
|
||||
when(privateProfileManager.splitIntoUserInstalledAndSystemApps())
|
||||
.thenReturn(iteminfo -> iteminfo.componentName == null
|
||||
|| !iteminfo.componentName.getPackageName()
|
||||
.equals(CAMERA_PACKAGE_NAME));
|
||||
doReturn(splitIntoUserInstalledAndSystemApps()).when(privateProfileManager)
|
||||
.splitIntoUserInstalledAndSystemApps(any());
|
||||
doReturn(0).when(privateProfileManager).addPrivateSpaceHeader(any());
|
||||
doNothing().when(privateProfileManager).addPrivateSpaceInstallAppButton(any());
|
||||
doReturn(0).when(privateProfileManager).addSystemAppsDivider(any());
|
||||
@@ -465,4 +458,10 @@ public class PrivateSpaceHeaderViewTest {
|
||||
}
|
||||
return appInfos.toArray(AppInfo[]::new);
|
||||
}
|
||||
|
||||
private Predicate<AppInfo> splitIntoUserInstalledAndSystemApps() {
|
||||
return iteminfo -> iteminfo.componentName == null
|
||||
|| !iteminfo.componentName.getPackageName()
|
||||
.equals(CAMERA_PACKAGE_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user