1/* 2 * Copyright (c) 2021-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 16import { paramMock } from "../utils" 17import { PixelMapMock } from "../multimedia" 18 19export function mockWallpaper() { 20 const wallpaper = { 21 WallpaperType: { 22 WALLPAPER_SYSTEM: '[PC preview] unknow WALLPAPER_SYSTEM', 23 WALLPAPER_LOCKSCREEN: '[PC preview] unknow WALLPAPER_LOCKSCREEN' 24 }, 25 getColors: function (...args) { 26 console.warn("wallpaper.getColors interface mocked in the Previewer. How this interface works on the" + 27 " Previewer may be different from that on a real device.") 28 const len = args.length; 29 let colors = new Array(); 30 colors.push(RgbaColorMock); 31 if (typeof args[len - 1] === 'function') { 32 args[len - 1].call(this, paramMock.businessErrorMock, colors); 33 } else { 34 return new Promise((resolve, reject) => { 35 resolve(colors); 36 }) 37 } 38 }, 39 getId: function (...args) { 40 console.warn("wallpaper.getId interface mocked in the Previewer. How this interface works on the" + 41 " Previewer may be different from that on a real device.") 42 const len = args.length 43 if (typeof args[len - 1] === 'function') { 44 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 45 } else { 46 return new Promise((resolve, reject) => { 47 resolve(paramMock.paramNumberMock); 48 }) 49 } 50 }, 51 getFile: function (...args) { 52 console.warn("wallpaper.getFile interface mocked in the Previewer. How this interface works on the" + 53 " Previewer may be different from that on a real device.") 54 const len = args.length 55 if (typeof args[len - 1] === 'function') { 56 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 57 } else { 58 return new Promise((resolve, reject) => { 59 resolve(paramMock.paramNumberMock); 60 }) 61 } 62 }, 63 getMinHeight: function (...args) { 64 console.warn("wallpaper.getMinHeight interface mocked in the Previewer. How this interface works on the" + 65 " Previewer may be different from that on a real device.") 66 const len = args.length 67 if (typeof args[len - 1] === 'function') { 68 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 69 } else { 70 return new Promise((resolve, reject) => { 71 resolve(paramMock.paramNumberMock); 72 }) 73 } 74 }, 75 getMinWidth: function (...args) { 76 console.warn("wallpaper.getMinWidth interface mocked in the Previewer. How this interface works on the" + 77 " Previewer may be different from that on a real device.") 78 const len = args.length 79 if (typeof args[len - 1] === 'function') { 80 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 81 } else { 82 return new Promise((resolve, reject) => { 83 resolve(paramMock.paramNumberMock); 84 }) 85 } 86 }, 87 isChangePermitted: function (...args) { 88 console.warn("wallpaper.isChangePermitted interface mocked in the Previewer. How this interface works on the" + 89 " Previewer may be different from that on a real device.") 90 const len = args.length 91 if (typeof args[len - 1] === 'function') { 92 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) 93 } else { 94 return new Promise((resolve, reject) => { 95 resolve(paramMock.paramBooleanMock); 96 }) 97 } 98 }, 99 isOperationAllowed: function (...args) { 100 console.warn("wallpaper.isOperationAllowed interface mocked in the Previewer. How this interface works on the" + 101 " Previewer may be different from that on a real device.") 102 const len = args.length 103 if (typeof args[len - 1] === 'function') { 104 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) 105 } else { 106 return new Promise((resolve, reject) => { 107 resolve(paramMock.paramBooleanMock); 108 }) 109 } 110 }, 111 reset: function (...args) { 112 console.warn("wallpaper.reset interface mocked in the Previewer. How this interface works on the" + 113 " Previewer may be different from that on a real device.") 114 const len = args.length 115 if (typeof args[len - 1] === 'function') { 116 args[len - 1].call(this, paramMock.businessErrorMock) 117 } else { 118 return new Promise((resolve, reject) => { 119 resolve(); 120 }) 121 } 122 }, 123 setWallpaper: function (...args) { 124 console.warn("wallpaper.setWallpaper interface mocked in the Previewer. How this interface works on the" + 125 " Previewer may be different from that on a real device.") 126 const len = args.length 127 if (typeof args[len - 1] === 'function') { 128 args[len - 1].call(this, paramMock.businessErrorMock) 129 } else { 130 return new Promise((resolve, reject) => { 131 resolve(); 132 }) 133 } 134 }, 135 getPixelMap: function (...args) { 136 console.warn("wallpaper.getPixelMap interface mocked in the Previewer. How this interface works on the" + 137 " Previewer may be different from that on a real device.") 138 const len = args.length 139 if (typeof args[len - 1] === 'function') { 140 args[len - 1].call(this, paramMock.businessErrorMock, PixelMapMock) 141 } else { 142 return new Promise((resolve, reject) => { 143 resolve(PixelMapMock); 144 }) 145 } 146 }, 147 screenshotLiveWallpaper: function (...args) { 148 console.warn("wallpaper.screenshotLiveWallpaper interface mocked in the Previewer. How this interface works on the" + 149 " Previewer may be different from that on a real device.") 150 const len = args.length 151 if (typeof args[len - 1] === 'function') { 152 args[len - 1].call(this, paramMock.businessErrorMock, PixelMapMock) 153 } else { 154 return new Promise((resolve, reject) => { 155 resolve(PixelMapMock); 156 }) 157 } 158 }, 159 on: function (...args) { 160 console.warn("wallpaper.on interface mocked in the Previewer. How this interface works on the" + 161 " Previewer may be different from that on a real device."); 162 const len = args.length 163 if (typeof args[len - 1] === 'function') { 164 if (args[0] == 'colorChange') { 165 let colors = new Array(); 166 colors.push(RgbaColorMock); 167 args[len - 1].call(this, colors, wallpaper.WallpaperType.WALLPAPER_SYSTEM); 168 } 169 } 170 }, 171 off: function (...args) { 172 console.warn("wallpaper.off interface mocked in the Previewer. How this interface works on the" + 173 " Previewer may be different from that on a real device."); 174 const len = args.length; 175 if (typeof args[len - 1] === 'function') { 176 if (args[0] == 'colorChange') { 177 let colors = new Array(); 178 colors.push(RgbaColorMock); 179 args[len - 1].call(this, colors, wallpaper.WallpaperType.WALLPAPER_SYSTEM); 180 } 181 } 182 } 183 } 184 const RgbaColorMock = { 185 red: '[PC preview] unknow red', 186 green: '[PC preview] unknow green', 187 blue: '[PC preview] unknow blue', 188 alpha: '[PC preview] unknow alpha' 189 } 190 return wallpaper 191}