• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <android-base/logging.h>
18 #include <android/binder_manager.h>
19 
20 #include "radio_config_utils.h"
21 
22 #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
23 
SetUp()24 void RadioConfigTest::SetUp() {
25     std::string serviceName = GetParam();
26 
27     radio_config = IRadioConfig::fromBinder(
28             ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
29     ASSERT_NE(nullptr, radio_config.get());
30 
31     radioRsp_config = ndk::SharedRefBase::make<RadioConfigResponse>(*this);
32     ASSERT_NE(nullptr, radioRsp_config.get());
33 
34     count_ = 0;
35 
36     radioInd_config = ndk::SharedRefBase::make<RadioConfigIndication>(*this);
37     ASSERT_NE(nullptr, radioInd_config.get());
38 
39     radio_config->setResponseFunctions(radioRsp_config, radioInd_config);
40 }
41 
updateSimSlotStatus()42 void RadioConfigTest::updateSimSlotStatus() {
43     serial = GetRandomSerialNumber();
44     radio_config->getSimSlotsStatus(serial);
45     EXPECT_EQ(std::cv_status::no_timeout, wait());
46     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
47     EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
48     EXPECT_EQ(RadioError::NONE, radioRsp_config->rspInfo.error);
49     // assuming only 1 slot
50     for (const SimSlotStatus& slotStatusResponse : radioRsp_config->simSlotStatus) {
51         slotStatus = slotStatusResponse;
52     }
53 }
54 
55 /*
56  * Test IRadioConfig.getHalDeviceCapabilities() for the response returned.
57  */
TEST_P(RadioConfigTest,getHalDeviceCapabilities)58 TEST_P(RadioConfigTest, getHalDeviceCapabilities) {
59     serial = GetRandomSerialNumber();
60     ndk::ScopedAStatus res = radio_config->getHalDeviceCapabilities(serial);
61     ASSERT_OK(res);
62     EXPECT_EQ(std::cv_status::no_timeout, wait());
63     ALOGI("getHalDeviceCapabilities, rspInfo.error = %s\n",
64           toString(radioRsp_config->rspInfo.error).c_str());
65 }
66 
67 /*
68  * Test IRadioConfig.getSimSlotsStatus() for the response returned.
69  */
TEST_P(RadioConfigTest,getSimSlotsStatus)70 TEST_P(RadioConfigTest, getSimSlotsStatus) {
71     serial = GetRandomSerialNumber();
72     ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial);
73     ASSERT_OK(res);
74     EXPECT_EQ(std::cv_status::no_timeout, wait());
75     ALOGI("getSimSlotsStatus, rspInfo.error = %s\n",
76           toString(radioRsp_config->rspInfo.error).c_str());
77 }
78 
79 /*
80  * Test IRadioConfig.getPhoneCapability() for the response returned.
81  */
TEST_P(RadioConfigTest,getPhoneCapability)82 TEST_P(RadioConfigTest, getPhoneCapability) {
83     serial = GetRandomSerialNumber();
84     ndk::ScopedAStatus res = radio_config->getPhoneCapability(serial);
85     ASSERT_OK(res);
86     EXPECT_EQ(std::cv_status::no_timeout, wait());
87     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
88     EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
89     ALOGI("getPhoneCapability, rspInfo.error = %s\n",
90           toString(radioRsp_config->rspInfo.error).c_str());
91 
92     ASSERT_TRUE(CheckAnyOfErrors(
93             radioRsp_config->rspInfo.error,
94             {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
95 
96     if (radioRsp_config->rspInfo.error == RadioError ::NONE) {
97         // maxActiveData should be greater than or equal to maxActiveInternetData.
98         EXPECT_GE(radioRsp_config->phoneCap.maxActiveData,
99                   radioRsp_config->phoneCap.maxActiveInternetData);
100         // maxActiveData and maxActiveInternetData should be 0 or positive numbers.
101         EXPECT_GE(radioRsp_config->phoneCap.maxActiveInternetData, 0);
102     }
103 }
104 
105 /*
106  * Test IRadioConfig.setPreferredDataModem() for the response returned.
107  */
TEST_P(RadioConfigTest,setPreferredDataModem)108 TEST_P(RadioConfigTest, setPreferredDataModem) {
109     serial = GetRandomSerialNumber();
110     ndk::ScopedAStatus res = radio_config->getPhoneCapability(serial);
111     ASSERT_OK(res);
112     EXPECT_EQ(std::cv_status::no_timeout, wait());
113     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
114     EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
115     ALOGI("getPhoneCapability, rspInfo.error = %s\n",
116           toString(radioRsp_config->rspInfo.error).c_str());
117 
118     ASSERT_TRUE(CheckAnyOfErrors(
119             radioRsp_config->rspInfo.error,
120             {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
121 
122     if (radioRsp_config->rspInfo.error != RadioError ::NONE) {
123         return;
124     }
125 
126     if (radioRsp_config->phoneCap.logicalModemIds.size() == 0) {
127         return;
128     }
129 
130     // We get phoneCapability. Send setPreferredDataModem command
131     serial = GetRandomSerialNumber();
132     uint8_t modemId = radioRsp_config->phoneCap.logicalModemIds[0];
133     res = radio_config->setPreferredDataModem(serial, modemId);
134 
135     ASSERT_OK(res);
136     EXPECT_EQ(std::cv_status::no_timeout, wait());
137     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
138     EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
139     ALOGI("setPreferredDataModem, rspInfo.error = %s\n",
140           toString(radioRsp_config->rspInfo.error).c_str());
141 
142     ASSERT_TRUE(CheckAnyOfErrors(
143             radioRsp_config->rspInfo.error,
144             {RadioError::NONE, RadioError::RADIO_NOT_AVAILABLE, RadioError::INTERNAL_ERR}));
145 }
146 
147 /*
148  * Test IRadioConfig.setPreferredDataModem() with invalid arguments.
149  */
TEST_P(RadioConfigTest,setPreferredDataModem_invalidArgument)150 TEST_P(RadioConfigTest, setPreferredDataModem_invalidArgument) {
151     serial = GetRandomSerialNumber();
152     uint8_t modemId = -1;
153     ndk::ScopedAStatus res = radio_config->setPreferredDataModem(serial, modemId);
154 
155     ASSERT_OK(res);
156     EXPECT_EQ(std::cv_status::no_timeout, wait());
157     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
158     EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
159     ALOGI("setPreferredDataModem, rspInfo.error = %s\n",
160           toString(radioRsp_config->rspInfo.error).c_str());
161 
162     ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error,
163                                  {RadioError::INVALID_ARGUMENTS, RadioError::RADIO_NOT_AVAILABLE,
164                                   RadioError::INTERNAL_ERR}));
165 }
166 
167 /*
168  * Test IRadioConfig.setSimSlotsMapping() for the response returned.
169  */
TEST_P(RadioConfigTest,setSimSlotsMapping)170 TEST_P(RadioConfigTest, setSimSlotsMapping) {
171     // get slot status and set SIM slots mapping based on the result.
172     updateSimSlotStatus();
173     if (radioRsp_config->rspInfo.error == RadioError::NONE) {
174         SlotPortMapping slotPortMapping;
175         // put invalid value at first and adjust by slotStatusResponse.
176         slotPortMapping.physicalSlotId = -1;
177         slotPortMapping.portId = -1;
178         std::vector<SlotPortMapping> slotPortMappingList = {slotPortMapping};
179         if (isDsDsEnabled() || isDsDaEnabled()) {
180             slotPortMappingList.push_back(slotPortMapping);
181         } else if (isTsTsEnabled()) {
182             slotPortMappingList.push_back(slotPortMapping);
183             slotPortMappingList.push_back(slotPortMapping);
184         }
185         for (size_t i = 0; i < radioRsp_config->simSlotStatus.size(); i++) {
186             ASSERT_TRUE(radioRsp_config->simSlotStatus[i].portInfo.size() > 0);
187             for (size_t j = 0; j < radioRsp_config->simSlotStatus[i].portInfo.size(); j++) {
188                 if (radioRsp_config->simSlotStatus[i].portInfo[j].portActive) {
189                     int32_t logicalSlotId =
190                             radioRsp_config->simSlotStatus[i].portInfo[j].logicalSlotId;
191                     // logicalSlotId should be 0 or positive numbers if the port
192                     // is active.
193                     EXPECT_GE(logicalSlotId, 0);
194                     // logicalSlotId should be less than the maximum number of
195                     // supported SIM slots.
196                     EXPECT_LT(logicalSlotId, slotPortMappingList.size());
197                     if (logicalSlotId >= 0 && logicalSlotId < slotPortMappingList.size()) {
198                         slotPortMappingList[logicalSlotId].physicalSlotId = i;
199                         slotPortMappingList[logicalSlotId].portId = j;
200                     }
201                 }
202             }
203         }
204 
205         // set SIM slots mapping
206         for (size_t i = 0; i < slotPortMappingList.size(); i++) {
207             // physicalSlotId and portId should be 0 or positive numbers for the
208             // input of setSimSlotsMapping.
209             EXPECT_GE(slotPortMappingList[i].physicalSlotId, 0);
210             EXPECT_GE(slotPortMappingList[i].portId, 0);
211         }
212         serial = GetRandomSerialNumber();
213         ndk::ScopedAStatus res = radio_config->setSimSlotsMapping(serial, slotPortMappingList);
214         ASSERT_OK(res);
215         EXPECT_EQ(std::cv_status::no_timeout, wait());
216         EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
217         EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
218         ALOGI("setSimSlotsMapping, rspInfo.error = %s\n",
219               toString(radioRsp_config->rspInfo.error).c_str());
220         ASSERT_TRUE(CheckAnyOfErrors(radioRsp_config->rspInfo.error, {RadioError::NONE}));
221 
222         // Give some time for modem to fully switch SIM configuration
223         sleep(MODEM_SET_SIM_SLOT_MAPPING_DELAY_IN_SECONDS);
224     }
225 }
226 
227 /*
228  * Test IRadioConfig.getSimSlotStatus() for the response returned.
229  */
230 
TEST_P(RadioConfigTest,checkPortInfoExistsAndPortActive)231 TEST_P(RadioConfigTest, checkPortInfoExistsAndPortActive) {
232     serial = GetRandomSerialNumber();
233     ndk::ScopedAStatus res = radio_config->getSimSlotsStatus(serial);
234     ASSERT_OK(res);
235     ALOGI("getSimSlotsStatus, rspInfo.error = %s\n",
236           toString(radioRsp_config->rspInfo.error).c_str());
237     EXPECT_EQ(std::cv_status::no_timeout, wait());
238     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_config->rspInfo.type);
239     EXPECT_EQ(serial, radioRsp_config->rspInfo.serial);
240     if (radioRsp_config->rspInfo.error == RadioError::NONE) {
241         uint8_t simCount = 0;
242         // check if cardState is present, portInfo size should be more than 0
243         for (const SimSlotStatus& slotStatusResponse : radioRsp_config->simSlotStatus) {
244             if (slotStatusResponse.cardState == CardStatus::STATE_PRESENT) {
245                 ASSERT_TRUE(slotStatusResponse.portInfo.size() > 0);
246                 for (const SimPortInfo& simPortInfo : slotStatusResponse.portInfo) {
247                     if (simPortInfo.portActive) {
248                         simCount++;
249                     }
250                 }
251             }
252         }
253         if (isSsSsEnabled()) {
254             EXPECT_EQ(1, simCount);
255         } else if (isDsDsEnabled() || isDsDaEnabled()) {
256             EXPECT_EQ(2, simCount);
257         } else if (isTsTsEnabled()) {
258             EXPECT_EQ(3, simCount);
259         }
260     }
261 }
262