Adding some source hints when generating theme icons

Bug: 381897614
Flag: EXEMPT refactor
Test: Presubmit
Change-Id: Ief779bb04cd69372ec3acd4501e283f09de41b4d
This commit is contained in:
Sunny Goyal
2025-01-14 15:50:27 -08:00
parent bc3995222b
commit 01a976f210
3 changed files with 22 additions and 4 deletions

View File

@@ -112,7 +112,9 @@ object CacheableShortcutCachingLogic : CachingLogic<CacheableShortcutInfo> {
?.let { d ->
li.createBadgedIconBitmap(
d,
IconOptions().setExtractedColor(Themes.getColorAccent(context)),
IconOptions()
.setExtractedColor(Themes.getColorAccent(context))
.setSourceHint(getSourceHint(info, cache)),
)
} ?: BitmapInfo.LOW_RES_INFO
}

View File

@@ -594,7 +594,8 @@ public class IconCache extends BaseIconCache {
@VisibleForTesting
synchronized boolean isItemInDb(ComponentKey cacheKey) {
return getEntryFromDBLocked(cacheKey, new CacheEntry(), DEFAULT_LOOKUP_FLAG);
return getEntryFromDBLocked(cacheKey, new CacheEntry(), DEFAULT_LOOKUP_FLAG,
LauncherActivityCachingLogic.INSTANCE);
}
/**

View File

@@ -16,9 +16,11 @@
package com.android.launcher3.icons.mono
import android.content.ComponentName
import android.graphics.Color
import android.graphics.drawable.AdaptiveIconDrawable
import android.graphics.drawable.ColorDrawable
import android.os.Process
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.SetFlagsRule
@@ -29,6 +31,9 @@ import androidx.test.filters.SmallTest
import com.android.launcher3.Flags
import com.android.launcher3.icons.BaseIconFactory
import com.android.launcher3.icons.BitmapInfo
import com.android.launcher3.icons.SourceHint
import com.android.launcher3.icons.cache.LauncherActivityCachingLogic
import com.android.launcher3.util.ComponentKey
import com.android.launcher3.util.LauncherMultivalentJUnit.Companion.isRunningInRobolectric
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
@@ -45,6 +50,12 @@ class MonoIconThemeControllerTest {
private val iconFactory = BaseIconFactory(context, DisplayMetrics.DENSITY_MEDIUM, 30)
private val sourceHint =
SourceHint(
key = ComponentKey(ComponentName("a", "a"), Process.myUserHandle()),
logic = LauncherActivityCachingLogic,
)
@Test
fun `createThemedBitmap when mono drawable is present`() {
val icon = AdaptiveIconDrawable(ColorDrawable(Color.BLACK), null, ColorDrawable(Color.RED))
@@ -81,7 +92,8 @@ class MonoIconThemeControllerTest {
val themeBitmap =
MonoIconThemeController().createThemedBitmap(icon, iconInfo, iconFactory)!!
assertNotNull(
MonoIconThemeController().decode(themeBitmap.serialize(), iconInfo, iconFactory)
MonoIconThemeController()
.decode(themeBitmap.serialize(), iconInfo, iconFactory, sourceHint)
)
}
@@ -90,7 +102,10 @@ class MonoIconThemeControllerTest {
ensureBitmapSerializationSupported()
val icon = AdaptiveIconDrawable(ColorDrawable(Color.BLACK), null, ColorDrawable(Color.RED))
val iconInfo = iconFactory.createBadgedIconBitmap(icon)
assertNull(MonoIconThemeController().decode(byteArrayOf(1, 1, 1, 1), iconInfo, iconFactory))
assertNull(
MonoIconThemeController()
.decode(byteArrayOf(1, 1, 1, 1), iconInfo, iconFactory, sourceHint)
)
}
@Test