• Home
Name Date Size #Lines LOC

..--

etc/init/12-May-2024-6155

figures/12-May-2024-

frameworks/12-May-2024-3,5462,526

interfaces/kits/12-May-2024-1,7351,285

profile/12-May-2024-4428

services/12-May-2024-2,2721,758

test/12-May-2024-474268

utils/12-May-2024-358245

BUILD.gnD12-May-2024902 2623

LICENSED12-May-20249.9 KiB177150

OAT.xmlD12-May-20244 KiB6714

README.mdD12-May-20247.6 KiB134118

README_ZH.mdD12-May-202410.3 KiB199170

bundle.jsonD12-May-20242.2 KiB6564

wallpaper.gniD12-May-2024721 1715

README.md

1# wallpaper service
2
3#### Introduction
41、Provide wallpaper service capability for the system, and support wallpaper display, setting, switching wallpaper and other functions;
5
62、Provide the framework and interface for developers to develop wallpaper, and develop wallpaper applications;
7
8**subsystem architecture diagram**
9![](figures/subsystem_architecture.png "subsystem architecture diagram")
10
11#### Warehouse path
12/base/miscservices/wallpaper
13
14#### Introduction to framework code
15/base/miscservices/wallpaper
16├── figures                  # architecture diagram
17├── frameworks/innerkitsimpl # interface provided for app
18├── interfaces               # interface code provided by module
19│   ├── innerkits            # inter service interface
20│   └── kits                 # napi interface
21├── sa_profile               # module contains the config files of system services and processes
22├── services                 # implementation of wallpaper manager service
23├── test                     # unit test of interface
24└── utils                    # module contains log printing and constants for ordered commonEvent
25
26#### Interface Introduction
27**Table 1**  Main method of wallpaper service
28
29<a name="table033515471012"></a>
30<table><thead align="left"><tr id="row143351854201012"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p103351154121010"><a name="p103351154121010"></a><a name="p103351154121010"></a>Interface Name</p>
31</th>
32<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p1033585416105"><a name="p1033585416105"></a><a name="p1033585416105"></a>Description</p>
33</th>
34</tr>
35</thead>
36<tbody><tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function getColors(wallpaperType: WallpaperType): Promise&lt;Array&lt;RgbaColor&gt;&gt;</p>
37</td>
38<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>Obtains the wallpaper colors for the wallpaper of the specified type(system screen or lockscreen),Promise </p>
39</td>
40</tr>
41<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getId(wallpaperType: WallpaperType): Promise&lt;number&gt;</p>
42</td>
43<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>Obtains the ID of the wallpaper of the specified type(system screen or lockscreen),Promise </p>
44</td>
45</tr>
46<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function getPixelMap(wallpaperType: WallpaperType): Promise&lt;image.PixelMap&gt;</p>
47</td>
48<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>Obtains the default pixel map of a wallpaper of the specified type(system screen or lockscreen),Promise</p>
49</td>
50</tr>
51<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt;</p>
52</td>
53<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>Sets a wallpaper of the specified type based on the uri path from a JPEG or PNG file or the pixel map of a PNG file(wallpaper path or pixelmap),Promise</p>
54</td>
55</tr>
56<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function on(type: 'colorChange', callback: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) => void): void;
57</p>
58</td>
59<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>Registers a listener for wallpaper color changes to receive notifications about the changes,callback</p>
60</td>
61</tr>
62<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function off(type: 'colorChange', callback?: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) => void): void;
63</p>
64</td>
65<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>Unregisters a listener for wallpaper color changes,callback</p>
66</td>
67</tr>
68</tbody>
69</table>
70
71JS APIs instructions
72```
73//get pixelmap callback with callback
74wallpaper.getPixelMap(WALLPAPER_SYSTEM, function (err, data) {
75            console.info('wallpaperXTS ===> testGetPixelMapCallbackSystem err : ' + JSON.stringify(err));
76            console.info('wallpaperXTS ===> testGetPixelMapCallbackSystem data : ' + JSON.stringify(data));
77            if(err){
78                expect(null).assertFail();
79            }
80            if((data != undefined) && (data != null) && (data != '')){
81                expect(true).assertTrue();
82            }
83        })
84
85//get pixelmap callback with Promise
86wallpaper.getPixelMap(WALLPAPER_SYSTEM).then((data) => {
87            console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem data : ' + data);
88            console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem data : ' + JSON.stringify(data));
89            if((data != undefined) && (data != null) && (data != '')){
90                expect(true).assertTrue();
91            }
92        }).catch((err) => {
93            console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem err : ' + err);
94            console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem err : ' + JSON.stringify(err));
95            if(err){
96                expect(null).assertFail();
97            }
98        });
99
100//set pixelmap callback with callback
101wallpaper.setWallpaper(pixelmap, WALLPAPER_SYSTEM, function (err, data) {
102                console.info('wallpaperXTS ===> testSetWallpaperPixelMapCallbackSystem err : ' + JSON.stringify(err));
103                console.info('wallpaperXTS ===> testSetWallpaperPixelMapCallbackSystem data : ' + JSON.stringify(data));
104                if(err){
105                    expect(null).assertFail();
106                }
107                if((data != undefined) && (data != null) && (data != '')){
108                    expect(true).assertTrue();
109                }
110            });
111
112//set pixelmap callback with Promise
113wallpaper.setWallpaper(pixelmap, WALLPAPER_SYSTEM).then((data) => {
114                console.info('wallpaperXTS ===> testSetWallpaperPixelMapPromiseSystem data : ' + JSON.stringify(data));
115                if((data != undefined) && (data != null) && (data != '')){
116                    expect(true).assertTrue();
117                }
118            }).catch((err) => {
119                console.info('wallpaperXTS ===> testSetWallpaperPixelMapPromiseSystem err : ' + JSON.stringify(err));
120                if(err){
121                    expect(null).assertFail();
122                }
123            });
124```
125
126#### Participation contribution
127
1281. Fork warehouse
1292. Submission code
1303. Create a new pull request
1314. Commit is complete
132
133
134

README_ZH.md

1# 杂散子系统/壁纸管理服务
2
3## 简介
4
5### 内容介绍
6该仓主要为系统提供壁纸管理服务能力,支持系统显示、设置、切换壁纸等功能。
7
8### 架构图介绍
9**图 1** 子系统架构图
10![](figures/subsystem_architecture_zh.png "子系统架构图")
11
12#### 仓路径
13
14/base/miscservices/wallpaper
15
16## 目录
17
18```
19/base/miscservices/wallpaper
20├── figures                  # 构架图
21├── frameworks/innerkitsimpl # 对应用提供的接口
22├── interfaces/kits          # 组件对外提供的接口代码
23│   ├── jskits               # 服务间接口
24│   └── napi                 # js接口解析成napi接口
25├── profile                  # 组件包含的系统服务的配置文件和进程的配置文件
26├── services                 # 壁纸管理服务实现
27├── test                     # 接口的单元测试
28└── utils                    # 组件包含日志打印和有序公共事件定义的常量
29```
30## 说明
31
32#### 接口说明
33**表 1**  壁纸管理服务开放的主要方法
34
35<a name="table033515471012"></a>
36<table><thead align="left"><tr id="row143351854201012"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p103351154121010"><a name="p103351154121010"></a><a name="p103351154121010"></a>接口名</p>
37</th>
38<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p1033585416105"><a name="p1033585416105"></a><a name="p1033585416105"></a>描述</p>
39</th>
40</tr>
41</thead>
42<tbody><tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function getColors(wallpaperType: WallpaperType): Promise&lt;Array&lt;RgbaColor&gt;&gt;</p>
43</td>
44<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>获取壁纸图片主颜色(桌面或者锁屏壁纸),Promise方式</p>
45</td>
46</tr>
47<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getId(wallpaperType: WallpaperType): Promise&lt;number&gt;</p>
48</td>
49<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取壁纸id(桌面或者锁屏壁纸),Promise方式</p>
50</td>
51</tr>
52<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function getPixelMap(wallpaperType: WallpaperType): Promise&lt;image.PixelMap&gt;</p>
53</td>
54<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>获取壁纸图片的pixelmap(桌面或者锁屏壁纸),Promise方式</p>
55</td>
56</tr>
57<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt;</p>
58</td>
59<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>设置壁纸(图片路径或pixelmap),Promise方式</p>
60</td>
61</tr>
62<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function on(type: 'colorChange', callback: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) => void): void;
63</p>
64</td>
65<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>监听壁纸图片主颜色变化,callback方式</p>
66</td>
67</tr>
68<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function off(type: 'colorChange', callback?: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) => void): void;
69</p>
70</td>
71<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>取消监听壁纸图片主颜色变化,callback方式</p>
72</td>
73</tr>
74</tbody>
75</table>
76
77**表 2**  应用extension的主要接口
78
79<a name="table033515471012"></a>
80<table><thead align="left"><tr id="row143351854201012"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p103351154121010"><a name="p103351154121010"></a><a name="p103351154121010"></a>接口名</p>
81</th>
82<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p1033585416105"><a name="p1033585416105"></a><a name="p1033585416105"></a>描述</p>
83</th>
84</tr>
85</thead>
86<tbody><tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>onCreated(want: object): void</p>
87</td>
88<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>wallpaper extension 初始化的回调</p>
89</td>
90</tr>
91<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>onWallpaperChanged(wallpaperType: number): void</p>
92</td>
93<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>壁纸发生了变化的回调</p>
94</td>
95</tr>
96<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>setUiContent(url:string): void</p>
97</td>
98<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>应用设置壁纸的布局文件路径</p>
99</td>
100</tr>
101<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>onDestroy(): void
102</p>
103</td>
104<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>wallpaper extension 销毁回调</p>
105</td>
106</tr>
107</tbody>
108</table>
109
110### 使用说明
111```
112//获取壁纸callback方式
113wallpaper.getPixelMap(WALLPAPER_SYSTEM, function (err, data) {
114            console.info('wallpaperXTS ===> testGetPixelMapCallbackSystem err : ' + JSON.stringify(err));
115            console.info('wallpaperXTS ===> testGetPixelMapCallbackSystem data : ' + JSON.stringify(data));
116        })
117
118//获取壁纸Promise方式
119wallpaper.getPixelMap(WALLPAPER_SYSTEM).then((data) => {
120            console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem data : ' + data);
121            console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem data : ' + JSON.stringify(data));
122
123        }).catch((err) => {
124            console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem err : ' + err);
125            console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem err : ' + JSON.stringify(err));
126
127        });
128
129//设置壁纸callback方式
130wallpaper.setWallpaper(pixelmap, WALLPAPER_SYSTEM, function (err, data) {
131                console.info('wallpaperXTS ===> testSetWallpaperPixelMapCallbackSystem err : ' + JSON.stringify(err));
132                console.info('wallpaperXTS ===> testSetWallpaperPixelMapCallbackSystem data : ' + JSON.stringify(data));
133            });
134
135//设置壁纸Promise方式
136wallpaper.setWallpaper(pixelmap, WALLPAPER_SYSTEM).then((data) => {
137                console.info('wallpaperXTS ===> testSetWallpaperPixelMapPromiseSystem data : ' + JSON.stringify(data));
138
139            }).catch((err) => {
140                console.info('wallpaperXTS ===> testSetWallpaperPixelMapPromiseSystem err : ' + JSON.stringify(err));
141
142            });
143```
144
145js 应用接口使用说明
146```
147import Extension from '@ohos.wallpaperextension'
148import wallPaper from '@ohos.wallpaper'
149
150export default class WallpaperExtAbility extends Extension {
151    onCreated(want) {
152        console.info(MODULE_TAG + 'ability on created start');
153        super.setUiContent("pages/index");
154        console.info(MODULE_TAG + 'ability on created end');
155    }
156
157    onWallpaperChanged(wallpaperType) {
158        console.info(MODULE_TAG + "ability on wallpaper changed start, type is : " + wallpaperType);
159        if (wallPaper) {
160            this.sendPixelMapData();
161        }
162       console.info(MODULE_TAG + "ability on wallpaper changed end");
163    }
164
165    onDestroy() {
166        console.info(MODULE_TAG + 'ability on destroy');
167    }
168
169    initWallpaperImage() {
170        console.info(MODULE_TAG + 'ability init wallpaper image start');
171        if (!wallPaper) {
172            console.info(MODULE_TAG + "ability init wallpaper image failed as wallpaper is null");
173            return;
174        }
175        this.sendPixelMapData()
176        console.info(MODULE_TAG + 'ability init wallpaper image end');
177    }
178
179    sendPixelMapData() {
180        // 0 is WallpaperType:WALLPAPER_SYSTEM, 1 isWallpaperType:WALLPAPER_LOCKSCREEN
181        wallPaper.getPixelMap(0, (err, data) => {
182            console.info(MODULE_TAG + "ability get pixel map data start");
183            if (err) {
184                console.info(MODULE_TAG + "ability get pixel map failed, error : " + JSON.stringify(err));
185            } else {
186                console.info(MODULE_TAG + "ability get pixel map, data : " + JSON.stringify(data));
187                AppStorage.SetOrCreate('slPixelData', data);
188            }
189            console.info(MODULE_TAG + "ability get pixel map data end");
190        });
191    }
192};
193
194```
195
196## 相关仓
197[miscservices_wallpaper](https://gitee.com/openharmony/miscservices_wallpaper/blob/master/README_ZH.md)
198
199