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

Commit 48116b41 authored by Hao Dong's avatar Hao Dong Committed by Android (Google) Code Review
Browse files

Merge "Fix package name not found crash" into main

parents 761fadd2 0532837f
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.biometrics.ui.viewmodel

import android.content.Context
import android.content.pm.PackageManager
import android.graphics.Rect
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
@@ -244,7 +245,13 @@ constructor(
                    !customBiometricPrompt() || it == null -> null
                    it.logoRes != -1 -> context.resources.getDrawable(it.logoRes, context.theme)
                    it.logoBitmap != null -> BitmapDrawable(context.resources, it.logoBitmap)
                    else -> context.packageManager.getApplicationIcon(it.opPackageName)
                    else ->
                        try {
                            context.packageManager.getApplicationIcon(it.opPackageName)
                        } catch (e: PackageManager.NameNotFoundException) {
                            Log.w(TAG, "Cannot find icon for package " + it.opPackageName, e)
                            null
                        }
                }
            }
            .distinctUntilChanged()
+14 −2
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ private const val USER_ID = 4
private const val CHALLENGE = 2L
private const val DELAY = 1000L
private const val OP_PACKAGE_NAME = "biometric.testapp"
private const val OP_PACKAGE_NAME_NO_ICON = "biometric.testapp.noicon"

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@@ -1245,6 +1246,14 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa
            assertThat(contentView).isNull()
        }

    @Test
    fun logoIsNullIfPackageNameNotFound() =
        runGenericTest(packageName = OP_PACKAGE_NAME_NO_ICON) {
            mSetFlagsRule.enableFlags(FLAG_CUSTOM_BIOMETRIC_PROMPT)
            val logo by collectLastValue(viewModel.logo)
            assertThat(logo).isNull()
        }

    @Test
    fun defaultLogoIfNoLogoSet() = runGenericTest {
        mSetFlagsRule.enableFlags(FLAG_CUSTOM_BIOMETRIC_PROMPT)
@@ -1291,7 +1300,8 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa
        contentView: PromptContentView? = null,
        logoRes: Int = -1,
        logoBitmap: Bitmap? = null,
        block: suspend TestScope.() -> Unit
        packageName: String = OP_PACKAGE_NAME,
        block: suspend TestScope.() -> Unit,
    ) {
        selector.initializePrompt(
            requireConfirmation = testCase.confirmationRequested,
@@ -1302,6 +1312,7 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa
            contentViewFromApp = contentView,
            logoResFromApp = logoRes,
            logoBitmapFromApp = logoBitmap,
            packageName = packageName,
        )

        // put the view model in the initial authenticating state, unless explicitly skipped
@@ -1481,6 +1492,7 @@ private fun PromptSelectorInteractor.initializePrompt(
    contentViewFromApp: PromptContentView? = null,
    logoResFromApp: Int = -1,
    logoBitmapFromApp: Bitmap? = null,
    packageName: String = OP_PACKAGE_NAME,
) {
    val info =
        PromptInfo().apply {
@@ -1500,7 +1512,7 @@ private fun PromptSelectorInteractor.initializePrompt(
        USER_ID,
        CHALLENGE,
        BiometricModalities(fingerprintProperties = fingerprint, faceProperties = face),
        OP_PACKAGE_NAME,
        packageName,
    )
}