• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/theme/wallpaper_mgr
13
14#### Introduction to framework code
15/base/theme/wallpaper_mgr
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