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_PROXY_H
17 #define SERVICES_INCLUDE_WALLPAPER_SERVICE_PROXY_H
18 
19 #include <mutex>
20 
21 #include "i_wallpaper_service.h"
22 #include "iremote_proxy.h"
23 #include "wallpaper_service_ipc_interface_code.h"
24 
25 namespace OHOS {
26 namespace WallpaperMgrService {
27 class WallpaperServiceProxy : public IRemoteProxy<IWallpaperService> {
28 public:
WallpaperServiceProxy(const sptr<IRemoteObject> & object)29     explicit WallpaperServiceProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IWallpaperService>(object)
30     {
31     }
~WallpaperServiceProxy()32     ~WallpaperServiceProxy()
33     {
34     }
35     DISALLOW_COPY_AND_MOVE(WallpaperServiceProxy);
36     ErrorCode SetWallpaper(int32_t fd, int32_t wallpaperType, int32_t length) override;
37     ErrorCode SetWallpaperByPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap, int32_t wallpaperType) override;
38     ErrorCode GetPixelMap(int32_t wallpaperType, IWallpaperService::FdInfo &fdInfo) override;
39     ErrorCode GetColors(int32_t wallpaperType, std::vector<uint64_t> &colors) override;
40     ErrorCode GetFile(int32_t wallpaperType, int32_t &wallpaperFd) override;
41     int32_t GetWallpaperId(int32_t wallpaperType) override;
42     bool IsChangePermitted() override;
43     bool IsOperationAllowed() override;
44     ErrorCode ResetWallpaper(int32_t wallpaperType) override;
45     ErrorCode On(const std::string &type, sptr<IWallpaperEventListener> listener) override;
46     ErrorCode Off(const std::string &type, sptr<IWallpaperEventListener> listener) override;
47     bool RegisterWallpaperCallback(const sptr<IWallpaperCallback> callback) override;
48     ErrorCode SetVideo(int32_t fd, int32_t wallpaperType, int32_t length) override;
49     ErrorCode SetCustomWallpaper(int32_t fd, int32_t wallpaperType, int32_t length) override;
50     ErrorCode SendEvent(const std::string &eventType) override;
51     ErrorCode ConvertIntToErrorCode(int32_t errorCode);
52 
53     ErrorCode SetWallpaperV9(int32_t fd, int32_t wallpaperType, int32_t length) override;
54     ErrorCode SetWallpaperV9ByPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap, int32_t wallpaperType) override;
55     ErrorCode GetPixelMapV9(int32_t wallpaperType, IWallpaperService::FdInfo &fdInfo) override;
56     ErrorCode GetColorsV9(int32_t wallpaperType, std::vector<uint64_t> &colors) override;
57     ErrorCode ResetWallpaperV9(int32_t wallpaperType) override;
58     ErrorCode SetAllWallpapers(std::vector<WallpaperPictureInfo> allWallpaperInfo, int32_t wallpaperType) override;
59     ErrorCode GetCorrespondWallpaper(
60         int32_t wallpaperType, int32_t foldState, int32_t rotateState, IWallpaperService::FdInfo &fdInfo) override;
61 
62 private:
63     ErrorCode SetWallpaperInner(
64         int32_t fd, int32_t wallpaperType, int32_t length, WallpaperServiceIpcInterfaceCode code);
65     ErrorCode SetWallpaperInnerByPixelMap(
66         std::shared_ptr<OHOS::Media::PixelMap> pixelMap, int32_t wallpaperType, WallpaperServiceIpcInterfaceCode code);
67     ErrorCode GetPixelMapInner(
68         int32_t wallpaperType, WallpaperServiceIpcInterfaceCode code, IWallpaperService::FdInfo &fdInfo);
69     ErrorCode GetColorsInner(
70         int32_t wallpaperType, WallpaperServiceIpcInterfaceCode code, std::vector<uint64_t> &colors);
71     ErrorCode ResetWallpaperInner(int32_t wallpaperType, WallpaperServiceIpcInterfaceCode code);
72     ErrorCode SetAllWallpapersInner(std::vector<WallpaperPictureInfo> allWallpaperInfo, int32_t wallpaperType,
73         WallpaperServiceIpcInterfaceCode code);
74     ErrorCode GetCorrespondWallpaperInner(int32_t wallpaperType, int32_t foldState, int32_t rotateState,
75         WallpaperServiceIpcInterfaceCode code, IWallpaperService::FdInfo &fdInfo);
76     bool StartSocket(std::string uri, std::string name);
77     std::vector<std::uint8_t> PixelMapToVector(std::shared_ptr<OHOS::Media::PixelMap> pixelMap);
78     static inline BrokerDelegator<WallpaperServiceProxy> delegator_;
79     sptr<OHOS::Media::PixelMap> pixelMapData_;
80     std::string serviceReadUri = "";
81     int32_t mapSize = 0;
82 };
83 } // namespace WallpaperMgrService
84 } // namespace OHOS
85 #endif // SERVICES_INCLUDE_WALLPAPER_SERVICE_PROXY_H