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 "hilog_wrapper.h"
17 #include "wallpaper_common_event_subscriber.h"
18 #include "wallpaper_service.h"
19 
20 namespace OHOS {
21 namespace WallpaperMgrService {
22 
OnReceiveEvent(const OHOS::EventFwk::CommonEventData & data)23 void WallpaperCommonEventSubscriber::OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data)
24 {
25     HILOG_INFO("WallpaperCommonEvent::OnReceiveEvent.");
26     auto want = data.GetWant();
27     std::string action = want.GetAction();
28     if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_ADDED) {
29         wallpaperService_.OnInitUser(data.GetCode());
30     } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED) {
31         wallpaperService_.OnRemovedUser(data.GetCode());
32     } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {
33         wallpaperService_.OnSwitchedUser(data.GetCode());
34     }
35 }
36 
CreateSubscriberInfo()37 CommonEventSubscribeInfo WallpaperCommonEventSubscriber::CreateSubscriberInfo()
38 {
39     OHOS::EventFwk::MatchingSkills matchingSkills;
40     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_ADDED);
41     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED);
42     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
43     return CommonEventSubscribeInfo(matchingSkills);
44 }
45 } // namespace WallpaperMgrService
46 } // namespace OHOS