• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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
18const sizeMock = {
19  height: "[PC Preview] unknow height",
20  width: "[PC Preview] unknow width"
21}
22const imageInfoMock = {
23  size: sizeMock,
24  pixelFortmat: "[PC Preview] unknow pixelFortmat",
25  colorSpace: "[PC Preview] unknow colorSpace",
26  alphaType: "[PC Preview] unknow alphaType"
27}
28export const PixelMapMock = {
29  isEditable: "[PC Preview]: unknow isEditable",
30  readPixelsToBuffer: function (...args) {
31    console.warn("PixelMap.readPixelsToBuffer interface mocked in the Previewer. How this interface works on the Previewer" +
32      " may be different from that on a real device.")
33    const len = args.length
34    if (typeof args[len - 1] === 'function') {
35      args[len - 1].call(this, paramMock.businessErrorMock);
36    } else {
37      return new Promise((resolve, reject) => {
38        resolve();
39      })
40    }
41  },
42  readPixels: function (...args) {
43    console.warn("PixelMap.readPixels interface mocked in the Previewer. How this interface works on the Previewer" +
44      " may be different from that on a real device.")
45    const len = args.length
46    if (typeof args[len - 1] === 'function') {
47      args[len - 1].call(this, paramMock.businessErrorMock);
48    } else {
49      return new Promise((resolve, reject) => {
50        resolve();
51      })
52    }
53  },
54  writePixels: function (...args) {
55    console.warn("PixelMap.writePixels interface mocked in the Previewer. How this interface works on the Previewer" +
56      " may be different from that on a real device.")
57    const len = args.length
58    if (typeof args[len - 1] === 'function') {
59      args[len - 1].call(this, paramMock.businessErrorMock);
60    } else {
61      return new Promise((resolve, reject) => {
62        resolve();
63      })
64    }
65  },
66  writeBufferToPixels: function (...args) {
67    console.warn("PixelMap.writeBufferToPixels interface mocked in the Previewer. How this interface works on the Previewer" +
68      " may be different from that on a real device.")
69    const len = args.length
70    if (typeof args[len - 1] === 'function') {
71      args[len - 1].call(this, paramMock.businessErrorMock);
72    } else {
73      return new Promise((resolve, reject) => {
74        resolve();
75      })
76    }
77  },
78  getImageInfo: function (...args) {
79    console.warn("PixelMap.getImageInfo interface mocked in the Previewer. How this interface works on the Previewer" +
80      " may be different from that on a real device.")
81    const len = args.length
82    if (len > 0 && typeof args[len - 1] === 'function') {
83      args[len - 1].call(this, paramMock.businessErrorMock, imageInfoMock);
84    } else {
85      return new Promise((resolve, reject) => {
86        resolve(imageInfoMock);
87      })
88    }
89  },
90  getBytesNumberPerRow: function (...args) {
91    console.warn("PixelMap.getBytesNumberPerRow interface mocked in the Previewer. How this interface works on the Previewer" +
92      " may be different from that on a real device.")
93    return paramMock.paramNumberMock
94  },
95  getPixelBytesNumber: function (...args) {
96    console.warn("PixelMap.getPixelBytesNumber interface mocked in the Previewer. How this interface works on the Previewer" +
97      " may be different from that on a real device.")
98    return paramMock.paramNumberMock
99  },
100  release: function (...args) {
101    console.warn("PixelMap.release interface mocked in the Previewer. How this interface works on the Previewer" +
102      " may be different from that on a real device.")
103    const len = args.length
104    if (len > 0 && typeof args[len - 1] === 'function') {
105      args[len - 1].call(this, paramMock.businessErrorMock);
106    } else {
107      return new Promise((resolve, reject) => {
108        resolve();
109      })
110    }
111  }
112}
113
114export function mockMultimediaImage() {
115  global.systemplugin.multimedia = {}
116  const imageSourceMock = {
117    getImageInfo: function (...args) {
118      console.warn("ImageSource.getImageInfo interface mocked in the Previewer. How this interface works on the" +
119        " Previewer may be different from that on a real device.")
120      const len = args.length
121      if (typeof args[len - 1] === 'function') {
122        args[len - 1].call(this, paramMock.businessErrorMock, imageInfoMock);
123      } else {
124        return new Promise((resolve, reject) => {
125          resolve(imageInfoMock);
126        })
127      }
128    },
129    release: function (...args) {
130      console.warn("ImageSource.release interface mocked in the Previewer. How this interface works on the Previewer" +
131        " may be different from that on a real device.")
132      const len = args.length
133      if (len > 0 && typeof args[len - 1] === 'function') {
134        args[len - 1].call(this, paramMock.businessErrorMock);
135      } else {
136        return new Promise((resolve, reject) => {
137          resolve();
138        })
139      }
140    },
141    createPixelMap: function (...args) {
142      console.warn("ImageSource.createPixelMap interface mocked in the Previewer. How this interface works on the Previewer" +
143        " may be different from that on a real device.")
144      const len = args.length
145      if (len > 0 && typeof args[len - 1] === 'function') {
146        args[len - 1].call(this, paramMock.businessErrorMock, PixelMapMock);
147      } else {
148        return new Promise((resolve, reject) => {
149          resolve(PixelMapMock);
150        })
151      }
152    },
153    getImageProperty: function (...args) {
154      console.warn("ImageSource.getImageProperty interface mocked in the Previewer. How this interface works on the Previewer" +
155        " may be different from that on a real device.")
156      const len = args.length
157      if (len > 0 && typeof args[len - 1] === 'function') {
158        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
159      } else {
160        return new Promise((resolve, reject) => {
161          resolve(paramMock.paramStringMock);
162        })
163      }
164    },
165    supportedFormats: "[PC Preview] unknow supportedFormats"
166  }
167  const imagePackerMock = {
168    packing: function (...args) {
169      console.warn("ImagePacker.packing interface mocked in the Previewer. How this interface works on the Previewer" +
170        " may be different from that on a real device.")
171      const len = args.length
172      if (typeof args[len - 1] === 'function') {
173        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock);
174      } else {
175        return new Promise((resolve, reject) => {
176          resolve(paramMock.paramArrayMock);
177        })
178      }
179    },
180    release: function (...args) {
181      console.warn("ImagePacker.release interface mocked in the Previewer. How this interface works on the Previewer" +
182        " may be different from that on a real device.")
183      const len = args.length
184      if (typeof args[len - 1] === 'function') {
185        args[len - 1].call(this, paramMock.businessErrorMock);
186      } else {
187        return new Promise((resolve, reject) => {
188          resolve();
189        })
190      }
191    },
192    supportedFormats: "[PC Preview] unknow supportedFormats"
193  }
194  const PixelMapFormatMock = {
195    UNKNOWN: "[PC Preview]: unknow UNKNOWN",
196    RGB_565: "[PC Preview]: unknow RGB_565",
197    RGBA_8888: "[PC Preview]: unknow RGBA_8888",
198  }
199  const PropertyKeyMock = {
200    BITS_PER_SAMPLE: "[PC Preview]: unknow BITS_PER_SAMPLE",
201    ORIENTATION: "[PC Preview]: unknow ORIENTATION",
202    IMAGE_LENGTH: "[PC Preview]: unknow IMAGE_LENGTH",
203    GPS_LATITUDE: "[PC Preview]: unknow GPS_LATITUDE",
204    GPS_LONGITUDE: "[PC Preview]: unknow GPS_LONGITUDE",
205    GPS_LATITUDE_REF: "[PC Preview]: unknow GPS_LATITUDE_REF",
206    GPS_LONGITUDE_REF: "[PC Preview]: unknow GPS_LONGITUDE_REF"
207  }
208
209  global.systemplugin.multimedia.image = {
210    PixelMapFormat: PixelMapFormatMock,
211    PropertyKey: PropertyKeyMock,
212    createImageSource: function () {
213      console.warn("multimedia.image.createImageSource interface mocked in the Previewer. How this interface works" +
214        " on the Previewer may be different from that on a real device.")
215      return imageSourceMock;
216    },
217    createImagePacker: function () {
218      console.warn("multimedia.image.createImagePacker interface mocked in the Previewer. How this interface works" +
219        " on the Previewer may be different from that on a real device.")
220      return imagePackerMock;
221    }
222  }
223}
224
225export function mockMultimediaMedia() {
226  const MediaType = {
227    VIDEO: "[PC Preview]: unknow VIDEO",
228    AUDIO: "[PC Preview]: unknow AUDIO",
229  }
230  const ComposerTrack = {
231    trackId: "[PC Preview]: unknow trackId",
232    type: MediaType,
233    duration: "[PC Preview]: unknow duration"
234  }
235  const sizeMock = {
236    height: "[PC Preview] unknow height",
237    width: "[PC Preview] unknow width"
238  }
239  const DecoderFrameMock = {
240    size: sizeMock,
241    pts: "[PC Preview] unknow pts",
242    buffer: "[PC Preview] unknow buffer"
243  }
244  const audioPlayerMock = {
245    play: function () {
246      console.warn("AudioPlayer.play interface mocked in the Previewer. How this interface works on the Previewer" +
247        " may be different from that on a real device.")
248    },
249    pause: function () {
250      console.warn("AudioPlayer.pause interface mocked in the Previewer. How this interface works on the Previewer" +
251        " may be different from that on a real device.")
252    },
253    stop: function () {
254      console.warn("AudioPlayer.stop interface mocked in the Previewer. How this interface works on the Previewer" +
255        " may be different from that on a real device.")
256    },
257    reset: function () {
258      console.warn("AudioPlayer.stop interface mocked in the Previewer. How this interface works on the Previewer" +
259        " may be different from that on a real device.")
260    },
261    seek: function (...args) {
262      console.warn("AudioPlayer.seek interface mocked in the Previewer. How this interface works on the Previewer" +
263        " may be different from that on a real device.")
264    },
265    setVolume: function (...args) {
266      console.warn("AudioPlayer.setVolume interface mocked in the Previewer. How this interface works on the" +
267        " Previewer may be different from that on a real device.")
268    },
269    release: function () {
270      console.warn("AudioPlayer.release interface mocked in the Previewer. How this interface works on the Previewer" +
271        " may be different from that on a real device.")
272    },
273    src: "[PC Preview] unknow src",
274    loop: "[PC Preview] unknow loop",
275    currentTime: "[PC Preview] unknow currentTime",
276    duration: "[PC Preview] unknow duration",
277    state: "[PC Preview] unknow state",
278    on: function (...args) {
279      console.warn("AudioPlayer.on interface mocked in the Previewer. How this interface works on the Previewer may" +
280        " be different from that on a real device.")
281      const len = args.length
282      if (typeof args[len - 1] === 'function') {
283        if (args[0] == 'error') {
284          args[len - 1].call(this, paramMock.businessErrorMock);
285        } else if (args[0] == 'timeUpdate') {
286          args[len - 1].call(this, paramMock.paramNumberMock);
287        } else {
288          args[len - 1].call(this);
289        }
290      }
291    }
292  }
293  const audioRecorderMock = {
294    prepare: function () {
295      console.warn("AudioRecorder.prepare interface mocked in the Previewer. How this interface works on the" +
296        " Previewer may be different from that on a real device.")
297    },
298    start: function () {
299      console.warn("AudioRecorder.start interface mocked in the Previewer. How this interface works on the Previewer" +
300        " may be different from that on a real device.")
301    },
302    pause: function () {
303      console.warn("AudioRecorder.pause interface mocked in the Previewer. How this interface works on the Previewer" +
304        " may be different from that on a real device.")
305    },
306    resume: function () {
307      console.warn("AudioRecorder.resume interface mocked in the Previewer. How this interface works on the" +
308        " Previewer may be different from that on a real device.")
309    },
310    stop: function () {
311      console.warn("AudioRecorder.stop interface mocked in the Previewer. How this interface works on the Previewer" +
312        " may be different from that on a real device.")
313    },
314    release: function () {
315      console.warn("AudioRecorder.release interface mocked in the Previewer. How this interface works on the" +
316        " Previewer may be different from that on a real device.")
317    },
318    reset: function () {
319      console.warn("AudioRecorder.reset interface mocked in the Previewer. How this interface works on the Previewer" +
320        " may be different from that on a real device.")
321    },
322    on: function (...args) {
323      console.warn("AudioRecorder.on interface mocked in the Previewer. How this interface works on the Previewer" +
324        " may be different from that on a real device.")
325      const len = args.length
326      if (typeof args[len - 1] === 'function') {
327        if (args[0] == 'error') {
328          args[len - 1].call(this, paramMock.businessErrorMock);
329        } else {
330          args[len - 1].call(this);
331        }
332      }
333    }
334  }
335  const MediaComposerMock = {
336    extractSource: function (...args) {
337      console.warn("MediaComposer.extractSource interface mocked in the Previewer. How this interface works on the" +
338        " Previewer may be different from that on a real device.")
339      const len = args.length
340      var composerTracks = new Array(ComposerTrack)
341      if (typeof args[len - 1] === 'function') {
342        args[len - 1].call(this, paramMock.businessErrorMock, composerTracks);
343      } else {
344        return new Promise((resolve, reject) => {
345          resolve(composerTracks);
346        })
347      }
348    },
349    configOutput: function (...args) {
350      console.warn("MediaComposer.configOutput interface mocked in the Previewer. How this interface works on" +
351        " the Previewer may be different from that on a real device.")
352      const len = args.length
353      if (typeof args[len - 1] === 'function') {
354        args[len - 1].call(this, paramMock.businessErrorMock);
355      } else {
356        return new Promise((resolve, reject) => {
357          resolve();
358        })
359      }
360    },
361    addTrack: function (...args) {
362      console.warn("MediaComposer.addTrack interface mocked in the Previewer. How this interface works on the" +
363        " Previewer may be different from that on a real device.")
364      const len = args.length
365      if (typeof args[len - 1] === 'function') {
366        args[len - 1].call(this, paramMock.businessErrorMock);
367      } else {
368        return new Promise((resolve, reject) => {
369          resolve();
370        })
371      }
372    },
373    removeTrack: function (...args) {
374      console.warn("MediaComposer.removeTrack interface mocked in the Previewer. How this interface works on the" +
375        " Previewer may be different from that on a real device.")
376      const len = args.length
377      if (typeof args[len - 1] === 'function') {
378        args[len - 1].call(this, paramMock.businessErrorMock);
379      } else {
380        return new Promise((resolve, reject) => {
381          resolve();
382        })
383      }
384    },
385    compose: function (...args) {
386      console.warn("MediaComposer.compose interface mocked in the Previewer. How this interface works on the" +
387        " Previewer may be different from that on a real device.")
388      const len = args.length
389      if (typeof args[len - 1] === 'function') {
390        args[len - 1].call(this, paramMock.businessErrorMock);
391      } else {
392        return new Promise((resolve, reject) => {
393          resolve();
394        })
395      }
396    },
397    release: function (...args) {
398      console.warn("MediaComposer.release interface mocked in the Previewer. How this interface works on the" +
399        " Previewer may be different from that on a real device.")
400      const len = args.length
401      if (typeof args[len - 1] === 'function') {
402        args[len - 1].call(this, paramMock.businessErrorMock);
403      } else {
404        return new Promise((resolve, reject) => {
405          resolve();
406        })
407      }
408    }
409  }
410  const mediaDecoderMock = {
411    start: function (...args) {
412      console.warn("MediaDecoder.start interface mocked in the Previewer. How this interface works on the Previewer" +
413        " may be different from that on a real device.")
414    },
415    seek: function (...args) {
416      console.warn("MediaDecoder.seek interface mocked in the Previewer. How this interface works on the Previewer" +
417        " may be different from that on a real device.")
418    },
419    stop: function () {
420      console.warn("MediaDecoder.stop interface mocked in the Previewer. How this interface works on the Previewer" +
421        " may be different from that on a real device.")
422    },
423    release: function () {
424      console.warn("MediaDecoder.release interface mocked in the Previewer. How this interface works on the" +
425        " Previewer may be different from that on a real device.")
426    },
427    requestFrame: function () {
428      console.warn("MediaDecoder.requestFrame interface mocked in the Previewer. How this interface works on the Previewer" +
429        " may be different from that on a real device.")
430    },
431    on: function (...args) {
432      console.warn("MediaDecoder.on interface mocked in the Previewer. How this interface works on the Previewer" +
433        " may be different from that on a real device.")
434      const len = args.length
435      if (typeof args[len - 1] === 'function') {
436        if (args[0] == 'error') {
437          args[len - 1].call(this, paramMock.businessErrorMock);
438        } else if (args[0] == 'start') {
439          args[len - 1].call(this, sizeMock);
440        } else if (args[0] == 'frameChange') {
441          args[len - 1].call(this, sizeMock);
442        } else if (args[0] == 'frameAvailable') {
443          args[len - 1].call(this, DecoderFrameMock);
444        } else {
445          args[len - 1].call(this);
446        }
447      }
448    }
449  }
450  const MimeTypeMock = '[PC Preview] unknow mimeType'
451  const CodecDescriptionMock = {
452    name: "[PC Preview] unknow name",
453    mimeTypes: new Array(MimeTypeMock),
454    isAudio: "[PC Preview] unknow isAudio",
455    isEncoder: "[PC Preview] unknow isEncoder",
456    isSoftware: "[PC Preview] unknow isSoftware",
457  }
458  const codecDescriptionHelperMock = {
459    findDecoder: function (...args) {
460      console.warn("CodecDescriptionHelper.findDecoder interface mocked in the Previewer. How this interface works" +
461        " on the Previewer may be different from that on a real device.")
462      const len = args.length
463      if (typeof args[len - 1] === 'function') {
464        args[len - 1].call(this, paramMock.businessErrorMock, CodecDescriptionMock);
465      } else {
466        return new Promise((resolve, reject) => {
467          resolve(CodecDescriptionMock);
468        })
469      }
470    },
471    findEncoder: function (...args) {
472      console.warn("CodecDescriptionHelper.findEncoder interface mocked in the Previewer. How this interface works" +
473        " on the Previewer may be different from that on a real device.")
474      const len = args.length
475      if (typeof args[len - 1] === 'function') {
476        args[len - 1].call(this, paramMock.businessErrorMock, CodecDescriptionMock);
477      } else {
478        return new Promise((resolve, reject) => {
479          resolve(CodecDescriptionMock);
480        })
481      }
482    },
483    getSupportedDecoders: function (...args) {
484      console.warn("CodecDescriptionHelper.getSupportedDecoders interface mocked in the Previewer. How this interface works" +
485        " on the Previewer may be different from that on a real device.")
486      const len = args.length
487      var CodecDescriptionArray = new Array(CodecDescriptionMock)
488      if (typeof args[len - 1] === 'function') {
489        args[len - 1].call(this, paramMock.businessErrorMock, CodecDescriptionArray);
490      } else {
491        return new Promise((resolve, reject) => {
492          resolve(CodecDescriptionArray);
493        })
494      }
495    },
496    getSupportedEncoders: function (...args) {
497      console.warn("CodecDescriptionHelper.getSupportedEncoders interface mocked in the Previewer. How this interface works" +
498        " on the Previewer may be different from that on a real device.")
499      const len = args.length
500      var CodecDescriptionArray = new Array(CodecDescriptionMock)
501      if (typeof args[len - 1] === 'function') {
502        args[len - 1].call(this, paramMock.businessErrorMock, CodecDescriptionArray);
503      } else {
504        return new Promise((resolve, reject) => {
505          resolve(CodecDescriptionArray);
506        })
507      }
508    },
509    getSupportedMimes: function (...args) {
510      console.warn("CodecDescriptionHelper.getSupportedMimes interface mocked in the Previewer. How this interface works" +
511        " on the Previewer may be different from that on a real device.")
512      const len = args.length
513      var MimeTypeArray = new Array(MimeTypeMock)
514      if (typeof args[len - 1] === 'function') {
515        args[len - 1].call(this, paramMock.businessErrorMock, MimeTypeArray);
516      } else {
517        return new Promise((resolve, reject) => {
518          resolve(MimeTypeArray);
519        })
520      }
521    },
522    isDecoderSupportedByFormat: function (...args) {
523      console.warn("CodecDescriptionHelper.isDecoderSupportedByFormat interface mocked in the Previewer. How this interface works" +
524        " on the Previewer may be different from that on a real device.")
525      const len = args.length
526      if (typeof args[len - 1] === 'function') {
527        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
528      } else {
529        return new Promise((resolve, reject) => {
530          resolve(paramMock.paramBooleanMock);
531        })
532      }
533    },
534    isDecoderSupportedByMime: function (...args) {
535      console.warn("CodecDescriptionHelper.isDecoderSupportedByMime interface mocked in the Previewer. How this interface works" +
536        " on the Previewer may be different from that on a real device.")
537      const len = args.length
538      if (typeof args[len - 1] === 'function') {
539        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
540      } else {
541        return new Promise((resolve, reject) => {
542          resolve(paramMock.paramBooleanMock);
543        })
544      }
545    },
546    isEncoderSupportedByFormat: function (...args) {
547      console.warn("CodecDescriptionHelper.isEncoderSupportedByFormat interface mocked in the Previewer. How this interface works" +
548        " on the Previewer may be different from that on a real device.")
549      const len = args.length
550      if (typeof args[len - 1] === 'function') {
551        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
552      } else {
553        return new Promise((resolve, reject) => {
554          resolve(paramMock.paramBooleanMock);
555        })
556      }
557    },
558    isEncoderSupportedByMime: function (...args) {
559      console.warn("CodecDescriptionHelper.findDisEncoderSupportedByMime interface mocked in the Previewer. How this interface works" +
560        " on the Previewer may be different from that on a real device.")
561      const len = args.length
562      if (typeof args[len - 1] === 'function') {
563        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
564      } else {
565        return new Promise((resolve, reject) => {
566          resolve(paramMock.paramBooleanMock);
567        })
568      }
569    }
570  }
571  global.systemplugin.multimedia.media = {
572    MediaType: {
573      VIDEO: 0,
574      AUDIO: 1,
575    },
576    createAudioPlayer: function () {
577      console.warn("multimedia.media.createAudioPlayer interface mocked in the Previewer. How this interface works" +
578        " on the Previewer may be different from that on a real device.")
579      return audioPlayerMock;
580    },
581    createAudioRecorder: function () {
582      console.warn("multimedia.media.createAudioRecorder interface mocked in the Previewer. How this interface works" +
583        " on the Previewer may be different from that on a real device.")
584      return audioRecorderMock;
585    },
586    createMediaComposer: function () {
587      console.warn("multimedia.media.createMediaComposer interface mocked in the Previewer. How this interface works" +
588        " on the Previewer may be different from that on a real device.")
589      return MediaComposerMock;
590    },
591    createMediaDecoder: function () {
592      console.warn("multimedia.media.createMediaDecoder interface mocked in the Previewer. How this interface works" +
593        " on the Previewer may be different from that on a real device.")
594      return mediaDecoderMock;
595    },
596    getCodecDescriptionHelper: function () {
597      console.warn("multimedia.media.getCodecDescriptionHelper interface mocked in the Previewer. How this" +
598        " interface works on the Previewer may be different from that on a real device.")
599      return codecDescriptionHelperMock;
600    }
601  }
602}
603
604export function mockMultimediaMedialibrary() {
605  const FileAssetMock = {
606    id: "[PC Preview] unknow id",
607    uri: "[PC Preview] unknow uri",
608    thumbnailUri: "[PC Preview] unknow thumbnailUri",
609    mimeType: "[PC Preview] unknow mimeType",
610    mediaType: "[PC Preview] unknow mediaType",
611    displayName: "[PC Preview] unknow displayName",
612    title: "[PC Preview] unknow title",
613    size: "[PC Preview] unknow size",
614    albumId: "[PC Preview] unknow albumId",
615    albumName: "[PC Preview] unknow albumName",
616    dateAdded: "[PC Preview] unknow dateAdded",
617    dateModified: "[PC Preview] unknow dateMidified",
618    dateTaken: "[PC Preview] unknow dateTaken",
619    orientation: "[PC Preview] unknow orientation",
620    width: "[PC Preview] unknow width",
621    height: "[PC Preview] unknow height",
622    extendedValues: "[PC Preview] unknow extendedValues",
623  }
624  const MediaLibraryMock = {
625    storeMediaAsset: function (...args) {
626      console.warn("MediaLibrary.storeMediaAsset interface mocked in the Previewer. How this interface works on the" +
627        " Previewer may be different from that on a real device.")
628      const len = args.length
629      if (typeof args[len - 1] === 'function') {
630        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
631      } else {
632        return new Promise((resolve, reject) => {
633          resolve(paramMock.paramStringMock);
634        })
635      }
636    },
637    startImagePreview: function (...args) {
638      console.warn("MediaLibrary.startImagePreview interface mocked in the Previewer. How this interface works on" +
639        " the Previewer may be different from that on a real device.")
640      const len = args.length
641      if (typeof args[len - 1] === 'function') {
642        args[len - 1].call(this, paramMock.businessErrorMock);
643      } else {
644        return new Promise((resolve, reject) => {
645          resolve();
646        })
647      }
648    },
649    startMediaSelect: function (...args) {
650      console.warn("MediaLibrary.startMediaSelect interface mocked in the Previewer. How this interface works on the" +
651        " Previewer may be different from that on a real device.")
652      const len = args.length
653      if (typeof args[len - 1] === 'function') {
654        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock);
655      } else {
656        return new Promise((resolve, reject) => {
657          resolve(paramMock.paramArrayMock);
658        })
659      }
660    },
661    getFileAssets: function (...args) {
662      console.warn("MediaLibrary.getFileAssets interface mocked in the Previewer. How this interface works on the" +
663        " Previewer may be different from that on a real device.")
664      const len = args.length
665      var isCallBack = typeof args[len - 1] === 'function'
666      return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FetchFileResultMock)
667        : new Promise((resolve, reject) => {
668          resolve(FetchFileResultMock);
669        })
670    },
671    getAlbums: function (...args) {
672      console.warn("MediaLibrary.getAlbums interface mocked in the Previewer. How this interface works on the" +
673        " Previewer may be different from that on a real device.")
674      const len = args.length
675      var albumsMock = new Array(AlbumMock)
676      var isCallBack = typeof args[len - 1] === 'function'
677      return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, albumsMock)
678        : new Promise((resolve, reject) => {
679          resolve(albumsMock);
680        })
681    },
682    on: function (...args) {
683      console.warn("MediaLibrary.on interface mocked in the Previewer. How this interface works on the Previewer" +
684        " may be different from that on a real device.")
685    },
686    off: function (...args) {
687      console.warn("MediaLibrary.off interface mocked in the Previewer. How this interface works on the Previewer" +
688        " may be different from that on a real device.")
689    }
690  }
691  const FetchFileResultMock = {
692    getCount: function (...args) {
693      console.warn("FetchFileResult.getCount interface mocked in the Previewer. How this interface works on the" +
694        " Previewer may be different from that on a real device.")
695      return paramMock.paramNumberMock
696    },
697    isAfterLast: function (...args) {
698      console.warn("FetchFileResult.isAfterLast interface mocked in the Previewer. How this interface works on the" +
699        " Previewer may be different from that on a real device.")
700      return paramMock.paramBooleanMock
701    },
702    close: function (...args) {
703      console.warn("FetchFileResult.close interface mocked in the Previewer. How this interface works on the Previewer" +
704        " may be different from that on a real device.")
705    },
706    getFirstObject: function (...args) {
707      console.warn("FetchFileResult.getFirstObject interface mocked in the Previewer. How this interface works on the" +
708        " Previewer may be different from that on a real device.")
709      const len = args.length
710      var isCallBack = typeof args[len - 1] === 'function'
711      return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FileAssetMock)
712        : new Promise((resolve, reject) => {
713          resolve(FileAssetMock);
714        })
715    },
716    getLastObject: function (...args) {
717      console.warn("FetchFileResult.getLastObject interface mocked in the Previewer. How this interface works on the" +
718        " Previewer may be different from that on a real device.")
719      const len = args.length
720      var isCallBack = typeof args[len - 1] === 'function'
721      return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FileAssetMock)
722        : new Promise((resolve, reject) => {
723          resolve(FileAssetMock);
724        })
725    },
726    getNextObject: function (...args) {
727      console.warn("FetchFileResult.getNextObject interface mocked in the Previewer. How this interface works on the" +
728        " Previewer may be different from that on a real device.")
729      const len = args.length
730      var isCallBack = typeof args[len - 1] === 'function'
731      return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FileAssetMock)
732        : new Promise((resolve, reject) => {
733          resolve(FileAssetMock);
734        })
735    },
736    getPositionObject: function (...args) {
737      console.warn("FetchFileResult.getPositionObject interface mocked in the Previewer. How this interface works on" +
738        " the Previewer may be different from that on a real device.")
739      const len = args.length
740      var isCallBack = typeof args[len - 1] === 'function'
741      return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FileAssetMock)
742        : new Promise((resolve, reject) => {
743          resolve(FileAssetMock);
744        })
745    },
746    getAllObject: function (...args) {
747      console.warn("FetchFileResult.getAllObject interface mocked in the Previewer. How this interface works on" +
748        " the Previewer may be different from that on a real device.")
749      const len = args.length
750      var fileAssets = new Array(FileAssetMock)
751      var isCallBack = typeof args[len - 1] === 'function'
752      return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, fileAssets)
753        : new Promise((resolve, reject) => {
754          resolve(fileAssets);
755        })
756    }
757  }
758  const AlbumMock = {
759    albumId: "[PC Preview] unknow albumId",
760    albumName: "[PC Preview] unknow albumName",
761    path: "[PC Preview] unknow path",
762    dateModified: "[PC Preview] unknow dateModified",
763    getFileAssets: function (...args) {
764      console.warn("Album.getFileAssets interface mocked in the Previewer. How this interface works on the" +
765        " Previewer may be different from that on a real device.")
766      const len = args.length
767      var isCallBack = typeof args[len - 1] === 'function'
768      return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, FetchFileResultMock)
769        : new Promise((resolve, reject) => {
770          resolve(FetchFileResultMock);
771        })
772    }
773  }
774  const AVMetadataHelperMock = {
775    setSource: function (...args) {
776      console.warn("AVMetadataHelper.setSource interface mocked in the Previewer. How this interface works on the" +
777        " Previewer may be different from that on a real device.")
778      const len = args.length
779      var isCallBack = typeof args[len - 1] === 'function'
780      return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock)
781        : new Promise((resolve, reject) => {
782          resolve();
783        })
784    },
785    fetchVideoPixelMapByTime: function (...args) {
786      console.warn("AVMetadataHelper.fetchVideoPixelMapByTime interface mocked in the Previewer. How this interface" +
787        " works on the Previewer may be different from that on a real device.")
788      const len = args.length
789      var isCallBack = typeof args[len - 1] === 'function'
790      return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock)
791        : new Promise((resolve, reject) => {
792          resolve(paramMock.paramObjectMock);
793        })
794    },
795    resolveMetadata: function (...args) {
796      console.warn("AVMetadataHelper.resolveMetadata interface mocked in the Previewer. How this interface" +
797        " works on the Previewer may be different from that on a real device.")
798      const len = args.length
799      var isCallBack = typeof args[len - 1] === 'function'
800      return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock)
801        : new Promise((resolve, reject) => {
802          resolve(paramMock.paramStringMock);
803        })
804    },
805    release: function (...args) {
806      console.warn("AVMetadataHelper.release interface mocked in the Previewer. How this interface works on the" +
807        " Previewer may be different from that on a real device.")
808      const len = args.length
809      var isCallBack = typeof args[len - 1] === 'function'
810      return isCallBack ? args[len - 1].call(this, paramMock.businessErrorMock)
811        : new Promise((resolve, reject) => {
812          resolve();
813        })
814    }
815  }
816  global.systemplugin.multimedia.mediaLibrary = {
817    getMediaLibrary: function () {
818      console.warn("multimedia.mediaLibrary.getMediaLibrary interface mocked in the Previewer. How this interface" +
819        " works on the Previewer may be different from that on a real device.")
820      return MediaLibraryMock;
821    },
822    createAVMetadataHelper: function () {
823      console.warn("multimedia.mediaLibrary.createAVMetadataHelper interface mocked in the Previewer. How this" +
824        " interface works on the Previewer may be different from that on a real device.")
825      return AVMetadataHelperMock;
826    },
827  }
828}
829
830export function mockMultimediaAudio() {
831  const interruptActionMock = {
832    actionType: "[PC Preview] unknow actionType",
833    type: "[PC Preview] unknow type",
834    hint: "[PC Preview] unknow hint",
835    activated: "[PC Preview] unknow activated",
836  }
837  const AudioEncodingFormatMock = "[PC Preview]: unknow AudioEncodingFormat"
838  const DeviceRoleMock = "[PC Preview]: unknow DeviceRole"
839  const DeviceTypeMock = "[PC Preview]: unknow DeviceType"
840  const AudioDeviceDescriptorMock = {
841    id: "[PC Preview]: unknow id",
842    name: "[PC Preview]: unknow name",
843    address: "[PC Preview]: unknow address",
844    sampleRates: new Array(paramMock.paramNumberMock),
845    channelCounts: new Array(paramMock.paramNumberMock),
846    channelIndexMasks: new Array(paramMock.paramNumberMock),
847    channelMasks: new Array(paramMock.paramNumberMock),
848    encodingFormats: new Array(AudioEncodingFormatMock),
849    deviceRole: DeviceRoleMock,
850    deviceType: DeviceTypeMock,
851  }
852  const DeviceChangeActionMock = {
853    type: "[PC Preview]: unknow type",
854    deviceDescriptors: AudioDeviceDescriptorMock,
855  }
856  const AudioRingModeMock = '[PC Preview]: unknow AudioRingMode'
857  const audioManagerMock = {
858    on: function (...args) {
859      console.warn("AudioManager.on interface mocked in the Previewer. How this interface works on the Previewer" +
860        " may be different from that on a real device.")
861      const len = args.length
862      if (typeof args[len - 1] === 'function') {
863        if (args[0] == 'interrupt') {
864          args[len - 1].call(this, interruptActionMock);
865        } else if (args[0] == 'deviceChange') {
866          args[len - 1].call(this, DeviceChangeActionMock);
867        } else {
868          args[len - 1].call(this);
869        }
870      }
871    },
872    off: function (...args) {
873      console.warn("AudioManager.off interface mocked in the Previewer. How this interface works on the Previewer" +
874        " may be different from that on a real device.")
875      const len = args.length
876      if (typeof args[len - 1] === 'function') {
877        if (args[0] == 'interrupt') {
878          args[len - 1].call(this, interruptActionMock);
879        } else if (args[0] == 'deviceChange') {
880          args[len - 1].call(this);
881        } else {
882          args[len - 1].call(this);
883        }
884      }
885    },
886    getDevices: function (...args) {
887      console.warn("AudioManager.getDevices interface mocked in the Previewer. How this interface works on the" +
888        " Previewer may be different from that on a real device.")
889      var AudioDeviceDescriptors = new Array(AudioDeviceDescriptorMock)
890      const len = args.length
891      if (typeof args[len - 1] === 'function') {
892        args[len - 1].call(this, paramMock.businessErrorMock, AudioDeviceDescriptors);
893      } else {
894        return new Promise((resolve, reject) => {
895          resolve(AudioDeviceDescriptors);
896        })
897      }
898    },
899    isDeviceActive: function (...args) {
900      console.warn("AudioManager.isDeviceActive interface mocked in the Previewer. How this interface works on" +
901        " the Previewer may be different from that on a real device.")
902      const len = args.length
903      if (typeof args[len - 1] === 'function') {
904        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
905      } else {
906        return new Promise((resolve, reject) => {
907          resolve(paramMock.paramBooleanMock);
908        })
909      }
910    },
911    setDeviceActive: function (...args) {
912      console.warn("AudioManager.setDeviceActive interface mocked in the Previewer. How this interface works on the" +
913        " Previewer may be different from that on a real device.")
914      const len = args.length
915      if (typeof args[len - 1] === 'function') {
916        args[len - 1].call(this, paramMock.businessErrorMock);
917      } else {
918        return new Promise((resolve, reject) => {
919          resolve();
920        })
921      }
922    },
923    setRingerMode: function (...args) {
924      console.warn("AudioManager.setRingerMode interface mocked in the Previewer. How this interface works on the" +
925        " Previewer may be different from that on a real device.")
926      const len = args.length
927      if (typeof args[len - 1] === 'function') {
928        args[len - 1].call(this, paramMock.businessErrorMock);
929      } else {
930        return new Promise((resolve, reject) => {
931          resolve();
932        })
933      }
934    },
935    setAudioParameter: function (...args) {
936      console.warn("AudioManager.setAudioParameter interface mocked in the Previewer. How this interface works on the" +
937        " Previewer may be different from that on a real device.")
938      const len = args.length
939      if (typeof args[len - 1] === 'function') {
940        args[len - 1].call(this, paramMock.businessErrorMock);
941      } else {
942        return new Promise((resolve, reject) => {
943          resolve();
944        })
945      }
946    },
947    setVolume: function (...args) {
948      console.warn("AudioManager.setVolume interface mocked in the Previewer. How this interface works on the" +
949        " Previewer may be different from that on a real device.")
950      const len = args.length
951      if (typeof args[len - 1] === 'function') {
952        args[len - 1].call(this, paramMock.businessErrorMock);
953      } else {
954        return new Promise((resolve, reject) => {
955          resolve();
956        })
957      }
958    },
959    getVolume: function (...args) {
960      console.warn("AudioManager.getVolume interface mocked in the Previewer. How this interface works on the" +
961        " Previewer may be different from that on a real device.")
962      const len = args.length
963      if (typeof args[len - 1] === 'function') {
964        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
965      } else {
966        return new Promise((resolve, reject) => {
967          resolve(paramMock.paramNumberMock);
968        })
969      }
970    },
971    getMinVolume: function (...args) {
972      console.warn("AudioManager.getMinVolume interface mocked in the Previewer. How this interface works on the" +
973        " Previewer may be different from that on a real device.")
974      const len = args.length
975      if (typeof args[len - 1] === 'function') {
976        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
977      } else {
978        return new Promise((resolve, reject) => {
979          resolve(paramMock.paramNumberMock);
980        })
981      }
982    },
983    getMaxVolume: function (...args) {
984      console.warn("AudioManager.getMaxVolume interface mocked in the Previewer. How this interface works on the" +
985        " Previewer may be different from that on a real device.")
986      const len = args.length
987      if (typeof args[len - 1] === 'function') {
988        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock);
989      } else {
990        return new Promise((resolve, reject) => {
991          resolve(paramMock.paramNumberMock);
992        })
993      }
994    },
995    isMute: function (...args) {
996      console.warn("AudioManager.isMute interface mocked in the Previewer. How this interface works on the" +
997        " Previewer may be different from that on a real device.")
998      const len = args.length
999      if (typeof args[len - 1] === 'function') {
1000        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
1001      } else {
1002        return new Promise((resolve, reject) => {
1003          resolve(paramMock.paramBooleanMock);
1004        })
1005      }
1006    },
1007    mute: function (...args) {
1008      console.warn("AudioManager.mute interface mocked in the Previewer. How this interface works on the" +
1009        " Previewer may be different from that on a real device.")
1010      const len = args.length
1011      if (typeof args[len - 1] === 'function') {
1012        args[len - 1].call(this, paramMock.businessErrorMock);
1013      } else {
1014        return new Promise((resolve, reject) => {
1015          resolve();
1016        })
1017      }
1018    },
1019    isActive: function (...args) {
1020      console.warn("AudioManager.isActive interface mocked in the Previewer. How this interface works on the" +
1021        " Previewer may be different from that on a real device.")
1022      const len = args.length
1023      if (typeof args[len - 1] === 'function') {
1024        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
1025      } else {
1026        return new Promise((resolve, reject) => {
1027          resolve(paramMock.paramBooleanMock);
1028        })
1029      }
1030    },
1031    isMicrophoneMute: function (...args) {
1032      console.warn("AudioManager.isMicrophoneMute interface mocked in the Previewer. How this interface works on the" +
1033        " Previewer may be different from that on a real device.")
1034      const len = args.length
1035      if (typeof args[len - 1] === 'function') {
1036        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock);
1037      } else {
1038        return new Promise((resolve, reject) => {
1039          resolve(paramMock.paramBooleanMock);
1040        })
1041      }
1042    },
1043    setMicrophoneMute: function (...args) {
1044      console.warn("AudioManager.setMicrophoneMute interface mocked in the Previewer. How this interface works on the" +
1045        " Previewer may be different from that on a real device.")
1046      const len = args.length
1047      if (typeof args[len - 1] === 'function') {
1048        args[len - 1].call(this, paramMock.businessErrorMock);
1049      } else {
1050        return new Promise((resolve, reject) => {
1051          resolve();
1052        })
1053      }
1054    },
1055    getAudioParameter: function (...args) {
1056      console.warn("AudioManager.getAudioParameter interface mocked in the Previewer. How this interface works on the" +
1057        " Previewer may be different from that on a real device.")
1058      const len = args.length
1059      if (typeof args[len - 1] === 'function') {
1060        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock);
1061      } else {
1062        return new Promise((resolve, reject) => {
1063          resolve(paramMock.paramStringMock);
1064        })
1065      }
1066    },
1067    getRingerMode: function (...args) {
1068      console.warn("AudioManager.getRingerMode interface mocked in the Previewer. How this interface works on the" +
1069        " Previewer may be different from that on a real device.")
1070      const len = args.length
1071      if (typeof args[len - 1] === 'function') {
1072        args[len - 1].call(this, paramMock.businessErrorMock, AudioRingModeMock);
1073      } else {
1074        return new Promise((resolve, reject) => {
1075          resolve(AudioRingModeMock);
1076        })
1077      }
1078    }
1079  }
1080  global.systemplugin.multimedia.audio = {
1081    AudioVolumeType: {
1082      RINGTONE: 2,
1083      MEDIA: 3,
1084    },
1085    ContentType: {
1086      CONTENT_TYPE_UNKNOWN: 0,
1087      CONTENT_TYPE_SPEECH: 1,
1088      CONTENT_TYPE_MUSIC: 2,
1089      CONTENT_TYPE_MOVIE: 3,
1090      CONTENT_TYPE_SONIFICATION: 4,
1091    },
1092    StreamUsage: {
1093      STREAM_USAGE_UNKNOWN: 0,
1094      STREAM_USAGE_MEDIA: 1,
1095      STREAM_USAGE_VOICE_COMMUNICATION: 2,
1096      STREAM_USAGE_NOTIFICATION_RINGTONE: 6,
1097    },
1098    DeviceFlag: {
1099      OUTPUT_DEVICES_FLAG: 1,
1100      INPUT_DEVICES_FLAG: 2,
1101      ALL_DEVICES_FLAG: 3,
1102    },
1103    ActiveDeviceType: {
1104      SPEAKER: 2,
1105      BLUETOOTH_SCO: 7,
1106    },
1107    AudioRingMode: {
1108      RINGER_MODE_NORMAL: 2,
1109      RINGER_MODE_SILENT: 0,
1110      RINGER_MODE_VIBRATE: 1,
1111    },
1112    getAudioManager: function () {
1113      console.warn("multimedia.media.getAudioManager interface mocked in the Previewer. How this interface works" +
1114        " on the Previewer may be different from that on a real device.")
1115      return audioManagerMock;
1116    }
1117  }
1118}
1119