# wallpaper service #### Introduction 1、Provide wallpaper service capability for the system, and support wallpaper display, setting, switching wallpaper and other functions; 2、Provide the framework and interface for developers to develop wallpaper, and develop wallpaper applications; **subsystem architecture diagram** ![](figures/subsystem_architecture.png "subsystem architecture diagram") #### Warehouse path /base/theme/wallpaper_mgr #### Introduction to framework code /base/theme/wallpaper_mgr ├── figures # architecture diagram ├── frameworks │ ├── js/napi # the js interface resolves to the napi interface │ ├── kits/extension # extension │ └── native # interface provided for app ├── services # implementation of wallpaper manager service │ ├── profile # module contains the config files of system services │ └── etc # module contains the config files of processes ├── test # unit test of interface └── utils # module contains log printing and constants for ordered commonEvent #### Interface Introduction **Table 1** Main method of wallpaper service

Interface Name

Description

function getColors(wallpaperType: WallpaperType): Promise<Array<RgbaColor>>

Obtains the wallpaper colors for the wallpaper of the specified type(system screen or lockscreen),Promise

function getId(wallpaperType: WallpaperType): Promise<number>

Obtains the ID of the wallpaper of the specified type(system screen or lockscreen),Promise

function getPixelMap(wallpaperType: WallpaperType): Promise<image.PixelMap>

Obtains the default pixel map of a wallpaper of the specified type(system screen or lockscreen),Promise

function setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise<void>

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

function on(type: 'colorChange', callback: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void;

Registers a listener for wallpaper color changes to receive notifications about the changes,callback

function off(type: 'colorChange', callback?: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void;

Unregisters a listener for wallpaper color changes,callback

JS APIs instructions ``` //get pixelmap callback with callback wallpaper.getPixelMap(WALLPAPER_SYSTEM, function (err, data) { console.info('wallpaperXTS ===> testGetPixelMapCallbackSystem err : ' + JSON.stringify(err)); console.info('wallpaperXTS ===> testGetPixelMapCallbackSystem data : ' + JSON.stringify(data)); if(err){ expect(null).assertFail(); } if((data != undefined) && (data != null) && (data != '')){ expect(true).assertTrue(); } }) //get pixelmap callback with Promise wallpaper.getPixelMap(WALLPAPER_SYSTEM).then((data) => { console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem data : ' + data); console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem data : ' + JSON.stringify(data)); if((data != undefined) && (data != null) && (data != '')){ expect(true).assertTrue(); } }).catch((err) => { console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem err : ' + err); console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem err : ' + JSON.stringify(err)); if(err){ expect(null).assertFail(); } }); //set pixelmap callback with callback wallpaper.setWallpaper(pixelmap, WALLPAPER_SYSTEM, function (err, data) { console.info('wallpaperXTS ===> testSetWallpaperPixelMapCallbackSystem err : ' + JSON.stringify(err)); console.info('wallpaperXTS ===> testSetWallpaperPixelMapCallbackSystem data : ' + JSON.stringify(data)); if(err){ expect(null).assertFail(); } if((data != undefined) && (data != null) && (data != '')){ expect(true).assertTrue(); } }); //set pixelmap callback with Promise wallpaper.setWallpaper(pixelmap, WALLPAPER_SYSTEM).then((data) => { console.info('wallpaperXTS ===> testSetWallpaperPixelMapPromiseSystem data : ' + JSON.stringify(data)); if((data != undefined) && (data != null) && (data != '')){ expect(true).assertTrue(); } }).catch((err) => { console.info('wallpaperXTS ===> testSetWallpaperPixelMapPromiseSystem err : ' + JSON.stringify(err)); if(err){ expect(null).assertFail(); } }); ``` #### Participation contribution 1. Fork warehouse 2. Submission code 3. Create a new pull request 4. Commit is complete