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