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 #pragma once 18 19 #include <aidl/Gtest.h> 20 #include <aidl/Vintf.h> 21 #include <aidl/android/hardware/radio/RadioError.h> 22 #include <aidl/android/hardware/radio/config/IRadioConfig.h> 23 #include <aidl/android/hardware/radio/config/SimSlotStatus.h> 24 #include <aidl/android/hardware/radio/network/RegState.h> 25 #include <aidl/android/hardware/radio/sim/CardStatus.h> 26 #include <aidl/android/hardware/radio/sim/IRadioSim.h> 27 #include <com_android_internal_telephony_flags.h> 28 #include <utils/Log.h> 29 30 using namespace aidl::android::hardware::radio; 31 using aidl::android::hardware::radio::config::SimSlotStatus; 32 using aidl::android::hardware::radio::network::RegState; 33 using aidl::android::hardware::radio::sim::CardStatus; 34 35 namespace telephony_flags = com::android::internal::telephony::flags; 36 37 extern CardStatus cardStatus; 38 extern SimSlotStatus slotStatus; 39 extern int serial; 40 extern int count_; 41 42 /* 43 * MACRO used to skip test case when radio response return error REQUEST_NOT_SUPPORTED 44 * on HAL versions which has deprecated the request interfaces. The MACRO can only be used 45 * AFTER receiving radio response. 46 */ 47 #define SKIP_TEST_IF_REQUEST_NOT_SUPPORTED_WITH_HAL(__ver__, __radio__, __radioRsp__) \ 48 do { \ 49 sp<::android::hardware::radio::V##__ver__::IRadio> __radio = \ 50 ::android::hardware::radio::V##__ver__::IRadio::castFrom(__radio__); \ 51 if (__radio && __radioRsp__->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED) { \ 52 GTEST_SKIP() << "REQUEST_NOT_SUPPORTED"; \ 53 } \ 54 } while (0) 55 56 enum CheckFlag { 57 CHECK_DEFAULT = 0, 58 CHECK_GENERAL_ERROR = 1, 59 CHECK_OEM_ERROR = 2, 60 CHECK_OEM_AND_GENERAL_ERROR = 3, 61 CHECK_SAP_ERROR = 4, 62 }; 63 64 static constexpr const char* FEATURE_VOICE_CALL = "android.software.connectionservice"; 65 66 static constexpr const char* FEATURE_TELEPHONY = "android.hardware.telephony"; 67 68 static constexpr const char* FEATURE_TELEPHONY_IMS = "android.hardware.telephony.ims"; 69 70 static constexpr const char* FEATURE_TELEPHONY_CALLING = "android.hardware.telephony.calling"; 71 72 static constexpr const char* FEATURE_TELEPHONY_DATA = "android.hardware.telephony.data"; 73 74 static constexpr const char* FEATURE_TELEPHONY_MESSAGING = "android.hardware.telephony.messaging"; 75 76 static constexpr const char* FEATURE_TELEPHONY_SUBSCRIPTION = 77 "android.hardware.telephony.subscription"; 78 79 static constexpr const char* FEATURE_TELEPHONY_RADIO_ACCESS = 80 "android.hardware.telephony.radio.access"; 81 82 #define MODEM_EMERGENCY_CALL_ESTABLISH_TIME 3 83 #define MODEM_EMERGENCY_CALL_DISCONNECT_TIME 3 84 #define MODEM_SET_SIM_POWER_DELAY_IN_SECONDS 2 85 #define MODEM_SET_SIM_SLOT_MAPPING_DELAY_IN_SECONDS 6 86 87 #define RADIO_SERVICE_SLOT1_NAME "slot1" // HAL instance name for SIM slot 1 or single SIM device 88 #define RADIO_SERVICE_SLOT2_NAME "slot2" // HAL instance name for SIM slot 2 on dual SIM device 89 #define RADIO_SERVICE_SLOT3_NAME "slot3" // HAL instance name for SIM slot 3 on triple SIM device 90 91 /* 92 * Generate random serial number for radio test 93 */ 94 int GetRandomSerialNumber(); 95 96 /* 97 * Check multiple radio error codes which are possibly returned because of the different 98 * vendor/devices implementations. It allows optional checks for general errors or/and oem errors. 99 */ 100 ::testing::AssertionResult CheckAnyOfErrors(RadioError err, std::vector<RadioError> generalError, 101 CheckFlag flag = CHECK_DEFAULT); 102 103 /* 104 * Check if device supports feature. 105 */ 106 bool deviceSupportsFeature(const char* feature); 107 108 /* 109 * Check if device is in SsSs (Single SIM Single Standby). 110 */ 111 bool isSsSsEnabled(); 112 113 /* 114 * Check if device is in DSDS (Dual SIM Dual Standby). 115 */ 116 bool isDsDsEnabled(); 117 118 /* 119 * Check if device is in DSDA (Dual SIM Dual Active). 120 */ 121 bool isDsDaEnabled(); 122 123 /* 124 * Check if device is in TSTS (Triple SIM Triple Standby). 125 */ 126 bool isTsTsEnabled(); 127 128 /* 129 * Check if voice status is in emergency only. 130 */ 131 bool isVoiceEmergencyOnly(RegState state); 132 133 /* 134 * Check if voice status is in service. 135 */ 136 bool isVoiceInService(RegState state); 137 138 /* 139 * Check if service is valid for device configuration 140 */ 141 bool isServiceValidForDeviceConfiguration(std::string& serviceName); 142 143 /* 144 * Check if device is in Lte Connected status. 145 */ 146 bool isLteConnected(); 147 148 /** 149 * RadioServiceTest base class 150 */ 151 class RadioServiceTest : public ::testing::TestWithParam<std::string> { 152 protected: 153 std::shared_ptr<config::IRadioConfig> radio_config; 154 std::shared_ptr<sim::IRadioSim> radio_sim; 155 156 public: 157 void SetUp() override; 158 void TearDown() override; 159 160 /* Used as a mechanism to inform the test about data/event callback */ 161 void notify(int receivedSerial); 162 163 /* Test code calls this function to wait for response */ 164 std::cv_status wait(); 165 166 /* Get the radio HAL capabilities */ 167 bool getRadioHalCapabilities(); 168 169 /* Update SIM card status */ 170 void updateSimCardStatus(); 171 172 /* Update SIM slot status */ 173 void updateSimSlotStatus(int physicalSlotId); 174 175 private: 176 std::mutex mtx_; 177 std::condition_variable cv_; 178 }; 179