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_modem_utils.h" |
| 22 | |
| 23 | #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk()) |
| 24 | |
| 25 | void RadioModemTest::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_modem = IRadioModem::fromBinder( |
| 34 | ndk::SpAIBinder(AServiceManager_waitForService(GetParam().c_str()))); |
| 35 | ASSERT_NE(nullptr, radio_modem.get()); |
| 36 | |
| 37 | radioRsp_modem = ndk::SharedRefBase::make<RadioModemResponse>(*this); |
| 38 | ASSERT_NE(nullptr, radioRsp_modem.get()); |
| 39 | |
| 40 | count_ = 0; |
| 41 | |
| 42 | radioInd_modem = ndk::SharedRefBase::make<RadioModemIndication>(*this); |
| 43 | ASSERT_NE(nullptr, radioInd_modem.get()); |
| 44 | |
| 45 | radio_modem->setResponseFunctions(radioRsp_modem, radioInd_modem); |
| 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 | /* |
| 56 | * Test IRadioModem.setRadioPower() for the response returned. |
| 57 | */ |
| 58 | TEST_P(RadioModemTest, setRadioPower_emergencyCall_cancelled) { |
| 59 | // Set radio power to off. |
| 60 | serial = GetRandomSerialNumber(); |
| 61 | radio_modem->setRadioPower(serial, false, false, false); |
| 62 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 63 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 64 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 65 | EXPECT_EQ(RadioError::NONE, radioRsp_modem->rspInfo.error); |
| 66 | |
| 67 | // Set radio power to on with forEmergencyCall being true. This should put modem to only scan |
| 68 | // emergency call bands. |
| 69 | serial = GetRandomSerialNumber(); |
| 70 | radio_modem->setRadioPower(serial, true, true, true); |
| 71 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 72 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 73 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 74 | EXPECT_EQ(RadioError::NONE, radioRsp_modem->rspInfo.error); |
| 75 | |
| 76 | // Set radio power to on with forEmergencyCall being false. This should put modem in regular |
| 77 | // operation modem. |
| 78 | serial = GetRandomSerialNumber(); |
| 79 | radio_modem->setRadioPower(serial, true, false, false); |
| 80 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 81 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 82 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 83 | EXPECT_EQ(RadioError::NONE, radioRsp_modem->rspInfo.error); |
| 84 | } |