• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3# Copyright (C) 2016 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# 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, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
16"""
17Automated tests for the testing send and receive SMS commands in MAP profile.
18"""
19
20import time
21import queue
22
23import acts
24from acts.test_decorators import test_tracker_info
25from acts_contrib.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
26from acts_contrib.test_utils.bt.BluetoothCarHfpBaseTest import BluetoothCarHfpBaseTest
27from acts_contrib.test_utils.bt import bt_test_utils
28from acts_contrib.test_utils.bt import BtEnum
29from acts_contrib.test_utils.tel.tel_defines import EventSmsReceived
30from acts_contrib.test_utils.tel.tel_defines import EventSmsSentSuccess
31from acts_contrib.test_utils.tel.tel_defines import EventSmsDeliverSuccess
32from acts_contrib.test_utils.tel.tel_test_utils import get_phone_number
33from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode_by_adb
34
35EVENT_MAP_MESSAGE_RECEIVED = "MapMessageReceived"
36TIMEOUT = 2000
37MESSAGE_TO_SEND = "Don't text and Drive!"
38
39SEND_FAILED_NO_MCE = 1
40SEND_FAILED_NO_NETWORK = 2
41
42
43class BtCarMapMceTest(BluetoothCarHfpBaseTest):
44    def setup_class(self):
45        if not super(BtCarMapMceTest, self).setup_class():
46            return False
47        # MAP roles
48        # Carkit device
49        self.MCE = self.hf
50        # Phone device
51        self.MSE = self.ag
52        # Remote device
53        self.REMOTE = self.re
54        time.sleep(4)
55        return True
56
57    def setup_test(self):
58        for dut in self.android_devices:
59            toggle_airplane_mode_by_adb(self.log, dut, False)
60
61        if not bt_test_utils.connect_pri_to_sec(
62            self.MCE, self.MSE, set([BtEnum.BluetoothProfile.MAP_MCE.value])):
63            return False
64        # Grace time for connection to complete.
65        time.sleep(3)
66
67    def teardown_class(self):
68        for dut in self.android_devices:
69            toggle_airplane_mode_by_adb(self.log, dut, False)
70
71    def message_delivered(self, device):
72        try:
73            self.MCE.ed.pop_event(EventSmsDeliverSuccess, 15)
74        except queue.Empty:
75            self.log.error("Message failed to be delivered.")
76            return False
77        return True
78
79    def send_message(self, remotes):
80        self.REMOTE.droid.smsStartTrackingIncomingSmsMessage()
81        destinations = []
82        for phone in remotes:
83            destinations.append("tel:{}".format(
84                get_phone_number(self.log, phone)))
85        self.log.info(destinations)
86        self.MCE.droid.mapSendMessage(
87            self.MSE.droid.bluetoothGetLocalAddress(), destinations,
88            MESSAGE_TO_SEND)
89        try:
90            self.MCE.ed.pop_event(EventSmsSentSuccess, 15)
91        except queue.Empty:
92            self.MCE.log.error("Message failed to send.")
93            return False
94
95        try:
96            receivedMessage = self.REMOTE.ed.pop_event(EventSmsReceived, 15)
97            self.REMOTE.log.info("Received a message: {}".format(
98                receivedMessage['data']['Text']))
99        except queue.Empty:
100            self.REMOTE.log.error("Remote did not receive message.")
101            return False
102
103        if MESSAGE_TO_SEND != receivedMessage['data']['Text']:
104            self.log.error("Messages don't match.")
105            self.log.error("Sent     {}".format(MESSAGE_TO_SEND))
106            self.log.error("Received {}".format(receivedMessage['data'][
107                'Text']))
108            return False
109        return True
110
111    @test_tracker_info(uuid='0858347a-e649-4f18-85b6-6990cc311dee')
112    @BluetoothBaseTest.bt_test_wrap
113    def test_send_message(self):
114        return self.send_message([self.REMOTE])
115
116    @test_tracker_info(uuid='b25caa53-3c7f-4cfa-a0ec-df9a8f925fe5')
117    @BluetoothBaseTest.bt_test_wrap
118    def test_receive_message(self):
119        self.MSE.log.info("Start Tracking SMS.")
120        self.MSE.droid.smsStartTrackingIncomingSmsMessage()
121        self.REMOTE.log.info("Ready to send")
122        self.REMOTE.droid.smsSendTextMessage(
123            get_phone_number(self.log, self.MSE), "test_receive_message",
124            False)
125        self.MCE.log.info("Check inbound Messages.")
126        receivedMessage = self.MCE.ed.pop_event(EVENT_MAP_MESSAGE_RECEIVED, 15)
127        self.MCE.log.info(receivedMessage['data'])
128        return True
129
130    @test_tracker_info(uuid='5b7b3ded-0a1a-470f-b119-9a03bc092805')
131    @BluetoothBaseTest.bt_test_wrap
132    def test_send_message_failure_no_cellular(self):
133        if not toggle_airplane_mode_by_adb(self.log, self.MSE, True):
134            return False
135        bt_test_utils.reset_bluetooth([self.MSE])
136        bt_test_utils.connect_pri_to_sec(
137            self.MCE, self.MSE, set([BtEnum.BluetoothProfile.MAP_MCE.value]))
138        return not self.send_message([self.REMOTE])
139
140    @test_tracker_info(uuid='19444142-1d07-47dc-860b-f435cba46fca')
141    @BluetoothBaseTest.bt_test_wrap
142    def test_send_message_failure_no_map_connection(self):
143        if not bt_test_utils.disconnect_pri_from_sec(
144            self.MCE, self.MSE, [BtEnum.BluetoothProfile.MAP_MCE.value]):
145            return False
146        return not self.send_message([self.REMOTE])
147
148    @test_tracker_info(uuid='c7e569c0-9f6c-49a4-8132-14bc544ccb53')
149    @BluetoothBaseTest.bt_test_wrap
150    def test_send_message_failure_no_bluetooth(self):
151        if not toggle_airplane_mode_by_adb(self.log, self.MSE, True):
152            return False
153        try:
154            bt_test_utils.connect_pri_to_sec(
155                self.MCE, self.MSE,
156                set([BtEnum.BluetoothProfile.MAP_MCE.value]))
157        except acts.controllers.android.SL4AAPIError:
158            self.MCE.log.info("Failed to connect as expected")
159        return not self.send_message([self.REMOTE])
160
161    @test_tracker_info(uuid='8cdb4a54-3f18-482f-be3d-acda9c4cbeed')
162    @BluetoothBaseTest.bt_test_wrap
163    def test_disconnect_failure_send_message(self):
164        addr = self.MSE.droid.bluetoothGetLocalAddress()
165        if bt_test_utils.is_map_mce_device_connected(self.MCE, addr):
166            connected = True
167        disconnected = bt_test_utils.disconnect_pri_from_sec(
168            self.MCE, self.MSE, [BtEnum.BluetoothProfile.MAP_MCE.value])
169        # Grace time for the disconnection to complete.
170        time.sleep(3)
171        if not bt_test_utils.is_map_mce_device_connected(self.MCE, addr):
172            disconnected = True
173        self.MCE.log.info("Connected = {}, Disconnected = {}".format(
174            connected, disconnected))
175        return connected and disconnected and not self.send_message(
176            [self.REMOTE])
177
178    @test_tracker_info(uuid='2d79a896-b1c1-4fb7-9924-db8b5c698be5')
179    @BluetoothBaseTest.bt_test_wrap
180    def manual_test_send_message_to_contact(self):
181        contacts = self.MCE.droid.contactsGetContactIds()
182        self.log.info(contacts)
183        selected_contact = self.MCE.droid.contactsDisplayContactPickList()
184        if selected_contact:
185            return self.MCE.droid.mapSendMessage(
186                self.MSE.droid.bluetoothGetLocalAddress(),
187                selected_contact['data'], "Don't Text and Drive!")
188        return False
189
190    @test_tracker_info(uuid='8ce9a7dd-3b5e-4aee-a897-30740e2439c3')
191    @BluetoothBaseTest.bt_test_wrap
192    def test_send_message_to_multiple_phones(self):
193        return self.send_message([self.REMOTE, self.REMOTE])
194