diff --git a/aconfig/launcher.aconfig b/aconfig/launcher.aconfig index 1856b39372..4ff976d148 100644 --- a/aconfig/launcher.aconfig +++ b/aconfig/launcher.aconfig @@ -501,10 +501,13 @@ flag { } flag { - name: "enforce_system_radius_for_app_widgets" + name: "use_system_radius_for_app_widgets" namespace: "launcher" - description: "Enforce system radius for widget corners instead of a separate 16.dp value" - bug: "370950552" + description: "Use system radius for enforced widget corners instead of a separate 16.dp value" + bug: "373351337" + metadata { + purpose: PURPOSE_BUGFIX + } } flag { diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml index 53f37ba45b..b221b22e80 100644 --- a/quickstep/res/values/dimens.xml +++ b/quickstep/res/values/dimens.xml @@ -362,11 +362,6 @@ 12dp 4dp 6dp - 22dp - 15dp - 2dp - 18dp - 15dp 12dp diff --git a/quickstep/res/values/styles.xml b/quickstep/res/values/styles.xml index c423d094bf..6ffcb9b687 100644 --- a/quickstep/res/values/styles.xml +++ b/quickstep/res/values/styles.xml @@ -211,6 +211,7 @@ false true @android:color/transparent + false + android:bottom="@dimen/all_apps_tabs_focus_vertical_inset" + android:end="@dimen/all_apps_tabs_focus_horizontal_inset" + android:start="@dimen/all_apps_tabs_focus_horizontal_inset" + android:top="@dimen/all_apps_tabs_focus_vertical_inset"> diff --git a/res/drawable/all_apps_tabs_background_unselected.xml b/res/drawable/all_apps_tabs_background_unselected.xml index ab592a8304..ce7b334687 100644 --- a/res/drawable/all_apps_tabs_background_unselected.xml +++ b/res/drawable/all_apps_tabs_background_unselected.xml @@ -15,10 +15,10 @@ --> + android:bottom="@dimen/all_apps_tabs_focus_vertical_inset" + android:end="@dimen/all_apps_tabs_focus_horizontal_inset" + android:start="@dimen/all_apps_tabs_focus_horizontal_inset" + android:top="@dimen/all_apps_tabs_focus_vertical_inset"> diff --git a/res/layout/add_item_confirmation_activity.xml b/res/layout/add_item_confirmation_activity.xml index d113a38ac8..2bb2eb3097 100644 --- a/res/layout/add_item_confirmation_activity.xml +++ b/res/layout/add_item_confirmation_activity.xml @@ -71,7 +71,8 @@ android:id="@+id/widget_preview_scroll_view" android:layout_width="match_parent" android:layout_height="0dp" - android:layout_marginVertical="16dp" + android:layout_margin="16dp" + android:background="@drawable/widgets_surface_background" android:layout_weight="1"> - + - + diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 61d99d743b..0d4e79b0fd 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -125,9 +125,8 @@ 16dp 20dp 4dp - 6dp - 1dp - 5dp + 5dp + 6dp 3dp 2dp 8dp diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java index 3d715e59a8..867bf98e47 100644 --- a/src/com/android/launcher3/ButtonDropTarget.java +++ b/src/com/android/launcher3/ButtonDropTarget.java @@ -41,8 +41,11 @@ import com.android.launcher3.dragndrop.DragLayer; import com.android.launcher3.dragndrop.DragOptions; import com.android.launcher3.dragndrop.DragView; import com.android.launcher3.model.data.ItemInfo; +import com.android.launcher3.util.MSDLPlayerWrapper; import com.android.launcher3.views.ActivityContext; +import com.google.android.msdl.data.model.MSDLToken; + /** * Implements a DropTarget. */ @@ -62,6 +65,7 @@ public abstract class ButtonDropTarget extends TextView protected final ActivityContext mActivityContext; protected final DropTargetHandler mDropTargetHandler; protected DropTargetBar mDropTargetBar; + private final MSDLPlayerWrapper mMSDLPlayerWrapper; /** Whether this drop target is active for the current drag */ protected boolean mActive; @@ -94,6 +98,7 @@ public abstract class ButtonDropTarget extends TextView super(context, attrs, defStyle); mActivityContext = ActivityContext.lookupContext(context); mDropTargetHandler = mActivityContext.getDropTargetHandler(); + mMSDLPlayerWrapper = MSDLPlayerWrapper.INSTANCE.get(context); Resources resources = getResources(); mDragDistanceThreshold = resources.getDimensionPixelSize(R.dimen.drag_distanceThreshold); @@ -142,6 +147,10 @@ public abstract class ButtonDropTarget extends TextView @Override public final void onDragEnter(DragObject d) { + // Perform Haptic feedback + if (Flags.msdlFeedback()) { + mMSDLPlayerWrapper.playToken(MSDLToken.SWIPE_THRESHOLD_INDICATOR); + } if (!mAccessibleDrag && !mTextVisible) { // Show tooltip hideTooltip(); diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index e18862a493..e1d84be3d9 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -651,14 +651,14 @@ public class InvariantDeviceProfile implements SafeCloseable { } /** - * Parses through the xml to find NumRows specs. Then calls findBestRowCount to get the correct - * row count for this GridOption. + * Parses through the xml to find GridDimension specs. Then calls findBestRowCount to get the + * correct row count for this GridOption. * * @return the result of {@link #findBestRowCount(List, Info)}. */ - public static NumRows getRowCount(ResourceHelper resourceHelper, Context context, + public static GridDimension getRowCount(ResourceHelper resourceHelper, Context context, Info displayInfo) { - ArrayList rowCounts = new ArrayList<>(); + ArrayList rowCounts = new ArrayList<>(); try (XmlResourceParser parser = resourceHelper.getXml()) { final int depth = parser.getDepth(); @@ -666,8 +666,8 @@ public class InvariantDeviceProfile implements SafeCloseable { while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if ((type == XmlPullParser.START_TAG) - && "NumRows".equals(parser.getName())) { - rowCounts.add(new NumRows(context, Xml.asAttributeSet(parser))); + && "GridDimension".equals(parser.getName())) { + rowCounts.add(new GridDimension(context, Xml.asAttributeSet(parser))); } } } catch (IOException | XmlPullParserException e) { @@ -678,10 +678,10 @@ public class InvariantDeviceProfile implements SafeCloseable { } /** - * @return the biggest row count that fits the display dimensions spec using NumRows to + * @return the biggest row count that fits the display dimensions spec using GridDimension to * determine that. If no best row count is found, return -1. */ - public static NumRows findBestRowCount(List list, Info displayInfo) { + public static GridDimension findBestRowCount(List list, Info displayInfo) { int minWidthPx = Integer.MAX_VALUE; int minHeightPx = Integer.MAX_VALUE; for (WindowBounds bounds : displayInfo.supportedBounds) { @@ -700,10 +700,10 @@ public class InvariantDeviceProfile implements SafeCloseable { } } - NumRows selectedRow = null; - for (NumRows item: list) { + GridDimension selectedRow = null; + for (GridDimension item: list) { if (minWidthPx >= item.mMinDeviceWidthPx && minHeightPx >= item.mMinDeviceHeightPx) { - if (selectedRow == null || selectedRow.mNumRowsNew < item.mNumRowsNew) { + if (selectedRow == null || selectedRow.mNumGridDimension < item.mNumGridDimension) { selectedRow = item; } } @@ -1045,8 +1045,8 @@ public class InvariantDeviceProfile implements SafeCloseable { mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false); if (mRowCountSpecsId != INVALID_RESOURCE_HANDLE) { ResourceHelper resourceHelper = new ResourceHelper(context, mRowCountSpecsId); - NumRows numR = getRowCount(resourceHelper, context, displayInfo); - numRows = numR.mNumRowsNew; + GridDimension numR = getRowCount(resourceHelper, context, displayInfo); + numRows = numR.mNumGridDimension; dbFile = numR.mDbFile; defaultLayoutId = numR.mDefaultLayoutId; demoModeLayoutId = numR.mDemoModeLayoutId; @@ -1235,8 +1235,8 @@ public class InvariantDeviceProfile implements SafeCloseable { } } - public static final class NumRows { - final int mNumRowsNew; + public static final class GridDimension { + final int mNumGridDimension; final float mMinDeviceWidthPx; final float mMinDeviceHeightPx; final String mDbFile; @@ -1244,17 +1244,17 @@ public class InvariantDeviceProfile implements SafeCloseable { final int mDemoModeLayoutId; - NumRows(Context context, AttributeSet attrs) { - TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumRows); + GridDimension(Context context, AttributeSet attrs) { + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridDimension); - mNumRowsNew = (int) a.getFloat(R.styleable.NumRows_numRowsNew, 0); - mMinDeviceWidthPx = a.getFloat(R.styleable.NumRows_minDeviceWidthPx, 0); - mMinDeviceHeightPx = a.getFloat(R.styleable.NumRows_minDeviceHeightPx, 0); - mDbFile = a.getString(R.styleable.NumRows_dbFile); + mNumGridDimension = (int) a.getFloat(R.styleable.GridDimension_numGridDimension, 0); + mMinDeviceWidthPx = a.getFloat(R.styleable.GridDimension_minDeviceWidthPx, 0); + mMinDeviceHeightPx = a.getFloat(R.styleable.GridDimension_minDeviceHeightPx, 0); + mDbFile = a.getString(R.styleable.GridDimension_dbFile); mDefaultLayoutId = a.getResourceId( - R.styleable.NumRows_defaultLayoutId, 0); + R.styleable.GridDimension_defaultLayoutId, 0); mDemoModeLayoutId = a.getResourceId( - R.styleable.NumRows_demoModeLayoutId, mDefaultLayoutId); + R.styleable.GridDimension_demoModeLayoutId, mDefaultLayoutId); a.recycle(); } diff --git a/src/com/android/launcher3/util/MSDLPlayerWrapper.java b/src/com/android/launcher3/util/MSDLPlayerWrapper.java index 1e53ac1e8a..aab70090a0 100644 --- a/src/com/android/launcher3/util/MSDLPlayerWrapper.java +++ b/src/com/android/launcher3/util/MSDLPlayerWrapper.java @@ -28,6 +28,9 @@ import com.android.launcher3.dagger.LauncherBaseAppComponent; import com.google.android.msdl.data.model.MSDLToken; import com.google.android.msdl.domain.InteractionProperties; import com.google.android.msdl.domain.MSDLPlayer; +import com.google.android.msdl.logging.MSDLEvent; + +import java.util.List; import javax.inject.Inject; @@ -58,4 +61,8 @@ public class MSDLPlayerWrapper { public void playToken(MSDLToken token) { mMSDLPlayer.playToken(token, null); } + + public List getHistory() { + return mMSDLPlayer.getHistory(); + } } diff --git a/src/com/android/launcher3/widget/RoundedCornerEnforcement.java b/src/com/android/launcher3/widget/RoundedCornerEnforcement.java index e190dc3749..2c07fd9ad1 100644 --- a/src/com/android/launcher3/widget/RoundedCornerEnforcement.java +++ b/src/com/android/launcher3/widget/RoundedCornerEnforcement.java @@ -16,7 +16,7 @@ package com.android.launcher3.widget; -import static com.android.launcher3.Flags.enforceSystemRadiusForAppWidgets; +import static com.android.launcher3.Flags.useSystemRadiusForAppWidgets; import android.appwidget.AppWidgetHostView; import android.content.Context; @@ -99,7 +99,7 @@ public class RoundedCornerEnforcement { public static float computeEnforcedRadius(@NonNull Context context) { Resources res = context.getResources(); float systemRadius = res.getDimension(android.R.dimen.system_app_widget_background_radius); - if (enforceSystemRadiusForAppWidgets()) { + if (useSystemRadiusForAppWidgets()) { return systemRadius; } diff --git a/tests/multivalentTests/src/com/android/launcher3/AbstractDeviceProfileTest.kt b/tests/multivalentTests/src/com/android/launcher3/AbstractDeviceProfileTest.kt index f8794f86b4..c4519ebfd5 100644 --- a/tests/multivalentTests/src/com/android/launcher3/AbstractDeviceProfileTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/AbstractDeviceProfileTest.kt @@ -168,7 +168,6 @@ abstract class AbstractDeviceProfileTest { isLandscape: Boolean = false, isGestureMode: Boolean = true, isFolded: Boolean = false, - isFixedLandscape: Boolean = false, ) { val (unfoldedNaturalX, unfoldedNaturalY) = deviceSpecUnfolded.naturalSize val unfoldedWindowsBounds = @@ -195,7 +194,6 @@ abstract class AbstractDeviceProfileTest { rotation = if (isLandscape) Surface.ROTATION_90 else Surface.ROTATION_0, isGestureMode = isGestureMode, densityDpi = deviceSpecFolded.densityDpi, - isFixedLandscape = isFixedLandscape, ) } else { initializeCommonVars( @@ -204,7 +202,6 @@ abstract class AbstractDeviceProfileTest { rotation = if (isLandscape) Surface.ROTATION_0 else Surface.ROTATION_90, isGestureMode = isGestureMode, densityDpi = deviceSpecUnfolded.densityDpi, - isFixedLandscape = isFixedLandscape, ) } } diff --git a/tests/multivalentTests/src/com/android/launcher3/DeleteDropTargetTest.kt b/tests/multivalentTests/src/com/android/launcher3/DeleteDropTargetTest.kt index 46e66e404d..42374a569b 100644 --- a/tests/multivalentTests/src/com/android/launcher3/DeleteDropTargetTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/DeleteDropTargetTest.kt @@ -1,20 +1,29 @@ package com.android.launcher3 import android.content.Context +import android.platform.test.annotations.EnableFlags +import android.platform.test.flag.junit.SetFlagsRule import androidx.test.core.app.ApplicationProvider.getApplicationContext import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.launcher3.Utilities.* +import com.android.launcher3.dragndrop.DragView import com.android.launcher3.util.ActivityContextWrapper +import com.android.launcher3.util.MSDLPlayerWrapper +import com.google.android.msdl.data.model.MSDLToken import com.google.common.truth.Truth.assertThat import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import org.mockito.kotlin.mock @SmallTest @RunWith(AndroidJUnit4::class) class DeleteDropTargetTest { + @get:Rule val mSetFlagsRule = SetFlagsRule() + private var mContext: Context = ActivityContextWrapper(getApplicationContext()) // Use a non-abstract class implementation @@ -37,4 +46,17 @@ class DeleteDropTargetTest { // A lot of space for text so the text should not be clipped assertThat(buttonDropTarget.isTextClippedVertically(1000)).isFalse() } + + @Test + @EnableFlags(Flags.FLAG_MSDL_FEEDBACK) + fun onDragEnter_performsMSDLSwipeThresholdFeedback() { + val target = DropTarget.DragObject(mContext) + target.dragView = mock>() + buttonDropTarget.onDragEnter(target) + val wrapper = MSDLPlayerWrapper.INSTANCE.get(mContext) + + val history = wrapper.history + assertThat(history.size).isEqualTo(1) + assertThat(history[0].tokenName).isEqualTo(MSDLToken.SWIPE_THRESHOLD_INDICATOR.name) + } } diff --git a/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheTest.java b/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheTest.java index ce00b28c51..9b4bd71608 100644 --- a/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheTest.java +++ b/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheTest.java @@ -71,6 +71,7 @@ import com.android.launcher3.util.PackageUserKey; import com.google.common.truth.Truth; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -99,6 +100,11 @@ public class IconCacheTest { new LauncherIconProvider(mContext)); } + @After + public void tearDown() { + mIconCache.close(); + } + @Test public void getShortcutInfoBadge_nullComponent_overrideAllowed() throws Exception { String overridePackage = "com.android.settings"; diff --git a/tests/multivalentTests/src/com/android/launcher3/model/DatabaseHelperTest.kt b/tests/multivalentTests/src/com/android/launcher3/model/DatabaseHelperTest.kt index c9ea421039..09752b860e 100644 --- a/tests/multivalentTests/src/com/android/launcher3/model/DatabaseHelperTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/model/DatabaseHelperTest.kt @@ -1,5 +1,6 @@ package com.android.launcher3.model +import android.content.Context import android.database.sqlite.SQLiteDatabase import android.os.UserHandle import androidx.test.ext.junit.runners.AndroidJUnit4 @@ -11,8 +12,10 @@ import com.android.launcher3.LauncherSettings.Favorites.addTableToDb import com.android.launcher3.pm.UserCache import com.android.launcher3.provider.LauncherDbUtils import java.util.function.ToLongFunction +import org.junit.After import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse +import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -24,6 +27,19 @@ private const val ICON_RESOURCE = "iconResource" @SmallTest @RunWith(AndroidJUnit4::class) class DatabaseHelperTest { + val context: Context = InstrumentationRegistry.getInstrumentation().targetContext + // v30 - 21 columns + lateinit var db: SQLiteDatabase + + @Before + fun setUp() { + db = FactitiousDbController(context, INSERTION_SQL).inMemoryDb + } + + @After + fun tearDown() { + db.close() + } /** * b/304687723 occurred when a return was accidentally added to a case statement in @@ -33,13 +49,11 @@ class DatabaseHelperTest { */ @Test fun onUpgrade_to_version_32_from_30() { - val context = InstrumentationRegistry.getInstrumentation().targetContext val userSerialProvider = ToLongFunction { UserCache.INSTANCE.get(context).getSerialNumberForUser(it) } val dbHelper = DatabaseHelper(context, null, userSerialProvider) {} - val db = FactitiousDbController(context, INSERTION_SQL).inMemoryDb dbHelper.onUpgrade(db, 30, 32) @@ -54,9 +68,6 @@ class DatabaseHelperTest { */ @Test fun after_migrating_from_db_v30_to_v32_copy_table() { - val context = InstrumentationRegistry.getInstrumentation().targetContext - val db = FactitiousDbController(context, INSERTION_SQL).inMemoryDb // v30 - 21 columns - addTableToDb(db, 1, true, TMP_TABLE) LauncherDbUtils.copyTable(db, TABLE_NAME, db, TMP_TABLE, context) diff --git a/tests/multivalentTests/src/com/android/launcher3/model/GridSizeMigrationTest.kt b/tests/multivalentTests/src/com/android/launcher3/model/GridSizeMigrationTest.kt index 7933331cff..eee6191f15 100644 --- a/tests/multivalentTests/src/com/android/launcher3/model/GridSizeMigrationTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/model/GridSizeMigrationTest.kt @@ -82,6 +82,7 @@ class GridSizeMigrationTest { @After fun tearDown() { + db.close() modelHelper.destroy() } diff --git a/tests/multivalentTests/src/com/android/launcher3/model/LoaderCursorTest.java b/tests/multivalentTests/src/com/android/launcher3/model/LoaderCursorTest.java index b4945d7129..63359ec1cd 100644 --- a/tests/multivalentTests/src/com/android/launcher3/model/LoaderCursorTest.java +++ b/tests/multivalentTests/src/com/android/launcher3/model/LoaderCursorTest.java @@ -109,6 +109,7 @@ public class LoaderCursorTest { @After public void tearDown() { + mCursor.close(); mModelHelper.destroy(); } diff --git a/tests/multivalentTests/src/com/android/launcher3/provider/RestoreDbTaskTest.java b/tests/multivalentTests/src/com/android/launcher3/provider/RestoreDbTaskTest.java index d0c168a8d1..c30b730807 100644 --- a/tests/multivalentTests/src/com/android/launcher3/provider/RestoreDbTaskTest.java +++ b/tests/multivalentTests/src/com/android/launcher3/provider/RestoreDbTaskTest.java @@ -92,6 +92,7 @@ public class RestoreDbTaskTest { private Cursor mMockCursor; private LauncherPrefs mPrefs; private LauncherRestoreEventLogger mMockRestoreEventLogger; + private SQLiteDatabase mDb; @Before public void setup() { @@ -107,57 +108,60 @@ public class RestoreDbTaskTest { @After public void teardown() { + if (mDb != null) { + mDb.close(); + } mModelHelper.destroy(); LauncherPrefs.get(mContext).removeSync(RESTORE_DEVICE); } @Test public void testGetProfileId() throws Exception { - SQLiteDatabase db = new MyModelDbController(23).getDb(); - assertEquals(23, new RestoreDbTask().getDefaultProfileId(db)); + mDb = new MyModelDbController(23).getDb(); + assertEquals(23, new RestoreDbTask().getDefaultProfileId(mDb)); } @Test public void testMigrateProfileId() throws Exception { - SQLiteDatabase db = new MyModelDbController(42).getDb(); + mDb = new MyModelDbController(42).getDb(); // Add some mock data for (int i = 0; i < 5; i++) { ContentValues values = new ContentValues(); values.put(Favorites._ID, i); values.put(Favorites.TITLE, "item " + i); - db.insert(Favorites.TABLE_NAME, null, values); + mDb.insert(Favorites.TABLE_NAME, null, values); } // Verify item add - assertEquals(5, getCount(db, "select * from favorites where profileId = 42")); + assertEquals(5, getCount(mDb, "select * from favorites where profileId = 42")); - new RestoreDbTask().migrateProfileId(db, 42, 33); + new RestoreDbTask().migrateProfileId(mDb, 42, 33); // verify data migrated - assertEquals(0, getCount(db, "select * from favorites where profileId = 42")); - assertEquals(5, getCount(db, "select * from favorites where profileId = 33")); + assertEquals(0, getCount(mDb, "select * from favorites where profileId = 42")); + assertEquals(5, getCount(mDb, "select * from favorites where profileId = 33")); } @Test public void testChangeDefaultColumn() throws Exception { - SQLiteDatabase db = new MyModelDbController(42).getDb(); + mDb = new MyModelDbController(42).getDb(); // Add some mock data for (int i = 0; i < 5; i++) { ContentValues values = new ContentValues(); values.put(Favorites._ID, i); values.put(Favorites.TITLE, "item " + i); - db.insert(Favorites.TABLE_NAME, null, values); + mDb.insert(Favorites.TABLE_NAME, null, values); } // Verify default column is 42 - assertEquals(5, getCount(db, "select * from favorites where profileId = 42")); + assertEquals(5, getCount(mDb, "select * from favorites where profileId = 42")); - new RestoreDbTask().changeDefaultColumn(db, 33); + new RestoreDbTask().changeDefaultColumn(mDb, 33); // Verify default value changed ContentValues values = new ContentValues(); values.put(Favorites._ID, 100); values.put(Favorites.TITLE, "item 100"); - db.insert(Favorites.TABLE_NAME, null, values); - assertEquals(1, getCount(db, "select * from favorites where profileId = 33")); + mDb.insert(Favorites.TABLE_NAME, null, values); + assertEquals(1, getCount(mDb, "select * from favorites where profileId = 33")); } @Test @@ -170,7 +174,7 @@ public class RestoreDbTaskTest { long workProfileId_old = myProfileId + 3; MyModelDbController controller = new MyModelDbController(myProfileId); - SQLiteDatabase db = controller.getDb(); + mDb = controller.getDb(); BackupManager bm = spy(new BackupManager(mContext)); doReturn(myUserHandle()).when(bm).getUserForAncestralSerialNumber(eq(myProfileId_old)); doReturn(mWorkUser).when(bm).getUserForAncestralSerialNumber(eq(workProfileId_old)); @@ -178,16 +182,16 @@ public class RestoreDbTaskTest { addIconsBulk(controller, 10, 1, myProfileId_old); addIconsBulk(controller, 6, 2, workProfileId_old); - assertEquals(10, getItemCountForProfile(db, myProfileId_old)); - assertEquals(6, getItemCountForProfile(db, workProfileId_old)); + assertEquals(10, getItemCountForProfile(mDb, myProfileId_old)); + assertEquals(6, getItemCountForProfile(mDb, workProfileId_old)); mTask.sanitizeDB(mContext, controller, controller.getDb(), bm, mMockRestoreEventLogger); // All the data has been migrated to the new user ids - assertEquals(0, getItemCountForProfile(db, myProfileId_old)); - assertEquals(0, getItemCountForProfile(db, workProfileId_old)); - assertEquals(10, getItemCountForProfile(db, myProfileId)); - assertEquals(6, getItemCountForProfile(db, workProfileId)); + assertEquals(0, getItemCountForProfile(mDb, myProfileId_old)); + assertEquals(0, getItemCountForProfile(mDb, workProfileId_old)); + assertEquals(10, getItemCountForProfile(mDb, myProfileId)); + assertEquals(6, getItemCountForProfile(mDb, workProfileId)); } @Test @@ -199,7 +203,7 @@ public class RestoreDbTaskTest { long workProfileId_old = myProfileId + 3; MyModelDbController controller = new MyModelDbController(myProfileId); - SQLiteDatabase db = controller.getDb(); + mDb = controller.getDb(); BackupManager bm = spy(new BackupManager(mContext)); doReturn(myUserHandle()).when(bm).getUserForAncestralSerialNumber(eq(myProfileId_old)); // Work profile is not migrated @@ -207,16 +211,16 @@ public class RestoreDbTaskTest { addIconsBulk(controller, 10, 1, myProfileId_old); addIconsBulk(controller, 6, 2, workProfileId_old); - assertEquals(10, getItemCountForProfile(db, myProfileId_old)); - assertEquals(6, getItemCountForProfile(db, workProfileId_old)); + assertEquals(10, getItemCountForProfile(mDb, myProfileId_old)); + assertEquals(6, getItemCountForProfile(mDb, workProfileId_old)); mTask.sanitizeDB(mContext, controller, controller.getDb(), bm, mMockRestoreEventLogger); // All the data has been migrated to the new user ids - assertEquals(0, getItemCountForProfile(db, myProfileId_old)); - assertEquals(0, getItemCountForProfile(db, workProfileId_old)); - assertEquals(10, getItemCountForProfile(db, myProfileId)); - assertEquals(10, getCount(db, "select * from favorites")); + assertEquals(0, getItemCountForProfile(mDb, myProfileId_old)); + assertEquals(0, getItemCountForProfile(mDb, workProfileId_old)); + assertEquals(10, getItemCountForProfile(mDb, myProfileId)); + assertEquals(10, getCount(mDb, "select * from favorites")); } @Test @@ -342,24 +346,24 @@ public class RestoreDbTaskTest { } private void runRemoveScreenIdGapsTest(int[] screenIds, int[] expectedScreenIds) { - SQLiteDatabase db = new MyModelDbController(42).getDb(); + mDb = new MyModelDbController(42).getDb(); // Add some mock data for (int i = 0; i < screenIds.length; i++) { ContentValues values = new ContentValues(); values.put(Favorites._ID, i); values.put(Favorites.SCREEN, screenIds[i]); values.put(Favorites.CONTAINER, CONTAINER_DESKTOP); - db.insert(Favorites.TABLE_NAME, null, values); + mDb.insert(Favorites.TABLE_NAME, null, values); } // Verify items are added assertEquals(screenIds.length, - getCount(db, "select * from favorites where container = -100")); + getCount(mDb, "select * from favorites where container = -100")); - new RestoreDbTask().removeScreenIdGaps(db); + new RestoreDbTask().removeScreenIdGaps(mDb); // verify screenId gaps removed int[] resultScreenIds = new int[screenIds.length]; - try (Cursor c = db.rawQuery( + try (Cursor c = mDb.rawQuery( "select screen from favorites where container = -100 order by screen", null)) { int i = 0; while (c.moveToNext()) { diff --git a/tests/multivalentTests/src/com/android/launcher3/widget/GeneratedPreviewTest.kt b/tests/multivalentTests/src/com/android/launcher3/widget/GeneratedPreviewTest.kt index 7484bce091..ac5fda26a4 100644 --- a/tests/multivalentTests/src/com/android/launcher3/widget/GeneratedPreviewTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/widget/GeneratedPreviewTest.kt @@ -26,6 +26,7 @@ import com.android.launcher3.model.WidgetItem import com.android.launcher3.util.ActivityContextWrapper import com.android.launcher3.util.Executors import com.google.common.truth.Truth.assertThat +import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test @@ -38,7 +39,7 @@ class GeneratedPreviewTest { @get:Rule val checkFlagsRule: CheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule() private val providerName = ComponentName( - getInstrumentation().getContext().getPackageName(), + getInstrumentation().context.packageName, "com.android.launcher3.testcomponent.AppWidgetNoConfig", ) private val generatedPreviewLayout = @@ -51,6 +52,7 @@ class GeneratedPreviewTest { private lateinit var helper: WidgetManagerHelper private lateinit var appWidgetProviderInfo: LauncherAppWidgetProviderInfo private lateinit var widgetItem: WidgetItem + private lateinit var iconCache: IconCache @Before fun setup() { @@ -88,17 +90,17 @@ class GeneratedPreviewTest { createWidgetItem() } + @After + fun tearDown() { + iconCache.close() + } + private fun createWidgetItem() { Executors.MODEL_EXECUTOR.submit { val idp = InvariantDeviceProfile() - widgetItem = - WidgetItem( - appWidgetProviderInfo, - idp, - IconCache(context, idp, null, IconProvider(context)), - context, - helper, - ) + if (::iconCache.isInitialized) iconCache.close() + iconCache = IconCache(context, idp, null, IconProvider(context)) + widgetItem = WidgetItem(appWidgetProviderInfo, idp, iconCache, context, helper) } .get() } diff --git a/tests/multivalentTests/src/com/android/launcher3/widget/RoundedCornerEnforcementTest.kt b/tests/multivalentTests/src/com/android/launcher3/widget/RoundedCornerEnforcementTest.kt index c82e84c18a..13e23c9753 100644 --- a/tests/multivalentTests/src/com/android/launcher3/widget/RoundedCornerEnforcementTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/widget/RoundedCornerEnforcementTest.kt @@ -86,7 +86,7 @@ class RoundedCornerEnforcementTest { } @Test - @DisableFlags(Flags.FLAG_ENFORCE_SYSTEM_RADIUS_FOR_APP_WIDGETS) + @DisableFlags(Flags.FLAG_USE_SYSTEM_RADIUS_FOR_APP_WIDGETS) fun `Compute system radius when smaller`() { val mockContext = mock(Context::class.java) val mockRes = mock(Resources::class.java) @@ -103,7 +103,7 @@ class RoundedCornerEnforcementTest { } @Test - @DisableFlags(Flags.FLAG_ENFORCE_SYSTEM_RADIUS_FOR_APP_WIDGETS) + @DisableFlags(Flags.FLAG_USE_SYSTEM_RADIUS_FOR_APP_WIDGETS) fun `Compute launcher radius when smaller`() { val mockContext = mock(Context::class.java) val mockRes = mock(Resources::class.java) @@ -120,7 +120,7 @@ class RoundedCornerEnforcementTest { } @Test - @EnableFlags(Flags.FLAG_ENFORCE_SYSTEM_RADIUS_FOR_APP_WIDGETS) + @EnableFlags(Flags.FLAG_USE_SYSTEM_RADIUS_FOR_APP_WIDGETS) fun `Compute system radius ignoring launcher radius`() { val mockContext = mock(Context::class.java) val mockRes = mock(Resources::class.java) diff --git a/tests/src/com/android/launcher3/util/BaseLauncherActivityTest.kt b/tests/src/com/android/launcher3/util/BaseLauncherActivityTest.kt index 644659296d..61fa7d57ea 100644 --- a/tests/src/com/android/launcher3/util/BaseLauncherActivityTest.kt +++ b/tests/src/com/android/launcher3/util/BaseLauncherActivityTest.kt @@ -124,9 +124,10 @@ open class BaseLauncherActivityTest { @JvmOverloads protected fun injectKeyEvent(keyCode: Int, actionDown: Boolean, metaState: Int = 0) { + uiDevice.waitForIdle() val eventTime = SystemClock.uptimeMillis() val event = - KeyEvent.obtain( + KeyEvent( eventTime, eventTime, if (actionDown) KeyEvent.ACTION_DOWN else MotionEvent.ACTION_UP, @@ -137,10 +138,8 @@ open class BaseLauncherActivityTest { /* scancode= */ 0, /* flags= */ 0, InputDevice.SOURCE_KEYBOARD, - /* characters =*/ null, ) executeOnLauncher { it.dispatchKeyEvent(event) } - event.recycle() } @JvmOverloads