Merge "[MediaProjection] Avoid SysUI crash by handling NameNotFoundException" into udc-dev am: 6a3a7bde34

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22616880

Change-Id: I5a8dc494eec9daa6ffde481410b25edaa0ff6d7b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Yalan Yiue
2023-04-21 14:52:17 +00:00
committed by Automerger Merge Worker
2 changed files with 19 additions and 9 deletions

View File

@@ -20,6 +20,7 @@ import android.annotation.UserIdInt
import android.content.ComponentName
import android.content.pm.PackageManager
import android.os.UserHandle
import android.util.Log
import com.android.systemui.dagger.qualifiers.Background
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
@@ -36,18 +37,27 @@ constructor(
private val packageManager: PackageManager
) : RecentTaskLabelLoader {
private val TAG = "RecentTaskLabelLoader"
override suspend fun loadLabel(
@UserIdInt userId: Int,
componentName: ComponentName
): CharSequence? =
withContext(coroutineDispatcher) {
val userHandle = UserHandle(userId)
val appInfo =
packageManager.getApplicationInfo(
componentName.packageName,
PackageManager.ApplicationInfoFlags.of(0 /* no flags */)
)
val label = packageManager.getApplicationLabel(appInfo)
return@withContext packageManager.getUserBadgedLabel(label, userHandle)
var badgedLabel: CharSequence? = null
try {
val appInfo =
packageManager.getApplicationInfoAsUser(
componentName.packageName,
PackageManager.ApplicationInfoFlags.of(0 /* no flags */),
userId
)
val label = packageManager.getApplicationLabel(appInfo)
val userHandle = UserHandle(userId)
badgedLabel = packageManager.getUserBadgedLabel(label, userHandle)
} catch (e: PackageManager.NameNotFoundException) {
Log.e(TAG, "Unable to get application info", e)
}
return@withContext badgedLabel
}
}

View File

@@ -68,7 +68,7 @@ constructor(
}
launch {
val label = labelLoader.loadLabel(task.userId, component)
root.contentDescription = label
root.contentDescription = label ?: root.context.getString(R.string.unknown)
}
}
launch {