Converting BaseIconCache to kotlin
Bug: 366237794
Flag: EXEMPT refactor
Test: Presubmit
Change-Id: Ia191ed468eda24f910bba87221cf1f1714408a55
diff --git a/src/com/android/launcher3/icons/IconCache.java b/src/com/android/launcher3/icons/IconCache.java
index ab4105c..0ebd69f 100644
--- a/src/com/android/launcher3/icons/IconCache.java
+++ b/src/com/android/launcher3/icons/IconCache.java
@@ -107,9 +107,9 @@
IconProvider iconProvider) {
super(context, dbFileName, MODEL_EXECUTOR.getLooper(),
idp.fillResIconDpi, idp.iconBitmapSize, true /* inMemoryCache */, iconProvider);
- mLauncherApps = mContext.getSystemService(LauncherApps.class);
- mUserManager = UserCache.INSTANCE.get(mContext);
- mInstantAppResolver = InstantAppResolver.newInstance(mContext);
+ mLauncherApps = context.getSystemService(LauncherApps.class);
+ mUserManager = UserCache.INSTANCE.get(context);
+ mInstantAppResolver = InstantAppResolver.newInstance(context);
mWidgetCategoryBitmapInfos = new SparseArray<>();
mCancelledTask = new CancellableTask(() -> null, MAIN_EXECUTOR, c -> { });
@@ -117,7 +117,7 @@
}
@Override
- protected long getSerialNumberForUser(@NonNull UserHandle user) {
+ public long getSerialNumberForUser(@NonNull UserHandle user) {
return mUserManager.getSerialNumberForUser(user);
}
@@ -129,7 +129,7 @@
@NonNull
@Override
public BaseIconFactory getIconFactory() {
- return LauncherIcons.obtain(mContext);
+ return LauncherIcons.obtain(context);
}
/**
@@ -151,7 +151,7 @@
// This will clear all pending updates
getUpdateHandler();
- mIconDb.close();
+ iconDb.close();
}
/**
@@ -231,7 +231,7 @@
* Fill in {@code info} with the icon for {@code si}
*/
public void getShortcutIcon(ItemInfoWithIcon info, ShortcutInfo si) {
- getShortcutIcon(info, new CacheableShortcutInfo(si, mContext));
+ getShortcutIcon(info, new CacheableShortcutInfo(si, context));
}
/**
@@ -279,7 +279,7 @@
String override = shortcutInfo.getExtras() == null ? null
: shortcutInfo.getExtras().getString(EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE);
if (!TextUtils.isEmpty(override)
- && InstallSessionHelper.INSTANCE.get(mContext)
+ && InstallSessionHelper.INSTANCE.get(context)
.isTrustedPackage(pkg, shortcutInfo.getUserHandle())) {
pkg = override;
} else {
@@ -364,11 +364,11 @@
String componentNameQuery = TextUtils.join(
",", Collections.nCopies(queryParams.length - 1, "?"));
- return mIconDb.query(
- useLowResIcons ? IconDB.COLUMNS_LOW_RES : IconDB.COLUMNS_HIGH_RES,
- IconDB.COLUMN_COMPONENT
+ return iconDb.query(
+ useLowResIcons ? COLUMNS_LOW_RES : COLUMNS_HIGH_RES,
+ COLUMN_COMPONENT
+ " IN ( " + componentNameQuery + " )"
- + " AND " + IconDB.COLUMN_USER + " = ?",
+ + " AND " + COLUMN_USER + " = ?",
queryParams);
}
@@ -428,7 +428,7 @@
/* user = */ sectionKey.first,
/* useLowResIcons = */ sectionKey.second)) {
// Database title and icon loading
- int componentNameColumnIndex = c.getColumnIndexOrThrow(IconDB.COLUMN_COMPONENT);
+ int componentNameColumnIndex = c.getColumnIndexOrThrow(COLUMN_COMPONENT);
while (c.moveToNext()) {
ComponentName cn = ComponentName.unflattenFromString(
c.getString(componentNameColumnIndex));
@@ -525,9 +525,9 @@
return;
}
- WidgetSection widgetSection = WidgetSections.getWidgetSections(mContext)
+ WidgetSection widgetSection = WidgetSections.getWidgetSections(context)
.get(infoInOut.widgetCategory);
- infoInOut.title = mContext.getString(widgetSection.mSectionTitle);
+ infoInOut.title = context.getString(widgetSection.mSectionTitle);
infoInOut.contentDescription = getUserBadgedLabel(infoInOut.title, infoInOut.user);
final BitmapInfo cachedBitmap = mWidgetCategoryBitmapInfos.get(infoInOut.widgetCategory);
if (cachedBitmap != null) {
@@ -535,9 +535,9 @@
return;
}
- try (LauncherIcons li = LauncherIcons.obtain(mContext)) {
+ try (LauncherIcons li = LauncherIcons.obtain(context)) {
final BitmapInfo tempBitmap = li.createBadgedIconBitmap(
- mContext.getDrawable(widgetSection.mSectionDrawable),
+ context.getDrawable(widgetSection.mSectionDrawable),
new BaseIconFactory.IconOptions());
mWidgetCategoryBitmapInfos.put(infoInOut.widgetCategory, tempBitmap);
infoInOut.bitmap = getBadgedIcon(tempBitmap, infoInOut.user);
@@ -606,7 +606,7 @@
/** Log persistently to FileLog.d for debugging. */
@Override
- protected void logdPersistently(String tag, String message, @Nullable Exception e) {
- FileLog.d(tag, message, e);
+ protected void logPersistently(@NonNull String message, @Nullable Exception e) {
+ FileLog.d(BaseIconCache.TAG, message, e);
}
}
diff --git a/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheUpdateHandlerTest.kt b/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheUpdateHandlerTest.kt
index bae74c8..9dbed74 100644
--- a/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheUpdateHandlerTest.kt
+++ b/tests/multivalentTests/src/com/android/launcher3/icons/IconCacheUpdateHandlerTest.kt
@@ -62,7 +62,11 @@
private var cursor =
MatrixCursor(
- arrayOf(IconDB.COLUMN_ROWID, IconDB.COLUMN_COMPONENT, IconDB.COLUMN_FRESHNESS_ID)
+ arrayOf(
+ BaseIconCache.COLUMN_ROWID,
+ BaseIconCache.COLUMN_COMPONENT,
+ BaseIconCache.COLUMN_FRESHNESS_ID,
+ )
)
private lateinit var updateHandlerUnderTest: IconCacheUpdateHandler
diff --git a/tests/src/com/android/launcher3/model/LoaderTaskTest.kt b/tests/src/com/android/launcher3/model/LoaderTaskTest.kt
index 4d181ff..d2229c4 100644
--- a/tests/src/com/android/launcher3/model/LoaderTaskTest.kt
+++ b/tests/src/com/android/launcher3/model/LoaderTaskTest.kt
@@ -124,7 +124,7 @@
`when`(app.invariantDeviceProfile).thenReturn(idp)
`when`(launcherBinder.newIdleLock(any())).thenReturn(idleLock)
`when`(idleLock.awaitLocked(1000)).thenReturn(false)
- `when`(iconCache.updateHandler).thenReturn(iconCacheUpdateHandler)
+ `when`(iconCache.getUpdateHandler()).thenReturn(iconCacheUpdateHandler)
`when`(widgetsFilterDataProvider.getDefaultWidgetsFilter()).thenReturn(Predicate { true })
context.putObject(UserCache.INSTANCE, userCache)