1// @ts-nocheck 2/* 3 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import {Log} from "./Log"; 18import hiSysEvent from '@ohos.hiSysEvent' 19 20const TAG = 'SystemFaultLogger'; 21const APP_DOMAIN: string = "SYSTEMUI_APP"; 22const APP_LOG_NAME: string = "SCREENLOCK_FAULT"; 23 24interface LogParam { 25 FAULT_ID: string, 26 MSG: string 27} 28 29export enum FaultID { 30 MEMORY = "MEMORY_MONITOR", 31 SCREEN_LOCK_MANAGER = "CONNECT_SCREENLOCKMANAGERSERVICE_ABNORMAL", 32 ACCOUNT_SYSTEM = "ACCOUNTSYSTEM_CALL_ABNORMAL" 33} 34 35export function WriteFaultLog(logParam: LogParam) { 36 const sysEventInfo = { 37 domain: APP_DOMAIN, 38 name: APP_LOG_NAME, 39 eventType: hiSysEvent.EventType.FAULT, 40 params: logParam 41 } 42 hiSysEvent.write(sysEventInfo, (err, val) => { 43 Log.showInfo(TAG, "fault log params is : " + JSON.stringify(sysEventInfo)) 44 Log.showInfo(TAG, `write fault log result: ${val}`) 45 }) 46} 47 48export function SysFaultLogger(logParam: LogParam) { 49 return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) { 50 const originalFunc = descriptor.value; 51 descriptor.value = function(...args) { 52 try { 53 originalFunc.apply(this, args); 54 } catch (err: any) { 55 Log.showInfo(TAG, "catch error in execute: " + propertyKey); 56 WriteFaultLog(logParam); 57 } 58 }; 59 }; 60}