• 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 #ifndef INNERKITS_WALLPAPER_MANAGER_KITS_H
17 #define INNERKITS_WALLPAPER_MANAGER_KITS_H
18 #include <cstdint>
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "pixel_map.h"
24 #include "visibility.h"
25 #include "wallpaper_common.h"
26 #include "wallpaper_event_listener.h"
27 #include "wallpaper_manager_common_info.h"
28 
29 /**
30  * Interfaces for ohos account subsystem.
31  */
32 namespace OHOS {
33 namespace WallpaperMgrService {
34 class WallpaperManagerkits {
35 public:
36     virtual ~WallpaperManagerkits() = default;
37     DISALLOW_COPY_AND_MOVE(WallpaperManagerkits);
38 
39     /**
40      * Get instance of ohos Wallpaper manager.
41      *
42      * @return Instance of ohos Wallpaper manager.
43      */
44     WALLPAPER_API static WallpaperManagerkits &GetInstance();
45 
46     /**
47     * Wallpaper set.
48     * @param  uriOrPixelMap Wallpaper picture; wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or
49     * WALLPAPER_LOCKSCREEN
50     * @return  ErrorCode
51     */
52     virtual ErrorCode SetWallpaper(std::string uri, int32_t wallpaperType, const ApiInfo &apiInfo) = 0;
53 
54     /**
55     * Wallpaper set.
56     * @param  pixelMap:picture pixelMap struct; wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or
57     * WALLPAPER_LOCKSCREEN
58     * @return  ErrorCode
59     */
60     virtual ErrorCode SetWallpaper(std::shared_ptr<OHOS::Media::PixelMap> pixelMap, int32_t wallpaperType,
61         const ApiInfo &apiInfo) = 0;
62 
63     /**
64         *Obtains the default pixel map of a wallpaper of the specified type.
65         * @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN ;
66         * Obtains image.PixelMap png type The bitmap file of wallpaper
67         * @return ErrorCode
68         * @permission ohos.permission.GET_WALLPAPER
69         * @systemapi Hide this for inner system use.
70     */
71     virtual ErrorCode GetPixelMap(int32_t wallpaperType, const ApiInfo &apiInfo,
72         std::shared_ptr<OHOS::Media::PixelMap> &pixelMap) = 0;
73 
74     /**
75      * Obtains the WallpaperColorsCollection instance for the wallpaper of the specified type.
76      * @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
77      * @return number type of array callback function
78      */
79     virtual ErrorCode GetColors(int32_t wallpaperType, const ApiInfo &apiInfo, std::vector<uint64_t> &colors) = 0;
80 
81     /**
82      * Obtains the ID of the wallpaper of the specified type.
83      * @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
84      * @return number type of callback function
85      */
86     virtual int32_t GetWallpaperId(int32_t wallpaperType) = 0;
87 
88     virtual ErrorCode GetFile(int32_t wallpaperType, int32_t &wallpaperFd) = 0;
89 
90     /**
91      * Obtains the minimum height of the wallpaper.
92      * @return number type of callback function
93      */
94     virtual ErrorCode GetWallpaperMinHeight(const ApiInfo &apiInfo, int32_t &minHeight) = 0;
95 
96     /**
97      * Obtains the minimum width of the wallpaper.
98      * @return number type of callback function
99      */
100     virtual ErrorCode GetWallpaperMinWidth(const ApiInfo &apiInfo, int32_t &minWidth) = 0;
101 
102     /**
103      * Checks whether to allow the application to change the wallpaper for the current user.
104      * @return boolean type of callback function
105      */
106     virtual bool IsChangePermitted() = 0;
107 
108     /**
109      * Checks whether a user is allowed to set wallpapers.
110      * @return boolean type of callback function
111      */
112     virtual bool IsOperationAllowed() = 0;
113 
114     /**
115      * Removes a wallpaper of the specified type and restores the default one.
116      * @param wallpaperType  Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
117      * @permission ohos.permission.SET_WALLPAPER
118      */
119     virtual ErrorCode ResetWallpaper(std::int32_t wallpaperType, const ApiInfo &apiInfo) = 0;
120 
121     /**
122      * Registers a listener for wallpaper event to receive notifications about the changes.
123      * @param type event type
124      * @param listener event listener
125      * @return error code
126      */
127     virtual ErrorCode On(const std::string &type, std::shared_ptr<WallpaperEventListener> listener) = 0;
128 
129     /**
130      * Unregisters a listener for wallpaper event to receive notifications about the changes.
131      * @param type event type
132      * @param listener event listener
133      * @return error code
134      */
135     virtual ErrorCode Off(const std::string &type, std::shared_ptr<WallpaperEventListener> listener) = 0;
136 
137     /**
138      * Sets live wallpaper of the specified type based on the uri path of the MP4 file.
139      * @param uri Indicates the uri path of the MP4 file.
140      * @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
141      * @return ErrorCode
142      * @permission ohos.permission.SET_WALLPAPER
143      */
144     virtual ErrorCode SetVideo(const std::string &uri, const int32_t wallpaperType) = 0;
145 
146     /**
147      * Sets custom wallpaper of the specified type based on the uri path.
148      * @param uri Indicates the uri path.
149      * @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
150      * @return ErrorCode
151      * @permission ohos.permission.SET_WALLPAPER
152      */
153     virtual ErrorCode SetCustomWallpaper(const std::string &uri, int32_t wallpaperType) = 0;
154 
155     /**
156      * The application sends the event to the wallpaper service.
157      * @param eventType Event type, values for SHOW_SYSTEMSCREEN or SHOW_LOCKSCREEN
158      * @return ErrorCode
159      * @permission ohos.permission.SET_WALLPAPER
160      */
161     virtual ErrorCode SendEvent(const std::string &eventType) = 0;
162     using JScallback = bool (*)(int32_t);
163 
164     virtual bool RegisterWallpaperCallback(JScallback callback) = 0;
165 
166     virtual JScallback GetCallback() = 0;
167 
168     virtual void SetCallback(JScallback cb) = 0;
169 
170     virtual void CloseWallpaperFd(int32_t wallpaperType) = 0;
171 
172 protected:
173     WallpaperManagerkits() = default;
174 };
175 } // namespace WallpaperMgrService
176 } // namespace OHOS
177 
178 #endif
179