Search in sources :

Example 1 with LauncherLayoutBuilder

use of com.android.launcher3.util.LauncherLayoutBuilder in project android_packages_apps_Launcher3 by crdroidandroid.

the class DefaultLayoutProviderTest method testCustomProfileLoaded_with_widget.

@Test
public void testCustomProfileLoaded_with_widget() throws Exception {
    String pendingAppPkg = "com.test.pending";
    // Add a placeholder session info so that the widget exists
    SessionParams params = new SessionParams(SessionParams.MODE_FULL_INSTALL);
    params.setAppPackageName(pendingAppPkg);
    PackageInstaller installer = mTargetContext.getPackageManager().getPackageInstaller();
    int sessionId = installer.createSession(params);
    SessionInfo sessionInfo = installer.getSessionInfo(sessionId);
    setField(sessionInfo, "installerPackageName", "com.test");
    setField(sessionInfo, "appIcon", BitmapInfo.LOW_RES_ICON);
    writeLayoutAndLoad(new LauncherLayoutBuilder().atWorkspace(0, 1, 0).putWidget(pendingAppPkg, "PlaceholderWidget", 2, 2));
    // Verify widget
    assertEquals(1, mModelHelper.getBgDataModel().appWidgets.size());
    ItemInfo info = mModelHelper.getBgDataModel().appWidgets.get(0);
    assertEquals(LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET, info.itemType);
    assertEquals(2, info.spanX);
    assertEquals(2, info.spanY);
}
Also used : SessionParams(android.content.pm.PackageInstaller.SessionParams) LauncherLayoutBuilder(com.android.launcher3.util.LauncherLayoutBuilder) ItemInfo(com.android.launcher3.model.data.ItemInfo) PackageInstaller(android.content.pm.PackageInstaller) SessionInfo(android.content.pm.PackageInstaller.SessionInfo) Test(org.junit.Test)

Example 2 with LauncherLayoutBuilder

use of com.android.launcher3.util.LauncherLayoutBuilder in project android_packages_apps_Launcher3 by crdroidandroid.

the class DefaultLayoutProviderTest method testCustomProfileLoaded_with_folder_custom_title.

@Test
public void testCustomProfileLoaded_with_folder_custom_title() throws Exception {
    writeLayoutAndLoad(new LauncherLayoutBuilder().atHotseat(0).putFolder("CustomFolder").addApp(TEST_PACKAGE, TEST_PACKAGE).addApp(TEST_PACKAGE, TEST_PACKAGE).addApp(TEST_PACKAGE, TEST_PACKAGE).build());
    // Verify folder
    assertEquals(1, mModelHelper.getBgDataModel().workspaceItems.size());
    ItemInfo info = mModelHelper.getBgDataModel().workspaceItems.get(0);
    assertEquals(LauncherSettings.Favorites.ITEM_TYPE_FOLDER, info.itemType);
    assertEquals(3, ((FolderInfo) info).contents.size());
    assertEquals("CustomFolder", info.title.toString());
}
Also used : LauncherLayoutBuilder(com.android.launcher3.util.LauncherLayoutBuilder) ItemInfo(com.android.launcher3.model.data.ItemInfo) FolderInfo(com.android.launcher3.model.data.FolderInfo) Test(org.junit.Test)

Example 3 with LauncherLayoutBuilder

use of com.android.launcher3.util.LauncherLayoutBuilder in project android_packages_apps_Launcher3 by crdroidandroid.

the class ModelMultiCallbacksTest method setupWorkspacePages.

private void setupWorkspacePages(int pageCount) throws Exception {
    // Create a layout with 3 pages
    LauncherLayoutBuilder builder = new LauncherLayoutBuilder();
    for (int i = 0; i < pageCount; i++) {
        builder.atWorkspace(1, 1, i).putApp(TEST_PACKAGE, TEST_PACKAGE);
    }
    mModelHelper.setupDefaultLayoutProvider(builder);
}
Also used : LauncherLayoutBuilder(com.android.launcher3.util.LauncherLayoutBuilder)

Example 4 with LauncherLayoutBuilder

use of com.android.launcher3.util.LauncherLayoutBuilder in project android_packages_apps_Launcher3 by crdroidandroid.

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 {
    Context context = RuntimeEnvironment.application;
    InvariantDeviceProfile idp = InvariantDeviceProfile.INSTANCE.get(context);
    idp.numRows = idp.numColumns = idp.numDatabaseHotseatIcons = DEFAULT_GRID_SIZE;
    idp.iconBitmapSize = DEFAULT_BITMAP_SIZE;
    Settings.Secure.putString(context.getContentResolver(), "launcher3.layout.provider", TEST_PROVIDER_AUTHORITY);
    shadowOf(context.getPackageManager()).addProviderIfNotPresent(new ComponentName("com.test", "Mock")).authority = TEST_PROVIDER_AUTHORITY;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    builder.build(new OutputStreamWriter(bos));
    Uri layoutUri = LauncherProvider.getLayoutUri(TEST_PROVIDER_AUTHORITY, context);
    shadowOf(context.getContentResolver()).registerInputStream(layoutUri, new ByteArrayInputStream(bos.toByteArray()));
    return this;
}
Also used : Context(android.content.Context) ByteArrayInputStream(java.io.ByteArrayInputStream) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ComponentName(android.content.ComponentName) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Uri(android.net.Uri)

Example 5 with LauncherLayoutBuilder

use of com.android.launcher3.util.LauncherLayoutBuilder in project android_packages_apps_Launcher3 by AOSPA.

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;
}
Also used : TestInformationProvider(com.android.launcher3.testing.TestInformationProvider) ContentProvider(android.content.ContentProvider) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) AutoCloseOutputStream(android.os.ParcelFileDescriptor.AutoCloseOutputStream) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileNotFoundException(java.io.FileNotFoundException) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Uri(android.net.Uri) FileNotFoundException(java.io.FileNotFoundException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

LauncherLayoutBuilder (com.android.launcher3.util.LauncherLayoutBuilder)36 Test (org.junit.Test)27 ItemInfo (com.android.launcher3.model.data.ItemInfo)24 SmallTest (androidx.test.filters.SmallTest)16 FolderInfo (com.android.launcher3.model.data.FolderInfo)12 PackageInstaller (android.content.pm.PackageInstaller)6 SessionParams (android.content.pm.PackageInstaller.SessionParams)6 Uri (android.net.Uri)6 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 OutputStreamWriter (java.io.OutputStreamWriter)6 ContentProvider (android.content.ContentProvider)4 ParcelFileDescriptor (android.os.ParcelFileDescriptor)4 AutoCloseOutputStream (android.os.ParcelFileDescriptor.AutoCloseOutputStream)4 TestInformationProvider (com.android.launcher3.testing.TestInformationProvider)4 FileNotFoundException (java.io.FileNotFoundException)4 ExecutionException (java.util.concurrent.ExecutionException)4 MediumTest (androidx.test.filters.MediumTest)3 LauncherModelHelper (com.android.launcher3.util.LauncherModelHelper)3 Before (org.junit.Before)3