use of com.android.launcher3.util.LauncherModelHelper in project android_packages_apps_Launcher3 by ProtonAOSP.
the class LoaderCursorTest method setup.
@Before
public void setup() {
mModelHelper = new LauncherModelHelper();
mContext = mModelHelper.sandboxContext;
mIDP = InvariantDeviceProfile.INSTANCE.get(mContext);
mApp = LauncherAppState.getInstance(mContext);
mCursor = new MatrixCursor(new String[] { ICON, ICON_PACKAGE, ICON_RESOURCE, TITLE, _ID, CONTAINER, ITEM_TYPE, PROFILE_ID, SCREEN, CELLX, CELLY, RESTORED, INTENT });
UserManagerState ums = new UserManagerState();
mLoaderCursor = new LoaderCursor(mCursor, Favorites.CONTENT_URI, mApp, ums);
ums.allUsers.put(0, Process.myUserHandle());
}
use of com.android.launcher3.util.LauncherModelHelper in project android_packages_apps_Launcher3 by ProtonAOSP.
the class PackageInstallStateChangedTaskTest method setup.
@Before
public void setup() throws Exception {
mModelHelper = new LauncherModelHelper();
mModelHelper.initializeData("package_install_state_change_task_data");
}
use of com.android.launcher3.util.LauncherModelHelper in project android_packages_apps_Launcher3 by ProtonAOSP.
the class WidgetsPredicationUpdateTaskTest method setup.
@Before
public void setup() throws Exception {
mModelHelper = new LauncherModelHelper();
MockitoAnnotations.initMocks(this);
doAnswer(invocation -> {
ComponentWithLabel componentWithLabel = invocation.getArgument(0);
return componentWithLabel.getComponent().getShortClassName();
}).when(mIconCache).getTitleNoCache(any());
mUserHandle = myUserHandle();
mApp1Provider1 = createAppWidgetProviderInfo(ComponentName.createRelative("app1", "provider1"));
mApp1Provider2 = createAppWidgetProviderInfo(ComponentName.createRelative("app1", "provider2"));
mApp2Provider1 = createAppWidgetProviderInfo(ComponentName.createRelative("app2", "provider1"));
mApp4Provider1 = createAppWidgetProviderInfo(ComponentName.createRelative("app4", "provider1"));
mApp4Provider2 = createAppWidgetProviderInfo(ComponentName.createRelative("app4", ".provider2"));
mApp5Provider1 = createAppWidgetProviderInfo(ComponentName.createRelative("app5", "provider1"));
allWidgets = Arrays.asList(mApp1Provider1, mApp1Provider2, mApp2Provider1, mApp4Provider1, mApp4Provider2, mApp5Provider1);
AppWidgetManager manager = mModelHelper.sandboxContext.spyService(AppWidgetManager.class);
doReturn(allWidgets).when(manager).getInstalledProviders();
doReturn(allWidgets).when(manager).getInstalledProvidersForProfile(eq(myUserHandle()));
doAnswer(i -> {
String pkg = i.getArgument(0);
Log.e("Hello", "Getting v " + pkg);
return TextUtils.isEmpty(pkg) ? allWidgets : allWidgets.stream().filter(a -> pkg.equals(a.provider.getPackageName())).collect(Collectors.toList());
}).when(manager).getInstalledProvidersForPackage(any(), eq(myUserHandle()));
// 2 widgets, app4/provider1 & app5/provider1, have already been added to the workspace.
mModelHelper.initializeData("widgets_predication_update_task_data");
MAIN_EXECUTOR.submit(() -> mModelHelper.getModel().addCallbacks(mCallback)).get();
MODEL_EXECUTOR.post(() -> mModelHelper.getBgDataModel().widgetsModel.update(LauncherAppState.getInstance(mModelHelper.sandboxContext), /* packageUser= */
null));
MODEL_EXECUTOR.submit(() -> {
}).get();
MAIN_EXECUTOR.submit(() -> {
}).get();
}
use of com.android.launcher3.util.LauncherModelHelper in project android_packages_apps_Launcher3 by ProtonAOSP.
the class LauncherModelHelper method setupDefaultLayoutProvider.
/**
* Sets up a mock provider to load the provided layout by default, next time the layout loads
*/
public LauncherModelHelper setupDefaultLayoutProvider(LauncherLayoutBuilder builder) throws Exception {
InvariantDeviceProfile idp = InvariantDeviceProfile.INSTANCE.get(sandboxContext);
idp.numRows = idp.numColumns = idp.numDatabaseHotseatIcons = DEFAULT_GRID_SIZE;
idp.iconBitmapSize = DEFAULT_BITMAP_SIZE;
UiDevice.getInstance(getInstrumentation()).executeShellCommand("settings put secure launcher3.layout.provider " + TEST_PROVIDER_AUTHORITY);
ContentProvider cp = new TestInformationProvider() {
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
try {
ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
AutoCloseOutputStream outputStream = new AutoCloseOutputStream(pipe[1]);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
builder.build(new OutputStreamWriter(bos));
outputStream.write(bos.toByteArray());
outputStream.flush();
outputStream.close();
return pipe[0];
} catch (Exception e) {
throw new FileNotFoundException(e.getMessage());
}
}
};
setupProvider(TEST_PROVIDER_AUTHORITY, cp);
return this;
}
use of com.android.launcher3.util.LauncherModelHelper in project android_packages_apps_404Launcher by P-404.
the class CacheDataUpdatedTaskTest method setup.
@Before
public void setup() throws Exception {
mModelHelper = new LauncherModelHelper();
mModelHelper.initializeData("cache_data_updated_task_data");
// Add placeholder entries in the cache to simulate update
Context context = mModelHelper.sandboxContext;
IconCache iconCache = LauncherAppState.getInstance(context).getIconCache();
CachingLogic<ItemInfo> placeholderLogic = new CachingLogic<ItemInfo>() {
@Override
public ComponentName getComponent(ItemInfo info) {
return info.getTargetComponent();
}
@Override
public UserHandle getUser(ItemInfo info) {
return info.user;
}
@Override
public CharSequence getLabel(ItemInfo info) {
return NEW_LABEL_PREFIX + info.id;
}
@NonNull
@Override
public BitmapInfo loadIcon(Context context, ItemInfo info) {
return BitmapInfo.of(Bitmap.createBitmap(1, 1, Config.ARGB_8888), Color.RED);
}
};
UserManager um = context.getSystemService(UserManager.class);
for (ItemInfo info : mModelHelper.getBgDataModel().itemsIdMap) {
iconCache.addIconToDBAndMemCache(info, placeholderLogic, new PackageInfo(), um.getSerialNumberForUser(info.user), true);
}
}
Aggregations