Merge "Separating system and user-installed apps in PS container." into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
eaeb666e43
@@ -19,6 +19,7 @@ package com.android.launcher3.allapps;
|
||||
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||
|
||||
import static com.android.launcher3.allapps.BaseAllAppsAdapter.VIEW_TYPE_PRIVATE_SPACE_HEADER;
|
||||
import static com.android.launcher3.allapps.BaseAllAppsAdapter.VIEW_TYPE_PRIVATE_SPACE_SYS_APPS_DIVIDER;
|
||||
import static com.android.launcher3.allapps.SectionDecorationInfo.ROUND_BOTTOM_LEFT;
|
||||
import static com.android.launcher3.allapps.SectionDecorationInfo.ROUND_BOTTOM_RIGHT;
|
||||
import static com.android.launcher3.allapps.SectionDecorationInfo.ROUND_NOTHING;
|
||||
@@ -63,9 +64,10 @@ public class AlphabeticalAppsListTest {
|
||||
|
||||
private static final int PRIVATE_SPACE_HEADER_ITEM_COUNT = 1;
|
||||
private static final int MAIN_USER_APP_COUNT = 2;
|
||||
private static final int PRIVATE_USER_APP_COUNT = 1;
|
||||
private static final int PRIVATE_USER_APP_COUNT = 2;
|
||||
private static final int NUM_APP_COLS = 4;
|
||||
private static final int NUM_APP_ROWS = 3;
|
||||
private static final int PRIVATE_SPACE_SYS_APP_SEPARATOR_ITEM_COUNT = 1;
|
||||
|
||||
private AlphabeticalAppsList<?> mAlphabeticalAppsList;
|
||||
@Mock
|
||||
@@ -96,6 +98,10 @@ public class AlphabeticalAppsListTest {
|
||||
when(mPrivateProfileManager.addPrivateSpaceHeader(any()))
|
||||
.thenAnswer(answer(this::addPrivateSpaceHeader));
|
||||
when(mPrivateProfileManager.getCurrentState()).thenReturn(STATE_ENABLED);
|
||||
when(mPrivateProfileManager.splitIntoUserInstalledAndSystemApps())
|
||||
.thenReturn(iteminfo -> iteminfo.componentName == null
|
||||
|| !iteminfo.componentName.getPackageName()
|
||||
.equals("com.android.launcher3.tests.camera"));
|
||||
|
||||
mAlphabeticalAppsList.updateItemFilter(info -> info != null
|
||||
&& info.user.equals(MAIN_HANDLE));
|
||||
@@ -111,6 +117,44 @@ public class AlphabeticalAppsListTest {
|
||||
&& item.itemInfo.user.equals(PRIVATE_HANDLE)).toList().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void privateProfileEnabled_privateProfileAppsShownWithSeparator() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_PRIVATE_SPACE);
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_PRIVATE_SPACE_SYS_APPS_SEPARATION);
|
||||
when(mAllAppsStore.getApps()).thenReturn(createAppInfoListForMainAndPrivateUser());
|
||||
when(mPrivateProfileManager.addPrivateSpaceHeader(any()))
|
||||
.thenAnswer(answer(this::addPrivateSpaceHeader));
|
||||
when(mPrivateProfileManager.addSystemAppsDivider(any()))
|
||||
.thenAnswer(answer(this::addSystemAppsDivider));
|
||||
when(mPrivateProfileManager.getCurrentState()).thenReturn(STATE_ENABLED);
|
||||
when(mPrivateProfileManager.splitIntoUserInstalledAndSystemApps())
|
||||
.thenReturn(iteminfo -> iteminfo.componentName == null
|
||||
|| !iteminfo.componentName.getPackageName()
|
||||
.equals("com.android.launcher3.tests.camera"));
|
||||
|
||||
mAlphabeticalAppsList.updateItemFilter(info -> info != null
|
||||
&& info.user.equals(MAIN_HANDLE));
|
||||
|
||||
assertEquals(MAIN_USER_APP_COUNT + PRIVATE_SPACE_HEADER_ITEM_COUNT
|
||||
+ PRIVATE_SPACE_SYS_APP_SEPARATOR_ITEM_COUNT
|
||||
+ PRIVATE_USER_APP_COUNT, mAlphabeticalAppsList.getAdapterItems().size());
|
||||
assertEquals(PRIVATE_SPACE_HEADER_ITEM_COUNT,
|
||||
mAlphabeticalAppsList.getAdapterItems().stream().filter(item ->
|
||||
item.viewType == VIEW_TYPE_PRIVATE_SPACE_HEADER).toList().size());
|
||||
assertEquals(PRIVATE_SPACE_SYS_APP_SEPARATOR_ITEM_COUNT,
|
||||
mAlphabeticalAppsList.getAdapterItems().stream().filter(item ->
|
||||
item.viewType == VIEW_TYPE_PRIVATE_SPACE_SYS_APPS_DIVIDER).toList().size());
|
||||
List<BaseAllAppsAdapter.AdapterItem> psApps = mAlphabeticalAppsList.getAdapterItems()
|
||||
.stream()
|
||||
.filter(item -> item.itemInfo != null && item.itemInfo.user.equals(PRIVATE_HANDLE))
|
||||
.toList();
|
||||
assertEquals(PRIVATE_USER_APP_COUNT, psApps.size());
|
||||
assert psApps.get(0).itemInfo.title != null;
|
||||
assertEquals("Private Messenger", psApps.get(0).itemInfo.title.toString());
|
||||
assert psApps.get(1).itemInfo.title != null;
|
||||
assertEquals("Private Camera", psApps.get(1).itemInfo.title.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void privateProfileDisabled_onlyPrivateProfileHeaderViewIsPresent() {
|
||||
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_PRIVATE_SPACE);
|
||||
@@ -281,6 +325,12 @@ public class AlphabeticalAppsListTest {
|
||||
return adapterItemList.size();
|
||||
}
|
||||
|
||||
private int addSystemAppsDivider(List<BaseAllAppsAdapter.AdapterItem> adapterItemList) {
|
||||
adapterItemList.add(new BaseAllAppsAdapter
|
||||
.AdapterItem(VIEW_TYPE_PRIVATE_SPACE_SYS_APPS_DIVIDER));
|
||||
return adapterItemList.size();
|
||||
}
|
||||
|
||||
private AppInfo[] createAppInfoListForMainUser() {
|
||||
ComponentName gmailComponentName = new ComponentName(mContext,
|
||||
"com.android.launcher3.tests.Activity" + "Gmail");
|
||||
@@ -298,7 +348,11 @@ public class AlphabeticalAppsListTest {
|
||||
"com.android.launcher3.tests.Activity" + "PrivateMessenger");
|
||||
AppInfo privateMessengerAppInfo = new AppInfo(privateMessengercomponentName,
|
||||
"Private Messenger", PRIVATE_HANDLE, new Intent());
|
||||
return new AppInfo[]{privateMessengerAppInfo};
|
||||
ComponentName privateCameraComponentName = new ComponentName(
|
||||
"com.android.launcher3.tests.camera", "CameraActivity");
|
||||
AppInfo privateCameraAppInfo = new AppInfo(privateCameraComponentName,
|
||||
"Private Camera", PRIVATE_HANDLE, new Intent());
|
||||
return new AppInfo[]{privateMessengerAppInfo, privateCameraAppInfo};
|
||||
}
|
||||
|
||||
private AppInfo[] createAppInfoListForMainAndPrivateUser() {
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.launcher3.allapps;
|
||||
|
||||
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||
|
||||
import static com.android.launcher3.allapps.UserProfileManager.STATE_DISABLED;
|
||||
import static com.android.launcher3.allapps.UserProfileManager.STATE_ENABLED;
|
||||
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_PRIVATE_PROFILE_QUIET_MODE_ENABLED;
|
||||
@@ -31,8 +33,10 @@ import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.LauncherApps;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Process;
|
||||
@@ -43,6 +47,7 @@ import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.launcher3.logging.StatsLogManager;
|
||||
import com.android.launcher3.pm.UserCache;
|
||||
import com.android.launcher3.util.ActivityContextWrapper;
|
||||
import com.android.launcher3.util.UserIconInfo;
|
||||
import com.android.launcher3.util.rule.TestStabilityRule;
|
||||
|
||||
@@ -56,6 +61,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@@ -89,6 +95,8 @@ public class PrivateProfileManagerTest {
|
||||
private AllAppsStore mAllAppsStore;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private LauncherApps mLauncherApps;
|
||||
|
||||
private boolean mRunnableCalled = false;
|
||||
|
||||
@@ -103,6 +111,13 @@ public class PrivateProfileManagerTest {
|
||||
when(mActivityAllAppsContainerView.getAppsStore()).thenReturn(mAllAppsStore);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.resolveActivity(any(), any())).thenReturn(new ResolveInfo());
|
||||
when(mContext.getSystemService(LauncherApps.class)).thenReturn(mLauncherApps);
|
||||
when(mLauncherApps.getAppMarketActivityIntent(any(), any())).thenReturn(PendingIntent
|
||||
.getActivity(new ActivityContextWrapper(getApplicationContext()), 0,
|
||||
new Intent(), PendingIntent.FLAG_IMMUTABLE).getIntentSender());
|
||||
when(mContext.getPackageName())
|
||||
.thenReturn("com.android.launcher3.tests.privateProfileManager");
|
||||
when(mLauncherApps.getPreInstalledSystemPackages(any())).thenReturn(new ArrayList<>());
|
||||
mPrivateProfileManager = new PrivateProfileManager(mUserManager,
|
||||
mActivityAllAppsContainerView, mStatsLogManager, mUserCache);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user