1 /* 2 * Copyright (C) 2019 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.applications.specialaccess.zenaccess; 18 19 import android.app.Dialog; 20 import android.app.Flags; 21 import android.app.settings.SettingsEnums; 22 import android.os.Bundle; 23 import android.text.TextUtils; 24 25 import androidx.appcompat.app.AlertDialog; 26 import androidx.fragment.app.Fragment; 27 28 import com.android.settings.R; 29 import com.android.settings.core.instrumentation.InstrumentedDialogFragment; 30 31 /** 32 * Warning dialog when revoking zen access warning that zen rule instances will be deleted. 33 */ 34 public class FriendlyWarningDialogFragment extends InstrumentedDialogFragment { 35 static final String KEY_PKG = "p"; 36 static final String KEY_LABEL = "l"; 37 38 39 @Override getMetricsCategory()40 public int getMetricsCategory() { 41 return SettingsEnums.DIALOG_ZEN_ACCESS_REVOKE; 42 } 43 setPkgInfo(String pkg, CharSequence label, Fragment target)44 public FriendlyWarningDialogFragment setPkgInfo(String pkg, CharSequence label, 45 Fragment target) { 46 Bundle args = new Bundle(); 47 args.putString(KEY_PKG, pkg); 48 args.putString(KEY_LABEL, TextUtils.isEmpty(label) ? pkg : label.toString()); 49 setTargetFragment(target, 0); 50 setArguments(args); 51 return this; 52 } 53 54 @Override onCreateDialog(Bundle savedInstanceState)55 public Dialog onCreateDialog(Bundle savedInstanceState) { 56 super.onCreate(savedInstanceState); 57 final Bundle args = getArguments(); 58 final String pkg = args.getString(KEY_PKG); 59 final String label = args.getString(KEY_LABEL); 60 61 final String title = getResources().getString( 62 Flags.modesUi() 63 ? R.string.zen_modes_access_revoke_warning_dialog_title 64 : R.string.zen_access_revoke_warning_dialog_title, 65 label); 66 final String summary = getResources() 67 .getString(Flags.modesUi() 68 ? R.string.zen_modes_access_revoke_warning_dialog_summary 69 : R.string.zen_access_revoke_warning_dialog_summary); 70 71 ZenAccessDetails parent = (ZenAccessDetails) getTargetFragment(); 72 return new AlertDialog.Builder(getContext()) 73 .setMessage(summary) 74 .setTitle(title) 75 .setCancelable(true) 76 .setPositiveButton(R.string.okay, 77 (dialog, id) -> { 78 ZenAccessController.deleteRules(getContext(), pkg); 79 ZenAccessController.setAccess(getContext(), pkg, false); 80 parent.refreshUi(); 81 }) 82 .setNegativeButton(R.string.cancel, 83 (dialog, id) -> { 84 // pass 85 }) 86 .create(); 87 } 88 } 89