summaryrefslogtreecommitdiffstats
path: root/tests/wifitests/src/com/android/server/wifi/rtt/RttNativeTest.java
blob: 7bbe6bb79c62153bff5b8033c89bcc0e5d9fd29a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package com.android.server.wifi.rtt;

import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import android.hardware.wifi.V1_0.IWifiRttController;
import android.hardware.wifi.V1_0.RttBw;
import android.hardware.wifi.V1_0.RttCapabilities;
import android.hardware.wifi.V1_0.RttConfig;
import android.hardware.wifi.V1_0.RttPeerType;
import android.hardware.wifi.V1_0.RttPreamble;
import android.hardware.wifi.V1_0.RttResult;
import android.hardware.wifi.V1_0.RttStatus;
import android.hardware.wifi.V1_0.RttType;
import android.hardware.wifi.V1_0.WifiChannelWidthInMhz;
import android.hardware.wifi.V1_0.WifiStatus;
import android.hardware.wifi.V1_0.WifiStatusCode;
import android.net.MacAddress;
import android.net.wifi.rtt.RangingRequest;

import com.android.server.wifi.HalDeviceManager;

import org.hamcrest.core.IsNull;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ErrorCollector;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Unit test harness for the RttNative class.
 */
public class RttNativeTest {
    private RttNative mDut;
    private WifiStatus mStatusSuccess;
    private WifiStatus mStatusRttControllerInvalid;

    private ArgumentCaptor<ArrayList> mRttConfigCaptor = ArgumentCaptor.forClass(ArrayList.class);
    private ArgumentCaptor<List> mRttResultCaptor = ArgumentCaptor.forClass(List.class);
    private ArgumentCaptor<HalDeviceManager.ManagerStatusListener> mHdmStatusListener =
            ArgumentCaptor.forClass(HalDeviceManager.ManagerStatusListener.class);
    private ArgumentCaptor<IWifiRttController.getCapabilitiesCallback> mGetCapCbCatpr =
            ArgumentCaptor.forClass(IWifiRttController.getCapabilitiesCallback.class);

    @Rule
    public ErrorCollector collector = new ErrorCollector();

    @Mock
    public RttServiceImpl mockRttServiceImpl;

    @Mock
    public HalDeviceManager mockHalDeviceManager;

    @Mock
    public IWifiRttController mockRttController;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);

        when(mockHalDeviceManager.isStarted()).thenReturn(true);
        when(mockHalDeviceManager.createRttController()).thenReturn(mockRttController);

        mStatusSuccess = new WifiStatus();
        mStatusSuccess.code = WifiStatusCode.SUCCESS;
        when(mockRttController.registerEventCallback(any())).thenReturn(mStatusSuccess);
        when(mockRttController.rangeRequest(anyInt(), any(ArrayList.class))).thenReturn(
                mStatusSuccess);
        when(mockRttController.rangeCancel(anyInt(), any(ArrayList.class))).thenReturn(
                mStatusSuccess);

        mStatusRttControllerInvalid = new WifiStatus();
        mStatusRttControllerInvalid.code = WifiStatusCode.ERROR_WIFI_RTT_CONTROLLER_INVALID;

        mDut = new RttNative(mockRttServiceImpl, mockHalDeviceManager);
        mDut.start(null);
        verify(mockHalDeviceManager).registerStatusListener(mHdmStatusListener.capture(), any());
        verify(mockRttController).registerEventCallback(any());
        verify(mockRttServiceImpl).enableIfPossible();
        verify(mockRttController).getCapabilities(mGetCapCbCatpr.capture());
        // will override capabilities (just call cb again) for specific tests
        mGetCapCbCatpr.getValue().onValues(mStatusSuccess, getFullRttCapabilities());
        assertTrue(mDut.isReady());
    }

    /**
     * Validate successful ranging flow.
     */
    @Test
    public void testRangeRequest() throws Exception {
        int cmdId = 55;
        RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0);

        // (1) issue range request
        mDut.rangeRequest(cmdId, request, true);

        // (2) verify HAL call and parameters
        verify(mockRttController).rangeRequest(eq(cmdId), mRttConfigCaptor.capture());

        // verify contents of HAL request (hard codes knowledge from getDummyRangingRequest()).
        ArrayList<RttConfig> halRequest = mRttConfigCaptor.getValue();

        collector.checkThat("number of entries", halRequest.size(),
                equalTo(request.mRttPeers.size()));

        RttConfig rttConfig = halRequest.get(0);
        collector.checkThat("entry 0: MAC", rttConfig.addr,
                equalTo(MacAddress.fromString("00:01:02:03:04:00").toByteArray()));
        collector.checkThat("entry 0: rtt type", rttConfig.type, equalTo(RttType.TWO_SIDED));
        collector.checkThat("entry 0: peer type", rttConfig.peer, equalTo(RttPeerType.AP));
        collector.checkThat("entry 0: lci", rttConfig.mustRequestLci, equalTo(true));
        collector.checkThat("entry 0: lcr", rttConfig.mustRequestLcr, equalTo(true));

        rttConfig = halRequest.get(1);
        collector.checkThat("entry 1: MAC", rttConfig.addr,
                equalTo(MacAddress.fromString("0A:0B:0C:0D:0E:00").toByteArray()));
        collector.checkThat("entry 1: rtt type", rttConfig.type, equalTo(RttType.ONE_SIDED));
        collector.checkThat("entry 1: peer type", rttConfig.peer, equalTo(RttPeerType.AP));
        collector.checkThat("entry 1: lci", rttConfig.mustRequestLci, equalTo(true));
        collector.checkThat("entry 1: lcr", rttConfig.mustRequestLcr, equalTo(true));

        rttConfig = halRequest.get(2);
        collector.checkThat("entry 2: MAC", rttConfig.addr,
                equalTo(MacAddress.fromString("08:09:08:07:06:05").toByteArray()));
        collector.checkThat("entry 2: rtt type", rttConfig.type, equalTo(RttType.TWO_SIDED));
        collector.checkThat("entry 2: peer type", rttConfig.peer, equalTo(RttPeerType.NAN));
        collector.checkThat("entry 2: lci", rttConfig.mustRequestLci, equalTo(false));
        collector.checkThat("entry 2: lcr", rttConfig.mustRequestLcr, equalTo(false));

        verifyNoMoreInteractions(mockRttController, mockRttServiceImpl);
    }

    /**
     * Validate ranging request with a mix of Repsonders with and without IEEE 802.11mc support,
     * from a non- privileged context.
     */
    @Test
    public void testRangeRequestNotPrivilegedNo80211mcSupportMixed() throws Exception {
        int cmdId = 66;

        // the request has 3 responders: first AP support 802.11mc, second AP does not, third is
        // Aware (which supports 802.11mc by default)
        RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0);

        // (1) issue range request
        mDut.rangeRequest(cmdId, request, false);

        // (2) verify HAL call and parameters
        verify(mockRttController).rangeRequest(eq(cmdId), mRttConfigCaptor.capture());

        // verify contents of HAL request (hard codes knowledge from getDummyRangingRequest()).
        ArrayList<RttConfig> halRequest = mRttConfigCaptor.getValue();

        collector.checkThat("number of entries", halRequest.size(), equalTo(2));

        RttConfig rttConfig = halRequest.get(0);
        collector.checkThat("entry 0: MAC", rttConfig.addr,
                equalTo(MacAddress.fromString("00:01:02:03:04:00").toByteArray()));
        collector.checkThat("entry 0: rtt type", rttConfig.type, equalTo(RttType.TWO_SIDED));
        collector.checkThat("entry 0: peer type", rttConfig.peer, equalTo(RttPeerType.AP));
        collector.checkThat("entry 0: lci", rttConfig.mustRequestLci, equalTo(false));
        collector.checkThat("entry 0: lcr", rttConfig.mustRequestLcr, equalTo(false));

        rttConfig = halRequest.get(1);
        collector.checkThat("entry 1: MAC", rttConfig.addr,
                equalTo(MacAddress.fromString("08:09:08:07:06:05").toByteArray()));
        collector.checkThat("entry 1: rtt type", rttConfig.type, equalTo(RttType.TWO_SIDED));
        collector.checkThat("entry 1: peer type", rttConfig.peer, equalTo(RttPeerType.NAN));
        collector.checkThat("entry 1: lci", rttConfig.mustRequestLci, equalTo(false));
        collector.checkThat("entry 1: lcr", rttConfig.mustRequestLcr, equalTo(false));

        verifyNoMoreInteractions(mockRttController, mockRttServiceImpl);
    }

    /**
     * Validate successful ranging flow - with privileges access but with limited capabilities:
     * - No single-sided RTT
     * - No LCI/LCR
     * - Limited BW
     * - Limited Preamble
     */
    @Test
    public void testRangeRequestWithLimitedCapabilities() throws Exception {
        int cmdId = 55;
        RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0);

        // update capabilities to a limited set
        RttCapabilities cap = getFullRttCapabilities();
        cap.rttOneSidedSupported = false;
        cap.lciSupported = false;
        cap.lcrSupported = false;
        cap.bwSupport = RttBw.BW_10MHZ | RttBw.BW_160MHZ;
        cap.preambleSupport = RttPreamble.LEGACY;
        mGetCapCbCatpr.getValue().onValues(mStatusSuccess, cap);

        // Note: request 1: BW = 40MHz --> 10MHz, Preamble = HT (since 40MHz) -> Legacy

        // (1) issue range request
        mDut.rangeRequest(cmdId, request, true);

        // (2) verify HAL call and parameters
        verify(mockRttController).rangeRequest(eq(cmdId), mRttConfigCaptor.capture());

        // verify contents of HAL request (hard codes knowledge from getDummyRangingRequest()).
        ArrayList<RttConfig> halRequest = mRttConfigCaptor.getValue();

        collector.checkThat("number of entries", halRequest.size(), equalTo(2));

        RttConfig rttConfig = halRequest.get(0);
        collector.checkThat("entry 0: MAC", rttConfig.addr,
                equalTo(MacAddress.fromString("00:01:02:03:04:00").toByteArray()));
        collector.checkThat("entry 0: rtt type", rttConfig.type, equalTo(RttType.TWO_SIDED));
        collector.checkThat("entry 0: peer type", rttConfig.peer, equalTo(RttPeerType.AP));
        collector.checkThat("entry 0: lci", rttConfig.mustRequestLci, equalTo(false));
        collector.checkThat("entry 0: lcr", rttConfig.mustRequestLcr, equalTo(false));
        collector.checkThat("entry 0: channel.width", rttConfig.channel.width, equalTo(
                WifiChannelWidthInMhz.WIDTH_40));
        collector.checkThat("entry 0: bw", rttConfig.bw, equalTo(RttBw.BW_10MHZ));
        collector.checkThat("entry 0: preamble", rttConfig.preamble, equalTo(RttPreamble.LEGACY));

        rttConfig = halRequest.get(1);
        collector.checkThat("entry 1: MAC", rttConfig.addr,
                equalTo(MacAddress.fromString("08:09:08:07:06:05").toByteArray()));
        collector.checkThat("entry 1: rtt type", rttConfig.type, equalTo(RttType.TWO_SIDED));
        collector.checkThat("entry 1: peer type", rttConfig.peer, equalTo(RttPeerType.NAN));
        collector.checkThat("entry 1: lci", rttConfig.mustRequestLci, equalTo(false));
        collector.checkThat("entry 1: lcr", rttConfig.mustRequestLcr, equalTo(false));

        verifyNoMoreInteractions(mockRttController, mockRttServiceImpl);
    }

    /**
     * Validate successful ranging flow - with privileges access but with limited capabilities:
     * - Very limited BW
     * - Very limited Preamble
     */
    @Test
    public void testRangeRequestWithLimitedCapabilitiesNoOverlap() throws Exception {
        int cmdId = 55;
        RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0);

        // update capabilities to a limited set
        RttCapabilities cap = getFullRttCapabilities();
        cap.bwSupport = RttBw.BW_80MHZ;
        cap.preambleSupport = RttPreamble.VHT;
        mGetCapCbCatpr.getValue().onValues(mStatusSuccess, cap);

        // Note: request 1: BW = 40MHz --> no overlap -> dropped
        // Note: request 2: BW = 160MHz --> 160MHz, preamble = VHT (since 160MHz) -> no overlap,
        //                                                                           dropped

        // (1) issue range request
        mDut.rangeRequest(cmdId, request, true);

        // (2) verify HAL call and parameters
        verify(mockRttController).rangeRequest(eq(cmdId), mRttConfigCaptor.capture());

        // verify contents of HAL request (hard codes knowledge from getDummyRangingRequest()).
        ArrayList<RttConfig> halRequest = mRttConfigCaptor.getValue();

        collector.checkThat("number of entries", halRequest.size(), equalTo(1));

        RttConfig rttConfig = halRequest.get(0);
        collector.checkThat("entry 0: MAC", rttConfig.addr,
                equalTo(MacAddress.fromString("08:09:08:07:06:05").toByteArray()));
        collector.checkThat("entry 0: rtt type", rttConfig.type, equalTo(RttType.TWO_SIDED));
        collector.checkThat("entry 0: peer type", rttConfig.peer, equalTo(RttPeerType.NAN));
        collector.checkThat("entry 0: lci", rttConfig.mustRequestLci, equalTo(false));
        collector.checkThat("entry 0: lcr", rttConfig.mustRequestLcr, equalTo(false));

        verifyNoMoreInteractions(mockRttController, mockRttServiceImpl);
    }

    /**
     * Validate ranging request with all Repsonders without IEEE 802.11mc support, from a non-
     * privileged context.
     */
    @Test
    public void testRangeRequestNotPrivilegedNo80211mcSupportForAny() throws Exception {
        int cmdId = 77;
        RangingRequest request = RttTestUtils.getDummyRangingRequestNo80211mcSupport((byte) 0);

        // (1) issue range request
        mDut.rangeRequest(cmdId, request, false);

        // (2) verify immediate result callback (empty result set)
        verify(mockRttServiceImpl).onRangingResults(eq(cmdId), mRttResultCaptor.capture());

        collector.checkThat("Result set", mRttResultCaptor.getValue().size(), equalTo(0));

        verifyNoMoreInteractions(mockRttController, mockRttServiceImpl);
    }

    /**
     * Validate no range request when Wi-Fi is down
     */
    @Test
    public void testWifiDown() throws Exception {
        int cmdId = 55;
        RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0);

        InOrder order = inOrder(mockRttServiceImpl);

        // (1) configure Wi-Fi down and send a status change indication
        when(mockHalDeviceManager.isStarted()).thenReturn(false);
        mHdmStatusListener.getValue().onStatusChanged();
        order.verify(mockRttServiceImpl).disable();
        assertFalse(mDut.isReady());

        // (2) issue range request
        mDut.rangeRequest(cmdId, request, true);

        order.verify(mockRttServiceImpl).disable(); // due to re-init attempt
        verifyNoMoreInteractions(mockRttServiceImpl, mockRttController);
    }

    /**
     * Validate ranging cancel flow.
     */
    @Test
    public void testRangeCancel() throws Exception {
        int cmdId = 66;
        ArrayList<byte[]> macAddresses = new ArrayList<>();
        byte[] mac1 = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
        byte[] mac2 = {0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
        macAddresses.add(mac1);
        macAddresses.add(mac2);

        // (1) issue cancel request
        mDut.rangeCancel(cmdId, macAddresses);

        // (2) verify HAL call and parameters
        verify(mockRttController).rangeCancel(cmdId, macAddresses);

        verifyNoMoreInteractions(mockRttController);
    }

    /**
     * Validate correct result conversion from HAL to framework.
     */
    @Test
    public void testRangeResults() throws Exception {
        int cmdId = 55;
        ArrayList<RttResult> results = new ArrayList<>();
        RttResult res = new RttResult();
        res.addr[0] = 5;
        res.addr[1] = 6;
        res.addr[2] = 7;
        res.addr[3] = 8;
        res.addr[4] = 9;
        res.addr[5] = 10;
        res.status = RttStatus.SUCCESS;
        res.distanceInMm = 1500;
        res.timeStampInUs = 666;
        results.add(res);

        // (1) have HAL call native with results
        mDut.onResults(cmdId, results);

        // (2) verify call to framework
        verify(mockRttServiceImpl).onRangingResults(eq(cmdId), mRttResultCaptor.capture());

        // verify contents of the framework results
        List<RttResult> rttR = mRttResultCaptor.getValue();

        collector.checkThat("number of entries", rttR.size(), equalTo(1));

        RttResult rttResult = rttR.get(0);
        collector.checkThat("status", rttResult.status,
                equalTo(RttStatus.SUCCESS));
        collector.checkThat("mac", rttResult.addr,
                equalTo(MacAddress.fromString("05:06:07:08:09:0A").toByteArray()));
        collector.checkThat("distanceCm", rttResult.distanceInMm, equalTo(1500));
        collector.checkThat("timestamp", rttResult.timeStampInUs, equalTo(666L));

        verifyNoMoreInteractions(mockRttController, mockRttServiceImpl);
    }

    /**
     * Validate correct cleanup when a null array of results is provided by HAL.
     */
    @Test
    public void testRangeResultsNullArray() {
        int cmdId = 66;

        mDut.onResults(cmdId, null);
        verify(mockRttServiceImpl).onRangingResults(eq(cmdId), mRttResultCaptor.capture());

        collector.checkThat("number of entries", mRttResultCaptor.getValue().size(), equalTo(0));
    }

    /**
     * Validate correct cleanup when an array of results containing null entries is provided by HAL.
     */
    @Test
    public void testRangeResultsSomeNulls() {
        int cmdId = 77;

        ArrayList<RttResult> results = new ArrayList<>();
        results.add(null);
        results.add(new RttResult());
        results.add(null);
        results.add(null);
        results.add(new RttResult());
        results.add(null);

        mDut.onResults(cmdId, results);
        verify(mockRttServiceImpl).onRangingResults(eq(cmdId), mRttResultCaptor.capture());

        List<RttResult> rttR = mRttResultCaptor.getValue();
        collector.checkThat("number of entries", rttR.size(), equalTo(2));
        for (int i = 0; i < rttR.size(); ++i) {
            collector.checkThat("entry", rttR.get(i), IsNull.notNullValue());
        }
    }

    /**
     * Validate correct re-initialization when the RTT Controller is invalid (which can happen
     * due to mode change in the HAL). Expect a re-initialization and a rerun of the range request.
     */
    @Test
    public void testRangeRequestInvalidRttControllerOnce() throws Exception {
        int cmdId = 55;
        RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0);

        InOrder inOrder = Mockito.inOrder(mockRttController);

        // configure failure then success
        when(mockRttController.rangeRequest(anyInt(), any(ArrayList.class))).thenReturn(
                mStatusRttControllerInvalid).thenReturn(mStatusSuccess);

        // issue range request
        boolean result = mDut.rangeRequest(cmdId, request, true);
        assertTrue("rangeRequest should succeeed", result);

        // verify HAL call
        inOrder.verify(mockRttController).rangeRequest(eq(cmdId), mRttConfigCaptor.capture());
        ArrayList<RttConfig> halRequest1 = mRttConfigCaptor.getValue();

        // verify re-initialization (i.e. callback re-registered)
        inOrder.verify(mockRttController).registerEventCallback(any());

        // verify HAL call
        inOrder.verify(mockRttController).rangeRequest(eq(cmdId), mRttConfigCaptor.capture());
        ArrayList<RttConfig> halRequest2 = mRttConfigCaptor.getValue();

        assertTrue("HAL parameters different between calls!",
                Arrays.equals(halRequest1.toArray(), halRequest2.toArray()));
        verifyNoMoreInteractions(mockRttController);
    }

    /**
     * Validate correct re-initialization when the RTT Controller is invalid (which can happen
     * due to mode change in the HAL). Expect a re-initialization and a rerun of the range request -
     * but only once (no infinite loop).
     */
    @Test
    public void testRangeRequestInvalidRttControllerForever() throws Exception {
        int cmdId = 55;
        RangingRequest request = RttTestUtils.getDummyRangingRequest((byte) 0);

        InOrder inOrder = Mockito.inOrder(mockRttController);

        // configure failure
        when(mockRttController.rangeRequest(anyInt(), any(ArrayList.class))).thenReturn(
                mStatusRttControllerInvalid);

        // issue range request
        boolean result = mDut.rangeRequest(cmdId, request, true);
        assertFalse("rangeRequest should fail", result);

        // verify HAL call
        inOrder.verify(mockRttController).rangeRequest(eq(cmdId), mRttConfigCaptor.capture());
        ArrayList<RttConfig> halRequest1 = mRttConfigCaptor.getValue();

        // verify re-initialization (i.e. callback re-registered)
        inOrder.verify(mockRttController).registerEventCallback(any());

        // verify HAL call
        inOrder.verify(mockRttController).rangeRequest(eq(cmdId), mRttConfigCaptor.capture());
        ArrayList<RttConfig> halRequest2 = mRttConfigCaptor.getValue();

        assertTrue("HAL parameters different between calls!",
                Arrays.equals(halRequest1.toArray(), halRequest2.toArray()));
        verifyNoMoreInteractions(mockRttController);
    }

    // Utilities

    /**
     * Return an RttCapabilities structure with all features enabled and support for all
     * preambles and bandwidths. The purpose is to enable any request. The returned structure can
     * then be modified to disable specific features.
     */
    RttCapabilities getFullRttCapabilities() {
        RttCapabilities cap = new RttCapabilities();

        cap.rttOneSidedSupported = true;
        cap.rttFtmSupported = true;
        cap.lciSupported = true;
        cap.lcrSupported = true;
        cap.responderSupported = true; // unused
        cap.preambleSupport = RttPreamble.LEGACY | RttPreamble.HT | RttPreamble.VHT;
        cap.bwSupport =
                RttBw.BW_5MHZ | RttBw.BW_10MHZ | RttBw.BW_20MHZ | RttBw.BW_40MHZ | RttBw.BW_80MHZ
                        | RttBw.BW_160MHZ;
        cap.mcVersion = 1; // unused

        return cap;
    }
}