Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2000228d authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Adding support for multiple Model clients" into ub-launcher3-master

parents 0e7a81ea a7a5bf31
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -16,10 +16,11 @@

package com.android.launcher3.model;

import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;

import com.android.launcher3.LauncherAppState;
import com.android.launcher3.model.BgDataModel.Callbacks;

import java.lang.ref.WeakReference;
import com.android.launcher3.util.LooperExecutor;

/**
 * Helper class to handle results of {@link com.android.launcher3.model.LoaderTask}.
@@ -27,8 +28,13 @@ import java.lang.ref.WeakReference;
public class LoaderResults extends BaseLoaderResults {

    public LoaderResults(LauncherAppState app, BgDataModel dataModel,
            AllAppsList allAppsList, int pageToBindFirst, WeakReference<Callbacks> callbacks) {
        super(app, dataModel, allAppsList, pageToBindFirst, callbacks);
            AllAppsList allAppsList, Callbacks[] callbacks) {
        this(app, dataModel, allAppsList, callbacks, MAIN_EXECUTOR);
    }

    public LoaderResults(LauncherAppState app, BgDataModel dataModel,
            AllAppsList allAppsList, Callbacks[] callbacks, LooperExecutor executor) {
        super(app, dataModel, allAppsList, callbacks, executor);
    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ public class HotseatEduController {
    }

    void finishOnboarding() {
        mLauncher.rebindModel();
        mLauncher.getModel().rebindCallbacks();
        mLauncher.getSharedPrefs().edit().putBoolean(KEY_HOTSEAT_EDU_SEEN, true).apply();
        removeNotification();
    }
+1 −1
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@ public class AddWorkspaceItemsTaskTest {
    @Test
    public void testAddItem_some_items_added() throws Exception {
        Callbacks callbacks = mock(Callbacks.class);
        mModelHelper.getModel().initialize(callbacks);
        mModelHelper.getModel().addCallbacks(callbacks);

        WorkspaceItemInfo info = new WorkspaceItemInfo();
        info.intent = new Intent().setComponent(mComponent1);
+10 −42
Original line number Diff line number Diff line
@@ -16,8 +16,9 @@

package com.android.launcher3.model;

import static com.android.launcher3.util.LauncherModelHelper.TEST_PACKAGE;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.robolectric.Shadows.shadowOf;
import static org.robolectric.util.ReflectionHelpers.setField;

@@ -26,14 +27,10 @@ import android.content.Context;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.SessionInfo;
import android.content.pm.PackageInstaller.SessionParams;
import android.net.Uri;
import android.provider.Settings;

import com.android.launcher3.FolderInfo;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherProvider;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.icons.BitmapInfo;
import com.android.launcher3.model.BgDataModel.Callbacks;
@@ -48,12 +45,7 @@ import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.LooperMode;
import org.robolectric.annotation.LooperMode.Mode;
import org.robolectric.shadows.ShadowPackageManager;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStreamWriter;
import java.lang.ref.WeakReference;
import java.util.ArrayList;

/**
@@ -63,40 +55,22 @@ import java.util.ArrayList;
@LooperMode(Mode.PAUSED)
public class DefaultLayoutProviderTest {

    private static final String SETTINGS_APP = "com.android.settings";
    private static final String TEST_PROVIDER_AUTHORITY =
            DefaultLayoutProviderTest.class.getName().toLowerCase();

    private static final int BITMAP_SIZE = 10;
    private static final int GRID_SIZE = 4;

    private LauncherModelHelper mModelHelper;
    private Context mTargetContext;
    private InvariantDeviceProfile mIdp;

    @Before
    public void setUp() {
        mModelHelper = new LauncherModelHelper();
        mTargetContext = RuntimeEnvironment.application;

        mIdp = InvariantDeviceProfile.INSTANCE.get(mTargetContext);
        mIdp.numRows = mIdp.numColumns = mIdp.numHotseatIcons = GRID_SIZE;
        mIdp.iconBitmapSize = BITMAP_SIZE;

        mModelHelper.provider.setAllowLoadDefaultFavorites(true);
        Settings.Secure.putString(mTargetContext.getContentResolver(),
                "launcher3.layout.provider", TEST_PROVIDER_AUTHORITY);

        ShadowPackageManager spm = shadowOf(mTargetContext.getPackageManager());
        spm.addProviderIfNotPresent(new ComponentName("com.test", "Dummy")).authority =
                TEST_PROVIDER_AUTHORITY;
        spm.addActivityIfNotPresent(new ComponentName(SETTINGS_APP, SETTINGS_APP));
        shadowOf(mTargetContext.getPackageManager())
                .addActivityIfNotPresent(new ComponentName(TEST_PACKAGE, TEST_PACKAGE));
    }

    @Test
    public void testCustomProfileLoaded_with_icon_on_hotseat() throws Exception {
        writeLayoutAndLoad(new LauncherLayoutBuilder().atHotseat(0)
                .putApp(SETTINGS_APP, SETTINGS_APP));
                .putApp(TEST_PACKAGE, TEST_PACKAGE));

        // Verify one item in hotseat
        assertEquals(1, mModelHelper.getBgDataModel().workspaceItems.size());
@@ -108,9 +82,9 @@ public class DefaultLayoutProviderTest {
    @Test
    public void testCustomProfileLoaded_with_folder() throws Exception {
        writeLayoutAndLoad(new LauncherLayoutBuilder().atHotseat(0).putFolder(android.R.string.copy)
                .addApp(SETTINGS_APP, SETTINGS_APP)
                .addApp(SETTINGS_APP, SETTINGS_APP)
                .addApp(SETTINGS_APP, SETTINGS_APP)
                .addApp(TEST_PACKAGE, TEST_PACKAGE)
                .addApp(TEST_PACKAGE, TEST_PACKAGE)
                .addApp(TEST_PACKAGE, TEST_PACKAGE)
                .build());

        // Verify folder
@@ -146,19 +120,13 @@ public class DefaultLayoutProviderTest {
    }

    private void writeLayoutAndLoad(LauncherLayoutBuilder builder) throws Exception {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        builder.build(new OutputStreamWriter(bos));

        Uri layoutUri = LauncherProvider.getLayoutUri(TEST_PROVIDER_AUTHORITY, mTargetContext);
        shadowOf(mTargetContext.getContentResolver()).registerInputStream(layoutUri,
                new ByteArrayInputStream(bos.toByteArray()));
        mModelHelper.setupDefaultLayoutProvider(builder);

        LoaderResults results = new LoaderResults(
                LauncherAppState.getInstance(mTargetContext),
                mModelHelper.getBgDataModel(),
                mModelHelper.getAllAppsList(),
                0,
                new WeakReference<>(mock(Callbacks.class)));
                new Callbacks[0]);
        LoaderTask task = new LoaderTask(
                LauncherAppState.getInstance(mTargetContext),
                mModelHelper.getAllAppsList(),
+2 −2
Original line number Diff line number Diff line
@@ -190,7 +190,7 @@ public class GridSizeMigrationTaskTest {

    @Test
    public void testWorkspace_items_not_merged_in_next_screen() throws Exception {
        // First screen has 2 items that need to be moved, but second screen has only one
        // First screen has 2 mItems that need to be moved, but second screen has only one
        // empty space after migration (top-left corner)
        int[][][] ids = mModelHelper.createGrid(new int[][][]{{
                {  0,  0,  0,  1},
@@ -277,7 +277,7 @@ public class GridSizeMigrationTaskTest {
    }

    /**
     * Verifies that the workspace items are arranged in the provided order.
     * Verifies that the workspace mItems are arranged in the provided order.
     * @param ids A 3d array where the first dimension represents the screen, and the rest two
     *            represent the workspace grid.
     */
Loading