Search in sources :

Example 1 with ShadowDeviceFlag

use of com.android.launcher3.shadows.ShadowDeviceFlag in project android_packages_apps_Launcher3 by crdroidandroid.

the class WidgetsPredicationUpdateTaskTest method widgetsRecommendationRan_localFilterDisabled_shouldReturnWidgetsInPredicationOrder.

@Test
public void widgetsRecommendationRan_localFilterDisabled_shouldReturnWidgetsInPredicationOrder() throws Exception {
    ShadowDeviceFlag shadowDeviceFlag = Shadow.extract(FeatureFlags.ENABLE_LOCAL_RECOMMENDED_WIDGETS_FILTER);
    shadowDeviceFlag.setValue(false);
    // WHEN newPredicationTask is executed with 5 predicated widgets.
    AppTarget widget1 = new AppTarget(new AppTargetId("app1"), "app1", "provider1", mUserHandle);
    AppTarget widget2 = new AppTarget(new AppTargetId("app1"), "app1", "provider2", mUserHandle);
    // Not installed app
    AppTarget widget3 = new AppTarget(new AppTargetId("app2"), "app3", "provider1", mUserHandle);
    // Not installed widget
    AppTarget widget4 = new AppTarget(new AppTargetId("app4"), "app4", "provider3", mUserHandle);
    AppTarget widget5 = new AppTarget(new AppTargetId("app5"), "app5", "provider1", mUserHandle);
    mModelHelper.executeTaskForTest(newWidgetsPredicationTask(List.of(widget5, widget3, widget2, widget4, widget1))).forEach(Runnable::run);
    // THEN only 3 widgets are returned because the launcher only filters out non-exist widgets.
    List<PendingAddWidgetInfo> recommendedWidgets = mCallback.mRecommendedWidgets.items.stream().map(itemInfo -> (PendingAddWidgetInfo) itemInfo).collect(Collectors.toList());
    assertThat(recommendedWidgets).hasSize(3);
    assertWidgetInfo(recommendedWidgets.get(0).info, mApp5Provider1);
    assertWidgetInfo(recommendedWidgets.get(1).info, mApp1Provider2);
    assertWidgetInfo(recommendedWidgets.get(2).info, mApp1Provider1);
}
Also used : CONTAINER_WIDGETS_PREDICTION(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION) ViewOnDrawExecutor(com.android.launcher3.util.ViewOnDrawExecutor) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) IconCache(com.android.launcher3.icons.IconCache) AppTarget(android.app.prediction.AppTarget) Process(android.os.Process) MockitoAnnotations(org.mockito.MockitoAnnotations) ReflectionHelpers(org.robolectric.util.ReflectionHelpers) Mockito.doAnswer(org.mockito.Mockito.doAnswer) MAIN_EXECUTOR(com.android.launcher3.util.Executors.MAIN_EXECUTOR) ShadowDeviceFlag(com.android.launcher3.shadows.ShadowDeviceFlag) LauncherModelHelper(com.android.launcher3.util.LauncherModelHelper) Shadow(org.robolectric.shadow.api.Shadow) RuntimeEnvironment(org.robolectric.RuntimeEnvironment) Collectors(java.util.stream.Collectors) RobolectricTestRunner(org.robolectric.RobolectricTestRunner) List(java.util.List) LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) ComponentWithLabel(com.android.launcher3.icons.ComponentWithLabel) ItemInfoMatcher(com.android.launcher3.util.ItemInfoMatcher) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Context(android.content.Context) MODEL_EXECUTOR(com.android.launcher3.util.Executors.MODEL_EXECUTOR) AppTargetId(android.app.prediction.AppTargetId) AppInfo(com.android.launcher3.model.data.AppInfo) Mock(org.mockito.Mock) ItemInfo(com.android.launcher3.model.data.ItemInfo) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Shadows.shadowOf(org.robolectric.Shadows.shadowOf) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ShadowAppWidgetManager(org.robolectric.shadows.ShadowAppWidgetManager) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) UserHandle(android.os.UserHandle) Before(org.junit.Before) IntArray(com.android.launcher3.util.IntArray) ComponentName(android.content.ComponentName) LauncherAppState(com.android.launcher3.LauncherAppState) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) FeatureFlags(com.android.launcher3.config.FeatureFlags) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) AppWidgetManager(android.appwidget.AppWidgetManager) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ShadowPackageManager(org.robolectric.shadows.ShadowPackageManager) WidgetsListBaseEntry(com.android.launcher3.widget.model.WidgetsListBaseEntry) ComponentKey(com.android.launcher3.util.ComponentKey) PredictorState(com.android.launcher3.model.QuickstepModelDelegate.PredictorState) AppTarget(android.app.prediction.AppTarget) ShadowDeviceFlag(com.android.launcher3.shadows.ShadowDeviceFlag) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) AppTargetId(android.app.prediction.AppTargetId) Test(org.junit.Test)

Aggregations

AppTarget (android.app.prediction.AppTarget)1 AppTargetId (android.app.prediction.AppTargetId)1 AppWidgetManager (android.appwidget.AppWidgetManager)1 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 Process (android.os.Process)1 UserHandle (android.os.UserHandle)1 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)1 LauncherAppState (com.android.launcher3.LauncherAppState)1 CONTAINER_WIDGETS_PREDICTION (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION)1 FeatureFlags (com.android.launcher3.config.FeatureFlags)1 ComponentWithLabel (com.android.launcher3.icons.ComponentWithLabel)1 IconCache (com.android.launcher3.icons.IconCache)1 FixedContainerItems (com.android.launcher3.model.BgDataModel.FixedContainerItems)1 PredictorState (com.android.launcher3.model.QuickstepModelDelegate.PredictorState)1 AppInfo (com.android.launcher3.model.data.AppInfo)1 ItemInfo (com.android.launcher3.model.data.ItemInfo)1 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)1 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)1