• 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 {
25 static const int32_t MAX_SIZE = 10000;
BluetoothCallProxy(const sptr<IRemoteObject> & impl)26 BluetoothCallProxy::BluetoothCallProxy(const sptr<IRemoteObject> &impl)
27     : IRemoteProxy<IBluetoothCall>(impl)
28 {}
29 
AnswerCall()30 int32_t BluetoothCallProxy::AnswerCall()
31 {
32     MessageOption option;
33     MessageParcel dataParcel;
34     MessageParcel replyParcel;
35     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
36         TELEPHONY_LOGE("write descriptor fail");
37         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
38     }
39     if (Remote() == nullptr) {
40         TELEPHONY_LOGE("function Remote() return nullptr!");
41         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
42     }
43     int32_t error = Remote()->SendRequest(INTERFACE_BT_ANSWER_CALL, dataParcel, replyParcel, option);
44     if (error != TELEPHONY_SUCCESS) {
45         TELEPHONY_LOGE("function AnswerCall call failed! errCode:%{public}d", error);
46         return error;
47     }
48     return replyParcel.ReadInt32();
49 }
50 
RejectCall()51 int32_t BluetoothCallProxy::RejectCall()
52 {
53     MessageOption option;
54     MessageParcel dataParcel;
55     MessageParcel replyParcel;
56     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
57         TELEPHONY_LOGE("write descriptor fail");
58         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
59     }
60     if (Remote() == nullptr) {
61         TELEPHONY_LOGE("function Remote() return nullptr!");
62         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
63     }
64     int32_t error = Remote()->SendRequest(INTERFACE_BT_REJECT_CALL, dataParcel, replyParcel, option);
65     if (error != TELEPHONY_SUCCESS) {
66         TELEPHONY_LOGE("function RejectCall call failed! errCode:%{public}d", error);
67         return error;
68     }
69     return replyParcel.ReadInt32();
70 }
71 
HangUpCall()72 int32_t BluetoothCallProxy::HangUpCall()
73 {
74     MessageOption option;
75     MessageParcel dataParcel;
76     MessageParcel replyParcel;
77     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
78         TELEPHONY_LOGE("write descriptor fail");
79         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
80     }
81     if (Remote() == nullptr) {
82         TELEPHONY_LOGE("function Remote() return nullptr!");
83         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
84     }
85     int32_t error = Remote()->SendRequest(INTERFACE_BT_DISCONNECT_CALL, dataParcel, replyParcel, option);
86     if (error != TELEPHONY_SUCCESS) {
87         TELEPHONY_LOGE("function HangUpCall call failed! errCode:%{public}d", error);
88         return error;
89     }
90     return replyParcel.ReadInt32();
91 }
92 
GetCallState()93 int32_t BluetoothCallProxy::GetCallState()
94 {
95     MessageOption option;
96     MessageParcel dataParcel;
97     MessageParcel replyParcel;
98     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
99         TELEPHONY_LOGE("write descriptor fail");
100         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
101     }
102     if (Remote() == nullptr) {
103         TELEPHONY_LOGE("function Remote() return nullptr!");
104         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
105     }
106     int32_t error = Remote()->SendRequest(INTERFACE_BT_GET_CALL_STATE, dataParcel, replyParcel, option);
107     if (error != TELEPHONY_SUCCESS) {
108         TELEPHONY_LOGE("function GetCallState! errCode:%{public}d", error);
109         return error;
110     }
111     return replyParcel.ReadInt32();
112 }
113 
HoldCall()114 int32_t BluetoothCallProxy::HoldCall()
115 {
116     MessageOption option;
117     MessageParcel dataParcel;
118     MessageParcel replyParcel;
119     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
120         TELEPHONY_LOGE("write descriptor fail");
121         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
122     }
123     if (Remote() == nullptr) {
124         TELEPHONY_LOGE("function Remote() return nullptr!");
125         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
126     }
127     int32_t error = Remote()->SendRequest(INTERFACE_BT_HOLD_CALL, dataParcel, replyParcel, option);
128     if (error != TELEPHONY_SUCCESS) {
129         TELEPHONY_LOGE("Function HoldCall call failed! errCode:%{public}d", error);
130         return error;
131     }
132     return replyParcel.ReadInt32();
133 }
134 
UnHoldCall()135 int32_t BluetoothCallProxy::UnHoldCall()
136 {
137     MessageOption option;
138     MessageParcel dataParcel;
139     MessageParcel replyParcel;
140     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
141         TELEPHONY_LOGE("write descriptor fail");
142         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
143     }
144     if (Remote() == nullptr) {
145         TELEPHONY_LOGE("function Remote() return nullptr!");
146         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
147     }
148     int32_t error = Remote()->SendRequest(INTERFACE_BT_UNHOLD_CALL, dataParcel, replyParcel, option);
149     if (error != TELEPHONY_SUCCESS) {
150         TELEPHONY_LOGE("Function UnHoldCall call failed! errCode:%{public}d", error);
151         return error;
152     }
153     return replyParcel.ReadInt32();
154 }
155 
SwitchCall()156 int32_t BluetoothCallProxy::SwitchCall()
157 {
158     MessageOption option;
159     MessageParcel dataParcel;
160     MessageParcel replyParcel;
161     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
162         TELEPHONY_LOGE("write descriptor fail");
163         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
164     }
165     if (Remote() == nullptr) {
166         TELEPHONY_LOGE("function Remote() return nullptr!");
167         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
168     }
169     int32_t error = Remote()->SendRequest(INTERFACE_BT_SWAP_CALL, dataParcel, replyParcel, option);
170     if (error != TELEPHONY_SUCCESS) {
171         TELEPHONY_LOGE("Function UnHoldCall call failed! errCode:%{public}d", error);
172         return error;
173     }
174     return replyParcel.ReadInt32();
175 }
176 
StartDtmf(char str)177 int32_t BluetoothCallProxy::StartDtmf(char str)
178 {
179     MessageOption option;
180     MessageParcel dataParcel;
181     MessageParcel replyParcel;
182     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
183         TELEPHONY_LOGE("write descriptor fail");
184         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
185     }
186     if (Remote() == nullptr) {
187         TELEPHONY_LOGE("function Remote() return nullptr!");
188         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
189     }
190     dataParcel.WriteInt8(str);
191     int32_t error =
192             Remote()->SendRequest(INTERFACE_BT_START_DTMF, dataParcel, replyParcel, option);
193     if (error != TELEPHONY_SUCCESS) {
194         TELEPHONY_LOGE("Function StartDtmf! errCode:%{public}d", error);
195         return error;
196     }
197     return replyParcel.ReadInt32();
198 }
199 
StopDtmf()200 int32_t BluetoothCallProxy::StopDtmf()
201 {
202     MessageOption option;
203     MessageParcel dataParcel;
204     MessageParcel replyParcel;
205     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
206         TELEPHONY_LOGE("write descriptor fail");
207         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
208     }
209     if (Remote() == nullptr) {
210         TELEPHONY_LOGE("function Remote() return nullptr!");
211         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
212     }
213     int32_t error =
214             Remote()->SendRequest(INTERFACE_BT_STOP_DTMF, dataParcel, replyParcel, option);
215     if (error != TELEPHONY_SUCCESS) {
216         TELEPHONY_LOGE("Function StopDtmf! errCode:%{public}d", error);
217         return error;
218     }
219     return replyParcel.ReadInt32();
220 }
221 
CombineConference()222 int32_t BluetoothCallProxy::CombineConference()
223 {
224     MessageOption option;
225     MessageParcel dataParcel;
226     MessageParcel replyParcel;
227     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
228         TELEPHONY_LOGE("write descriptor fail");
229         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
230     }
231     if (Remote() == nullptr) {
232         TELEPHONY_LOGE("function Remote() return nullptr!");
233         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
234     }
235     int32_t error = Remote()->SendRequest(INTERFACE_BT_COMBINE_CONFERENCE, dataParcel, replyParcel, option);
236     if (error != TELEPHONY_SUCCESS) {
237         TELEPHONY_LOGE("Function CombineConference failed! errCode:%{public}d", error);
238         return error;
239     }
240     return replyParcel.ReadInt32();
241 }
242 
SeparateConference()243 int32_t BluetoothCallProxy::SeparateConference()
244 {
245     MessageOption option;
246     MessageParcel dataParcel;
247     MessageParcel replyParcel;
248     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
249         TELEPHONY_LOGE("write descriptor fail");
250         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
251     }
252     if (Remote() == nullptr) {
253         TELEPHONY_LOGE("function Remote() return nullptr!");
254         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
255     }
256     int32_t error = Remote()->SendRequest(INTERFACE_BT_SEPARATE_CONFERENCE, dataParcel, replyParcel, option);
257     if (error != TELEPHONY_SUCCESS) {
258         TELEPHONY_LOGE("Function SeparateConference call failed! errCode:%{public}d", error);
259         return error;
260     }
261     return replyParcel.ReadInt32();
262 }
263 
GetCurrentCallList(int32_t slotId)264 std::vector<CallAttributeInfo> BluetoothCallProxy::GetCurrentCallList(int32_t slotId)
265 {
266     std::vector<CallAttributeInfo> callVec;
267     MessageOption option;
268     MessageParcel dataParcel;
269     MessageParcel replyParcel;
270     if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
271         TELEPHONY_LOGE("write descriptor fail");
272         return callVec;
273     }
274     dataParcel.WriteInt32(slotId);
275     if (Remote() == nullptr) {
276         TELEPHONY_LOGE("function Remote() return nullptr!");
277         return callVec;
278     }
279     int32_t error = Remote()->SendRequest(INTERFACE_BT_GET_CURRENT_CALL_LIST, dataParcel, replyParcel, option);
280     if (error != TELEPHONY_SUCCESS) {
281         TELEPHONY_LOGE("Function GetCurrentCallList call failed! errCode:%{public}d", error);
282         return callVec;
283     }
284     int32_t vecCnt = replyParcel.ReadInt32();
285     if (vecCnt <= 0 || vecCnt >= MAX_SIZE) {
286         TELEPHONY_LOGE("vector size is error");
287         return callVec;
288     }
289     for (int32_t i = 0; i < vecCnt; i++) {
290         auto value = reinterpret_cast<const CallAttributeInfo *>(replyParcel.ReadRawData(sizeof(CallAttributeInfo)));
291         if (value == nullptr) {
292             TELEPHONY_LOGE("data error");
293             return callVec;
294         }
295         callVec.push_back(*value);
296     }
297     return callVec;
298 }
299 } // namespace Telephony
300 } // namespace OHOS
301