• 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.wifi;
18 
19 import android.content.Context;
20 import android.provider.Settings;
21 
22 import com.android.settings.core.TogglePreferenceController;
23 
24 /**
25  * CellularFallbackPreferenceController controls whether we should fall back to celluar when
26  * wifi is bad.
27  */
28 public class CellularFallbackPreferenceController extends TogglePreferenceController {
29 
CellularFallbackPreferenceController(Context context, String key)30     public CellularFallbackPreferenceController(Context context, String key) {
31         super(context, key);
32     }
33 
34     @Override
getAvailabilityStatus()35     public int getAvailabilityStatus() {
36         return !avoidBadWifiConfig() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
37     }
38 
39     @Override
isChecked()40     public boolean isChecked() {
41         return avoidBadWifiCurrentSettings();
42     }
43 
44     @Override
setChecked(boolean isChecked)45     public boolean setChecked(boolean isChecked) {
46         // On: avoid bad wifi. Off: prompt.
47         return Settings.Global.putString(mContext.getContentResolver(),
48                 Settings.Global.NETWORK_AVOID_BAD_WIFI, isChecked ? "1" : null);
49     }
50 
avoidBadWifiConfig()51     private boolean avoidBadWifiConfig() {
52         return mContext.getResources().getInteger(
53                 com.android.internal.R.integer.config_networkAvoidBadWifi) == 1;
54     }
55 
avoidBadWifiCurrentSettings()56     private boolean avoidBadWifiCurrentSettings() {
57         return "1".equals(Settings.Global.getString(mContext.getContentResolver(),
58                 Settings.Global.NETWORK_AVOID_BAD_WIFI));
59     }
60 }