• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.wifi.details2;
18 
19 import android.content.Context;
20 
21 import com.android.settings.core.TogglePreferenceController;
22 import com.android.wifitrackerlib.WifiEntry;
23 
24 /**
25  * {@link TogglePreferenceController} that controls whether the Wi-Fi Auto-connect feature should be
26  * enabled.
27  */
28 public class WifiAutoConnectPreferenceController2 extends TogglePreferenceController {
29 
30     private static final String KEY_AUTO_CONNECT = "auto_connect";
31 
32     private WifiEntry mWifiEntry;
33 
WifiAutoConnectPreferenceController2(Context context)34     public WifiAutoConnectPreferenceController2(Context context) {
35         super(context, KEY_AUTO_CONNECT);
36     }
37 
setWifiEntry(WifiEntry wifiEntry)38     public void setWifiEntry(WifiEntry wifiEntry) {
39         mWifiEntry = wifiEntry;
40     }
41 
42     @Override
getAvailabilityStatus()43     public int getAvailabilityStatus() {
44         return mWifiEntry.canSetAutoJoinEnabled() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
45     }
46 
47     @Override
isChecked()48     public boolean isChecked() {
49         return mWifiEntry.isAutoJoinEnabled();
50     }
51 
52     @Override
setChecked(boolean isChecked)53     public boolean setChecked(boolean isChecked) {
54         mWifiEntry.setAutoJoinEnabled(isChecked);
55         return true;
56     }
57 }
58