Search in sources :

Example 1 with AppTargetId

use of android.app.prediction.AppTargetId in project android_packages_apps_Launcher3 by crdroidandroid.

the class AppEventProducer method toAppTarget.

@Nullable
private AppTarget toAppTarget(LauncherAtom.ItemInfo info) {
    UserHandle userHandle = Process.myUserHandle();
    if (info.getIsWork()) {
        userHandle = UserCache.INSTANCE.get(mContext).getUserProfiles().stream().filter(((Predicate<UserHandle>) userHandle::equals).negate()).findAny().orElse(null);
    }
    if (userHandle == null) {
        return null;
    }
    ComponentName cn = null;
    ShortcutInfo shortcutInfo = null;
    String id = null;
    switch(info.getItemCase()) {
        case APPLICATION:
            {
                LauncherAtom.Application app = info.getApplication();
                if ((cn = parseNullable(app.getComponentName())) != null) {
                    id = "app:" + cn.getPackageName();
                }
                break;
            }
        case SHORTCUT:
            {
                LauncherAtom.Shortcut si = info.getShortcut();
                if (!TextUtils.isEmpty(si.getShortcutId()) && (cn = parseNullable(si.getShortcutName())) != null) {
                    Optional<ShortcutInfo> opt = new ShortcutRequest(mContext, userHandle).forPackage(cn.getPackageName(), si.getShortcutId()).query(ShortcutRequest.ALL).stream().findFirst();
                    if (opt.isPresent()) {
                        shortcutInfo = opt.get();
                    } else {
                        return null;
                    }
                    id = "shortcut:" + si.getShortcutId();
                }
                break;
            }
        case WIDGET:
            {
                LauncherAtom.Widget widget = info.getWidget();
                if ((cn = parseNullable(widget.getComponentName())) != null) {
                    id = "widget:" + cn.getPackageName();
                }
                break;
            }
        case TASK:
            {
                LauncherAtom.Task task = info.getTask();
                if ((cn = parseNullable(task.getComponentName())) != null) {
                    id = "app:" + cn.getPackageName();
                }
                break;
            }
        case FOLDER_ICON:
            return createTempFolderTarget();
    }
    if (id != null && cn != null) {
        if (shortcutInfo != null) {
            return new AppTarget.Builder(new AppTargetId(id), shortcutInfo).build();
        }
        return new AppTarget.Builder(new AppTargetId(id), cn.getPackageName(), userHandle).setClassName(cn.getClassName()).build();
    }
    return null;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) Optional(java.util.Optional) AppTargetId(android.app.prediction.AppTargetId) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) Predicate(java.util.function.Predicate) AppTarget(android.app.prediction.AppTarget) UserHandle(android.os.UserHandle) ComponentName(android.content.ComponentName) Nullable(androidx.annotation.Nullable)

Example 2 with AppTargetId

use of android.app.prediction.AppTargetId in project android_packages_apps_Launcher3 by crdroidandroid.

the class WidgetsPredicationUpdateTaskTest method widgetsRecommendationRan_shouldOnlyReturnNotAddedWidgetsInAppPredictionOrder.

@Test
public void widgetsRecommendationRan_shouldOnlyReturnNotAddedWidgetsInAppPredictionOrder() throws Exception {
    // WHEN newPredicationTask is executed with app predication of 5 apps.
    AppTarget app1 = new AppTarget(new AppTargetId("app1"), "app1", "className", mUserHandle);
    AppTarget app2 = new AppTarget(new AppTargetId("app2"), "app2", "className", mUserHandle);
    AppTarget app3 = new AppTarget(new AppTargetId("app3"), "app3", "className", mUserHandle);
    AppTarget app4 = new AppTarget(new AppTargetId("app4"), "app4", "className", mUserHandle);
    AppTarget app5 = new AppTarget(new AppTargetId("app5"), "app5", "className", mUserHandle);
    mModelHelper.executeTaskForTest(newWidgetsPredicationTask(List.of(app5, app3, app2, app4, app1))).forEach(Runnable::run);
    // THEN only 3 widgets are returned because
    // 1. app5/provider1 & app4/provider1 have already been added to workspace. They are
    // excluded from the result.
    // 2. app3 doesn't have a widget.
    // 3. only 1 widget is picked from app1 because we only want to promote one widget per app.
    List<PendingAddWidgetInfo> recommendedWidgets = mCallback.mRecommendedWidgets.items.stream().map(itemInfo -> (PendingAddWidgetInfo) itemInfo).collect(Collectors.toList());
    assertThat(recommendedWidgets).hasSize(3);
    assertWidgetInfo(recommendedWidgets.get(0).info, mApp2Provider1);
    assertWidgetInfo(recommendedWidgets.get(1).info, mApp4Provider2);
    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) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) AppTargetId(android.app.prediction.AppTargetId) Test(org.junit.Test)

Example 3 with AppTargetId

use of android.app.prediction.AppTargetId 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)3 AppTargetId (android.app.prediction.AppTargetId)3 ComponentName (android.content.ComponentName)3 UserHandle (android.os.UserHandle)3 AppWidgetManager (android.appwidget.AppWidgetManager)2 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)2 Context (android.content.Context)2 Process (android.os.Process)2 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)2 LauncherAppState (com.android.launcher3.LauncherAppState)2 CONTAINER_WIDGETS_PREDICTION (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION)2 FeatureFlags (com.android.launcher3.config.FeatureFlags)2 ComponentWithLabel (com.android.launcher3.icons.ComponentWithLabel)2 IconCache (com.android.launcher3.icons.IconCache)2 FixedContainerItems (com.android.launcher3.model.BgDataModel.FixedContainerItems)2 PredictorState (com.android.launcher3.model.QuickstepModelDelegate.PredictorState)2 AppInfo (com.android.launcher3.model.data.AppInfo)2 ItemInfo (com.android.launcher3.model.data.ItemInfo)2 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)2 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)2