Home | History | Annotate | Download | only in security
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.settings.security;
     18 
     19 import android.app.Activity;
     20 import android.app.AlertDialog;
     21 import android.app.Dialog;
     22 import android.app.admin.DevicePolicyManager;
     23 import android.content.DialogInterface;
     24 import android.content.Intent;
     25 import android.os.Bundle;
     26 import android.support.annotation.VisibleForTesting;
     27 
     28 import com.android.internal.logging.nano.MetricsProto;
     29 import com.android.settings.CredentialStorage;
     30 import com.android.settings.R;
     31 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
     32 import com.android.settings.password.ChooseLockGeneric;
     33 
     34 /**
     35  * Prompt for key guard configuration confirmation.
     36  */
     37 public class ConfigureKeyGuardDialog extends InstrumentedDialogFragment
     38         implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
     39 
     40     public static final String TAG = "ConfigureKeyGuardDialog";
     41 
     42     private boolean mConfigureConfirmed;
     43 
     44     @Override
     45     public int getMetricsCategory() {
     46         return MetricsProto.MetricsEvent.CONFIGURE_KEYGUARD_DIALOG;
     47     }
     48 
     49     @Override
     50     public Dialog onCreateDialog(Bundle savedInstanceState) {
     51         return new AlertDialog.Builder(getActivity())
     52                 .setTitle(android.R.string.dialog_alert_title)
     53                 .setMessage(R.string.credentials_configure_lock_screen_hint)
     54                 .setPositiveButton(R.string.credentials_configure_lock_screen_button, this)
     55                 .setNegativeButton(android.R.string.cancel, this)
     56                 .create();
     57     }
     58 
     59     @Override
     60     public void onClick(DialogInterface dialog, int button) {
     61         mConfigureConfirmed = (button == DialogInterface.BUTTON_POSITIVE);
     62     }
     63 
     64     @Override
     65     public void onDismiss(DialogInterface dialog) {
     66         if (mConfigureConfirmed) {
     67             mConfigureConfirmed = false;
     68             startPasswordSetup();
     69             return;
     70         } else {
     71             final Activity activity = getActivity();
     72             if (activity != null) {
     73                 activity.finish();
     74             }
     75         }
     76     }
     77 
     78     @VisibleForTesting
     79     void startPasswordSetup() {
     80         Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
     81         intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.MINIMUM_QUALITY_KEY,
     82                 CredentialStorage.MIN_PASSWORD_QUALITY);
     83         startActivity(intent);
     84     }
     85 }
     86