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;
}
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);
}
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);
}
Aggregations