[BiometricsV2] Fix intro overlap enrolling page

Fix fragment overlapped if user rotates device on findSensor page, then
enter enrolling page and back again.

It is because the flag isFirstFragmentAdded is not saved and restored
after activity recreated

Bug: 288212767
Test: atest FingerprintEnrollmentActivityTest
Test: atest FingerprintEnrollmentViewModelTest
Test: atest biometrics-enrollment-test
Test: Manually test this scenario
Change-Id: I5b582582d97caac2488b787f551c50abec9f810c
This commit is contained in:
Milton Wu
2023-06-27 19:00:37 +08:00
parent 4dd2e56ddf
commit 570b23e0a0
4 changed files with 339 additions and 69 deletions

View File

@@ -22,13 +22,13 @@ import android.hardware.fingerprint.FingerprintManager
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal
import android.hardware.fingerprint.IFingerprintAuthenticatorsRegisteredCallback
import android.os.UserHandle
import android.support.test.uiautomator.By
import android.support.test.uiautomator.UiDevice
import android.support.test.uiautomator.UiObject2
import android.support.test.uiautomator.Until
import android.util.Log
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiObject2
import androidx.test.uiautomator.Until
import com.android.internal.widget.LockPatternChecker
import com.android.internal.widget.LockPatternUtils
import com.android.internal.widget.LockscreenCredential
@@ -57,6 +57,7 @@ class FingerprintEnrollmentActivityTest {
private var canAssumeUdfps = false
private var canAssumeSfps = false
private var enrollingPageTitle: String = ""
private var runAsLandscape = false
private val device: UiDevice by lazy {
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
@@ -108,12 +109,16 @@ class FingerprintEnrollmentActivityTest {
@After
@Throws(Exception::class)
fun tearDown() {
runAsLandscape = false
setDeviceOrientation()
LockScreenUtil.resetLockscreen(TEST_PIN)
device.pressHome()
}
@Test
fun testIntroChooseLock() {
setDeviceOrientation()
val intent = newActivityIntent(false)
context.startActivity(intent)
assertThat(
@@ -124,6 +129,12 @@ class FingerprintEnrollmentActivityTest {
).isTrue()
}
@Test
fun testIntroChooseLock_landscape() {
runAsLandscape = true
testIntroChooseLock()
}
private fun verifyIntroPage() {
device.waitForIdle()
run {
@@ -141,7 +152,8 @@ class FingerprintEnrollmentActivityTest {
// Click more btn at most twice and the introduction should stay in the last page
var moreBtn: UiObject2? = null
var i = 0
while (i < 2 && device.findObject(By.text("More")).also { moreBtn = it } != null) {
val more = if (runAsLandscape) 5 else 2
while (i < more && device.findObject(By.text("More")).also { moreBtn = it } != null) {
moreBtn!!.click()
device.waitForIdle()
device.wait(Until.hasObject(By.text("More")), IDLE_TIMEOUT)
@@ -154,6 +166,8 @@ class FingerprintEnrollmentActivityTest {
@Test
fun testIntroWithGkPwHandle_withUdfps_clickStart() {
Assume.assumeTrue(canAssumeUdfps)
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchIntroWithGkPwHandle(false)
@@ -178,9 +192,17 @@ class FingerprintEnrollmentActivityTest {
assertThat(device.wait(Until.hasObject(By.text(enrollingPageTitle)), IDLE_TIMEOUT)).isTrue()
}
@Test
fun testIntroWithGkPwHandle_withUdfps_clickStart_landscape() {
runAsLandscape = true
testIntroWithGkPwHandle_withUdfps_clickStart()
}
@Test
fun testIntroWithGkPwHandle_withUdfps_clickLottie() {
Assume.assumeTrue(canAssumeUdfps)
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchIntroWithGkPwHandle(false)
@@ -203,9 +225,17 @@ class FingerprintEnrollmentActivityTest {
assertThat(device.wait(Until.hasObject(By.text(enrollingPageTitle)), IDLE_TIMEOUT)).isTrue()
}
@Test
fun testIntroWithGkPwHandle_withUdfps_clickLottie_landscape() {
runAsLandscape = true
testIntroWithGkPwHandle_withUdfps_clickLottie()
}
@Test
fun testIntroWithGkPwHandle_withSfps() {
Assume.assumeTrue(canAssumeSfps)
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchIntroWithGkPwHandle(false)
@@ -225,9 +255,17 @@ class FingerprintEnrollmentActivityTest {
// We don't have view which can be clicked to run to next page, stop at here.
}
@Test
fun testIntroWithGkPwHandle_withSfps_landscape() {
runAsLandscape = true
testIntroWithGkPwHandle_withSfps()
}
@Test
fun testIntroWithGkPwHandle_withRfps() {
Assume.assumeFalse(canAssumeUdfps || canAssumeSfps)
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchIntroWithGkPwHandle(false)
@@ -252,8 +290,15 @@ class FingerprintEnrollmentActivityTest {
}
}
@Test
fun testIntroWithGkPwHandle_withRfps_landscape() {
runAsLandscape = true
testIntroWithGkPwHandle_withRfps()
}
@Test
fun testIntroWithGkPwHandle_clickNoThanksInIntroPage() {
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchIntroWithGkPwHandle(false)
@@ -268,8 +313,15 @@ class FingerprintEnrollmentActivityTest {
assertThat(device.findObject(By.text("No thanks"))).isNull()
}
@Test
fun testIntroWithGkPwHandle_clickNoThanksInIntroPage_landscape() {
runAsLandscape = true
testIntroWithGkPwHandle_clickNoThanksInIntroPage()
}
@Test
fun testIntroWithGkPwHandle_clickSkipInFindSensor() {
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchIntroWithGkPwHandle(false)
@@ -291,8 +343,15 @@ class FingerprintEnrollmentActivityTest {
assertThat(device.findObject(By.text(DO_IT_LATER))).isNull()
}
@Test
fun testIntroWithGkPwHandle_clickSkipInFindSensor_landscape() {
runAsLandscape = true
testIntroWithGkPwHandle_clickSkipInFindSensor()
}
@Test
fun testIntroWithGkPwHandle_clickSkipAnywayInFindFpsDialog_whenIsSuw() {
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchIntroWithGkPwHandle(true)
@@ -322,8 +381,15 @@ class FingerprintEnrollmentActivityTest {
assertThat(device.findObject(By.text(DO_IT_LATER))).isNull()
}
@Test
fun testIntroWithGkPwHandle_clickSkipAnywayInFindFpsDialog_whenIsSuw_landscape() {
runAsLandscape = true
testIntroWithGkPwHandle_clickSkipAnywayInFindFpsDialog_whenIsSuw()
}
@Test
fun testIntroWithGkPwHandle_clickGoBackInFindFpsDialog_whenIsSuw() {
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchIntroWithGkPwHandle(true)
@@ -351,8 +417,15 @@ class FingerprintEnrollmentActivityTest {
assertThat(device.wait(Until.hasObject(By.text(DO_IT_LATER)), IDLE_TIMEOUT)).isTrue()
}
@Test
fun testIntroWithGkPwHandle_clickGoBackInFindFpsDialog_whenIsSuw_landscape() {
runAsLandscape = true
testIntroWithGkPwHandle_clickGoBackInFindFpsDialog_whenIsSuw()
}
@Test
fun testIntroCheckPin() {
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
val intent = newActivityIntent(false)
context.startActivity(intent)
@@ -366,6 +439,7 @@ class FingerprintEnrollmentActivityTest {
@Test
fun testEnrollingWithGkPwHandle() {
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchEnrollingWithGkPwHandle()
@@ -374,9 +448,17 @@ class FingerprintEnrollmentActivityTest {
assertThat(device.wait(Until.hasObject(By.text(enrollingPageTitle)), IDLE_TIMEOUT)).isTrue()
}
@Test
fun testEnrollingWithGkPwHandle_landscape() {
runAsLandscape = true
testEnrollingWithGkPwHandle()
}
@Test
fun testEnrollingIconTouchDialog_withSfps() {
Assume.assumeTrue(canAssumeSfps)
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchEnrollingWithGkPwHandle()
@@ -409,9 +491,17 @@ class FingerprintEnrollmentActivityTest {
assertThat(device.wait(Until.hasObject(By.text(enrollingPageTitle)), IDLE_TIMEOUT)).isTrue()
}
@Test
fun testEnrollingIconTouchDialog_withSfps_landscape() {
runAsLandscape = true
testEnrollingIconTouchDialog_withSfps()
}
@Test
fun testEnrollingIconTouchDialog_withRfps() {
Assume.assumeFalse(canAssumeUdfps || canAssumeSfps)
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchEnrollingWithGkPwHandle()
@@ -443,9 +533,17 @@ class FingerprintEnrollmentActivityTest {
assertThat(device.wait(Until.hasObject(By.text(enrollingPageTitle)), IDLE_TIMEOUT)).isTrue()
}
@Test
fun testEnrollingIconTouchDialog_withRfps_landscape() {
runAsLandscape = true
testEnrollingIconTouchDialog_withRfps()
}
@Test
fun testFindUdfpsWithGkPwHandle_clickStart() {
Assume.assumeTrue(canAssumeUdfps)
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchFindSensorWithGkPwHandle()
@@ -464,9 +562,54 @@ class FingerprintEnrollmentActivityTest {
assertThat(device.wait(Until.hasObject(By.text(enrollingPageTitle)), IDLE_TIMEOUT)).isTrue()
}
@Test
fun testFindUdfpsWithGkPwHandle_clickStart_landscape() {
runAsLandscape = true
testFindUdfpsWithGkPwHandle_clickStart()
}
@Test
fun testFindUdfpsLandscapeWithGkPwHandle_clickStartThenBack() {
Assume.assumeTrue(canAssumeUdfps)
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchFindSensorWithGkPwHandle()
// FindUdfps page (portrait)
assertThat(device.wait(Until.hasObject(By.text(DO_IT_LATER)), IDLE_TIMEOUT)).isTrue()
// rotate device
device.setOrientationLandscape()
device.waitForIdle()
// FindUdfps page (landscape)
assertThat(device.wait(Until.hasObject(By.text(DO_IT_LATER)), IDLE_TIMEOUT)).isTrue()
val lottie = device.findObject(
By.res(SETTINGS_PACKAGE_NAME, "illustration_lottie")
)
assertThat(lottie).isNotNull()
assertThat(lottie.isClickable).isTrue()
val startBtn = device.findObject(By.text("Start"))
assertThat(startBtn.isClickable).isTrue()
startBtn.click()
// Enrolling page
assertThat(device.wait(Until.hasObject(By.text(enrollingPageTitle)), IDLE_TIMEOUT)).isTrue()
// Press back
device.pressBack()
device.waitForIdle()
// FindUdfps page (landscape-again)
assertThat(device.wait(Until.hasObject(By.text(DO_IT_LATER)), IDLE_TIMEOUT)).isTrue()
}
@Test
fun testFindUdfpsWithGkPwHandle_clickLottie() {
Assume.assumeTrue(canAssumeUdfps)
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchFindSensorWithGkPwHandle()
@@ -485,9 +628,17 @@ class FingerprintEnrollmentActivityTest {
assertThat(device.wait(Until.hasObject(By.text(enrollingPageTitle)), IDLE_TIMEOUT)).isTrue()
}
@Test
fun testFindUdfpsWithGkPwHandle_clickLottie_landscape() {
runAsLandscape = true
testFindUdfpsWithGkPwHandle_clickLottie()
}
@Test
fun testFindSfpsWithGkPwHandle() {
Assume.assumeTrue(canAssumeSfps)
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchFindSensorWithGkPwHandle()
@@ -501,9 +652,17 @@ class FingerprintEnrollmentActivityTest {
// We don't have view which can be clicked to run to next page, stop at here.
}
@Test
fun testFindSfpsWithGkPwHandle_landscape() {
runAsLandscape = true
testFindSfpsWithGkPwHandle()
}
@Test
fun testFindRfpsWithGkPwHandle() {
Assume.assumeFalse(canAssumeUdfps || canAssumeSfps)
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchFindSensorWithGkPwHandle()
@@ -528,8 +687,15 @@ class FingerprintEnrollmentActivityTest {
}
}
@Test
fun testFindRfpsWithGkPwHandle_landscape() {
runAsLandscape = true
testFindRfpsWithGkPwHandle()
}
@Test
fun testFindSensorWithGkPwHandle_clickSkipInFindSensor() {
setDeviceOrientation()
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true)
launchFindSensorWithGkPwHandle()
@@ -545,6 +711,12 @@ class FingerprintEnrollmentActivityTest {
assertThat(device.wait(Until.gone(By.text(DO_IT_LATER)), IDLE_TIMEOUT)).isTrue()
}
@Test
fun testFindSensorWithGkPwHandle_clickSkipInFindSensor_landscape() {
runAsLandscape = true
testFindSensorWithGkPwHandle_clickSkipInFindSensor()
}
private fun launchIntroWithGkPwHandle(isSuw: Boolean) {
val lockPatternUtils = LockPatternUtils(context)
val lockscreenCredential = LockscreenCredential.createPin(TEST_PIN)
@@ -610,6 +782,15 @@ class FingerprintEnrollmentActivityTest {
return intent
}
private fun setDeviceOrientation() {
if (runAsLandscape) {
device.setOrientationLandscape()
} else {
device.setOrientationPortrait()
}
device.waitForIdle()
}
companion object {
private const val TAG = "FingerprintEnrollmentActivityTest"
const val SETTINGS_PACKAGE_NAME = "com.android.settings"