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

Commit 7b9e28f1 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Removing all usage of LauncherProvider

Also fixing a race condition in model when an item update/delete task
gets queued and executed after the model has reloaded (making the old
data obsolete)

Bug: 277345535
Bug: 263079498
Test: Presubmit
Flag: N/A
Change-Id: Ibd4bdbb3eece05b38b73a22a4be5f368df3754f0
parent 859d0d87
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ import androidx.annotation.Nullable;

import com.android.launcher3.BubbleTextView;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.ShortcutAndWidgetContainer;
import com.android.launcher3.testing.shared.TestProtocol;

@@ -189,10 +189,11 @@ public class DebugTestInformationHandler extends TestInformationHandler {
            case TestProtocol.REQUEST_CLEAR_DATA: {
                final long identity = Binder.clearCallingIdentity();
                try {
                    LauncherSettings.Settings.call(mContext.getContentResolver(),
                            LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB);
                    MAIN_EXECUTOR.submit(() ->
                            LauncherAppState.getInstance(mContext).getModel().forceReload());
                    MODEL_EXECUTOR.execute(() -> {
                        LauncherModel model = LauncherAppState.getInstance(mContext).getModel();
                        model.getModelDbController().createEmptyDB();
                        MAIN_EXECUTOR.execute(model::forceReload);
                    });
                    return response;
                } finally {
                    Binder.restoreCallingIdentity(identity);
+1 −3
Original line number Diff line number Diff line
@@ -95,9 +95,7 @@ public class HotseatEduController {
            }
        }
        if (pageId == -1) {
            pageId = LauncherSettings.Settings.call(mLauncher.getContentResolver(),
                    LauncherSettings.Settings.METHOD_NEW_SCREEN_ID)
                    .getInt(LauncherSettings.Settings.EXTRA_VALUE);
            pageId = mLauncher.getModel().getModelDbController().getNewScreenId();
            mNewScreens = IntArray.wrap(pageId);
        }
        boolean isPortrait = !mLauncher.getDeviceProfile().isVerticalBarLayout();
+10 −15
Original line number Diff line number Diff line
@@ -22,9 +22,10 @@ import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
import android.content.Context;

import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.model.GridBackupTable;
import com.android.launcher3.provider.LauncherDbUtils;
import com.android.launcher3.model.ModelDbController;
import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction;

/**
 * A helper class to manage migration revert restoration for hybrid hotseat
@@ -36,16 +37,13 @@ public class HotseatRestoreHelper {
     */
    public static void createBackup(Context context) {
        MODEL_EXECUTOR.execute(() -> {
            try (LauncherDbUtils.SQLiteTransaction transaction = (LauncherDbUtils.SQLiteTransaction)
                    LauncherSettings.Settings.call(
                            context.getContentResolver(),
                            LauncherSettings.Settings.METHOD_NEW_TRANSACTION)
                            .getBinder(LauncherSettings.Settings.EXTRA_VALUE)) {
            ModelDbController dbController = LauncherAppState.getInstance(context)
                    .getModel().getModelDbController();
            try (SQLiteTransaction transaction = dbController.newTransaction()) {
                GridBackupTable backupTable = new GridBackupTable(context, transaction.getDb());
                backupTable.createCustomBackupTable(HYBRID_HOTSEAT_BACKUP_TABLE);
                transaction.commit();
                LauncherSettings.Settings.call(context.getContentResolver(),
                        LauncherSettings.Settings.METHOD_REFRESH_HOTSEAT_RESTORE_TABLE);
                dbController.refreshHotseatRestoreTable();
            }
        });
    }
@@ -55,18 +53,15 @@ public class HotseatRestoreHelper {
     */
    public static void restoreBackup(Context context) {
        MODEL_EXECUTOR.execute(() -> {
            try (LauncherDbUtils.SQLiteTransaction transaction = (LauncherDbUtils.SQLiteTransaction)
                    LauncherSettings.Settings.call(
                            context.getContentResolver(),
                            LauncherSettings.Settings.METHOD_NEW_TRANSACTION)
                            .getBinder(LauncherSettings.Settings.EXTRA_VALUE)) {
            LauncherModel model = LauncherAppState.getInstance(context).getModel();
            try (SQLiteTransaction transaction = model.getModelDbController().newTransaction()) {
                if (!tableExists(transaction.getDb(), HYBRID_HOTSEAT_BACKUP_TABLE)) {
                    return;
                }
                GridBackupTable backupTable = new GridBackupTable(context, transaction.getDb());
                backupTable.restoreFromCustomBackupTable(HYBRID_HOTSEAT_BACKUP_TABLE, true);
                transaction.commit();
                LauncherAppState.getInstance(context).getModel().forceReload();
                model.forceReload();
            }
        });
    }
+24 −17
Original line number Diff line number Diff line
@@ -17,8 +17,8 @@ package com.android.quickstep;

import static androidx.test.InstrumentationRegistry.getContext;
import static androidx.test.InstrumentationRegistry.getInstrumentation;
import static androidx.test.InstrumentationRegistry.getTargetContext;

import static com.android.launcher3.WorkspaceLayoutManager.FIRST_SCREEN_ID;
import static com.android.launcher3.testcomponent.TestCommandReceiver.EXTRA_VALUE;
import static com.android.launcher3.testcomponent.TestCommandReceiver.SET_LIST_VIEW_SERVICE_BINDER;
import static com.android.launcher3.util.WidgetUtils.createWidgetInfo;
@@ -32,7 +32,6 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.spy;

import android.appwidget.AppWidgetManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@@ -42,14 +41,16 @@ import android.view.View;
import android.view.ViewConfiguration;
import android.widget.RemoteViews;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.filters.Suppress;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.Until;

import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.celllayout.FavoriteItemsTransaction;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.tapl.LaunchedAppState;
import com.android.launcher3.testcomponent.ListViewService;
@@ -57,6 +58,7 @@ import com.android.launcher3.testcomponent.ListViewService.SimpleViewsFactory;
import com.android.launcher3.testcomponent.TestCommandReceiver;
import com.android.launcher3.ui.TaplTestsLauncher3;
import com.android.launcher3.ui.TestViewHelpers;
import com.android.launcher3.util.Executors;
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch;

@@ -67,6 +69,7 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import java.lang.reflect.Field;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.IntConsumer;

/**
@@ -84,9 +87,9 @@ import java.util.function.IntConsumer;
@RunWith(AndroidJUnit4.class)
public class ViewInflationDuringSwipeUp extends AbstractQuickStepTest {

    private ContentResolver mResolver;
    private SparseArray<ViewConfiguration> mConfigMap;
    private InitTracker mInitTracker;
    private LauncherModel mModel;

    @Before
    public void setUp() throws Exception {
@@ -101,8 +104,8 @@ public class ViewInflationDuringSwipeUp extends AbstractQuickStepTest {

        TaplTestsLauncher3.initialize(this);

        mResolver = mTargetContext.getContentResolver();
        LauncherSettings.Settings.call(mResolver, LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB);
        mModel = LauncherAppState.getInstance(mTargetContext).getModel();
        Executors.MODEL_EXECUTOR.submit(mModel.getModelDbController()::createEmptyDB).get();

        // Get static configuration map
        Field field = ViewConfiguration.class.getDeclaredField("sConfigurations");
@@ -182,26 +185,30 @@ public class ViewInflationDuringSwipeUp extends AbstractQuickStepTest {
    private void executeSwipeUpTestWithWidget(IntConsumer widgetIdCreationCallback,
            IntConsumer updateBeforeSwipeUp, String finalWidgetText) {
        try {
            // Clear all existing data
            LauncherSettings.Settings.call(mResolver,
                    LauncherSettings.Settings.METHOD_CREATE_EMPTY_DB);
            LauncherSettings.Settings.call(mResolver,
                    LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG);
            LauncherAppWidgetProviderInfo info = TestViewHelpers.findWidgetProvider(false);

            // Make sure the widget is big enough to show a list of items
            info.minSpanX = 2;
            info.minSpanY = 2;
            info.spanX = 2;
            info.spanY = 2;
            LauncherAppWidgetInfo item = createWidgetInfo(info, getTargetContext(), true);
            AtomicInteger widgetId = new AtomicInteger();
            new FavoriteItemsTransaction(mTargetContext)
                    .addItem(() -> {
                        LauncherAppWidgetInfo item = createWidgetInfo(info, mTargetContext, true);
                        item.screenId = FIRST_SCREEN_ID;
                        widgetId.set(item.appWidgetId);
                        return item;
                    })
                    .commitAndLoadHome(mLauncher);



            addItemToScreen(item);
            assertTrue("Widget is not present",
                    mLauncher.goHome().tryGetWidget(info.label, DEFAULT_UI_TIMEOUT) != null);
            int widgetId = item.appWidgetId;

            // Verify widget id
            widgetIdCreationCallback.accept(widgetId);
            widgetIdCreationCallback.accept(widgetId.get());

            // Go to overview once so that all views are initialized and cached
            startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
@@ -214,7 +221,7 @@ public class ViewInflationDuringSwipeUp extends AbstractQuickStepTest {
            LaunchedAppState launchedAppState = mLauncher.getLaunchedAppState();

            // Update widget
            updateBeforeSwipeUp.accept(widgetId);
            updateBeforeSwipeUp.accept(widgetId.get());

            launchedAppState.switchToOverview();
            assertEquals("Views inflated during swipe up", 0, mInitTracker.viewInitCount);
+4 −6
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.launcher3;

import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
import static com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME;
import static com.android.launcher3.provider.LauncherDbUtils.itemIdMatch;

import android.content.ComponentName;
import android.content.ContentValues;
@@ -30,7 +32,6 @@ import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.content.res.XmlResourceParser;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.os.Process;
import android.text.TextUtils;
@@ -44,7 +45,6 @@ import androidx.annotation.StringRes;
import androidx.annotation.WorkerThread;
import androidx.annotation.XmlRes;

import com.android.launcher3.LauncherProvider.SqlArguments;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
@@ -619,9 +619,7 @@ public class AutoInstallsLayout {
            // failed to add, and less than 2 were actually added
            if (folderItems.size() < 2) {
                // Delete the folder
                Uri uri = Favorites.getContentUri(folderId);
                SqlArguments args = new SqlArguments(uri, null, null);
                mDb.delete(args.table, args.where, args.args);
                mDb.delete(TABLE_NAME, itemIdMatch(folderId), null);
                addedId = -1;

                // If we have a single item, promote it to where the folder
@@ -634,7 +632,7 @@ public class AutoInstallsLayout {
                    copyInteger(myValues, childValues, Favorites.CELLY);

                    addedId = folderItems.get(0);
                    mDb.update(Favorites.TABLE_NAME, childValues,
                    mDb.update(TABLE_NAME, childValues,
                            Favorites._ID + "=" + addedId, null);
                }
            }
Loading