Fan Zhang | eb83a0d | 2016-09-21 11:34:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | package com.android.settingslib.wifi; |
| 17 | |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 18 | import static com.google.common.truth.Truth.assertThat; |
| 19 | import static com.google.common.truth.Truth.assertWithMessage; |
Sundeep Ghuman | 71f4a82 | 2017-04-18 19:51:46 -0700 | [diff] [blame] | 20 | |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 21 | import static org.mockito.Mockito.any; |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 22 | import static org.mockito.Mockito.anyInt; |
Sundeep Ghuman | f4d3302 | 2017-06-05 19:47:36 -0700 | [diff] [blame] | 23 | import static org.mockito.Mockito.mock; |
| 24 | import static org.mockito.Mockito.verify; |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 25 | import static org.mockito.Mockito.when; |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 26 | |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 27 | import android.content.Context; |
| 28 | import android.net.ConnectivityManager; |
| 29 | import android.net.NetworkInfo; |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 30 | import android.net.NetworkKey; |
| 31 | import android.net.RssiCurve; |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 32 | import android.net.ScoredNetwork; |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 33 | import android.net.WifiKey; |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 34 | import android.net.wifi.ScanResult; |
| 35 | import android.net.wifi.WifiConfiguration; |
| 36 | import android.net.wifi.WifiInfo; |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 37 | import android.net.wifi.WifiNetworkScoreCache; |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 38 | import android.net.wifi.WifiSsid; |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 39 | import android.net.wifi.hotspot2.PasspointConfiguration; |
| 40 | import android.net.wifi.hotspot2.pps.HomeSp; |
Fan Zhang | eb83a0d | 2016-09-21 11:34:08 -0700 | [diff] [blame] | 41 | import android.os.Bundle; |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 42 | import android.os.SystemClock; |
Fan Zhang | eb83a0d | 2016-09-21 11:34:08 -0700 | [diff] [blame] | 43 | import android.support.test.InstrumentationRegistry; |
| 44 | import android.support.test.filters.SmallTest; |
| 45 | import android.support.test.runner.AndroidJUnit4; |
| 46 | import android.text.SpannableString; |
| 47 | import android.text.style.TtsSpan; |
Sundeep Ghuman | 71f4a82 | 2017-04-18 19:51:46 -0700 | [diff] [blame] | 48 | |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 49 | import com.android.settingslib.R; |
| 50 | |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 51 | import org.junit.Before; |
Fan Zhang | eb83a0d | 2016-09-21 11:34:08 -0700 | [diff] [blame] | 52 | import org.junit.Test; |
| 53 | import org.junit.runner.RunWith; |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 54 | import org.mockito.Mock; |
| 55 | import org.mockito.MockitoAnnotations; |
Fan Zhang | eb83a0d | 2016-09-21 11:34:08 -0700 | [diff] [blame] | 56 | |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 57 | import java.util.ArrayList; |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 58 | import java.util.Collections; |
Fan Zhang | eb83a0d | 2016-09-21 11:34:08 -0700 | [diff] [blame] | 59 | |
| 60 | @SmallTest |
| 61 | @RunWith(AndroidJUnit4.class) |
| 62 | public class AccessPointTest { |
| 63 | |
| 64 | private static final String TEST_SSID = "test_ssid"; |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 65 | private Context mContext; |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 66 | @Mock private RssiCurve mockBadgeCurve; |
| 67 | @Mock private WifiNetworkScoreCache mockWifiNetworkScoreCache; |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 68 | |
| 69 | @Before |
| 70 | public void setUp() { |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 71 | MockitoAnnotations.initMocks(this); |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 72 | mContext = InstrumentationRegistry.getTargetContext(); |
| 73 | } |
Fan Zhang | eb83a0d | 2016-09-21 11:34:08 -0700 | [diff] [blame] | 74 | |
| 75 | @Test |
| 76 | public void testSsidIsTelephoneSpan() { |
| 77 | final Bundle bundle = new Bundle(); |
| 78 | bundle.putString("key_ssid", TEST_SSID); |
| 79 | final AccessPoint ap = new AccessPoint(InstrumentationRegistry.getTargetContext(), bundle); |
| 80 | final CharSequence ssid = ap.getSsid(); |
| 81 | |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 82 | assertThat(ssid instanceof SpannableString).isTrue(); |
Fan Zhang | eb83a0d | 2016-09-21 11:34:08 -0700 | [diff] [blame] | 83 | |
| 84 | TtsSpan[] spans = ((SpannableString) ssid).getSpans(0, TEST_SSID.length(), TtsSpan.class); |
| 85 | |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 86 | assertThat(spans.length).isEqualTo(1); |
| 87 | assertThat(spans[0].getType()).isEqualTo(TtsSpan.TYPE_TELEPHONE); |
Fan Zhang | eb83a0d | 2016-09-21 11:34:08 -0700 | [diff] [blame] | 88 | } |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 89 | |
| 90 | @Test |
| 91 | public void testCopyAccessPoint_dataShouldMatch() { |
| 92 | WifiConfiguration configuration = createWifiConfiguration(); |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 93 | configuration.meteredHint = true; |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 94 | |
| 95 | NetworkInfo networkInfo = |
| 96 | new NetworkInfo(ConnectivityManager.TYPE_WIFI, 2, "WIFI", "WIFI_SUBTYPE"); |
| 97 | AccessPoint originalAccessPoint = new AccessPoint(mContext, configuration); |
| 98 | WifiInfo wifiInfo = new WifiInfo(); |
| 99 | wifiInfo.setSSID(WifiSsid.createFromAsciiEncoded(configuration.SSID)); |
| 100 | wifiInfo.setBSSID(configuration.BSSID); |
| 101 | originalAccessPoint.update(configuration, wifiInfo, networkInfo); |
| 102 | AccessPoint copy = new AccessPoint(mContext, originalAccessPoint); |
| 103 | |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 104 | assertThat(originalAccessPoint.getSsid().toString()).isEqualTo(copy.getSsid().toString()); |
| 105 | assertThat(originalAccessPoint.getBssid()).isEqualTo(copy.getBssid()); |
| 106 | assertThat(originalAccessPoint.getConfig()).isEqualTo(copy.getConfig()); |
| 107 | assertThat(originalAccessPoint.getSecurity()).isEqualTo(copy.getSecurity()); |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 108 | assertThat(originalAccessPoint.isMetered()).isEqualTo(copy.isMetered()); |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 109 | assertThat(originalAccessPoint.compareTo(copy) == 0).isTrue(); |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Test |
| 113 | public void testThatCopyAccessPoint_scanCacheShouldMatch() { |
Sundeep Ghuman | 54bdcfa | 2017-03-08 19:52:05 -0800 | [diff] [blame] | 114 | AccessPoint original = createAccessPointWithScanResultCache(); |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 115 | assertThat(original.getRssi()).isEqualTo(4); |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 116 | AccessPoint copy = new AccessPoint(mContext, createWifiConfiguration()); |
Sundeep Ghuman | 54bdcfa | 2017-03-08 19:52:05 -0800 | [diff] [blame] | 117 | assertThat(copy.getRssi()).isEqualTo(AccessPoint.UNREACHABLE_RSSI); |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 118 | copy.copyFrom(original); |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 119 | assertThat(original.getRssi()).isEqualTo(copy.getRssi()); |
| 120 | } |
| 121 | |
| 122 | @Test |
| 123 | public void testCompareTo_GivesActiveBeforeInactive() { |
| 124 | AccessPoint activeAp = new TestAccessPointBuilder(mContext).setActive(true).build(); |
| 125 | AccessPoint inactiveAp = new TestAccessPointBuilder(mContext).setActive(false).build(); |
| 126 | |
| 127 | assertSortingWorks(activeAp, inactiveAp); |
| 128 | } |
| 129 | |
| 130 | @Test |
| 131 | public void testCompareTo_GivesReachableBeforeUnreachable() { |
| 132 | AccessPoint nearAp = new TestAccessPointBuilder(mContext).setReachable(true).build(); |
| 133 | AccessPoint farAp = new TestAccessPointBuilder(mContext).setReachable(false).build(); |
| 134 | |
| 135 | assertSortingWorks(nearAp, farAp); |
| 136 | } |
| 137 | |
| 138 | @Test |
| 139 | public void testCompareTo_GivesSavedBeforeUnsaved() { |
| 140 | AccessPoint savedAp = new TestAccessPointBuilder(mContext).setSaved(true).build(); |
| 141 | AccessPoint notSavedAp = new TestAccessPointBuilder(mContext).setSaved(false).build(); |
| 142 | |
| 143 | assertSortingWorks(savedAp, notSavedAp); |
| 144 | } |
| 145 | |
| 146 | //TODO: add tests for mRankingScore sort order if ranking is exposed |
| 147 | |
| 148 | @Test |
| 149 | public void testCompareTo_GivesHighLevelBeforeLowLevel() { |
| 150 | final int highLevel = AccessPoint.SIGNAL_LEVELS - 1; |
| 151 | final int lowLevel = 1; |
| 152 | assertThat(highLevel).isGreaterThan(lowLevel); |
| 153 | |
| 154 | AccessPoint strongAp = new TestAccessPointBuilder(mContext).setLevel(highLevel).build(); |
| 155 | AccessPoint weakAp = new TestAccessPointBuilder(mContext).setLevel(lowLevel).build(); |
| 156 | |
| 157 | assertSortingWorks(strongAp, weakAp); |
| 158 | } |
| 159 | |
| 160 | @Test |
| 161 | public void testCompareTo_GivesSsidAlphabetically() { |
| 162 | |
| 163 | final String firstName = "AAAAAA"; |
| 164 | final String secondName = "zzzzzz"; |
| 165 | |
| 166 | AccessPoint firstAp = new TestAccessPointBuilder(mContext).setSsid(firstName).build(); |
| 167 | AccessPoint secondAp = new TestAccessPointBuilder(mContext).setSsid(secondName).build(); |
| 168 | |
| 169 | assertThat(firstAp.getSsidStr().compareToIgnoreCase(secondAp.getSsidStr()) < 0).isTrue(); |
| 170 | assertSortingWorks(firstAp, secondAp); |
| 171 | } |
| 172 | |
| 173 | @Test |
Sundeep Ghuman | d44b8e4 | 2017-06-21 21:40:06 -0700 | [diff] [blame] | 174 | public void testCompareTo_GivesSsidCasePrecendenceAfterAlphabetical() { |
| 175 | |
| 176 | final String firstName = "aaAaaa"; |
| 177 | final String secondName = "aaaaaa"; |
| 178 | final String thirdName = "BBBBBB"; |
| 179 | |
| 180 | AccessPoint firstAp = new TestAccessPointBuilder(mContext).setSsid(firstName).build(); |
| 181 | AccessPoint secondAp = new TestAccessPointBuilder(mContext).setSsid(secondName).build(); |
| 182 | AccessPoint thirdAp = new TestAccessPointBuilder(mContext).setSsid(thirdName).build(); |
| 183 | |
| 184 | assertSortingWorks(firstAp, secondAp); |
| 185 | assertSortingWorks(secondAp, thirdAp); |
| 186 | } |
| 187 | |
| 188 | @Test |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 189 | public void testCompareTo_AllSortingRulesCombined() { |
| 190 | |
| 191 | AccessPoint active = new TestAccessPointBuilder(mContext).setActive(true).build(); |
| 192 | AccessPoint reachableAndMinLevel = new TestAccessPointBuilder(mContext) |
| 193 | .setReachable(true).build(); |
| 194 | AccessPoint saved = new TestAccessPointBuilder(mContext).setSaved(true).build(); |
| 195 | AccessPoint highLevelAndReachable = new TestAccessPointBuilder(mContext) |
| 196 | .setLevel(AccessPoint.SIGNAL_LEVELS - 1).build(); |
| 197 | AccessPoint firstName = new TestAccessPointBuilder(mContext).setSsid("a").build(); |
| 198 | AccessPoint lastname = new TestAccessPointBuilder(mContext).setSsid("z").build(); |
| 199 | |
| 200 | ArrayList<AccessPoint> points = new ArrayList<AccessPoint>(); |
| 201 | points.add(lastname); |
| 202 | points.add(firstName); |
| 203 | points.add(highLevelAndReachable); |
| 204 | points.add(saved); |
| 205 | points.add(reachableAndMinLevel); |
| 206 | points.add(active); |
| 207 | |
| 208 | Collections.sort(points); |
| 209 | assertThat(points.indexOf(active)).isLessThan(points.indexOf(reachableAndMinLevel)); |
| 210 | assertThat(points.indexOf(reachableAndMinLevel)).isLessThan(points.indexOf(saved)); |
| 211 | // note: the saved AP will not appear before highLevelAndReachable, |
| 212 | // because all APs with a signal level are reachable, |
| 213 | // and isReachable() takes higher sorting precedence than isSaved(). |
| 214 | assertThat(points.indexOf(saved)).isLessThan(points.indexOf(firstName)); |
| 215 | assertThat(points.indexOf(highLevelAndReachable)).isLessThan(points.indexOf(firstName)); |
| 216 | assertThat(points.indexOf(firstName)).isLessThan(points.indexOf(lastname)); |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Sundeep Ghuman | 54bdcfa | 2017-03-08 19:52:05 -0800 | [diff] [blame] | 219 | @Test |
| 220 | public void testRssiIsSetFromScanResults() { |
| 221 | AccessPoint ap = createAccessPointWithScanResultCache(); |
| 222 | int originalRssi = ap.getRssi(); |
| 223 | assertThat(originalRssi).isNotEqualTo(AccessPoint.UNREACHABLE_RSSI); |
| 224 | } |
| 225 | |
| 226 | @Test |
| 227 | public void testGetRssiShouldReturnSetRssiValue() { |
| 228 | AccessPoint ap = createAccessPointWithScanResultCache(); |
| 229 | int originalRssi = ap.getRssi(); |
| 230 | int newRssi = originalRssi - 10; |
| 231 | ap.setRssi(newRssi); |
| 232 | assertThat(ap.getRssi()).isEqualTo(newRssi); |
| 233 | } |
| 234 | |
Sundeep Ghuman | ce78a5f | 2017-03-15 19:06:14 -0700 | [diff] [blame] | 235 | @Test |
| 236 | public void testUpdateWithScanResultShouldAverageRssi() { |
| 237 | String ssid = "ssid"; |
| 238 | int originalRssi = -65; |
| 239 | int newRssi = -80; |
| 240 | int expectedRssi = (originalRssi + newRssi) / 2; |
| 241 | AccessPoint ap = |
| 242 | new TestAccessPointBuilder(mContext).setSsid(ssid).setRssi(originalRssi).build(); |
| 243 | |
| 244 | ScanResult scanResult = new ScanResult(); |
| 245 | scanResult.SSID = ssid; |
| 246 | scanResult.level = newRssi; |
| 247 | scanResult.BSSID = "bssid"; |
| 248 | scanResult.timestamp = SystemClock.elapsedRealtime() * 1000; |
| 249 | scanResult.capabilities = ""; |
| 250 | assertThat(ap.update(scanResult)).isTrue(); |
| 251 | |
| 252 | assertThat(ap.getRssi()).isEqualTo(expectedRssi); |
| 253 | } |
| 254 | |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 255 | @Test |
| 256 | public void testCreateFromPasspointConfig() { |
| 257 | PasspointConfiguration config = new PasspointConfiguration(); |
| 258 | HomeSp homeSp = new HomeSp(); |
| 259 | homeSp.setFqdn("test.com"); |
| 260 | homeSp.setFriendlyName("Test Provider"); |
| 261 | config.setHomeSp(homeSp); |
| 262 | AccessPoint ap = new AccessPoint(mContext, config); |
Stephen Chen | b5bcb8d | 2017-05-19 15:55:02 -0700 | [diff] [blame] | 263 | assertThat(ap.isPasspointConfig()).isTrue(); |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 266 | @Test |
| 267 | public void testIsMetered_returnTrueWhenWifiConfigurationIsMetered() { |
| 268 | WifiConfiguration configuration = createWifiConfiguration(); |
| 269 | configuration.meteredHint = true; |
| 270 | |
| 271 | NetworkInfo networkInfo = |
| 272 | new NetworkInfo(ConnectivityManager.TYPE_WIFI, 2, "WIFI", "WIFI_SUBTYPE"); |
| 273 | AccessPoint accessPoint = new AccessPoint(mContext, configuration); |
| 274 | WifiInfo wifiInfo = new WifiInfo(); |
| 275 | wifiInfo.setSSID(WifiSsid.createFromAsciiEncoded(configuration.SSID)); |
| 276 | wifiInfo.setBSSID(configuration.BSSID); |
| 277 | wifiInfo.setNetworkId(configuration.networkId); |
| 278 | accessPoint.update(configuration, wifiInfo, networkInfo); |
| 279 | |
Stephen Chen | b5bcb8d | 2017-05-19 15:55:02 -0700 | [diff] [blame] | 280 | assertThat(accessPoint.isMetered()).isTrue(); |
| 281 | } |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 282 | |
| 283 | @Test |
| 284 | public void testIsMetered_returnTrueWhenWifiInfoIsMetered() { |
| 285 | WifiConfiguration configuration = createWifiConfiguration(); |
| 286 | |
| 287 | NetworkInfo networkInfo = |
| 288 | new NetworkInfo(ConnectivityManager.TYPE_WIFI, 2, "WIFI", "WIFI_SUBTYPE"); |
| 289 | AccessPoint accessPoint = new AccessPoint(mContext, configuration); |
| 290 | WifiInfo wifiInfo = new WifiInfo(); |
| 291 | wifiInfo.setSSID(WifiSsid.createFromAsciiEncoded(configuration.SSID)); |
| 292 | wifiInfo.setBSSID(configuration.BSSID); |
| 293 | wifiInfo.setNetworkId(configuration.networkId); |
| 294 | wifiInfo.setMeteredHint(true); |
| 295 | accessPoint.update(configuration, wifiInfo, networkInfo); |
| 296 | |
Stephen Chen | b5bcb8d | 2017-05-19 15:55:02 -0700 | [diff] [blame] | 297 | assertThat(accessPoint.isMetered()).isTrue(); |
| 298 | } |
| 299 | |
| 300 | @Test |
| 301 | public void testIsMetered_returnTrueWhenNetworkInfoIsMetered() { |
| 302 | WifiConfiguration configuration = createWifiConfiguration(); |
| 303 | |
| 304 | NetworkInfo networkInfo = |
| 305 | new NetworkInfo(ConnectivityManager.TYPE_WIFI, 2, "WIFI", "WIFI_SUBTYPE"); |
| 306 | networkInfo.setMetered(true); |
| 307 | AccessPoint accessPoint = new AccessPoint(mContext, configuration); |
| 308 | WifiInfo wifiInfo = new WifiInfo(); |
| 309 | wifiInfo.setSSID(WifiSsid.createFromAsciiEncoded(configuration.SSID)); |
| 310 | wifiInfo.setBSSID(configuration.BSSID); |
| 311 | wifiInfo.setNetworkId(configuration.networkId); |
| 312 | accessPoint.update(configuration, wifiInfo, networkInfo); |
| 313 | |
| 314 | assertThat(accessPoint.isMetered()).isTrue(); |
| 315 | } |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 316 | |
| 317 | @Test |
| 318 | public void testIsMetered_returnTrueWhenScoredNetworkIsMetered() { |
| 319 | AccessPoint ap = createAccessPointWithScanResultCache(); |
| 320 | |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 321 | when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 322 | .thenReturn( |
| 323 | new ScoredNetwork( |
| 324 | null /* NetworkKey */, |
| 325 | null /* rssiCurve */, |
| 326 | true /* metered */)); |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 327 | ap.update(mockWifiNetworkScoreCache, false /* scoringUiEnabled */); |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 328 | |
Stephen Chen | b5bcb8d | 2017-05-19 15:55:02 -0700 | [diff] [blame] | 329 | assertThat(ap.isMetered()).isTrue(); |
| 330 | } |
| 331 | |
| 332 | @Test |
| 333 | public void testIsMetered_returnFalseByDefault() { |
| 334 | WifiConfiguration configuration = createWifiConfiguration(); |
| 335 | |
| 336 | NetworkInfo networkInfo = |
| 337 | new NetworkInfo(ConnectivityManager.TYPE_WIFI, 2, "WIFI", "WIFI_SUBTYPE"); |
| 338 | AccessPoint accessPoint = new AccessPoint(mContext, configuration); |
| 339 | WifiInfo wifiInfo = new WifiInfo(); |
| 340 | wifiInfo.setSSID(WifiSsid.createFromAsciiEncoded(configuration.SSID)); |
| 341 | wifiInfo.setBSSID(configuration.BSSID); |
| 342 | wifiInfo.setNetworkId(configuration.networkId); |
| 343 | accessPoint.update(configuration, wifiInfo, networkInfo); |
| 344 | |
| 345 | assertThat(accessPoint.isMetered()).isFalse(); |
| 346 | } |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 347 | |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 348 | @Test |
Sundeep Ghuman | 55adc6b | 2017-06-05 16:46:59 -0700 | [diff] [blame] | 349 | public void testSpeedLabel_returnsVeryFast() { |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 350 | AccessPoint ap = createAccessPointWithScanResultCache(); |
| 351 | |
| 352 | when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) |
| 353 | .thenReturn(buildScoredNetworkWithMockBadgeCurve()); |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 354 | when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.Speed.VERY_FAST); |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 355 | |
| 356 | ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); |
| 357 | |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 358 | assertThat(ap.getSpeed()).isEqualTo(AccessPoint.Speed.VERY_FAST); |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 359 | assertThat(ap.getSpeedLabel()) |
| 360 | .isEqualTo(mContext.getString(R.string.speed_label_very_fast)); |
| 361 | } |
| 362 | |
| 363 | @Test |
Sundeep Ghuman | 55adc6b | 2017-06-05 16:46:59 -0700 | [diff] [blame] | 364 | public void testSpeedLabel_returnsFast() { |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 365 | AccessPoint ap = createAccessPointWithScanResultCache(); |
| 366 | |
| 367 | when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) |
| 368 | .thenReturn(buildScoredNetworkWithMockBadgeCurve()); |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 369 | when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.Speed.FAST); |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 370 | |
| 371 | ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); |
| 372 | |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 373 | assertThat(ap.getSpeed()).isEqualTo(AccessPoint.Speed.FAST); |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 374 | assertThat(ap.getSpeedLabel()) |
| 375 | .isEqualTo(mContext.getString(R.string.speed_label_fast)); |
| 376 | } |
| 377 | |
| 378 | @Test |
Sundeep Ghuman | 55adc6b | 2017-06-05 16:46:59 -0700 | [diff] [blame] | 379 | public void testSpeedLabel_returnsOkay() { |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 380 | AccessPoint ap = createAccessPointWithScanResultCache(); |
| 381 | |
| 382 | when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) |
| 383 | .thenReturn(buildScoredNetworkWithMockBadgeCurve()); |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 384 | when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.Speed.MODERATE); |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 385 | |
| 386 | ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); |
| 387 | |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 388 | assertThat(ap.getSpeed()).isEqualTo(AccessPoint.Speed.MODERATE); |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 389 | assertThat(ap.getSpeedLabel()) |
| 390 | .isEqualTo(mContext.getString(R.string.speed_label_okay)); |
| 391 | } |
| 392 | |
| 393 | @Test |
Sundeep Ghuman | 55adc6b | 2017-06-05 16:46:59 -0700 | [diff] [blame] | 394 | public void testSpeedLabel_returnsSlow() { |
| 395 | AccessPoint ap = createAccessPointWithScanResultCache(); |
| 396 | |
| 397 | when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) |
| 398 | .thenReturn(buildScoredNetworkWithMockBadgeCurve()); |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 399 | when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.Speed.SLOW); |
Sundeep Ghuman | 55adc6b | 2017-06-05 16:46:59 -0700 | [diff] [blame] | 400 | |
| 401 | ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); |
| 402 | |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 403 | assertThat(ap.getSpeed()).isEqualTo(AccessPoint.Speed.SLOW); |
Sundeep Ghuman | 55adc6b | 2017-06-05 16:46:59 -0700 | [diff] [blame] | 404 | assertThat(ap.getSpeedLabel()) |
| 405 | .isEqualTo(mContext.getString(R.string.speed_label_slow)); |
| 406 | } |
| 407 | |
| 408 | @Test |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 409 | public void testSummaryString_showsSpeedLabel() { |
| 410 | AccessPoint ap = createAccessPointWithScanResultCache(); |
| 411 | |
| 412 | when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) |
| 413 | .thenReturn(buildScoredNetworkWithMockBadgeCurve()); |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 414 | when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.Speed.VERY_FAST); |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 415 | |
| 416 | ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); |
| 417 | |
| 418 | assertThat(ap.getSummary()).isEqualTo(mContext.getString(R.string.speed_label_very_fast)); |
| 419 | } |
| 420 | |
| 421 | @Test |
| 422 | public void testSummaryString_concatenatesSpeedLabel() { |
| 423 | AccessPoint ap = createAccessPointWithScanResultCache(); |
| 424 | ap.update(new WifiConfiguration()); |
| 425 | |
| 426 | when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) |
| 427 | .thenReturn(buildScoredNetworkWithMockBadgeCurve()); |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 428 | when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.Speed.VERY_FAST); |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 429 | |
| 430 | ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); |
| 431 | |
| 432 | String expectedString = mContext.getString(R.string.speed_label_very_fast) + " / " |
| 433 | + mContext.getString(R.string.wifi_remembered); |
| 434 | assertThat(ap.getSummary()).isEqualTo(expectedString); |
| 435 | } |
| 436 | |
Peter Qiu | 9c4c6ad | 2017-06-20 13:17:36 -0700 | [diff] [blame] | 437 | @Test |
| 438 | public void testSummaryString_showsWrongPasswordLabel() { |
| 439 | WifiConfiguration configuration = createWifiConfiguration(); |
| 440 | configuration.getNetworkSelectionStatus().setNetworkSelectionStatus( |
| 441 | WifiConfiguration.NetworkSelectionStatus.NETWORK_SELECTION_PERMANENTLY_DISABLED); |
| 442 | configuration.getNetworkSelectionStatus().setNetworkSelectionDisableReason( |
| 443 | WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD); |
| 444 | AccessPoint ap = new AccessPoint(mContext, configuration); |
| 445 | |
| 446 | assertThat(ap.getSummary()).isEqualTo(mContext.getString( |
| 447 | R.string.wifi_check_password_try_again)); |
| 448 | } |
| 449 | |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 450 | private ScoredNetwork buildScoredNetworkWithMockBadgeCurve() { |
| 451 | Bundle attr1 = new Bundle(); |
| 452 | attr1.putParcelable(ScoredNetwork.ATTRIBUTES_KEY_BADGING_CURVE, mockBadgeCurve); |
| 453 | return new ScoredNetwork( |
| 454 | new NetworkKey(new WifiKey("\"ssid\"", "00:00:00:00:00:00")), |
| 455 | mockBadgeCurve, |
| 456 | false /* meteredHint */, |
| 457 | attr1); |
| 458 | |
| 459 | } |
| 460 | |
Sundeep Ghuman | 54bdcfa | 2017-03-08 19:52:05 -0800 | [diff] [blame] | 461 | private AccessPoint createAccessPointWithScanResultCache() { |
| 462 | Bundle bundle = new Bundle(); |
| 463 | ArrayList<ScanResult> scanResults = new ArrayList<>(); |
| 464 | for (int i = 0; i < 5; i++) { |
| 465 | ScanResult scanResult = new ScanResult(); |
| 466 | scanResult.level = i; |
| 467 | scanResult.BSSID = "bssid-" + i; |
| 468 | scanResult.timestamp = SystemClock.elapsedRealtime() * 1000; |
Sundeep Ghuman | ce78a5f | 2017-03-15 19:06:14 -0700 | [diff] [blame] | 469 | scanResult.capabilities = ""; |
Sundeep Ghuman | 54bdcfa | 2017-03-08 19:52:05 -0800 | [diff] [blame] | 470 | scanResults.add(scanResult); |
| 471 | } |
| 472 | |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 473 | bundle.putParcelableArrayList(AccessPoint.KEY_SCANRESULTCACHE, scanResults); |
Sundeep Ghuman | 54bdcfa | 2017-03-08 19:52:05 -0800 | [diff] [blame] | 474 | return new AccessPoint(mContext, bundle); |
| 475 | } |
| 476 | |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 477 | private WifiConfiguration createWifiConfiguration() { |
| 478 | WifiConfiguration configuration = new WifiConfiguration(); |
| 479 | configuration.BSSID = "bssid"; |
| 480 | configuration.SSID = "ssid"; |
| 481 | configuration.networkId = 123; |
| 482 | return configuration; |
| 483 | } |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 484 | |
| 485 | /** |
| 486 | * Assert that the first AccessPoint appears after the second AccessPoint |
| 487 | * once sorting has been completed. |
| 488 | */ |
| 489 | private void assertSortingWorks(AccessPoint first, AccessPoint second) { |
| 490 | |
| 491 | ArrayList<AccessPoint> points = new ArrayList<AccessPoint>(); |
| 492 | |
| 493 | // add in reverse order so we can tell that sorting actually changed something |
| 494 | points.add(second); |
| 495 | points.add(first); |
| 496 | Collections.sort(points); |
| 497 | assertWithMessage( |
| 498 | String.format("After sorting: second AccessPoint should have higher array index " |
| 499 | + "than the first, but found indicies second '%s' and first '%s'.", |
| 500 | points.indexOf(second), points.indexOf(first))) |
| 501 | .that(points.indexOf(second)).isGreaterThan(points.indexOf(first)); |
| 502 | } |
| 503 | |
| 504 | @Test |
| 505 | public void testBuilder_setActive() { |
| 506 | AccessPoint activeAp = new TestAccessPointBuilder(mContext).setActive(true).build(); |
| 507 | assertThat(activeAp.isActive()).isTrue(); |
| 508 | |
| 509 | AccessPoint inactiveAp = new TestAccessPointBuilder(mContext).setActive(false).build(); |
| 510 | assertThat(inactiveAp.isActive()).isFalse(); |
| 511 | } |
| 512 | |
| 513 | @Test |
| 514 | public void testBuilder_setReachable() { |
| 515 | AccessPoint nearAp = new TestAccessPointBuilder(mContext).setReachable(true).build(); |
| 516 | assertThat(nearAp.isReachable()).isTrue(); |
| 517 | |
| 518 | AccessPoint farAp = new TestAccessPointBuilder(mContext).setReachable(false).build(); |
| 519 | assertThat(farAp.isReachable()).isFalse(); |
| 520 | } |
| 521 | |
| 522 | @Test |
| 523 | public void testBuilder_setSaved() { |
| 524 | AccessPoint savedAp = new TestAccessPointBuilder(mContext).setSaved(true).build(); |
| 525 | assertThat(savedAp.isSaved()).isTrue(); |
| 526 | |
| 527 | AccessPoint newAp = new TestAccessPointBuilder(mContext).setSaved(false).build(); |
| 528 | assertThat(newAp.isSaved()).isFalse(); |
| 529 | } |
| 530 | |
| 531 | @Test |
| 532 | public void testBuilder_setLevel() { |
| 533 | AccessPoint testAp; |
| 534 | |
| 535 | for (int i = 0; i < AccessPoint.SIGNAL_LEVELS; i++) { |
| 536 | testAp = new TestAccessPointBuilder(mContext).setLevel(i).build(); |
| 537 | assertThat(testAp.getLevel()).isEqualTo(i); |
| 538 | } |
| 539 | |
| 540 | // numbers larger than the max level should be set to max |
| 541 | testAp = new TestAccessPointBuilder(mContext).setLevel(AccessPoint.SIGNAL_LEVELS).build(); |
| 542 | assertThat(testAp.getLevel()).isEqualTo(AccessPoint.SIGNAL_LEVELS - 1); |
| 543 | |
| 544 | // numbers less than 0 should give level 0 |
| 545 | testAp = new TestAccessPointBuilder(mContext).setLevel(-100).build(); |
| 546 | assertThat(testAp.getLevel()).isEqualTo(0); |
| 547 | } |
| 548 | |
| 549 | @Test |
| 550 | public void testBuilder_settingReachableAfterLevelDoesNotAffectLevel() { |
| 551 | int level = 1; |
| 552 | assertThat(level).isLessThan(AccessPoint.SIGNAL_LEVELS - 1); |
| 553 | |
| 554 | AccessPoint testAp = |
| 555 | new TestAccessPointBuilder(mContext).setLevel(level).setReachable(true).build(); |
| 556 | assertThat(testAp.getLevel()).isEqualTo(level); |
| 557 | } |
| 558 | |
| 559 | @Test |
| 560 | public void testBuilder_setSsid() { |
| 561 | String name = "AmazingSsid!"; |
| 562 | AccessPoint namedAp = new TestAccessPointBuilder(mContext).setSsid(name).build(); |
| 563 | assertThat(namedAp.getSsidStr()).isEqualTo(name); |
| 564 | } |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 565 | |
| 566 | @Test |
| 567 | public void testBuilder_passpointConfig() { |
| 568 | String fqdn = "Test.com"; |
| 569 | String providerFriendlyName = "Test Provider"; |
| 570 | AccessPoint ap = new TestAccessPointBuilder(mContext).setFqdn(fqdn) |
| 571 | .setProviderFriendlyName(providerFriendlyName).build(); |
Stephen Chen | b5bcb8d | 2017-05-19 15:55:02 -0700 | [diff] [blame] | 572 | assertThat(ap.isPasspointConfig()).isTrue(); |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 573 | assertThat(ap.getPasspointFqdn()).isEqualTo(fqdn); |
| 574 | assertThat(ap.getConfigName()).isEqualTo(providerFriendlyName); |
| 575 | } |
Sundeep Ghuman | 96a5357 | 2017-04-20 21:25:41 -0700 | [diff] [blame] | 576 | |
| 577 | @Test |
| 578 | public void testUpdateNetworkInfo_returnsTrue() { |
| 579 | int networkId = 123; |
| 580 | int rssi = -55; |
| 581 | WifiConfiguration config = new WifiConfiguration(); |
| 582 | config.networkId = networkId; |
| 583 | WifiInfo wifiInfo = new WifiInfo(); |
| 584 | wifiInfo.setNetworkId(networkId); |
| 585 | wifiInfo.setRssi(rssi); |
| 586 | |
| 587 | NetworkInfo networkInfo = |
| 588 | new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", ""); |
| 589 | networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTING, "", ""); |
| 590 | |
| 591 | AccessPoint ap = new TestAccessPointBuilder(mContext) |
| 592 | .setNetworkInfo(networkInfo) |
| 593 | .setNetworkId(networkId) |
| 594 | .setRssi(rssi) |
| 595 | .setWifiInfo(wifiInfo) |
| 596 | .build(); |
| 597 | |
| 598 | NetworkInfo newInfo = new NetworkInfo(networkInfo); |
| 599 | newInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "", ""); |
| 600 | assertThat(ap.update(config, wifiInfo, newInfo)).isTrue(); |
| 601 | } |
| 602 | |
| 603 | @Test |
| 604 | public void testUpdateNetworkInfoWithSameInfo_returnsFalse() { |
| 605 | int networkId = 123; |
| 606 | int rssi = -55; |
| 607 | WifiConfiguration config = new WifiConfiguration(); |
| 608 | config.networkId = networkId; |
| 609 | WifiInfo wifiInfo = new WifiInfo(); |
| 610 | wifiInfo.setNetworkId(networkId); |
| 611 | wifiInfo.setRssi(rssi); |
| 612 | |
| 613 | NetworkInfo networkInfo = |
| 614 | new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", ""); |
| 615 | networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTING, "", ""); |
| 616 | |
| 617 | AccessPoint ap = new TestAccessPointBuilder(mContext) |
| 618 | .setNetworkInfo(networkInfo) |
| 619 | .setNetworkId(networkId) |
| 620 | .setRssi(rssi) |
| 621 | .setWifiInfo(wifiInfo) |
| 622 | .build(); |
| 623 | |
| 624 | NetworkInfo newInfo = new NetworkInfo(networkInfo); // same values |
| 625 | assertThat(ap.update(config, wifiInfo, newInfo)).isFalse(); |
| 626 | } |
Sundeep Ghuman | f4d3302 | 2017-06-05 19:47:36 -0700 | [diff] [blame] | 627 | |
| 628 | @Test |
| 629 | public void testUpdateWithConfigChangeOnly_returnsFalseButInvokesListener() { |
| 630 | int networkId = 123; |
| 631 | int rssi = -55; |
| 632 | WifiConfiguration config = new WifiConfiguration(); |
| 633 | config.networkId = networkId; |
| 634 | config.numNoInternetAccessReports = 1; |
| 635 | |
| 636 | WifiInfo wifiInfo = new WifiInfo(); |
| 637 | wifiInfo.setNetworkId(networkId); |
| 638 | wifiInfo.setRssi(rssi); |
| 639 | |
| 640 | NetworkInfo networkInfo = |
| 641 | new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", ""); |
| 642 | networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "", ""); |
| 643 | |
| 644 | AccessPoint ap = new TestAccessPointBuilder(mContext) |
| 645 | .setNetworkInfo(networkInfo) |
| 646 | .setNetworkId(networkId) |
| 647 | .setRssi(rssi) |
| 648 | .setWifiInfo(wifiInfo) |
| 649 | .build(); |
| 650 | |
| 651 | AccessPoint.AccessPointListener mockListener = mock(AccessPoint.AccessPointListener.class); |
| 652 | ap.setListener(mockListener); |
| 653 | WifiConfiguration newConfig = new WifiConfiguration(config); |
| 654 | config.validatedInternetAccess = true; |
| 655 | |
| 656 | assertThat(ap.update(newConfig, wifiInfo, networkInfo)).isFalse(); |
| 657 | verify(mockListener).onAccessPointChanged(ap); |
| 658 | } |
Sundeep Ghuman | d911da3 | 2017-07-05 20:06:05 -0700 | [diff] [blame] | 659 | |
| 660 | @Test |
| 661 | public void testUpdateWithNullWifiConfiguration_doesNotThrowNPE() { |
| 662 | int networkId = 123; |
| 663 | int rssi = -55; |
| 664 | WifiConfiguration config = new WifiConfiguration(); |
| 665 | config.networkId = networkId; |
| 666 | WifiInfo wifiInfo = new WifiInfo(); |
| 667 | wifiInfo.setNetworkId(networkId); |
| 668 | wifiInfo.setRssi(rssi); |
| 669 | |
| 670 | NetworkInfo networkInfo = |
| 671 | new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", ""); |
| 672 | networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTING, "", ""); |
| 673 | |
| 674 | AccessPoint ap = new TestAccessPointBuilder(mContext) |
| 675 | .setNetworkInfo(networkInfo) |
| 676 | .setNetworkId(networkId) |
| 677 | .setRssi(rssi) |
| 678 | .setWifiInfo(wifiInfo) |
| 679 | .build(); |
| 680 | |
| 681 | ap.update(null, wifiInfo, networkInfo); |
| 682 | } |
Fan Zhang | eb83a0d | 2016-09-21 11:34:08 -0700 | [diff] [blame] | 683 | } |