1 /*
2 * Copyright (C) 2023 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_common_event_helper.h"
17 #include "common_event_data.h"
18 #include "common_event_manager.h"
19 #include "common_event_subscriber.h"
20 #include "log.h"
21
22 using namespace OHOS::EventFwk;
23
24 namespace OHOS {
25 namespace BluetoothHelper {
PublishEvent(const std::string & eventAction,int code,const std::vector<std::string> & permissions)26 bool BluetoothCommonEventHelper::PublishEvent(const std::string &eventAction,int code,
27 const std::vector<std::string> &permissions)
28 {
29 Want want;
30 want.SetAction(eventAction);
31 CommonEventData commonData;
32 commonData.SetWant(want);
33 commonData.SetCode(code);
34 if (permissions.size() > 0) {
35 CommonEventPublishInfo publishInfo;
36 publishInfo.SetSubscriberPermissions(permissions);
37 if (!CommonEventManager::PublishCommonEvent(commonData, publishInfo)) {
38 HILOGE("failed to send common event with permission!");
39 return false;
40 }
41 HILOGI("send common event with permission!");
42 return true;
43 }
44 if (!CommonEventManager::PublishCommonEvent(commonData)) {
45 HILOGE("failed to send common event!");
46 return false;
47 }
48 return true;
49 }
50
PublishBluetoothStateChangeEvent(int code,const std::vector<std::string> & permissions)51 bool BluetoothCommonEventHelper::PublishBluetoothStateChangeEvent(int code,
52 const std::vector<std::string> &permissions)
53 {
54 return BluetoothCommonEventHelper::PublishEvent(COMMON_EVENT_BLUETOOTH_HOST_STATE_UPDATE , code, permissions);
55 }
56 }
57 }
58
59
60