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 | |
Sarah Chin | 91997ac | 2021-12-29 00:35:12 -0800 | [diff] [blame^] | 47 | // Assert IRadioSim exists and SIM is present before testing |
| 48 | radio_sim = sim::IRadioSim::fromBinder(ndk::SpAIBinder( |
| 49 | AServiceManager_waitForService("android.hardware.radio.sim.IRadioSim/slot1"))); |
| 50 | ASSERT_NE(nullptr, radio_sim.get()); |
| 51 | updateSimCardStatus(); |
| 52 | EXPECT_EQ(CardStatus::STATE_PRESENT, cardStatus.cardState); |
| 53 | |
Sarah Chin | d2a4119 | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 54 | // Assert IRadioConfig exists before testing |
Sarah Chin | 91997ac | 2021-12-29 00:35:12 -0800 | [diff] [blame^] | 55 | radio_config = config::IRadioConfig::fromBinder(ndk::SpAIBinder( |
| 56 | AServiceManager_waitForService("android.hardware.radio.config.IRadioConfig/default"))); |
| 57 | ASSERT_NE(nullptr, radio_config.get()); |
Sarah Chin | d2a4119 | 2021-12-21 11:34:00 -0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /* |
| 61 | * Test IRadioModem.setRadioPower() for the response returned. |
| 62 | */ |
| 63 | TEST_P(RadioModemTest, setRadioPower_emergencyCall_cancelled) { |
| 64 | // Set radio power to off. |
| 65 | serial = GetRandomSerialNumber(); |
| 66 | radio_modem->setRadioPower(serial, false, false, false); |
| 67 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 68 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 69 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 70 | EXPECT_EQ(RadioError::NONE, radioRsp_modem->rspInfo.error); |
| 71 | |
| 72 | // Set radio power to on with forEmergencyCall being true. This should put modem to only scan |
| 73 | // emergency call bands. |
| 74 | serial = GetRandomSerialNumber(); |
| 75 | radio_modem->setRadioPower(serial, true, true, true); |
| 76 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 77 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 78 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 79 | EXPECT_EQ(RadioError::NONE, radioRsp_modem->rspInfo.error); |
| 80 | |
| 81 | // Set radio power to on with forEmergencyCall being false. This should put modem in regular |
| 82 | // operation modem. |
| 83 | serial = GetRandomSerialNumber(); |
| 84 | radio_modem->setRadioPower(serial, true, false, false); |
| 85 | EXPECT_EQ(std::cv_status::no_timeout, wait()); |
| 86 | EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_modem->rspInfo.type); |
| 87 | EXPECT_EQ(serial, radioRsp_modem->rspInfo.serial); |
| 88 | EXPECT_EQ(RadioError::NONE, radioRsp_modem->rspInfo.error); |
| 89 | } |