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