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