• 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_map_mce_stub.h"
17 #include "bluetooth_log.h"
18 
19 namespace OHOS {
20 namespace Bluetooth {
BluetoothMapMceStub()21 BluetoothMapMceStub::BluetoothMapMceStub()
22 {
23     HILOGD("%{public}s start.", __func__);
24     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_REGISTER_OBSERVER)] =
25         &BluetoothMapMceStub::RegisterObserverInner;
26     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_DE_REGISTER_OBSERVER)] =
27         &BluetoothMapMceStub::DeregisterObserverInner;
28     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_CONNECT)] =
29         &BluetoothMapMceStub::ConnectInner;
30     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_DISCONNECT)] =
31         &BluetoothMapMceStub::DisconnectInner;
32     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_ISCONNECTED)] =
33         &BluetoothMapMceStub::IsConnectedInner;
34     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_GET_CONNECT_DEVICES)] =
35         &BluetoothMapMceStub::GetConnectDevicesInner;
36     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_GET_DEVICES_BY_STATES)] =
37         &BluetoothMapMceStub::GetDevicesByStatesInner;
38     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_GET_CONNECTION_STATE)] =
39         &BluetoothMapMceStub::GetConnectionStateInner;
40     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_SET_CONNECTION_STRATEGY)] =
41         &BluetoothMapMceStub::SetConnectionStrategyInner;
42     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_GET_CONNECTION_STRATEGY)] =
43         &BluetoothMapMceStub::GetConnectionStrategyInner;
44     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_GET_UNREAD_MESSAGES)] =
45         &BluetoothMapMceStub::GetUnreadMessagesInner;
46     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_GET_SUPPORTED_FEATURES)] =
47         &BluetoothMapMceStub::GetSupportedFeaturesInner;
48     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_SEND_MESSAGE)] =
49         &BluetoothMapMceStub::SendMessageInner;
50     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_SET_NOTIFICATION_FILTER)] =
51         &BluetoothMapMceStub::SetNotificationFilterInner;
52     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_GET_MESSAGES_LISTING)] =
53         &BluetoothMapMceStub::GetMessagesListingInner;
54     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_GET_MESSAGE)] =
55         &BluetoothMapMceStub::GetMessageInner;
56     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_UPDATE_INBOX)] =
57         &BluetoothMapMceStub::UpdateInboxInner;
58     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_GET_CONVERSATION_LISTING)] =
59         &BluetoothMapMceStub::GetConversationListingInner;
60     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_SET_MESSAGE_STATUS)] =
61         &BluetoothMapMceStub::SetMessageStatusInner;
62     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_SET_OWNER_STATUS)] =
63         &BluetoothMapMceStub::SetOwnerStatusInner;
64     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_GET_OWNER_STATUS)] =
65         &BluetoothMapMceStub::GetOwnerStatusInner;
66     memberFuncMap_[static_cast<uint32_t>(IBluetoothMapMce::Code::MCE_GET_MAS_INSTANCE_INFO)] =
67         &BluetoothMapMceStub::GetMasInstanceInfoInner;
68 }
69 
~BluetoothMapMceStub()70 BluetoothMapMceStub::~BluetoothMapMceStub()
71 {
72     HILOGD("%{public}s start.", __func__);
73     memberFuncMap_.clear();
74 }
75 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)76 int BluetoothMapMceStub::OnRemoteRequest(
77     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
78 {
79     HILOGD("BluetoothMapMceStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d",
80         code,
81         option.GetFlags());
82     std::u16string descriptor = BluetoothMapMceStub::GetDescriptor();
83     std::u16string remoteDescriptor = data.ReadInterfaceToken();
84     if (descriptor != remoteDescriptor) {
85         HILOGI("local descriptor is not equal to remote");
86         return ERR_INVALID_STATE;
87     }
88     auto itFunc = memberFuncMap_.find(code);
89     if (itFunc != memberFuncMap_.end()) {
90         auto memberFunc = itFunc->second;
91         if (memberFunc != nullptr) {
92             return (this->*memberFunc)(data, reply);
93         }
94     }
95     HILOGW("BluetoothMapMceStub::OnRemoteRequest, default case, need check.");
96     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
97 }
98 
RegisterObserverInner(MessageParcel & data,MessageParcel & reply)99 ErrCode BluetoothMapMceStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)
100 {
101     HILOGI("BluetoothMapMceStub::RegisterObserverInner Triggered!");
102     sptr<IRemoteObject> remote = data.ReadRemoteObject();
103     const sptr<IBluetoothMapMceObserver> callback = OHOS::iface_cast<IBluetoothMapMceObserver>(remote);
104     RegisterObserver(callback);
105     return NO_ERROR;
106 }
107 
DeregisterObserverInner(MessageParcel & data,MessageParcel & reply)108 ErrCode BluetoothMapMceStub::DeregisterObserverInner(MessageParcel &data, MessageParcel &reply)
109 {
110     HILOGI("BluetoothMapMceStub::DeregisterObserverInner Triggered!");
111     sptr<IRemoteObject> remote = data.ReadRemoteObject();
112     const sptr<IBluetoothMapMceObserver> callback = OHOS::iface_cast<IBluetoothMapMceObserver>(remote);
113     DeregisterObserver(callback);
114     return NO_ERROR;
115 }
116 
ConnectInner(MessageParcel & data,MessageParcel & reply)117 ErrCode BluetoothMapMceStub::ConnectInner(MessageParcel &data, MessageParcel &reply)
118 {
119     HILOGI("BluetoothMapMceStub::ConnectInner Triggered!");
120     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
121     int result = Connect(*device);
122     delete device;
123     bool ret = reply.WriteInt32(result);
124     if (!ret) {
125         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
126         return ERR_INVALID_VALUE;
127     }
128     return NO_ERROR;
129 }
130 
DisconnectInner(MessageParcel & data,MessageParcel & reply)131 ErrCode BluetoothMapMceStub::DisconnectInner(MessageParcel &data, MessageParcel &reply)
132 {
133     HILOGI("BluetoothMapMceStub::DisconnectInner Triggered!");
134     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
135     int result = Disconnect(*device);
136     delete device;
137     bool ret = reply.WriteInt32(result);
138     if (!ret) {
139         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
140         return ERR_INVALID_VALUE;
141     }
142     return NO_ERROR;
143 }
144 
IsConnectedInner(MessageParcel & data,MessageParcel & reply)145 ErrCode BluetoothMapMceStub::IsConnectedInner(MessageParcel &data, MessageParcel &reply)
146 {
147     HILOGI("BluetoothMapMceStub::IsConnectedInner Triggered!");
148     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
149     int result = IsConnected(*device);
150     delete device;
151     bool ret = reply.WriteInt32(result);
152     if (!ret) {
153         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
154         return ERR_INVALID_VALUE;
155     }
156     return NO_ERROR;
157 }
158 
GetConnectDevicesInner(MessageParcel & data,MessageParcel & reply)159 ErrCode BluetoothMapMceStub::GetConnectDevicesInner(MessageParcel &data, MessageParcel &reply)
160 {
161     HILOGI("BluetoothMapMceStub::GetConnectDevicesInner Triggered!");
162     std::vector<BluetoothRawAddress> devices;
163     GetConnectDevices(devices);
164     reply.WriteInt32(devices.size());
165     int num = devices.size();
166     for (int i = 0; i < num; i++) {
167         bool ret = reply.WriteParcelable(&devices[i]);
168         if (!ret) {
169             HILOGE("WriteParcelable<GetConnectDevicesInner> failed");
170             return ERR_INVALID_VALUE;
171         }
172     }
173     return NO_ERROR;
174 }
175 
GetDevicesByStatesInner(MessageParcel & data,MessageParcel & reply)176 ErrCode BluetoothMapMceStub::GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply)
177 {
178     HILOGI("BluetoothMapMceStub::GetDevicesByStates Triggered!");
179     std::vector<int32_t> states;
180     if (!data.ReadInt32Vector(&states)) {
181         HILOGW("BluetoothMapMceStub::GetDevicesByStatesInner: get tmpState failed.");
182         return INVALID_DATA;
183     }
184     std::vector<BluetoothRawAddress> rawDevices;
185     GetDevicesByStates(states, rawDevices);
186     reply.WriteInt32(rawDevices.size());
187     int num = rawDevices.size();
188     for (int i = 0; i < num; i++) {
189         bool ret = reply.WriteParcelable(&rawDevices[i]);
190         if (!ret) {
191             HILOGE("WriteParcelable<GetDevicesByStatesInner> failed");
192             return ERR_INVALID_VALUE;
193         }
194     }
195     return NO_ERROR;
196 }
197 
GetConnectionStateInner(MessageParcel & data,MessageParcel & reply)198 ErrCode BluetoothMapMceStub::GetConnectionStateInner(MessageParcel &data, MessageParcel &reply)
199 {
200     HILOGI("BluetoothMapMceStub::GetConnectionStateInner Triggered!");
201     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
202     int result = GetConnectionState(*device);
203     delete device;
204     bool ret = reply.WriteInt32(result);
205     if (!ret) {
206         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
207         return ERR_INVALID_VALUE;
208     }
209     return NO_ERROR;
210 }
211 
SetConnectionStrategyInner(MessageParcel & data,MessageParcel & reply)212 ErrCode BluetoothMapMceStub::SetConnectionStrategyInner(MessageParcel &data, MessageParcel &reply)
213 {
214     HILOGI("BluetoothMapMceStub::SetConnectionStrategyInner Triggered!");
215     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
216     int32_t strategy = data.ReadInt32();
217     int result = SetConnectionStrategy(*device, strategy);
218     delete device;
219     bool ret = reply.WriteInt32(result);
220     if (!ret) {
221         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
222         return ERR_INVALID_VALUE;
223     }
224     return NO_ERROR;
225 }
226 
GetConnectionStrategyInner(MessageParcel & data,MessageParcel & reply)227 ErrCode BluetoothMapMceStub::GetConnectionStrategyInner(MessageParcel &data, MessageParcel &reply)
228 {
229     HILOGI("BluetoothMapMceStub::GetConnectionStrategyInner Triggered!");
230     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
231     int result = GetConnectionStrategy(*device);
232     delete device;
233     bool ret = reply.WriteInt32(result);
234     if (!ret) {
235         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
236         return ERR_INVALID_VALUE;
237     }
238     return NO_ERROR;
239 }
240 
GetUnreadMessagesInner(MessageParcel & data,MessageParcel & reply)241 ErrCode BluetoothMapMceStub::GetUnreadMessagesInner(MessageParcel &data, MessageParcel &reply)
242 {
243     HILOGI("BluetoothMapMceStub::GetUnreadMessagesInner Triggered!");
244     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
245     int32_t msgType = data.ReadInt32();
246     int32_t max = data.ReadInt32();
247     int result = GetUnreadMessages(*device, msgType, max);
248     delete device;
249     bool ret = reply.WriteInt32(result);
250     if (!ret) {
251         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
252         return ERR_INVALID_VALUE;
253     }
254     return NO_ERROR;
255 }
256 
GetSupportedFeaturesInner(MessageParcel & data,MessageParcel & reply)257 ErrCode BluetoothMapMceStub::GetSupportedFeaturesInner(MessageParcel &data, MessageParcel &reply)
258 {
259     HILOGI("BluetoothMapMceStub::GetSupportedFeaturesInner Triggered!");
260     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
261     int result = GetSupportedFeatures(*device);
262     delete device;
263     bool ret = reply.WriteInt32(result);
264     if (!ret) {
265         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
266         return ERR_INVALID_VALUE;
267     }
268     return NO_ERROR;
269 }
270 
SendMessageInner(MessageParcel & data,MessageParcel & reply)271 ErrCode BluetoothMapMceStub::SendMessageInner(MessageParcel &data, MessageParcel &reply)
272 {
273     HILOGI("BluetoothMapMceStub::SendMessageInner Triggered!");
274     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
275     const BluetoothIProfileSendMessageParameters *msg = data.ReadParcelable<BluetoothIProfileSendMessageParameters>();
276     int result = SendMessage(*device, *msg);
277     delete device;
278     delete msg;
279     bool ret = reply.WriteInt32(result);
280     if (!ret) {
281         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
282         return ERR_INVALID_VALUE;
283     }
284     return NO_ERROR;
285 }
286 
SetNotificationFilterInner(MessageParcel & data,MessageParcel & reply)287 ErrCode BluetoothMapMceStub::SetNotificationFilterInner(MessageParcel &data, MessageParcel &reply)
288 {
289     HILOGI("BluetoothMapMceStub::SetNotificationFilterInner Triggered!");
290     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
291     int32_t mask = data.ReadInt32();
292     int result = SetNotificationFilter(*device, mask);
293     delete device;
294     bool ret = reply.WriteInt32(result);
295     if (!ret) {
296         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
297         return ERR_INVALID_VALUE;
298     }
299     return NO_ERROR;
300 }
301 
GetMessagesListingInner(MessageParcel & data,MessageParcel & reply)302 ErrCode BluetoothMapMceStub::GetMessagesListingInner(MessageParcel &data, MessageParcel &reply)
303 {
304     HILOGI("BluetoothMapMceStub::GetMessagesListingInner Triggered!");
305     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
306     const BluetoothIProfileGetMessagesListingParameters *msg =
307         data.ReadParcelable<BluetoothIProfileGetMessagesListingParameters>();
308     int result = GetMessagesListing(*device, *msg);
309     delete device;
310     delete msg;
311     bool ret = reply.WriteInt32(result);
312     if (!ret) {
313         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
314         return ERR_INVALID_VALUE;
315     }
316     return NO_ERROR;
317 }
318 
GetMessageInner(MessageParcel & data,MessageParcel & reply)319 ErrCode BluetoothMapMceStub::GetMessageInner(MessageParcel &data, MessageParcel &reply)
320 {
321     HILOGI("BluetoothMapMceStub::GetMessagesListingInner Triggered!");
322     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
323     int32_t msgType = data.ReadInt32();
324     const std::u16string msgHandle = data.ReadString16();
325     const BluetoothIProfileGetMessageParameters *msg =
326         data.ReadParcelable<BluetoothIProfileGetMessageParameters>();
327     int result = GetMessage(*device, msgType, msgHandle, *msg);
328     delete device;
329     delete msg;
330     bool ret = reply.WriteInt32(result);
331     if (!ret) {
332         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
333         return ERR_INVALID_VALUE;
334     }
335     return NO_ERROR;
336 }
337 
UpdateInboxInner(MessageParcel & data,MessageParcel & reply)338 ErrCode BluetoothMapMceStub::UpdateInboxInner(MessageParcel &data, MessageParcel &reply)
339 {
340     HILOGI("BluetoothMapMceStub::UpdateInboxInner Triggered!");
341     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
342     int32_t msgType = data.ReadInt32();
343     int result = UpdateInbox(*device, msgType);
344     delete device;
345     bool ret = reply.WriteInt32(result);
346     if (!ret) {
347         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
348         return ERR_INVALID_VALUE;
349     }
350     return NO_ERROR;
351 }
352 
GetConversationListingInner(MessageParcel & data,MessageParcel & reply)353 ErrCode BluetoothMapMceStub::GetConversationListingInner(MessageParcel &data, MessageParcel &reply)
354 {
355     HILOGI("BluetoothMapMceStub::GetConversationListingInner Triggered!");
356     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
357     const BluetoothIProfileGetConversationListingParameters *msg =
358         data.ReadParcelable<BluetoothIProfileGetConversationListingParameters>();
359     int result = GetConversationListing(*device, *msg);
360     delete device;
361     delete msg;
362     bool ret = reply.WriteInt32(result);
363     if (!ret) {
364         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
365         return ERR_INVALID_VALUE;
366     }
367     return NO_ERROR;
368 }
369 
SetMessageStatusInner(MessageParcel & data,MessageParcel & reply)370 ErrCode BluetoothMapMceStub::SetMessageStatusInner(MessageParcel &data, MessageParcel &reply)
371 {
372     HILOGI("BluetoothMapMceStub::SetMessageStatusInner Triggered!");
373     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
374     int32_t msgType = data.ReadInt32();
375     const std::u16string msgHandle = data.ReadString16();
376     int32_t statusIndicator = data.ReadInt32();
377     int32_t statusValue = data.ReadInt32();
378     const std::string extendedData = data.ReadString();
379     int result = SetMessageStatus(*device, msgType, msgHandle, statusIndicator, statusValue, extendedData);
380     delete device;
381     bool ret = reply.WriteInt32(result);
382     if (!ret) {
383         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
384         return ERR_INVALID_VALUE;
385     }
386     return NO_ERROR;
387 }
388 
SetOwnerStatusInner(MessageParcel & data,MessageParcel & reply)389 ErrCode BluetoothMapMceStub::SetOwnerStatusInner(MessageParcel &data, MessageParcel &reply)
390 {
391     HILOGI("BluetoothMapMceStub::SetOwnerStatusInner Triggered!");
392     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
393     const BluetoothIProfileSetOwnerStatusParameters *msg =
394         data.ReadParcelable<BluetoothIProfileSetOwnerStatusParameters>();
395     int result = SetOwnerStatus(*device, *msg);
396     delete device;
397     delete msg;
398     bool ret = reply.WriteInt32(result);
399     if (!ret) {
400         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
401         return ERR_INVALID_VALUE;
402     }
403     return NO_ERROR;
404 }
405 
GetOwnerStatusInner(MessageParcel & data,MessageParcel & reply)406 ErrCode BluetoothMapMceStub::GetOwnerStatusInner(MessageParcel &data, MessageParcel &reply)
407 {
408     HILOGI("BluetoothMapMceStub::SetOwnerStatusInner Triggered!");
409     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
410     const std::string conversationId = data.ReadString();
411     int result = GetOwnerStatus(*device, conversationId);
412     delete device;
413     bool ret = reply.WriteInt32(result);
414     if (!ret) {
415         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
416         return ERR_INVALID_VALUE;
417     }
418     return NO_ERROR;
419 }
420 
GetMasInstanceInfoInner(MessageParcel & data,MessageParcel & reply)421 ErrCode BluetoothMapMceStub::GetMasInstanceInfoInner(MessageParcel &data, MessageParcel &reply)
422 {
423     HILOGI("BluetoothMapMceStub::GetMasInstanceInfoInner Triggered!");
424     const BluetoothRawAddress *device = data.ReadParcelable<BluetoothRawAddress>();
425     BluetoothIProfileMasInstanceInfoList result;
426     GetMasInstanceInfo(*device, result);
427     delete device;
428     bool ret = reply.WriteParcelable(&result);
429     if (!ret) {
430         HILOGE("BluetoothMapMceStub: reply writing failed in: %{public}s.", __func__);
431         return ERR_INVALID_VALUE;
432     }
433     return NO_ERROR;
434 }
435 }  // namespace Bluetooth
436 }  // namespace OHOS
437