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