• 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.wifitrackerlib;
18 
19 import static com.android.wifitrackerlib.TestUtils.buildScanResult;
20 import static com.android.wifitrackerlib.WifiEntry.SPEED_FAST;
21 import static com.android.wifitrackerlib.WifiEntry.SPEED_SLOW;
22 
23 import static com.google.common.truth.Truth.assertThat;
24 
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.spy;
28 import static org.mockito.Mockito.times;
29 import static org.mockito.Mockito.verify;
30 import static org.mockito.Mockito.when;
31 
32 import android.content.Context;
33 import android.content.res.Resources;
34 import android.net.ConnectivityManager;
35 import android.net.NetworkCapabilities;
36 import android.net.NetworkInfo;
37 import android.net.NetworkKey;
38 import android.net.ScoredNetwork;
39 import android.net.wifi.ScanResult;
40 import android.net.wifi.WifiConfiguration;
41 import android.net.wifi.WifiInfo;
42 import android.net.wifi.WifiManager;
43 import android.net.wifi.WifiNetworkScoreCache;
44 import android.net.wifi.hotspot2.PasspointConfiguration;
45 import android.net.wifi.hotspot2.pps.Credential;
46 import android.net.wifi.hotspot2.pps.HomeSp;
47 import android.os.Handler;
48 import android.os.test.TestLooper;
49 
50 import org.junit.Before;
51 import org.junit.Test;
52 import org.mockito.Mock;
53 import org.mockito.MockitoAnnotations;
54 
55 import java.util.Arrays;
56 import java.util.Collections;
57 
58 public class PasspointWifiEntryTest {
59     public static final int GOOD_RSSI = -50;
60     public static final int OKAY_RSSI = -60;
61     public static final int BAD_RSSI = -70;
62 
63     @Mock private Context mMockContext;
64     @Mock private WifiManager mMockWifiManager;
65     @Mock private Resources mMockResources;
66     @Mock private WifiInfo mMockWifiInfo;
67     @Mock private NetworkInfo mMockNetworkInfo;
68     @Mock private WifiNetworkScoreCache mMockScoreCache;
69     @Mock private ScoredNetwork mMockScoredNetwork;
70     @Mock private ConnectivityManager mMockConnectivityManager;
71 
72     private TestLooper mTestLooper;
73     private Handler mTestHandler;
74 
75     private static final String FQDN = "fqdn";
76 
77     @Before
setUp()78     public void setUp() {
79         Utils.sFeatureFlagUtilsWrapper = new Utils.FeatureFlagUtilsWrapper() {
80             @Override
81             boolean isProviderModelEnabled(Context context) {
82                 return false;
83             }
84         };
85 
86         MockitoAnnotations.initMocks(this);
87 
88         mTestLooper = new TestLooper();
89         mTestHandler = new Handler(mTestLooper.getLooper());
90 
91         when(mMockWifiInfo.getNetworkId()).thenReturn(WifiConfiguration.INVALID_NETWORK_ID);
92         when(mMockWifiInfo.getRssi()).thenReturn(WifiInfo.INVALID_RSSI);
93         when(mMockNetworkInfo.getDetailedState()).thenReturn(
94                 NetworkInfo.DetailedState.DISCONNECTED);
95         when(mMockContext.getResources()).thenReturn(mMockResources);
96         when(mMockResources.getString(R.string.wifitrackerlib_summary_separator)).thenReturn("/");
97         when(mMockScoreCache.getScoredNetwork((ScanResult) any())).thenReturn(mMockScoredNetwork);
98         when(mMockScoreCache.getScoredNetwork((NetworkKey) any())).thenReturn(mMockScoredNetwork);
99     }
100 
101     @Test
testGetSummary_expiredTimeNotAvailable_notShowExpired()102     public void testGetSummary_expiredTimeNotAvailable_notShowExpired() {
103         // default SubscriptionExpirationTimeInMillis is unset
104         PasspointConfiguration passpointConfiguration = getPasspointConfiguration();
105         String expired = "Expired";
106         when(mMockResources.getString(R.string.wifitrackerlib_wifi_passpoint_expired))
107                 .thenReturn(expired);
108 
109         PasspointWifiEntry passpointWifiEntry = new PasspointWifiEntry(mMockContext, mTestHandler,
110                 passpointConfiguration, mMockWifiManager, mMockScoreCache,
111                 false /* forSavedNetworksPage */);
112 
113         assertThat(passpointWifiEntry.getSummary()).isNotEqualTo(expired);
114     }
115 
116     @Test
testGetSummary_expired_showExpired()117     public void testGetSummary_expired_showExpired() {
118         PasspointConfiguration passpointConfiguration = getPasspointConfiguration();
119         String expired = "Expired";
120         when(mMockResources.getString(R.string.wifitrackerlib_wifi_passpoint_expired))
121                 .thenReturn(expired);
122         PasspointWifiEntry passpointWifiEntry = new PasspointWifiEntry(mMockContext, mTestHandler,
123                 passpointConfiguration, mMockWifiManager, mMockScoreCache,
124                 false /* forSavedNetworksPage */);
125         PasspointWifiEntry spyEntry = spy(passpointWifiEntry);
126         when(spyEntry.isExpired()).thenReturn(true);
127 
128         assertThat(spyEntry.getSummary()).isEqualTo(expired);
129     }
130 
getPasspointConfiguration()131     private PasspointConfiguration getPasspointConfiguration() {
132         PasspointConfiguration passpointConfiguration = new PasspointConfiguration();
133         HomeSp homeSp = new HomeSp();
134         homeSp.setFqdn(FQDN);
135         passpointConfiguration.setHomeSp(homeSp);
136         passpointConfiguration.setCredential(new Credential());
137         return passpointConfiguration;
138     }
139 
140     @Test
testGetMeteredChoice_afterSetMeteredChoice_getCorrectValue()141     public void testGetMeteredChoice_afterSetMeteredChoice_getCorrectValue() {
142         PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
143                 getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
144                 false /* forSavedNetworksPage */);
145 
146         entry.setMeteredChoice(WifiEntry.METERED_CHOICE_UNMETERED);
147 
148         assertThat(entry.getMeteredChoice()).isEqualTo(WifiEntry.METERED_CHOICE_UNMETERED);
149     }
150 
151     @Test
testGetSummary_connectedWifiNetwork_showsConnected()152     public void testGetSummary_connectedWifiNetwork_showsConnected() {
153         String summarySeparator = " / ";
154         String[] wifiStatusArray = new String[]{"", "Scanning", "Connecting",
155                 "Authenticating", "Obtaining IP address", "Connected"};
156 
157         Resources mockResources = mock(Resources.class);
158         when(mMockContext.getResources()).thenReturn(mockResources);
159         when(mockResources.getString(R.string.wifitrackerlib_summary_separator))
160                 .thenReturn(summarySeparator);
161         when(mockResources.getStringArray(R.array.wifitrackerlib_wifi_status))
162                 .thenReturn(wifiStatusArray);
163         ConnectivityManager mockConnectivityManager = mock(ConnectivityManager.class);
164         when(mMockContext.getSystemService(Context.CONNECTIVITY_SERVICE))
165                 .thenReturn(mockConnectivityManager);
166         final NetworkCapabilities networkCapabilities = new NetworkCapabilities.Builder()
167                 .addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED).build();
168         WifiInfo wifiInfo = mock(WifiInfo.class);
169         when(wifiInfo.isPasspointAp()).thenReturn(true);
170         when(wifiInfo.getPasspointFqdn()).thenReturn(FQDN);
171         NetworkInfo networkInfo =
172                 new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", "");
173         networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "", "");
174 
175         PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
176                 getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
177                 false /* forSavedNetworksPage */);
178         entry.updateConnectionInfo(wifiInfo, networkInfo);
179         entry.updateNetworkCapabilities(networkCapabilities);
180         entry.setIsDefaultNetwork(true);
181 
182         assertThat(entry.getSummary()).isEqualTo("Connected");
183     }
184 
185     @Test
testGetSummary_providerModelConnectedButNotDefault_doesNotShowConnected()186     public void testGetSummary_providerModelConnectedButNotDefault_doesNotShowConnected() {
187         Utils.sFeatureFlagUtilsWrapper = new Utils.FeatureFlagUtilsWrapper() {
188             @Override
189             boolean isProviderModelEnabled(Context context) {
190                 return true;
191             }
192         };
193         String summarySeparator = " / ";
194         String[] wifiStatusArray = new String[]{"", "Scanning", "Connecting",
195                 "Authenticating", "Obtaining IP address", "Connected"};
196 
197         Resources mockResources = mock(Resources.class);
198         when(mMockContext.getResources()).thenReturn(mockResources);
199         when(mockResources.getString(R.string.wifitrackerlib_summary_separator))
200                 .thenReturn(summarySeparator);
201         when(mockResources.getStringArray(R.array.wifitrackerlib_wifi_status))
202                 .thenReturn(wifiStatusArray);
203         ConnectivityManager mockConnectivityManager = mock(ConnectivityManager.class);
204         when(mMockContext.getSystemService(Context.CONNECTIVITY_SERVICE))
205                 .thenReturn(mockConnectivityManager);
206         final NetworkCapabilities networkCapabilities = new NetworkCapabilities.Builder()
207                 .addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED).build();
208         WifiInfo wifiInfo = mock(WifiInfo.class);
209         when(wifiInfo.isPasspointAp()).thenReturn(true);
210         when(wifiInfo.getPasspointFqdn()).thenReturn(FQDN);
211         NetworkInfo networkInfo =
212                 new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", "");
213         networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "", "");
214 
215         PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
216                 getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
217                 false /* forSavedNetworksPage */);
218         entry.updateConnectionInfo(wifiInfo, networkInfo);
219         entry.updateNetworkCapabilities(networkCapabilities);
220         entry.setIsDefaultNetwork(false);
221 
222         assertThat(entry.getSummary()).isEqualTo("");
223     }
224 
225     @Test
testGetSecurityTypes_connectedWifiNetwork_showsCurrentSecurityType()226     public void testGetSecurityTypes_connectedWifiNetwork_showsCurrentSecurityType() {
227         WifiInfo wifiInfo = mock(WifiInfo.class);
228         when(wifiInfo.isPasspointAp()).thenReturn(true);
229         when(wifiInfo.getPasspointFqdn()).thenReturn(FQDN);
230         when(wifiInfo.getCurrentSecurityType()).thenReturn(WifiInfo.SECURITY_TYPE_PASSPOINT_R1_R2);
231         NetworkInfo networkInfo =
232                 new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", "");
233         networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "", "");
234 
235         PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
236                 getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
237                 false /* forSavedNetworksPage */);
238 
239         assertThat(entry.getSecurityTypes()).containsExactlyElementsIn(Arrays.asList(
240                 WifiInfo.SECURITY_TYPE_PASSPOINT_R1_R2,
241                 WifiInfo.SECURITY_TYPE_PASSPOINT_R3));
242 
243         entry.updateConnectionInfo(wifiInfo, networkInfo);
244 
245         assertThat(entry.getSecurityTypes())
246                 .containsExactly(WifiInfo.SECURITY_TYPE_PASSPOINT_R1_R2);
247 
248         when(wifiInfo.getCurrentSecurityType()).thenReturn(WifiInfo.SECURITY_TYPE_PASSPOINT_R3);
249         entry.updateConnectionInfo(wifiInfo, networkInfo);
250 
251         assertThat(entry.getSecurityTypes()).containsExactly(WifiInfo.SECURITY_TYPE_PASSPOINT_R3);
252     }
253 
254     @Test
testGetSecurityString_showsPasspoint()255     public void testGetSecurityString_showsPasspoint() {
256         PasspointConfiguration passpointConfiguration = getPasspointConfiguration();
257         String passpointSecurity = "Passpoint";
258         when(mMockResources.getString(R.string.wifitrackerlib_wifi_security_passpoint))
259                 .thenReturn(passpointSecurity);
260 
261         PasspointWifiEntry passpointWifiEntry = new PasspointWifiEntry(mMockContext, mTestHandler,
262                 passpointConfiguration, mMockWifiManager, mMockScoreCache,
263                 false /* forSavedNetworksPage */);
264 
265         assertThat(passpointWifiEntry.getSecurityString(false)).isEqualTo(passpointSecurity);
266     }
267 
268     @Test
testShouldShowXLevelIcon_unvalidatedOrNotDefault_returnsTrue()269     public void testShouldShowXLevelIcon_unvalidatedOrNotDefault_returnsTrue() {
270         ConnectivityManager mockConnectivityManager = mock(ConnectivityManager.class);
271         when(mMockContext.getSystemService(Context.CONNECTIVITY_SERVICE))
272                 .thenReturn(mockConnectivityManager);
273         final NetworkCapabilities networkCapabilities = new NetworkCapabilities.Builder()
274                 .addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED).build();
275         WifiInfo wifiInfo = mock(WifiInfo.class);
276         when(wifiInfo.isPasspointAp()).thenReturn(true);
277         when(wifiInfo.getPasspointFqdn()).thenReturn(FQDN);
278         final NetworkInfo networkInfo =
279                 new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", "");
280         networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "", "");
281 
282         PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
283                 getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
284                 false /* forSavedNetworksPage */);
285 
286         // Disconnected should return false;
287         assertThat(entry.shouldShowXLevelIcon()).isEqualTo(false);
288 
289         // Not validated, Not Default
290         entry.updateConnectionInfo(wifiInfo, networkInfo);
291 
292         assertThat(entry.shouldShowXLevelIcon()).isEqualTo(true);
293 
294         // Not Validated, Default
295         entry.setIsDefaultNetwork(true);
296 
297         assertThat(entry.shouldShowXLevelIcon()).isEqualTo(true);
298 
299         // Validated, Default
300         entry.updateNetworkCapabilities(networkCapabilities);
301 
302         assertThat(entry.shouldShowXLevelIcon()).isEqualTo(false);
303 
304         // Validated, Not Default
305         entry.setIsDefaultNetwork(false);
306 
307         assertThat(entry.shouldShowXLevelIcon()).isEqualTo(true);
308     }
309 
310     @Test
testGetSpeed_cacheUpdated_speedValueChanges()311     public void testGetSpeed_cacheUpdated_speedValueChanges() {
312         when(mMockScoredNetwork.calculateBadge(GOOD_RSSI)).thenReturn(SPEED_FAST);
313         PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
314                 getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
315                 false /* forSavedNetworksPage */);
316         WifiConfiguration wifiConfig = new WifiConfiguration();
317         wifiConfig.FQDN = FQDN;
318         entry.updateScanResultInfo(wifiConfig,
319                 Collections.singletonList(buildScanResult("ssid", "bssid0", 0, GOOD_RSSI)),
320                 null);
321 
322         when(mMockScoredNetwork.calculateBadge(GOOD_RSSI)).thenReturn(SPEED_SLOW);
323         entry.onScoreCacheUpdated();
324 
325         assertThat(entry.getSpeed()).isEqualTo(SPEED_SLOW);
326     }
327 
328     @Test
testGetSpeed_connected_useWifiInfoRssiForSpeed()329     public void testGetSpeed_connected_useWifiInfoRssiForSpeed() {
330         when(mMockScoredNetwork.calculateBadge(BAD_RSSI)).thenReturn(SPEED_SLOW);
331         when(mMockScoredNetwork.calculateBadge(GOOD_RSSI)).thenReturn(SPEED_FAST);
332         when(mMockWifiInfo.isPasspointAp()).thenReturn(true);
333         when(mMockWifiInfo.getPasspointFqdn()).thenReturn(FQDN);
334         when(mMockWifiInfo.getRssi()).thenReturn(BAD_RSSI);
335         when(mMockWifiInfo.getSSID()).thenReturn("\"ssid\"");
336         when(mMockWifiInfo.getBSSID()).thenReturn("01:23:45:67:89:ab");
337         PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
338                 getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
339                 false /* forSavedNetworksPage */);
340         WifiConfiguration wifiConfig = new WifiConfiguration();
341         wifiConfig.FQDN = FQDN;
342         entry.updateScanResultInfo(wifiConfig,
343                 Collections.singletonList(buildScanResult("ssid", "bssid0", 0, GOOD_RSSI)),
344                 null);
345 
346         entry.updateConnectionInfo(mMockWifiInfo, mMockNetworkInfo);
347 
348         assertThat(entry.getSpeed()).isEqualTo(SPEED_SLOW);
349     }
350 
351     @Test
testGetSpeed_newScanResults_speedValueChanges()352     public void testGetSpeed_newScanResults_speedValueChanges() {
353         when(mMockScoredNetwork.calculateBadge(BAD_RSSI)).thenReturn(SPEED_SLOW);
354         when(mMockScoredNetwork.calculateBadge(GOOD_RSSI)).thenReturn(SPEED_FAST);
355         PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
356                 getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
357                 false /* forSavedNetworksPage */);
358         WifiConfiguration wifiConfig = new WifiConfiguration();
359         wifiConfig.FQDN = FQDN;
360         entry.updateScanResultInfo(wifiConfig,
361                 Collections.singletonList(buildScanResult("ssid", "bssid0", 0, GOOD_RSSI)),
362                 null);
363 
364         entry.updateScanResultInfo(wifiConfig,
365                 Collections.singletonList(buildScanResult("ssid", "bssid0", 0, BAD_RSSI)),
366                 null);
367 
368         assertThat(entry.getSpeed()).isEqualTo(SPEED_SLOW);
369     }
370 
371     @Test
testGetMacAddress_wifiInfoAvailable_usesWifiInfoMacAddress()372     public void testGetMacAddress_wifiInfoAvailable_usesWifiInfoMacAddress() {
373         final String factoryMac = "01:23:45:67:89:ab";
374         final String wifiInfoMac = "11:23:45:67:89:ab";
375         final WifiConfiguration config = new WifiConfiguration();
376         config.SSID = "\"ssid\"";
377         config.macRandomizationSetting = WifiConfiguration.RANDOMIZATION_NONE;
378         config.FQDN = FQDN;
379         when(mMockWifiManager.getFactoryMacAddresses()).thenReturn(new String[]{factoryMac});
380         WifiInfo wifiInfo = mock(WifiInfo.class);
381         when(wifiInfo.isPasspointAp()).thenReturn(true);
382         when(wifiInfo.getPasspointFqdn()).thenReturn(FQDN);
383         when(wifiInfo.getMacAddress()).thenReturn(wifiInfoMac);
384         NetworkInfo networkInfo =
385                 new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", "");
386         networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "", "");
387         PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
388                 getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
389                 false /* forSavedNetworksPage */);
390 
391         entry.updateConnectionInfo(wifiInfo, networkInfo);
392 
393         assertThat(entry.getMacAddress()).isEqualTo(wifiInfoMac);
394     }
395 
396     @Test
testIsAutoJoinEnabled_nullConfigs_returnsFalse()397     public void testIsAutoJoinEnabled_nullConfigs_returnsFalse() {
398         PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
399                 getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
400                 false /* forSavedNetworksPage */);
401 
402         entry.updatePasspointConfig(null);
403 
404         assertThat(entry.isAutoJoinEnabled()).isFalse();
405     }
406 
407     @Test
testCanSignIn_captivePortalCapability_returnsTrue()408     public void testCanSignIn_captivePortalCapability_returnsTrue() {
409         PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
410                 getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
411                 false /* forSavedNetworksPage */);
412 
413         NetworkCapabilities captivePortalCapabilities = new NetworkCapabilities.Builder()
414                 .addCapability(NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL).build();
415         entry.updateNetworkCapabilities(captivePortalCapabilities);
416 
417         assertThat(entry.canSignIn()).isTrue();
418     }
419 
420     @Test
testUpdateNetworkCapabilities_userConnect_autoOpenCaptivePortalOnce()421     public void testUpdateNetworkCapabilities_userConnect_autoOpenCaptivePortalOnce() {
422         when(mMockContext.getSystemService(Context.CONNECTIVITY_SERVICE))
423                 .thenReturn(mMockConnectivityManager);
424         PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
425                 getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
426                 false /* forSavedNetworksPage */);
427         NetworkCapabilities captivePortalCapabilities = new NetworkCapabilities.Builder()
428                 .addCapability(NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL).build();
429 
430         // Simulate user tapping on the network and receiving captive portal capabilities.
431         // This should trigger the captive portal app.
432         entry.connect(null /* callback */);
433         entry.updateNetworkCapabilities(captivePortalCapabilities);
434 
435         verify(mMockConnectivityManager, times(1)).startCaptivePortalApp(any());
436 
437         // Update network capabilities again. This should not trigger the captive portal app.
438         entry.updateNetworkCapabilities(captivePortalCapabilities);
439 
440         verify(mMockConnectivityManager, times(1)).startCaptivePortalApp(any());
441     }
442 
443     @Test
testDisconnect_noScansOrWifiConfig_disconnectIsSuccessful()444     public void testDisconnect_noScansOrWifiConfig_disconnectIsSuccessful() {
445         // Setup a connected PasspointWifiEntry
446         String summarySeparator = " / ";
447         String[] wifiStatusArray = new String[]{"", "Scanning", "Connecting",
448                 "Authenticating", "Obtaining IP address", "Connected"};
449         Resources mockResources = mock(Resources.class);
450         when(mMockContext.getResources()).thenReturn(mockResources);
451         when(mockResources.getString(R.string.wifitrackerlib_summary_separator))
452                 .thenReturn(summarySeparator);
453         when(mockResources.getStringArray(R.array.wifitrackerlib_wifi_status))
454                 .thenReturn(wifiStatusArray);
455         ConnectivityManager mockConnectivityManager = mock(ConnectivityManager.class);
456         when(mMockContext.getSystemService(Context.CONNECTIVITY_SERVICE))
457                 .thenReturn(mockConnectivityManager);
458         final NetworkCapabilities networkCapabilities = new NetworkCapabilities.Builder()
459                 .addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED).build();
460         WifiInfo wifiInfo = mock(WifiInfo.class);
461         when(wifiInfo.isPasspointAp()).thenReturn(true);
462         when(wifiInfo.getPasspointFqdn()).thenReturn(FQDN);
463         NetworkInfo networkInfo =
464                 new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", "");
465         networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "", "");
466         PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
467                 getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
468                 false /* forSavedNetworksPage */);
469         entry.updateConnectionInfo(wifiInfo, networkInfo);
470         entry.updateNetworkCapabilities(networkCapabilities);
471 
472         // Disconnect the entry before it can be updated with scans and a WifiConfiguration
473         entry.disconnect(null);
474 
475         verify(mMockWifiManager).disableEphemeralNetwork(FQDN);
476         verify(mMockWifiManager).disconnect();
477     }
478 }
479