Home | History | Annotate | Download | only in live
      1 #!/usr/bin/env python3.4
      2 #
      3 #   Copyright 2016 - 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 
     17 import math
     18 import os
     19 from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
     20 from acts.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED
     21 from acts.test_utils.tel.tel_test_utils import call_setup_teardown
     22 from acts.test_utils.tel.tel_test_utils import ensure_phone_default_state
     23 from acts.test_utils.tel.tel_test_utils import ensure_phones_idle
     24 from acts.test_utils.tel.tel_test_utils import ensure_wifi_connected
     25 from acts.test_utils.tel.tel_test_utils import hangup_call
     26 from acts.test_utils.tel.tel_test_utils import is_wfc_enabled
     27 from acts.test_utils.tel.tel_test_utils import set_phone_screen_on
     28 from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
     29 from acts.test_utils.tel.tel_test_utils import verify_incall_state
     30 from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_3g
     31 from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_iwlan
     32 from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
     33 from acts.test_utils.tel.tel_voice_utils import phone_idle_3g
     34 from acts.test_utils.tel.tel_voice_utils import phone_idle_iwlan
     35 from acts.test_utils.tel.tel_voice_utils import phone_idle_volte
     36 from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_3g
     37 from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_2g
     38 from acts.test_utils.tel.tel_voice_utils import phone_setup_csfb
     39 from acts.test_utils.tel.tel_voice_utils import phone_setup_iwlan
     40 from acts.test_utils.tel.tel_voice_utils import phone_setup_volte
     41 from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_general
     42 from acts.utils import create_dir
     43 from acts.utils import disable_doze
     44 from acts.utils import get_current_human_time
     45 from acts.utils import set_adaptive_brightness
     46 from acts.utils import set_ambient_display
     47 from acts.utils import set_auto_rotate
     48 from acts.utils import set_location_service
     49 from acts.utils import set_mobile_data_always_on
     50 
     51 # Monsoon output Voltage in V
     52 MONSOON_OUTPUT_VOLTAGE = 4.2
     53 # Monsoon output max current in A
     54 MONSOON_MAX_CURRENT = 7.8
     55 
     56 # Default power test pass criteria
     57 DEFAULT_POWER_PASS_CRITERIA = 999
     58 
     59 # Sampling rate in Hz
     60 ACTIVE_CALL_TEST_SAMPLING_RATE = 100
     61 # Sample duration in seconds
     62 ACTIVE_CALL_TEST_SAMPLE_TIME = 300
     63 # Offset time in seconds
     64 ACTIVE_CALL_TEST_OFFSET_TIME = 180
     65 
     66 # Sampling rate in Hz
     67 IDLE_TEST_SAMPLING_RATE = 100
     68 # Sample duration in seconds
     69 IDLE_TEST_SAMPLE_TIME = 2400
     70 # Offset time in seconds
     71 IDLE_TEST_OFFSET_TIME = 360
     72 
     73 # For wakeup ping test, the frequency to wakeup. In unit of second.
     74 WAKEUP_PING_TEST_WAKEUP_FREQ = 60
     75 
     76 WAKEUP_PING_TEST_NUMBER_OF_ALARM = math.ceil(
     77     (IDLE_TEST_SAMPLE_TIME * 60 + IDLE_TEST_OFFSET_TIME) /
     78     WAKEUP_PING_TEST_WAKEUP_FREQ)
     79 
     80 
     81 class TelPowerTest(TelephonyBaseTest):
     82     def __init__(self, controllers):
     83         TelephonyBaseTest.__init__(self, controllers)
     84         self.tests = (
     85             # Note: For all these power tests, please do environment calibration
     86             # and baseline for pass criteria.
     87             # All pass criteria information should be included in test config file.
     88             # The test result will be meaning less if pass criteria is not correct.
     89             "test_power_active_call_3g",
     90             "test_power_active_call_volte",
     91             "test_power_active_call_wfc_2g_apm",
     92             "test_power_active_call_wfc_2g_lte_volte_on",
     93             "test_power_active_call_wfc_5g_apm",
     94             "test_power_active_call_wfc_5g_lte_volte_on",
     95             "test_power_idle_baseline",
     96             "test_power_idle_baseline_wifi_connected",
     97             "test_power_idle_wfc_2g_apm",
     98             "test_power_idle_wfc_2g_lte",
     99             "test_power_idle_lte_volte_enabled",
    100             "test_power_idle_lte_volte_disabled",
    101             "test_power_idle_3g",
    102             "test_power_idle_lte_volte_enabled_wakeup_ping",
    103             "test_power_idle_lte_volte_disabled_wakeup_ping",
    104             "test_power_idle_3g_wakeup_ping",
    105 
    106             # Mobile Data Always On
    107             "test_power_mobile_data_always_on_lte",
    108             "test_power_mobile_data_always_on_wcdma",
    109             "test_power_mobile_data_always_on_gsm",
    110             "test_power_mobile_data_always_on_1x",
    111             "test_power_mobile_data_always_on_lte_wifi_on",
    112             "test_power_mobile_data_always_on_wcdma_wifi_on",
    113             "test_power_mobile_data_always_on_gsm_wifi_on",
    114             "test_power_mobile_data_always_on_1x_wifi_on")
    115 
    116     def setup_class(self):
    117         super().setup_class()
    118         self.mon = self.monsoons[0]
    119         self.mon.set_voltage(MONSOON_OUTPUT_VOLTAGE)
    120         self.mon.set_max_current(MONSOON_MAX_CURRENT)
    121         # Monsoon phone
    122         self.mon.dut = self.ad = self.android_devices[0]
    123         set_adaptive_brightness(self.ad, False)
    124         set_ambient_display(self.ad, False)
    125         set_auto_rotate(self.ad, False)
    126         set_location_service(self.ad, False)
    127         # This is not needed for AOSP build
    128         disable_doze(self.ad)
    129         set_phone_screen_on(self.log, self.ad, 15)
    130 
    131         self.wifi_network_ssid_2g = self.user_params["wifi_network_ssid_2g"]
    132         self.wifi_network_pass_2g = self.user_params["wifi_network_pass_2g"]
    133         self.wifi_network_ssid_5g = self.user_params["wifi_network_ssid_5g"]
    134         self.wifi_network_pass_5g = self.user_params["wifi_network_pass_5g"]
    135 
    136         self.monsoon_log_path = os.path.join(self.log_path, "MonsoonLog")
    137         create_dir(self.monsoon_log_path)
    138         return True
    139 
    140     def _save_logs_for_power_test(self, test_name, monsoon_result):
    141         current_time = get_current_human_time()
    142         file_name = "{}_{}".format(test_name, current_time)
    143         if "monsoon_log_for_power_test" in self.user_params:
    144             monsoon_result.save_to_text_file(
    145                 [monsoon_result],
    146                 os.path.join(self.monsoon_log_path, file_name))
    147         if "bug_report_for_power_test" in self.user_params:
    148             self.android_devices[0].take_bug_report(test_name, current_time)
    149 
    150     def _test_power_active_call(self,
    151                                 test_name,
    152                                 test_setup_func,
    153                                 pass_criteria=DEFAULT_POWER_PASS_CRITERIA,
    154                                 phone_check_func_after_power_test=None,
    155                                 *args,
    156                                 **kwargs):
    157         average_current = 0
    158         try:
    159             ensure_phone_default_state(self.log, self.android_devices[0])
    160             ensure_phone_default_state(self.log, self.android_devices[1])
    161             if not phone_setup_voice_general(self.log,
    162                                              self.android_devices[1]):
    163                 self.log.error("PhoneB Failed to Set Up Properly.")
    164                 return False
    165             if not test_setup_func(self.android_devices[0], *args, **kwargs):
    166                 self.log.error("DUT Failed to Set Up Properly.")
    167                 return False
    168             result = self.mon.measure_power(
    169                 ACTIVE_CALL_TEST_SAMPLING_RATE, ACTIVE_CALL_TEST_SAMPLE_TIME,
    170                 test_name, ACTIVE_CALL_TEST_OFFSET_TIME)
    171             self._save_logs_for_power_test(test_name, result)
    172             average_current = result.average_current
    173             if not verify_incall_state(self.log, [
    174                     self.android_devices[0], self.android_devices[1]
    175             ], True):
    176                 self.log.error("Call drop during power test.")
    177                 return False
    178             if ((phone_check_func_after_power_test is not None) and
    179                 (not phone_check_func_after_power_test(
    180                     self.log, self.android_devices[0]))):
    181                 self.log.error(
    182                     "Phone is not in correct status after power test.")
    183                 return False
    184             return (average_current <= pass_criteria)
    185         finally:
    186             hangup_call(self.log, self.android_devices[1])
    187             self.log.info("Result: {} mA, pass criteria: {} mA".format(
    188                 average_current, pass_criteria))
    189 
    190     def _test_power_idle(self,
    191                          test_name,
    192                          test_setup_func,
    193                          pass_criteria=DEFAULT_POWER_PASS_CRITERIA,
    194                          phone_check_func_after_power_test=None,
    195                          *args,
    196                          **kwargs):
    197         average_current = 0
    198         try:
    199             ensure_phone_default_state(self.log, self.android_devices[0])
    200             if not test_setup_func(self.android_devices[0], *args, **kwargs):
    201                 self.log.error("DUT Failed to Set Up Properly.")
    202                 return False
    203             result = self.mon.measure_power(IDLE_TEST_SAMPLING_RATE,
    204                                             IDLE_TEST_SAMPLE_TIME, test_name,
    205                                             IDLE_TEST_OFFSET_TIME)
    206             self._save_logs_for_power_test(test_name, result)
    207             average_current = result.average_current
    208             if ((phone_check_func_after_power_test is not None) and
    209                 (not phone_check_func_after_power_test(
    210                     self.log, self.android_devices[0]))):
    211                 self.log.error(
    212                     "Phone is not in correct status after power test.")
    213                 return False
    214             return (average_current <= pass_criteria)
    215         finally:
    216             self.log.info("Result: {} mA, pass criteria: {} mA".format(
    217                 average_current, pass_criteria))
    218 
    219     def _start_alarm(self):
    220         alarm_id = self.ad.droid.telephonyStartRecurringAlarm(
    221             WAKEUP_PING_TEST_NUMBER_OF_ALARM,
    222             1000 * WAKEUP_PING_TEST_WAKEUP_FREQ, "PING_GOOGLE", None)
    223         if alarm_id is None:
    224             self.log.error("Start alarm failed.")
    225             return False
    226         return True
    227 
    228     def _setup_phone_idle_and_wakeup_ping(self, ad, phone_setup_func):
    229         if not phone_setup_func(self.log, ad):
    230             self.log.error("Phone failed to setup {}.".format(
    231                 phone_setup_func.__name__))
    232             return False
    233         if not self._start_alarm():
    234             return False
    235         ad.droid.goToSleepNow()
    236         return True
    237 
    238     def _setup_phone_mobile_data_always_on(self,
    239                                            ad,
    240                                            phone_setup_func,
    241                                            connect_wifi,
    242                                            wifi_ssid=None,
    243                                            wifi_password=None,
    244                                            mobile_data_always_on=True):
    245         set_mobile_data_always_on(ad, mobile_data_always_on)
    246         if not phone_setup_func(self.log, ad):
    247             self.log.error("Phone failed to setup {}.".format(
    248                 phone_setup_func.__name__))
    249             return False
    250         if (connect_wifi and not ensure_wifi_connected(self.log, ad, wifi_ssid,
    251                                                        wifi_password)):
    252             self.log.error("WiFi connect failed")
    253             return False
    254         # simulate normal user behavior -- wake up every 1 minutes and do ping
    255         # (transmit data)
    256         if not self._start_alarm():
    257             return False
    258         ad.droid.goToSleepNow()
    259         return True
    260 
    261     def _setup_phone_active_call(self, ad, phone_setup_func,
    262                                  phone_idle_check_func,
    263                                  phone_in_call_check_func):
    264         if not phone_setup_func(self.log, ad):
    265             self.log.error("DUT Failed to Set Up Properly: {}".format(
    266                 phone_setup_func.__name__))
    267             return False
    268         ensure_phones_idle(self.log, [ad, self.android_devices[1]])
    269         if not phone_idle_check_func(self.log, ad):
    270             self.log.error("DUT not in correct idle state: {}".format(
    271                 phone_idle_check_func.__name__))
    272             return False
    273         if not call_setup_teardown(
    274                 self.log,
    275                 ad,
    276                 self.android_devices[1],
    277                 ad_hangup=None,
    278                 verify_caller_func=phone_in_call_check_func):
    279             self.log.error("Setup Call failed.")
    280             return False
    281         ad.droid.goToSleepNow()
    282         return True
    283 
    284     def _setup_phone_active_call_wfc(self,
    285                                      ad,
    286                                      ssid,
    287                                      password,
    288                                      airplane_mode,
    289                                      wfc_mode,
    290                                      setup_volte=False):
    291         if setup_volte and (not phone_setup_volte(self.log, ad)):
    292             self.log.error("Phone failed to setup VoLTE.")
    293             return False
    294         if not phone_setup_iwlan(self.log, ad, airplane_mode, wfc_mode, ssid,
    295                                  password):
    296             self.log.error("DUT Failed to Set Up WiFi Calling")
    297             return False
    298         ensure_phones_idle(self.log, [ad, self.android_devices[1]])
    299         if not phone_idle_iwlan(self.log, ad):
    300             self.log.error("DUT not in WFC enabled state.")
    301             return False
    302         if not call_setup_teardown(
    303                 self.log,
    304                 ad,
    305                 self.android_devices[1],
    306                 ad_hangup=None,
    307                 verify_caller_func=is_phone_in_call_iwlan):
    308             self.log.error("Setup Call failed.")
    309             return False
    310         ad.droid.goToSleepNow()
    311         return True
    312 
    313     @TelephonyBaseTest.tel_test_wrap
    314     def test_power_active_call_3g(self):
    315         """Power measurement test for active CS(3G) call.
    316 
    317         Steps:
    318         1. DUT idle, in 3G mode.
    319         2. Make a phone Call from DUT to PhoneB. Answer on PhoneB.
    320             Make sure DUT is in CS(3G) call.
    321         3. Turn off screen and wait for 3 minutes.
    322             Then measure power consumption for 5 minutes and get average.
    323 
    324         Expected Results:
    325         Average power consumption should be within pre-defined limit.
    326 
    327         Returns:
    328         True if Pass, False if Fail.
    329 
    330         Note: Please calibrate your test environment and baseline pass criteria.
    331         Pass criteria info should be in test config file.
    332         """
    333         try:
    334             PASS_CRITERIA = int(self.user_params["pass_criteria_call_3g"][
    335                 "pass_criteria"])
    336         except KeyError:
    337             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    338 
    339         return self._test_power_active_call(
    340             "test_power_active_call_3g",
    341             self._setup_phone_active_call,
    342             PASS_CRITERIA,
    343             phone_check_func_after_power_test=is_phone_in_call_3g,
    344             phone_setup_func=phone_setup_voice_3g,
    345             phone_idle_check_func=phone_idle_3g,
    346             phone_in_call_check_func=is_phone_in_call_3g)
    347 
    348     @TelephonyBaseTest.tel_test_wrap
    349     def test_power_active_call_volte(self):
    350         """Power measurement test for active VoLTE call.
    351 
    352         Steps:
    353         1. DUT idle, in LTE mode, VoLTE enabled.
    354         2. Make a phone Call from DUT to PhoneB. Answer on PhoneB.
    355             Make sure DUT is in VoLTE call.
    356         3. Turn off screen and wait for 3 minutes.
    357             Then measure power consumption for 5 minutes and get average.
    358 
    359         Expected Results:
    360         Average power consumption should be within pre-defined limit.
    361 
    362         Returns:
    363         True if Pass, False if Fail.
    364 
    365         Note: Please calibrate your test environment and baseline pass criteria.
    366         Pass criteria info should be in test config file.
    367         """
    368         try:
    369             PASS_CRITERIA = int(self.user_params["pass_criteria_call_volte"][
    370                 "pass_criteria"])
    371         except KeyError:
    372             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    373 
    374         return self._test_power_active_call(
    375             "test_power_active_call_volte",
    376             self._setup_phone_active_call,
    377             PASS_CRITERIA,
    378             phone_check_func_after_power_test=is_phone_in_call_volte,
    379             phone_setup_func=phone_setup_volte,
    380             phone_idle_check_func=phone_idle_volte,
    381             phone_in_call_check_func=is_phone_in_call_volte)
    382 
    383     @TelephonyBaseTest.tel_test_wrap
    384     def test_power_active_call_wfc_2g_apm(self):
    385         """Power measurement test for active WiFi call.
    386 
    387         Steps:
    388         1. DUT idle, in Airplane mode, connect to 2G WiFi,
    389             WiFi Calling enabled (WiFi-preferred mode).
    390         2. Make a phone Call from DUT to PhoneB. Answer on PhoneB.
    391             Make sure DUT is in WFC call.
    392         3. Turn off screen and wait for 3 minutes.
    393             Then measure power consumption for 5 minutes and get average.
    394 
    395         Expected Results:
    396         Average power consumption should be within pre-defined limit.
    397 
    398         Returns:
    399         True if Pass, False if Fail.
    400 
    401         Note: Please calibrate your test environment and baseline pass criteria.
    402         Pass criteria info should be in test config file.
    403         """
    404         try:
    405             PASS_CRITERIA = int(self.user_params[
    406                 "pass_criteria_call_wfc_2g_apm"]["pass_criteria"])
    407         except KeyError:
    408             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    409 
    410         return self._test_power_active_call(
    411             "test_power_active_call_wfc_2g_apm",
    412             self._setup_phone_active_call_wfc,
    413             PASS_CRITERIA,
    414             phone_check_func_after_power_test=is_phone_in_call_iwlan,
    415             ssid=self.wifi_network_ssid_2g,
    416             password=self.wifi_network_pass_2g,
    417             airplane_mode=True,
    418             wfc_mode=WFC_MODE_WIFI_PREFERRED,
    419             setup_volte=False)
    420 
    421     @TelephonyBaseTest.tel_test_wrap
    422     def test_power_active_call_wfc_2g_lte_volte_on(self):
    423         """Power measurement test for active WiFi call.
    424 
    425         Steps:
    426         1. DUT idle, LTE cellular data network, VoLTE is On, connect to 2G WiFi,
    427             WiFi Calling enabled (WiFi-preferred).
    428         2. Make a phone Call from DUT to PhoneB. Answer on PhoneB.
    429             Make sure DUT is in WFC call.
    430         3. Turn off screen and wait for 3 minutes.
    431             Then measure power consumption for 5 minutes and get average.
    432 
    433         Expected Results:
    434         Average power consumption should be within pre-defined limit.
    435 
    436         Returns:
    437         True if Pass, False if Fail.
    438 
    439         Note: Please calibrate your test environment and baseline pass criteria.
    440         Pass criteria info should be in test config file.
    441         """
    442         try:
    443             PASS_CRITERIA = int(self.user_params[
    444                 "pass_criteria_call_wfc_2g_lte_volte_on"]["pass_criteria"])
    445         except KeyError:
    446             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    447 
    448         return self._test_power_active_call(
    449             "test_power_active_call_wfc_2g_lte_volte_on",
    450             self._setup_phone_active_call_wfc,
    451             PASS_CRITERIA,
    452             phone_check_func_after_power_test=is_phone_in_call_iwlan,
    453             ssid=self.wifi_network_ssid_2g,
    454             password=self.wifi_network_pass_2g,
    455             airplane_mode=False,
    456             wfc_mode=WFC_MODE_WIFI_PREFERRED,
    457             setup_volte=True)
    458 
    459     @TelephonyBaseTest.tel_test_wrap
    460     def test_power_active_call_wfc_5g_apm(self):
    461         """Power measurement test for active WiFi call.
    462 
    463         Steps:
    464         1. DUT idle, in Airplane mode, connect to 5G WiFi,
    465             WiFi Calling enabled (WiFi-preferred mode).
    466         2. Make a phone Call from DUT to PhoneB. Answer on PhoneB.
    467             Make sure DUT is in WFC call.
    468         3. Turn off screen and wait for 3 minutes.
    469             Then measure power consumption for 5 minutes and get average.
    470 
    471         Expected Results:
    472         Average power consumption should be within pre-defined limit.
    473 
    474         Returns:
    475         True if Pass, False if Fail.
    476 
    477         Note: Please calibrate your test environment and baseline pass criteria.
    478         Pass criteria info should be in test config file.
    479         """
    480         try:
    481             PASS_CRITERIA = int(self.user_params[
    482                 "pass_criteria_call_wfc_5g_apm"]["pass_criteria"])
    483         except KeyError:
    484             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    485 
    486         return self._test_power_active_call(
    487             "test_power_active_call_wfc_5g_apm",
    488             self._setup_phone_active_call_wfc,
    489             PASS_CRITERIA,
    490             phone_check_func_after_power_test=is_phone_in_call_iwlan,
    491             ssid=self.wifi_network_ssid_5g,
    492             password=self.wifi_network_pass_5g,
    493             airplane_mode=True,
    494             wfc_mode=WFC_MODE_WIFI_PREFERRED,
    495             setup_volte=False)
    496 
    497     @TelephonyBaseTest.tel_test_wrap
    498     def test_power_active_call_wfc_5g_lte_volte_on(self):
    499         """Power measurement test for active WiFi call.
    500 
    501         Steps:
    502         1. DUT idle, LTE cellular data network, VoLTE is On, connect to 5G WiFi,
    503             WiFi Calling enabled (WiFi-preferred).
    504         2. Make a phone Call from DUT to PhoneB. Answer on PhoneB.
    505             Make sure DUT is in WFC call.
    506         3. Turn off screen and wait for 3 minutes.
    507             Then measure power consumption for 5 minutes and get average.
    508 
    509         Expected Results:
    510         Average power consumption should be within pre-defined limit.
    511 
    512         Returns:
    513         True if Pass, False if Fail.
    514 
    515         Note: Please calibrate your test environment and baseline pass criteria.
    516         Pass criteria info should be in test config file.
    517         """
    518 
    519         try:
    520             PASS_CRITERIA = int(self.user_params[
    521                 "pass_criteria_call_wfc_5g_lte_volte_on"]["pass_criteria"])
    522         except KeyError:
    523             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    524 
    525         return self._test_power_active_call(
    526             "test_power_active_call_wfc_5g_lte_volte_on",
    527             self._setup_phone_active_call_wfc,
    528             PASS_CRITERIA,
    529             phone_check_func_after_power_test=is_phone_in_call_iwlan,
    530             ssid=self.wifi_network_ssid_5g,
    531             password=self.wifi_network_pass_5g,
    532             airplane_mode=False,
    533             wfc_mode=WFC_MODE_WIFI_PREFERRED,
    534             setup_volte=True)
    535 
    536     @TelephonyBaseTest.tel_test_wrap
    537     def test_power_idle_baseline(self):
    538         """Power measurement test for phone idle baseline.
    539 
    540         Steps:
    541         1. DUT idle, in Airplane mode. WiFi disabled, WiFi Calling disabled.
    542         2. Turn off screen and wait for 6 minutes. Then measure power
    543             consumption for 40 minutes and get average.
    544 
    545         Expected Results:
    546         Average power consumption should be within pre-defined limit.
    547 
    548         Returns:
    549         True if Pass, False if Fail.
    550 
    551         Note: Please calibrate your test environment and baseline pass criteria.
    552         Pass criteria info should be in test config file.
    553         """
    554         try:
    555             PASS_CRITERIA = int(self.user_params["pass_criteria_idle_baseline"]
    556                                 ["pass_criteria"])
    557         except KeyError:
    558             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    559 
    560         def _idle_baseline(ad):
    561             if not toggle_airplane_mode(self.log, ad, True):
    562                 self.log.error("Phone failed to turn on airplane mode.")
    563                 return False
    564             ad.droid.goToSleepNow()
    565             return True
    566 
    567         return self._test_power_idle("test_power_idle_baseline",
    568                                      _idle_baseline, PASS_CRITERIA)
    569 
    570     @TelephonyBaseTest.tel_test_wrap
    571     def test_power_idle_baseline_wifi_connected(self):
    572         """Power measurement test for phone idle baseline (WiFi connected).
    573 
    574         Steps:
    575         1. DUT idle, in Airplane mode. WiFi connected to 2.4G WiFi,
    576             WiFi Calling disabled.
    577         2. Turn off screen and wait for 6 minutes. Then measure power
    578             consumption for 40 minutes and get average.
    579 
    580         Expected Results:
    581         Average power consumption should be within pre-defined limit.
    582 
    583         Returns:
    584         True if Pass, False if Fail.
    585 
    586         Note: Please calibrate your test environment and baseline pass criteria.
    587         Pass criteria info should be in test config file.
    588         """
    589         try:
    590             PASS_CRITERIA = int(self.user_params[
    591                 "pass_criteria_idle_baseline_wifi_connected"]["pass_criteria"])
    592         except KeyError:
    593             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    594 
    595         def _idle_baseline_wifi_connected(ad):
    596             if not toggle_airplane_mode(self.log, ad, True):
    597                 self.log.error("Phone failed to turn on airplane mode.")
    598                 return False
    599             if not ensure_wifi_connected(self.log, ad,
    600                                          self.wifi_network_ssid_2g,
    601                                          self.wifi_network_pass_2g):
    602                 self.log.error("WiFi connect failed")
    603                 return False
    604             ad.droid.goToSleepNow()
    605             return True
    606 
    607         return self._test_power_idle("test_power_idle_baseline_wifi_connected",
    608                                      _idle_baseline_wifi_connected,
    609                                      PASS_CRITERIA)
    610 
    611     @TelephonyBaseTest.tel_test_wrap
    612     def test_power_idle_wfc_2g_apm(self):
    613         """Power measurement test for phone idle WiFi Calling Airplane Mode.
    614 
    615         Steps:
    616         1. DUT idle, in Airplane mode. Connected to 2G WiFi,
    617             WiFi Calling enabled (WiFi preferred).
    618         2. Turn off screen and wait for 6 minutes. Then measure power
    619             consumption for 40 minutes and get average.
    620 
    621         Expected Results:
    622         Average power consumption should be within pre-defined limit.
    623 
    624         Returns:
    625         True if Pass, False if Fail.
    626 
    627         Note: Please calibrate your test environment and baseline pass criteria.
    628         Pass criteria info should be in test config file.
    629         """
    630         try:
    631             PASS_CRITERIA = int(self.user_params[
    632                 "pass_criteria_idle_wfc_2g_apm"]["pass_criteria"])
    633         except KeyError:
    634             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    635 
    636         def _idle_wfc_2g_apm(ad):
    637             if not phone_setup_iwlan(
    638                     self.log, ad, True, WFC_MODE_WIFI_PREFERRED,
    639                     self.wifi_network_ssid_2g, self.wifi_network_pass_2g):
    640                 self.log.error("Phone failed to setup WFC.")
    641                 return False
    642             ad.droid.goToSleepNow()
    643             return True
    644 
    645         return self._test_power_idle("test_power_idle_wfc_2g_apm",
    646                                      _idle_wfc_2g_apm, PASS_CRITERIA,
    647                                      is_wfc_enabled)
    648 
    649     @TelephonyBaseTest.tel_test_wrap
    650     def test_power_idle_wfc_2g_lte(self):
    651         """Power measurement test for phone idle WiFi Calling LTE VoLTE enabled.
    652 
    653         Steps:
    654         1. DUT idle, in LTE mode, VoLTE enabled. Connected to 2G WiFi,
    655             WiFi Calling enabled (WiFi preferred).
    656         2. Turn off screen and wait for 6 minutes. Then measure power
    657             consumption for 40 minutes and get average.
    658 
    659         Expected Results:
    660         Average power consumption should be within pre-defined limit.
    661 
    662         Returns:
    663         True if Pass, False if Fail.
    664 
    665         Note: Please calibrate your test environment and baseline pass criteria.
    666         Pass criteria info should be in test config file.
    667         """
    668         try:
    669             PASS_CRITERIA = int(self.user_params[
    670                 "pass_criteria_idle_wfc_2g_lte"]["pass_criteria"])
    671         except KeyError:
    672             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    673 
    674         def _idle_wfc_2g_lte(ad):
    675             if not phone_setup_volte(self.log, ad):
    676                 self.log.error("Phone failed to setup VoLTE.")
    677                 return False
    678             if not phone_setup_iwlan(
    679                     self.log, ad, False, WFC_MODE_WIFI_PREFERRED,
    680                     self.wifi_network_ssid_2g, self.wifi_network_pass_2g):
    681                 self.log.error("Phone failed to setup WFC.")
    682                 return False
    683             ad.droid.goToSleepNow()
    684             return True
    685 
    686         return self._test_power_idle("test_power_idle_wfc_2g_lte",
    687                                      _idle_wfc_2g_lte, PASS_CRITERIA,
    688                                      is_wfc_enabled)
    689 
    690     @TelephonyBaseTest.tel_test_wrap
    691     def test_power_idle_lte_volte_enabled(self):
    692         """Power measurement test for phone idle LTE VoLTE enabled.
    693 
    694         Steps:
    695         1. DUT idle, in LTE mode, VoLTE enabled. WiFi disabled,
    696             WiFi Calling disabled.
    697         2. Turn off screen and wait for 6 minutes. Then measure power
    698             consumption for 40 minutes and get average.
    699 
    700         Expected Results:
    701         Average power consumption should be within pre-defined limit.
    702 
    703         Returns:
    704         True if Pass, False if Fail.
    705 
    706         Note: Please calibrate your test environment and baseline pass criteria.
    707         Pass criteria info should be in test config file.
    708         """
    709         try:
    710             PASS_CRITERIA = int(self.user_params[
    711                 "pass_criteria_idle_lte_volte_enabled"]["pass_criteria"])
    712         except KeyError:
    713             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    714 
    715         def _idle_lte_volte_enabled(ad):
    716             if not phone_setup_volte(self.log, ad):
    717                 self.log.error("Phone failed to setup VoLTE.")
    718                 return False
    719             ad.droid.goToSleepNow()
    720             return True
    721 
    722         return self._test_power_idle("test_power_idle_lte_volte_enabled",
    723                                      _idle_lte_volte_enabled, PASS_CRITERIA)
    724 
    725     @TelephonyBaseTest.tel_test_wrap
    726     def test_power_idle_lte_volte_disabled(self):
    727         """Power measurement test for phone idle LTE VoLTE disabled.
    728 
    729         Steps:
    730         1. DUT idle, in LTE mode, VoLTE disabled. WiFi disabled,
    731             WiFi Calling disabled.
    732         2. Turn off screen and wait for 6 minutes. Then measure power
    733             consumption for 40 minutes and get average.
    734 
    735         Expected Results:
    736         Average power consumption should be within pre-defined limit.
    737 
    738         Returns:
    739         True if Pass, False if Fail.
    740 
    741         Note: Please calibrate your test environment and baseline pass criteria.
    742         Pass criteria info should be in test config file.
    743         """
    744         try:
    745             PASS_CRITERIA = int(self.user_params[
    746                 "pass_criteria_idle_lte_volte_disabled"]["pass_criteria"])
    747         except KeyError:
    748             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    749 
    750         def _idle_lte_volte_disabled(ad):
    751             if not phone_setup_csfb(self.log, ad):
    752                 self.log.error("Phone failed to setup CSFB.")
    753                 return False
    754             ad.droid.goToSleepNow()
    755             return True
    756 
    757         return self._test_power_idle("test_power_idle_lte_volte_disabled",
    758                                      _idle_lte_volte_disabled, PASS_CRITERIA)
    759 
    760     @TelephonyBaseTest.tel_test_wrap
    761     def test_power_idle_3g(self):
    762         """Power measurement test for phone idle 3G.
    763 
    764         Steps:
    765         1. DUT idle, in 3G mode. WiFi disabled, WiFi Calling disabled.
    766         2. Turn off screen and wait for 6 minutes. Then measure power
    767             consumption for 40 minutes and get average.
    768 
    769         Expected Results:
    770         Average power consumption should be within pre-defined limit.
    771 
    772         Returns:
    773         True if Pass, False if Fail.
    774 
    775         Note: Please calibrate your test environment and baseline pass criteria.
    776         Pass criteria info should be in test config file.
    777         """
    778         try:
    779             PASS_CRITERIA = int(self.user_params["pass_criteria_idle_3g"][
    780                 "pass_criteria"])
    781         except KeyError:
    782             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    783 
    784         def _idle_3g(ad):
    785             if not phone_setup_voice_3g(self.log, ad):
    786                 self.log.error("Phone failed to setup 3g.")
    787                 return False
    788             ad.droid.goToSleepNow()
    789             return True
    790 
    791         return self._test_power_idle("test_power_idle_3g", _idle_3g,
    792                                      PASS_CRITERIA)
    793 
    794     # TODO: This one is not working right now. Requires SL4A API to start alarm.
    795     @TelephonyBaseTest.tel_test_wrap
    796     def test_power_idle_lte_volte_enabled_wakeup_ping(self):
    797         """Power measurement test for phone LTE VoLTE enabled Wakeup Ping every
    798         1 minute.
    799 
    800         Steps:
    801         1. DUT idle, in LTE mode, VoLTE enabled. WiFi disabled,
    802             WiFi Calling disabled.
    803         2. Start script to wake up AP every 1 minute, after wakeup,
    804             DUT send http Request to Google.com then go to sleep.
    805         3. Turn off screen and wait for 6 minutes. Then measure power
    806             consumption for 40 minutes and get average.
    807 
    808         Expected Results:
    809         Average power consumption should be within pre-defined limit.
    810 
    811         Returns:
    812         True if Pass, False if Fail.
    813 
    814         Note: Please calibrate your test environment and baseline pass criteria.
    815         Pass criteria info should be in test config file.
    816         """
    817         try:
    818             PASS_CRITERIA = int(self.user_params[
    819                 "pass_criteria_idle_lte_volte_enabled_wakeup_ping"][
    820                     "pass_criteria"])
    821         except KeyError:
    822             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    823         # TODO: b/26338146 need a SL4A API to clear all existing alarms.
    824 
    825         result = self._test_power_idle(
    826             "test_power_idle_lte_volte_enabled_wakeup_ping",
    827             self._setup_phone_idle_and_wakeup_ping,
    828             PASS_CRITERIA,
    829             phone_setup_func=phone_setup_volte)
    830         return result
    831 
    832     # TODO: This one is not working right now. Requires SL4A API to start alarm.
    833     @TelephonyBaseTest.tel_test_wrap
    834     def test_power_idle_lte_volte_disabled_wakeup_ping(self):
    835         """Power measurement test for phone LTE VoLTE disabled Wakeup Ping every
    836         1 minute.
    837 
    838         Steps:
    839         1. DUT idle, in LTE mode, VoLTE disabled. WiFi disabled,
    840             WiFi Calling disabled.
    841         2. Start script to wake up AP every 1 minute, after wakeup,
    842             DUT send http Request to Google.com then go to sleep.
    843         3. Turn off screen and wait for 6 minutes. Then measure power
    844             consumption for 40 minutes and get average.
    845 
    846         Expected Results:
    847         Average power consumption should be within pre-defined limit.
    848 
    849         Returns:
    850         True if Pass, False if Fail.
    851 
    852         Note: Please calibrate your test environment and baseline pass criteria.
    853         Pass criteria info should be in test config file.
    854         """
    855         try:
    856             PASS_CRITERIA = int(self.user_params[
    857                 "pass_criteria_idle_lte_volte_disabled_wakeup_ping"][
    858                     "pass_criteria"])
    859         except KeyError:
    860             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    861         # TODO: b/26338146 need a SL4A API to clear all existing alarms.
    862 
    863         result = self._test_power_idle(
    864             "test_power_idle_lte_volte_disabled_wakeup_ping",
    865             self._setup_phone_idle_and_wakeup_ping,
    866             PASS_CRITERIA,
    867             phone_setup_func=phone_setup_csfb)
    868         return result
    869 
    870     # TODO: This one is not working right now. Requires SL4A API to start alarm.
    871     @TelephonyBaseTest.tel_test_wrap
    872     def test_power_idle_3g_wakeup_ping(self):
    873         """Power measurement test for phone 3G Wakeup Ping every 1 minute.
    874 
    875         Steps:
    876         1. DUT idle, in 3G mode. WiFi disabled, WiFi Calling disabled.
    877         2. Start script to wake up AP every 1 minute, after wakeup,
    878             DUT send http Request to Google.com then go to sleep.
    879         3. Turn off screen and wait for 6 minutes. Then measure power
    880             consumption for 40 minutes and get average.
    881 
    882         Expected Results:
    883         Average power consumption should be within pre-defined limit.
    884 
    885         Returns:
    886         True if Pass, False if Fail.
    887 
    888         Note: Please calibrate your test environment and baseline pass criteria.
    889         Pass criteria info should be in test config file.
    890         """
    891         try:
    892             PASS_CRITERIA = int(self.user_params[
    893                 "pass_criteria_idle_3g_wakeup_ping"]["pass_criteria"])
    894         except KeyError:
    895             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    896         # TODO: b/26338146 need a SL4A API to clear all existing alarms.
    897 
    898         result = self._test_power_idle(
    899             "test_power_idle_3g_wakeup_ping",
    900             self._setup_phone_idle_and_wakeup_ping,
    901             PASS_CRITERIA,
    902             phone_setup_func=phone_setup_voice_3g)
    903         return result
    904 
    905     # TODO: This one is not working right now. Requires SL4A API to start alarm.
    906     @TelephonyBaseTest.tel_test_wrap
    907     def test_power_mobile_data_always_on_lte(self):
    908         try:
    909             PASS_CRITERIA = int(self.user_params[
    910                 "pass_criteria_mobile_data_always_on_lte"]["pass_criteria"])
    911         except KeyError:
    912             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    913         result = self._test_power_idle(
    914             "test_power_mobile_data_always_on_lte",
    915             self._setup_phone_mobile_data_always_on,
    916             PASS_CRITERIA,
    917             phone_setup_func=phone_setup_csfb,
    918             connect_wifi=False)
    919         set_mobile_data_always_on(self.ad, False)
    920         return result
    921 
    922     # TODO: This one is not working right now. Requires SL4A API to start alarm.
    923     @TelephonyBaseTest.tel_test_wrap
    924     def test_power_mobile_data_always_on_wcdma(self):
    925         try:
    926             PASS_CRITERIA = int(self.user_params[
    927                 "pass_criteria_mobile_data_always_on_wcdma"]["pass_criteria"])
    928         except KeyError:
    929             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    930         result = self._test_power_idle(
    931             "test_power_mobile_data_always_on_wcdma",
    932             self._setup_phone_mobile_data_always_on,
    933             PASS_CRITERIA,
    934             phone_setup_func=phone_setup_voice_3g,
    935             connect_wifi=False)
    936         set_mobile_data_always_on(self.ad, False)
    937         return result
    938 
    939     # TODO: This one is not working right now. Requires SL4A API to start alarm.
    940     @TelephonyBaseTest.tel_test_wrap
    941     def test_power_mobile_data_always_on_1xevdo(self):
    942         try:
    943             PASS_CRITERIA = int(self.user_params[
    944                 "pass_criteria_mobile_data_always_on_1xevdo"]["pass_criteria"])
    945         except KeyError:
    946             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    947         result = self._test_power_idle(
    948             "test_power_mobile_data_always_on_1xevdo",
    949             self._setup_phone_mobile_data_always_on,
    950             PASS_CRITERIA,
    951             phone_setup_func=phone_setup_voice_3g,
    952             connect_wifi=False)
    953         set_mobile_data_always_on(self.ad, False)
    954         return result
    955 
    956     # TODO: This one is not working right now. Requires SL4A API to start alarm.
    957     @TelephonyBaseTest.tel_test_wrap
    958     def test_power_mobile_data_always_on_gsm(self):
    959         try:
    960             PASS_CRITERIA = int(self.user_params[
    961                 "pass_criteria_mobile_data_always_on_gsm"]["pass_criteria"])
    962         except KeyError:
    963             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    964         result = self._test_power_idle(
    965             "test_power_mobile_data_always_on_gsm",
    966             self._setup_phone_mobile_data_always_on,
    967             PASS_CRITERIA,
    968             phone_setup_func=phone_setup_voice_2g,
    969             connect_wifi=False)
    970         set_mobile_data_always_on(self.ad, False)
    971         return result
    972 
    973     # TODO: This one is not working right now. Requires SL4A API to start alarm.
    974     @TelephonyBaseTest.tel_test_wrap
    975     def test_power_mobile_data_always_on_lte_wifi_on(self):
    976         try:
    977             PASS_CRITERIA = int(self.user_params[
    978                 "pass_criteria_mobile_data_always_on_lte_wifi_on"][
    979                     "pass_criteria"])
    980         except KeyError:
    981             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
    982         result = self._test_power_idle(
    983             "test_power_mobile_data_always_on_lte_wifi_on",
    984             self._setup_phone_mobile_data_always_on,
    985             PASS_CRITERIA,
    986             phone_setup_func=phone_setup_csfb,
    987             connect_wifi=True,
    988             wifi_ssid=self.wifi_network_ssid_2g,
    989             wifi_password=self.wifi_network_pass_2g)
    990         set_mobile_data_always_on(self.ad, False)
    991         return result
    992 
    993     # TODO: This one is not working right now. Requires SL4A API to start alarm.
    994     @TelephonyBaseTest.tel_test_wrap
    995     def test_power_mobile_data_always_on_wcdma_wifi_on(self):
    996         try:
    997             PASS_CRITERIA = int(self.user_params[
    998                 "pass_criteria_mobile_data_always_on_wcdma_wifi_on"][
    999                     "pass_criteria"])
   1000         except KeyError:
   1001             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
   1002         result = self._test_power_idle(
   1003             "test_power_mobile_data_always_on_wcdma_wifi_on",
   1004             self._setup_phone_mobile_data_always_on,
   1005             PASS_CRITERIA,
   1006             phone_setup_func=phone_setup_voice_3g,
   1007             connect_wifi=True,
   1008             wifi_ssid=self.wifi_network_ssid_2g,
   1009             wifi_password=self.wifi_network_pass_2g)
   1010         set_mobile_data_always_on(self.ad, False)
   1011         return result
   1012 
   1013     # TODO: This one is not working right now. Requires SL4A API to start alarm.
   1014     @TelephonyBaseTest.tel_test_wrap
   1015     def test_power_mobile_data_always_on_1xevdo_wifi_on(self):
   1016         try:
   1017             PASS_CRITERIA = int(self.user_params[
   1018                 "pass_criteria_mobile_data_always_on_1xevdo_wifi_on"][
   1019                     "pass_criteria"])
   1020         except KeyError:
   1021             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
   1022         result = self._test_power_idle(
   1023             "test_power_mobile_data_always_on_1xevdo_wifi_on",
   1024             self._setup_phone_mobile_data_always_on,
   1025             PASS_CRITERIA,
   1026             phone_setup_func=phone_setup_voice_3g,
   1027             connect_wifi=True,
   1028             wifi_ssid=self.wifi_network_ssid_2g,
   1029             wifi_password=self.wifi_network_pass_2g)
   1030         set_mobile_data_always_on(self.ad, False)
   1031         return result
   1032 
   1033     # TODO: This one is not working right now. Requires SL4A API to start alarm.
   1034     @TelephonyBaseTest.tel_test_wrap
   1035     def test_power_mobile_data_always_on_gsm_wifi_on(self):
   1036         try:
   1037             PASS_CRITERIA = int(self.user_params[
   1038                 "pass_criteria_mobile_data_always_on_gsm_wifi_on"][
   1039                     "pass_criteria"])
   1040         except KeyError:
   1041             PASS_CRITERIA = DEFAULT_POWER_PASS_CRITERIA
   1042         result = self._test_power_idle(
   1043             "test_power_mobile_data_always_on_gsm_wifi_on",
   1044             self._setup_phone_mobile_data_always_on,
   1045             PASS_CRITERIA,
   1046             phone_setup_func=phone_setup_voice_2g,
   1047             connect_wifi=True,
   1048             wifi_ssid=self.wifi_network_ssid_2g,
   1049             wifi_password=self.wifi_network_pass_2g)
   1050         set_mobile_data_always_on(self.ad, False)
   1051         return result
   1052