1 /*
2  * Copyright (C) 2017 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 <android-base/logging.h>
18 
19 #include <log/log.h>
20 #include <chrono>
21 #include <condition_variable>
22 #include <mutex>
23 
24 #include <android/hardware/radio/1.0/IRadio.h>
25 #include <android/hardware/radio/1.0/IRadioIndication.h>
26 #include <android/hardware/radio/1.0/IRadioResponse.h>
27 #include <android/hardware/radio/1.0/types.h>
28 #include <gtest/gtest.h>
29 
30 #include "vts_test_util.h"
31 
32 using namespace ::android::hardware::radio::V1_0;
33 
34 using ::android::hardware::hidl_string;
35 using ::android::hardware::hidl_vec;
36 using ::android::hardware::Return;
37 using ::android::hardware::Void;
38 using ::android::sp;
39 
40 #define TIMEOUT_PERIOD 75
41 #define RADIO_SERVICE_NAME "slot1"
42 #define SKIP_TEST_IF_REQUEST_NOT_SUPPORTED_WITH_HAL_VERSION_AT_LEAST(__ver__) \
43     SKIP_TEST_IF_REQUEST_NOT_SUPPORTED_WITH_HAL(__ver__, radio, radioRsp)
44 
45 // HAL instance name for SIM slot 1 or single SIM device
46 #define RADIO_SERVICE_SLOT1_NAME "slot1"
47 
48 // HAL instance name for SIM slot 2 on dual SIM device
49 #define RADIO_SERVICE_SLOT2_NAME "slot2"
50 
51 // HAL instance name for SIM slot 3 on triple SIM device
52 #define RADIO_SERVICE_SLOT3_NAME "slot3"
53 
54 class RadioHidlTest;
55 extern CardStatus cardStatus;
56 
57 /* Callback class for radio response */
58 class RadioResponse : public IRadioResponse {
59    protected:
60     RadioHidlTest& parent;
61 
62    public:
63     RadioResponseInfo rspInfo;
64     hidl_string imsi;
65     IccIoResult iccIoResult;
66     int channelId;
67 
68     // Sms
69     SendSmsResult sendSmsResult;
70     hidl_string smscAddress;
71     uint32_t writeSmsToSimIndex;
72     uint32_t writeSmsToRuimIndex;
73 
74     // Data
75     DataRegStateResult dataRegResp;
76 
77     RadioResponse(RadioHidlTest& parent);
78 
79     virtual ~RadioResponse() = default;
80 
81     Return<void> getIccCardStatusResponse(const RadioResponseInfo& info,
82                                           const CardStatus& cardStatus);
83 
84     Return<void> supplyIccPinForAppResponse(const RadioResponseInfo& info,
85                                             int32_t remainingRetries);
86 
87     Return<void> supplyIccPukForAppResponse(const RadioResponseInfo& info,
88                                             int32_t remainingRetries);
89 
90     Return<void> supplyIccPin2ForAppResponse(const RadioResponseInfo& info,
91                                              int32_t remainingRetries);
92 
93     Return<void> supplyIccPuk2ForAppResponse(const RadioResponseInfo& info,
94                                              int32_t remainingRetries);
95 
96     Return<void> changeIccPinForAppResponse(const RadioResponseInfo& info,
97                                             int32_t remainingRetries);
98 
99     Return<void> changeIccPin2ForAppResponse(const RadioResponseInfo& info,
100                                              int32_t remainingRetries);
101 
102     Return<void> supplyNetworkDepersonalizationResponse(const RadioResponseInfo& info,
103                                                         int32_t remainingRetries);
104 
105     Return<void> getCurrentCallsResponse(const RadioResponseInfo& info,
106                                          const ::android::hardware::hidl_vec<Call>& calls);
107 
108     Return<void> dialResponse(const RadioResponseInfo& info);
109 
110     Return<void> getIMSIForAppResponse(const RadioResponseInfo& info,
111                                        const ::android::hardware::hidl_string& imsi);
112 
113     Return<void> hangupConnectionResponse(const RadioResponseInfo& info);
114 
115     Return<void> hangupWaitingOrBackgroundResponse(const RadioResponseInfo& info);
116 
117     Return<void> hangupForegroundResumeBackgroundResponse(const RadioResponseInfo& info);
118 
119     Return<void> switchWaitingOrHoldingAndActiveResponse(const RadioResponseInfo& info);
120 
121     Return<void> conferenceResponse(const RadioResponseInfo& info);
122 
123     Return<void> rejectCallResponse(const RadioResponseInfo& info);
124 
125     Return<void> getLastCallFailCauseResponse(const RadioResponseInfo& info,
126                                               const LastCallFailCauseInfo& failCauseInfo);
127 
128     Return<void> getSignalStrengthResponse(const RadioResponseInfo& info,
129                                            const SignalStrength& sigStrength);
130 
131     Return<void> getVoiceRegistrationStateResponse(const RadioResponseInfo& info,
132                                                    const VoiceRegStateResult& voiceRegResponse);
133 
134     Return<void> getDataRegistrationStateResponse(const RadioResponseInfo& info,
135                                                   const DataRegStateResult& dataRegResponse);
136 
137     Return<void> getOperatorResponse(const RadioResponseInfo& info,
138                                      const ::android::hardware::hidl_string& longName,
139                                      const ::android::hardware::hidl_string& shortName,
140                                      const ::android::hardware::hidl_string& numeric);
141 
142     Return<void> setRadioPowerResponse(const RadioResponseInfo& info);
143 
144     Return<void> sendDtmfResponse(const RadioResponseInfo& info);
145 
146     Return<void> sendSmsResponse(const RadioResponseInfo& info, const SendSmsResult& sms);
147 
148     Return<void> sendSMSExpectMoreResponse(const RadioResponseInfo& info, const SendSmsResult& sms);
149 
150     Return<void> setupDataCallResponse(const RadioResponseInfo& info,
151                                        const SetupDataCallResult& dcResponse);
152 
153     Return<void> iccIOForAppResponse(const RadioResponseInfo& info, const IccIoResult& iccIo);
154 
155     Return<void> sendUssdResponse(const RadioResponseInfo& info);
156 
157     Return<void> cancelPendingUssdResponse(const RadioResponseInfo& info);
158 
159     Return<void> getClirResponse(const RadioResponseInfo& info, int32_t n, int32_t m);
160 
161     Return<void> setClirResponse(const RadioResponseInfo& info);
162 
163     Return<void> getCallForwardStatusResponse(
164         const RadioResponseInfo& info,
165         const ::android::hardware::hidl_vec<CallForwardInfo>& call_forwardInfos);
166 
167     Return<void> setCallForwardResponse(const RadioResponseInfo& info);
168 
169     Return<void> getCallWaitingResponse(const RadioResponseInfo& info, bool enable,
170                                         int32_t serviceClass);
171 
172     Return<void> setCallWaitingResponse(const RadioResponseInfo& info);
173 
174     Return<void> acknowledgeLastIncomingGsmSmsResponse(const RadioResponseInfo& info);
175 
176     Return<void> acceptCallResponse(const RadioResponseInfo& info);
177 
178     Return<void> deactivateDataCallResponse(const RadioResponseInfo& info);
179 
180     Return<void> getFacilityLockForAppResponse(const RadioResponseInfo& info, int32_t response);
181 
182     Return<void> setFacilityLockForAppResponse(const RadioResponseInfo& info, int32_t retry);
183 
184     Return<void> setBarringPasswordResponse(const RadioResponseInfo& info);
185 
186     Return<void> getNetworkSelectionModeResponse(const RadioResponseInfo& info, bool manual);
187 
188     Return<void> setNetworkSelectionModeAutomaticResponse(const RadioResponseInfo& info);
189 
190     Return<void> setNetworkSelectionModeManualResponse(const RadioResponseInfo& info);
191 
192     Return<void> getAvailableNetworksResponse(
193         const RadioResponseInfo& info,
194         const ::android::hardware::hidl_vec<OperatorInfo>& networkInfos);
195 
196     Return<void> startDtmfResponse(const RadioResponseInfo& info);
197 
198     Return<void> stopDtmfResponse(const RadioResponseInfo& info);
199 
200     Return<void> getBasebandVersionResponse(const RadioResponseInfo& info,
201                                             const ::android::hardware::hidl_string& version);
202 
203     Return<void> separateConnectionResponse(const RadioResponseInfo& info);
204 
205     Return<void> setMuteResponse(const RadioResponseInfo& info);
206 
207     Return<void> getMuteResponse(const RadioResponseInfo& info, bool enable);
208 
209     Return<void> getClipResponse(const RadioResponseInfo& info, ClipStatus status);
210 
211     Return<void> getDataCallListResponse(
212         const RadioResponseInfo& info,
213         const ::android::hardware::hidl_vec<SetupDataCallResult>& dcResponse);
214 
215     Return<void> sendOemRilRequestRawResponse(const RadioResponseInfo& info,
216                                               const ::android::hardware::hidl_vec<uint8_t>& data);
217 
218     Return<void> sendOemRilRequestStringsResponse(
219         const RadioResponseInfo& info,
220         const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& data);
221 
222     Return<void> setSuppServiceNotificationsResponse(const RadioResponseInfo& info);
223 
224     Return<void> writeSmsToSimResponse(const RadioResponseInfo& info, int32_t index);
225 
226     Return<void> deleteSmsOnSimResponse(const RadioResponseInfo& info);
227 
228     Return<void> setBandModeResponse(const RadioResponseInfo& info);
229 
230     Return<void> getAvailableBandModesResponse(
231         const RadioResponseInfo& info,
232         const ::android::hardware::hidl_vec<RadioBandMode>& bandModes);
233 
234     Return<void> sendEnvelopeResponse(const RadioResponseInfo& info,
235                                       const ::android::hardware::hidl_string& commandResponse);
236 
237     Return<void> sendTerminalResponseToSimResponse(const RadioResponseInfo& info);
238 
239     Return<void> handleStkCallSetupRequestFromSimResponse(const RadioResponseInfo& info);
240 
241     Return<void> explicitCallTransferResponse(const RadioResponseInfo& info);
242 
243     Return<void> setPreferredNetworkTypeResponse(const RadioResponseInfo& info);
244 
245     Return<void> getPreferredNetworkTypeResponse(const RadioResponseInfo& info,
246                                                  PreferredNetworkType nwType);
247 
248     Return<void> getNeighboringCidsResponse(
249         const RadioResponseInfo& info, const ::android::hardware::hidl_vec<NeighboringCell>& cells);
250 
251     Return<void> setLocationUpdatesResponse(const RadioResponseInfo& info);
252 
253     Return<void> setCdmaSubscriptionSourceResponse(const RadioResponseInfo& info);
254 
255     Return<void> setCdmaRoamingPreferenceResponse(const RadioResponseInfo& info);
256 
257     Return<void> getCdmaRoamingPreferenceResponse(const RadioResponseInfo& info,
258                                                   CdmaRoamingType type);
259 
260     Return<void> setTTYModeResponse(const RadioResponseInfo& info);
261 
262     Return<void> getTTYModeResponse(const RadioResponseInfo& info, TtyMode mode);
263 
264     Return<void> setPreferredVoicePrivacyResponse(const RadioResponseInfo& info);
265 
266     Return<void> getPreferredVoicePrivacyResponse(const RadioResponseInfo& info, bool enable);
267 
268     Return<void> sendCDMAFeatureCodeResponse(const RadioResponseInfo& info);
269 
270     Return<void> sendBurstDtmfResponse(const RadioResponseInfo& info);
271 
272     Return<void> sendCdmaSmsResponse(const RadioResponseInfo& info, const SendSmsResult& sms);
273 
274     Return<void> acknowledgeLastIncomingCdmaSmsResponse(const RadioResponseInfo& info);
275 
276     Return<void> getGsmBroadcastConfigResponse(
277         const RadioResponseInfo& info,
278         const ::android::hardware::hidl_vec<GsmBroadcastSmsConfigInfo>& configs);
279 
280     Return<void> setGsmBroadcastConfigResponse(const RadioResponseInfo& info);
281 
282     Return<void> setGsmBroadcastActivationResponse(const RadioResponseInfo& info);
283 
284     Return<void> getCdmaBroadcastConfigResponse(
285         const RadioResponseInfo& info,
286         const ::android::hardware::hidl_vec<CdmaBroadcastSmsConfigInfo>& configs);
287 
288     Return<void> setCdmaBroadcastConfigResponse(const RadioResponseInfo& info);
289 
290     Return<void> setCdmaBroadcastActivationResponse(const RadioResponseInfo& info);
291 
292     Return<void> getCDMASubscriptionResponse(const RadioResponseInfo& info,
293                                              const ::android::hardware::hidl_string& mdn,
294                                              const ::android::hardware::hidl_string& hSid,
295                                              const ::android::hardware::hidl_string& hNid,
296                                              const ::android::hardware::hidl_string& min,
297                                              const ::android::hardware::hidl_string& prl);
298 
299     Return<void> writeSmsToRuimResponse(const RadioResponseInfo& info, uint32_t index);
300 
301     Return<void> deleteSmsOnRuimResponse(const RadioResponseInfo& info);
302 
303     Return<void> getDeviceIdentityResponse(const RadioResponseInfo& info,
304                                            const ::android::hardware::hidl_string& imei,
305                                            const ::android::hardware::hidl_string& imeisv,
306                                            const ::android::hardware::hidl_string& esn,
307                                            const ::android::hardware::hidl_string& meid);
308 
309     Return<void> exitEmergencyCallbackModeResponse(const RadioResponseInfo& info);
310 
311     Return<void> getSmscAddressResponse(const RadioResponseInfo& info,
312                                         const ::android::hardware::hidl_string& smsc);
313 
314     Return<void> setSmscAddressResponse(const RadioResponseInfo& info);
315 
316     Return<void> reportSmsMemoryStatusResponse(const RadioResponseInfo& info);
317 
318     Return<void> reportStkServiceIsRunningResponse(const RadioResponseInfo& info);
319 
320     Return<void> getCdmaSubscriptionSourceResponse(const RadioResponseInfo& info,
321                                                    CdmaSubscriptionSource source);
322 
323     Return<void> requestIsimAuthenticationResponse(
324         const RadioResponseInfo& info, const ::android::hardware::hidl_string& response);
325 
326     Return<void> acknowledgeIncomingGsmSmsWithPduResponse(const RadioResponseInfo& info);
327 
328     Return<void> sendEnvelopeWithStatusResponse(const RadioResponseInfo& info,
329                                                 const IccIoResult& iccIo);
330 
331     Return<void> getVoiceRadioTechnologyResponse(const RadioResponseInfo& info,
332                                                  RadioTechnology rat);
333 
334     Return<void> getCellInfoListResponse(const RadioResponseInfo& info,
335                                          const ::android::hardware::hidl_vec<CellInfo>& cellInfo);
336 
337     Return<void> setCellInfoListRateResponse(const RadioResponseInfo& info);
338 
339     Return<void> setInitialAttachApnResponse(const RadioResponseInfo& info);
340 
341     Return<void> getImsRegistrationStateResponse(const RadioResponseInfo& info, bool isRegistered,
342                                                  RadioTechnologyFamily ratFamily);
343 
344     Return<void> sendImsSmsResponse(const RadioResponseInfo& info, const SendSmsResult& sms);
345 
346     Return<void> iccTransmitApduBasicChannelResponse(const RadioResponseInfo& info,
347                                                      const IccIoResult& result);
348 
349     Return<void> iccOpenLogicalChannelResponse(
350         const RadioResponseInfo& info, int32_t channelId,
351         const ::android::hardware::hidl_vec<int8_t>& selectResponse);
352 
353     Return<void> iccCloseLogicalChannelResponse(const RadioResponseInfo& info);
354 
355     Return<void> iccTransmitApduLogicalChannelResponse(const RadioResponseInfo& info,
356                                                        const IccIoResult& result);
357 
358     Return<void> nvReadItemResponse(const RadioResponseInfo& info,
359                                     const ::android::hardware::hidl_string& result);
360 
361     Return<void> nvWriteItemResponse(const RadioResponseInfo& info);
362 
363     Return<void> nvWriteCdmaPrlResponse(const RadioResponseInfo& info);
364 
365     Return<void> nvResetConfigResponse(const RadioResponseInfo& info);
366 
367     Return<void> setUiccSubscriptionResponse(const RadioResponseInfo& info);
368 
369     Return<void> setDataAllowedResponse(const RadioResponseInfo& info);
370 
371     Return<void> getHardwareConfigResponse(
372         const RadioResponseInfo& info, const ::android::hardware::hidl_vec<HardwareConfig>& config);
373 
374     Return<void> requestIccSimAuthenticationResponse(const RadioResponseInfo& info,
375                                                      const IccIoResult& result);
376 
377     Return<void> setDataProfileResponse(const RadioResponseInfo& info);
378 
379     Return<void> requestShutdownResponse(const RadioResponseInfo& info);
380 
381     Return<void> getRadioCapabilityResponse(const RadioResponseInfo& info,
382                                             const RadioCapability& rc);
383 
384     Return<void> setRadioCapabilityResponse(const RadioResponseInfo& info,
385                                             const RadioCapability& rc);
386 
387     Return<void> startLceServiceResponse(const RadioResponseInfo& info,
388                                          const LceStatusInfo& statusInfo);
389 
390     Return<void> stopLceServiceResponse(const RadioResponseInfo& info,
391                                         const LceStatusInfo& statusInfo);
392 
393     Return<void> pullLceDataResponse(const RadioResponseInfo& info, const LceDataInfo& lceInfo);
394 
395     Return<void> getModemActivityInfoResponse(const RadioResponseInfo& info,
396                                               const ActivityStatsInfo& activityInfo);
397 
398     Return<void> setAllowedCarriersResponse(const RadioResponseInfo& info, int32_t numAllowed);
399 
400     Return<void> getAllowedCarriersResponse(const RadioResponseInfo& info, bool allAllowed,
401                                             const CarrierRestrictions& carriers);
402 
403     Return<void> sendDeviceStateResponse(const RadioResponseInfo& info);
404 
405     Return<void> setIndicationFilterResponse(const RadioResponseInfo& info);
406 
407     Return<void> setSimCardPowerResponse(const RadioResponseInfo& info);
408 
409     Return<void> acknowledgeRequest(int32_t serial);
410 };
411 
412 /* Callback class for radio indication */
413 class RadioIndication : public IRadioIndication {
414    protected:
415     RadioHidlTest& parent;
416 
417    public:
418     RadioIndication(RadioHidlTest& parent);
419     virtual ~RadioIndication() = default;
420 
421     Return<void> radioStateChanged(RadioIndicationType type, RadioState radioState);
422 
423     Return<void> callStateChanged(RadioIndicationType type);
424 
425     Return<void> networkStateChanged(RadioIndicationType type);
426 
427     Return<void> newSms(RadioIndicationType type,
428                         const ::android::hardware::hidl_vec<uint8_t>& pdu);
429 
430     Return<void> newSmsStatusReport(RadioIndicationType type,
431                                     const ::android::hardware::hidl_vec<uint8_t>& pdu);
432 
433     Return<void> newSmsOnSim(RadioIndicationType type, int32_t recordNumber);
434 
435     Return<void> onUssd(RadioIndicationType type, UssdModeType modeType,
436                         const ::android::hardware::hidl_string& msg);
437 
438     Return<void> nitzTimeReceived(RadioIndicationType type,
439                                   const ::android::hardware::hidl_string& nitzTime,
440                                   uint64_t receivedTime);
441 
442     Return<void> currentSignalStrength(RadioIndicationType type,
443                                        const SignalStrength& signalStrength);
444 
445     Return<void> dataCallListChanged(
446         RadioIndicationType type, const ::android::hardware::hidl_vec<SetupDataCallResult>& dcList);
447 
448     Return<void> suppSvcNotify(RadioIndicationType type, const SuppSvcNotification& suppSvc);
449 
450     Return<void> stkSessionEnd(RadioIndicationType type);
451 
452     Return<void> stkProactiveCommand(RadioIndicationType type,
453                                      const ::android::hardware::hidl_string& cmd);
454 
455     Return<void> stkEventNotify(RadioIndicationType type,
456                                 const ::android::hardware::hidl_string& cmd);
457 
458     Return<void> stkCallSetup(RadioIndicationType type, int64_t timeout);
459 
460     Return<void> simSmsStorageFull(RadioIndicationType type);
461 
462     Return<void> simRefresh(RadioIndicationType type, const SimRefreshResult& refreshResult);
463 
464     Return<void> callRing(RadioIndicationType type, bool isGsm, const CdmaSignalInfoRecord& record);
465 
466     Return<void> simStatusChanged(RadioIndicationType type);
467 
468     Return<void> cdmaNewSms(RadioIndicationType type, const CdmaSmsMessage& msg);
469 
470     Return<void> newBroadcastSms(RadioIndicationType type,
471                                  const ::android::hardware::hidl_vec<uint8_t>& data);
472 
473     Return<void> cdmaRuimSmsStorageFull(RadioIndicationType type);
474 
475     Return<void> restrictedStateChanged(RadioIndicationType type, PhoneRestrictedState state);
476 
477     Return<void> enterEmergencyCallbackMode(RadioIndicationType type);
478 
479     Return<void> cdmaCallWaiting(RadioIndicationType type,
480                                  const CdmaCallWaiting& callWaitingRecord);
481 
482     Return<void> cdmaOtaProvisionStatus(RadioIndicationType type, CdmaOtaProvisionStatus status);
483 
484     Return<void> cdmaInfoRec(RadioIndicationType type, const CdmaInformationRecords& records);
485 
486     Return<void> indicateRingbackTone(RadioIndicationType type, bool start);
487 
488     Return<void> resendIncallMute(RadioIndicationType type);
489 
490     Return<void> cdmaSubscriptionSourceChanged(RadioIndicationType type,
491                                                CdmaSubscriptionSource cdmaSource);
492 
493     Return<void> cdmaPrlChanged(RadioIndicationType type, int32_t version);
494 
495     Return<void> exitEmergencyCallbackMode(RadioIndicationType type);
496 
497     Return<void> rilConnected(RadioIndicationType type);
498 
499     Return<void> voiceRadioTechChanged(RadioIndicationType type, RadioTechnology rat);
500 
501     Return<void> cellInfoList(RadioIndicationType type,
502                               const ::android::hardware::hidl_vec<CellInfo>& records);
503 
504     Return<void> imsNetworkStateChanged(RadioIndicationType type);
505 
506     Return<void> subscriptionStatusChanged(RadioIndicationType type, bool activate);
507 
508     Return<void> srvccStateNotify(RadioIndicationType type, SrvccState state);
509 
510     Return<void> hardwareConfigChanged(
511         RadioIndicationType type, const ::android::hardware::hidl_vec<HardwareConfig>& configs);
512 
513     Return<void> radioCapabilityIndication(RadioIndicationType type, const RadioCapability& rc);
514 
515     Return<void> onSupplementaryServiceIndication(RadioIndicationType type,
516                                                   const StkCcUnsolSsResult& ss);
517 
518     Return<void> stkCallControlAlphaNotify(RadioIndicationType type,
519                                            const ::android::hardware::hidl_string& alpha);
520 
521     Return<void> lceData(RadioIndicationType type, const LceDataInfo& lce);
522 
523     Return<void> pcoData(RadioIndicationType type, const PcoDataInfo& pco);
524 
525     Return<void> modemReset(RadioIndicationType type,
526                             const ::android::hardware::hidl_string& reason);
527 };
528 
529 // The main test class for Radio HIDL.
530 class RadioHidlTest : public ::testing::TestWithParam<std::string> {
531   protected:
532     std::mutex mtx;
533     std::condition_variable cv;
534     int count;
535 
536     /* Serial number for radio request */
537     int serial;
538 
539     /* Update Sim Card Status */
540     void updateSimCardStatus();
541 
542    public:
543     virtual void SetUp() override;
544 
545     /* Used as a mechanism to inform the test about data/event callback */
546     void notify(int receivedSerial);
547 
548     /* Test code calls this function to wait for response */
549     std::cv_status wait(int sec = TIMEOUT_PERIOD);
550 
551     sp<IRadio> radio;
552     sp<RadioResponse> radioRsp;
553     sp<RadioIndication> radioInd;
554 };
555