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