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_GSM = "android.hardware.telephony.gsm"; 69 70 static constexpr const char* FEATURE_TELEPHONY_CDMA = "android.hardware.telephony.cdma"; 71 72 static constexpr const char* FEATURE_TELEPHONY_IMS = "android.hardware.telephony.ims"; 73 74 static constexpr const char* FEATURE_TELEPHONY_CALLING = "android.hardware.telephony.calling"; 75 76 static constexpr const char* FEATURE_TELEPHONY_DATA = "android.hardware.telephony.data"; 77 78 static constexpr const char* FEATURE_TELEPHONY_MESSAGING = "android.hardware.telephony.messaging"; 79 80 static constexpr const char* FEATURE_TELEPHONY_SUBSCRIPTION = 81 "android.hardware.telephony.subscription"; 82 83 static constexpr const char* FEATURE_TELEPHONY_RADIO_ACCESS = 84 "android.hardware.telephony.radio.access"; 85 86 #define MODEM_EMERGENCY_CALL_ESTABLISH_TIME 3 87 #define MODEM_EMERGENCY_CALL_DISCONNECT_TIME 3 88 #define MODEM_SET_SIM_POWER_DELAY_IN_SECONDS 2 89 #define MODEM_SET_SIM_SLOT_MAPPING_DELAY_IN_SECONDS 6 90 91 #define RADIO_SERVICE_SLOT1_NAME "slot1" // HAL instance name for SIM slot 1 or single SIM device 92 #define RADIO_SERVICE_SLOT2_NAME "slot2" // HAL instance name for SIM slot 2 on dual SIM device 93 #define RADIO_SERVICE_SLOT3_NAME "slot3" // HAL instance name for SIM slot 3 on triple SIM device 94 95 /* 96 * Generate random serial number for radio test 97 */ 98 int GetRandomSerialNumber(); 99 100 /* 101 * Check multiple radio error codes which are possibly returned because of the different 102 * vendor/devices implementations. It allows optional checks for general errors or/and oem errors. 103 */ 104 ::testing::AssertionResult CheckAnyOfErrors(RadioError err, std::vector<RadioError> generalError, 105 CheckFlag flag = CHECK_DEFAULT); 106 107 /* 108 * Check if device supports feature. 109 */ 110 bool deviceSupportsFeature(const char* feature); 111 112 /* 113 * Check if device is in SsSs (Single SIM Single Standby). 114 */ 115 bool isSsSsEnabled(); 116 117 /* 118 * Check if device is in DSDS (Dual SIM Dual Standby). 119 */ 120 bool isDsDsEnabled(); 121 122 /* 123 * Check if device is in DSDA (Dual SIM Dual Active). 124 */ 125 bool isDsDaEnabled(); 126 127 /* 128 * Check if device is in TSTS (Triple SIM Triple Standby). 129 */ 130 bool isTsTsEnabled(); 131 132 /* 133 * Check if voice status is in emergency only. 134 */ 135 bool isVoiceEmergencyOnly(RegState state); 136 137 /* 138 * Check if voice status is in service. 139 */ 140 bool isVoiceInService(RegState state); 141 142 /* 143 * Check if service is valid for device configuration 144 */ 145 bool isServiceValidForDeviceConfiguration(std::string& serviceName); 146 147 /* 148 * Check if device is in Lte Connected status. 149 */ 150 bool isLteConnected(); 151 152 /** 153 * RadioServiceTest base class 154 */ 155 class RadioServiceTest : public ::testing::TestWithParam<std::string> { 156 protected: 157 std::shared_ptr<config::IRadioConfig> radio_config; 158 std::shared_ptr<sim::IRadioSim> radio_sim; 159 160 public: 161 void SetUp() override; 162 void TearDown() override; 163 164 /* Used as a mechanism to inform the test about data/event callback */ 165 void notify(int receivedSerial); 166 167 /* Test code calls this function to wait for response */ 168 std::cv_status wait(); 169 170 /* Get the radio HAL capabilities */ 171 bool getRadioHalCapabilities(); 172 173 /* Update SIM card status */ 174 void updateSimCardStatus(); 175 176 /* Update SIM slot status */ 177 void updateSimSlotStatus(int physicalSlotId); 178 179 private: 180 std::mutex mtx_; 181 std::condition_variable cv_; 182 }; 183