Merge "Apply dark light theme for enrollment activities" into tm-qpr-dev am: a46b426bcf am: 8a8fe4fabd

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/19989471

Change-Id: Id20b934f044607e7b4f93b2d5cb5ce37322fd65d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
index bea9cc5..c26837c 100644
--- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
@@ -31,6 +31,7 @@
 import android.content.Intent;
 import android.content.res.ColorStateList;
 import android.content.res.Configuration;
+import android.content.res.Resources;
 import android.graphics.PorterDuff;
 import android.graphics.PorterDuffColorFilter;
 import android.graphics.drawable.Animatable2;
@@ -63,6 +64,7 @@
 
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.settings.R;
+import com.android.settings.SetupWizardUtils;
 import com.android.settings.biometrics.BiometricEnrollSidecar;
 import com.android.settings.biometrics.BiometricUtils;
 import com.android.settings.biometrics.BiometricsEnrollEnrolling;
@@ -213,6 +215,13 @@
     }
 
     @Override
+    protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
+        final int newResid = SetupWizardUtils.getTheme(this, getIntent());
+        theme.applyStyle(R.style.SetupWizardPartnerResource, true);
+        super.onApplyThemeResource(theme, newResid, first);
+    }
+
+    @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java
index 5c32dff..bb03ee4 100644
--- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java
@@ -18,6 +18,7 @@
 
 import android.app.settings.SettingsEnums;
 import android.content.Intent;
+import android.content.res.Resources;
 import android.hardware.fingerprint.FingerprintManager;
 import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
 import android.os.Bundle;
@@ -31,6 +32,7 @@
 import androidx.annotation.Nullable;
 
 import com.android.settings.R;
+import com.android.settings.SetupWizardUtils;
 import com.android.settings.Utils;
 import com.android.settings.biometrics.BiometricEnrollBase;
 import com.android.settings.biometrics.BiometricEnrollSidecar;
@@ -211,6 +213,13 @@
         super.onBackPressed();
     }
 
+    @Override
+    protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
+        final int newResid = SetupWizardUtils.getTheme(this, getIntent());
+        theme.applyStyle(R.style.SetupWizardPartnerResource, true);
+        super.onApplyThemeResource(theme, newResid, first);
+    }
+
     protected int getContentView() {
         if (mCanAssumeUdfps) {
             return R.layout.udfps_enroll_find_sensor_layout;
diff --git a/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java b/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java
index 1ae5dae..f6b947a 100644
--- a/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java
+++ b/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java
@@ -77,7 +77,7 @@
 
         @NonNull
         public AlertDialog.Builder onCreateDialogBuilder() {
-            return new AlertDialog.Builder(getActivity(), R.style.GlifV2ThemeAlertDialog)
+            return new AlertDialog.Builder(getActivity())
                     .setTitle(R.string.setup_fingerprint_enroll_skip_title)
                     .setPositiveButton(R.string.skip_anyway_button_label, this)
                     .setNegativeButton(R.string.go_back_button_label, this)
diff --git a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrollingTest.java b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrollingTest.java
index 64786ea..42c3091 100644
--- a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrollingTest.java
+++ b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrollingTest.java
@@ -17,6 +17,7 @@
 package com.android.settings.biometrics.fingerprint;
 
 import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_POWER_BUTTON;
+import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_UDFPS_OPTICAL;
 
 import static com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling.KEY_STATE_PREVIOUS_ROTATION;
 import static com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling.SFPS_STAGE_NO_ANIMATION;
@@ -37,6 +38,7 @@
 
 import android.content.Context;
 import android.content.res.ColorStateList;
+import android.content.res.Resources;
 import android.hardware.biometrics.ComponentInfoInternal;
 import android.hardware.biometrics.SensorProperties;
 import android.hardware.fingerprint.FingerprintManager;
@@ -84,6 +86,8 @@
 
     @Mock private Display mMockDisplay;
 
+    @Mock private Resources.Theme mTheme;
+
     private final int[] mSfpsStageThresholds = new int[]{0, 9, 13, 19, 25};
 
     private FingerprintEnrollEnrolling mActivity;
@@ -110,7 +114,7 @@
 
     @Test
     public void fingerprintUdfpsEnrollSuccessProgress_shouldNotVibrate() {
-        initializeActivityFor(FingerprintSensorProperties.TYPE_UDFPS_OPTICAL);
+        initializeActivityFor(TYPE_UDFPS_OPTICAL);
 
         mActivity.onEnrollmentProgressChange(1, 1);
 
@@ -128,7 +132,7 @@
 
     @Test
     public void fingerprintUdfpsOverlayEnrollment_gainFocus_shouldNotCancel() {
-        initializeActivityFor(FingerprintSensorProperties.TYPE_UDFPS_OPTICAL);
+        initializeActivityFor(TYPE_UDFPS_OPTICAL);
 
         mActivity.onEnrollmentProgressChange(1, 1);
         mActivity.onWindowFocusChanged(true);
@@ -138,7 +142,7 @@
 
     @Test
     public void fingerprintUdfpsOverlayEnrollment_loseFocus_shouldCancel() {
-        initializeActivityFor(FingerprintSensorProperties.TYPE_UDFPS_OPTICAL);
+        initializeActivityFor(TYPE_UDFPS_OPTICAL);
 
         mActivity.onEnrollmentProgressChange(1, 1);
         mActivity.onWindowFocusChanged(false);
@@ -232,6 +236,24 @@
         verify(mActivity, never()).onCancelEnrollment(anyInt());
     }
 
+    @Test
+    public void fingerprintUdfpsEnroll_activityApplyDarkLightStyle() {
+        initializeActivityFor(TYPE_UDFPS_OPTICAL);
+
+        mActivity.onApplyThemeResource(mTheme, R.style.GlifTheme, true /* first */);
+
+        verify(mTheme).applyStyle(R.style.SetupWizardPartnerResource, true);
+    }
+
+    @Test
+    public void fingerprintSfpsEnroll_activityApplyDarkLightStyle() {
+        initializeActivityFor(TYPE_POWER_BUTTON);
+
+        mActivity.onApplyThemeResource(mTheme, R.style.GlifTheme, true /* first */);
+
+        verify(mTheme).applyStyle(R.style.SetupWizardPartnerResource, true);
+    }
+
     private void initializeActivityFor(int sensorType) {
         final List<ComponentInfoInternal> componentInfo = new ArrayList<>();
         final FingerprintSensorPropertiesInternal prop =
diff --git a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensorTest.java b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensorTest.java
index fad3abf..b6fcc47 100644
--- a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensorTest.java
+++ b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensorTest.java
@@ -16,6 +16,7 @@
 
 package com.android.settings.biometrics.fingerprint;
 
+import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_POWER_BUTTON;
 import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_REAR;
 import static android.hardware.fingerprint.FingerprintSensorProperties.TYPE_UDFPS_OPTICAL;
 
@@ -38,6 +39,7 @@
 import android.app.Activity;
 import android.content.ComponentName;
 import android.content.Intent;
+import android.content.res.Resources;
 import android.hardware.biometrics.ComponentInfoInternal;
 import android.hardware.biometrics.SensorProperties;
 import android.hardware.fingerprint.FingerprintManager;
@@ -87,6 +89,9 @@
     @Mock
     private FingerprintManager mFingerprintManager;
 
+    @Mock
+    private Resources.Theme mTheme;
+
     private ActivityController<FingerprintEnrollFindSensor> mActivityController;
 
     private FingerprintEnrollFindSensor mActivity;
@@ -125,6 +130,14 @@
         mActivityController.setup();
     }
 
+    private void setupActivity_onSfpsDevice() {
+        final ArrayList<FingerprintSensorPropertiesInternal> props = new ArrayList<>();
+        props.add(newFingerprintSensorPropertiesInternal(TYPE_POWER_BUTTON));
+        doReturn(props).when(mFingerprintManager).getSensorPropertiesInternal();
+
+        mActivityController.setup();
+    }
+
     private FingerprintSensorPropertiesInternal newFingerprintSensorPropertiesInternal(
             @FingerprintSensorProperties.SensorType int sensorType) {
         return new FingerprintSensorPropertiesInternal(
@@ -542,6 +555,16 @@
         gotEnrollingResult_recreateActivityAndVerifyResultThenForward(RESULT_TIMEOUT, bundle);
     }
 
+    @Test
+    public void fingerprintEnrollFindSensor_activityApplyDarkLightStyle() {
+        setupActivity_onSfpsDevice();
+        verifySidecar_onRearOrSfpsDevice();
+
+        mActivity.onApplyThemeResource(mActivity.getTheme(), R.style.GlifTheme, true /* first */);
+
+        verify(mTheme).applyStyle(R.style.SetupWizardPartnerResource, true);
+    }
+
     private void triggerEnrollProgressAndError_onRearDevice() {
         EnrollmentCallback enrollmentCallback = verifyAndCaptureEnrollmentCallback();
         enrollmentCallback.onEnrollmentProgress(123);
diff --git a/tests/robotests/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensorTest.java b/tests/robotests/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensorTest.java
index 54a7fb1..71cecc0 100644
--- a/tests/robotests/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensorTest.java
+++ b/tests/robotests/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensorTest.java
@@ -18,9 +18,11 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
+import static org.mockito.Mockito.verify;
 import static org.robolectric.RuntimeEnvironment.application;
 
 import android.content.Intent;
+import android.content.res.Resources.Theme;
 import android.hardware.fingerprint.FingerprintManager;
 
 import androidx.appcompat.app.AlertDialog;
@@ -48,14 +50,23 @@
 @Config(shadows = {ShadowUtils.class, ShadowAlertDialogCompat.class})
 public class SetupFingerprintEnrollFindSensorTest {
 
-    @Mock
-    private FingerprintManager mFingerprintManager;
+    @Mock private FingerprintManager mFingerprintManager;
+
+    @Mock private Theme mTheme;
+
+    private SetupFingerprintEnrollFindSensor mActivity;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         ShadowUtils.setFingerprintManager(mFingerprintManager);
         FakeFeatureFactory.setupForTest();
+
+        final Intent intent = new Intent()
+                // Set the challenge token so the confirm screen will not be shown
+                .putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
+        mActivity = Robolectric.buildActivity(SetupFingerprintEnrollFindSensor.class,
+                intent).setup().get();
     }
 
     @After
@@ -74,23 +85,14 @@
     }
 
     @Test
-    public void fingerprintEnroll_showsAlert_setSudTheme() {
-        final AlertDialog alertDialog = setupAlertDialog();
+    public void fingerprintEnroll_activityApplyDarkLightStyle() {
+        mActivity.onApplyThemeResource(mTheme, R.style.GlifTheme, true /* first */);
 
-        assertThat(alertDialog.getContext().getThemeResId()).isEqualTo(
-                R.style.GlifV2ThemeAlertDialog);
+        verify(mTheme).applyStyle(R.style.SetupWizardPartnerResource, true);
     }
 
     private AlertDialog setupAlertDialog() {
-        final Intent intent = new Intent()
-                // Set the challenge token so the confirm screen will not be shown
-                .putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
-
-        final SetupFingerprintEnrollFindSensor activity =
-                Robolectric.buildActivity(SetupFingerprintEnrollFindSensor.class,
-                        intent).setup().get();
-
-        PartnerCustomizationLayout layout = activity.findViewById(R.id.setup_wizard_layout);
+        PartnerCustomizationLayout layout = mActivity.findViewById(R.id.setup_wizard_layout);
         layout.getMixin(FooterBarMixin.class).getSecondaryButtonView().performClick();
 
         final AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();