Home | History | Annotate | Download | only in security
      1 /*
      2  * Copyright (C) 2018 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.AlertDialog;
     20 import android.app.Dialog;
     21 import android.app.FragmentManager;
     22 import android.content.DialogInterface;
     23 import android.os.Bundle;
     24 
     25 import com.android.internal.logging.nano.MetricsProto;
     26 import com.android.settings.R;
     27 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
     28 
     29 public class UnificationConfirmationDialog extends InstrumentedDialogFragment {
     30 
     31     static final String TAG_UNIFICATION_DIALOG = "unification_dialog";
     32     private static final String EXTRA_COMPLIANT = "compliant";
     33 
     34     public static UnificationConfirmationDialog newInstance(boolean compliant) {
     35         UnificationConfirmationDialog
     36                 dialog = new UnificationConfirmationDialog();
     37         Bundle args = new Bundle();
     38         args.putBoolean(EXTRA_COMPLIANT, compliant);
     39         dialog.setArguments(args);
     40         return dialog;
     41     }
     42 
     43     public void show(SecuritySettings host) {
     44         final FragmentManager manager = host.getChildFragmentManager();
     45         if (manager.findFragmentByTag(TAG_UNIFICATION_DIALOG) == null) {
     46             // Prevent opening multiple dialogs if tapped on button quickly
     47             show(manager, TAG_UNIFICATION_DIALOG);
     48         }
     49     }
     50 
     51     @Override
     52     public Dialog onCreateDialog(Bundle savedInstanceState) {
     53         final SecuritySettings parentFragment = ((SecuritySettings) getParentFragment());
     54         final boolean compliant = getArguments().getBoolean(EXTRA_COMPLIANT);
     55         return new AlertDialog.Builder(getActivity())
     56                 .setTitle(R.string.lock_settings_profile_unification_dialog_title)
     57                 .setMessage(compliant ? R.string.lock_settings_profile_unification_dialog_body
     58                         : R.string.lock_settings_profile_unification_dialog_uncompliant_body)
     59                 .setPositiveButton(
     60                         compliant ? R.string.lock_settings_profile_unification_dialog_confirm
     61                                 : R.string
     62                                         .lock_settings_profile_unification_dialog_uncompliant_confirm,
     63                         (dialog, whichButton) -> {
     64                             if (compliant) {
     65                                 parentFragment.launchConfirmDeviceLockForUnification();
     66                             } else {
     67                                 parentFragment.unifyUncompliantLocks();
     68                             }
     69                         }
     70                 )
     71                 .setNegativeButton(R.string.cancel, null)
     72                 .create();
     73     }
     74 
     75     @Override
     76     public void onDismiss(DialogInterface dialog) {
     77         super.onDismiss(dialog);
     78         ((SecuritySettings) getParentFragment()).updateUnificationPreference();
     79     }
     80 
     81     @Override
     82     public int getMetricsCategory() {
     83         return MetricsProto.MetricsEvent.DIALOG_UNIFICATION_CONFIRMATION;
     84     }
     85 }
     86