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.widget.SettingsMainSwitchPreferenceController; 26 27 /** 28 * {@link SettingsMainSwitchPreferenceController} 29 * that controls whether Adaptive connectivity option is enabled. 30 */ 31 public class AdaptiveConnectivityTogglePreferenceController extends 32 SettingsMainSwitchPreferenceController { 33 34 private final WifiManager mWifiManager; 35 AdaptiveConnectivityTogglePreferenceController(Context context, String preferenceKey)36 public AdaptiveConnectivityTogglePreferenceController(Context context, String preferenceKey) { 37 super(context, preferenceKey); 38 mWifiManager = context.getSystemService(WifiManager.class); 39 } 40 41 @Override displayPreference(PreferenceScreen screen)42 public void displayPreference(PreferenceScreen screen) { 43 super.displayPreference(screen); 44 } 45 46 @Override getAvailabilityStatus()47 public int getAvailabilityStatus() { 48 return AVAILABLE; 49 } 50 51 @Override isChecked()52 public boolean isChecked() { 53 return Settings.Secure.getInt(mContext.getContentResolver(), 54 Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 1) == 1; 55 } 56 57 @Override setChecked(boolean isChecked)58 public boolean setChecked(boolean isChecked) { 59 Settings.Secure.putInt(mContext.getContentResolver(), 60 Settings.Secure.ADAPTIVE_CONNECTIVITY_ENABLED, 61 isChecked ? 1 : 0); 62 mWifiManager.setWifiScoringEnabled(isChecked); 63 return true; 64 } 65 } 66