• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3.4
2#
3#   Copyright 2016 - 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"""
17    Test Script for Telephony integration with TF
18"""
19
20import time
21from acts.base_test import BaseTestClass
22from queue import Empty
23from acts.test_utils.tel import tel_defines
24from acts.test_utils.tel.tel_test_utils import initiate_call
25from acts.test_utils.tel.tel_test_utils import hangup_call
26from acts.test_utils.tel.tel_test_utils import ensure_phone_default_state
27from acts.test_utils.tel.tel_test_utils import ensure_phone_idle
28from acts.test_utils.tel.tel_test_utils import verify_active_call_number
29from acts.test_utils.tel.tel_voice_utils import phone_setup_voice_3g
30from acts.test_utils.tel.tel_voice_utils import phone_idle_3g
31from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_3g
32
33MAX_NUMBER_REDIALS = 20
34INCORRECT_STATE_MSG = "Caller not in correct state!"
35
36
37class TelLiveStressCallTest(BaseTestClass):
38    def __init__(self, controllers):
39        BaseTestClass.__init__(self, controllers)
40        self.tests = ("test_call_3g_stress", )
41
42    def setup_class(self):
43        self.ad_caller = self.android_devices[0]
44        self.stress_test_callee_number = self.user_params["call_server_number"]
45        self.phone_call_iteration = self.user_params["phone_call_iteration"]
46        return True
47
48    def setup_test(self):
49        # try removing lock
50        self.android_devices[0].droid.wakeLockAcquireBright()
51        self.android_devices[0].droid.wakeUpNow()
52        self.assert_true(
53            ensure_phone_default_state(self.log, self.ad_caller),
54            "Make sure phone is in default state")
55        return True
56
57    def teardown_test(self):
58        self.android_devices[0].droid.wakeLockRelease()
59        self.android_devices[0].droid.goToSleepNow()
60        self.assert_true(
61            ensure_phone_default_state(self.log, self.ad_caller),
62            "Make sure phone returns to default state")
63
64    """ Tests Begin """
65
66    def test_call_3g_stress(self):
67        """ 3G to 800 call test
68
69        Steps:
70        1. Make Sure PhoneA is in 3G mode.
71        2. Call from PhoneA to a 800 number, hang up on PhoneA.
72        3, Repeat 2 around 100 times based on the config setup
73
74        Expected Results:
75        1, Verify phone is at IDLE state
76        2, Verify the phone is at ACTIVE, if it is in dialing, then we retry
77        3, Verify the phone is IDLE after hung up
78
79        Returns:
80            True if pass; False if fail.
81        """
82        ad_caller = self.ad_caller
83        callee_number = self.stress_test_callee_number
84        self.assert_true(
85            phone_setup_voice_3g(self.log,
86                                 ad_caller), "Phone Failed to Set Up Properly.")
87
88        # Make sure phone is idle.
89        ensure_phone_idle(self.log, ad_caller)
90        self.assert_true(
91            phone_idle_3g(self.log, ad_caller), "DUT Failed to Reselect")
92
93        self.log.info("Call test:{} to {}".format(ad_caller.serial,
94                                                  callee_number))
95        subid_caller = ad_caller.droid.subscriptionGetDefaultVoiceSubId()
96
97        total_iteration = self.phone_call_iteration
98        current_iteration = 0
99        redial_time = 0
100        while current_iteration < total_iteration:
101            self.log.info("---> Call test: iteration {} redial {}<---"
102                          .format(current_iteration, redial_time))
103            self.log.info("Checking Telephony Manager Call State")
104            self.assert_true(
105                self._check_phone_call_status(
106                    ad_caller, tel_defines.TELEPHONY_STATE_IDLE),
107                INCORRECT_STATE_MSG)
108
109            self.log.info("Making a phone call")
110            self.assert_true(
111                initiate_call(self.log, ad_caller, callee_number),
112                "Initiate call failed.")
113
114            self.log.info("Ensure that all internal states are updated")
115            time.sleep(tel_defines.WAIT_TIME_ANDROID_STATE_SETTLING)
116            self.assert_true(
117                is_phone_in_call_3g(self.log, ad_caller), INCORRECT_STATE_MSG)
118            self.assert_true(
119                self._check_phone_call_status(
120                    ad_caller, tel_defines.TELEPHONY_STATE_OFFHOOK,
121                    tel_defines.CALL_STATE_DIALING), INCORRECT_STATE_MSG)
122
123            time.sleep(tel_defines.WAIT_TIME_IN_CALL)
124            self.log.info(
125                "Checking Telephony Manager Call State after waiting for a while")
126            if (self._check_phone_call_status(
127                    ad_caller, tel_defines.TELEPHONY_STATE_OFFHOOK,
128                    tel_defines.CALL_STATE_ACTIVE)):
129                current_iteration += 1
130                redial_time = 0
131            elif (self._check_phone_call_status(
132                    ad_caller, tel_defines.TELEPHONY_STATE_OFFHOOK,
133                    tel_defines.CALL_STATE_DIALING)):
134                self.log.info("The line is busy, try again")
135                redial_time += 1
136                if redial_time > MAX_NUMBER_REDIALS:
137                    self.assert_true(
138                        False, "Re-dial {} times and still having busy signal"
139                        .format(redial_time))
140            else:
141                self.assert_true(False, INCORRECT_STATE_MSG)
142                current_iteration += 1
143
144            self.log.info("Hang up phone for this iteration")
145            self.assert_true(
146                hangup_call(self.log, ad_caller), "Error in Hanging-Up Call")
147            time.sleep(tel_defines.WAIT_TIME_ANDROID_STATE_SETTLING)
148            self.log.info(
149                "Checking Telephony Manager Call State after hang up")
150            self.assert_true(
151                self._check_phone_call_status(
152                    ad_caller, tel_defines.TELEPHONY_STATE_IDLE),
153                INCORRECT_STATE_MSG)
154
155            ensure_phone_idle(self.log, ad_caller)
156
157    """ Tests End """
158
159    def _check_phone_call_status(self, ad, telecom_status, call_status=None):
160        """Check existing event until we get either "ACTIVE" or "DIALING" event
161        Args:
162            ad: Android object
163            telecome_status: expected telecom call state
164            call_status: expcted telecomcall call state
165
166        Return:
167            True if all the status are matching, False otherwise
168         """
169        # Checking phone call status
170        if ad.droid.telecomGetCallState() != telecom_status:
171            return False
172        if call_status:
173            call_list = ad.droid.telecomCallGetCallIds()
174            if not call_list:
175                return False
176            if not verify_active_call_number(self.log, ad, 1):
177                return False
178            call_id = call_list[0]
179            self.log.info("TelecomCall Call State {}"
180                          .format(ad.droid.telecomCallGetCallState(call_id)))
181            if ad.droid.telecomCallGetCallState(call_id) != call_status:
182                return False
183        return True
184
185
186if __name__ == "__main__":
187    pass
188