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