1 /* 2 * Copyright (C) 2020 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.app; 18 19 import android.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.text.TextUtils; 22 import android.util.Log; 23 24 import com.android.settings.R; 25 import com.android.settings.notification.NotificationBackend; 26 import com.android.settingslib.core.AbstractPreferenceController; 27 28 import java.util.ArrayList; 29 import java.util.List; 30 31 /** 32 * Per-app Settings page that shows a list of notification channels that a user can toggle for 33 * the channel to bypass DND. 34 * 35 * This can be found at: 36 * Settings > Sound > Do Not Disturb > Apps > (Choose app) 37 */ 38 public class AppChannelsBypassingDndSettings extends NotificationSettings { 39 private static final String TAG = "AppChannelsBypassingDndSettings"; 40 41 @Override getMetricsCategory()42 public int getMetricsCategory() { 43 return SettingsEnums.DND_APPS_BYPASSING; 44 } 45 46 @Override onResume()47 public void onResume() { 48 super.onResume(); 49 if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) { 50 Log.w(TAG, "Missing package or uid or packageinfo"); 51 finish(); 52 return; 53 } 54 55 for (NotificationPreferenceController controller : mControllers) { 56 controller.onResume(mAppRow, null, null, null, null, mSuspendedAppsAdmin, null); 57 controller.displayPreference(getPreferenceScreen()); 58 } 59 updatePreferenceStates(); 60 } 61 62 @Override getLogTag()63 protected String getLogTag() { 64 return TAG; 65 } 66 67 @Override getPreferenceScreenResId()68 protected int getPreferenceScreenResId() { 69 return R.xml.app_channels_bypassing_dnd_settings; 70 } 71 72 @Override createPreferenceControllers(Context context)73 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 74 mControllers = new ArrayList<>(); 75 mControllers.add(new HeaderPreferenceController(context, this)); 76 mControllers.add(new AppChannelsBypassingDndPreferenceController(context, 77 new NotificationBackend())); 78 return new ArrayList<>(mControllers); 79 } 80 } 81