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 18│ ├── js/napi # the js interface resolves to the napi interface 19│ ├── kits/extension # extension 20│ └── native # interface provided for app 21├── services # implementation of wallpaper manager service 22│ ├── profile # module contains the config files of system services 23│ └── etc # module contains the config files of processes 24├── test # unit test of interface 25└── utils # module contains log printing and constants for ordered commonEvent 26 27#### Interface Introduction 28**Table 1** Main method of wallpaper service 29 30<a name="table033515471012"></a> 31<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> 32</th> 33<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> 34</th> 35</tr> 36</thead> 37<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<Array<RgbaColor>></p> 38</td> 39<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> 40</td> 41</tr> 42<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<number></p> 43</td> 44<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> 45</td> 46</tr> 47<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<image.PixelMap></p> 48</td> 49<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> 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 setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise<void></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>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> 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 on(type: 'colorChange', callback: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void; 58</p> 59</td> 60<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> 61</td> 62</tr> 63<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<RgbaColor>, wallpaperType: WallpaperType) => void): void; 64</p> 65</td> 66<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> 67</td> 68</tr> 69</tbody> 70</table> 71 72JS APIs instructions 73``` 74//get pixelmap callback with callback 75wallpaper.getPixelMap(WALLPAPER_SYSTEM, function (err, data) { 76 console.info('wallpaperXTS ===> testGetPixelMapCallbackSystem err : ' + JSON.stringify(err)); 77 console.info('wallpaperXTS ===> testGetPixelMapCallbackSystem data : ' + JSON.stringify(data)); 78 if(err){ 79 expect(null).assertFail(); 80 } 81 if((data != undefined) && (data != null) && (data != '')){ 82 expect(true).assertTrue(); 83 } 84 }) 85 86//get pixelmap callback with Promise 87wallpaper.getPixelMap(WALLPAPER_SYSTEM).then((data) => { 88 console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem data : ' + data); 89 console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem data : ' + JSON.stringify(data)); 90 if((data != undefined) && (data != null) && (data != '')){ 91 expect(true).assertTrue(); 92 } 93 }).catch((err) => { 94 console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem err : ' + err); 95 console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem err : ' + JSON.stringify(err)); 96 if(err){ 97 expect(null).assertFail(); 98 } 99 }); 100 101//set pixelmap callback with callback 102wallpaper.setWallpaper(pixelmap, WALLPAPER_SYSTEM, function (err, data) { 103 console.info('wallpaperXTS ===> testSetWallpaperPixelMapCallbackSystem err : ' + JSON.stringify(err)); 104 console.info('wallpaperXTS ===> testSetWallpaperPixelMapCallbackSystem data : ' + JSON.stringify(data)); 105 if(err){ 106 expect(null).assertFail(); 107 } 108 if((data != undefined) && (data != null) && (data != '')){ 109 expect(true).assertTrue(); 110 } 111 }); 112 113//set pixelmap callback with Promise 114wallpaper.setWallpaper(pixelmap, WALLPAPER_SYSTEM).then((data) => { 115 console.info('wallpaperXTS ===> testSetWallpaperPixelMapPromiseSystem data : ' + JSON.stringify(data)); 116 if((data != undefined) && (data != null) && (data != '')){ 117 expect(true).assertTrue(); 118 } 119 }).catch((err) => { 120 console.info('wallpaperXTS ===> testSetWallpaperPixelMapPromiseSystem err : ' + JSON.stringify(err)); 121 if(err){ 122 expect(null).assertFail(); 123 } 124 }); 125``` 126 127#### Participation contribution 128 1291. Fork warehouse 1302. Submission code 1313. Create a new pull request 1324. Commit is complete 133 134 135