1#!/usr/bin/env python3.4
2#
3#   Copyright 2018 - 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 ViWiFi live call test
18"""
19
20import time
21from queue import Empty
22from acts.test_decorators import test_tracker_info
23from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
24from acts.test_utils.tel.tel_defines import AUDIO_ROUTE_EARPIECE
25from acts.test_utils.tel.tel_defines import AUDIO_ROUTE_SPEAKER
26from acts.test_utils.tel.tel_defines import CALL_STATE_ACTIVE
27from acts.test_utils.tel.tel_defines import CALL_STATE_HOLDING
28from acts.test_utils.tel.tel_defines import CALL_CAPABILITY_MANAGE_CONFERENCE
29from acts.test_utils.tel.tel_defines import CALL_CAPABILITY_MERGE_CONFERENCE
30from acts.test_utils.tel.tel_defines import CALL_CAPABILITY_SWAP_CONFERENCE
31from acts.test_utils.tel.tel_defines import CALL_PROPERTY_CONFERENCE
32from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_VIDEO_SESSION_EVENT
33from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_VOLTE_ENABLED
34from acts.test_utils.tel.tel_defines import VT_STATE_AUDIO_ONLY
35from acts.test_utils.tel.tel_defines import VT_STATE_BIDIRECTIONAL
36from acts.test_utils.tel.tel_defines import VT_STATE_BIDIRECTIONAL_PAUSED
37from acts.test_utils.tel.tel_defines import VT_VIDEO_QUALITY_DEFAULT
38from acts.test_utils.tel.tel_defines import VT_STATE_RX_ENABLED
39from acts.test_utils.tel.tel_defines import VT_STATE_TX_ENABLED
40from acts.test_utils.tel.tel_defines import WAIT_TIME_ANDROID_STATE_SETTLING
41from acts.test_utils.tel.tel_defines import WAIT_TIME_IN_CALL
42from acts.test_utils.tel.tel_defines import EVENT_VIDEO_SESSION_EVENT
43from acts.test_utils.tel.tel_defines import EventTelecomVideoCallSessionEvent
44from acts.test_utils.tel.tel_defines import SESSION_EVENT_RX_PAUSE
45from acts.test_utils.tel.tel_defines import SESSION_EVENT_RX_RESUME
46from acts.test_utils.tel.tel_defines import WFC_MODE_WIFI_PREFERRED
47from acts.test_utils.tel.tel_test_utils import call_setup_teardown
48from acts.test_utils.tel.tel_test_utils import disconnect_call_by_id
49from acts.test_utils.tel.tel_test_utils import hangup_call
50from acts.test_utils.tel.tel_test_utils import multithread_func
51from acts.test_utils.tel.tel_test_utils import num_active_calls
52from acts.test_utils.tel.tel_test_utils import verify_http_connection
53from acts.test_utils.tel.tel_test_utils import verify_incall_state
54from acts.test_utils.tel.tel_test_utils import wait_for_video_enabled
55from acts.test_utils.tel.tel_video_utils import get_call_id_in_video_state
56from acts.test_utils.tel.tel_video_utils import \
57    is_phone_in_call_video_bidirectional
58from acts.test_utils.tel.tel_video_utils import \
59    is_phone_in_call_viwifi_bidirectional
60from acts.test_utils.tel.tel_video_utils import is_phone_in_call_voice_hd
61from acts.test_utils.tel.tel_video_utils import phone_setup_video
62from acts.test_utils.tel.tel_video_utils import \
63    verify_video_call_in_expected_state
64from acts.test_utils.tel.tel_video_utils import video_call_downgrade
65from acts.test_utils.tel.tel_video_utils import video_call_modify_video
66from acts.test_utils.tel.tel_video_utils import video_call_setup_teardown
67from acts.test_utils.tel.tel_voice_utils import get_audio_route
68from acts.test_utils.tel.tel_voice_utils import is_phone_in_call_volte
69from acts.test_utils.tel.tel_voice_utils import phone_setup_volte
70from acts.test_utils.tel.tel_voice_utils import set_audio_route
71from acts.test_utils.tel.tel_voice_utils import get_cep_conference_call_id
72from acts.test_utils.tel.tel_voice_utils import phone_setup_iwlan
73
74DEFAULT_LONG_DURATION_CALL_TOTAL_DURATION = 1 * 60 * 60  # default 1 hour
75
76
77class TelWifiVideoTest(TelephonyBaseTest):
78    def __init__(self, controllers):
79        TelephonyBaseTest.__init__(self, controllers)
80
81        self.stress_test_number = self.get_stress_test_number()
82        self.wifi_network_ssid = self.user_params.get("wifi_network_ssid")
83        self.wifi_network_pass = self.user_params.get("wifi_network_pass")
84
85        self.long_duration_call_total_duration = self.user_params.get(
86            "long_duration_call_total_duration",
87            DEFAULT_LONG_DURATION_CALL_TOTAL_DURATION)
88
89    """ Tests Begin """
90
91    @test_tracker_info(uuid="375e9b88-8d8e-45fe-8502-e4da4147682d")
92    @TelephonyBaseTest.tel_test_wrap
93    def test_call_video_to_video_wifi_preferred(self):
94        """ Test ViWifi<->ViWifi call functionality.
95
96        Make Sure PhoneA is in iWLAN mode (with Video Calling).
97        Make Sure PhoneB is in iWLAN mode (with Video Calling).
98        Connect to Wifi
99        Call from PhoneA to PhoneB as Bi-Directional Video,
100        Accept on PhoneB as video call, hang up on PhoneA.
101
102        Returns:
103            True if pass; False if fail.
104        """
105        ads = self.android_devices
106        tasks = [
107            (phone_setup_iwlan,
108             (self.log, ads[0], False, WFC_MODE_WIFI_PREFERRED,
109              self.wifi_network_ssid, self.wifi_network_pass)),
110            (phone_setup_iwlan,
111             (self.log, ads[1], False, WFC_MODE_WIFI_PREFERRED,
112              self.wifi_network_ssid, self.wifi_network_pass)),
113        ]
114        if not multithread_func(self.log, tasks):
115            self.log.error("Phone Failed to Set Up Properly.")
116            return False
117
118        if not video_call_setup_teardown(
119                self.log,
120                ads[0],
121                ads[1],
122                ads[0],
123                video_state=VT_STATE_BIDIRECTIONAL,
124                verify_caller_func=is_phone_in_call_viwifi_bidirectional,
125                verify_callee_func=is_phone_in_call_viwifi_bidirectional):
126            self.log.error("Failed to setup+teardown a call")
127            return False
128
129        return True
130
131    @test_tracker_info(uuid="0c6782b4-fa81-4c18-a7bf-9f0f5cc05d6d")
132    @TelephonyBaseTest.tel_test_wrap
133    def test_call_video_to_video_wifi_preferred_apm(self):
134        """ Test ViWifi<->ViWifi call functionality in APM Mode.
135
136        Make Sure PhoneA is in iWLAN mode (with Video Calling).
137        Make Sure PhoneB is in iWLAN mode (with Video Calling).
138        Turn on APM Mode
139        Connect to Wifi
140        Call from PhoneA to PhoneB as Bi-Directional Video,
141        Accept on PhoneB as video call, hang up on PhoneA.
142
143        Returns:
144            True if pass; False if fail.
145        """
146        ads = self.android_devices
147        tasks = [
148            (phone_setup_iwlan,
149             (self.log, ads[0], True, WFC_MODE_WIFI_PREFERRED,
150              self.wifi_network_ssid, self.wifi_network_pass)),
151            (phone_setup_iwlan,
152             (self.log, ads[1], True, WFC_MODE_WIFI_PREFERRED,
153              self.wifi_network_ssid, self.wifi_network_pass)),
154        ]
155        if not multithread_func(self.log, tasks):
156            self.log.error("Phone Failed to Set Up Properly.")
157            return False
158
159        if not video_call_setup_teardown(
160                self.log,
161                ads[0],
162                ads[1],
163                ads[0],
164                video_state=VT_STATE_BIDIRECTIONAL,
165                verify_caller_func=is_phone_in_call_viwifi_bidirectional,
166                verify_callee_func=is_phone_in_call_viwifi_bidirectional):
167            self.log.error("Failed to setup+teardown a call")
168            return False
169
170        return True
171
172
173""" Tests End """
174