diff --git a/src/com/android/launcher3/dragndrop/AddItemActivity.java b/src/com/android/launcher3/dragndrop/AddItemActivity.java index a3cfe5c3a0..25de4791e5 100644 --- a/src/com/android/launcher3/dragndrop/AddItemActivity.java +++ b/src/com/android/launcher3/dragndrop/AddItemActivity.java @@ -281,7 +281,7 @@ public class AddItemActivity extends BaseActivity new PinShortcutRequestActivityInfo(mRequest, this); mWidgetCell.getWidgetView().setTag(new PendingAddShortcutInfo(shortcutInfo)); applyWidgetItemAsync( - () -> new WidgetItem(shortcutInfo, mApp.getIconCache(), getPackageManager())); + () -> new WidgetItem(shortcutInfo, mApp.getIconCache())); return new PackageItemInfo(mRequest.getShortcutInfo().getPackage(), mRequest.getShortcutInfo().getUserHandle()); } diff --git a/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java b/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java index cc5e89028d..a6a50d7252 100644 --- a/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java +++ b/src/com/android/launcher3/dragndrop/PinShortcutRequestActivityInfo.java @@ -30,7 +30,6 @@ import android.content.Context; import android.content.Intent; import android.content.pm.LauncherApps; import android.content.pm.LauncherApps.PinItemRequest; -import android.content.pm.PackageManager; import android.content.pm.ShortcutInfo; import android.graphics.drawable.Drawable; import android.os.Build; @@ -40,7 +39,7 @@ import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherSettings; import com.android.launcher3.R; -import com.android.launcher3.icons.IconCache; +import com.android.launcher3.icons.cache.BaseIconCache; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.pm.PinRequestHelper; import com.android.launcher3.pm.ShortcutConfigActivityInfo; @@ -82,12 +81,12 @@ public class PinShortcutRequestActivityInfo extends ShortcutConfigActivityInfo { } @Override - public CharSequence getLabel(PackageManager pm) { + public CharSequence getLabel() { return mInfo.getShortLabel(); } @Override - public Drawable getFullResIcon(IconCache cache) { + public Drawable getFullResIcon(BaseIconCache cache) { Drawable d = mContext.getSystemService(LauncherApps.class) .getShortcutIconDrawable(mInfo, LauncherAppState.getIDP(mContext).fillResIconDpi); if (d == null) { diff --git a/src/com/android/launcher3/icons/IconCache.java b/src/com/android/launcher3/icons/IconCache.java index b6fe66a1f2..e7c4024a18 100644 --- a/src/com/android/launcher3/icons/IconCache.java +++ b/src/com/android/launcher3/icons/IconCache.java @@ -51,8 +51,8 @@ import com.android.launcher3.Flags; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.Utilities; import com.android.launcher3.icons.cache.BaseIconCache; +import com.android.launcher3.icons.cache.CachedObject; import com.android.launcher3.icons.cache.CachedObjectCachingLogic; -import com.android.launcher3.icons.cache.CachingLogic; import com.android.launcher3.icons.cache.LauncherActivityCachingLogic; import com.android.launcher3.logging.FileLog; import com.android.launcher3.model.data.AppInfo; @@ -92,9 +92,6 @@ public class IconCache extends BaseIconCache { private final Predicate mIsUsingFallbackOrNonDefaultIconCheck = w -> w.bitmap != null && (w.bitmap.isNullOrLowRes() || !isDefaultIcon(w.bitmap, w.user)); - private final CachingLogic mComponentWithLabelCachingLogic; - private final CachingLogic mLauncherActivityInfoCachingLogic; - private final LauncherApps mLauncherApps; private final UserCache mUserManager; private final InstantAppResolver mInstantAppResolver; @@ -108,8 +105,6 @@ public class IconCache extends BaseIconCache { IconProvider iconProvider) { super(context, dbFileName, MODEL_EXECUTOR.getLooper(), idp.fillResIconDpi, idp.iconBitmapSize, true /* inMemoryCache */, iconProvider); - mComponentWithLabelCachingLogic = new CachedObjectCachingLogic(context); - mLauncherActivityInfoCachingLogic = LauncherActivityCachingLogic.INSTANCE; mLauncherApps = mContext.getSystemService(LauncherApps.class); mUserManager = UserCache.INSTANCE.get(mContext); mInstantAppResolver = InstantAppResolver.newInstance(mContext); @@ -143,7 +138,7 @@ public class IconCache extends BaseIconCache { removeIconsForPkg(packageName, user); long userSerial = mUserManager.getSerialNumberForUser(user); for (LauncherActivityInfo app : mLauncherApps.getActivityList(packageName, user)) { - addIconToDBAndMemCache(app, mLauncherActivityInfoCachingLogic, userSerial); + addIconToDBAndMemCache(app, LauncherActivityCachingLogic.INSTANCE, userSerial); } } @@ -211,7 +206,7 @@ public class IconCache extends BaseIconCache { */ public synchronized void updateTitleAndIcon(AppInfo application) { CacheEntry entry = cacheLocked(application.componentName, - application.user, () -> null, mLauncherActivityInfoCachingLogic, + application.user, () -> null, LauncherActivityCachingLogic.INSTANCE, application.usingLowResIcon() ? LookupFlag.USE_LOW_RES : LookupFlag.DEFAULT); if (entry.bitmap != null || !isDefaultIcon(entry.bitmap, application.user)) { applyCacheEntry(entry, application); @@ -326,9 +321,9 @@ public class IconCache extends BaseIconCache { /** * Loads and returns the icon for the provided object without adding it to memCache */ - public synchronized String getTitleNoCache(ComponentWithLabel info) { + public synchronized String getTitleNoCache(CachedObject info) { CacheEntry entry = cacheLocked(info.getComponent(), info.getUser(), () -> info, - mComponentWithLabelCachingLogic, + CachedObjectCachingLogic.INSTANCE, LookupFlag.USE_LOW_RES | LookupFlag.SKIP_ADD_TO_MEM_CACHE); return Utilities.trim(entry.title); } @@ -344,7 +339,7 @@ public class IconCache extends BaseIconCache { if (usePkgIcon) lookupFlags |= LookupFlag.USE_PACKAGE_ICON; if (useLowResIcon) lookupFlags |= LookupFlag.USE_LOW_RES; CacheEntry entry = cacheLocked(infoInOut.getTargetComponent(), infoInOut.user, - activityInfoProvider, mLauncherActivityInfoCachingLogic, lookupFlags); + activityInfoProvider, LauncherActivityCachingLogic.INSTANCE, lookupFlags); applyCacheEntry(entry, infoInOut); } @@ -445,7 +440,7 @@ public class IconCache extends BaseIconCache { cn, /* user = */ sectionKey.first, () -> duplicateIconRequests.get(0).launcherActivityInfo, - mLauncherActivityInfoCachingLogic, + LauncherActivityCachingLogic.INSTANCE, sectionKey.second ? LookupFlag.USE_LOW_RES : LookupFlag.DEFAULT, c); @@ -494,7 +489,7 @@ public class IconCache extends BaseIconCache { loadFallbackIcon( lai, entry, - mLauncherActivityInfoCachingLogic, + LauncherActivityCachingLogic.INSTANCE, /* usePackageIcon= */ false, /* usePackageTitle= */ loadFallbackTitle, cn, @@ -504,7 +499,7 @@ public class IconCache extends BaseIconCache { loadFallbackTitle( lai, entry, - mLauncherActivityInfoCachingLogic, + LauncherActivityCachingLogic.INSTANCE, sectionKey.first); } diff --git a/src/com/android/launcher3/icons/Legacy.kt b/src/com/android/launcher3/icons/Legacy.kt deleted file mode 100644 index 3bf3bb2539..0000000000 --- a/src/com/android/launcher3/icons/Legacy.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2024 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.launcher3.icons - -import com.android.launcher3.icons.cache.CachedObject - -/** - * This files contains some definitions used during refactoring to avoid breaking changes. - * - * TODO(b/366237794) remove this file once refactoring is complete - */ - -/** Temporary interface to allow easier refactoring */ -interface ComponentWithLabel : CachedObject - -/** Temporary interface to allow easier refactoring */ -interface ComponentWithLabelAndIcon : ComponentWithLabel diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java index dff5463d9a..09d1146932 100644 --- a/src/com/android/launcher3/model/LoaderTask.java +++ b/src/com/android/launcher3/model/LoaderTask.java @@ -72,8 +72,8 @@ import com.android.launcher3.folder.FolderNameInfos; import com.android.launcher3.folder.FolderNameProvider; import com.android.launcher3.icons.CacheableShortcutCachingLogic; import com.android.launcher3.icons.CacheableShortcutInfo; -import com.android.launcher3.icons.ComponentWithLabelAndIcon; import com.android.launcher3.icons.IconCache; +import com.android.launcher3.icons.cache.CachedObject; import com.android.launcher3.icons.cache.CachedObjectCachingLogic; import com.android.launcher3.icons.cache.IconCacheUpdateHandler; import com.android.launcher3.icons.cache.LauncherActivityCachingLogic; @@ -335,8 +335,7 @@ public class LoaderTask implements Runnable { verifyNotStopped(); // fourth step - List allWidgetsList = - mBgDataModel.widgetsModel.update(mApp, null); + List allWidgetsList = mBgDataModel.widgetsModel.update(mApp, null); logASplit("load widgets"); verifyNotStopped(); @@ -364,7 +363,7 @@ public class LoaderTask implements Runnable { } updateHandler.updateIcons(allWidgetsList, - new CachedObjectCachingLogic(mApp.getContext()), + CachedObjectCachingLogic.INSTANCE, mApp.getModel()::onWidgetLabelsUpdated); logASplit("save widgets in icon cache"); diff --git a/src/com/android/launcher3/model/WidgetItem.java b/src/com/android/launcher3/model/WidgetItem.java index ac9f2d68eb..e757a683c6 100644 --- a/src/com/android/launcher3/model/WidgetItem.java +++ b/src/com/android/launcher3/model/WidgetItem.java @@ -7,7 +7,6 @@ import static android.appwidget.AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX; import android.annotation.SuppressLint; import android.content.Context; import android.content.pm.ActivityInfo; -import android.content.pm.PackageManager; import android.content.res.Resources; import android.util.SparseArray; import android.widget.RemoteViews; @@ -75,10 +74,10 @@ public class WidgetItem extends ComponentKey { this(info, idp, iconCache, context, new WidgetManagerHelper(context)); } - public WidgetItem(ShortcutConfigActivityInfo info, IconCache iconCache, PackageManager pm) { + public WidgetItem(ShortcutConfigActivityInfo info, IconCache iconCache) { super(info.getComponent(), info.getUser()); label = info.isPersistable() ? iconCache.getTitleNoCache(info) : - Utilities.trim(info.getLabel(pm)); + Utilities.trim(info.getLabel()); description = null; widgetInfo = null; activityInfo = info; diff --git a/src/com/android/launcher3/model/WidgetsModel.java b/src/com/android/launcher3/model/WidgetsModel.java index c949ce66b6..b450f46836 100644 --- a/src/com/android/launcher3/model/WidgetsModel.java +++ b/src/com/android/launcher3/model/WidgetsModel.java @@ -14,7 +14,6 @@ import static java.util.stream.Collectors.toList; import android.appwidget.AppWidgetProviderInfo; import android.content.ComponentName; import android.content.Context; -import android.content.pm.PackageManager; import android.os.UserHandle; import android.util.Log; import android.util.Pair; @@ -27,8 +26,8 @@ import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.LauncherAppState; import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; -import com.android.launcher3.icons.ComponentWithLabelAndIcon; import com.android.launcher3.icons.IconCache; +import com.android.launcher3.icons.cache.CachedObject; import com.android.launcher3.model.data.PackageItemInfo; import com.android.launcher3.pm.ShortcutConfigActivityInfo; import com.android.launcher3.util.ComponentKey; @@ -96,20 +95,18 @@ public class WidgetsModel { * @param packageUser If null, all widgets and shortcuts are updated and returned, otherwise * only widgets and shortcuts associated with the package/user are. */ - public List update( + public List update( LauncherAppState app, @Nullable PackageUserKey packageUser) { if (!WIDGETS_ENABLED) { - return Collections.emptyList(); + return new ArrayList<>(); } Preconditions.assertWorkerThread(); Context context = app.getContext(); final ArrayList widgetsAndShortcuts = new ArrayList<>(); - List updatedItems = new ArrayList<>(); + List updatedItems = new ArrayList<>(); try { InvariantDeviceProfile idp = app.getInvariantDeviceProfile(); - PackageManager pm = app.getContext().getPackageManager(); - // Widgets WidgetManagerHelper widgetManager = new WidgetManagerHelper(context); for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders(packageUser)) { @@ -125,7 +122,7 @@ public class WidgetsModel { // Shortcuts for (ShortcutConfigActivityInfo info : queryList(context, packageUser)) { - widgetsAndShortcuts.add(new WidgetItem(info, app.getIconCache(), pm)); + widgetsAndShortcuts.add(new WidgetItem(info, app.getIconCache())); updatedItems.add(info); } setWidgetsAndShortcuts(widgetsAndShortcuts, app, packageUser); @@ -190,8 +187,7 @@ public class WidgetsModel { WidgetItem item = items.get(i); if (item.user.equals(user)) { if (item.activityInfo != null) { - items.set(i, new WidgetItem(item.activityInfo, app.getIconCache(), - app.getContext().getPackageManager())); + items.set(i, new WidgetItem(item.activityInfo, app.getIconCache())); } else { items.set(i, new WidgetItem(item.widgetInfo, app.getInvariantDeviceProfile(), app.getIconCache(), diff --git a/src/com/android/launcher3/pm/ShortcutConfigActivityInfo.java b/src/com/android/launcher3/pm/ShortcutConfigActivityInfo.java index 3064abfc9f..409174e068 100644 --- a/src/com/android/launcher3/pm/ShortcutConfigActivityInfo.java +++ b/src/com/android/launcher3/pm/ShortcutConfigActivityInfo.java @@ -29,7 +29,6 @@ import android.content.IntentSender; import android.content.pm.ApplicationInfo; import android.content.pm.LauncherActivityInfo; import android.content.pm.LauncherApps; -import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Process; @@ -41,8 +40,8 @@ import androidx.annotation.Nullable; import com.android.launcher3.LauncherSettings; import com.android.launcher3.R; -import com.android.launcher3.icons.ComponentWithLabelAndIcon; -import com.android.launcher3.icons.IconCache; +import com.android.launcher3.icons.cache.BaseIconCache; +import com.android.launcher3.icons.cache.CachedObject; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.util.ApplicationInfoWrapper; import com.android.launcher3.util.PackageUserKey; @@ -54,7 +53,7 @@ import java.util.List; /** * Wrapper class for representing a shortcut configure activity. */ -public abstract class ShortcutConfigActivityInfo implements ComponentWithLabelAndIcon { +public abstract class ShortcutConfigActivityInfo implements CachedObject { private static final String TAG = "SCActivityInfo"; @@ -91,7 +90,7 @@ public abstract class ShortcutConfigActivityInfo implements ComponentWithLabelAn } @Override - public abstract Drawable getFullResIcon(IconCache cache); + public abstract Drawable getFullResIcon(BaseIconCache cache); /** * Return a WorkspaceItemInfo, if it can be created directly on drop, without requiring any @@ -125,7 +124,7 @@ public abstract class ShortcutConfigActivityInfo implements ComponentWithLabelAn } /** - * Returns true if various properties ({@link #getLabel(PackageManager)}, + * Returns true if various properties ({@link #getLabel()}, * {@link #getFullResIcon}) can be safely persisted. */ public boolean isPersistable() { @@ -144,12 +143,12 @@ public abstract class ShortcutConfigActivityInfo implements ComponentWithLabelAn } @Override - public CharSequence getLabel(PackageManager pm) { + public CharSequence getLabel() { return mInfo.getLabel(); } @Override - public Drawable getFullResIcon(IconCache cache) { + public Drawable getFullResIcon(BaseIconCache cache) { return cache.getFullResIcon(mInfo.getActivityInfo()); } diff --git a/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java b/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java index 1db3b5a4af..fba3936be9 100644 --- a/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java +++ b/src/com/android/launcher3/widget/LauncherAppWidgetProviderInfo.java @@ -16,8 +16,8 @@ import androidx.annotation.Nullable; import com.android.launcher3.DeviceProfile; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.LauncherAppState; -import com.android.launcher3.icons.ComponentWithLabelAndIcon; -import com.android.launcher3.icons.IconCache; +import com.android.launcher3.icons.cache.BaseIconCache; +import com.android.launcher3.icons.cache.CachedObject; import com.android.launcher3.model.data.LauncherAppWidgetInfo; /** @@ -26,8 +26,7 @@ import com.android.launcher3.model.data.LauncherAppWidgetInfo; * (who's implementation is owned by the launcher). This object represents a widget type / class, * as opposed to a widget instance, and so should not be confused with {@link LauncherAppWidgetInfo} */ -public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo - implements ComponentWithLabelAndIcon { +public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo implements CachedObject { public static final String CLS_CUSTOM_WIDGET_PREFIX = "#custom-widget-"; @@ -69,6 +68,8 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo protected boolean mIsMinSizeFulfilled; + private PackageManager mPM; + public static LauncherAppWidgetProviderInfo fromProviderInfo(Context context, AppWidgetProviderInfo info) { final LauncherAppWidgetProviderInfo launcherInfo; @@ -97,6 +98,7 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo } public void initSpans(Context context, InvariantDeviceProfile idp) { + mPM = context.getPackageManager(); int minSpanX = 0; int minSpanY = 0; int maxSpanX = idp.numColumns; @@ -104,7 +106,6 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo int spanX = 0; int spanY = 0; - Point cellSize = new Point(); for (DeviceProfile dp : idp.supportedProfiles) { dp.getCellSize(cellSize); @@ -188,8 +189,9 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo (widgetSize + widgetPadding + cellSpacing) / (cellSize + cellSpacing))); } - public String getLabel(PackageManager packageManager) { - return super.loadLabel(packageManager); + @Override + public CharSequence getLabel() { + return super.loadLabel(mPM); } public Point getMinSpans() { @@ -225,7 +227,7 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo } @Override - public Drawable getFullResIcon(IconCache cache) { + public Drawable getFullResIcon(BaseIconCache cache) { return cache.getFullResIcon(getActivityInfo()); } diff --git a/src/com/android/launcher3/widget/custom/CustomAppWidgetProviderInfo.java b/src/com/android/launcher3/widget/custom/CustomAppWidgetProviderInfo.java index 5ad9222335..82a688306a 100644 --- a/src/com/android/launcher3/widget/custom/CustomAppWidgetProviderInfo.java +++ b/src/com/android/launcher3/widget/custom/CustomAppWidgetProviderInfo.java @@ -18,7 +18,6 @@ package com.android.launcher3.widget.custom; import android.content.ComponentName; import android.content.Context; -import android.content.pm.PackageManager; import android.os.Parcel; import android.os.Parcelable; @@ -64,7 +63,7 @@ public class CustomAppWidgetProviderInfo extends LauncherAppWidgetProviderInfo } @Override - public String getLabel(PackageManager packageManager) { + public CharSequence getLabel() { return Utilities.trim(label); } diff --git a/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheUpdateHandlerTest.kt b/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheUpdateHandlerTest.kt index 8e54c9451c..ed9a0804d2 100644 --- a/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheUpdateHandlerTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheUpdateHandlerTest.kt @@ -18,10 +18,8 @@ package com.android.launcher3.icons import android.content.ComponentName import android.content.pm.ApplicationInfo -import android.content.pm.PackageManager import android.database.MatrixCursor import android.os.Process.myUserHandle -import androidx.test.core.app.ApplicationProvider.getApplicationContext import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.launcher3.icons.cache.BaseIconCache @@ -49,7 +47,7 @@ class IconCacheUpdateHandlerTest { @Mock private lateinit var baseIconCache: BaseIconCache private var cursor: MatrixCursor? = null - private var cachingLogic = CachedObjectCachingLogic(getApplicationContext()) + private var cachingLogic = CachedObjectCachingLogic @Before fun setup() { @@ -137,14 +135,13 @@ fun IconCache.waitForUpdateHandlerToFinish() { } } -class TestCachedObject(val cn: ComponentName, val freshnessId: String) : - CachedObject { +class TestCachedObject(val cn: ComponentName, val freshnessId: String) : CachedObject { override fun getComponent() = cn override fun getUser() = myUserHandle() - override fun getLabel(pm: PackageManager?): CharSequence? = null + override fun getLabel(): CharSequence? = null override fun getApplicationInfo(): ApplicationInfo? = null diff --git a/tests/multivalentTests/src/com/android/launcher3/widget/custom/CustomAppWidgetProviderInfoTest.kt b/tests/multivalentTests/src/com/android/launcher3/widget/custom/CustomAppWidgetProviderInfoTest.kt index 0a3035aa56..af2c3785db 100644 --- a/tests/multivalentTests/src/com/android/launcher3/widget/custom/CustomAppWidgetProviderInfoTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/widget/custom/CustomAppWidgetProviderInfoTest.kt @@ -17,7 +17,6 @@ package com.android.launcher3.widget.custom import android.content.ComponentName -import android.content.pm.PackageManager import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.MediumTest import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation @@ -25,7 +24,6 @@ import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mockito.mock @MediumTest @RunWith(AndroidJUnit4::class) @@ -47,7 +45,7 @@ class CustomAppWidgetProviderInfoTest { @Test fun get_label() { underTest.label = " TEST_LABEL" - assertEquals(LABEL_NAME, underTest.getLabel(mock(PackageManager::class.java))) + assertEquals(LABEL_NAME, underTest.getLabel()) } companion object { diff --git a/tests/multivalentTests/src/com/android/launcher3/widget/model/WidgetsListBaseEntriesBuilderTest.kt b/tests/multivalentTests/src/com/android/launcher3/widget/model/WidgetsListBaseEntriesBuilderTest.kt index 5df7caa372..063ab327c0 100644 --- a/tests/multivalentTests/src/com/android/launcher3/widget/model/WidgetsListBaseEntriesBuilderTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/widget/model/WidgetsListBaseEntriesBuilderTest.kt @@ -26,8 +26,8 @@ import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import com.android.launcher3.InvariantDeviceProfile import com.android.launcher3.LauncherAppState -import com.android.launcher3.icons.ComponentWithLabel import com.android.launcher3.icons.IconCache +import com.android.launcher3.icons.cache.CachedObject import com.android.launcher3.model.WidgetItem import com.android.launcher3.model.data.PackageItemInfo import com.android.launcher3.util.ActivityContextWrapper @@ -66,11 +66,11 @@ class WidgetsListBaseEntriesBuilderTest { testInvariantProfile = LauncherAppState.getIDP(context) doAnswer { invocation: InvocationOnMock -> - val componentWithLabel = invocation.getArgument(0) as ComponentWithLabel + val componentWithLabel = invocation.getArgument(0) as CachedObject componentWithLabel.getComponent().shortClassName } .`when`(iconCache) - .getTitleNoCache(any()) + .getTitleNoCache(any()) underTest = WidgetsListBaseEntriesBuilder(context) allWidgets = @@ -79,14 +79,14 @@ class WidgetsListBaseEntriesBuilderTest { packageItemInfoWithTitle(APP_1_PACKAGE_NAME, APP_1_PACKAGE_TITLE) to listOf( createWidgetItem(APP_1_PACKAGE_NAME, APP_1_PROVIDER_1_CLASS_NAME), - createWidgetItem(APP_1_PACKAGE_NAME, APP_1_PROVIDER_2_CLASS_NAME) + createWidgetItem(APP_1_PACKAGE_NAME, APP_1_PROVIDER_2_CLASS_NAME), ), // app 2 packageItemInfoWithTitle(APP_2_PACKAGE_NAME, APP_2_PACKAGE_TITLE) to listOf(createWidgetItem(APP_2_PACKAGE_NAME, APP_2_PROVIDER_1_CLASS_NAME)), // app 3 packageItemInfoWithTitle(APP_3_PACKAGE_NAME, APP_3_PACKAGE_TITLE) to - listOf(createWidgetItem(APP_3_PACKAGE_NAME, APP_3_PROVIDER_1_CLASS_NAME)) + listOf(createWidgetItem(APP_3_PACKAGE_NAME, APP_3_PROVIDER_1_CLASS_NAME)), ) } @@ -96,7 +96,7 @@ class WidgetsListBaseEntriesBuilderTest { listOf( APP_1_EXPECTED_SECTION_NAME to 2, APP_2_EXPECTED_SECTION_NAME to 1, - APP_3_EXPECTED_SECTION_NAME to 1 + APP_3_EXPECTED_SECTION_NAME to 1, ) val entries = underTest.build(allWidgets) @@ -122,7 +122,7 @@ class WidgetsListBaseEntriesBuilderTest { val expectedWidgetsCountBySection = listOf( APP_1_EXPECTED_SECTION_NAME to 1, // one widget filtered out - APP_3_EXPECTED_SECTION_NAME to 1 + APP_3_EXPECTED_SECTION_NAME to 1, ) val entries = diff --git a/tests/multivalentTests/src/com/android/launcher3/widget/picker/WidgetsListHeaderViewHolderBinderTest.java b/tests/multivalentTests/src/com/android/launcher3/widget/picker/WidgetsListHeaderViewHolderBinderTest.java index d4e061a161..c9b6d4f808 100644 --- a/tests/multivalentTests/src/com/android/launcher3/widget/picker/WidgetsListHeaderViewHolderBinderTest.java +++ b/tests/multivalentTests/src/com/android/launcher3/widget/picker/WidgetsListHeaderViewHolderBinderTest.java @@ -42,8 +42,8 @@ import androidx.test.filters.SmallTest; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.R; import com.android.launcher3.icons.BitmapInfo; -import com.android.launcher3.icons.ComponentWithLabel; import com.android.launcher3.icons.IconCache; +import com.android.launcher3.icons.cache.CachedObject; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.model.data.PackageItemInfo; import com.android.launcher3.util.ActivityContextWrapper; @@ -87,7 +87,7 @@ public final class WidgetsListHeaderViewHolderBinderTest { mTestProfile.numColumns = 5; doAnswer(invocation -> { - ComponentWithLabel componentWithLabel = (ComponentWithLabel) invocation.getArgument(0); + CachedObject componentWithLabel = invocation.getArgument(0); return componentWithLabel.getComponent().getShortClassName(); }).when(mIconCache).getTitleNoCache(any()); mViewHolderBinder = new WidgetsListHeaderViewHolderBinder( diff --git a/tests/multivalentTests/src/com/android/launcher3/widget/picker/WidgetsListTableViewHolderBinderTest.java b/tests/multivalentTests/src/com/android/launcher3/widget/picker/WidgetsListTableViewHolderBinderTest.java index e1cc010e61..0d9464a187 100644 --- a/tests/multivalentTests/src/com/android/launcher3/widget/picker/WidgetsListTableViewHolderBinderTest.java +++ b/tests/multivalentTests/src/com/android/launcher3/widget/picker/WidgetsListTableViewHolderBinderTest.java @@ -45,8 +45,8 @@ import androidx.test.filters.SmallTest; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.R; import com.android.launcher3.icons.BitmapInfo; -import com.android.launcher3.icons.ComponentWithLabel; import com.android.launcher3.icons.IconCache; +import com.android.launcher3.icons.cache.CachedObject; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.model.data.PackageItemInfo; import com.android.launcher3.util.ActivityContextWrapper; @@ -92,7 +92,7 @@ public final class WidgetsListTableViewHolderBinderTest { mTestProfile.numColumns = 5; doAnswer(invocation -> { - ComponentWithLabel componentWithLabel = (ComponentWithLabel) invocation.getArgument(0); + CachedObject componentWithLabel = invocation.getArgument(0); return componentWithLabel.getComponent().getShortClassName(); }).when(mIconCache).getTitleNoCache(any()); diff --git a/tests/multivalentTests/src/com/android/launcher3/widget/picker/model/WidgetPickerDataProviderTest.kt b/tests/multivalentTests/src/com/android/launcher3/widget/picker/model/WidgetPickerDataProviderTest.kt index 18226392e3..1da74cb809 100644 --- a/tests/multivalentTests/src/com/android/launcher3/widget/picker/model/WidgetPickerDataProviderTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/widget/picker/model/WidgetPickerDataProviderTest.kt @@ -27,8 +27,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import com.android.launcher3.InvariantDeviceProfile import com.android.launcher3.LauncherAppState import com.android.launcher3.LauncherSettings -import com.android.launcher3.icons.ComponentWithLabel import com.android.launcher3.icons.IconCache +import com.android.launcher3.icons.cache.CachedObject import com.android.launcher3.model.WidgetItem import com.android.launcher3.model.data.PackageItemInfo import com.android.launcher3.util.ActivityContextWrapper @@ -81,11 +81,11 @@ class WidgetPickerDataProviderTest { testInvariantProfile = LauncherAppState.getIDP(context) doAnswer { invocation: InvocationOnMock -> - val componentWithLabel = invocation.getArgument(0) as ComponentWithLabel + val componentWithLabel = invocation.getArgument(0) as CachedObject componentWithLabel.getComponent().shortClassName } .`when`(iconCache) - .getTitleNoCache(any()) + .getTitleNoCache(any()) appWidgetItem = createWidgetItem() } @@ -113,8 +113,8 @@ class WidgetPickerDataProviderTest { listOf( PendingAddWidgetInfo( appWidgetItem.widgetInfo, - LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION - ), + LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION, + ) ) underTest.setWidgetRecommendations(recommendations) @@ -133,8 +133,8 @@ class WidgetPickerDataProviderTest { listOf( PendingAddWidgetInfo( appWidgetItem.widgetInfo, - LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION - ), + LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION, + ) ) underTest.setWidgetRecommendations(recommendations) diff --git a/tests/multivalentTests/src/com/android/launcher3/widget/picker/model/WidgetsListContentEntryTest.java b/tests/multivalentTests/src/com/android/launcher3/widget/picker/model/WidgetsListContentEntryTest.java index 755261915d..6088c8e412 100644 --- a/tests/multivalentTests/src/com/android/launcher3/widget/picker/model/WidgetsListContentEntryTest.java +++ b/tests/multivalentTests/src/com/android/launcher3/widget/picker/model/WidgetsListContentEntryTest.java @@ -33,8 +33,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; import com.android.launcher3.InvariantDeviceProfile; -import com.android.launcher3.icons.ComponentWithLabel; import com.android.launcher3.icons.IconCache; +import com.android.launcher3.icons.cache.CachedObject; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.model.data.PackageItemInfo; import com.android.launcher3.widget.LauncherAppWidgetProviderInfo; @@ -81,7 +81,7 @@ public final class WidgetsListContentEntryTest { mTestProfile.numColumns = 5; doAnswer(invocation -> { - ComponentWithLabel componentWithLabel = (ComponentWithLabel) invocation.getArgument(0); + CachedObject componentWithLabel = invocation.getArgument(0); return mWidgetsToLabels.get(componentWithLabel.getComponent()); }).when(mIconCache).getTitleNoCache(any()); } diff --git a/tests/multivalentTests/src/com/android/launcher3/widget/picker/model/data/WidgetPickerDataTest.kt b/tests/multivalentTests/src/com/android/launcher3/widget/picker/model/data/WidgetPickerDataTest.kt index e59e211de4..deec67a263 100644 --- a/tests/multivalentTests/src/com/android/launcher3/widget/picker/model/data/WidgetPickerDataTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/widget/picker/model/data/WidgetPickerDataTest.kt @@ -27,8 +27,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import com.android.launcher3.InvariantDeviceProfile import com.android.launcher3.LauncherAppState import com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION -import com.android.launcher3.icons.ComponentWithLabel import com.android.launcher3.icons.IconCache +import com.android.launcher3.icons.cache.CachedObject import com.android.launcher3.model.WidgetItem import com.android.launcher3.model.data.ItemInfo import com.android.launcher3.model.data.PackageItemInfo @@ -86,11 +86,11 @@ class WidgetPickerDataTest { testInvariantProfile = LauncherAppState.getIDP(context) doAnswer { invocation: InvocationOnMock -> - val componentWithLabel = invocation.getArgument(0) as ComponentWithLabel + val componentWithLabel = invocation.getArgument(0) as CachedObject componentWithLabel.getComponent().shortClassName } .`when`(iconCache) - .getTitleNoCache(any()) + .getTitleNoCache(any()) app1PackageItemInfo = packageItemInfoWithTitle(APP_1_PACKAGE_NAME, APP_1_PACKAGE_TITLE) app2PackageItemInfo = packageItemInfoWithTitle(APP_2_PACKAGE_NAME, APP_2_PACKAGE_TITLE) @@ -123,7 +123,7 @@ class WidgetPickerDataTest { val widgetPickerData = WidgetPickerData( allWidgets = appTwoWidgetsListBaseEntries(), - defaultWidgets = appTwoWidgetsListBaseEntries() + defaultWidgets = appTwoWidgetsListBaseEntries(), ) val newWidgetData = @@ -143,19 +143,19 @@ class WidgetPickerDataTest { addAll(appOneWidgetsListBaseEntries()) addAll(appTwoWidgetsListBaseEntries()) }, - defaultWidgets = buildList { appTwoWidgetsListBaseEntries() } + defaultWidgets = buildList { appTwoWidgetsListBaseEntries() }, ) val recommendations: List = listOf( PendingAddWidgetInfo( app1WidgetItem1.widgetInfo, CONTAINER_WIDGETS_PREDICTION, - CATEGORY_1 + CATEGORY_1, ), PendingAddWidgetInfo( app2WidgetItem1.widgetInfo, CONTAINER_WIDGETS_PREDICTION, - CATEGORY_2 + CATEGORY_2, ), ) @@ -175,7 +175,7 @@ class WidgetPickerDataTest { addAll(appOneWidgetsListBaseEntries()) addAll(appTwoWidgetsListBaseEntries()) }, - defaultWidgets = buildList { appTwoWidgetsListBaseEntries() } + defaultWidgets = buildList { appTwoWidgetsListBaseEntries() }, ) val recommendations: List = listOf( @@ -201,7 +201,7 @@ class WidgetPickerDataTest { addAll(appTwoWidgetsListBaseEntries()) }, defaultWidgets = buildList { appTwoWidgetsListBaseEntries() }, - recommendations = mapOf(CATEGORY_1 to listOf(app1WidgetItem1)) + recommendations = mapOf(CATEGORY_1 to listOf(app1WidgetItem1)), ) val updatedData = widgetPickerData.withRecommendedWidgets(listOf()) @@ -242,7 +242,7 @@ class WidgetPickerDataTest { addAll(appOneWidgetsListBaseEntries()) addAll(appTwoWidgetsListBaseEntries()) }, - defaultWidgets = buildList { addAll(appTwoWidgetsListBaseEntries()) } + defaultWidgets = buildList { addAll(appTwoWidgetsListBaseEntries()) }, ) val app1PackageUserKey = PackageUserKey.fromPackageItemInfo(app1PackageItemInfo) @@ -263,7 +263,7 @@ class WidgetPickerDataTest { addAll(appTwoWidgetsListBaseEntries()) }, defaultWidgets = - buildList { addAll(appOneWidgetsListBaseEntries(includeWidgetTwo = false)) } + buildList { addAll(appOneWidgetsListBaseEntries(includeWidgetTwo = false)) }, ) val app1PackageUserKey = PackageUserKey.fromPackageItemInfo(app1PackageItemInfo) @@ -271,7 +271,7 @@ class WidgetPickerDataTest { findContentEntryForPackageUser( widgetPickerData = widgetPickerData, packageUserKey = app1PackageUserKey, - fromDefaultWidgets = true + fromDefaultWidgets = true, ) assertThat(contentEntry).isNotNull() @@ -302,7 +302,7 @@ class WidgetPickerDataTest { addAll(appTwoWidgetsListBaseEntries()) }, defaultWidgets = - buildList { addAll(appOneWidgetsListBaseEntries(includeWidgetTwo = false)) } + buildList { addAll(appOneWidgetsListBaseEntries(includeWidgetTwo = false)) }, ) val widgets = findAllWidgetsForPackageUser(widgetPickerData, app1PackageUserKey) @@ -314,9 +314,7 @@ class WidgetPickerDataTest { @Test fun findAllWidgetsForPackageUser_noMatch_returnsEmptyList() { val widgetPickerData = - WidgetPickerData( - allWidgets = buildList { addAll(appTwoWidgetsListBaseEntries()) }, - ) + WidgetPickerData(allWidgets = buildList { addAll(appTwoWidgetsListBaseEntries()) }) val app1PackageUserKey = PackageUserKey.fromPackageItemInfo(app1PackageItemInfo) val widgets = findAllWidgetsForPackageUser(widgetPickerData, app1PackageUserKey) diff --git a/tests/multivalentTests/src/com/android/launcher3/widget/picker/search/SimpleWidgetsSearchAlgorithmTest.java b/tests/multivalentTests/src/com/android/launcher3/widget/picker/search/SimpleWidgetsSearchAlgorithmTest.java index 24d66a302e..59f352b2a9 100644 --- a/tests/multivalentTests/src/com/android/launcher3/widget/picker/search/SimpleWidgetsSearchAlgorithmTest.java +++ b/tests/multivalentTests/src/com/android/launcher3/widget/picker/search/SimpleWidgetsSearchAlgorithmTest.java @@ -41,8 +41,8 @@ import androidx.test.filters.SmallTest; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.icons.BitmapInfo; -import com.android.launcher3.icons.ComponentWithLabel; import com.android.launcher3.icons.IconCache; +import com.android.launcher3.icons.cache.CachedObject; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.model.data.PackageItemInfo; import com.android.launcher3.search.SearchCallback; @@ -87,7 +87,7 @@ public class SimpleWidgetsSearchAlgorithmTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); doAnswer(invocation -> { - ComponentWithLabel componentWithLabel = (ComponentWithLabel) invocation.getArgument(0); + CachedObject componentWithLabel = invocation.getArgument(0); return componentWithLabel.getComponent().getShortClassName(); }).when(mIconCache).getTitleNoCache(any()); mTestProfile = new InvariantDeviceProfile(); diff --git a/tests/multivalentTests/src/com/android/launcher3/widget/picker/util/WidgetsTableUtilsTest.java b/tests/multivalentTests/src/com/android/launcher3/widget/picker/util/WidgetsTableUtilsTest.java index 7adb2b17f4..2f5fcfef2d 100644 --- a/tests/multivalentTests/src/com/android/launcher3/widget/picker/util/WidgetsTableUtilsTest.java +++ b/tests/multivalentTests/src/com/android/launcher3/widget/picker/util/WidgetsTableUtilsTest.java @@ -28,7 +28,6 @@ import static org.mockito.Mockito.when; import android.appwidget.AppWidgetProviderInfo; import android.content.ComponentName; import android.content.Context; -import android.content.pm.PackageManager; import android.graphics.Point; import android.graphics.drawable.Drawable; import android.os.UserHandle; @@ -39,8 +38,9 @@ import androidx.test.filters.SmallTest; import com.android.launcher3.DeviceProfile; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.LauncherAppState; -import com.android.launcher3.icons.ComponentWithLabel; import com.android.launcher3.icons.IconCache; +import com.android.launcher3.icons.cache.BaseIconCache; +import com.android.launcher3.icons.cache.CachedObject; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.pm.ShortcutConfigActivityInfo; import com.android.launcher3.util.ActivityContextWrapper; @@ -99,7 +99,7 @@ public final class WidgetsTableUtilsTest { initTestWidgets(); initTestShortcuts(); - doAnswer(invocation -> ((ComponentWithLabel) invocation.getArgument(0)) + doAnswer(invocation -> ((CachedObject) invocation.getArgument(0)) .getComponent().getPackageName()) .when(mIconCache).getTitleNoCache(any()); } @@ -280,16 +280,15 @@ public final class WidgetsTableUtilsTest { } private void initTestShortcuts() { - PackageManager packageManager = mContext.getPackageManager(); mShortcut1 = new WidgetItem(new TestShortcutConfigActivityInfo( ComponentName.createRelative(TEST_PACKAGE, ".shortcut1"), UserHandle.CURRENT), - mIconCache, packageManager); + mIconCache); mShortcut2 = new WidgetItem(new TestShortcutConfigActivityInfo( ComponentName.createRelative(TEST_PACKAGE, ".shortcut2"), UserHandle.CURRENT), - mIconCache, packageManager); + mIconCache); mShortcut3 = new WidgetItem(new TestShortcutConfigActivityInfo( ComponentName.createRelative(TEST_PACKAGE, ".shortcut3"), UserHandle.CURRENT), - mIconCache, packageManager); + mIconCache); } @@ -300,12 +299,12 @@ public final class WidgetsTableUtilsTest { } @Override - public Drawable getFullResIcon(IconCache cache) { + public Drawable getFullResIcon(BaseIconCache cache) { return null; } @Override - public CharSequence getLabel(PackageManager pm) { + public CharSequence getLabel() { return null; } } diff --git a/tests/src/com/android/launcher3/ui/widget/TaplAddConfigWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/TaplAddConfigWidgetTest.java index e6e02b49ac..961e7fc5e6 100644 --- a/tests/src/com/android/launcher3/ui/widget/TaplAddConfigWidgetTest.java +++ b/tests/src/com/android/launcher3/ui/widget/TaplAddConfigWidgetTest.java @@ -93,7 +93,7 @@ public class TaplAddConfigWidgetTest extends AbstractLauncherUiTest { WidgetConfigStartupMonitor monitor = new WidgetConfigStartupMonitor(); mLauncher.getWorkspace() .openAllWidgets() - .getWidget(mWidgetInfo.getLabel(mTargetContext.getPackageManager())) + .getWidget(mWidgetInfo.getLabel()) .dragToWorkspace(true, false); // Widget id for which the config activity was opened mWidgetId = monitor.getWidgetId(); diff --git a/tests/src/com/android/launcher3/ui/widget/TaplAddWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/TaplAddWidgetTest.java index 9c916fa638..9a2147af4b 100644 --- a/tests/src/com/android/launcher3/ui/widget/TaplAddWidgetTest.java +++ b/tests/src/com/android/launcher3/ui/widget/TaplAddWidgetTest.java @@ -61,7 +61,7 @@ public class TaplAddWidgetTest extends AbstractLauncherUiTest { WidgetResizeFrame resizeFrame = mLauncher .getWorkspace() .openAllWidgets() - .getWidget(widgetInfo.getLabel(mTargetContext.getPackageManager())) + .getWidget(widgetInfo.getLabel()) .dragWidgetToWorkspace(); assertNotNull("Widget resize frame not shown after widget add", resizeFrame); @@ -111,7 +111,7 @@ public class TaplAddWidgetTest extends AbstractLauncherUiTest { WidgetResizeFrame resizeFrame = mLauncher .getWorkspace() .openAllWidgets() - .getWidget(widgetInfo.getLabel(mTargetContext.getPackageManager())) + .getWidget(widgetInfo.getLabel()) .dragWidgetToWorkspace(); assertNotNull("Widget resize frame not shown after widget add", resizeFrame); diff --git a/tests/tapl/com/android/launcher3/tapl/Widgets.java b/tests/tapl/com/android/launcher3/tapl/Widgets.java index 6387b05cc8..3097d9c539 100644 --- a/tests/tapl/com/android/launcher3/tapl/Widgets.java +++ b/tests/tapl/com/android/launcher3/tapl/Widgets.java @@ -116,8 +116,8 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer } /** Get widget with supplied text. */ - public Widget getWidget(String labelText) { - return getWidget(labelText, null); + public Widget getWidget(CharSequence labelText) { + return getWidget(labelText.toString(), null); } /** Get widget with supplied text and app package */