1 /*
2  * Copyright (C) 2020 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_6.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_6::SetUp() {
44     hidl_string serviceName = GetParam();
45 
46     if (!isServiceValidForDeviceConfiguration(serviceName)) {
47         ALOGI("Skipped the test due to device configuration.");
48         GTEST_SKIP();
49     }
50 
51     radio_v1_6 = android::hardware::radio::V1_6::IRadio::getService(serviceName);
52     ASSERT_NE(nullptr, radio_v1_6.get());
53 
54     radioRsp_v1_6 = new (std::nothrow) RadioResponse_v1_6(*this);
55     ASSERT_NE(nullptr, radioRsp_v1_6.get());
56 
57     count_ = 0;
58 
59     radioInd_v1_6 = new (std::nothrow) RadioIndication_v1_6(*this);
60     ASSERT_NE(nullptr, radioInd_v1_6.get());
61 
62     radio_v1_6->setResponseFunctions(radioRsp_v1_6, radioInd_v1_6);
63 
64     updateSimCardStatus();
65     EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_6->rspInfo_v1_0.type);
66     EXPECT_EQ(serial, radioRsp_v1_6->rspInfo_v1_0.serial);
67     EXPECT_EQ(::android::hardware::radio::V1_0::RadioError::NONE,
68               radioRsp_v1_6->rspInfo_v1_0.error);
69 
70     sp<::android::hardware::radio::config::V1_1::IRadioConfig> radioConfig =
71             ::android::hardware::radio::config::V1_1::IRadioConfig::getService();
72     /* Enforce Vts testing with RadioConfig is existed. */
73     ASSERT_NE(nullptr, radioConfig.get());
74 
75     /* Enforce Vts Testing with Sim Status Present only. */
76     EXPECT_EQ(CardState::PRESENT, cardStatus.base.base.base.cardState);
77 }
78 
clearPotentialEstablishedCalls()79 void RadioHidlTest_v1_6::clearPotentialEstablishedCalls() {
80     // Get the current call Id to hangup the established emergency call.
81     serial = GetRandomSerialNumber();
82     radio_v1_6->getCurrentCalls_1_6(serial);
83     EXPECT_EQ(std::cv_status::no_timeout, wait());
84 
85     // Hang up to disconnect the established call channels.
86     for (const ::android::hardware::radio::V1_6::Call& call : radioRsp_v1_6->currentCalls) {
87         serial = GetRandomSerialNumber();
88         radio_v1_6->hangup(serial, call.base.base.index);
89         ALOGI("Hang up to disconnect the established call channel: %d", call.base.base.index);
90         EXPECT_EQ(std::cv_status::no_timeout, wait());
91         // Give some time for modem to disconnect the established call channel.
92         sleep(MODEM_EMERGENCY_CALL_DISCONNECT_TIME);
93     }
94 
95     // Verify there are no more current calls.
96     serial = GetRandomSerialNumber();
97     radio_v1_6->getCurrentCalls_1_6(serial);
98     EXPECT_EQ(std::cv_status::no_timeout, wait());
99     EXPECT_EQ(0, radioRsp_v1_6->currentCalls.size());
100 }
101 
updateSimCardStatus()102 void RadioHidlTest_v1_6::updateSimCardStatus() {
103     serial = GetRandomSerialNumber();
104     radio_v1_6->getIccCardStatus(serial);
105     EXPECT_EQ(std::cv_status::no_timeout, wait());
106 }
107 
getDataCallList()108 void RadioHidlTest_v1_6::getDataCallList() {
109     serial = GetRandomSerialNumber();
110     radio_v1_6->getDataCallList_1_6(serial);
111     EXPECT_EQ(std::cv_status::no_timeout, wait());
112 }
113 
114 /**
115  * Specific features on the Radio Hal rely on Radio Hal Capabilities.  The VTS
116  * tests related to that features must not run if the related capability is
117  * disabled.
118  * <p/>
119  * Typical usage within VTS:
120  * if (getRadioHalCapabilities()) return;
121  */
getRadioHalCapabilities()122 bool RadioHidlTest_v1_6::getRadioHalCapabilities() {
123     sp<::android::hardware::radio::config::V1_3::IRadioConfig> radioConfig_v1_3 =
124             ::android::hardware::radio::config::V1_3::IRadioConfig::getService();
125     if (radioConfig_v1_3.get() == nullptr) {
126         // If v1_3 isn't present, the values are initialized to false
127         return false;
128     } else {
129         // Get radioHalDeviceCapabilities from the radio config
130         sp<RadioConfigResponse> radioConfigRsp = new (std::nothrow) RadioConfigResponse(*this);
131         radioConfig_v1_3->setResponseFunctions(radioConfigRsp, nullptr);
132         serial = GetRandomSerialNumber();
133 
134         radioConfig_v1_3->getHalDeviceCapabilities(serial);
135         EXPECT_EQ(std::cv_status::no_timeout, wait());
136         return radioConfigRsp->modemReducedFeatureSet1;
137     }
138 }
139