1 /* 2 * Copyright (C) 2020 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.network; 18 19 import android.content.Context; 20 import android.net.wifi.WifiManager; 21 import android.provider.Settings; 22 23 import androidx.preference.PreferenceScreen; 24 25 import com.android.settings.R; 26 import com.android.settings.widget.SettingsMainSwitchPreferenceController; 27 28 /** 29 * {@link SettingsMainSwitchPreferenceController} 30 * that controls whether Adaptive connectivity option is enabled. 31 */ 32 public class AdaptiveConnectivityTogglePreferenceController extends 33 SettingsMainSwitchPreferenceController { 34 35 private final WifiManager mWifiManager; 36 AdaptiveConnectivityTogglePreferenceController(Context context, String preferenceKey)37 public AdaptiveConnectivityTogglePreferenceController(Context context, String preferenceKey) { 38 super(context, preferenceKey); 39 mWifiManager = context.getSystemService(WifiManager.class); 40 } 41 42 @Override displayPreference(PreferenceScreen screen)43 public void displayPreference(PreferenceScreen screen) { 44 super.displayPreference(screen); 45 } 46 47 @Override getAvailabilityStatus()48 public int getAvailabilityStatus() { 49 return AVAILABLE; 50 } 51 52 @Override isChecked()53 public boolean isChecked() { 54 return Settings.Secure.getInt(mContext.getContentResolver(), 55 Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 1) == 1; 56 } 57 58 @Override setChecked(boolean isChecked)59 public boolean setChecked(boolean isChecked) { 60 Settings.Secure.putInt(mContext.getContentResolver(), 61 Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 62 isChecked ? 1 : 0); 63 mWifiManager.setWifiScoringEnabled(isChecked); 64 return true; 65 } 66 67 @Override getSliceHighlightMenuRes()68 public int getSliceHighlightMenuRes() { 69 return R.string.menu_key_network; 70 } 71 } 72