• 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.tv.settings.connectivity.setup;
18 
19 import android.arch.lifecycle.ViewModel;
20 import android.net.wifi.ScanResult;
21 import android.net.wifi.WifiConfiguration;
22 import android.support.annotation.IntDef;
23 import android.text.TextUtils;
24 
25 import java.lang.annotation.Retention;
26 import java.lang.annotation.RetentionPolicy;
27 import java.util.HashMap;
28 
29 /**
30  * Class that stores the user choice information for basic Wi-Fi flow.
31  */
32 public class UserChoiceInfo extends ViewModel {
33     public static final int SELECT_WIFI = 1;
34     public static final int PASSWORD = 2;
35     public static final int SECURITY = 3;
36     public static final int SSID = 4;
37 
38     @IntDef({
39             SELECT_WIFI,
40             PASSWORD,
41             SECURITY,
42             SSID
43     })
44     @Retention(RetentionPolicy.SOURCE)
45     public @interface PAGE {
46     }
47 
48     private HashMap<Integer, CharSequence> mDataSummary = new HashMap<>();
49 
50     private WifiConfiguration mWifiConfiguration = new WifiConfiguration();
51     private int mWifiSecurity;
52     private ScanResult mChosenNetwork;
53     private String mConnectedNetwork;
54     private boolean mIsPasswordHidden = false;
55 
56     /**
57      * Store the page summary into a HashMap.
58      *
59      * @param page The page as the key.
60      * @param info The info as the value.
61      */
put(@AGE int page, String info)62     public void put(@PAGE int page, String info) {
63         mDataSummary.put(page, info);
64     }
65 
66     /**
67      * Check if the summary of the queried page matches with expected string.
68      *
69      * @param choice The expected string.
70      * @param page   The page queried.
71      * @return true if matched.
72      */
choiceChosen(CharSequence choice, @PAGE int page)73     public boolean choiceChosen(CharSequence choice, @PAGE int page) {
74         if (!mDataSummary.containsKey(page)) {
75             return false;
76         }
77         return TextUtils.equals(choice, mDataSummary.get(page));
78     }
79 
80     /**
81      * Get summary of a page.
82      *
83      * @param page The queried page.
84      * @return The summary of the page.
85      */
getPageSummary(@AGE int page)86     public CharSequence getPageSummary(@PAGE int page) {
87         if (!mDataSummary.containsKey(page)) {
88             return null;
89         }
90         return mDataSummary.get(page);
91     }
92 
93     /**
94      * Remove the summary of a page.
95      *
96      * @param page The page.
97      */
removePageSummary(@AGE int page)98     public void removePageSummary(@PAGE int page) {
99         mDataSummary.remove(page);
100     }
101 
102     /**
103      * Get {@link ScanResult} of the chosen network.
104      */
getChosenNetwork()105     public ScanResult getChosenNetwork() {
106         return mChosenNetwork;
107     }
108 
109     /**
110      * Set {@link ScanResult} of the chosen network.
111      */
setChosenNetwork(ScanResult result)112     public void setChosenNetwork(ScanResult result) {
113         mChosenNetwork = result;
114     }
115 
116     /**
117      * Get {@link WifiConfiguration}
118      */
getWifiConfiguration()119     public WifiConfiguration getWifiConfiguration() {
120         return mWifiConfiguration;
121     }
122 
123     /**
124      * Set {@link WifiConfiguration}
125      */
setWifiConfiguration(WifiConfiguration wifiConfiguration)126     public void setWifiConfiguration(WifiConfiguration wifiConfiguration) {
127         this.mWifiConfiguration = wifiConfiguration;
128     }
129 
130     /**
131      * Get WifiSecurity category. The category value is defined in
132      * {@link com.android.settingslib.wifi.AccessPoint}
133      */
getWifiSecurity()134     public int getWifiSecurity() {
135         return mWifiSecurity;
136     }
137 
138     /**
139      * Set WifiSecurity
140      *
141      * @param wifiSecurity WifiSecurity category defined in
142      *                     {@link com.android.settingslib.wifi.AccessPoint}.
143      */
setWifiSecurity(int wifiSecurity)144     public void setWifiSecurity(int wifiSecurity) {
145         this.mWifiSecurity = wifiSecurity;
146     }
147 
148     /**
149      * Get the SSID of the connected network.
150      *
151      * @return the SSID.
152      */
getConnectedNetwork()153     public String getConnectedNetwork() {
154         return mConnectedNetwork;
155     }
156 
157     /**
158      * Set the SSID of the connected network.
159      *
160      * @param connectedNetwork SSID of the network.
161      */
setConnectedNetwork(String connectedNetwork)162     public void setConnectedNetwork(String connectedNetwork) {
163         mConnectedNetwork = connectedNetwork;
164     }
165 
166     /**
167      * Determine whether the password is hidden.
168      *
169      * @return True if hidden.
170      */
isPasswordHidden()171     public boolean isPasswordHidden() {
172         return this.mIsPasswordHidden;
173     }
174 
175     /**
176      * Set whether the password is hidden.
177      *
178      * @param hidden true if hidden.
179      */
setPasswordHidden(boolean hidden)180     public void setPasswordHidden(boolean hidden) {
181         this.mIsPasswordHidden = hidden;
182     }
183 
184     /**
185      * Initialize all the information.
186      */
init()187     public void init() {
188         mDataSummary = new HashMap<>();
189         mWifiConfiguration = new WifiConfiguration();
190         mWifiSecurity = 0;
191         mChosenNetwork = null;
192         mChosenNetwork = null;
193         mIsPasswordHidden = false;
194     }
195 }
196