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/android/hardware/radio/voice/BnRadioVoiceIndication.h>
20 #include <aidl/android/hardware/radio/voice/BnRadioVoiceResponse.h>
21 #include <aidl/android/hardware/radio/voice/IRadioVoice.h>
22 
23 #include "radio_aidl_hal_utils.h"
24 #include "radio_network_utils.h"
25 
26 using namespace aidl::android::hardware::radio::voice;
27 
28 class RadioVoiceTest;
29 
30 /* Callback class for radio voice response */
31 class RadioVoiceResponse : public BnRadioVoiceResponse {
32   protected:
33     RadioServiceTest& parent_voice;
34 
35   public:
36     RadioVoiceResponse(RadioServiceTest& parent_voice);
37     virtual ~RadioVoiceResponse() = default;
38 
39     RadioResponseInfo rspInfo;
40     std::vector<Call> currentCalls;
41 
42     virtual ndk::ScopedAStatus acceptCallResponse(const RadioResponseInfo& info) override;
43 
44     virtual ndk::ScopedAStatus acknowledgeRequest(int32_t serial) override;
45 
46     virtual ndk::ScopedAStatus cancelPendingUssdResponse(const RadioResponseInfo& info) override;
47 
48     virtual ndk::ScopedAStatus conferenceResponse(const RadioResponseInfo& info) override;
49 
50     virtual ndk::ScopedAStatus dialResponse(const RadioResponseInfo& info) override;
51 
52     virtual ndk::ScopedAStatus emergencyDialResponse(const RadioResponseInfo& info) override;
53 
54     virtual ndk::ScopedAStatus exitEmergencyCallbackModeResponse(
55             const RadioResponseInfo& info) override;
56 
57     virtual ndk::ScopedAStatus explicitCallTransferResponse(const RadioResponseInfo& info) override;
58 
59     virtual ndk::ScopedAStatus getCallForwardStatusResponse(
60             const RadioResponseInfo& info,
61             const std::vector<CallForwardInfo>& call_forwardInfos) override;
62 
63     virtual ndk::ScopedAStatus getCallWaitingResponse(const RadioResponseInfo& info, bool enable,
64                                                       int32_t serviceClass) override;
65 
66     virtual ndk::ScopedAStatus getClipResponse(const RadioResponseInfo& info,
67                                                ClipStatus status) override;
68 
69     virtual ndk::ScopedAStatus getClirResponse(const RadioResponseInfo& info, int32_t n,
70                                                int32_t m) override;
71 
72     virtual ndk::ScopedAStatus getCurrentCallsResponse(const RadioResponseInfo& info,
73                                                        const std::vector<Call>& calls) override;
74 
75     virtual ndk::ScopedAStatus getLastCallFailCauseResponse(
76             const RadioResponseInfo& info, const LastCallFailCauseInfo& failCauseInfo) override;
77 
78     virtual ndk::ScopedAStatus getMuteResponse(const RadioResponseInfo& info, bool enable) override;
79 
80     virtual ndk::ScopedAStatus getPreferredVoicePrivacyResponse(const RadioResponseInfo& info,
81                                                                 bool enable) override;
82 
83     virtual ndk::ScopedAStatus getTtyModeResponse(const RadioResponseInfo& info,
84                                                   TtyMode mode) override;
85 
86     virtual ndk::ScopedAStatus handleStkCallSetupRequestFromSimResponse(
87             const RadioResponseInfo& info) override;
88 
89     virtual ndk::ScopedAStatus hangupConnectionResponse(const RadioResponseInfo& info) override;
90 
91     virtual ndk::ScopedAStatus hangupForegroundResumeBackgroundResponse(
92             const RadioResponseInfo& info) override;
93 
94     virtual ndk::ScopedAStatus hangupWaitingOrBackgroundResponse(
95             const RadioResponseInfo& info) override;
96 
97     virtual ndk::ScopedAStatus isVoNrEnabledResponse(const RadioResponseInfo& info,
98                                                      bool enable) override;
99 
100     virtual ndk::ScopedAStatus rejectCallResponse(const RadioResponseInfo& info) override;
101 
102     virtual ndk::ScopedAStatus sendBurstDtmfResponse(const RadioResponseInfo& info) override;
103 
104     virtual ndk::ScopedAStatus sendCdmaFeatureCodeResponse(const RadioResponseInfo& info) override;
105 
106     virtual ndk::ScopedAStatus sendDtmfResponse(const RadioResponseInfo& info) override;
107 
108     virtual ndk::ScopedAStatus sendUssdResponse(const RadioResponseInfo& info) override;
109 
110     virtual ndk::ScopedAStatus separateConnectionResponse(const RadioResponseInfo& info) override;
111 
112     virtual ndk::ScopedAStatus setCallForwardResponse(const RadioResponseInfo& info) override;
113 
114     virtual ndk::ScopedAStatus setCallWaitingResponse(const RadioResponseInfo& info) override;
115 
116     virtual ndk::ScopedAStatus setClirResponse(const RadioResponseInfo& info) override;
117 
118     virtual ndk::ScopedAStatus setMuteResponse(const RadioResponseInfo& info) override;
119 
120     virtual ndk::ScopedAStatus setPreferredVoicePrivacyResponse(
121             const RadioResponseInfo& info) override;
122 
123     virtual ndk::ScopedAStatus setTtyModeResponse(const RadioResponseInfo& info) override;
124 
125     virtual ndk::ScopedAStatus setVoNrEnabledResponse(const RadioResponseInfo& info) override;
126 
127     virtual ndk::ScopedAStatus startDtmfResponse(const RadioResponseInfo& info) override;
128 
129     virtual ndk::ScopedAStatus stopDtmfResponse(const RadioResponseInfo& info) override;
130 
131     virtual ndk::ScopedAStatus switchWaitingOrHoldingAndActiveResponse(
132             const RadioResponseInfo& info) override;
133 };
134 
135 /* Callback class for radio voice indication */
136 class RadioVoiceIndication : public BnRadioVoiceIndication {
137   protected:
138     RadioServiceTest& parent_voice;
139 
140   public:
141     RadioVoiceIndication(RadioServiceTest& parent_voice);
142     virtual ~RadioVoiceIndication() = default;
143 
144     virtual ndk::ScopedAStatus callRing(RadioIndicationType type, bool isGsm,
145                                         const CdmaSignalInfoRecord& record) override;
146 
147     virtual ndk::ScopedAStatus callStateChanged(RadioIndicationType type) override;
148 
149     virtual ndk::ScopedAStatus cdmaCallWaiting(RadioIndicationType type,
150                                                const CdmaCallWaiting& callWaitingRecord) override;
151 
152     virtual ndk::ScopedAStatus cdmaInfoRec(
153             RadioIndicationType type, const std::vector<CdmaInformationRecord>& records) override;
154 
155     virtual ndk::ScopedAStatus cdmaOtaProvisionStatus(RadioIndicationType type,
156                                                       CdmaOtaProvisionStatus status) override;
157 
158     virtual ndk::ScopedAStatus currentEmergencyNumberList(
159             RadioIndicationType type,
160             const std::vector<EmergencyNumber>& emergencyNumberList) override;
161 
162     virtual ndk::ScopedAStatus enterEmergencyCallbackMode(RadioIndicationType type) override;
163 
164     virtual ndk::ScopedAStatus exitEmergencyCallbackMode(RadioIndicationType type) override;
165 
166     virtual ndk::ScopedAStatus indicateRingbackTone(RadioIndicationType type, bool start) override;
167 
168     virtual ndk::ScopedAStatus onSupplementaryServiceIndication(
169             RadioIndicationType type, const StkCcUnsolSsResult& ss) override;
170 
171     virtual ndk::ScopedAStatus onUssd(RadioIndicationType type, UssdModeType modeType,
172                                       const std::string& msg) override;
173 
174     virtual ndk::ScopedAStatus resendIncallMute(RadioIndicationType type) override;
175 
176     virtual ndk::ScopedAStatus srvccStateNotify(RadioIndicationType type,
177                                                 SrvccState state) override;
178 
179     virtual ndk::ScopedAStatus stkCallControlAlphaNotify(RadioIndicationType type,
180                                                          const std::string& alpha) override;
181 
182     virtual ndk::ScopedAStatus stkCallSetup(RadioIndicationType type, int64_t timeout) override;
183 };
184 
185 // The main test class for Radio AIDL Voice.
186 class RadioVoiceTest : public RadioServiceTest {
187   protected:
188     /* Clear Potential Established Calls */
189     virtual ndk::ScopedAStatus clearPotentialEstablishedCalls();
190     std::shared_ptr<network::IRadioNetwork> radio_network;
191     std::shared_ptr<RadioNetworkResponse> radioRsp_network;
192     std::shared_ptr<RadioNetworkIndication> radioInd_network;
193 
194   public:
195     void SetUp() override;
196 
197     /* radio voice service handle */
198     std::shared_ptr<IRadioVoice> radio_voice;
199     /* radio voice response handle */
200     std::shared_ptr<RadioVoiceResponse> radioRsp_voice;
201     /* radio voice indication handle */
202     std::shared_ptr<RadioVoiceIndication> radioInd_voice;
203 };
204