Merge changes from topic "face-bypass-move" into qt-r1-dev

* changes:
  Make bypass controller consistent with rest of face unlock settings
  Move lockscreen bypass setting to Settings > Security > Face unlock
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5f47c8c..eeb2ce1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6086,10 +6086,6 @@
     <string name="sms_access_restriction_enabled">Restrict SMS &amp; call log access</string>
     <!-- Summary for whether to enable SMS access restriction [CHAR LIMIT=NONE]-->
     <string name="sms_access_restriction_enabled_summary">Only default phone and messaging apps have SMS &amp; call log permissions</string>
-    <!-- Title for the new device identifier access restrictions [CHAR LIMIT=50]-->
-    <string name="device_identifier_access_restrictions_title">Disable device identifier restrictions</string>
-    <!-- Summary for the new device identifier access restrictions [CHAR LIMIT=NONE]-->
-    <string name="device_identifier_access_restrictions_summary">Disable the new access restrictions for device identifiers</string>
 
 
     <!-- Message when there are no available trust agents to display -->
diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml
index b819dbb..7cf52fa 100644
--- a/res/xml/development_settings.xml
+++ b/res/xml/development_settings.xml
@@ -562,11 +562,6 @@
             android:summary="@string/sms_access_restriction_enabled_summary" />
 
         <SwitchPreference
-            android:key="device_identifier_access_restrictions"
-            android:title="@string/device_identifier_access_restrictions_title"
-            android:summary="@string/device_identifier_access_restrictions_summary" />
-
-        <SwitchPreference
             android:key="notification_bubbles"
             android:title="@string/notification_bubbles_title"
             android:summary="@string/notification_bubbles_developer_setting_summary"/>
diff --git a/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java b/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java
index d5414c9..d94686e 100644
--- a/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java
+++ b/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java
@@ -47,6 +47,8 @@
     private boolean mHasPassword;
     private boolean mBiometricUnlockDisabledByAdmin;
     private TextView mErrorText;
+    protected boolean mConfirmingCredentials;
+    protected boolean mNextClicked;
 
     /**
      * @return true if the biometric is disabled by a device administrator
@@ -149,10 +151,12 @@
 
         if (!mHasPassword) {
             // No password registered, launch into enrollment wizard.
+            mConfirmingCredentials = true;
             launchChooseLock();
         } else if (mToken == null) {
             // It's possible to have a token but mLaunchedConfirmLock == false, since
             // ChooseLockGeneric can pass us a token.
+            mConfirmingCredentials = true;
             launchConfirmLock(getConfirmLockTitleResId(), getChallenge());
         }
     }
@@ -182,6 +186,7 @@
 
     @Override
     protected void onNextButtonClick(View view) {
+        mNextClicked = true;
         if (checkMaxEnrolled() == 0) {
             // Lock thingy is already set up, launch directly to the next page
             launchNextEnrollingActivity(mToken);
@@ -249,12 +254,14 @@
                 mToken = data.getByteArrayExtra(
                         ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
                 overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out);
+                mConfirmingCredentials = false;
                 return;
             } else {
                 setResult(resultCode, data);
                 finish();
             }
         } else if (requestCode == CONFIRM_REQUEST) {
+            mConfirmingCredentials = false;
             if (resultCode == RESULT_OK && data != null) {
                 mToken = data.getByteArrayExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
                 overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out);
diff --git a/src/com/android/settings/biometrics/face/FaceEnrollEducation.java b/src/com/android/settings/biometrics/face/FaceEnrollEducation.java
index 16b0fcb..4bf5a1d 100644
--- a/src/com/android/settings/biometrics/face/FaceEnrollEducation.java
+++ b/src/com/android/settings/biometrics/face/FaceEnrollEducation.java
@@ -61,6 +61,7 @@
     private Handler mHandler;
     private Intent mResultIntent;
     private TextView mDescriptionText;
+    private boolean mNextClicked;
 
     private CompoundButton.OnCheckedChangeListener mSwitchDiversityListener =
             new CompoundButton.OnCheckedChangeListener() {
@@ -185,6 +186,17 @@
     }
 
     @Override
+    protected void onStop() {
+        super.onStop();
+
+        if (!isChangingConfigurations() && !WizardManagerHelper.isAnySetupWizard(getIntent())
+                && !mNextClicked) {
+            setResult(RESULT_SKIP);
+            finish();
+        }
+    }
+
+    @Override
     protected void onNextButtonClick(View view) {
         final Intent intent = new Intent();
         if (mToken != null) {
@@ -193,6 +205,7 @@
         if (mUserId != UserHandle.USER_NULL) {
             intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
         }
+        intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, mFromSettingsSummary);
         final String flattenedString = getString(R.string.config_face_enroll);
         if (!TextUtils.isEmpty(flattenedString)) {
             ComponentName componentName = ComponentName.unflattenFromString(flattenedString);
@@ -204,6 +217,7 @@
         if (mResultIntent != null) {
             intent.putExtras(mResultIntent);
         }
+        mNextClicked = true;
         WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent);
         startActivityForResult(intent, BIOMETRIC_FIND_SENSOR_REQUEST);
     }
diff --git a/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java b/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java
index 525c1a3..6686c96 100644
--- a/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java
+++ b/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java
@@ -78,6 +78,16 @@
     }
 
     @Override
+    protected void onStop() {
+        super.onStop();
+
+        if (!isChangingConfigurations() && !mConfirmingCredentials && !mNextClicked
+                && !WizardManagerHelper.isAnySetupWizard(getIntent())) {
+            finish();
+        }
+    }
+
+    @Override
     protected boolean isDisabledByAdmin() {
         return RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
                 this, DevicePolicyManager.KEYGUARD_DISABLE_FACE, mUserId) != null;
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index b253702..f384d85 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -480,7 +480,6 @@
         controllers.add(new ResizableActivityPreferenceController(context));
         controllers.add(new FreeformWindowsPreferenceController(context));
         controllers.add(new DesktopModePreferenceController(context));
-        controllers.add(new DeviceIdentifierAccessRestrictionsPreferenceController(context));
         controllers.add(new ShortcutManagerThrottlingPreferenceController(context));
         controllers.add(new BubbleGlobalPreferenceController(context));
         controllers.add(new EnableGnssRawMeasFullTrackingPreferenceController(context));
diff --git a/src/com/android/settings/development/DeviceIdentifierAccessRestrictionsPreferenceController.java b/src/com/android/settings/development/DeviceIdentifierAccessRestrictionsPreferenceController.java
deleted file mode 100644
index f4e5953..0000000
--- a/src/com/android/settings/development/DeviceIdentifierAccessRestrictionsPreferenceController.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2019 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.
- */
-
-package com.android.settings.development;
-
-import android.content.ContentResolver;
-import android.content.Context;
-import android.provider.DeviceConfig;
-import android.provider.Settings;
-
-import androidx.preference.Preference;
-import androidx.preference.SwitchPreference;
-
-import com.android.settings.Utils;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.development.DeveloperOptionsPreferenceController;
-
-public class DeviceIdentifierAccessRestrictionsPreferenceController
-        extends DeveloperOptionsPreferenceController
-        implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
-
-    private static final String DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_KEY =
-            "device_identifier_access_restrictions";
-
-    // The settings that should be set when the new device identifier access restrictions are
-    // disabled.
-    private static final String[] RELAX_DEVICE_IDENTIFIER_CHECK_SETTINGS = {
-            Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_3P_CHECK_RELAXED,
-            Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_NON_PRIV_CHECK_RELAXED,
-            Settings.Global.PRIVILEGED_DEVICE_IDENTIFIER_PRIV_CHECK_RELAXED
-    };
-
-    private ContentResolver mContentResolver;
-
-    public DeviceIdentifierAccessRestrictionsPreferenceController(Context context) {
-        super(context);
-        mContentResolver = context.getContentResolver();
-    }
-
-    @Override
-    public boolean isAvailable() {
-        // If the new access restrictions have been disabled from the server side then do not
-        // display the option.
-        boolean disabledFromServerSide = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
-                        Utils.PROPERTY_DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_DISABLED, false);
-        return !disabledFromServerSide;
-    }
-
-    @Override
-    public String getPreferenceKey() {
-        return DEVICE_IDENTIFIER_ACCESS_RESTRICTIONS_KEY;
-    }
-
-    @Override
-    public boolean onPreferenceChange(Preference preference, Object newValue) {
-        writeSetting((boolean) newValue);
-        return true;
-    }
-
-    private void writeSetting(boolean isEnabled) {
-        for (String relaxCheckSetting : RELAX_DEVICE_IDENTIFIER_CHECK_SETTINGS) {
-            Settings.Global.putInt(mContentResolver, relaxCheckSetting, isEnabled ? 1 : 0);
-        }
-    }
-
-    @Override
-    public void updateState(Preference preference) {
-        boolean isEnabled = true;
-        for (String relaxCheckSetting : RELAX_DEVICE_IDENTIFIER_CHECK_SETTINGS) {
-            if (Settings.Global.getInt(mContentResolver, relaxCheckSetting, 0) == 0) {
-                isEnabled = false;
-                break;
-            }
-        }
-        ((SwitchPreference) mPreference).setChecked(isEnabled);
-    }
-
-    @Override
-    protected void onDeveloperOptionsSwitchDisabled() {
-        super.onDeveloperOptionsSwitchDisabled();
-        writeSetting(false);
-        ((SwitchPreference) mPreference).setChecked(false);
-    }
-}