1 /* <lambda>null2 * Copyright (C) 2025 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.launcher3.icons.cache 18 19 import android.content.ComponentName 20 import android.content.Context 21 import android.content.pm.ApplicationInfo 22 import android.content.pm.PackageManager 23 import android.os.UserHandle 24 import com.android.launcher3.icons.BaseIconFactory.IconOptions 25 import com.android.launcher3.icons.BitmapInfo 26 import com.android.launcher3.icons.IconProvider 27 import com.android.launcher3.icons.cache.BaseIconCache.Companion.EMPTY_CLASS_NAME 28 29 /** Caching logic for ApplicationInfo */ 30 class AppInfoCachingLogic( 31 private val pm: PackageManager, 32 private val instantAppResolver: (ApplicationInfo) -> Boolean, 33 private val errorLogger: (String, Exception?) -> Unit = { _, _ -> }, 34 ) : CachingLogic<ApplicationInfo> { 35 getComponentnull36 override fun getComponent(info: ApplicationInfo) = 37 ComponentName(info.packageName, info.packageName + EMPTY_CLASS_NAME) 38 39 override fun getUser(info: ApplicationInfo) = UserHandle.getUserHandleForUid(info.uid) 40 41 override fun getLabel(info: ApplicationInfo) = info.loadLabel(pm) 42 43 override fun getApplicationInfo(info: ApplicationInfo) = info 44 45 override fun loadIcon( 46 context: Context, 47 cache: BaseIconCache, 48 info: ApplicationInfo, 49 ): BitmapInfo { 50 // Load the full res icon for the application, but if useLowResIcon is set, then 51 // only keep the low resolution icon instead of the larger full-sized icon 52 val appIcon = cache.iconProvider.getIcon(info) 53 if (context.packageManager.isDefaultApplicationIcon(appIcon)) { 54 errorLogger.invoke( 55 String.format("Default icon returned for %s", info.packageName), 56 null, 57 ) 58 } 59 60 return cache.iconFactory.use { li -> 61 li.createBadgedIconBitmap( 62 appIcon, 63 IconOptions() 64 .setUser(getUser(info)) 65 .setInstantApp(instantAppResolver.invoke(info)) 66 .setSourceHint(getSourceHint(info, cache)), 67 ) 68 } 69 } 70 getFreshnessIdentifiernull71 override fun getFreshnessIdentifier(item: ApplicationInfo, iconProvider: IconProvider) = 72 iconProvider.getStateForApp(item) 73 } 74