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