Loading src/com/android/launcher3/allapps/AlphabeticalAppsList.java +1 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading src/com/android/launcher3/allapps/PrivateProfileManager.java +5 −8 Original line number Diff line number Diff line Loading @@ -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; /** Loading @@ -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; Loading Loading @@ -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); } Loading Loading @@ -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} */ Loading src/com/android/launcher3/pm/UserCache.java +27 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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; } /** Loading Loading @@ -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}. */ Loading tests/src/com/android/launcher3/allapps/AlphabeticalAppsListTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -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")); Loading Loading @@ -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")); Loading tests/src/com/android/launcher3/allapps/PrivateSpaceHeaderViewTest.java +15 −16 Original line number Diff line number Diff line Loading @@ -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) Loading Loading @@ -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()); Loading Loading @@ -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()); Loading Loading @@ -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()); Loading Loading @@ -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()); Loading Loading @@ -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); } } Loading
src/com/android/launcher3/allapps/AlphabeticalAppsList.java +1 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading
src/com/android/launcher3/allapps/PrivateProfileManager.java +5 −8 Original line number Diff line number Diff line Loading @@ -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; /** Loading @@ -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; Loading Loading @@ -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); } Loading Loading @@ -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} */ Loading
src/com/android/launcher3/pm/UserCache.java +27 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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; } /** Loading Loading @@ -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}. */ Loading
tests/src/com/android/launcher3/allapps/AlphabeticalAppsListTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -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")); Loading Loading @@ -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")); Loading
tests/src/com/android/launcher3/allapps/PrivateSpaceHeaderViewTest.java +15 −16 Original line number Diff line number Diff line Loading @@ -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) Loading Loading @@ -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()); Loading Loading @@ -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()); Loading Loading @@ -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()); Loading Loading @@ -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()); Loading Loading @@ -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); } }