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 18function buildMockInfo(interfaceName) { 19 return interfaceName + " interface mocked in the Previewer. How this interface works on the Previewer" + 20 " may be different from that on a real device." 21} 22 23export function mockFaultLogger() { 24 const FaultType = { 25 NO_SPECIFIC : 0, 26 CPP_CRASH : 2, 27 JS_CRASH : 3, 28 APP_FREEZE : 4 29 } 30 const FaultLogInfo = { 31 pid: "[PC Preview] unknow pid", 32 uid: "[PC Preview] unknow uid", 33 type: FaultType, 34 timestamp: "[PC Preview] unknow timestamp", 35 reason: "[PC Preview] unknow reason", 36 module: "[PC Preview] unknow module", 37 summary: "[PC Preview] unknow summary", 38 fullLog: "[PC Preview] unknow fullLog", 39 } 40 const FaultLogger = { 41 FaultType, 42 FaultLogInfo, 43 querySelfFaultLog: function(...args) { 44 console.warn(buildMockInfo("FaultLogger.querySelfFaultLog")) 45 var array = new Array() 46 array.push(FaultLogInfo) 47 const len = args.length 48 if (typeof args[len - 1] === 'function') { 49 args[len - 1].call(this, paramMock.businessErrorMock, array) 50 } else { 51 return new Promise((resolve) => { 52 resolve(array) 53 }); 54 } 55 }, 56 } 57 return FaultLogger 58}