162bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius/*
262bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius * Copyright (C) 2016 The Android Open Source Project
362bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius *
462bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius * Licensed under the Apache License, Version 2.0 (the "License");
562bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius * you may not use this file except in compliance with the License.
662bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius * You may obtain a copy of the License at
762bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius *
862bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius *      http://www.apache.org/licenses/LICENSE-2.0
962bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius *
1062bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius * Unless required by applicable law or agreed to in writing, software
1162bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius * distributed under the License is distributed on an "AS IS" BASIS,
1262bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1362bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius * See the License for the specific language governing permissions and
14a8367288377cbaed6371256ca837b7aa22280706Mitchell Wills * limitations under the License.
1562bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius */
1662bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
17a8367288377cbaed6371256ca837b7aa22280706Mitchell Willspackage com.android.server.wifi.scanner;
1862bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
19e7ba2963bedf426a1d8ba09ab535260ef364512bRoshan Piusimport static com.android.server.wifi.ScanTestUtil.NativeScanSettingsBuilder;
20da410c9b2c5ea87abb5939c27d127cc64936242fNingyuan Wangimport static com.android.server.wifi.ScanTestUtil.setupMockChannels;
21e7ba2963bedf426a1d8ba09ab535260ef364512bRoshan Pius
22e7ba2963bedf426a1d8ba09ab535260ef364512bRoshan Piusimport static org.junit.Assert.*;
23e7ba2963bedf426a1d8ba09ab535260ef364512bRoshan Piusimport static org.mockito.Mockito.*;
24e7ba2963bedf426a1d8ba09ab535260ef364512bRoshan Pius
25f4267b6840dbc7f430638c35c5448187b6e83846Christopher Wileyimport android.app.test.TestAlarmManager;
2662bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Piusimport android.content.Context;
2762bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Piusimport android.net.wifi.WifiScanner;
28ee0ab818341d44614ffe56ae73ecc08b974c2cbbRoshan Piusimport android.os.SystemClock;
296259b630ddb59b642729a2d2113d81ed8e33a0e3Roshan Piusimport android.os.test.TestLooper;
307f2a1e30dd5d14320ffc7b185ac25fdb79fe52b0Etan Cohenimport android.support.test.filters.SmallTest;
3162bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
3262bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Piusimport com.android.internal.R;
33ee0ab818341d44614ffe56ae73ecc08b974c2cbbRoshan Piusimport com.android.server.wifi.Clock;
34a8367288377cbaed6371256ca837b7aa22280706Mitchell Willsimport com.android.server.wifi.MockResources;
35a8367288377cbaed6371256ca837b7aa22280706Mitchell Willsimport com.android.server.wifi.MockWifiMonitor;
36a8367288377cbaed6371256ca837b7aa22280706Mitchell Willsimport com.android.server.wifi.ScanResults;
37a8367288377cbaed6371256ca837b7aa22280706Mitchell Willsimport com.android.server.wifi.WifiMonitor;
38a8367288377cbaed6371256ca837b7aa22280706Mitchell Willsimport com.android.server.wifi.WifiNative;
3962bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Piusimport com.android.server.wifi.scanner.ChannelHelper.ChannelCollection;
4062bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
4162bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Piusimport org.junit.Before;
4262bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Piusimport org.junit.Test;
4362bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Piusimport org.mockito.InOrder;
4462bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Piusimport org.mockito.Mock;
4562bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Piusimport org.mockito.MockitoAnnotations;
4662bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
4762bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Piusimport java.util.Set;
4862bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
4962bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius/**
5005d51a2d8eb67ea2eaf4cae43280d1cf9fe92645Ningyuan Wang * Unit tests for {@link com.android.server.wifi.scanner.WificondScannerImpl.setPnoList}.
5162bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius */
5262bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius@SmallTest
5305d51a2d8eb67ea2eaf4cae43280d1cf9fe92645Ningyuan Wangpublic class WificondPnoScannerTest {
5452ed1731664f7e0b76adb14eec7a76eaa95144c3Roshan Pius    private static final String IFACE_NAME = "a_test_interface_name";
5562bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
5662bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    @Mock Context mContext;
57f4267b6840dbc7f430638c35c5448187b6e83846Christopher Wiley    TestAlarmManager mAlarmManager;
5862bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    MockWifiMonitor mWifiMonitor;
59f4267b6840dbc7f430638c35c5448187b6e83846Christopher Wiley    TestLooper mLooper;
6062bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    @Mock WifiNative mWifiNative;
6162bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    MockResources mResources;
62ee0ab818341d44614ffe56ae73ecc08b974c2cbbRoshan Pius    @Mock Clock mClock;
6305d51a2d8eb67ea2eaf4cae43280d1cf9fe92645Ningyuan Wang    WificondScannerImpl mScanner;
6462bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
6562bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    @Before
6662bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    public void setup() throws Exception {
6762bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        MockitoAnnotations.initMocks(this);
6862bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
69f4267b6840dbc7f430638c35c5448187b6e83846Christopher Wiley        mLooper = new TestLooper();
70f4267b6840dbc7f430638c35c5448187b6e83846Christopher Wiley        mAlarmManager = new TestAlarmManager();
7162bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        mWifiMonitor = new MockWifiMonitor();
7262bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        mResources = new MockResources();
7362bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
74da410c9b2c5ea87abb5939c27d127cc64936242fNingyuan Wang        setupMockChannels(mWifiNative,
75da410c9b2c5ea87abb5939c27d127cc64936242fNingyuan Wang                new int[]{2400, 2450},
76da410c9b2c5ea87abb5939c27d127cc64936242fNingyuan Wang                new int[]{5150, 5175},
77da410c9b2c5ea87abb5939c27d127cc64936242fNingyuan Wang                new int[]{5600, 5650});
78da410c9b2c5ea87abb5939c27d127cc64936242fNingyuan Wang
7952ed1731664f7e0b76adb14eec7a76eaa95144c3Roshan Pius        when(mWifiNative.getClientInterfaceName()).thenReturn(IFACE_NAME);
8062bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        when(mContext.getSystemService(Context.ALARM_SERVICE))
8162bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius                .thenReturn(mAlarmManager.getAlarmManager());
8262bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        when(mContext.getResources()).thenReturn(mResources);
835de29ec72c54cb73fdc1b59072f66a2627b8764cNingyuan Wang        when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime());
8462bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    }
8562bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
8662bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    /**
8705d51a2d8eb67ea2eaf4cae43280d1cf9fe92645Ningyuan Wang     * Verify that the HW disconnected PNO scan triggers a wificond PNO scan and invokes the
886c5018cef1eb7acbcfa7fc6c9b7c018bab7ba7baRoshan Pius     * OnPnoNetworkFound callback when the scan results are received.
8962bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius     */
9062bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    @Test
91dcd877d6c143db557884993ea437e2a432cb0ba3Roshan Pius    public void startHwDisconnectedPnoScan() {
9262bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        createScannerWithHwPnoScanSupport();
9362bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
9462bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        WifiNative.PnoEventHandler pnoEventHandler = mock(WifiNative.PnoEventHandler.class);
95dcd877d6c143db557884993ea437e2a432cb0ba3Roshan Pius        WifiNative.PnoSettings pnoSettings = createDummyPnoSettings(false);
963219e97566a093ed10b2a9d6fe77ed9089084d63Mitchell Wills        ScanResults scanResults = createDummyScanResults(false);
9762bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
9862bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        InOrder order = inOrder(pnoEventHandler, mWifiNative);
9962bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        // Start PNO scan
10062bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        startSuccessfulPnoScan(null, pnoSettings, null, pnoEventHandler);
101dcd877d6c143db557884993ea437e2a432cb0ba3Roshan Pius        expectSuccessfulHwDisconnectedPnoScan(order, pnoSettings, pnoEventHandler, scanResults);
10262bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        verifyNoMoreInteractions(pnoEventHandler);
10362bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    }
10462bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
10562bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    /**
106e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius     * Verify that the HW PNO scan stop failure still resets the PNO scan state.
107e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius     * 1. Start Hw PNO.
108e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius     * 2. Stop Hw PNO scan which raises a stop command to WifiNative which is failed.
109e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius     * 3. Now restart a new PNO scan to ensure that the failure was cleanly handled.
110e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius     */
111e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius    @Test
112e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius    public void ignoreHwDisconnectedPnoScanStopFailure() {
113e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius        createScannerWithHwPnoScanSupport();
114e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius
115e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius        WifiNative.PnoEventHandler pnoEventHandler = mock(WifiNative.PnoEventHandler.class);
116e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius        WifiNative.PnoSettings pnoSettings = createDummyPnoSettings(false);
117e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius
118e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius        // Start PNO scan
119e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius        startSuccessfulPnoScan(null, pnoSettings, null, pnoEventHandler);
120e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius
121e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius        // Fail the PNO stop.
12252ed1731664f7e0b76adb14eec7a76eaa95144c3Roshan Pius        when(mWifiNative.stopPnoScan(IFACE_NAME)).thenReturn(false);
123e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius        assertTrue(mScanner.resetHwPnoList());
124e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius        mLooper.dispatchAll();
12552ed1731664f7e0b76adb14eec7a76eaa95144c3Roshan Pius        verify(mWifiNative).stopPnoScan(IFACE_NAME);
126e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius
127e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius        // Add a new PNO scan request and ensure it runs successfully.
128e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius        startSuccessfulPnoScan(null, pnoSettings, null, pnoEventHandler);
129e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius        mLooper.dispatchAll();
130e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius        InOrder order = inOrder(pnoEventHandler, mWifiNative);
1313219e97566a093ed10b2a9d6fe77ed9089084d63Mitchell Wills        ScanResults scanResults = createDummyScanResults(false);
132e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius        expectSuccessfulHwDisconnectedPnoScan(order, pnoSettings, pnoEventHandler, scanResults);
133e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius        verifyNoMoreInteractions(pnoEventHandler);
134e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius    }
135e483fd4a3151e59b3d0a596572b4d9f035fa8424Roshan Pius
13662bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    private void createScannerWithHwPnoScanSupport() {
13762bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        mResources.setBoolean(R.bool.config_wifi_background_scan_support, true);
138ec5fc620a38900385d7509d66a6eb75401eafeb4Roshan Pius        mScanner = new WificondScannerImpl(mContext, IFACE_NAME, mWifiNative, mWifiMonitor,
139da410c9b2c5ea87abb5939c27d127cc64936242fNingyuan Wang                new WificondChannelHelper(mWifiNative), mLooper.getLooper(), mClock);
14062bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    }
14162bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
1426259b630ddb59b642729a2d2113d81ed8e33a0e3Roshan Pius    private WifiNative.PnoNetwork createDummyPnoNetwork(String ssid) {
1431bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius        WifiNative.PnoNetwork pnoNetwork = new WifiNative.PnoNetwork();
1441bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius        pnoNetwork.ssid = ssid;
1451bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius        return pnoNetwork;
1461bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius    }
1471bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius
148dcd877d6c143db557884993ea437e2a432cb0ba3Roshan Pius    private WifiNative.PnoSettings createDummyPnoSettings(boolean isConnected) {
14962bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        WifiNative.PnoSettings pnoSettings = new WifiNative.PnoSettings();
150dcd877d6c143db557884993ea437e2a432cb0ba3Roshan Pius        pnoSettings.isConnected = isConnected;
15162bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        pnoSettings.networkList = new WifiNative.PnoNetwork[2];
1526259b630ddb59b642729a2d2113d81ed8e33a0e3Roshan Pius        pnoSettings.networkList[0] = createDummyPnoNetwork("ssid_pno_1");
1536259b630ddb59b642729a2d2113d81ed8e33a0e3Roshan Pius        pnoSettings.networkList[1] = createDummyPnoNetwork("ssid_pno_2");
15462bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        return pnoSettings;
15562bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    }
15662bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
157da410c9b2c5ea87abb5939c27d127cc64936242fNingyuan Wang    private WifiNative.ScanSettings createDummyScanSettings(boolean allChannelsScanned) {
15862bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        WifiNative.ScanSettings settings = new NativeScanSettingsBuilder()
15962bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius                .withBasePeriod(10000)
16062bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius                .withMaxApPerScan(10)
161da410c9b2c5ea87abb5939c27d127cc64936242fNingyuan Wang                .addBucketWithBand(
162da410c9b2c5ea87abb5939c27d127cc64936242fNingyuan Wang                    10000,
163da410c9b2c5ea87abb5939c27d127cc64936242fNingyuan Wang                    WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN,
164da410c9b2c5ea87abb5939c27d127cc64936242fNingyuan Wang                    allChannelsScanned
165da410c9b2c5ea87abb5939c27d127cc64936242fNingyuan Wang                            ? WifiScanner.WIFI_BAND_BOTH_WITH_DFS : WifiScanner.WIFI_BAND_24_GHZ)
16662bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius                .build();
16762bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        return settings;
16862bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    }
16962bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
1703219e97566a093ed10b2a9d6fe77ed9089084d63Mitchell Wills    private ScanResults createDummyScanResults(boolean allChannelsScanned) {
1713219e97566a093ed10b2a9d6fe77ed9089084d63Mitchell Wills        return ScanResults.create(0, allChannelsScanned, 2400, 2450, 2450, 2400, 2450, 2450, 2400,
1723219e97566a093ed10b2a9d6fe77ed9089084d63Mitchell Wills                2450, 2450);
17362bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    }
17462bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
17562bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    private void startSuccessfulPnoScan(WifiNative.ScanSettings scanSettings,
17662bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius            WifiNative.PnoSettings pnoSettings, WifiNative.ScanEventHandler scanEventHandler,
17762bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius            WifiNative.PnoEventHandler pnoEventHandler) {
17862bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        // Scans succeed
1793feac6fe9249c1b7bf284c7a9bfa65a86b973154Roshan Pius        when(mWifiNative.scan(eq(IFACE_NAME), anyInt(), any(), any(Set.class))).thenReturn(true);
18052ed1731664f7e0b76adb14eec7a76eaa95144c3Roshan Pius        when(mWifiNative.startPnoScan(eq(IFACE_NAME), any(WifiNative.PnoSettings.class)))
18152ed1731664f7e0b76adb14eec7a76eaa95144c3Roshan Pius                .thenReturn(true);
18252ed1731664f7e0b76adb14eec7a76eaa95144c3Roshan Pius        when(mWifiNative.stopPnoScan(IFACE_NAME)).thenReturn(true);
1836c5018cef1eb7acbcfa7fc6c9b7c018bab7ba7baRoshan Pius
18451fbc84e4424c637a50ffeb6dde78d11d743be21Ningyuan Wang        assertTrue(mScanner.setHwPnoList(pnoSettings, pnoEventHandler));
18562bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    }
18662bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
18762bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    private Set<Integer> expectedBandScanFreqs(int band) {
18862bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        ChannelCollection collection = mScanner.getChannelHelper().createChannelCollection();
18962bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        collection.addBand(band);
1909dc9a8750ecd1ab25c5b4c7d17c8930ca2ffb6c3Ningyuan Wang        return collection.getScanFreqs();
19162bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    }
19262bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
19362bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    /**
19462bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius     * Verify that the PNO scan was successfully started.
19562bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius     */
1961bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius    private void expectHwDisconnectedPnoScanStart(InOrder order,
1971bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius            WifiNative.PnoSettings pnoSettings) {
19862bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        // Verify  HW PNO scan started
19952ed1731664f7e0b76adb14eec7a76eaa95144c3Roshan Pius        order.verify(mWifiNative).startPnoScan(any(), any(WifiNative.PnoSettings.class));
2001bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius    }
2011bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius
2021bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius    /**
2031bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius     *
2041bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius     * 1. Verify that the PNO scan was successfully started.
2051bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius     * 2. Send scan results and ensure that the |onPnoNetworkFound| callback was called.
2061bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius     */
2071bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius    private void expectSuccessfulHwDisconnectedPnoScan(InOrder order,
2081bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius            WifiNative.PnoSettings pnoSettings, WifiNative.PnoEventHandler eventHandler,
2091bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius            ScanResults scanResults) {
2101bf983a4211f547593a60523e43112ecdb5c8997Roshan Pius        expectHwDisconnectedPnoScanStart(order, pnoSettings);
21162bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
21262bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        // Setup scan results
21352ed1731664f7e0b76adb14eec7a76eaa95144c3Roshan Pius        when(mWifiNative.getPnoScanResults(IFACE_NAME))
21452ed1731664f7e0b76adb14eec7a76eaa95144c3Roshan Pius                .thenReturn(scanResults.getScanDetailArrayList());
21552ed1731664f7e0b76adb14eec7a76eaa95144c3Roshan Pius        when(mWifiNative.getScanResults(IFACE_NAME))
21652ed1731664f7e0b76adb14eec7a76eaa95144c3Roshan Pius                .thenReturn(scanResults.getScanDetailArrayList());
21762bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
21862bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        // Notify scan has finished
21952ed1731664f7e0b76adb14eec7a76eaa95144c3Roshan Pius        mWifiMonitor.sendMessage(IFACE_NAME, WifiMonitor.PNO_SCAN_RESULTS_EVENT);
22062bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        assertEquals("dispatch message after results event", 1, mLooper.dispatchAll());
22162bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
22262bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius        order.verify(eventHandler).onPnoNetworkFound(scanResults.getRawScanResults());
22362bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius    }
22462bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius
22562bc101940ae1f5e60c4d8861a149b900dbf5e5cRoshan Pius}
226