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

Commit cdaa96cd authored by Milton's avatar Milton Committed by Michael Bestas
Browse files

Ignore enrollAfterFace in FaceEnroll from ext pkg

Remove key of enrollAfterFace in FaceEnroll if this intent is coming
from external package

Bug: 433252423
Flag: EXEMPT BUGFIX
Test: atest FaceEnrollTest
(cherry picked from commit 7ac22f2eae5d3e8e65bc7f8db5a173231ebba071)
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:c602fa951f06c4ae8b3fa4653e545fecd3e87193
Merged-In: Ibbb6340163613ea955516f11579d767b2ade4312
Change-Id: Ibbb6340163613ea955516f11579d767b2ade4312
parent c1684797
Loading
Loading
Loading
Loading
+14 −10
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import com.android.settings.biometrics.BiometricEnrollBase.RESULT_FINISHED
import com.android.settings.biometrics.BiometricEnrollBase.RESULT_SKIP
import com.android.settings.biometrics.BiometricEnrollBase.RESULT_TIMEOUT
import com.android.settings.biometrics.BiometricsOnboardingProto
import com.android.settings.biometrics.MultiBiometricEnrollHelper.EXTRA_ENROLL_AFTER_FACE
import com.android.settings.biometrics.combination.CombinedBiometricStatusUtils
import com.android.settings.biometrics.metrics.BiometricsLogger
import com.android.settings.biometrics.metrics.OnboardingEvent
@@ -45,8 +46,7 @@ class FaceEnroll: AppCompatActivity() {
    private val enrollActivityProvider: FaceEnrollActivityClassProvider
        get() = featureFactory.faceFeatureProvider.enrollActivityClassProvider

    @VisibleForTesting
    var launchedFromProvider: () -> String? = { launchedFromPackage }
    @VisibleForTesting var launchedFromProvider: () -> String? = { launchedFromPackage }

    private var isLaunched = false
    private var startTimeMillis: Long = 0
@@ -65,8 +65,8 @@ class FaceEnroll: AppCompatActivity() {

        if (!isLaunched) {
            /**
             *  Logs the next activity to be launched, creates an intent for that activity,
             *  adds flags to forward the result, includes any existing extras from the current intent,
             * Logs the next activity to be launched, creates an intent for that activity, adds
             * flags to forward the result, includes any existing extras from the current intent,
             * starts the new activity and then finishes the current one
             */
            Log.d("FaceEnroll", "forward to $nextActivityClass")
@@ -75,6 +75,7 @@ class FaceEnroll: AppCompatActivity() {

            // drop extras that are not allowed from external packages before launching
            if (launchedFromProvider() != packageName) {
                nextIntent.removeExtra(EXTRA_ENROLL_AFTER_FACE)
                nextIntent.removeExtra(Intent.EXTRA_USER_ID)
            }
            startActivityForResult(nextIntent, 0)
@@ -93,13 +94,16 @@ class FaceEnroll: AppCompatActivity() {
        requestCode: Int,
        resultCode: Int,
        data: Intent?,
        caller: ComponentCaller
        caller: ComponentCaller,
    ) {
        super.onActivityResult(requestCode, resultCode, data, caller)
        isLaunched = false
        if (intent.getBooleanExtra(
                CombinedBiometricStatusUtils.EXTRA_LAUNCH_FROM_SAFETY_SOURCE_ISSUE, false)
            && resultCode != RESULT_FINISHED) {
        if (
            intent.getBooleanExtra(
                CombinedBiometricStatusUtils.EXTRA_LAUNCH_FROM_SAFETY_SOURCE_ISSUE,
                false,
            ) && resultCode != RESULT_FINISHED
        ) {
            featureFactory.biometricsFeatureProvider.notifySafetyIssueActionLaunched()
        }
        updateOnboardingEvent(resultCode, data)
+24 −12
Original line number Diff line number Diff line
@@ -17,14 +17,17 @@
package com.android.settings.biometrics.face

import android.app.Activity
import android.app.PendingIntent
import android.content.Intent
import androidx.test.core.app.ApplicationProvider
import com.android.settings.biometrics.MultiBiometricEnrollHelper.EXTRA_ENROLL_AFTER_FACE
import com.android.settings.overlay.FeatureFactory
import com.android.settings.testutils.FakeFeatureFactory
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.`when` as whenever
import org.mockito.kotlin.whenever
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.Shadows
@@ -36,10 +39,6 @@ class FaceEnrollTest {
    private companion object {
        const val INTENT_KEY = "testKey"
        const val INTENT_VALUE = "testValue"
        val INTENT = Intent().apply {
            putExtra(INTENT_KEY, INTENT_VALUE)
            putExtra(Intent.EXTRA_USER_ID, 11)
        }
    }

    private val activityProvider = FaceEnrollActivityClassProvider()
@@ -55,7 +54,21 @@ class FaceEnrollTest {
        activityClass: Class<out FaceEnroll>,
        launchedFrom: String? = null,
    ): FaceEnroll {
        val activityController = Robolectric.buildActivity(activityClass, INTENT)
        val activityIntent =
            Intent().apply {
                putExtra(INTENT_KEY, INTENT_VALUE)
                putExtra(Intent.EXTRA_USER_ID, 11)
                putExtra(
                    EXTRA_ENROLL_AFTER_FACE,
                    PendingIntent.getActivity(
                        ApplicationProvider.getApplicationContext()!!,
                        1,
                        Intent(),
                        0,
                    ),
                )
            }
        val activityController = Robolectric.buildActivity(activityClass, activityIntent)
        activityController.get().launchedFromProvider = {
            launchedFrom ?: activityController.get().packageName
        }
@@ -68,23 +81,22 @@ class FaceEnrollTest {

        val nextActivityIntent = activity.asShadow().nextStartedActivity
        assertThat(nextActivityIntent.component!!.className).isEqualTo(activityProvider.next.name)
        assertThat(nextActivityIntent.extras!!.size()).isEqualTo(2)
        assertThat(nextActivityIntent.extras!!.size()).isEqualTo(3)
        assertThat(nextActivityIntent.getStringExtra(INTENT_KEY)).isEqualTo(INTENT_VALUE)
        assertThat(nextActivityIntent.hasExtra(Intent.EXTRA_USER_ID)).isTrue()
        assertThat(nextActivityIntent.hasExtra(EXTRA_ENROLL_AFTER_FACE)).isTrue()
    }

    @Test
    fun testFinishAndLaunchDefaultActivity_fromExternal_dropUser() {
        val activity = setupActivity(
            FaceEnroll::class.java,
            launchedFrom = "com.foo.bar"
        )
    fun testFinishAndLaunchDefaultActivity_fromExternal_dropUserAndDropEnrollAfterFace() {
        val activity = setupActivity(FaceEnroll::class.java, launchedFrom = "com.foo.bar")

        val nextActivityIntent = activity.asShadow().nextStartedActivity
        assertThat(nextActivityIntent.component!!.className).isEqualTo(activityProvider.next.name)
        assertThat(nextActivityIntent.extras!!.size()).isEqualTo(1)
        assertThat(nextActivityIntent.getStringExtra(INTENT_KEY)).isEqualTo(INTENT_VALUE)
        assertThat(nextActivityIntent.hasExtra(Intent.EXTRA_USER_ID)).isFalse()
        assertThat(nextActivityIntent.hasExtra(EXTRA_ENROLL_AFTER_FACE)).isFalse()
    }
}