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
17import time
18from acts.test_utils.tel.tel_test_utils \
19              import sms_send_receive_verify, multithread_func
20from acts.utils import rand_ascii_str
21from acts.test_utils.tel.tel_subscription_utils \
22              import get_subid_from_slot_index, set_subid_for_message
23from acts.test_utils.tel.tel_defines \
24              import MULTI_SIM_CONFIG, WAIT_TIME_ANDROID_STATE_SETTLING
25from acts.test_decorators import test_tracker_info
26from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
27from acts.test_utils.tel.tel_voice_utils \
28              import phone_setup_voice_general_for_slot
29
30
31class TelLiveMSIMSmsTest(TelephonyBaseTest):
32    def setup_class(self):
33        super().setup_class()
34        self.numer_of_slots = 2
35        self.sim_config = { "config": MULTI_SIM_CONFIG,
36                            "number_of_sims": 2 }
37        self.message_lengths = (50, 160, 180)
38
39    def _sms_test_dsds(self, ads):
40        """Test SMS between two phones on multiple sub_id
41
42        Returns:
43            True if success.
44            False if failed.
45        """
46        for slot in range(self.sim_config["number_of_sims"]):
47            set_subid_for_message(
48                ads[0], get_subid_from_slot_index(self.log,ads[0],slot))
49            set_subid_for_message(
50                ads[1], get_subid_from_slot_index(self.log,ads[1],slot))
51            for length in self.message_lengths:
52                message_array = [rand_ascii_str(length)]
53                ads[0].log.info("SMS Test - length %s from slot %s to slot %s",
54                                 length, slot, slot)
55                if not sms_send_receive_verify(self.log, ads[0], ads[1],
56                                              message_array, slot_id_rx = slot):
57                    ads[0].log.warning(
58                        "SMS of length %s test failed from slot %s to slot %s",
59                         length, slot, slot)
60                    return False
61                ads[0].log.info("SMS Test - length %s from slot %s to slot %s",
62                                length, slot, 1-slot)
63                if not sms_send_receive_verify(self.log, ads[0], ads[1],
64                                            message_array, slot_id_rx = 1-slot):
65                    ads[0].log.warning(
66                        "SMS of length %s test failed from slot %s to slot %s",
67                        length, slot, 1-slot)
68                    return False
69                else:
70                    ads[0].log.info("SMS of length %s test succeeded", length)
71            self.log.info("SMS test of length %s characters succeeded.",
72                          self.message_lengths)
73        return True
74
75    @test_tracker_info(uuid="5c0b60d0-a963-4ccf-8c0a-3d968b99d3cd")
76    @TelephonyBaseTest.tel_test_wrap
77    def test_msim_sms_general(self):
78        """Test SMS basic function between two phone. Phones in any network.
79
80        Airplane mode is off.
81        Send SMS from PhoneA (sub_id 0 and 1) to PhoneB (sub_id 0 and 1)
82        Verify received message on PhoneB is correct.
83
84        Returns:
85            True if success.
86            False if failed.
87        """
88        ads = self.android_devices
89
90        tasks = [(phone_setup_voice_general_for_slot, (self.log, ads[0],0)),
91                 (phone_setup_voice_general_for_slot, (self.log, ads[1],0)),
92                 (phone_setup_voice_general_for_slot, (self.log, ads[0],1)),
93                 (phone_setup_voice_general_for_slot, (self.log, ads[1],1))
94                 ]
95
96        if not multithread_func(self.log, tasks):
97            self.log.error("Phone Failed to Set Up Properly.")
98            return False
99        time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING)
100
101        return self._sms_test_dsds(ads)
102
103