• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#   Copyright 2021 - Google
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16
17from queue import Empty
18from acts_contrib.test_utils.tel.tel_defines import OverrideNetworkContainer
19from acts_contrib.test_utils.tel.tel_defines import DisplayInfoContainer
20from acts_contrib.test_utils.tel.tel_defines import EventDisplayInfoChanged
21
22def is_current_network_5g_nsa(ad, nsa_mmwave=False, timeout=30):
23    """Verifies 5G NSA override network type
24    Args:
25        ad: android device object.
26        nsa_mmwave: If true, check the band of NSA network is mmWave. Default is to check sub-6.
27        timeout: max time to wait for event.
28    Returns:
29        True: if data is on nsa5g NSA
30        False: if data is not on nsa5g NSA
31    """
32    ad.ed.clear_events(EventDisplayInfoChanged)
33    ad.droid.telephonyStartTrackingDisplayInfoChange()
34    nsa_band = OverrideNetworkContainer.OVERRIDE_NETWORK_TYPE_NR_NSA
35    if nsa_mmwave:
36        nsa_band = OverrideNetworkContainer.OVERRIDE_NETWORK_TYPE_NR_MMWAVE
37    try:
38        event = ad.ed.wait_for_event(
39                EventDisplayInfoChanged,
40                ad.ed.is_event_match,
41                timeout=timeout,
42                field=DisplayInfoContainer.OVERRIDE,
43                value=nsa_band)
44        ad.log.info("Got expected event %s", event)
45        return True
46    except Empty:
47        ad.log.info("No event for display info change")
48        return False
49    finally:
50        ad.droid.telephonyStopTrackingDisplayInfoChange()
51    return None
52
53
54def is_current_network_5g_nsa_for_subscription(ad, nsa_mmwave=False, timeout=30, sub_id=None):
55    """Verifies 5G NSA override network type for subscription id.
56    Args:
57        ad: android device object.
58        nsa_mmwave: If true, check the band of NSA network is mmWave. Default is to check sub-6.
59        timeout: max time to wait for event.
60        sub_id: subscription id.
61    Returns:
62        True: if data is on nsa5g NSA
63        False: if data is not on nsa5g NSA
64    """
65    if not sub_id:
66        return is_current_network_5g_nsa(ad, nsa_mmwave=nsa_mmwave)
67
68    voice_sub_id_changed = False
69    current_sub_id = ad.droid.subscriptionGetDefaultVoiceSubId()
70    if current_sub_id != sub_id:
71        ad.droid.subscriptionSetDefaultVoiceSubId(sub_id)
72        voice_sub_id_changed = True
73
74    result = is_current_network_5g_nsa(ad, nsa_mmwave=nsa_mmwave)
75
76    if voice_sub_id_changed:
77        ad.droid.subscriptionSetDefaultVoiceSubId(current_sub_id)
78
79    return result
80
81def is_current_network_5g_sa(ad):
82    """Verifies 5G SA override network type
83
84    Args:
85        ad: android device object.
86
87    Returns:
88        True: if data is on 5g SA
89        False: if data is not on 5g SA
90    """
91    network_connected = ad.droid.telephonyGetCurrentDataNetworkType()
92    if network_connected == 'NR':
93        ad.log.debug("Network is currently connected to %s", network_connected)
94        return True
95    else:
96        ad.log.error("Network is currently connected to %s, Expected on NR", network_connected)
97        return False