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 #ifndef SERVICES_INCLUDE_WALLPAPER_SERVICE_INTERFACE_H
17 #define SERVICES_INCLUDE_WALLPAPER_SERVICE_INTERFACE_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "i_wallpaper_callback.h"
23 #include "iremote_broker.h"
24 #include "iwallpaper_event_listener.h"
25 #include "pixel_map.h"
26 #include "pixel_map_parcel.h"
27 #include "wallpaper_common.h"
28 #include "wallpaper_event_listener.h"
29 #include "wallpaper_event_listener_client.h"
30 #include "wallpaper_manager_common_info.h"
31 
32 namespace OHOS {
33 namespace WallpaperMgrService {
34 class IWallpaperService : public IRemoteBroker {
35 public:
36     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.Wallpaper.IWallpaperService");
37     struct getPixelMap {
38         std::string result;
39         int32_t fileLen;
40     };
41 
42     struct FdInfo {
43         int32_t fd = -1;
44         int32_t size = 0;
45     };
46 
47     /**
48     * Wallpaper set.
49     * @param  uriOrPixelMap Wallpaper picture; wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or
50     * WALLPAPER_LOCKSCREEN
51     * @return  true or false
52     */
53     virtual ErrorCode SetWallpaper(int32_t fd, int32_t wallpaperType, int32_t length) = 0;
54     virtual ErrorCode SetAllWallpapers(
55         std::vector<WallpaperPictureInfo> wallpaperPictureInfo, int32_t wallpaperType) = 0;
56     virtual ErrorCode SetWallpaperByPixelMap(
57         std::shared_ptr<OHOS::Media::PixelMap> pixelMap, int32_t wallpaperType) = 0;
58     virtual ErrorCode GetPixelMap(int32_t wallpaperType, FdInfo &fdInfo) = 0;
59     virtual ErrorCode GetCorrespondWallpaper(
60         int32_t wallpaperType, int32_t foldState, int32_t rotateState, FdInfo &fdInfo) = 0;
61     /**
62      * Obtains the WallpaperColorsCollection instance for the wallpaper of the specified type.
63      * @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
64      * @return number type of array callback function
65      */
66     virtual ErrorCode GetColors(int32_t wallpaperType, std::vector<uint64_t> &colors) = 0;
67 
68     virtual ErrorCode GetFile(int32_t wallpaperType, int32_t &wallpaperFd) = 0;
69 
70     /**
71      * Obtains the ID of the wallpaper of the specified type.
72      * @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
73      * @return number type of callback function
74      */
75     virtual int32_t GetWallpaperId(int32_t wallpaperType) = 0;
76 
77     /**
78      * Checks whether to allow the application to change the wallpaper for the current user.
79      * @return boolean type of callback function
80      */
81     virtual bool IsChangePermitted() = 0;
82 
83     /**
84      * Checks whether a user is allowed to set wallpapers.
85      * @return boolean type of callback function
86      */
87     virtual bool IsOperationAllowed() = 0;
88 
89     /**
90      * Removes a wallpaper of the specified type and restores the default one.
91      * @param wallpaperType  Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
92      * @permission ohos.permission.SET_WALLPAPER
93      */
94     virtual ErrorCode ResetWallpaper(int32_t wallpaperType) = 0;
95 
96     /**
97      * Registers a listener for wallpaper event changes to receive notifications about the changes.
98      * @param type event type
99      * @param listener event observer.
100      * @return error code
101      */
102     virtual ErrorCode On(const std::string &type, sptr<IWallpaperEventListener> listener) = 0;
103 
104     /**
105      * Unregisters a listener for wallpaper event changes.
106      * @param type event type
107      * @param listener event observer.
108      * @return error code
109      */
110     virtual ErrorCode Off(const std::string &type, sptr<IWallpaperEventListener> listener) = 0;
111 
112     virtual bool RegisterWallpaperCallback(const sptr<IWallpaperCallback> callback) = 0;
113 
114     virtual ErrorCode SetWallpaperV9(int32_t fd, int32_t wallpaperType, int32_t length) = 0;
115     virtual ErrorCode SetWallpaperV9ByPixelMap(
116         std::shared_ptr<OHOS::Media::PixelMap> pixelMap, int32_t wallpaperType) = 0;
117     virtual ErrorCode GetPixelMapV9(int32_t wallpaperType, FdInfo &fdInfo) = 0;
118     virtual ErrorCode GetColorsV9(int32_t wallpaperType, std::vector<uint64_t> &colors) = 0;
119     virtual ErrorCode ResetWallpaperV9(int32_t wallpaperType) = 0;
120 
121     /**
122      * @brief Sets live wallpaper of the specified type based on the uri path
123      *        of the MP4 file.
124      *
125      * Need @permission ohos.permission.SET_WALLPAPER
126      *
127      * @param fd Indicates the handle of the MP4 file.
128      * @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM
129      *        or WALLPAPER_LOCKSCREEN
130      * @param length file size of the MP4 file.
131      * @return ErrorCode
132      */
133     virtual ErrorCode SetVideo(int32_t fd, int32_t wallpaperType, int32_t length) = 0;
134 
135     /**
136      * Sets the custom wallpaper.
137      */
138     virtual ErrorCode SetCustomWallpaper(int32_t fd, int32_t wallpaperType, int32_t length) = 0;
139 
140     /**
141      * @brief The application sends the event to the wallpaper service.
142      *
143      * Need @permission ohos.permission.SET_WALLPAPER
144      *
145      * @param eventType Event type, values for SHOW_SYSTEMSCREEN or SHOW_LOCKSCREEN
146      * @return ErrorCode
147      */
148     virtual ErrorCode SendEvent(const std::string &eventType) = 0;
149 };
150 } // namespace WallpaperMgrService
151 } // namespace OHOS
152 #endif // SERVICES_INCLUDE_WALLPAPER_SERVICE_INTERFACE_H