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