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