1 /* <lambda>null2 * Copyright (C) 2024 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.LauncherActivityInfo 22 import android.os.Build.VERSION 23 import android.os.UserHandle 24 import android.util.Log 25 import com.android.launcher3.Flags.useNewIconForArchivedApps 26 import com.android.launcher3.icons.BaseIconFactory.IconOptions 27 import com.android.launcher3.icons.BitmapInfo 28 import com.android.launcher3.icons.IconProvider 29 30 object LauncherActivityCachingLogic : CachingLogic<LauncherActivityInfo> { 31 const val TAG = "LauncherActivityCachingLogic" 32 33 override fun getComponent(info: LauncherActivityInfo): ComponentName = info.componentName 34 35 override fun getUser(info: LauncherActivityInfo): UserHandle = info.user 36 37 override fun getLabel(info: LauncherActivityInfo): CharSequence? = info.label 38 39 override fun getApplicationInfo(info: LauncherActivityInfo) = info.applicationInfo 40 41 override fun loadIcon( 42 context: Context, 43 cache: BaseIconCache, 44 info: LauncherActivityInfo, 45 ): BitmapInfo { 46 cache.iconFactory.use { li -> 47 val iconOptions: IconOptions = IconOptions().setUser(info.user) 48 iconOptions.setIsArchived( 49 useNewIconForArchivedApps() && VERSION.SDK_INT >= 35 && info.activityInfo.isArchived 50 ) 51 val iconDrawable = cache.iconProvider.getIcon(info.activityInfo, li.fullResIconDpi) 52 if (context.packageManager.isDefaultApplicationIcon(iconDrawable)) { 53 Log.w( 54 TAG, 55 "loadIcon: Default app icon returned from PackageManager." + 56 " component=${info.componentName}, user=${info.user}", 57 Exception(), 58 ) 59 // Make sure this default icon always matches BaseIconCache#getDefaultIcon 60 return cache.getDefaultIcon(info.user) 61 } 62 return li.createBadgedIconBitmap(iconDrawable, iconOptions) 63 } 64 } 65 66 override fun getFreshnessIdentifier( 67 item: LauncherActivityInfo, 68 provider: IconProvider, 69 ): String? = provider.getStateForApp(getApplicationInfo(item)) 70 } 71