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 getColorsSync: function (...args) { 40 console.warn("wallpaper.getColorsSync interface mocked in the Previewer. How this interface works on the" + 41 " Previewer may be different from that on a real device.") 42 let colors = new Array(); 43 colors.push(RgbaColorMock); 44 return colors; 45 }, 46 getId: function (...args) { 47 console.warn("wallpaper.getId interface mocked in the Previewer. How this interface works on the" + 48 " Previewer may be different from that on a real device.") 49 const len = args.length 50 if (typeof args[len - 1] === 'function') { 51 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 52 } else { 53 return new Promise((resolve, reject) => { 54 resolve(paramMock.paramNumberMock); 55 }) 56 } 57 }, 58 getIdSync: function (...args) { 59 console.warn("wallpaper.getIdSync interface mocked in the Previewer. How this interface works on the" + 60 " Previewer may be different from that on a real device.") 61 return paramMock.paramNumberMock; 62 }, 63 getFile: function (...args) { 64 console.warn("wallpaper.getFile 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 getFileSync: function (...args) { 76 console.warn("wallpaper.getFileSync interface mocked in the Previewer. How this interface works on the" + 77 " Previewer may be different from that on a real device.") 78 return paramMock.paramNumberMock; 79 }, 80 getMinHeight: function (...args) { 81 console.warn("wallpaper.getMinHeight interface mocked in the Previewer. How this interface works on the" + 82 " Previewer may be different from that on a real device.") 83 const len = args.length 84 if (typeof args[len - 1] === 'function') { 85 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 86 } else { 87 return new Promise((resolve, reject) => { 88 resolve(paramMock.paramNumberMock); 89 }) 90 } 91 }, 92 getMinHeightSync: function (...args) { 93 console.warn("wallpaper.getMinHeightSync interface mocked in the Previewer. How this interface works on the" + 94 " Previewer may be different from that on a real device.") 95 return paramMock.paramNumberMock; 96 }, 97 getMinWidth: function (...args) { 98 console.warn("wallpaper.getMinWidth interface mocked in the Previewer. How this interface works on the" + 99 " Previewer may be different from that on a real device.") 100 const len = args.length 101 if (typeof args[len - 1] === 'function') { 102 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 103 } else { 104 return new Promise((resolve, reject) => { 105 resolve(paramMock.paramNumberMock); 106 }) 107 } 108 }, 109 getMinWidthSync: function (...args) { 110 console.warn("wallpaper.getMinWidthSync interface mocked in the Previewer. How this interface works on the" + 111 " Previewer may be different from that on a real device.") 112 return paramMock.paramNumberMock; 113 }, 114 isChangePermitted: function (...args) { 115 console.warn("wallpaper.isChangePermitted interface mocked in the Previewer. How this interface works on the" + 116 " Previewer may be different from that on a real device.") 117 const len = args.length 118 if (typeof args[len - 1] === 'function') { 119 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) 120 } else { 121 return new Promise((resolve, reject) => { 122 resolve(paramMock.paramBooleanMock); 123 }) 124 } 125 }, 126 isChangeAllowed: function (...args) { 127 console.warn("wallpaper.isChangeAllowed interface mocked in the Previewer. How this interface works on the" + 128 " Previewer may be different from that on a real device.") 129 return paramMock.paramBooleanMock; 130 }, 131 isOperationAllowed: function (...args) { 132 console.warn("wallpaper.isOperationAllowed interface mocked in the Previewer. How this interface works on the" + 133 " Previewer may be different from that on a real device.") 134 const len = args.length 135 if (typeof args[len - 1] === 'function') { 136 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock) 137 } else { 138 return new Promise((resolve, reject) => { 139 resolve(paramMock.paramBooleanMock); 140 }) 141 } 142 }, 143 isUserChangeAllowed: function (...args) { 144 console.warn("wallpaper.isUserChangeAllowed interface mocked in the Previewer. How this interface works on the" + 145 " Previewer may be different from that on a real device.") 146 return paramMock.paramBooleanMock; 147 }, 148 reset: function (...args) { 149 console.warn("wallpaper.reset interface mocked in the Previewer. How this interface works on the" + 150 " Previewer may be different from that on a real device.") 151 const len = args.length 152 if (typeof args[len - 1] === 'function') { 153 args[len - 1].call(this, paramMock.businessErrorMock) 154 } else { 155 return new Promise((resolve, reject) => { 156 resolve(); 157 }) 158 } 159 }, 160 restore: function (...args) { 161 console.warn("wallpaper.restore interface mocked in the Previewer. How this interface works on the" + 162 " Previewer may be different from that on a real device.") 163 const len = args.length 164 if (typeof args[len - 1] === 'function') { 165 args[len - 1].call(this, paramMock.businessErrorMock) 166 } else { 167 return new Promise((resolve, reject) => { 168 resolve(); 169 }) 170 } 171 }, 172 setWallpaper: function (...args) { 173 console.warn("wallpaper.setWallpaper interface mocked in the Previewer. How this interface works on the" + 174 " Previewer may be different from that on a real device.") 175 const len = args.length 176 if (typeof args[len - 1] === 'function') { 177 args[len - 1].call(this, paramMock.businessErrorMock) 178 } else { 179 return new Promise((resolve, reject) => { 180 resolve(); 181 }) 182 } 183 }, 184 setImage: function (...args) { 185 console.warn("wallpaper.setImage interface mocked in the Previewer. How this interface works on the" + 186 " Previewer may be different from that on a real device.") 187 const len = args.length 188 if (typeof args[len - 1] === 'function') { 189 args[len - 1].call(this, paramMock.businessErrorMock) 190 } else { 191 return new Promise((resolve, reject) => { 192 resolve(); 193 }) 194 } 195 }, 196 getPixelMap: function (...args) { 197 console.warn("wallpaper.getPixelMap interface mocked in the Previewer. How this interface works on the" + 198 " Previewer may be different from that on a real device.") 199 const len = args.length 200 if (typeof args[len - 1] === 'function') { 201 args[len - 1].call(this, paramMock.businessErrorMock, PixelMapMock) 202 } else { 203 return new Promise((resolve, reject) => { 204 resolve(PixelMapMock); 205 }) 206 } 207 }, 208 getImage: function (...args) { 209 console.warn("wallpaper.getImage interface mocked in the Previewer. How this interface works on the" + 210 " Previewer may be different from that on a real device.") 211 const len = args.length 212 if (typeof args[len - 1] === 'function') { 213 args[len - 1].call(this, paramMock.businessErrorMock, PixelMapMock) 214 } else { 215 return new Promise((resolve, reject) => { 216 resolve(PixelMapMock); 217 }) 218 } 219 }, 220 on: function (...args) { 221 console.warn("wallpaper.on interface mocked in the Previewer. How this interface works on the" + 222 " Previewer may be different from that on a real device."); 223 const len = args.length 224 if (typeof args[len - 1] === 'function') { 225 if (args[0] == 'colorChange') { 226 let colors = new Array(); 227 colors.push(RgbaColorMock); 228 args[len - 1].call(this, colors, wallpaper.WallpaperType.WALLPAPER_SYSTEM); 229 } 230 } 231 }, 232 off: function (...args) { 233 console.warn("wallpaper.off interface mocked in the Previewer. How this interface works on the" + 234 " Previewer may be different from that on a real device."); 235 const len = args.length; 236 if (typeof args[len - 1] === 'function') { 237 if (args[0] == 'colorChange') { 238 let colors = new Array(); 239 colors.push(RgbaColorMock); 240 args[len - 1].call(this, colors, wallpaper.WallpaperType.WALLPAPER_SYSTEM); 241 } 242 } 243 } 244 } 245 const RgbaColorMock = { 246 red: '[PC preview] unknow red', 247 green: '[PC preview] unknow green', 248 blue: '[PC preview] unknow blue', 249 alpha: '[PC preview] unknow alpha' 250 } 251 return wallpaper 252}