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