• 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_stub.h"
17 
18 #include <string_ex.h>
19 
20 #include "call_manager_errors.h"
21 #include "telephony_log_wrapper.h"
22 
23 #include "message_option.h"
24 #include "message_parcel.h"
25 
26 #include "call_control_manager.h"
27 
28 namespace OHOS {
29 namespace Telephony {
BluetoothCallStub()30 BluetoothCallStub::BluetoothCallStub()
31 {
32     memberFuncMap_[INTERFACE_BT_ANSWER_CALL] = &BluetoothCallStub::OnAnswerCall;
33     memberFuncMap_[INTERFACE_BT_REJECT_CALL] = &BluetoothCallStub::OnRejectCall;
34     memberFuncMap_[INTERFACE_BT_HOLD_CALL] = &BluetoothCallStub::OnHoldCall;
35     memberFuncMap_[INTERFACE_BT_UNHOLD_CALL] = &BluetoothCallStub::OnUnHoldCall;
36     memberFuncMap_[INTERFACE_BT_DISCONNECT_CALL] = &BluetoothCallStub::OnHangUpCall;
37     memberFuncMap_[INTERFACE_BT_GET_CALL_STATE] = &BluetoothCallStub::OnGetBtCallState;
38     memberFuncMap_[INTERFACE_BT_SWAP_CALL] = &BluetoothCallStub::OnSwitchCall;
39     memberFuncMap_[INTERFACE_BT_COMBINE_CONFERENCE] = &BluetoothCallStub::OnCombineConference;
40     memberFuncMap_[INTERFACE_BT_SEPARATE_CONFERENCE] = &BluetoothCallStub::OnSeparateConference;
41     memberFuncMap_[INTERFACE_BT_START_DTMF] = &BluetoothCallStub::OnStartDtmf;
42     memberFuncMap_[INTERFACE_BT_STOP_DTMF] = &BluetoothCallStub::OnStopDtmf;
43     memberFuncMap_[INTERFACE_BT_GET_CURRENT_CALL_LIST] = &BluetoothCallStub::OnGetCurrentCallList;
44 }
45 
~BluetoothCallStub()46 BluetoothCallStub::~BluetoothCallStub()
47 {
48     memberFuncMap_.clear();
49 }
50 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)51 int32_t BluetoothCallStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
52     MessageOption &option)
53 {
54     std::u16string myDescriptor = BluetoothCallStub::GetDescriptor();
55     std::u16string remoteDescriptor = data.ReadInterfaceToken();
56     if (myDescriptor != remoteDescriptor) {
57         TELEPHONY_LOGE("descriptor checked fail !");
58         return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
59     }
60     TELEPHONY_LOGI("OnReceived, cmd = %{public}u", code);
61     auto itFunc = memberFuncMap_.find(code);
62     if (itFunc != memberFuncMap_.end()) {
63         auto memberFunc = itFunc->second;
64         if (memberFunc != nullptr) {
65             return (this->*memberFunc)(data, reply);
66         }
67     }
68     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
69 }
70 
OnAnswerCall(MessageParcel & data,MessageParcel & reply)71 int32_t BluetoothCallStub::OnAnswerCall(MessageParcel &data, MessageParcel &reply)
72 {
73     int32_t result = AnswerCall();
74     TELEPHONY_LOGI("result:%{public}d", result);
75     if (!reply.WriteInt32(result)) {
76         TELEPHONY_LOGE("fail to write parcel");
77         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
78     }
79     return result;
80 }
81 
OnRejectCall(MessageParcel & data,MessageParcel & reply)82 int32_t BluetoothCallStub::OnRejectCall(MessageParcel &data, MessageParcel &reply)
83 {
84     int32_t result = RejectCall();
85     TELEPHONY_LOGI("result:%{public}d", result);
86     if (!reply.WriteInt32(result)) {
87         TELEPHONY_LOGE("fail to write parcel");
88         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
89     }
90     return result;
91 }
92 
OnHangUpCall(MessageParcel & data,MessageParcel & reply)93 int32_t BluetoothCallStub::OnHangUpCall(MessageParcel &data, MessageParcel &reply)
94 {
95     int32_t result = HangUpCall();
96     TELEPHONY_LOGI("result:%{public}d", result);
97     if (!reply.WriteInt32(result)) {
98         TELEPHONY_LOGE("fail to write parcel");
99         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
100     }
101     return result;
102 }
103 
OnGetBtCallState(MessageParcel & data,MessageParcel & reply)104 int32_t BluetoothCallStub::OnGetBtCallState(MessageParcel &data, MessageParcel &reply)
105 {
106     int32_t result = GetCallState();
107     TELEPHONY_LOGI("result:%{public}d", result);
108     if (!reply.WriteInt32(result)) {
109         TELEPHONY_LOGE("fail to write parcel");
110         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
111     }
112     return TELEPHONY_SUCCESS;
113 }
114 
OnHoldCall(MessageParcel & data,MessageParcel & reply)115 int32_t BluetoothCallStub::OnHoldCall(MessageParcel &data, MessageParcel &reply)
116 {
117     int32_t result = HoldCall();
118     TELEPHONY_LOGI("result:%{public}d", result);
119     if (!reply.WriteInt32(result)) {
120         TELEPHONY_LOGE("fail to write parcel");
121         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
122     }
123     return result;
124 }
125 
OnUnHoldCall(MessageParcel & data,MessageParcel & reply)126 int32_t BluetoothCallStub::OnUnHoldCall(MessageParcel &data, MessageParcel &reply)
127 {
128     int32_t result = UnHoldCall();
129     TELEPHONY_LOGI("result:%{public}d", result);
130     if (!reply.WriteInt32(result)) {
131         TELEPHONY_LOGE("fail to write parcel");
132         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
133     }
134     return result;
135 }
136 
OnSwitchCall(MessageParcel & data,MessageParcel & reply)137 int32_t BluetoothCallStub::OnSwitchCall(MessageParcel &data, MessageParcel &reply)
138 {
139     int32_t result = SwitchCall();
140     TELEPHONY_LOGI("result:%{public}d", result);
141     if (!reply.WriteInt32(result)) {
142         TELEPHONY_LOGE("fail to write parcel");
143         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
144     }
145     return result;
146 }
147 
OnCombineConference(MessageParcel & data,MessageParcel & reply)148 int32_t BluetoothCallStub::OnCombineConference(MessageParcel &data, MessageParcel &reply)
149 {
150     int32_t result = CombineConference();
151     TELEPHONY_LOGI("result:%{public}d", result);
152     if (!reply.WriteInt32(result)) {
153         TELEPHONY_LOGE("fail to write parcel");
154         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
155     }
156     return TELEPHONY_SUCCESS;
157 }
158 
OnSeparateConference(MessageParcel & data,MessageParcel & reply)159 int32_t BluetoothCallStub::OnSeparateConference(MessageParcel &data, MessageParcel &reply)
160 {
161     int32_t result = SeparateConference();
162     TELEPHONY_LOGI("result:%{public}d", result);
163     if (!reply.WriteInt32(result)) {
164         TELEPHONY_LOGE("fail to write parcel");
165         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
166     }
167     return TELEPHONY_SUCCESS;
168 }
169 
OnStartDtmf(MessageParcel & data,MessageParcel & reply)170 int32_t BluetoothCallStub::OnStartDtmf(MessageParcel &data, MessageParcel &reply)
171 {
172     int32_t result = TELEPHONY_ERR_FAIL;
173     char str = static_cast<char>(data.ReadInt8());
174     result = StartDtmf(str);
175     TELEPHONY_LOGI("result:%{public}d", result);
176     if (!reply.WriteInt32(result)) {
177         TELEPHONY_LOGE("fail to write parcel");
178         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
179     }
180     return TELEPHONY_SUCCESS;
181 }
182 
OnStopDtmf(MessageParcel & data,MessageParcel & reply)183 int32_t BluetoothCallStub::OnStopDtmf(MessageParcel &data, MessageParcel &reply)
184 {
185     int32_t result = TELEPHONY_ERR_FAIL;
186     result = StopDtmf();
187     TELEPHONY_LOGI("result:%{public}d", result);
188     if (!reply.WriteInt32(result)) {
189         TELEPHONY_LOGE("fail to write parcel");
190         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
191     }
192     return TELEPHONY_SUCCESS;
193 }
194 
OnGetCurrentCallList(MessageParcel & data,MessageParcel & reply)195 int32_t BluetoothCallStub::OnGetCurrentCallList(MessageParcel &data, MessageParcel &reply)
196 {
197     int32_t slotId = data.ReadInt32();
198     std::vector<CallAttributeInfo> callVec = GetCurrentCallList(slotId);
199     reply.WriteInt32(callVec.size());
200     std::vector<CallAttributeInfo>::iterator it = callVec.begin();
201     for (; it != callVec.end(); ++it) {
202         reply.WriteRawData((const void *)&(*it), sizeof(CallAttributeInfo));
203     }
204     return TELEPHONY_SUCCESS;
205 }
206 } // namespace Telephony
207 } // namespace OHOS
208