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

Commit b0885022 authored by Hao Dong's avatar Hao Dong
Browse files

Fix res not found in PromptInfo.

Flag: android.hardware.biometrics.custom_biometric_prompt
Bug: 346751510
Test: Verified on addressbook_autoCredman.apk
Change-Id: I685707d314d84b3cd58b4329c82b3e95819ee674
parent d43735b3
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -200,7 +200,10 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
                throw new IllegalStateException(
                        "Exclusively one of logo resource or logo bitmap can be set");
            }
            mPromptInfo.setLogo(logoRes, convertDrawableToBitmap(mContext.getDrawable(logoRes)));
            if (logoRes != 0) {
                mPromptInfo.setLogo(logoRes,
                        convertDrawableToBitmap(mContext.getDrawable(logoRes)));
            }
            return this;
        }

@@ -219,11 +222,11 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
        @RequiresPermission(SET_BIOMETRIC_DIALOG_ADVANCED)
        @NonNull
        public BiometricPrompt.Builder setLogoBitmap(@NonNull Bitmap logoBitmap) {
            if (mPromptInfo.getLogoRes() != -1) {
            if (mPromptInfo.getLogoRes() != 0) {
                throw new IllegalStateException(
                        "Exclusively one of logo resource or logo bitmap can be set");
            }
            mPromptInfo.setLogo(-1, logoBitmap);
            mPromptInfo.setLogo(0, logoBitmap);
            return this;
        }

@@ -832,7 +835,7 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
     * Gets the drawable resource of the logo for the prompt, as set by
     * {@link Builder#setLogoRes(int)}. Currently for system applications use only.
     *
     * @return The drawable resource of the logo, or -1 if the prompt has no logo resource set.
     * @return The drawable resource of the logo, or 0 if the prompt has no logo resource set.
     */
    @FlaggedApi(FLAG_CUSTOM_BIOMETRIC_PROMPT)
    @RequiresPermission(SET_BIOMETRIC_DIALOG_ADVANCED)
+4 −4
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ import java.util.List;
 */
public class PromptInfo implements Parcelable {

    @DrawableRes private int mLogoRes = -1;
    @DrawableRes private int mLogoRes;
    @Nullable private Bitmap mLogoBitmap;
    @Nullable private String mLogoDescription;
    @NonNull private CharSequence mTitle;
@@ -187,7 +187,7 @@ public class PromptInfo implements Parcelable {
     * this permission.
     */
    public boolean requiresAdvancedPermission() {
        if (mLogoRes != -1) {
        if (mLogoRes != 0) {
            return true;
        } else if (mLogoBitmap != null) {
            return true;
@@ -221,7 +221,7 @@ public class PromptInfo implements Parcelable {
    /**
     * Sets logo res and bitmap
     *
     * @param logoRes    The logo res set by the app; Or -1 if the app sets bitmap directly.
     * @param logoRes    The logo res set by the app; Or 0 if the app sets bitmap directly.
     * @param logoBitmap The bitmap from logoRes if the app sets logoRes; Or the bitmap set by the
     *                   app directly.
     */
@@ -351,7 +351,7 @@ public class PromptInfo implements Parcelable {
    public Bitmap getLogoBitmap() {
        // If mLogoRes has been set, return null since mLogoBitmap is from the res, but not from
        // the app directly.
        return mLogoRes == -1 ? mLogoBitmap : null;
        return mLogoRes == 0 ? mLogoBitmap : null;
    }

    public String getLogoDescription() {
+5 −7
Original line number Diff line number Diff line
@@ -87,9 +87,6 @@ import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
import platform.test.runner.parameterized.Parameter
import platform.test.runner.parameterized.Parameters
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -97,6 +94,8 @@ import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mock
import org.mockito.junit.MockitoJUnit
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
import platform.test.runner.parameterized.Parameters

private const val USER_ID = 4
private const val REQUEST_ID = 4L
@@ -1401,7 +1400,7 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa
        allowCredentialFallback: Boolean = false,
        description: String? = null,
        contentView: PromptContentView? = null,
        logoRes: Int = -1,
        logoRes: Int = 0,
        logoBitmap: Bitmap? = null,
        logoDescription: String? = null,
        packageName: String = OP_PACKAGE_NAME,
@@ -1440,8 +1439,7 @@ internal class PromptViewModelTest(private val testCase: TestCase) : SysuiTestCa
            descriptionFromApp = description,
            contentViewFromApp = contentView,
            logoResFromApp = logoRes,
            logoBitmapFromApp =
                if (logoRes != -1) logoDrawableFromAppRes.toBitmap() else logoBitmap,
            logoBitmapFromApp = if (logoRes != 0) logoDrawableFromAppRes.toBitmap() else logoBitmap,
            logoDescriptionFromApp = logoDescription,
            packageName = packageName,
        )
@@ -1627,7 +1625,7 @@ private fun PromptSelectorInteractor.initializePrompt(
    allowCredentialFallback: Boolean = false,
    descriptionFromApp: String? = null,
    contentViewFromApp: PromptContentView? = null,
    logoResFromApp: Int = -1,
    logoResFromApp: Int = 0,
    logoBitmapFromApp: Bitmap? = null,
    logoDescriptionFromApp: String? = null,
    packageName: String = OP_PACKAGE_NAME,