1/* 2 * Copyright (c) 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'; 17 18export const Orientation = { 19 UNSPECIFIED: 0, 20 VERTICAL: 1, 21 HORIZONTAL: 2, 22 REVERSE_VERTICAL: 3, 23 REVERSE_HORIZONTAL: 4 24}; 25 26export const Screen = { 27 id: 'PC preview] unknown id', 28 parent: '[PC preview] unknown parent', 29 supportedModeInfo: supportedModeInfoArray, 30 activeModeIndex: '[PC preview] unknown activeModeIndex', 31 orientation: Orientation, 32 setOrientation: function(...args) { 33 console.warn('Screen.setOrientation interface mocked in the Previewer. How this interface works on the' + 34 ' Previewer may be different from that on a real device.'); 35 const len = args.length; 36 if (typeof args[len - 1] === 'function') { 37 args[len - 1].call(this, paramMock.businessErrorMock); 38 } else { 39 return new Promise((resolve) => { 40 resolve(); 41 }); 42 } 43 }, 44 setScreenActiveMode: function(...args) { 45 console.warn('Screen.setScreenActiveMode interface mocked in the Previewer. How this interface works on the' + 46 ' Previewer may be different from that on a real device.'); 47 const len = args.length; 48 if (typeof args[len - 1] === 'function') { 49 args[len - 1].call(this, paramMock.businessErrorMock); 50 } else { 51 return new Promise((resolve) => { 52 resolve(); 53 }); 54 } 55 }, 56 setDensityDpi: function(...args) { 57 console.warn('Screen.setDensityDpi interface mocked in the Previewer. How this interface works on the' + 58 ' Previewer may be different from that on a real device.'); 59 const len = args.length; 60 if (typeof args[len - 1] === 'function') { 61 args[len - 1].call(this, paramMock.businessErrorMock); 62 } else { 63 return new Promise((resolve) => { 64 resolve(); 65 }); 66 } 67 } 68}; 69 70export const allScreenMock = [ 71 Screen 72]; 73 74export const ExpandOption = { 75 screenId: '[PC preview] unknown screenId', 76 startX: '[PC preview] unknown startX', 77 startY: '[PC preview] unknown startY' 78}; 79 80export const VirtualScreenOption = { 81 name: '[PC preview] unknown name', 82 width: '[PC preview] unknown width', 83 height: '[PC preview] unknown height', 84 density: '[PC preview] unknown density', 85 surfaceId: '[PC preview] unknown surfaceId' 86}; 87 88export const ScreenModeInfo = { 89 id: '[PC preview] unknown id', 90 width: '[PC preview] unknown width', 91 height: '[PC preview] unknown height', 92 refreshRate: '[PC preview] unknown refreshRate' 93}; 94 95export const supportedModeInfoArray = [ 96 ScreenModeInfo 97] 98const EventTypeMock = { 99 connect: 'connect', 100 disconnect: 'disconnect', 101 change: 'change' 102} 103export function mockScreen() { 104 const screen = { 105 ExpandOption, 106 VirtualScreenOption, 107 Orientation, 108 ScreenModeInfo, 109 getAllScreens: function(...args) { 110 console.warn('Screen.getAllScreens interface mocked in the Previewer. How this interface works on the' + 111 ' Previewer may be different from that on a real device.'); 112 const len = args.length; 113 if (typeof args[len - 1] === 'function') { 114 args[len - 1].call(this, paramMock.businessErrorMock, allScreenMock); 115 } else { 116 return new Promise((resolve) => { 117 resolve(allScreenMock); 118 }); 119 } 120 }, 121 on: function(...args) { 122 console.warn('Screen.on interface mocked in the Previewer. How this interface works on the Previewer may be' + 123 ' different from that on a real device.'); 124 const len = args.length; 125 if (len!==2){ 126 console.warn("Screen.on please check params!") 127 return 128 } 129 if (typeof args[len - 1] === 'function') { 130 if (args[0] === EventTypeMock.connect || args[0] === EventTypeMock.disconnect || args[0] === EventTypeMock.change) { 131 console.warn(`Screen.on you has registered ${args[0]} event`) 132 } else { 133 console.warn('Screen.on please check first param!') 134 } 135 } else { 136 console.warn('Screen.on please check param!') 137 } 138 }, 139 off: function(...args) { 140 console.warn('Screen.off interface mocked in the Previewer. How this interface works on the Previewer may be' + 141 ' different from that on a real device.'); 142 const len = args.length; 143 if (len!==2){ 144 console.warn("Screen.off please check params!") 145 return 146 } 147 if (typeof args[len - 1] === 'function') { 148 if (args[0] === EventTypeMock.connect || args[0] === EventTypeMock.disconnect || args[0] === EventTypeMock.change) { 149 console.warn(`Screen.off you has registered ${args[0]} event`) 150 } else { 151 console.warn('Screen.off please check first param!') 152 } 153 } else { 154 console.warn('Screen.off please check param!') 155 } 156 }, 157 makeExpand: function(...args) { 158 console.warn('Screen.makeExpand interface mocked in the Previewer. How this interface works on the Previewer' + 159 ' may be different from that on a real device.'); 160 const len = args.length; 161 if (typeof args[len - 1] === 'function') { 162 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 163 } else { 164 return new Promise((resolve) => { 165 resolve(paramMock.paramNumberMock); 166 }); 167 } 168 }, 169 makeMirror: function(...args) { 170 console.warn( 'Screen.makeMirror interface mocked in the Previewer. How this interface works on the Previewer' + 171 ' may be different from that on a real device.'); 172 const len = args.length; 173 if (typeof args[len - 1] === 'function') { 174 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 175 } else { 176 return new Promise((resolve) => { 177 resolve(paramMock.paramNumberMock); 178 }); 179 } 180 }, 181 createVirtualScreen: function(...args) { 182 console.warn( 'Screen.createVirtualScreen interface mocked in the Previewer. How this interface works on the' + 183 ' Previewer may be different from that on a real device.'); 184 const len = args.length; 185 if (typeof args[len - 1] === 'function') { 186 args[len - 1].call(this, paramMock.businessErrorMock, Screen); 187 } else { 188 return new Promise((resolve) => { 189 resolve(Screen); 190 }); 191 } 192 }, 193 destroyVirtualScreen: function(...args) { 194 console.warn('Screen.destroyVirtualScreen interface mocked in the Previewer. How this interface works on the' + 195 ' Previewer may be different from that on a real device.'); 196 const len = args.length; 197 if (typeof args[len - 1] === 'function') { 198 args[len - 1].call(this, paramMock.businessErrorMock); 199 } else { 200 return new Promise((resolve) => { 201 resolve(); 202 }); 203 } 204 }, 205 setVirtualScreenSurface: function(...args) { 206 console.warn( 'Screen.setVirtualScreenSurface interface mocked in the Previewer. How this interface works on' + 207 ' the Previewer may be different from that on a real device.'); 208 const len = args.length; 209 if (typeof args[len - 1] === 'function') { 210 args[len - 1].call(this, paramMock.businessErrorMock); 211 } else { 212 return new Promise((resolve) => { 213 resolve(); 214 }); 215 } 216 }, 217 isScreenRotationLocked: function(...args) { 218 console.warn( 'Screen.setVirtualScreenSurface interface mocked in the Previewer. How this interface works on' + 219 ' the Previewer may be different from that on a real device.'); 220 const len = args.length; 221 if (typeof args[len - 1] === 'function') { 222 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 223 } else { 224 return new Promise((resolve) => { 225 resolve(paramMock.paramBooleanMock); 226 }); 227 } 228 }, 229 setScreenRotationLocked: function(...args) { 230 console.warn( 'Screen.setVirtualScreenSurface interface mocked in the Previewer. How this interface works on' + 231 ' the Previewer may be different from that on a real device.'); 232 const len = args.length; 233 if (typeof args[len - 1] === 'function') { 234 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 235 } else { 236 return new Promise((resolve) => { 237 resolve(paramMock.paramBooleanMock); 238 }); 239 } 240 } 241 } 242 return screen 243} 244 245