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 "hilog_wrapper.h"
17#include "wallpaper_common_event_manager.h"
18
19namespace OHOS {
20namespace WallpaperMgrService {
21constexpr const char *LOCKSCREEN_WALLPAPER_SETTING_SUCCESS_EVENT = "com.ohos.wallpaperlocksettingsuccess";
22constexpr const char *SYSTEM_WALLPAPER_SETTING_SUCCESS_EVENT = "com.ohos.wallpapersystemsettingsuccess";
23constexpr int32_t LOCKSCREEN_WALLPAPER_SETTING_SUCCESS_CODE = 11000;
24constexpr int32_t SYSTEM_WALLPAPER_SETTING_SUCCESS_CODE = 21000;
25
26bool WallpaperCommonEventManager::PublishEvent(
27    const OHOS::AAFwk::Want &want, int32_t eventCode, const std::string &eventData)
28{
29    OHOS::EventFwk::CommonEventData data;
30    data.SetWant(want);
31    data.SetCode(eventCode);
32    data.SetData(eventData);
33    OHOS::EventFwk::CommonEventPublishInfo publishInfo;
34    bool publishResult = OHOS::EventFwk::CommonEventManager::PublishCommonEvent(data, publishInfo, nullptr);
35    HILOG_INFO("PublishEvent end publishResult = %{public}d", publishResult);
36    return publishResult;
37}
38
39void WallpaperCommonEventManager::SendWallpaperLockSettingMessage(WallpaperResourceType resType)
40{
41    OHOS::AAFwk::Want want;
42    int32_t eventCode = LOCKSCREEN_WALLPAPER_SETTING_SUCCESS_CODE;
43    want.SetParam("WallpaperLockSettingMessage", true);
44    want.SetParam("WallpaperLockScreenResourceType", static_cast<int>(resType));
45    want.SetAction(LOCKSCREEN_WALLPAPER_SETTING_SUCCESS_EVENT);
46    std::string eventData("WallpaperLockSettingMessage");
47    PublishEvent(want, eventCode, eventData);
48}
49
50void WallpaperCommonEventManager::SendWallpaperSystemSettingMessage(WallpaperResourceType resType)
51{
52    OHOS::AAFwk::Want want;
53    int32_t eventCode = SYSTEM_WALLPAPER_SETTING_SUCCESS_CODE;
54    want.SetParam("WallpaperSystemSettingMessage", true);
55    want.SetParam("WallpaperSystemResourceType", static_cast<int>(resType));
56    want.SetAction(SYSTEM_WALLPAPER_SETTING_SUCCESS_EVENT);
57    std::string eventData("WallpaperSystemSettingMessage");
58    PublishEvent(want, eventCode, eventData);
59}
60} // namespace WallpaperMgrService
61} // namespace OHOS