1 /* 2 * Copyright (C) 2021 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.notification; 18 19 import android.app.Dialog; 20 import android.app.settings.SettingsEnums; 21 import android.content.ComponentName; 22 import android.content.DialogInterface; 23 import android.os.Bundle; 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 public class NotificationAssistantDialogFragment extends InstrumentedDialogFragment 32 implements DialogInterface.OnClickListener { 33 static final String KEY_COMPONENT = "c"; 34 newInstance(Fragment target, ComponentName cn)35 public static NotificationAssistantDialogFragment newInstance(Fragment target, 36 ComponentName cn) { 37 final NotificationAssistantDialogFragment dialogFragment = 38 new NotificationAssistantDialogFragment(); 39 final Bundle args = new Bundle(); 40 args.putString(KEY_COMPONENT, cn == null ? "" : cn.flattenToString()); 41 dialogFragment.setArguments(args); 42 dialogFragment.setTargetFragment(target, 0); 43 44 return dialogFragment; 45 } 46 47 @Override onCreateDialog(Bundle savedInstanceState)48 public Dialog onCreateDialog(Bundle savedInstanceState) { 49 final String summary = getResources() 50 .getString(R.string.notification_assistant_security_warning_summary); 51 return new AlertDialog.Builder(getContext()) 52 .setMessage(summary) 53 .setCancelable(true) 54 .setPositiveButton(R.string.okay, this) 55 .create(); 56 } 57 58 @Override getMetricsCategory()59 public int getMetricsCategory() { 60 return SettingsEnums.DEFAULT_NOTIFICATION_ASSISTANT; 61 } 62 63 @Override onClick(DialogInterface dialog, int which)64 public void onClick(DialogInterface dialog, int which) { 65 final Bundle args = getArguments(); 66 final ComponentName cn = ComponentName.unflattenFromString(args 67 .getString(KEY_COMPONENT)); 68 ConfigureNotificationSettings parent = (ConfigureNotificationSettings) getTargetFragment(); 69 parent.enableNAS(cn); 70 } 71 } 72