1 /*
2 * Copyright (C) 2019 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_3.h>
18
SetUp()19 void RadioHidlTest_v1_3::SetUp() {
20 radio_v1_3 = ::android::hardware::radio::V1_3::IRadio::getService(GetParam());
21 if (radio_v1_3 == NULL) {
22 sleep(60);
23 radio_v1_3 = ::android::hardware::radio::V1_3::IRadio::getService(GetParam());
24 }
25 ASSERT_NE(nullptr, radio_v1_3.get());
26
27 radioRsp_v1_3 = new (std::nothrow) RadioResponse_v1_3(*this);
28 ASSERT_NE(nullptr, radioRsp_v1_3.get());
29
30 count_ = 0;
31
32 radioInd_v1_3 = new (std::nothrow) RadioIndication_v1_3(*this);
33 ASSERT_NE(nullptr, radioInd_v1_3.get());
34
35 radio_v1_3->setResponseFunctions(radioRsp_v1_3, radioInd_v1_3);
36
37 updateSimCardStatus();
38 EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_3->rspInfo.type);
39 EXPECT_EQ(serial, radioRsp_v1_3->rspInfo.serial);
40 EXPECT_EQ(RadioError::NONE, radioRsp_v1_3->rspInfo.error);
41 }
42
43 /*
44 * Notify that the response message is received.
45 */
notify(int receivedSerial)46 void RadioHidlTest_v1_3::notify(int receivedSerial) {
47 std::unique_lock<std::mutex> lock(mtx_);
48 if (serial == receivedSerial) {
49 count_++;
50 cv_.notify_one();
51 }
52 }
53
54 /*
55 * Wait till the response message is notified or till TIMEOUT_PERIOD.
56 */
wait()57 std::cv_status RadioHidlTest_v1_3::wait() {
58 std::unique_lock<std::mutex> lock(mtx_);
59
60 std::cv_status status = std::cv_status::no_timeout;
61 auto now = std::chrono::system_clock::now();
62 while (count_ == 0) {
63 status = cv_.wait_until(lock, now + std::chrono::seconds(TIMEOUT_PERIOD));
64 if (status == std::cv_status::timeout) {
65 return status;
66 }
67 }
68 count_--;
69 return status;
70 }
71
updateSimCardStatus()72 void RadioHidlTest_v1_3::updateSimCardStatus() {
73 serial = GetRandomSerialNumber();
74 radio_v1_3->getIccCardStatus(serial);
75 EXPECT_EQ(std::cv_status::no_timeout, wait());
76 }