diff --git a/quickstep/src/com/android/quickstep/TaskIconCache.kt b/quickstep/src/com/android/quickstep/TaskIconCache.kt index bf94d4104f..b82c1103d7 100644 --- a/quickstep/src/com/android/quickstep/TaskIconCache.kt +++ b/quickstep/src/com/android/quickstep/TaskIconCache.kt @@ -40,6 +40,7 @@ import com.android.launcher3.util.Executors import com.android.launcher3.util.FlagOp import com.android.launcher3.util.Preconditions import com.android.quickstep.task.thumbnail.data.TaskIconDataSource +import com.android.quickstep.util.IconLabelUtil.getBadgedContentDescription import com.android.quickstep.util.TaskKeyLruCache import com.android.quickstep.util.TaskVisualsChangeListener import com.android.systemui.shared.recents.model.Task @@ -206,6 +207,7 @@ class TaskIconCache( TaskCacheEntry( entryIcon, getBadgedContentDescription( + context, activityInfo, task.key.userId, task.taskDescription, @@ -215,7 +217,12 @@ class TaskIconCache( else -> TaskCacheEntry( entryIcon, - getBadgedContentDescription(activityInfo, task.key.userId, task.taskDescription), + getBadgedContentDescription( + context, + activityInfo, + task.key.userId, + task.taskDescription, + ), ) }.also { iconCache.put(task.key, it) } } @@ -224,28 +231,6 @@ class TaskIconCache( desc.inMemoryIcon ?: ActivityManager.TaskDescription.loadTaskDescriptionIcon(desc.iconFilename, userId) - private fun getBadgedContentDescription( - info: ActivityInfo, - userId: Int, - taskDescription: ActivityManager.TaskDescription?, - ): String { - val packageManager = context.packageManager - var taskLabel = taskDescription?.let { Utilities.trim(it.label) } - if (taskLabel.isNullOrEmpty()) { - taskLabel = Utilities.trim(info.loadLabel(packageManager)) - } - - val applicationLabel = Utilities.trim(info.applicationInfo.loadLabel(packageManager)) - val badgedApplicationLabel = - if (userId != UserHandle.myUserId()) - packageManager - .getUserBadgedLabel(applicationLabel, UserHandle.of(userId)) - .toString() - else applicationLabel - return if (applicationLabel == taskLabel) badgedApplicationLabel - else "$badgedApplicationLabel $taskLabel" - } - @WorkerThread private fun getDefaultIcon(userId: Int): Drawable { synchronized(defaultIcons) { diff --git a/quickstep/src/com/android/quickstep/util/IconLabelUtil.kt b/quickstep/src/com/android/quickstep/util/IconLabelUtil.kt new file mode 100644 index 0000000000..a876bca982 --- /dev/null +++ b/quickstep/src/com/android/quickstep/util/IconLabelUtil.kt @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2025 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.quickstep.util + +import android.app.ActivityManager +import android.content.Context +import android.content.pm.ActivityInfo +import android.os.UserHandle +import com.android.launcher3.Utilities + +object IconLabelUtil { + @JvmStatic + @JvmOverloads + fun getBadgedContentDescription( + context: Context, + info: ActivityInfo, + userId: Int, + taskDescription: ActivityManager.TaskDescription? = null, + ): String { + val packageManager = context.packageManager + var taskLabel = taskDescription?.let { Utilities.trim(it.label) } + if (taskLabel.isNullOrEmpty()) { + taskLabel = Utilities.trim(info.loadLabel(packageManager)) + } + + val applicationLabel = Utilities.trim(info.applicationInfo.loadLabel(packageManager)) + val badgedApplicationLabel = + if (userId != UserHandle.myUserId()) + packageManager + .getUserBadgedLabel(applicationLabel, UserHandle.of(userId)) + .toString() + else applicationLabel + return if (applicationLabel == taskLabel) badgedApplicationLabel + else "$badgedApplicationLabel $taskLabel" + } +}