From d4d4d580dad832eb28b6e3a3b5da46c4d193ecba Mon Sep 17 00:00:00 2001 From: samcackett Date: Fri, 7 Feb 2025 11:42:15 +0000 Subject: [PATCH] Append application name to content description for direct share targets The direct share targets `label` will be the name of the receiving device, so we also need to append the application name for a better readout Fix: 380008872 Test: MANUAL. Talkback on. Open an app with a url or image. Open Recents . Select the url or image AiAi chip. Select the first direct share target. Talkback should read the targets name and application name. Share. App should dismiss. Flag: EXEMPT bugfix Change-Id: I3d7df44d239ae9b8a3a62b7343e65bcd6a2e9939 --- .../com/android/quickstep/TaskIconCache.kt | 31 +++--------- .../android/quickstep/util/IconLabelUtil.kt | 50 +++++++++++++++++++ 2 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 quickstep/src/com/android/quickstep/util/IconLabelUtil.kt 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" + } +}