WifiStateMachineTest.java revision 3fff4c9bd5db730141e75706a7229814d403b363
1/*
2 * Copyright (C) 2015 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
17package com.android.server.wifi;
18
19import android.content.ContentResolver;
20import android.content.Context;
21import android.content.pm.PackageManager;
22import android.content.res.Resources;
23import android.net.ConnectivityManager;
24import android.net.DhcpResults;
25import android.net.ip.IpManager;
26import android.net.wifi.ScanResult;
27import android.net.wifi.SupplicantState;
28import android.net.wifi.WifiConfiguration;
29import android.net.wifi.WifiManager;
30import android.net.wifi.WifiSsid;
31import android.net.wifi.p2p.IWifiP2pManager;
32import android.os.BatteryStats;
33import android.os.Handler;
34import android.os.HandlerThread;
35import android.os.IBinder;
36import android.os.IInterface;
37import android.os.INetworkManagementService;
38import android.os.IPowerManager;
39import android.os.Looper;
40import android.os.Message;
41import android.os.Messenger;
42import android.os.PowerManager;
43import android.os.UserHandle;
44import android.provider.Settings;
45import android.test.suitebuilder.annotation.SmallTest;
46import android.util.Log;
47
48import com.android.internal.R;
49import com.android.internal.app.IBatteryStats;
50import com.android.internal.util.AsyncChannel;
51import com.android.internal.util.IState;
52import com.android.internal.util.StateMachine;
53import com.android.server.wifi.MockAnswerUtil.AnswerWithArguments;
54import com.android.server.wifi.hotspot2.NetworkDetail;
55import com.android.server.wifi.hotspot2.SupplicantBridge;
56import com.android.server.wifi.hotspot2.Utils;
57import com.android.server.wifi.hotspot2.omadm.PasspointManagementObjectManager;
58import com.android.server.wifi.p2p.WifiP2pServiceImpl;
59
60import org.junit.After;
61import org.junit.Before;
62import org.junit.Test;
63import org.mockito.Mock;
64import org.mockito.Mockito;
65import org.mockito.MockitoAnnotations;
66
67import java.io.ByteArrayOutputStream;
68import java.io.PrintWriter;
69import java.lang.reflect.Field;
70import java.lang.reflect.InvocationTargetException;
71import java.lang.reflect.Method;
72import java.util.ArrayList;
73import java.util.HashMap;
74import java.util.List;
75import java.util.Map;
76
77import static org.junit.Assert.assertEquals;
78import static org.junit.Assert.assertTrue;
79import static org.mockito.Mockito.any;
80import static org.mockito.Mockito.anyBoolean;
81import static org.mockito.Mockito.anyInt;
82import static org.mockito.Mockito.anyObject;
83import static org.mockito.Mockito.anyString;
84import static org.mockito.Mockito.mock;
85import static org.mockito.Mockito.verify;
86import static org.mockito.Mockito.when;
87import static org.mockito.Mockito.withSettings;
88
89/**
90 * Unit tests for {@link com.android.server.wifi.WifiStateMachine}.
91 */
92@SmallTest
93public class WifiStateMachineTest {
94    public static final String TAG = "WifiStateMachineTest";
95
96    private static final String IFNAME = "wlan0";
97
98    private static <T> T mockWithInterfaces(Class<T> class1, Class<?>... interfaces) {
99        return mock(class1, withSettings().extraInterfaces(interfaces));
100    }
101
102    private static <T, I> IBinder mockService(Class<T> class1, Class<I> iface) {
103        T tImpl = mockWithInterfaces(class1, iface);
104        IBinder binder = mock(IBinder.class);
105        when(((IInterface) tImpl).asBinder()).thenReturn(binder);
106        when(binder.queryLocalInterface(iface.getCanonicalName()))
107                .thenReturn((IInterface) tImpl);
108        return binder;
109    }
110
111    private void enableDebugLogs() {
112        mWsm.enableVerboseLogging(1);
113    }
114
115    private static void installWlanWifiNative(WifiNative wifiNative) throws Exception {
116        Field field = WifiNative.class.getDeclaredField("wlanNativeInterface");
117        field.setAccessible(true);
118        field.set(null, wifiNative);
119
120        when(wifiNative.getInterfaceName()).thenReturn(IFNAME);
121    }
122
123    private class TestIpManager extends IpManager {
124        TestIpManager(Context context, String ifname, IpManager.Callback callback) {
125            // Call test-only superclass constructor.
126            super(ifname, callback);
127        }
128
129        @Override
130        public void startProvisioning() {}
131
132        @Override
133        public void stop() {}
134
135        @Override
136        public void confirmConfiguration() {}
137    }
138
139    private FrameworkFacade getFrameworkFacade() throws InterruptedException {
140        FrameworkFacade facade = mock(FrameworkFacade.class);
141
142        when(facade.makeBaseLogger()).thenReturn(mock(BaseWifiLogger.class));
143        when(facade.getService(Context.NETWORKMANAGEMENT_SERVICE)).thenReturn(
144                mockWithInterfaces(IBinder.class, INetworkManagementService.class));
145
146        IBinder p2pBinder = mockService(WifiP2pServiceImpl.class, IWifiP2pManager.class);
147        when(facade.getService(Context.WIFI_P2P_SERVICE)).thenReturn(p2pBinder);
148
149        WifiP2pServiceImpl p2pm = (WifiP2pServiceImpl) p2pBinder.queryLocalInterface(
150                IWifiP2pManager.class.getCanonicalName());
151
152        final Object sync = new Object();
153        synchronized (sync) {
154            mP2pThread = new HandlerThread("WifiP2pMockThread") {
155                @Override
156                protected void onLooperPrepared() {
157                    synchronized (sync) {
158                        sync.notifyAll();
159                    }
160                }
161            };
162
163            mP2pThread.start();
164            sync.wait();
165        }
166
167        Handler handler = new Handler(mP2pThread.getLooper());
168        when(p2pm.getP2pStateMachineMessenger()).thenReturn(new Messenger(handler));
169
170        IBinder batteryStatsBinder = mockService(BatteryStats.class, IBatteryStats.class);
171        when(facade.getService(BatteryStats.SERVICE_NAME)).thenReturn(batteryStatsBinder);
172
173        when(facade.makeIpManager(any(Context.class), anyString(), any(IpManager.Callback.class)))
174                .then(new AnswerWithArguments<IpManager>() {
175                    public IpManager answer(
176                            Context context, String ifname, IpManager.Callback callback) {
177                        return new TestIpManager(context, ifname, callback);
178                    }
179                });
180
181        return facade;
182    }
183
184    private Context getContext() throws Exception {
185        PackageManager pkgMgr = mock(PackageManager.class);
186        when(pkgMgr.hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)).thenReturn(true);
187
188        Context context = mock(Context.class);
189        when(context.getPackageManager()).thenReturn(pkgMgr);
190        when(context.getContentResolver()).thenReturn(mock(ContentResolver.class));
191
192        MockResources resources = new com.android.server.wifi.MockResources();
193        when(context.getResources()).thenReturn(resources);
194
195        ContentResolver cr = mock(ContentResolver.class);
196        when(context.getContentResolver()).thenReturn(cr);
197
198        when(context.getSystemService(Context.POWER_SERVICE)).thenReturn(
199                new PowerManager(context, mock(IPowerManager.class), new Handler()));
200
201        mAlarmManager = new MockAlarmManager();
202        when(context.getSystemService(Context.ALARM_SERVICE)).thenReturn(
203                mAlarmManager.getAlarmManager());
204
205        when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(
206                mock(ConnectivityManager.class));
207
208        return context;
209    }
210
211    private Resources getMockResources() {
212        MockResources resources = new MockResources();
213        resources.setBoolean(R.bool.config_wifi_enable_wifi_firmware_debugging, false);
214        return resources;
215    }
216
217    private IState getCurrentState() throws
218            NoSuchMethodException, InvocationTargetException, IllegalAccessException {
219        Method method = StateMachine.class.getDeclaredMethod("getCurrentState");
220        method.setAccessible(true);
221        return (IState) method.invoke(mWsm);
222    }
223
224    private static HandlerThread getWsmHandlerThread(WifiStateMachine wsm) throws
225            NoSuchFieldException, InvocationTargetException, IllegalAccessException {
226        Field field = StateMachine.class.getDeclaredField("mSmThread");
227        field.setAccessible(true);
228        return (HandlerThread) field.get(wsm);
229    }
230
231    private static void stopLooper(final Looper looper) throws Exception {
232        new Handler(looper).post(new Runnable() {
233            @Override
234            public void run() {
235                looper.quitSafely();
236            }
237        });
238    }
239
240    private void wait(int delayInMs) throws InterruptedException {
241        Looper looper = mWsmThread.getLooper();
242        final Handler handler = new Handler(looper);
243        synchronized (handler) {
244            handler.postDelayed(new Runnable() {
245                @Override
246                public void run() {
247                    synchronized (handler) {
248                        handler.notifyAll();
249                    }
250                }
251            }, delayInMs);
252
253            handler.wait();
254        }
255    }
256
257    private void dumpState() {
258        ByteArrayOutputStream stream = new ByteArrayOutputStream();
259        PrintWriter writer = new PrintWriter(stream);
260        mWsm.dump(null, writer, null);
261        writer.flush();
262        Log.d(TAG, "WifiStateMachine state -" + stream.toString());
263    }
264
265    private static ScanDetail getGoogleGuestScanDetail(int rssi) {
266        ScanResult.InformationElement ie[] = new ScanResult.InformationElement[1];
267        ie[0] = ScanResults.generateSsidIe(sSSID);
268        NetworkDetail nd = new NetworkDetail(sBSSID, ie, new ArrayList<String>(), sFreq);
269        ScanDetail detail = new ScanDetail(nd, sWifiSsid, sBSSID, "", rssi, sFreq,
270                Long.MAX_VALUE /* needed so that scan results aren't rejected because
271                                  there older than scan start */);
272        return detail;
273    }
274
275    private ArrayList<ScanDetail> getMockScanResults() {
276        ScanResults sr = ScanResults.create(0, 2412, 2437, 2462, 5180, 5220, 5745, 5825);
277        ArrayList<ScanDetail> list = sr.getScanDetailArrayList();
278
279        int rssi = -65;
280        list.add(getGoogleGuestScanDetail(rssi));
281        return list;
282    }
283
284    static final String   sSSID = "\"GoogleGuest\"";
285    static final WifiSsid sWifiSsid = WifiSsid.createFromAsciiEncoded(sSSID);
286    static final String   sHexSSID = sWifiSsid.getHexString().replace("0x", "").replace("22", "");
287    static final String   sBSSID = "01:02:03:04:05:06";
288    static final int      sFreq = 2437;
289
290    WifiStateMachine mWsm;
291    HandlerThread mWsmThread;
292    HandlerThread mP2pThread;
293    HandlerThread mSyncThread;
294    AsyncChannel  mWsmAsyncChannel;
295    MockAlarmManager mAlarmManager;
296    MockWifiMonitor mWifiMonitor;
297
298    @Mock WifiNative mWifiNative;
299    @Mock SupplicantStateTracker mSupplicantStateTracker;
300    @Mock WifiMetrics mWifiMetrics;
301
302    public WifiStateMachineTest() throws Exception {
303    }
304
305    @Before
306    public void setUp() throws Exception {
307        Log.d(TAG, "Setting up ...");
308
309        // Ensure looper exists
310        MockLooper looper = new MockLooper();
311
312        MockitoAnnotations.initMocks(this);
313
314        /** uncomment this to enable logs from WifiStateMachines */
315        // enableDebugLogs();
316
317        installWlanWifiNative(mWifiNative);
318        mWifiMonitor = new MockWifiMonitor();
319        mWifiMetrics = mock(WifiMetrics.class);
320        FrameworkFacade factory = getFrameworkFacade();
321        Context context = getContext();
322
323        Resources resources = getMockResources();
324        when(context.getResources()).thenReturn(resources);
325
326        when(factory.getIntegerSetting(context,
327                Settings.Global.WIFI_FREQUENCY_BAND,
328                WifiManager.WIFI_FREQUENCY_BAND_AUTO)).thenReturn(
329                WifiManager.WIFI_FREQUENCY_BAND_AUTO);
330
331        when(factory.makeApConfigStore(Mockito.eq(context)))
332                .thenCallRealMethod();
333
334        when(factory.makeSupplicantStateTracker(
335                any(Context.class), any(WifiStateMachine.class), any(WifiConfigStore.class),
336                any(Handler.class))).thenReturn(mSupplicantStateTracker);
337
338        mWsm = new WifiStateMachine(context, null, factory, mWifiMetrics);
339        mWsmThread = getWsmHandlerThread(mWsm);
340
341        final Object sync = new Object();
342        synchronized (sync) {
343            mSyncThread = new HandlerThread("SynchronizationThread");
344            final AsyncChannel channel = new AsyncChannel();
345            mSyncThread.start();
346            Handler handler = new Handler(mSyncThread.getLooper()) {
347                @Override
348                public void handleMessage(Message msg) {
349                    switch (msg.what) {
350                        case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED:
351                            if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
352                                mWsmAsyncChannel = channel;
353                                synchronized (sync) {
354                                    sync.notifyAll();
355                                    Log.d(TAG, "Successfully connected " + this);
356                                }
357                            } else {
358                                Log.d(TAG, "Failed to connect Command channel " + this);
359                            }
360                            break;
361                        case AsyncChannel.CMD_CHANNEL_DISCONNECTED:
362                            Log.d(TAG, "Command channel disconnected" + this);
363                            break;
364                    }
365                }
366            };
367
368            channel.connect(context, handler, mWsm.getMessenger());
369            sync.wait();
370        }
371
372        /* Now channel is supposed to be connected */
373    }
374
375    @After
376    public void cleanUp() throws Exception {
377
378        if (mSyncThread != null) stopLooper(mSyncThread.getLooper());
379        if (mWsmThread != null) stopLooper(mWsmThread.getLooper());
380        if (mP2pThread != null) stopLooper(mP2pThread.getLooper());
381
382        mWsmThread = null;
383        mP2pThread = null;
384        mSyncThread = null;
385        mWsmAsyncChannel = null;
386        mWsm = null;
387    }
388
389    @Test
390    public void createNew() throws Exception {
391        assertEquals("InitialState", getCurrentState().getName());
392
393        mWsm.sendMessage(WifiStateMachine.CMD_BOOT_COMPLETED);
394        wait(200);
395        assertEquals("InitialState", getCurrentState().getName());
396    }
397
398    @Test
399    public void loadComponents() throws Exception {
400
401        when(mWifiNative.loadDriver()).thenReturn(true);
402        when(mWifiNative.startHal()).thenReturn(true);
403        when(mWifiNative.startSupplicant(anyBoolean())).thenReturn(true);
404
405        mWsm.setSupplicantRunning(true);
406        wait(200);
407        assertEquals("SupplicantStartingState", getCurrentState().getName());
408
409        when(mWifiNative.setBand(anyInt())).thenReturn(true);
410        when(mWifiNative.setDeviceName(anyString())).thenReturn(true);
411        when(mWifiNative.setManufacturer(anyString())).thenReturn(true);
412        when(mWifiNative.setModelName(anyString())).thenReturn(true);
413        when(mWifiNative.setModelNumber(anyString())).thenReturn(true);
414        when(mWifiNative.setSerialNumber(anyString())).thenReturn(true);
415        when(mWifiNative.setConfigMethods(anyString())).thenReturn(true);
416        when(mWifiNative.setDeviceType(anyString())).thenReturn(true);
417        when(mWifiNative.setSerialNumber(anyString())).thenReturn(true);
418        when(mWifiNative.setScanningMacOui(any(byte[].class))).thenReturn(true);
419        when(mWifiNative.enableBackgroundScan(anyBoolean())).thenReturn(true);
420
421        mWsm.sendMessage(WifiMonitor.SUP_CONNECTION_EVENT);
422        wait(200);
423        assertEquals("DisconnectedState", getCurrentState().getName());
424    }
425
426    @Test
427    public void loadComponentsFailure() throws Exception {
428        when(mWifiNative.loadDriver()).thenReturn(false);
429        when(mWifiNative.startHal()).thenReturn(false);
430        when(mWifiNative.startSupplicant(anyBoolean())).thenReturn(false);
431
432        mWsm.setSupplicantRunning(true);
433        wait(200);
434        assertEquals("InitialState", getCurrentState().getName());
435
436        when(mWifiNative.loadDriver()).thenReturn(true);
437        mWsm.setSupplicantRunning(true);
438        wait(200);
439        assertEquals("InitialState", getCurrentState().getName());
440
441        when(mWifiNative.startHal()).thenReturn(true);
442        mWsm.setSupplicantRunning(true);
443        wait(200);
444        assertEquals("InitialState", getCurrentState().getName());
445    }
446
447    @Test
448    public void addNetwork() throws Exception {
449
450        loadComponents();
451
452        final HashMap<String, String> nameToValue = new HashMap<String, String>();
453
454        when(mWifiNative.addNetwork()).thenReturn(0);
455        when(mWifiNative.setNetworkVariable(anyInt(), anyString(), anyString()))
456                .then(new AnswerWithArguments<Boolean>() {
457                    public boolean answer(int netId, String name, String value) {
458                        if (netId != 0) {
459                            Log.d(TAG, "Can't set var " + name + " for " + netId);
460                            return false;
461                        }
462
463                        Log.d(TAG, "Setting var " + name + " to " + value + " for " + netId);
464                        nameToValue.put(name, value);
465                        return true;
466                    }
467                });
468
469        when(mWifiNative.setNetworkExtra(anyInt(), anyString(), (Map<String, String>) anyObject()))
470                .then(new AnswerWithArguments<Boolean>() {
471                    public boolean answer(int netId, String name, Map<String, String> values) {
472                        if (netId != 0) {
473                            Log.d(TAG, "Can't set extra " + name + " for " + netId);
474                            return false;
475                        }
476
477                        Log.d(TAG, "Setting extra for " + netId);
478                        return true;
479                    }
480                });
481
482        when(mWifiNative.getNetworkVariable(anyInt(), anyString()))
483                .then(new AnswerWithArguments<String>() {
484                    public String answer(int netId, String name) throws Throwable {
485                        if (netId != 0) {
486                            Log.d(TAG, "Can't find var " + name + " for " + netId);
487                            return null;
488                        }
489                        String value = nameToValue.get(name);
490                        if (value != null) {
491                            Log.d(TAG, "Returning var " + name + " to " + value + " for " + netId);
492                        } else {
493                            Log.d(TAG, "Can't find var " + name + " for " + netId);
494                        }
495                        return value;
496                    }
497                });
498
499        WifiConfiguration config = new WifiConfiguration();
500        config.SSID = sSSID;
501        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
502        mWsm.syncAddOrUpdateNetwork(mWsmAsyncChannel, config);
503        wait(200);
504
505        verify(mWifiNative).addNetwork();
506        verify(mWifiNative).setNetworkVariable(0, "ssid", sHexSSID);
507
508        List<WifiConfiguration> configs = mWsm.syncGetConfiguredNetworks(-1, mWsmAsyncChannel);
509        assertEquals(1, configs.size());
510
511        WifiConfiguration config2 = configs.get(0);
512        assertEquals("\"GoogleGuest\"", config2.SSID);
513        assertTrue(config2.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE));
514    }
515
516    @Test
517    public void scan() throws Exception {
518
519        addNetwork();
520
521        mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
522
523        mWsm.startScan(-1, 0, null, null);
524        wait(200);
525
526        verify(mWifiNative).scan(WifiNative.SCAN_WITHOUT_CONNECTION_SETUP, null);
527
528        when(mWifiNative.getScanResults()).thenReturn(getMockScanResults());
529        mWsm.sendMessage(WifiMonitor.SCAN_RESULTS_EVENT);
530
531        wait(200);
532        List<ScanResult> results = mWsm.syncGetScanResultsList();
533        assertEquals(8, results.size());
534    }
535
536    @Test
537    public void connect() throws Exception {
538
539        addNetwork();
540
541        mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
542        mWsm.syncEnableNetwork(mWsmAsyncChannel, 0, true);
543        wait(200);
544
545        verify(mWifiNative).enableNetwork(0, true);
546
547        mWsm.sendMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, sBSSID);
548        mWsm.sendMessage(WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT, 0, 0,
549                new StateChangeResult(0, sWifiSsid, sBSSID, SupplicantState.COMPLETED));
550        wait(200);
551
552        assertEquals("ObtainingIpState", getCurrentState().getName());
553
554        DhcpResults dhcpResults = new DhcpResults();
555        dhcpResults.setGateway("1.2.3.4");
556        dhcpResults.setIpAddress("192.168.1.100", 0);
557        dhcpResults.addDns("8.8.8.8");
558        dhcpResults.setLeaseDuration(3600);
559
560        mWsm.sendMessage(WifiStateMachine.CMD_IPV4_PROVISIONING_SUCCESS, 0, 0, dhcpResults);
561        wait(200);
562
563        assertEquals("ConnectedState", getCurrentState().getName());
564    }
565
566    @Test
567    public void testDhcpFailure() throws Exception {
568        addNetwork();
569
570        mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
571        mWsm.syncEnableNetwork(mWsmAsyncChannel, 0, true);
572        wait(200);
573
574        verify(mWifiNative).enableNetwork(0, true);
575
576        mWsm.sendMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, sBSSID);
577
578        mWsm.sendMessage(WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT, 0, 0,
579                new StateChangeResult(0, sWifiSsid, sBSSID, SupplicantState.COMPLETED));
580        wait(200);
581
582        assertEquals("ObtainingIpState", getCurrentState().getName());
583
584        mWsm.sendMessage(WifiStateMachine.CMD_IPV4_PROVISIONING_FAILURE, 0, 0, null);
585        wait(200);
586
587        assertEquals("DisconnectingState", getCurrentState().getName());
588    }
589
590    @Test
591    public void testBadNetworkEvent() throws Exception {
592        addNetwork();
593
594        mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
595        mWsm.syncEnableNetwork(mWsmAsyncChannel, 0, true);
596        wait(200);
597
598        verify(mWifiNative).enableNetwork(0, true);
599
600        mWsm.sendMessage(WifiMonitor.NETWORK_DISCONNECTION_EVENT, 0, 0, sBSSID);
601
602        mWsm.sendMessage(WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT, 0, 0,
603                new StateChangeResult(0, sWifiSsid, sBSSID, SupplicantState.COMPLETED));
604        wait(200);
605
606        assertEquals("DisconnectedState", getCurrentState().getName());
607    }
608
609
610    @Test
611    public void disconnect() throws Exception {
612        connect();
613
614        mWsm.sendMessage(WifiMonitor.NETWORK_DISCONNECTION_EVENT, -1, 3, "01:02:03:04:05:06");
615        mWsm.sendMessage(WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT, 0, 0,
616                new StateChangeResult(0, sWifiSsid, sBSSID, SupplicantState.DISCONNECTED));
617        wait(200);
618
619        assertEquals("DisconnectedState", getCurrentState().getName());
620    }
621
622    @Test
623    public void handleUserSwitch() throws Exception {
624        assertEquals(UserHandle.USER_SYSTEM, mWsm.getCurrentUserId());
625
626        mWsm.handleUserSwitch(10);
627        wait(200);
628
629        assertEquals(10, mWsm.getCurrentUserId());
630    }
631
632    @Test
633    public void iconQueryTest() throws Exception {
634        /* enable wi-fi */
635        addNetwork();
636
637        long bssid = 0x1234567800FFL;
638        String filename = "iconFileName.png";
639        String command = "REQ_HS20_ICON " + Utils.macToString(bssid) + " " + filename;
640
641        when(mWifiNative.doCustomSupplicantCommand(command)).thenReturn("OK");
642
643        boolean result = mWsm.syncQueryPasspointIcon(mWsmAsyncChannel, bssid, filename);
644
645        verify(mWifiNative).doCustomSupplicantCommand(command);
646        assertEquals(true, result);
647    }
648}
649