1 /*
2 * Copyright (C) 2018 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 <radio_hidl_hal_utils_v1_4.h>
18
isServiceValidForDeviceConfiguration(hidl_string & serviceName)19 bool isServiceValidForDeviceConfiguration(hidl_string& serviceName) {
20 if (isSsSsEnabled()) {
21 // Device is configured as SSSS.
22 if (serviceName != RADIO_SERVICE_SLOT1_NAME) {
23 ALOGI("%s instance is not valid for SSSS device.", serviceName.c_str());
24 return false;
25 }
26 } else if (isDsDsEnabled()) {
27 // Device is configured as DSDS.
28 if (serviceName != RADIO_SERVICE_SLOT1_NAME && serviceName != RADIO_SERVICE_SLOT2_NAME) {
29 ALOGI("%s instance is not valid for DSDS device.", serviceName.c_str());
30 return false;
31 }
32 } else if (isTsTsEnabled()) {
33 // Device is configured as TSTS.
34 if (serviceName != RADIO_SERVICE_SLOT1_NAME && serviceName != RADIO_SERVICE_SLOT2_NAME &&
35 serviceName != RADIO_SERVICE_SLOT3_NAME) {
36 ALOGI("%s instance is not valid for TSTS device.", serviceName.c_str());
37 return false;
38 }
39 }
40 return true;
41 }
42
SetUp()43 void RadioHidlTest_v1_4::SetUp() {
44 hidl_string serviceName = GetParam();
45 if (!isServiceValidForDeviceConfiguration(serviceName)) {
46 ALOGI("Skipped the test due to device configuration.");
47 GTEST_SKIP();
48 }
49 radio_v1_4 = ::android::hardware::radio::V1_4::IRadio::getService(serviceName);
50
51 if (radio_v1_4 == NULL) {
52 sleep(60);
53 radio_v1_4 = ::android::hardware::radio::V1_4::IRadio::getService(serviceName);
54 }
55 ASSERT_NE(nullptr, radio_v1_4.get());
56
57 radioRsp_v1_4 = new (std::nothrow) RadioResponse_v1_4(*this);
58 ASSERT_NE(nullptr, radioRsp_v1_4.get());
59
60 count_ = 0;
61
62 radioInd_v1_4 = new (std::nothrow) RadioIndication_v1_4(*this);
63 ASSERT_NE(nullptr, radioInd_v1_4.get());
64
65 radio_v1_4->setResponseFunctions(radioRsp_v1_4, radioInd_v1_4);
66
67 updateSimCardStatus();
68 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_4->rspInfo.type);
69 EXPECT_EQ(serial, radioRsp_v1_4->rspInfo.serial);
70 EXPECT_EQ(RadioError::NONE, radioRsp_v1_4->rspInfo.error);
71
72 sp<::android::hardware::radio::config::V1_1::IRadioConfig> radioConfig =
73 ::android::hardware::radio::config::V1_1::IRadioConfig::getService();
74
75 /* Enforce Vts tesing with RadioConfig is existed. */
76 ASSERT_NE(nullptr, radioConfig.get());
77
78 /* Enforce Vts Testing with Sim Status Present only. */
79 EXPECT_EQ(CardState::PRESENT, cardStatus.base.base.cardState);
80 }
81
82 /*
83 * Notify that the response message is received.
84 */
notify(int receivedSerial)85 void RadioHidlTest_v1_4::notify(int receivedSerial) {
86 std::unique_lock<std::mutex> lock(mtx_);
87 if (serial == receivedSerial) {
88 count_++;
89 cv_.notify_one();
90 }
91 }
92
93 /*
94 * Wait till the response message is notified or till TIMEOUT_PERIOD.
95 */
wait()96 std::cv_status RadioHidlTest_v1_4::wait() {
97 std::unique_lock<std::mutex> lock(mtx_);
98
99 std::cv_status status = std::cv_status::no_timeout;
100 auto now = std::chrono::system_clock::now();
101 while (count_ == 0) {
102 status = cv_.wait_until(lock, now + std::chrono::seconds(TIMEOUT_PERIOD));
103 if (status == std::cv_status::timeout) {
104 return status;
105 }
106 }
107 count_--;
108 return status;
109 }
110
clearPotentialEstablishedCalls()111 void RadioHidlTest_v1_4::clearPotentialEstablishedCalls() {
112 // Get the current call Id to hangup the established emergency call.
113 serial = GetRandomSerialNumber();
114 radio_v1_4->getCurrentCalls(serial);
115 EXPECT_EQ(std::cv_status::no_timeout, wait());
116
117 // Hang up to disconnect the established call channels.
118 for (const ::android::hardware::radio::V1_2::Call& call : radioRsp_v1_4->currentCalls) {
119 serial = GetRandomSerialNumber();
120 radio_v1_4->hangup(serial, call.base.index);
121 ALOGI("Hang up to disconnect the established call channel: %d", call.base.index);
122 EXPECT_EQ(std::cv_status::no_timeout, wait());
123 // Give some time for modem to disconnect the established call channel.
124 sleep(MODEM_EMERGENCY_CALL_DISCONNECT_TIME);
125 }
126
127 // Verify there are no more current calls.
128 serial = GetRandomSerialNumber();
129 radio_v1_4->getCurrentCalls(serial);
130 EXPECT_EQ(std::cv_status::no_timeout, wait());
131 EXPECT_EQ(0, radioRsp_v1_4->currentCalls.size());
132 }
133
updateSimCardStatus()134 void RadioHidlTest_v1_4::updateSimCardStatus() {
135 serial = GetRandomSerialNumber();
136 radio_v1_4->getIccCardStatus(serial);
137 EXPECT_EQ(std::cv_status::no_timeout, wait());
138 }
139
stopNetworkScan()140 void RadioHidlTest_v1_4::stopNetworkScan() {
141 serial = GetRandomSerialNumber();
142 radio_v1_4->stopNetworkScan(serial);
143 EXPECT_EQ(std::cv_status::no_timeout, wait());
144 }
145