• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 "wallpaper_common_event.h"
17 #include "hilog_wrapper.h"
18 #include "wallpaper_service.h"
19 namespace OHOS {
20 namespace WallpaperMgrService {
21 std::shared_ptr<WallpaperCommonEvent> WallpaperCommonEvent::subscriber = nullptr;
22 
OnReceiveEvent(const OHOS::EventFwk::CommonEventData & data)23 void WallpaperCommonEvent::OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data)
24 {
25     HILOG_INFO("WallpaperCommonEvent::OnReceiveEvent");
26     WallpaperService::OnBootPhase();
27 }
28 
PublishEvent(const OHOS::AAFwk::Want & want,int eventCode,const std::string & eventData)29 bool WallpaperCommonEvent::PublishEvent(const OHOS::AAFwk::Want &want, int eventCode, const std::string &eventData)
30 {
31     OHOS::EventFwk::CommonEventData data;
32     data.SetWant(want);
33     data.SetCode(eventCode);
34     data.SetData(eventData);
35     OHOS::EventFwk::CommonEventPublishInfo publishInfo;
36     publishInfo.SetOrdered(true);
37     bool publishResult = OHOS::EventFwk::CommonEventManager::PublishCommonEvent(data, publishInfo, nullptr);
38     HILOG_INFO("PublishEvent end publishResult = %{public}d", publishResult);
39     return publishResult;
40 }
41 
42 
UnregisterSubscriber(std::shared_ptr<OHOS::EventFwk::CommonEventSubscriber> subscriber)43 void WallpaperCommonEvent::UnregisterSubscriber(std::shared_ptr<OHOS::EventFwk::CommonEventSubscriber> subscriber)
44 {
45     if (subscriber != nullptr) {
46         bool subscribeResult = OHOS::EventFwk::CommonEventManager::UnSubscribeCommonEvent(subscriber);
47         subscriber = nullptr;
48         HILOG_INFO("WallpaperCommonEvent::UnregisterSubscriber end###subscribeResult = %{public}d", subscribeResult);
49     }
50 }
51 
RegisterSubscriber()52 bool WallpaperCommonEvent::RegisterSubscriber()
53 {
54     HILOG_INFO("WallpaperCommonEvent::RegisterSubscriber");
55     OHOS::EventFwk::MatchingSkills matchingSkills;
56     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED);
57     OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
58     subscriber = std::make_shared<WallpaperCommonEvent>(subscriberInfo);
59     return OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber);
60 }
61 
SendWallpaperLockSettingMessage()62 void WallpaperCommonEvent::SendWallpaperLockSettingMessage()
63 {
64     OHOS::AAFwk::Want want;
65     int32_t eventCode = WALLPAPER_LOCK_SETTING_SUCCESS_CODE;
66     want.SetParam("WallpaperLockSettingMessage", true);
67     want.SetAction(WALLPAPER_LOCK_SETTING_SUCCESS_EVENT);
68     std::string eventData("WallpaperLockSettingMessage");
69     PublishEvent(want, eventCode, eventData);
70 }
71 
SendWallpaperSystemSettingMessage()72 void WallpaperCommonEvent::SendWallpaperSystemSettingMessage()
73 {
74     OHOS::AAFwk::Want want;
75     int32_t eventCode = WALLPAPER_SYSTEM_SETTING_SUCCESS_CODE;
76     want.SetParam("WallpaperSystemSettingMessage", true);
77     want.SetAction(WALLPAPER_SYSTEM_SETTING_SUCCESS_EVENT);
78     std::string eventData("WallpaperSystemSettingMessage");
79     PublishEvent(want, eventCode, eventData);
80 }
81 }
82 }