• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "bluetooth_call_proxy.h"
17 
18 #include "message_option.h"
19 #include "message_parcel.h"
20 
21 #include "call_manager_errors.h"
22 
23 namespace OHOS {
24 namespace Telephony {
BluetoothCallProxy(const sptr<IRemoteObject> & impl)25 BluetoothCallProxy::BluetoothCallProxy(const sptr<IRemoteObject> &impl)
26     : IRemoteProxy<IBluetoothCall>(impl)
27 {}
28 
AnswerCall()29 int32_t BluetoothCallProxy::AnswerCall()
30 {
31     MessageOption option;
32     MessageParcel dataParcel;
33     MessageParcel replyParcel;
34     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
35         TELEPHONY_LOGE("write descriptor fail");
36         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
37     }
38     if (Remote() == nullptr) {
39         TELEPHONY_LOGE("function Remote() return nullptr!");
40         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
41     }
42     int32_t error = Remote()->SendRequest(INTERFACE_BT_ANSWER_CALL, dataParcel, replyParcel, option);
43     if (error != TELEPHONY_SUCCESS) {
44         TELEPHONY_LOGE("function AnswerCall call failed! errCode:%{public}d", error);
45         return error;
46     }
47     return replyParcel.ReadInt32();
48 }
49 
RejectCall()50 int32_t BluetoothCallProxy::RejectCall()
51 {
52     MessageOption option;
53     MessageParcel dataParcel;
54     MessageParcel replyParcel;
55     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
56         TELEPHONY_LOGE("write descriptor fail");
57         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
58     }
59     if (Remote() == nullptr) {
60         TELEPHONY_LOGE("function Remote() return nullptr!");
61         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
62     }
63     int32_t error = Remote()->SendRequest(INTERFACE_BT_REJECT_CALL, dataParcel, replyParcel, option);
64     if (error != TELEPHONY_SUCCESS) {
65         TELEPHONY_LOGE("function RejectCall call failed! errCode:%{public}d", error);
66         return error;
67     }
68     return replyParcel.ReadInt32();
69 }
70 
HangUpCall()71 int32_t BluetoothCallProxy::HangUpCall()
72 {
73     MessageOption option;
74     MessageParcel dataParcel;
75     MessageParcel replyParcel;
76     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
77         TELEPHONY_LOGE("write descriptor fail");
78         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
79     }
80     if (Remote() == nullptr) {
81         TELEPHONY_LOGE("function Remote() return nullptr!");
82         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
83     }
84     int32_t error = Remote()->SendRequest(INTERFACE_BT_DISCONNECT_CALL, dataParcel, replyParcel, option);
85     if (error != TELEPHONY_SUCCESS) {
86         TELEPHONY_LOGE("function HangUpCall call failed! errCode:%{public}d", error);
87         return error;
88     }
89     return replyParcel.ReadInt32();
90 }
91 
GetCallState()92 int32_t BluetoothCallProxy::GetCallState()
93 {
94     MessageOption option;
95     MessageParcel dataParcel;
96     MessageParcel replyParcel;
97     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
98         TELEPHONY_LOGE("write descriptor fail");
99         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
100     }
101     if (Remote() == nullptr) {
102         TELEPHONY_LOGE("function Remote() return nullptr!");
103         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
104     }
105     int32_t error = Remote()->SendRequest(INTERFACE_BT_GET_CALL_STATE, dataParcel, replyParcel, option);
106     if (error != TELEPHONY_SUCCESS) {
107         TELEPHONY_LOGE("function GetCallState! errCode:%{public}d", error);
108         return error;
109     }
110     return replyParcel.ReadInt32();
111 }
112 
HoldCall()113 int32_t BluetoothCallProxy::HoldCall()
114 {
115     MessageOption option;
116     MessageParcel dataParcel;
117     MessageParcel replyParcel;
118     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
119         TELEPHONY_LOGE("write descriptor fail");
120         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
121     }
122     if (Remote() == nullptr) {
123         TELEPHONY_LOGE("function Remote() return nullptr!");
124         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
125     }
126     int32_t error = Remote()->SendRequest(INTERFACE_BT_HOLD_CALL, dataParcel, replyParcel, option);
127     if (error != TELEPHONY_SUCCESS) {
128         TELEPHONY_LOGE("Function HoldCall call failed! errCode:%{public}d", error);
129         return error;
130     }
131     return replyParcel.ReadInt32();
132 }
133 
UnHoldCall()134 int32_t BluetoothCallProxy::UnHoldCall()
135 {
136     MessageOption option;
137     MessageParcel dataParcel;
138     MessageParcel replyParcel;
139     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
140         TELEPHONY_LOGE("write descriptor fail");
141         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
142     }
143     if (Remote() == nullptr) {
144         TELEPHONY_LOGE("function Remote() return nullptr!");
145         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
146     }
147     int32_t error = Remote()->SendRequest(INTERFACE_BT_UNHOLD_CALL, dataParcel, replyParcel, option);
148     if (error != TELEPHONY_SUCCESS) {
149         TELEPHONY_LOGE("Function UnHoldCall call failed! errCode:%{public}d", error);
150         return error;
151     }
152     return replyParcel.ReadInt32();
153 }
154 
SwitchCall()155 int32_t BluetoothCallProxy::SwitchCall()
156 {
157     MessageOption option;
158     MessageParcel dataParcel;
159     MessageParcel replyParcel;
160     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
161         TELEPHONY_LOGE("write descriptor fail");
162         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
163     }
164     if (Remote() == nullptr) {
165         TELEPHONY_LOGE("function Remote() return nullptr!");
166         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
167     }
168     int32_t error = Remote()->SendRequest(INTERFACE_BT_SWAP_CALL, dataParcel, replyParcel, option);
169     if (error != TELEPHONY_SUCCESS) {
170         TELEPHONY_LOGE("Function UnHoldCall call failed! errCode:%{public}d", error);
171         return error;
172     }
173     return replyParcel.ReadInt32();
174 }
175 
StartDtmf(char str)176 int32_t BluetoothCallProxy::StartDtmf(char str)
177 {
178     MessageOption option;
179     MessageParcel dataParcel;
180     MessageParcel replyParcel;
181     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
182         TELEPHONY_LOGE("write descriptor fail");
183         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
184     }
185     if (Remote() == nullptr) {
186         TELEPHONY_LOGE("function Remote() return nullptr!");
187         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
188     }
189     dataParcel.WriteInt8(str);
190     int32_t error =
191             Remote()->SendRequest(INTERFACE_BT_START_DTMF, dataParcel, replyParcel, option);
192     if (error != TELEPHONY_SUCCESS) {
193         TELEPHONY_LOGE("Function StartDtmf! errCode:%{public}d", error);
194         return error;
195     }
196     return replyParcel.ReadInt32();
197 }
198 
StopDtmf()199 int32_t BluetoothCallProxy::StopDtmf()
200 {
201     MessageOption option;
202     MessageParcel dataParcel;
203     MessageParcel replyParcel;
204     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
205         TELEPHONY_LOGE("write descriptor fail");
206         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
207     }
208     if (Remote() == nullptr) {
209         TELEPHONY_LOGE("function Remote() return nullptr!");
210         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
211     }
212     int32_t error =
213             Remote()->SendRequest(INTERFACE_BT_STOP_DTMF, dataParcel, replyParcel, option);
214     if (error != TELEPHONY_SUCCESS) {
215         TELEPHONY_LOGE("Function StopDtmf! errCode:%{public}d", error);
216         return error;
217     }
218     return replyParcel.ReadInt32();
219 }
220 
CombineConference()221 int32_t BluetoothCallProxy::CombineConference()
222 {
223     MessageOption option;
224     MessageParcel dataParcel;
225     MessageParcel replyParcel;
226     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
227         TELEPHONY_LOGE("write descriptor fail");
228         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
229     }
230     if (Remote() == nullptr) {
231         TELEPHONY_LOGE("function Remote() return nullptr!");
232         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
233     }
234     int32_t error = Remote()->SendRequest(INTERFACE_BT_COMBINE_CONFERENCE, dataParcel, replyParcel, option);
235     if (error != TELEPHONY_SUCCESS) {
236         TELEPHONY_LOGE("Function CombineConference failed! errCode:%{public}d", error);
237         return error;
238     }
239     return replyParcel.ReadInt32();
240 }
241 
SeparateConference()242 int32_t BluetoothCallProxy::SeparateConference()
243 {
244     MessageOption option;
245     MessageParcel dataParcel;
246     MessageParcel replyParcel;
247     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
248         TELEPHONY_LOGE("write descriptor fail");
249         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
250     }
251     if (Remote() == nullptr) {
252         TELEPHONY_LOGE("function Remote() return nullptr!");
253         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
254     }
255     int32_t error = Remote()->SendRequest(INTERFACE_BT_SEPARATE_CONFERENCE, dataParcel, replyParcel, option);
256     if (error != TELEPHONY_SUCCESS) {
257         TELEPHONY_LOGE("Function SeparateConference call failed! errCode:%{public}d", error);
258         return error;
259     }
260     return replyParcel.ReadInt32();
261 }
262 
GetCurrentCallList(int32_t slotId)263 std::vector<CallAttributeInfo> BluetoothCallProxy::GetCurrentCallList(int32_t slotId)
264 {
265     std::vector<CallAttributeInfo> callVec;
266     MessageOption option;
267     MessageParcel dataParcel;
268     MessageParcel replyParcel;
269     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
270         TELEPHONY_LOGE("write descriptor fail");
271         return callVec;
272     }
273     dataParcel.WriteInt32(slotId);
274     if (Remote() == nullptr) {
275         TELEPHONY_LOGE("function Remote() return nullptr!");
276         return callVec;
277     }
278     int32_t error = Remote()->SendRequest(INTERFACE_BT_GET_CURRENT_CALL_LIST, dataParcel, replyParcel, option);
279     if (error != TELEPHONY_SUCCESS) {
280         TELEPHONY_LOGE("Function GetCurrentCallList call failed! errCode:%{public}d", error);
281         return callVec;
282     }
283     int32_t vecCnt = replyParcel.ReadInt32();
284     if (vecCnt <= 0) {
285         TELEPHONY_LOGE("vector is empty");
286         return callVec;
287     }
288     CallAttributeInfo *infoPtr = nullptr;
289     for (int32_t i = 0; i < vecCnt; i++) {
290         infoPtr = (CallAttributeInfo *)replyParcel.ReadRawData(sizeof(CallAttributeInfo));
291         callVec.push_back(*infoPtr);
292     }
293     return callVec;
294 }
295 } // namespace Telephony
296 } // namespace OHOS
297