Snap for 9794482 from 3a2ef6db2f to tm-qpr3-release

Change-Id: Ice68ed60223ded9b58c046736376f9629cc5f1de
This commit is contained in:
Android Build Coastguard Worker
2023-03-22 23:28:28 +00:00
8 changed files with 218 additions and 65 deletions

View File

@@ -1,26 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/SudDescription.Glif"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingTop="@dimen/sud_description_glif_margin_top"
android:paddingBottom="@dimen/sud_description_glif_margin_bottom_lists"
android:text="@string/lock_settings_picker_biometrics_added_security_message" />

View File

@@ -1,26 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/SudDescription.Glif"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingTop="@dimen/sud_description_glif_margin_top"
android:paddingBottom="@dimen/sud_description_glif_margin_bottom_lists"
android:text="@string/setup_lock_settings_picker_message" />

View File

@@ -183,7 +183,9 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
mUserManager = UserManager.get(this);
updatePasswordQuality();
if (!mConfirmingCredentials) {
// Check isFinishing() because FaceEnrollIntroduction may finish self to launch
// FaceSettings during onCreate()
if (!mConfirmingCredentials && !isFinishing()) {
if (!mHasPassword) {
// No password registered, launch into enrollment wizard.
mConfirmingCredentials = true;

View File

@@ -28,6 +28,7 @@ import android.hardware.SensorPrivacyManager;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.face.FaceManager;
import android.os.Bundle;
import android.os.UserHandle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
@@ -42,6 +43,7 @@ import androidx.annotation.StringRes;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.Settings;
import com.android.settings.Utils;
import com.android.settings.biometrics.BiometricEnrollActivity;
import com.android.settings.biometrics.BiometricEnrollIntroduction;
@@ -110,8 +112,26 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
@Override
protected void onCreate(Bundle savedInstanceState) {
mFaceManager = getFaceManager();
if (savedInstanceState == null
&& !WizardManagerHelper.isAnySetupWizard(getIntent())
&& !getIntent().getBooleanExtra(EXTRA_FROM_SETTINGS_SUMMARY, false)
&& maxFacesEnrolled()) {
// from tips && maxEnrolled
Log.d(TAG, "launch face settings");
launchFaceSettingsActivity();
finish();
}
super.onCreate(savedInstanceState);
// Wait super::onCreated() then return because SuperNotCalledExceptio will be thrown
// if we don't wait for it.
if (isFinishing()) {
return;
}
// Apply extracted theme color to icons.
final ImageView iconGlasses = findViewById(R.id.icon_glasses);
final ImageView iconLooking = findViewById(R.id.icon_looking);
@@ -152,8 +172,6 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
infoMessageRequireEyes.setText(getInfoMessageRequireEyes());
}
mFaceManager = getFaceManager();
// This path is an entry point for SetNewPasswordController, e.g.
// adb shell am start -a android.app.action.SET_NEW_PASSWORD
if (mToken == null && BiometricUtils.containsGatekeeperPasswordHandle(getIntent())) {
@@ -191,6 +209,24 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
Log.v(TAG, "cameraPrivacyEnabled : " + cameraPrivacyEnabled);
}
private void launchFaceSettingsActivity() {
final Intent intent = new Intent(this, Settings.FaceSettingsInternalActivity.class);
final byte[] token = getIntent().getByteArrayExtra(
ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
if (token != null) {
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, token);
}
final int userId = getIntent().getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
if (userId != UserHandle.USER_NULL) {
intent.putExtra(Intent.EXTRA_USER_ID, userId);
}
BiometricUtils.copyMultiBiometricExtras(getIntent(), intent);
intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, true);
intent.putExtra(EXTRA_KEY_CHALLENGE, getIntent().getLongExtra(EXTRA_KEY_CHALLENGE, -1L));
intent.putExtra(EXTRA_KEY_SENSOR_ID, getIntent().getIntExtra(EXTRA_KEY_SENSOR_ID, -1));
startActivity(intent);
}
@VisibleForTesting
@Nullable
protected FaceManager getFaceManager() {
@@ -232,6 +268,15 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
@Override
protected void onStart() {
super.onStart();
listenFoldEventForPostureGuidance();
}
private void listenFoldEventForPostureGuidance() {
if (maxFacesEnrolled()) {
Log.d(TAG, "Device has enrolled face, do not show posture guidance");
return;
}
if (getPostureGuidanceIntent() == null) {
Log.d(TAG, "Device do not support posture guidance");
return;

View File

@@ -109,6 +109,7 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
super.onViewCreated(view, savedInstanceState);
GlifPreferenceLayout layout = (GlifPreferenceLayout) view;
layout.setDescriptionText(loadDescriptionText());
layout.setDividerItemDecoration(new SettingsDividerItemDecoration(getContext()));
layout.setDividerInset(getContext().getResources().getDimensionPixelSize(
R.dimen.sud_items_glif_text_divider_inset));
@@ -129,11 +130,9 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
@Override
protected void addHeaderView() {
if (isForBiometric()) {
setHeaderView(R.layout.setup_choose_lock_generic_biometrics_header);
} else {
setHeaderView(R.layout.setup_choose_lock_generic_header);
}
// The original logic has been moved to onViewCreated and
// uses GlifLayout#setDescriptionText instead,
// keep empty body here since we won't call super method.
}
@Override
@@ -239,6 +238,12 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
private boolean isForBiometric() {
return mForFingerprint || mForFace || mForBiometrics;
}
String loadDescriptionText() {
return getString(isForBiometric()
? R.string.lock_settings_picker_biometrics_added_security_message
: R.string.setup_lock_settings_picker_message);
}
}
public static class InternalActivity extends ChooseLockGeneric.InternalActivity {

View File

@@ -51,6 +51,8 @@ import androidx.test.core.app.ApplicationProvider;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
import com.android.settings.Settings;
import com.android.settings.biometrics.BiometricEnrollBase;
import com.android.settings.biometrics.BiometricUtils;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settings.testutils.FakeFeatureFactory;
@@ -62,6 +64,7 @@ import com.android.settings.testutils.shadow.ShadowUtils;
import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupcompat.template.FooterButton;
import com.google.android.setupcompat.util.WizardManagerHelper;
import com.google.android.setupdesign.GlifLayout;
import com.google.android.setupdesign.view.BottomScrollView;
@@ -168,6 +171,7 @@ public class FaceEnrollIntroductionTest {
@After
public void tearDown() {
ShadowUtils.reset();
ShadowLockPatternUtils.reset();
}
private void setupActivity() {
@@ -315,7 +319,7 @@ public class FaceEnrollIntroductionTest {
}
@Test
public void testFaceEnrollEducation_hasBottomScrollView() {
public void testFaceEnrollIntroduction_hasBottomScrollView() {
setupActivity();
BottomScrollView scrollView = getGlifLayout(mActivity).findViewById(R.id.sud_scroll_view);
@@ -387,7 +391,7 @@ public class FaceEnrollIntroductionTest {
}
@Test
public void testFaceEnrollEducation_onFoldedUpdated_folded() {
public void testFaceEnrollIntroduction_onFoldedUpdated_folded() {
final Configuration newConfig = new Configuration();
newConfig.smallestScreenWidthDp = DENSITY_DEFAULT;
setupActivityForPosture();
@@ -400,4 +404,97 @@ public class FaceEnrollIntroductionTest {
assertThat(mSpyActivity.getDevicePostureState()).isEqualTo(DEVICE_POSTURE_CLOSED);
}
@Test
public void testFaceEnrollIntroduction_maxFacesEnrolled_launchFaceSettings() {
setFaceManagerToHave(1 /* numEnrollments */);
final Intent intent = new Intent();
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get();
mActivity.mOverrideFaceManager = mFaceManager;
mController.create();
ShadowActivity shadowActivity = Shadows.shadowOf(mActivity);
final Intent nextStartedActivity = shadowActivity.getNextStartedActivity();
assertThat(nextStartedActivity).isNotNull();
assertThat(nextStartedActivity.getComponent().getClassName())
.isEqualTo(Settings.FaceSettingsInternalActivity.class.getName());
}
@Test
public void testFaceEnrollIntroduction_maxFacesEnrolled_isSuw_notLaunchFaceSettings() {
setFaceManagerToHave(1 /* numEnrollments */);
ShadowLockPatternUtils.setActivePasswordQuality(PASSWORD_QUALITY_NUMERIC);
final Intent intent = new Intent();
intent.putExtra(WizardManagerHelper.EXTRA_IS_SETUP_FLOW, true);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get();
mActivity.mOverrideFaceManager = mFaceManager;
mController.create();
ShadowActivity shadowActivity = Shadows.shadowOf(mActivity);
final Intent nextStartedActivity = shadowActivity.getNextStartedActivity();
assertThat(nextStartedActivity).isNull();
}
@Test
public void testFaceEnrollIntroduction_maxFacesEnrolled_fromSettings_notLaunchFaceSettings() {
setFaceManagerToHave(1 /* numEnrollments */);
ShadowLockPatternUtils.setActivePasswordQuality(PASSWORD_QUALITY_NUMERIC);
final Intent intent = new Intent();
intent.putExtra(BiometricEnrollBase.EXTRA_FROM_SETTINGS_SUMMARY, true);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get();
mActivity.mOverrideFaceManager = mFaceManager;
mController.create();
ShadowActivity shadowActivity = Shadows.shadowOf(mActivity);
final Intent nextStartedActivity = shadowActivity.getNextStartedActivity();
assertThat(nextStartedActivity).isNull();
}
@Test
public void testFaceEnrollIntroduction_hasPostureCallback() {
when(mFakeFeatureFactory.mFaceFeatureProvider.getPostureGuidanceIntent(any()))
.thenReturn(new Intent());
setFaceManagerToHave(0 /* numEnrollments */);
ShadowLockPatternUtils.setActivePasswordQuality(PASSWORD_QUALITY_NUMERIC);
final Intent intent = new Intent();
intent.putExtra(BiometricEnrollBase.EXTRA_FROM_SETTINGS_SUMMARY, true);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get();
mActivity.mOverrideFaceManager = mFaceManager;
mController.create();
mController.start();
assertThat(mActivity.getPostureCallback()).isNotNull();
}
@Test
public void testFaceEnrollIntroduction_maxFacesEnrolled_noPostureCallback() {
when(mFakeFeatureFactory.mFaceFeatureProvider.getPostureGuidanceIntent(any()))
.thenReturn(new Intent());
setFaceManagerToHave(1 /* numEnrollments */);
ShadowLockPatternUtils.setActivePasswordQuality(PASSWORD_QUALITY_NUMERIC);
final Intent intent = new Intent();
intent.putExtra(BiometricEnrollBase.EXTRA_FROM_SETTINGS_SUMMARY, true);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get();
mActivity.mOverrideFaceManager = mFaceManager;
mController.create();
mController.start();
assertThat(mActivity.getPostureCallback()).isNull();
}
}

View File

@@ -23,15 +23,20 @@ import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_R
import static com.google.common.truth.Truth.assertThat;
import static org.robolectric.Shadows.shadowOf;
import android.content.Intent;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.android.settings.password.SetupChooseLockGeneric.SetupChooseLockGenericFragment;
import com.android.settings.testutils.shadow.ShadowLockPatternUtils;
import com.android.settings.testutils.shadow.ShadowPasswordUtils;
import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settings.testutils.shadow.ShadowUtils;
import com.google.android.setupdesign.GlifPreferenceLayout;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -41,6 +46,8 @@ import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowActivity;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
ShadowUserManager.class,
@@ -78,4 +85,43 @@ public class SetupChooseLockGenericTest {
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
assertThat(shadowActivity.isFinishing()).isFalse();
}
@Test
public void setupChooseLockGenericUsingDescriptionTextOfGlifLayout() {
SetupChooseLockGenericFragment fragment = getFragmentOfSetupChooseLockGeneric(false);
GlifPreferenceLayout view = getViewOfSetupChooseLockGenericFragment(fragment);
assertThat(TextUtils.isEmpty(view.getDescriptionText())).isFalse();
assertThat(view.getDescriptionText().toString()).isEqualTo(fragment.loadDescriptionText());
}
@Test
public void setupChooseLockGenericUsingDescriptionTextOfGlifLayoutForBiometric() {
SetupChooseLockGenericFragment fragment = getFragmentOfSetupChooseLockGeneric(true);
GlifPreferenceLayout view = getViewOfSetupChooseLockGenericFragment(fragment);
assertThat(TextUtils.isEmpty(view.getDescriptionText())).isFalse();
assertThat(view.getDescriptionText().toString()).isEqualTo(fragment.loadDescriptionText());
}
private SetupChooseLockGenericFragment getFragmentOfSetupChooseLockGeneric(boolean biometric) {
ShadowPasswordUtils.addGrantedPermission(REQUEST_PASSWORD_COMPLEXITY);
Intent intent = new Intent("com.android.settings.SETUP_LOCK_SCREEN");
intent.putExtra(EXTRA_KEY_REQUESTED_MIN_COMPLEXITY, PASSWORD_COMPLEXITY_HIGH);
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, biometric);
SetupChooseLockGeneric activity =
Robolectric.buildActivity(SetupChooseLockGeneric.class, intent).setup().get();
List<Fragment> fragments = activity.getSupportFragmentManager().getFragments();
assertThat(fragments).isNotNull();
assertThat(fragments.size()).isEqualTo(1);
assertThat(fragments.get(0)).isInstanceOf(SetupChooseLockGenericFragment.class);
return (SetupChooseLockGenericFragment) fragments.get(0);
}
private GlifPreferenceLayout getViewOfSetupChooseLockGenericFragment(
@NonNull SetupChooseLockGenericFragment fragment) {
assertThat(fragment.getView()).isNotNull();
assertThat(fragment.getView()).isInstanceOf(GlifPreferenceLayout.class);
return (GlifPreferenceLayout) fragment.getView();
}
}

View File

@@ -36,6 +36,7 @@ import java.util.Map;
public class ShadowLockPatternUtils {
private static boolean sDeviceEncryptionEnabled;
private static Map<Integer, Integer> sUserToActivePasswordQualityMap = new HashMap<>();
private static Map<Integer, Integer> sUserToComplexityMap = new HashMap<>();
private static Map<Integer, Integer> sUserToProfileComplexityMap = new HashMap<>();
private static Map<Integer, PasswordMetrics> sUserToMetricsMap = new HashMap<>();
@@ -44,6 +45,7 @@ public class ShadowLockPatternUtils {
@Resetter
public static void reset() {
sUserToActivePasswordQualityMap.clear();
sUserToComplexityMap.clear();
sUserToProfileComplexityMap.clear();
sUserToMetricsMap.clear();
@@ -72,7 +74,11 @@ public class ShadowLockPatternUtils {
@Implementation
protected int getActivePasswordQuality(int userId) {
return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
final Integer activePasswordQuality = sUserToActivePasswordQualityMap.get(userId);
if (activePasswordQuality == null) {
return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
}
return activePasswordQuality;
}
@Implementation
@@ -153,6 +159,10 @@ public class ShadowLockPatternUtils {
sUserToProfileMetricsMap.put(UserHandle.myUserId(), metrics);
}
public static void setActivePasswordQuality(int quality) {
sUserToActivePasswordQualityMap.put(UserHandle.myUserId(), quality);
}
@Implementation
public boolean isLockScreenDisabled(int userId) {
return false;