• 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_H
17 #define INNERKITS_WALLPAPER_MANAGER_H
18 
19 #include <vector>
20 #include <string>
21 #include <mutex>
22 #include <list>
23 #include <map>
24 #include "ipc_skeleton.h"
25 #include "wallpaper_manager_kits.h"
26 #include "i_wallpaper_service.h"
27 #include "singleton.h"
28 #include "fault_reporter.h"
29 #include "wallpaper_common.h"
30 
31 using JScallback = bool (*) (int);
32 namespace OHOS {
33 using namespace MiscServices;
34 namespace WallpaperMgrService {
35 class WallpaperManager final : public WallpaperManagerkits, public DelayedRefSingleton<WallpaperManager> {
36     DECLARE_DELAYED_REF_SINGLETON(WallpaperManager);
37 public:
38     DISALLOW_COPY_AND_MOVE(WallpaperManager);
39 
40     /**
41     * Wallpaper set.
42     * @param  uriOrPixelMap Wallpaper picture; wallpaperType Wallpaper type,
43     * values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
44     * @return  true or false
45     */
46     int32_t SetWallpaper(std::string url, int32_t wallpaperType, const ApiInfo &apiInfo) final;
47 
48       /**
49     * Wallpaper set.
50     * @param  pixelMap:picture pixelMap struct; wallpaperType Wallpaper type,
51     * values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
52     * @return  true or false
53     */
54     int32_t SetWallpaper(std::shared_ptr<OHOS::Media::PixelMap> pixelMap, int32_t wallpaperType,
55         const ApiInfo &apiInfo) final;
56 
57     /**
58         *Obtains the default pixel map of a wallpaper of the specified type.
59         * @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
60         * @return image.PixelMap png type The bitmap file of wallpaper
61         * @permission ohos.permission.GET_WALLPAPER
62         * @systemapi Hide this for inner system use.
63     */
64 
65     int32_t GetPixelMap(int32_t wallpaperType, const ApiInfo &apiInfo,
66         std::shared_ptr<OHOS::Media::PixelMap> &PixelMap) final;
67 
68     /**
69      * Obtains the WallpaperColorsCollection instance for the wallpaper of the specified type.
70      * @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
71      * @return number type of array callback function
72      */
73     int32_t GetColors(int32_t wallpaperType, const ApiInfo &apiInfo, std::vector<uint64_t> &colors) final;
74 
75     /**
76      * Obtains the ID of the wallpaper of the specified type.
77      * @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
78      * @return number type of callback function
79      */
80     int GetWallpaperId(int wallpaperType) final;
81 
82     int32_t GetFile(int wallpaperType, int32_t &wallpaperFd) final;
83 
84     /**
85      * Obtains the minimum height of the wallpaper.
86      * @return number type of callback function
87      */
88     int32_t GetWallpaperMinHeight(const ApiInfo &apiInfo, int32_t &minHeight) final;
89 
90      /**
91      * Obtains the minimum width of the wallpaper.
92      * @return number type of callback function
93      */
94     int32_t GetWallpaperMinWidth(const ApiInfo &apiInfo, int32_t &minWidth) final;
95 
96      /**
97      * Checks whether to allow the application to change the wallpaper for the current user.
98      * @return boolean type of callback function
99      */
100     bool IsChangePermitted() final;
101 
102     /**
103      * Checks whether a user is allowed to set wallpapers.
104      * @return boolean type of callback function
105      */
106     bool IsOperationAllowed() final;
107 
108      /**
109      * Removes a wallpaper of the specified type and restores the default one.
110      * @param wallpaperType  Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
111      * @permission ohos.permission.SET_WALLPAPER
112      */
113     int32_t ResetWallpaper(std::int32_t wallpaperType, const ApiInfo &apiInfo) final;
114 
115      /**
116      * Registers a listener for wallpaper color changes to receive notifications about the changes.
117      * @param type The incoming colorChange table open receiver pick a color change wallpaper wallpaper color changes
118      * @param callback Provides dominant colors of the wallpaper.
119      * @return  true or false
120      */
121     bool On(const std::string &type, std::shared_ptr<WallpaperColorChangeListener> listener) final;
122 
123     /**
124      * Registers a listener for wallpaper color changes to receive notifications about the changes.
125      * @param type Incoming 'colorChange' table delete receiver to pick up a color change wallpaper wallpaper color
126      * changes
127      * @param callback Provides dominant colors of the wallpaper.
128      */
129     bool Off(const std::string &type, std::shared_ptr<WallpaperColorChangeListener> listener) final;
130 
131     bool RegisterWallpaperCallback(bool (*callback) (int)) final;
132 
133     JScallback GetCallback() final;
134 
135     void SetCallback(bool (*cb) (int)) final;
136 
137     void ReporterFault(FaultType faultType, FaultCode faultCode);
138 
139     void CloseWallpaperFd(int32_t wallpaperType);
140 private:
141     class DeathRecipient final : public IRemoteObject::DeathRecipient {
142     public:
143         DeathRecipient() = default;
144         ~DeathRecipient() final = default;
145         DISALLOW_COPY_AND_MOVE(DeathRecipient);
146 
147         void OnRemoteDied(const wptr<IRemoteObject>& remote) final;
148     };
149 
150     template<typename F, typename... Args>
151     ErrCode CallService(F func, Args&&... args);
152 
153     void ResetService(const wptr<IRemoteObject>& remote);
154     sptr<IWallpaperService> GetService();
155     int64_t WritePixelMapToStream(std::ostream &outputStream, std::shared_ptr<OHOS::Media::PixelMap> pixelMap);
156     bool GetRealPath(const std::string &inOriPath, std::string &outRealPath);
157 
158     sptr<IWallpaperService> wpProxy_ {};
159     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {};
160     std::mutex wpFdLock_;
161     std::map<int32_t, int32_t> wallpaperFdMap_;
162     std::mutex wpProxyLock_;
163     std::mutex listenerMapMutex_;
164     bool (*callback) (int);
165 };
166 }
167 }
168 #endif
169 
170