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