• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.development;
18 
19 import android.content.Context;
20 import android.os.Build;
21 import android.provider.Settings;
22 import android.support.annotation.VisibleForTesting;
23 import android.support.v14.preference.SwitchPreference;
24 import android.support.v7.preference.Preference;
25 
26 import com.android.settings.core.PreferenceControllerMixin;
27 import com.android.settingslib.development.DeveloperOptionsPreferenceController;
28 
29 public class NotificationChannelWarningsPreferenceController extends
30         DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
31         PreferenceControllerMixin {
32 
33     private static final String SHOW_NOTIFICATION_CHANNEL_WARNINGS_KEY =
34             "show_notification_channel_warnings";
35 
36     @VisibleForTesting
37     final static int SETTING_VALUE_ON = 1;
38     @VisibleForTesting
39     final static int SETTING_VALUE_OFF = 0;
40     @VisibleForTesting
41     final static int DEBUGGING_ENABLED = 1;
42     @VisibleForTesting
43     final static int DEBUGGING_DISABLED = 0;
44 
NotificationChannelWarningsPreferenceController(Context context)45     public NotificationChannelWarningsPreferenceController(Context context) {
46         super(context);
47     }
48 
49 
50     @Override
getPreferenceKey()51     public String getPreferenceKey() {
52         return SHOW_NOTIFICATION_CHANNEL_WARNINGS_KEY;
53     }
54 
55     @Override
onPreferenceChange(Preference preference, Object newValue)56     public boolean onPreferenceChange(Preference preference, Object newValue) {
57         final boolean isEnabled = (Boolean) newValue;
58         Settings.Global.putInt(mContext.getContentResolver(),
59                 Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS,
60                 isEnabled ? SETTING_VALUE_ON : SETTING_VALUE_OFF);
61         return true;
62     }
63 
64     @Override
updateState(Preference preference)65     public void updateState(Preference preference) {
66         final int defaultWarningEnabled = isDebuggable() ? DEBUGGING_ENABLED : DEBUGGING_DISABLED;
67         final int mode = Settings.Global.getInt(mContext.getContentResolver(),
68                 Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS, defaultWarningEnabled);
69         ((SwitchPreference) mPreference).setChecked(mode != SETTING_VALUE_OFF);
70     }
71 
72     @Override
onDeveloperOptionsSwitchDisabled()73     protected void onDeveloperOptionsSwitchDisabled() {
74         super.onDeveloperOptionsSwitchDisabled();
75         Settings.Global.putInt(mContext.getContentResolver(),
76                 Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS, SETTING_VALUE_OFF);
77         ((SwitchPreference) mPreference).setChecked(false);
78     }
79 
80     @VisibleForTesting
isDebuggable()81     boolean isDebuggable() {
82         return Build.IS_DEBUGGABLE;
83     }
84 }
85