1 /* 2 * Copyright (C) 2018 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.NotificationManager.Policy; 20 import android.app.settings.SettingsEnums; 21 import android.content.Context; 22 import android.provider.Settings; 23 import android.util.Log; 24 25 import androidx.preference.Preference; 26 import androidx.preference.SwitchPreference; 27 28 import com.android.settingslib.core.lifecycle.Lifecycle; 29 30 public class ZenModeSystemPreferenceController extends 31 AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener { 32 33 protected static final String KEY = "zen_mode_system"; 34 ZenModeSystemPreferenceController(Context context, Lifecycle lifecycle)35 public ZenModeSystemPreferenceController(Context context, Lifecycle lifecycle) { 36 super(context, KEY, lifecycle); 37 } 38 39 @Override getPreferenceKey()40 public String getPreferenceKey() { 41 return KEY; 42 } 43 44 @Override isAvailable()45 public boolean isAvailable() { 46 return true; 47 } 48 49 @Override updateState(Preference preference)50 public void updateState(Preference preference) { 51 super.updateState(preference); 52 53 SwitchPreference pref = (SwitchPreference) preference; 54 switch (getZenMode()) { 55 case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS: 56 pref.setEnabled(false); 57 pref.setChecked(false); 58 break; 59 case Settings.Global.ZEN_MODE_ALARMS: 60 pref.setEnabled(false); 61 pref.setChecked(false); 62 break; 63 default: 64 pref.setEnabled(true); 65 pref.setChecked(mBackend.isPriorityCategoryEnabled( 66 Policy.PRIORITY_CATEGORY_SYSTEM)); 67 } 68 } 69 70 @Override onPreferenceChange(Preference preference, Object newValue)71 public boolean onPreferenceChange(Preference preference, Object newValue) { 72 final boolean allowSystem = (Boolean) newValue; 73 if (ZenModeSettingsBase.DEBUG) { 74 Log.d(TAG, "onPrefChange allowSystem=" + allowSystem); 75 } 76 77 mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_ZEN_ALLOW_SYSTEM, 78 allowSystem); 79 mBackend.saveSoundPolicy(Policy.PRIORITY_CATEGORY_SYSTEM, allowSystem); 80 return true; 81 } 82 } 83