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
SetUp()19 void RadioHidlTest_v1_4::SetUp() {
20 radio_v1_4 = ::testing::VtsHalHidlTargetTestBase::getService<
21 ::android::hardware::radio::V1_4::IRadio>(
22 RadioHidlEnvironment::Instance()
23 ->getServiceName<::android::hardware::radio::V1_4::IRadio>(
24 hidl_string(RADIO_SERVICE_NAME)));
25 if (radio_v1_4 == NULL) {
26 sleep(60);
27 radio_v1_4 = ::testing::VtsHalHidlTargetTestBase::getService<
28 ::android::hardware::radio::V1_4::IRadio>(
29 RadioHidlEnvironment::Instance()
30 ->getServiceName<::android::hardware::radio::V1_4::IRadio>(
31 hidl_string(RADIO_SERVICE_NAME)));
32 }
33 ASSERT_NE(nullptr, radio_v1_4.get());
34
35 radioRsp_v1_4 = new (std::nothrow) RadioResponse_v1_4(*this);
36 ASSERT_NE(nullptr, radioRsp_v1_4.get());
37
38 count_ = 0;
39
40 radioInd_v1_4 = new (std::nothrow) RadioIndication_v1_4(*this);
41 ASSERT_NE(nullptr, radioInd_v1_4.get());
42
43 radio_v1_4->setResponseFunctions(radioRsp_v1_4, radioInd_v1_4);
44
45 updateSimCardStatus();
46 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_4->rspInfo.type);
47 EXPECT_EQ(serial, radioRsp_v1_4->rspInfo.serial);
48 EXPECT_EQ(RadioError::NONE, radioRsp_v1_4->rspInfo.error);
49
50 sp<::android::hardware::radio::config::V1_1::IRadioConfig> radioConfig =
51 ::testing::VtsHalHidlTargetTestBase::getService<
52 ::android::hardware::radio::config::V1_1::IRadioConfig>();
53
54 /* Enforce Vts tesing with RadioConfig is existed. */
55 ASSERT_NE(nullptr, radioConfig.get());
56
57 /* Enforce Vts Testing with Sim Status Present only. */
58 EXPECT_EQ(CardState::PRESENT, cardStatus.base.base.cardState);
59 }
60
61 /*
62 * Notify that the response message is received.
63 */
notify(int receivedSerial)64 void RadioHidlTest_v1_4::notify(int receivedSerial) {
65 std::unique_lock<std::mutex> lock(mtx_);
66 if (serial == receivedSerial) {
67 count_++;
68 cv_.notify_one();
69 }
70 }
71
72 /*
73 * Wait till the response message is notified or till TIMEOUT_PERIOD.
74 */
wait()75 std::cv_status RadioHidlTest_v1_4::wait() {
76 std::unique_lock<std::mutex> lock(mtx_);
77
78 std::cv_status status = std::cv_status::no_timeout;
79 auto now = std::chrono::system_clock::now();
80 while (count_ == 0) {
81 status = cv_.wait_until(lock, now + std::chrono::seconds(TIMEOUT_PERIOD));
82 if (status == std::cv_status::timeout) {
83 return status;
84 }
85 }
86 count_--;
87 return status;
88 }
89
clearPotentialEstablishedCalls()90 void RadioHidlTest_v1_4::clearPotentialEstablishedCalls() {
91 // Get the current call Id to hangup the established emergency call.
92 serial = GetRandomSerialNumber();
93 radio_v1_4->getCurrentCalls(serial);
94 EXPECT_EQ(std::cv_status::no_timeout, wait());
95
96 // Hang up to disconnect the established call channels.
97 for (const ::android::hardware::radio::V1_2::Call& call : radioRsp_v1_4->currentCalls) {
98 serial = GetRandomSerialNumber();
99 radio_v1_4->hangup(serial, call.base.index);
100 ALOGI("Hang up to disconnect the established call channel: %d", call.base.index);
101 EXPECT_EQ(std::cv_status::no_timeout, wait());
102 // Give some time for modem to disconnect the established call channel.
103 sleep(MODEM_EMERGENCY_CALL_DISCONNECT_TIME);
104 }
105 }
106
updateSimCardStatus()107 void RadioHidlTest_v1_4::updateSimCardStatus() {
108 serial = GetRandomSerialNumber();
109 radio_v1_4->getIccCardStatus(serial);
110 EXPECT_EQ(std::cv_status::no_timeout, wait());
111 }
112