Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5a3c1f1 authored by yyalan's avatar yyalan
Browse files

[MediaProjection] Avoid SysUI crash by handling NameNotFoundException

When the AppSelector fails to load the recent app's label, the exception causes SysUI to crash. Avoid this case by handling potential errors.

Fixes: 274912947
Test: manual
Change-Id: I56c33c7ff2af9c74e5a492e959fe05b8bb2de0aa
parent 0f453337
Loading
Loading
Loading
Loading
+18 −8
Original line number Diff line number Diff line
@@ -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)
            var badgedLabel: CharSequence? = null
            try {
                val appInfo =
                packageManager.getApplicationInfo(
                    packageManager.getApplicationInfoAsUser(
                        componentName.packageName,
                    PackageManager.ApplicationInfoFlags.of(0 /* no flags */)
                        PackageManager.ApplicationInfoFlags.of(0 /* no flags */),
                        userId
                    )
                val label = packageManager.getApplicationLabel(appInfo)
            return@withContext packageManager.getUserBadgedLabel(label, userHandle)
                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
        }
}
+1 −1
Original line number Diff line number Diff line
@@ -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 {