Sarah Chin | d2a4119 | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 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 <aidl/android/hardware/radio/config/IRadioConfig.h> |
| 18 | #include <android-base/logging.h> |
| 19 | #include <android/binder_manager.h> |
| 20 | |
| 21 | #include "radio_voice_utils.h" |
| 22 | |
| 23 | #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk()) |
| 24 | |
| 25 | void RadioVoiceTest::SetUp() { |
| 26 | std::string serviceName = GetParam(); |
| 27 | |
| 28 | if (!isServiceValidForDeviceConfiguration(serviceName)) { |
| 29 | ALOGI("Skipped the test due to device configuration."); |
| 30 | GTEST_SKIP(); |
| 31 | } |
| 32 | |
| 33 | radio_voice = IRadioVoice::fromBinder( |
| 34 | ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str()))); |
| 35 | ASSERT_NE(nullptr, radio_voice.get()); |
| 36 | |
| 37 | radioRsp_voice = ndk::SharedRefBase::make<RadioVoiceResponse>(*this); |
| 38 | ASSERT_NE(nullptr, radioRsp_voice.get()); |
| 39 | |
| 40 | count_ = 0; |
| 41 | |
| 42 | radioInd_voice = ndk::SharedRefBase::make<RadioVoiceIndication>(*this); |
| 43 | ASSERT_NE(nullptr, radioInd_voice.get()); |
| 44 | |
| 45 | radio_voice->setResponseFunctions(radioRsp_voice, radioInd_voice); |
| 46 | |
| 47 | // Assert IRadioConfig exists before testing |
| 48 | std::shared_ptr<aidl::android::hardware::radio::config::IRadioConfig> radioConfig = |
| 49 | aidl::android::hardware::radio::config::IRadioConfig::fromBinder( |
| 50 | ndk::SpAIBinder(AServiceManager_waitForService( |
| 51 | "android.hardware.radio.config.IRadioConfig/default"))); |
| 52 | ASSERT_NE(nullptr, radioConfig.get()); |
| 53 | } |
| 54 | |
| 55 | ndk::ScopedAStatus RadioVoiceTest::clearPotentialEstablishedCalls() { |
| 56 | // Get the current call Id to hangup the established emergency call. |
| 57 | serial = GetRandomSerialNumber(); |
| 58 | radio_voice->getCurrentCalls(serial); |
| 59 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 60 | |
| 61 | // Hang up to disconnect the established call channels. |
| 62 | for (const Call& call : radioRsp_voice->currentCalls) { |
| 63 | serial = GetRandomSerialNumber(); |
| 64 | radio_voice->hangup(serial, call.index); |
| 65 | ALOGI("Hang up to disconnect the established call channel: %d", call.index); |
| 66 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 67 | // Give some time for modem to disconnect the established call channel. |
| 68 | sleep(MODEM_EMERGENCY_CALL_DISCONNECT_TIME); |
| 69 | } |
| 70 | |
| 71 | // Verify there are no more current calls. |
| 72 | serial = GetRandomSerialNumber(); |
| 73 | radio_voice->getCurrentCalls(serial); |
| 74 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 75 | EXPECT_EQ(0, radioRsp_voice->currentCalls.size()); |
| 76 | return ndk::ScopedAStatus::ok(); |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | * Test IRadioVoice.emergencyDial() for the response returned. |
| 81 | */ |
| 82 | TEST_P(RadioVoiceTest, emergencyDial) { |
| 83 | if (!deviceSupportsFeature(FEATURE_VOICE_CALL)) { |
| 84 | ALOGI("Skipping emergencyDial because voice call is not supported in device"); |
| 85 | return; |
| 86 | } else if (!deviceSupportsFeature(FEATURE_TELEPHONY_GSM) && |
| 87 | !deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) { |
| 88 | ALOGI("Skipping emergencyDial because gsm/cdma radio is not supported in device"); |
| 89 | return; |
| 90 | } else { |
| 91 | ALOGI("Running emergencyDial because voice call is supported in device"); |
| 92 | } |
| 93 | |
| 94 | serial = GetRandomSerialNumber(); |
| 95 | |
| 96 | Dial dialInfo; |
| 97 | dialInfo.address = std::string("911"); |
| 98 | EmergencyServiceCategory categories = EmergencyServiceCategory::UNSPECIFIED; |
| 99 | std::vector<std::string> urns = {""}; |
| 100 | EmergencyCallRouting routing = EmergencyCallRouting::UNKNOWN; |
| 101 | |
| 102 | ndk::ScopedAStatus res = |
| 103 | radio_voice->emergencyDial(serial, dialInfo, categories, urns, routing, true, true); |
| 104 | ASSERT_OK(res); |
| 105 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 106 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_voice->rspInfo.type); |
| 107 | EXPECT_EQ(serial, radioRsp_voice->rspInfo.serial); |
| 108 | |
| 109 | ALOGI("emergencyDial, rspInfo.error = %s\n", toString(radioRsp_voice->rspInfo.error).c_str()); |
| 110 | |
| 111 | RadioError rspEmergencyDial = radioRsp_voice->rspInfo.error; |
| 112 | // In DSDS or TSTS, we only check the result if the current slot is IN_SERVICE |
| 113 | // or Emergency_Only. |
| 114 | if (isDsDsEnabled() || isTsTsEnabled()) { |
| 115 | // TODO(b/210712359): maybe create a local RadioNetwork instance |
| 116 | /** |
| 117 | serial = GetRandomSerialNumber(); |
| 118 | radio_v1_6->getVoiceRegistrationState(serial); |
| 119 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 120 | if (isVoiceEmergencyOnly(radioRsp_v1_6->voiceRegResp.regState) || |
| 121 | isVoiceInService(radioRsp_v1_6->voiceRegResp.regState)) { |
| 122 | EXPECT_EQ(RadioError::NONE, rspEmergencyDial); |
| 123 | } |
| 124 | **/ |
| 125 | } else { |
| 126 | EXPECT_EQ(RadioError::NONE, rspEmergencyDial); |
| 127 | } |
| 128 | |
| 129 | // Give some time for modem to establish the emergency call channel. |
| 130 | sleep(MODEM_EMERGENCY_CALL_ESTABLISH_TIME); |
| 131 | |
| 132 | // Disconnect all the potential established calls to prevent them affecting other tests. |
| 133 | clearPotentialEstablishedCalls(); |
| 134 | } |
| 135 | |
| 136 | /* |
| 137 | * Test IRadioVoice.emergencyDial() with specified service and its response returned. |
| 138 | */ |
| 139 | TEST_P(RadioVoiceTest, emergencyDial_withServices) { |
| 140 | if (!deviceSupportsFeature(FEATURE_VOICE_CALL)) { |
| 141 | ALOGI("Skipping emergencyDial because voice call is not supported in device"); |
| 142 | return; |
| 143 | } else if (!deviceSupportsFeature(FEATURE_TELEPHONY_GSM) && |
| 144 | !deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) { |
| 145 | ALOGI("Skipping emergencyDial because gsm/cdma radio is not supported in device"); |
| 146 | return; |
| 147 | } else { |
| 148 | ALOGI("Running emergencyDial because voice call is supported in device"); |
| 149 | } |
| 150 | |
| 151 | serial = GetRandomSerialNumber(); |
| 152 | |
| 153 | Dial dialInfo; |
| 154 | dialInfo.address = std::string("911"); |
| 155 | EmergencyServiceCategory categories = EmergencyServiceCategory::AMBULANCE; |
| 156 | std::vector<std::string> urns = {"urn:service:sos.ambulance"}; |
| 157 | EmergencyCallRouting routing = EmergencyCallRouting::UNKNOWN; |
| 158 | |
| 159 | ndk::ScopedAStatus res = |
| 160 | radio_voice->emergencyDial(serial, dialInfo, categories, urns, routing, true, true); |
| 161 | ASSERT_OK(res); |
| 162 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 163 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_voice->rspInfo.type); |
| 164 | EXPECT_EQ(serial, radioRsp_voice->rspInfo.serial); |
| 165 | |
| 166 | ALOGI("emergencyDial_withServices, rspInfo.error = %s\n", |
| 167 | toString(radioRsp_voice->rspInfo.error).c_str()); |
| 168 | RadioError rspEmergencyDial = radioRsp_voice->rspInfo.error; |
| 169 | |
| 170 | // In DSDS or TSTS, we only check the result if the current slot is IN_SERVICE |
| 171 | // or Emergency_Only. |
| 172 | if (isDsDsEnabled() || isTsTsEnabled()) { |
| 173 | // TODO(b/210712359): maybe create a local RadioNetwork instance |
| 174 | /** |
| 175 | serial = GetRandomSerialNumber(); |
| 176 | radio_v1_6->getVoiceRegistrationState_1_6(serial); |
| 177 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 178 | if (isVoiceEmergencyOnly(radioRsp_v1_6->voiceRegResp.regState) || |
| 179 | isVoiceInService(radioRsp_v1_6->voiceRegResp.regState)) { |
| 180 | EXPECT_EQ(RadioError::NONE, rspEmergencyDial); |
| 181 | } |
| 182 | **/ |
| 183 | } else { |
| 184 | EXPECT_EQ(RadioError::NONE, rspEmergencyDial); |
| 185 | } |
| 186 | // Give some time for modem to establish the emergency call channel. |
| 187 | sleep(MODEM_EMERGENCY_CALL_ESTABLISH_TIME); |
| 188 | |
| 189 | // Disconnect all the potential established calls to prevent them affecting other tests. |
| 190 | clearPotentialEstablishedCalls(); |
| 191 | } |
| 192 | |
| 193 | /* |
| 194 | * Test IRadioVoice.emergencyDial() with known emergency call routing and its response returned. |
| 195 | */ |
| 196 | TEST_P(RadioVoiceTest, emergencyDial_withEmergencyRouting) { |
| 197 | if (!deviceSupportsFeature(FEATURE_VOICE_CALL)) { |
| 198 | ALOGI("Skipping emergencyDial because voice call is not supported in device"); |
| 199 | return; |
| 200 | } else if (!deviceSupportsFeature(FEATURE_TELEPHONY_GSM) && |
| 201 | !deviceSupportsFeature(FEATURE_TELEPHONY_CDMA)) { |
| 202 | ALOGI("Skipping emergencyDial because gsm/cdma radio is not supported in device"); |
| 203 | return; |
| 204 | } else { |
| 205 | ALOGI("Running emergencyDial because voice call is supported in device"); |
| 206 | } |
| 207 | |
| 208 | serial = GetRandomSerialNumber(); |
| 209 | |
| 210 | Dial dialInfo; |
| 211 | dialInfo.address = std::string("911"); |
| 212 | EmergencyServiceCategory categories = EmergencyServiceCategory::UNSPECIFIED; |
| 213 | std::vector<std::string> urns = {""}; |
| 214 | EmergencyCallRouting routing = EmergencyCallRouting::EMERGENCY; |
| 215 | |
| 216 | ndk::ScopedAStatus res = |
| 217 | radio_voice->emergencyDial(serial, dialInfo, categories, urns, routing, true, true); |
| 218 | ASSERT_OK(res); |
| 219 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 220 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_voice->rspInfo.type); |
| 221 | EXPECT_EQ(serial, radioRsp_voice->rspInfo.serial); |
| 222 | |
| 223 | ALOGI("emergencyDial_withEmergencyRouting, rspInfo.error = %s\n", |
| 224 | toString(radioRsp_voice->rspInfo.error).c_str()); |
| 225 | RadioError rspEmergencyDial = radioRsp_voice->rspInfo.error; |
| 226 | |
| 227 | // In DSDS or TSTS, we only check the result if the current slot is IN_SERVICE |
| 228 | // or Emergency_Only. |
| 229 | if (isDsDsEnabled() || isTsTsEnabled()) { |
| 230 | // TODO(b/210712359): maybe create a local RadioNetwork instance |
| 231 | /** |
| 232 | serial = GetRandomSerialNumber(); |
| 233 | radio_v1_6->getVoiceRegistrationState_1_6(serial); |
| 234 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 235 | if (isVoiceEmergencyOnly(radioRsp_v1_6->voiceRegResp.regState) || |
| 236 | isVoiceInService(radioRsp_v1_6->voiceRegResp.regState)) { |
| 237 | EXPECT_EQ(RadioError::NONE, rspEmergencyDial); |
| 238 | } |
| 239 | **/ |
| 240 | } else { |
| 241 | EXPECT_EQ(RadioError::NONE, rspEmergencyDial); |
| 242 | } |
| 243 | |
| 244 | // Give some time for modem to establish the emergency call channel. |
| 245 | sleep(MODEM_EMERGENCY_CALL_ESTABLISH_TIME); |
| 246 | |
| 247 | // Disconnect all the potential established calls to prevent them affecting other tests. |
| 248 | clearPotentialEstablishedCalls(); |
| 249 | } |
| 250 | |
| 251 | /* |
| 252 | * Test IRadioVoice.getCurrentCalls() for the response returned. |
| 253 | */ |
| 254 | TEST_P(RadioVoiceTest, getCurrentCalls) { |
| 255 | serial = GetRandomSerialNumber(); |
| 256 | radio_voice->getCurrentCalls(serial); |
| 257 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 258 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_voice->rspInfo.type); |
| 259 | EXPECT_EQ(serial, radioRsp_voice->rspInfo.serial); |
| 260 | EXPECT_EQ(RadioError::NONE, radioRsp_voice->rspInfo.error); |
| 261 | } |