Merge "(2/N) Biometric error dialog" into main

This commit is contained in:
Diya Bera
2024-09-17 23:58:50 +00:00
committed by Android (Google) Code Review
9 changed files with 118 additions and 56 deletions

View File

@@ -65,11 +65,13 @@ import android.widget.TextView;
import androidx.annotation.VisibleForTesting;
import com.android.settings.biometrics.IdentityCheckBiometricErrorDialog;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.enterprise.ActionDisabledByAdminDialogHelper;
import com.android.settings.flags.Flags;
import com.android.settings.network.SubscriptionUtil;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settings.password.ConfirmDeviceCredentialActivity;
import com.android.settings.password.ConfirmLockPattern;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -178,6 +180,12 @@ public class MainClear extends InstrumentedFragment implements OnGlobalLayoutLis
if (resultCode != Activity.RESULT_OK) {
establishInitialState();
if (requestCode == BIOMETRICS_REQUEST) {
if (resultCode == ConfirmDeviceCredentialActivity.BIOMETRIC_LOCKOUT_ERROR_RESULT) {
IdentityCheckBiometricErrorDialog.showBiometricErrorDialog(getActivity(),
Utils.BiometricStatus.LOCKOUT, true /* twoFactorAuthentication */);
}
}
return;
}
@@ -192,6 +200,8 @@ public class MainClear extends InstrumentedFragment implements OnGlobalLayoutLis
userId, false /* hideBackground */);
return;
} else if (biometricAuthStatus != Utils.BiometricStatus.NOT_ACTIVE) {
IdentityCheckBiometricErrorDialog.showBiometricErrorDialog(getActivity(),
biometricAuthStatus, true /* twoFactorAuthentication */);
return;
}
}

View File

@@ -1522,6 +1522,7 @@ public final class Utils extends com.android.settingslib.Utils {
case BiometricManager.BIOMETRIC_ERROR_LOCKOUT:
return BiometricStatus.LOCKOUT;
case BiometricManager.BIOMETRIC_ERROR_MANDATORY_NOT_ACTIVE:
case BiometricManager.BIOMETRIC_ERROR_NOT_ENABLED_FOR_APPS:
return BiometricStatus.NOT_ACTIVE;
default:
return BiometricStatus.ERROR;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.development;
package com.android.settings.biometrics;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -45,10 +45,12 @@ import com.android.settings.Utils;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
/** Initializes and shows biometric error dialogs related to identity check. */
public class BiometricErrorDialog extends InstrumentedDialogFragment {
public class IdentityCheckBiometricErrorDialog extends InstrumentedDialogFragment {
private static final String TAG = "BiometricErrorDialog";
private static final String KEY_ERROR_CODE = "key_error_code";
private static final String KEY_TWO_FACTOR_AUTHENTICATION = "key_two_factor_authentication";
private String mActionIdentityCheckSettings = Settings.ACTION_SETTINGS;
@Nullable private BroadcastReceiver mBroadcastReceiver;
@@ -62,17 +64,19 @@ public class BiometricErrorDialog extends InstrumentedDialogFragment {
Utils.BiometricStatus.LOCKOUT.name());
final View customView = inflater.inflate(R.layout.biometric_lockout_error_dialog,
null);
final boolean twoFactorAuthentication = getArguments().getBoolean(
KEY_TWO_FACTOR_AUTHENTICATION);
final String identityCheckSettingsAction = getActivity().getString(
R.string.identity_check_settings_action);
mActionIdentityCheckSettings = identityCheckSettingsAction.isEmpty()
? mActionIdentityCheckSettings : identityCheckSettingsAction;
Log.d(TAG, mActionIdentityCheckSettings);
setTitle(customView, isLockoutError);
setBody(customView, isLockoutError);
setBody(customView, isLockoutError, twoFactorAuthentication);
alertDialogBuilder.setView(customView);
setPositiveButton(alertDialogBuilder, isLockoutError);
setNegativeButton(alertDialogBuilder, isLockoutError);
setPositiveButton(alertDialogBuilder, isLockoutError, twoFactorAuthentication);
if (!isLockoutError || !twoFactorAuthentication) {
setNegativeButton(alertDialogBuilder, isLockoutError);
}
if (isLockoutError) {
mBroadcastReceiver = new BroadcastReceiver() {
@Override
@@ -103,15 +107,16 @@ public class BiometricErrorDialog extends InstrumentedDialogFragment {
* @param fragmentActivity calling activity
* @param errorCode refers to the biometric error
*/
public static BiometricErrorDialog showBiometricErrorDialog(FragmentActivity fragmentActivity,
Utils.BiometricStatus errorCode) {
final BiometricErrorDialog biometricErrorDialog = new BiometricErrorDialog();
public static void showBiometricErrorDialog(FragmentActivity fragmentActivity,
Utils.BiometricStatus errorCode, boolean twoFactorAuthentication) {
final IdentityCheckBiometricErrorDialog identityCheckBiometricErrorDialog =
new IdentityCheckBiometricErrorDialog();
final Bundle args = new Bundle();
args.putCharSequence(KEY_ERROR_CODE, errorCode.name());
biometricErrorDialog.setArguments(args);
biometricErrorDialog.show(fragmentActivity.getSupportFragmentManager(),
BiometricErrorDialog.class.getName());
return biometricErrorDialog;
args.putBoolean(KEY_TWO_FACTOR_AUTHENTICATION, twoFactorAuthentication);
identityCheckBiometricErrorDialog.setArguments(args);
identityCheckBiometricErrorDialog.show(fragmentActivity.getSupportFragmentManager(),
IdentityCheckBiometricErrorDialog.class.getName());
}
private void setTitle(View view, boolean lockout) {
@@ -123,12 +128,17 @@ public class BiometricErrorDialog extends InstrumentedDialogFragment {
}
}
private void setBody(View view, boolean lockout) {
private void setBody(View view, boolean lockout, boolean twoFactorAuthentication) {
final TextView textView1 = view.findViewById(R.id.description_1);
final TextView textView2 = view.findViewById(R.id.description_2);
if (lockout) {
textView1.setText(R.string.identity_check_lockout_error_description_1);
if (twoFactorAuthentication) {
textView1.setText(
R.string.identity_check_lockout_error_two_factor_auth_description_1);
} else {
textView1.setText(R.string.identity_check_lockout_error_description_1);
}
textView2.setText(getClickableDescriptionForLockoutError());
textView2.setMovementMethod(LinkMovementMethod.getInstance());
} else {
@@ -167,15 +177,22 @@ public class BiometricErrorDialog extends InstrumentedDialogFragment {
return spannableString;
}
private void setPositiveButton(AlertDialog.Builder alertDialogBuilder, boolean lockout) {
private void setPositiveButton(AlertDialog.Builder alertDialogBuilder, boolean lockout,
boolean twoFactorAuthentication) {
if (lockout) {
DevicePolicyManager devicePolicyManager = (DevicePolicyManager)
getContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
alertDialogBuilder.setPositiveButton(R.string.identity_check_lockout_error_lock_screen,
(dialog, which) -> {
dialog.dismiss();
devicePolicyManager.lockNow();
});
if (twoFactorAuthentication) {
alertDialogBuilder.setPositiveButton((R.string.okay),
(dialog, which) -> dialog.dismiss());
} else {
DevicePolicyManager devicePolicyManager = (DevicePolicyManager)
getContext().getSystemService(Context.DEVICE_POLICY_SERVICE);
alertDialogBuilder.setPositiveButton(
R.string.identity_check_lockout_error_lock_screen,
(dialog, which) -> {
dialog.dismiss();
devicePolicyManager.lockNow();
});
}
} else {
alertDialogBuilder.setPositiveButton(R.string.identity_check_biometric_error_ok,
(dialog, which) -> dialog.dismiss());

View File

@@ -57,6 +57,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
import com.android.settings.biometrics.IdentityCheckBiometricErrorDialog;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.development.autofill.AutofillCategoryController;
@@ -378,8 +379,8 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
userId, false /* hideBackground */);
} else if (biometricAuthStatus != Utils.BiometricStatus.NOT_ACTIVE) {
mSwitchBar.setChecked(false);
BiometricErrorDialog.showBiometricErrorDialog(
getActivity(), biometricAuthStatus);
IdentityCheckBiometricErrorDialog.showBiometricErrorDialog(getActivity(),
biometricAuthStatus, false /* twoFactorAuthentication */);
} else {
//Reset biometrics once enable dialog is shown
mIsBiometricsAuthenticated = false;
@@ -564,8 +565,8 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
mSwitchBar.setChecked(true);
} else if (resultCode
== ConfirmDeviceCredentialActivity.BIOMETRIC_LOCKOUT_ERROR_RESULT) {
BiometricErrorDialog.showBiometricErrorDialog(getActivity(),
Utils.BiometricStatus.LOCKOUT);
IdentityCheckBiometricErrorDialog.showBiometricErrorDialog(getActivity(),
Utils.BiometricStatus.LOCKOUT, false /* twoFactorAuthentication */);
}
}
for (AbstractPreferenceController controller : mPreferenceControllers) {

View File

@@ -36,10 +36,12 @@ import androidx.preference.Preference;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.biometrics.IdentityCheckBiometricErrorDialog;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settings.password.ConfirmDeviceCredentialActivity;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -235,10 +237,18 @@ public class BuildNumberPreferenceController extends BasePreferenceController im
userId, false /* hideBackground */);
} else if (biometricAuthStatus == Utils.BiometricStatus.NOT_ACTIVE) {
enableDevelopmentSettings();
} else {
IdentityCheckBiometricErrorDialog.showBiometricErrorDialog(mFragment.getActivity(),
biometricAuthStatus, true /* twoFactorAuthentication */);
}
} else if (requestCode == REQUEST_IDENTITY_CHECK_FOR_DEV_PREF) {
if (resultCode == Activity.RESULT_OK) {
enableDevelopmentSettings();
} else if (resultCode
== ConfirmDeviceCredentialActivity.BIOMETRIC_LOCKOUT_ERROR_RESULT) {
IdentityCheckBiometricErrorDialog.showBiometricErrorDialog(mFragment.getActivity(),
Utils.BiometricStatus.LOCKOUT, true /* twoFactorAuthentication */);
}
} else if (requestCode == REQUEST_IDENTITY_CHECK_FOR_DEV_PREF
&& resultCode == Activity.RESULT_OK) {
enableDevelopmentSettings();
}
mProcessingLastDevHit = false;
return true;