1#!/usr/bin/env python3 2# 3# Copyright 2020 - The Android Open Source Project 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 acts.controllers.android_lib.tel import tel_utils 18from acts.controllers.cellular_lib import BaseCellularDut 19 20 21class AndroidCellularDut(BaseCellularDut.BaseCellularDut): 22 """ Android implementation of the cellular DUT class.""" 23 def __init__(self, ad, logger): 24 """ Keeps a handler to the android device. 25 26 Args: 27 ad: Android device handler 28 logger: a handler to the logger object 29 """ 30 self.ad = ad 31 self.log = logger 32 33 def toggle_airplane_mode(self, new_state=True): 34 """ Turns airplane mode on / off. 35 36 Args: 37 new_state: True if airplane mode needs to be enabled. 38 """ 39 tel_utils.toggle_airplane_mode(self.log, self.ad, new_state) 40 41 def toggle_data_roaming(self, new_state=True): 42 """ Enables or disables cellular data roaming. 43 44 Args: 45 new_state: True if data roaming needs to be enabled. 46 """ 47 tel_utils.toggle_cell_data_roaming(self.ad, new_state) 48 49 def get_rx_tx_power_levels(self): 50 """ Obtains Rx and Tx power levels measured from the DUT. 51 52 Returns: 53 A tuple where the first element is an array with the RSRP value 54 in each Rx chain, and the second element is the Tx power in dBm. 55 Values for invalid or disabled Rx / Tx chains are set to None. 56 """ 57 return tel_utils.get_rx_tx_power_levels(self.log, self.ad) 58 59 def set_apn(self, name, apn, type='default'): 60 """ Sets the Access Point Name. 61 62 Args: 63 name: the APN name 64 apn: the APN 65 type: the APN type 66 """ 67 self.ad.droid.telephonySetAPN(name, apn, type) 68 69 def set_preferred_network_type(self, type): 70 """ Sets the preferred RAT. 71 72 Args: 73 type: an instance of class PreferredNetworkType 74 """ 75 if type == BaseCellularDut.PreferredNetworkType.LTE_ONLY: 76 formatted_type = tel_utils.NETWORK_MODE_LTE_ONLY 77 elif type == BaseCellularDut.PreferredNetworkType.WCDMA_ONLY: 78 formatted_type = tel_utils.NETWORK_MODE_WCDMA_ONLY 79 elif type == BaseCellularDut.PreferredNetworkType.GSM_ONLY: 80 formatted_type = tel_utils.NETWORK_MODE_GSM_ONLY 81 else: 82 raise ValueError('Invalid RAT type.') 83 84 if not self.ad.droid.telephonySetPreferredNetworkTypesForSubscription( 85 formatted_type, self.ad.droid.subscriptionGetDefaultSubId()): 86 self.log.error("Could not set preferred network type.") 87 else: 88 self.log.info("Preferred network type set.") 89 90 def get_telephony_signal_strength(self): 91 """ Wrapper for the method with the same name in tel_utils. 92 93 Will be deprecated and replaced by get_rx_tx_power_levels. """ 94 tel_utils.get_telephony_signal_strength(self.ad) 95