• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.server.vcn.routeselection;
18 
19 import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_FORBIDDEN;
20 import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_REQUIRED;
21 import static android.net.vcn.VcnUnderlyingNetworkTemplateTestBase.TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS;
22 import static android.net.vcn.VcnUnderlyingNetworkTemplateTestBase.TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS;
23 import static android.net.vcn.VcnUnderlyingNetworkTemplateTestBase.TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS;
24 import static android.net.vcn.VcnUnderlyingNetworkTemplateTestBase.TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS;
25 
26 import static com.android.server.vcn.VcnTestUtils.setupSystemService;
27 import static com.android.server.vcn.routeselection.NetworkPriorityClassifier.PRIORITY_ANY;
28 import static com.android.server.vcn.routeselection.NetworkPriorityClassifier.calculatePriorityClass;
29 import static com.android.server.vcn.routeselection.NetworkPriorityClassifier.checkMatchesCellPriorityRule;
30 import static com.android.server.vcn.routeselection.NetworkPriorityClassifier.checkMatchesPriorityRule;
31 import static com.android.server.vcn.routeselection.NetworkPriorityClassifier.checkMatchesWifiPriorityRule;
32 import static com.android.server.vcn.routeselection.UnderlyingNetworkControllerTest.getLinkPropertiesWithName;
33 import static com.android.server.vcn.util.PersistableBundleUtils.PersistableBundleWrapper;
34 
35 import static org.junit.Assert.assertEquals;
36 import static org.junit.Assert.assertFalse;
37 import static org.junit.Assert.assertTrue;
38 import static org.mockito.Mockito.doNothing;
39 import static org.mockito.Mockito.mock;
40 import static org.mockito.Mockito.spy;
41 import static org.mockito.Mockito.when;
42 
43 import android.content.Context;
44 import android.net.LinkProperties;
45 import android.net.Network;
46 import android.net.NetworkCapabilities;
47 import android.net.TelephonyNetworkSpecifier;
48 import android.net.vcn.VcnCellUnderlyingNetworkTemplate;
49 import android.net.vcn.VcnGatewayConnectionConfig;
50 import android.net.vcn.VcnManager;
51 import android.net.vcn.VcnWifiUnderlyingNetworkTemplate;
52 import android.os.ParcelUuid;
53 import android.os.PersistableBundle;
54 import android.os.test.TestLooper;
55 import android.telephony.TelephonyManager;
56 import android.util.ArraySet;
57 
58 import com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscriptionSnapshot;
59 import com.android.server.vcn.VcnContext;
60 import com.android.server.vcn.VcnNetworkProvider;
61 
62 import org.junit.Before;
63 import org.junit.Test;
64 import org.mockito.Mock;
65 import org.mockito.MockitoAnnotations;
66 
67 import java.util.Set;
68 import java.util.UUID;
69 
70 public class NetworkPriorityClassifierTest {
71     private static final String SSID = "TestWifi";
72     private static final String SSID_OTHER = "TestWifiOther";
73     private static final String PLMN_ID = "123456";
74     private static final String PLMN_ID_OTHER = "234567";
75 
76     private static final int SUB_ID = 1;
77     private static final int WIFI_RSSI = -60;
78     private static final int WIFI_RSSI_HIGH = -50;
79     private static final int WIFI_RSSI_LOW = -80;
80     private static final int CARRIER_ID = 1;
81     private static final int CARRIER_ID_OTHER = 2;
82 
83     private static final int LINK_UPSTREAM_BANDWIDTH_KBPS = 1024;
84     private static final int LINK_DOWNSTREAM_BANDWIDTH_KBPS = 2048;
85 
86     private static final int TEST_MIN_UPSTREAM_BANDWIDTH_KBPS = 100;
87     private static final int TEST_MIN_DOWNSTREAM_BANDWIDTH_KBPS = 200;
88 
89     private static final ParcelUuid SUB_GROUP = new ParcelUuid(new UUID(0, 0));
90 
91     private static final NetworkCapabilities WIFI_NETWORK_CAPABILITIES =
92             new NetworkCapabilities.Builder()
93                     .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
94                     .setSignalStrength(WIFI_RSSI)
95                     .setSsid(SSID)
96                     .setLinkUpstreamBandwidthKbps(LINK_UPSTREAM_BANDWIDTH_KBPS)
97                     .setLinkDownstreamBandwidthKbps(LINK_DOWNSTREAM_BANDWIDTH_KBPS)
98                     .build();
99 
100     private static final TelephonyNetworkSpecifier TEL_NETWORK_SPECIFIER =
101             new TelephonyNetworkSpecifier.Builder().setSubscriptionId(SUB_ID).build();
102     private static final NetworkCapabilities CELL_NETWORK_CAPABILITIES =
103             new NetworkCapabilities.Builder()
104                     .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
105                     .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
106                     .setSubscriptionIds(Set.of(SUB_ID))
107                     .setNetworkSpecifier(TEL_NETWORK_SPECIFIER)
108                     .setLinkUpstreamBandwidthKbps(LINK_UPSTREAM_BANDWIDTH_KBPS)
109                     .setLinkDownstreamBandwidthKbps(LINK_DOWNSTREAM_BANDWIDTH_KBPS)
110                     .build();
111 
112     private static final LinkProperties LINK_PROPERTIES = getLinkPropertiesWithName("test_iface");
113 
114     @Mock private Network mNetwork;
115     @Mock private TelephonySubscriptionSnapshot mSubscriptionSnapshot;
116     @Mock private TelephonyManager mTelephonyManager;
117 
118     private TestLooper mTestLooper;
119     private VcnContext mVcnContext;
120     private UnderlyingNetworkRecord mWifiNetworkRecord;
121     private UnderlyingNetworkRecord mCellNetworkRecord;
122 
123     @Before
setUp()124     public void setUp() {
125         MockitoAnnotations.initMocks(this);
126 
127         final Context mockContext = mock(Context.class);
128         mTestLooper = new TestLooper();
129         mVcnContext =
130                 spy(
131                         new VcnContext(
132                                 mockContext,
133                                 mTestLooper.getLooper(),
134                                 mock(VcnNetworkProvider.class),
135                                 false /* isInTestMode */));
136         doNothing().when(mVcnContext).ensureRunningOnLooperThread();
137 
138         mWifiNetworkRecord =
139                 new UnderlyingNetworkRecord(
140                         mNetwork,
141                         WIFI_NETWORK_CAPABILITIES,
142                         LINK_PROPERTIES,
143                         false /* isBlocked */);
144 
145         mCellNetworkRecord =
146                 new UnderlyingNetworkRecord(
147                         mNetwork,
148                         CELL_NETWORK_CAPABILITIES,
149                         LINK_PROPERTIES,
150                         false /* isBlocked */);
151 
152         setupSystemService(
153                 mockContext, mTelephonyManager, Context.TELEPHONY_SERVICE, TelephonyManager.class);
154         when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager);
155         when(mTelephonyManager.getNetworkOperator()).thenReturn(PLMN_ID);
156         when(mTelephonyManager.getSimSpecificCarrierId()).thenReturn(CARRIER_ID);
157     }
158 
159     @Test
testMatchWithoutNotMeteredBit()160     public void testMatchWithoutNotMeteredBit() {
161         final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority =
162                 new VcnWifiUnderlyingNetworkTemplate.Builder()
163                         .setMetered(MATCH_FORBIDDEN)
164                         .build();
165 
166         assertFalse(
167                 checkMatchesPriorityRule(
168                         mVcnContext,
169                         wifiNetworkPriority,
170                         mWifiNetworkRecord,
171                         SUB_GROUP,
172                         mSubscriptionSnapshot,
173                         null /* currentlySelecetd */,
174                         null /* carrierConfig */));
175     }
176 
verifyMatchesPriorityRuleForUpstreamBandwidth( int entryUpstreamBandwidth, int exitUpstreamBandwidth, UnderlyingNetworkRecord currentlySelected, boolean expectMatch)177     private void verifyMatchesPriorityRuleForUpstreamBandwidth(
178             int entryUpstreamBandwidth,
179             int exitUpstreamBandwidth,
180             UnderlyingNetworkRecord currentlySelected,
181             boolean expectMatch) {
182         final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority =
183                 new VcnWifiUnderlyingNetworkTemplate.Builder()
184                         .setMinUpstreamBandwidthKbps(entryUpstreamBandwidth, exitUpstreamBandwidth)
185                         .build();
186 
187         assertEquals(
188                 expectMatch,
189                 checkMatchesPriorityRule(
190                         mVcnContext,
191                         wifiNetworkPriority,
192                         mWifiNetworkRecord,
193                         SUB_GROUP,
194                         mSubscriptionSnapshot,
195                         currentlySelected,
196                         null /* carrierConfig */));
197     }
198 
verifyMatchesPriorityRuleForDownstreamBandwidth( int entryDownstreamBandwidth, int exitDownstreamBandwidth, UnderlyingNetworkRecord currentlySelected, boolean expectMatch)199     private void verifyMatchesPriorityRuleForDownstreamBandwidth(
200             int entryDownstreamBandwidth,
201             int exitDownstreamBandwidth,
202             UnderlyingNetworkRecord currentlySelected,
203             boolean expectMatch) {
204         final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority =
205                 new VcnWifiUnderlyingNetworkTemplate.Builder()
206                         .setMinDownstreamBandwidthKbps(
207                                 entryDownstreamBandwidth, exitDownstreamBandwidth)
208                         .build();
209 
210         assertEquals(
211                 expectMatch,
212                 checkMatchesPriorityRule(
213                         mVcnContext,
214                         wifiNetworkPriority,
215                         mWifiNetworkRecord,
216                         SUB_GROUP,
217                         mSubscriptionSnapshot,
218                         currentlySelected,
219                         null /* carrierConfig */));
220     }
221 
222     @Test
testMatchWithEntryUpstreamBandwidthEquals()223     public void testMatchWithEntryUpstreamBandwidthEquals() {
224         verifyMatchesPriorityRuleForUpstreamBandwidth(
225                 TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS,
226                 TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS,
227                 null /* currentlySelected */,
228                 true);
229     }
230 
231     @Test
testMatchWithEntryUpstreamBandwidthTooLow()232     public void testMatchWithEntryUpstreamBandwidthTooLow() {
233         verifyMatchesPriorityRuleForUpstreamBandwidth(
234                 LINK_UPSTREAM_BANDWIDTH_KBPS + 1,
235                 LINK_UPSTREAM_BANDWIDTH_KBPS + 1,
236                 null /* currentlySelected */,
237                 false);
238     }
239 
240     @Test
testMatchWithEntryDownstreamBandwidthEquals()241     public void testMatchWithEntryDownstreamBandwidthEquals() {
242         verifyMatchesPriorityRuleForDownstreamBandwidth(
243                 TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS,
244                 TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS,
245                 null /* currentlySelected */,
246                 true);
247     }
248 
249     @Test
testMatchWithEntryDownstreamBandwidthTooLow()250     public void testMatchWithEntryDownstreamBandwidthTooLow() {
251         verifyMatchesPriorityRuleForDownstreamBandwidth(
252                 LINK_DOWNSTREAM_BANDWIDTH_KBPS + 1,
253                 LINK_DOWNSTREAM_BANDWIDTH_KBPS + 1,
254                 null /* currentlySelected */,
255                 false);
256     }
257 
258     @Test
testMatchWithExitUpstreamBandwidthEquals()259     public void testMatchWithExitUpstreamBandwidthEquals() {
260         verifyMatchesPriorityRuleForUpstreamBandwidth(
261                 TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS,
262                 TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS,
263                 mWifiNetworkRecord,
264                 true);
265     }
266 
267     @Test
testMatchWithExitUpstreamBandwidthTooLow()268     public void testMatchWithExitUpstreamBandwidthTooLow() {
269         verifyMatchesPriorityRuleForUpstreamBandwidth(
270                 LINK_UPSTREAM_BANDWIDTH_KBPS + 1,
271                 LINK_UPSTREAM_BANDWIDTH_KBPS + 1,
272                 mWifiNetworkRecord,
273                 false);
274     }
275 
276     @Test
testMatchWithExitDownstreamBandwidthEquals()277     public void testMatchWithExitDownstreamBandwidthEquals() {
278         verifyMatchesPriorityRuleForDownstreamBandwidth(
279                 TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS,
280                 TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS,
281                 mWifiNetworkRecord,
282                 true);
283     }
284 
285     @Test
testMatchWithExitDownstreamBandwidthTooLow()286     public void testMatchWithExitDownstreamBandwidthTooLow() {
287         verifyMatchesPriorityRuleForDownstreamBandwidth(
288                 LINK_DOWNSTREAM_BANDWIDTH_KBPS + 1,
289                 LINK_DOWNSTREAM_BANDWIDTH_KBPS + 1,
290                 mWifiNetworkRecord,
291                 false);
292     }
293 
verifyMatchWifi( boolean isSelectedNetwork, PersistableBundle carrierConfig, boolean expectMatch)294     private void verifyMatchWifi(
295             boolean isSelectedNetwork, PersistableBundle carrierConfig, boolean expectMatch) {
296         final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority =
297                 new VcnWifiUnderlyingNetworkTemplate.Builder()
298                         .setMinUpstreamBandwidthKbps(
299                                 TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS,
300                                 TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS)
301                         .setMinDownstreamBandwidthKbps(
302                                 TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS,
303                                 TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS)
304                         .build();
305         final UnderlyingNetworkRecord selectedNetworkRecord =
306                 isSelectedNetwork ? mWifiNetworkRecord : null;
307         assertEquals(
308                 expectMatch,
309                 checkMatchesWifiPriorityRule(
310                         wifiNetworkPriority,
311                         mWifiNetworkRecord,
312                         selectedNetworkRecord,
313                         carrierConfig == null
314                                 ? null
315                                 : new PersistableBundleWrapper(carrierConfig)));
316     }
317 
318     @Test
testMatchSelectedWifi()319     public void testMatchSelectedWifi() {
320         verifyMatchWifi(
321                 true /* isSelectedNetwork */, null /* carrierConfig */, true /* expectMatch */);
322     }
323 
324     @Test
testMatchSelectedWifiBelowRssiThreshold()325     public void testMatchSelectedWifiBelowRssiThreshold() {
326         final PersistableBundle carrierConfig = new PersistableBundle();
327         carrierConfig.putInt(
328                 VcnManager.VCN_NETWORK_SELECTION_WIFI_EXIT_RSSI_THRESHOLD_KEY, WIFI_RSSI_HIGH);
329         carrierConfig.putInt(
330                 VcnManager.VCN_NETWORK_SELECTION_WIFI_ENTRY_RSSI_THRESHOLD_KEY, WIFI_RSSI_HIGH);
331 
332         verifyMatchWifi(true /* isSelectedNetwork */, carrierConfig, false /* expectMatch */);
333     }
334 
335     @Test
testMatchUnselectedWifi()336     public void testMatchUnselectedWifi() {
337         verifyMatchWifi(
338                 false /* isSelectedNetwork */, null /* carrierConfig */, true /* expectMatch */);
339     }
340 
341     @Test
testMatchUnselectedWifiBelowRssiThreshold()342     public void testMatchUnselectedWifiBelowRssiThreshold() {
343         final PersistableBundle carrierConfig = new PersistableBundle();
344         carrierConfig.putInt(
345                 VcnManager.VCN_NETWORK_SELECTION_WIFI_ENTRY_RSSI_THRESHOLD_KEY, WIFI_RSSI_HIGH);
346 
347         verifyMatchWifi(false /* isSelectedNetwork */, carrierConfig, false /* expectMatch */);
348     }
349 
verifyMatchWifiWithSsid(boolean useMatchedSsid, boolean expectMatch)350     private void verifyMatchWifiWithSsid(boolean useMatchedSsid, boolean expectMatch) {
351         final String nwPrioritySsid = useMatchedSsid ? SSID : SSID_OTHER;
352         final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority =
353                 new VcnWifiUnderlyingNetworkTemplate.Builder()
354                         .setMinUpstreamBandwidthKbps(
355                                 TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS,
356                                 TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS)
357                         .setMinDownstreamBandwidthKbps(
358                                 TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS,
359                                 TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS)
360                         .setSsids(Set.of(nwPrioritySsid))
361                         .build();
362 
363         assertEquals(
364                 expectMatch,
365                 checkMatchesWifiPriorityRule(
366                         wifiNetworkPriority,
367                         mWifiNetworkRecord,
368                         null /* currentlySelecetd */,
369                         null /* carrierConfig */));
370     }
371 
372     @Test
testMatchWifiWithSsid()373     public void testMatchWifiWithSsid() {
374         verifyMatchWifiWithSsid(true /* useMatchedSsid */, true /* expectMatch */);
375     }
376 
377     @Test
testMatchWifiFailWithWrongSsid()378     public void testMatchWifiFailWithWrongSsid() {
379         verifyMatchWifiWithSsid(false /* useMatchedSsid */, false /* expectMatch */);
380     }
381 
getCellNetworkPriorityBuilder()382     private static VcnCellUnderlyingNetworkTemplate.Builder getCellNetworkPriorityBuilder() {
383         return new VcnCellUnderlyingNetworkTemplate.Builder()
384                 .setMinUpstreamBandwidthKbps(
385                         TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS,
386                         TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS)
387                 .setMinDownstreamBandwidthKbps(
388                         TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS,
389                         TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS);
390     }
391 
392     @Test
testMatchMacroCell()393     public void testMatchMacroCell() {
394         assertTrue(
395                 checkMatchesCellPriorityRule(
396                         mVcnContext,
397                         getCellNetworkPriorityBuilder().build(),
398                         mCellNetworkRecord,
399                         SUB_GROUP,
400                         mSubscriptionSnapshot));
401     }
402 
403     @Test
testMatchOpportunisticCell()404     public void testMatchOpportunisticCell() {
405         final VcnCellUnderlyingNetworkTemplate opportunisticCellNetworkPriority =
406                 getCellNetworkPriorityBuilder().setOpportunistic(MATCH_REQUIRED).build();
407 
408         when(mSubscriptionSnapshot.isOpportunistic(SUB_ID)).thenReturn(true);
409         when(mSubscriptionSnapshot.getAllSubIdsInGroup(SUB_GROUP)).thenReturn(new ArraySet<>());
410 
411         assertTrue(
412                 checkMatchesCellPriorityRule(
413                         mVcnContext,
414                         opportunisticCellNetworkPriority,
415                         mCellNetworkRecord,
416                         SUB_GROUP,
417                         mSubscriptionSnapshot));
418     }
419 
verifyMatchMacroCellWithAllowedPlmnIds( boolean useMatchedPlmnId, boolean expectMatch)420     private void verifyMatchMacroCellWithAllowedPlmnIds(
421             boolean useMatchedPlmnId, boolean expectMatch) {
422         final String networkPriorityPlmnId = useMatchedPlmnId ? PLMN_ID : PLMN_ID_OTHER;
423         final VcnCellUnderlyingNetworkTemplate networkPriority =
424                 getCellNetworkPriorityBuilder()
425                         .setOperatorPlmnIds(Set.of(networkPriorityPlmnId))
426                         .build();
427 
428         assertEquals(
429                 expectMatch,
430                 checkMatchesCellPriorityRule(
431                         mVcnContext,
432                         networkPriority,
433                         mCellNetworkRecord,
434                         SUB_GROUP,
435                         mSubscriptionSnapshot));
436     }
437 
438     @Test
testMatchMacroCellWithAllowedPlmnIds()439     public void testMatchMacroCellWithAllowedPlmnIds() {
440         verifyMatchMacroCellWithAllowedPlmnIds(true /* useMatchedPlmnId */, true /* expectMatch */);
441     }
442 
443     @Test
testMatchMacroCellFailWithDisallowedPlmnIds()444     public void testMatchMacroCellFailWithDisallowedPlmnIds() {
445         verifyMatchMacroCellWithAllowedPlmnIds(
446                 false /* useMatchedPlmnId */, false /* expectMatch */);
447     }
448 
verifyMatchMacroCellWithAllowedSpecificCarrierIds( boolean useMatchedCarrierId, boolean expectMatch)449     private void verifyMatchMacroCellWithAllowedSpecificCarrierIds(
450             boolean useMatchedCarrierId, boolean expectMatch) {
451         final int networkPriorityCarrierId = useMatchedCarrierId ? CARRIER_ID : CARRIER_ID_OTHER;
452         final VcnCellUnderlyingNetworkTemplate networkPriority =
453                 getCellNetworkPriorityBuilder()
454                         .setSimSpecificCarrierIds(Set.of(networkPriorityCarrierId))
455                         .build();
456 
457         assertEquals(
458                 expectMatch,
459                 checkMatchesCellPriorityRule(
460                         mVcnContext,
461                         networkPriority,
462                         mCellNetworkRecord,
463                         SUB_GROUP,
464                         mSubscriptionSnapshot));
465     }
466 
467     @Test
testMatchMacroCellWithAllowedSpecificCarrierIds()468     public void testMatchMacroCellWithAllowedSpecificCarrierIds() {
469         verifyMatchMacroCellWithAllowedSpecificCarrierIds(
470                 true /* useMatchedCarrierId */, true /* expectMatch */);
471     }
472 
473     @Test
testMatchMacroCellFailWithDisallowedSpecificCarrierIds()474     public void testMatchMacroCellFailWithDisallowedSpecificCarrierIds() {
475         verifyMatchMacroCellWithAllowedSpecificCarrierIds(
476                 false /* useMatchedCarrierId */, false /* expectMatch */);
477     }
478 
479     @Test
testMatchWifiFailWithoutNotRoamingBit()480     public void testMatchWifiFailWithoutNotRoamingBit() {
481         final VcnCellUnderlyingNetworkTemplate networkPriority =
482                 getCellNetworkPriorityBuilder().setRoaming(MATCH_FORBIDDEN).build();
483 
484         assertFalse(
485                 checkMatchesCellPriorityRule(
486                         mVcnContext,
487                         networkPriority,
488                         mCellNetworkRecord,
489                         SUB_GROUP,
490                         mSubscriptionSnapshot));
491     }
492 
verifyCalculatePriorityClass( UnderlyingNetworkRecord networkRecord, int expectedIndex)493     private void verifyCalculatePriorityClass(
494             UnderlyingNetworkRecord networkRecord, int expectedIndex) {
495         final int priorityIndex =
496                 calculatePriorityClass(
497                         mVcnContext,
498                         networkRecord,
499                         VcnGatewayConnectionConfig.DEFAULT_UNDERLYING_NETWORK_TEMPLATES,
500                         SUB_GROUP,
501                         mSubscriptionSnapshot,
502                         null /* currentlySelected */,
503                         null /* carrierConfig */);
504 
505         assertEquals(expectedIndex, priorityIndex);
506     }
507 
508     @Test
testCalculatePriorityClass()509     public void testCalculatePriorityClass() throws Exception {
510         verifyCalculatePriorityClass(mCellNetworkRecord, 2);
511     }
512 
513     @Test
testCalculatePriorityClassFailToMatchAny()514     public void testCalculatePriorityClassFailToMatchAny() throws Exception {
515         final NetworkCapabilities nc =
516                 new NetworkCapabilities.Builder()
517                         .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
518                         .setSignalStrength(WIFI_RSSI_LOW)
519                         .setSsid(SSID)
520                         .build();
521         final UnderlyingNetworkRecord wifiNetworkRecord =
522                 new UnderlyingNetworkRecord(mNetwork, nc, LINK_PROPERTIES, false /* isBlocked */);
523 
524         verifyCalculatePriorityClass(wifiNetworkRecord, PRIORITY_ANY);
525     }
526 }
527