1 /* 2 * Copyright (C) 2014 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.os.Bundle; 22 import android.text.TextUtils; 23 import android.util.Log; 24 25 import androidx.preference.Preference; 26 import androidx.preference.PreferenceGroup; 27 import androidx.preference.PreferenceScreen; 28 29 import com.android.internal.widget.LockPatternUtils; 30 import com.android.settings.R; 31 import com.android.settingslib.core.AbstractPreferenceController; 32 33 import java.util.ArrayList; 34 import java.util.List; 35 36 /** These settings are per app, so should not be returned in global search results. */ 37 public class AppNotificationSettings extends NotificationSettings { 38 private static final String TAG = "AppNotificationSettings"; 39 private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); 40 41 private static String KEY_ADVANCED_CATEGORY = "app_advanced"; 42 private static String KEY_BADGE = "badge"; 43 private static String KEY_APP_LINK = "app_link"; 44 private static String[] LEGACY_NON_ADVANCED_KEYS = {KEY_BADGE, KEY_APP_LINK}; 45 46 @Override getMetricsCategory()47 public int getMetricsCategory() { 48 return SettingsEnums.NOTIFICATION_APP_NOTIFICATION; 49 } 50 51 @Override onCreate(Bundle savedInstanceState)52 public void onCreate(Bundle savedInstanceState) { 53 super.onCreate(savedInstanceState); 54 final PreferenceScreen screen = getPreferenceScreen(); 55 if (mShowLegacyChannelConfig && screen != null) { 56 // if showing legacy settings, pull advanced settings out of the advanced category 57 PreferenceGroup advanced = (PreferenceGroup) findPreference(KEY_ADVANCED_CATEGORY); 58 removePreference(KEY_ADVANCED_CATEGORY); 59 if (advanced != null) { 60 for (String key : LEGACY_NON_ADVANCED_KEYS) { 61 Preference pref = advanced.findPreference(key); 62 advanced.removePreference(pref); 63 if (pref != null) { 64 screen.addPreference(pref); 65 } 66 } 67 } 68 } 69 } 70 71 @Override onResume()72 public void onResume() { 73 super.onResume(); 74 75 if (mUid < 0 || TextUtils.isEmpty(mPkg) || mPkgInfo == null) { 76 Log.w(TAG, "Missing package or uid or packageinfo"); 77 finish(); 78 return; 79 } 80 81 for (NotificationPreferenceController controller : mControllers) { 82 controller.onResume(mAppRow, mChannel, mChannelGroup, null, null, mSuspendedAppsAdmin); 83 controller.displayPreference(getPreferenceScreen()); 84 } 85 updatePreferenceStates(); 86 } 87 88 @Override getLogTag()89 protected String getLogTag() { 90 return TAG; 91 } 92 93 @Override getPreferenceScreenResId()94 protected int getPreferenceScreenResId() { 95 return R.xml.app_notification_settings; 96 } 97 98 @Override createPreferenceControllers(Context context)99 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 100 mControllers = new ArrayList<>(); 101 mControllers.add(new HeaderPreferenceController(context, this)); 102 mControllers.add(new BlockPreferenceController(context, mDependentFieldListener, mBackend)); 103 mControllers.add(new BadgePreferenceController(context, mBackend)); 104 mControllers.add(new AllowSoundPreferenceController( 105 context, mDependentFieldListener, mBackend)); 106 mControllers.add(new ImportancePreferenceController( 107 context, mDependentFieldListener, mBackend)); 108 mControllers.add(new MinImportancePreferenceController( 109 context, mDependentFieldListener, mBackend)); 110 mControllers.add(new HighImportancePreferenceController( 111 context, mDependentFieldListener, mBackend)); 112 mControllers.add(new SoundPreferenceController(context, this, 113 mDependentFieldListener, mBackend)); 114 mControllers.add(new LightsPreferenceController(context, mBackend)); 115 mControllers.add(new VibrationPreferenceController(context, mBackend)); 116 mControllers.add(new VisibilityPreferenceController(context, new LockPatternUtils(context), 117 mBackend)); 118 mControllers.add(new DndPreferenceController(context, mBackend)); 119 mControllers.add(new AppLinkPreferenceController(context)); 120 mControllers.add(new DescriptionPreferenceController(context)); 121 mControllers.add(new NotificationsOffPreferenceController(context)); 122 mControllers.add(new DeletedChannelsPreferenceController(context, mBackend)); 123 mControllers.add(new ChannelListPreferenceController(context, mBackend)); 124 mControllers.add(new AppConversationListPreferenceController(context, mBackend)); 125 mControllers.add(new InvalidConversationInfoPreferenceController(context, mBackend)); 126 mControllers.add(new InvalidConversationPreferenceController(context, mBackend)); 127 mControllers.add(new BubbleSummaryPreferenceController(context, mBackend)); 128 return new ArrayList<>(mControllers); 129 } 130 } 131