19b256929Sopenharmony_ci// @ts-nocheck
29b256929Sopenharmony_ci/*
39b256929Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
49b256929Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
59b256929Sopenharmony_ci * you may not use this file except in compliance with the License.
69b256929Sopenharmony_ci * You may obtain a copy of the License at
79b256929Sopenharmony_ci *
89b256929Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
99b256929Sopenharmony_ci *
109b256929Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
119b256929Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
129b256929Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139b256929Sopenharmony_ci * See the License for the specific language governing permissions and
149b256929Sopenharmony_ci * limitations under the License.
159b256929Sopenharmony_ci */
169b256929Sopenharmony_ci
179b256929Sopenharmony_ciimport {Log} from "./Log";
189b256929Sopenharmony_ciimport hiSysEvent from '@ohos.hiSysEvent'
199b256929Sopenharmony_ci
209b256929Sopenharmony_ciconst TAG = 'SystemFaultLogger';
219b256929Sopenharmony_ciconst APP_DOMAIN: string = "SYSTEMUI_APP";
229b256929Sopenharmony_ciconst APP_LOG_NAME: string = "SCREENLOCK_FAULT";
239b256929Sopenharmony_ci
249b256929Sopenharmony_ciinterface LogParam {
259b256929Sopenharmony_ci  FAULT_ID: string,
269b256929Sopenharmony_ci  MSG: string
279b256929Sopenharmony_ci}
289b256929Sopenharmony_ci
299b256929Sopenharmony_ciexport enum FaultID {
309b256929Sopenharmony_ci  MEMORY = "MEMORY_MONITOR",
319b256929Sopenharmony_ci  SCREEN_LOCK_MANAGER = "CONNECT_SCREENLOCKMANAGERSERVICE_ABNORMAL",
329b256929Sopenharmony_ci  ACCOUNT_SYSTEM = "ACCOUNTSYSTEM_CALL_ABNORMAL"
339b256929Sopenharmony_ci}
349b256929Sopenharmony_ci
359b256929Sopenharmony_ciexport function WriteFaultLog(logParam: LogParam) {
369b256929Sopenharmony_ci  const sysEventInfo = {
379b256929Sopenharmony_ci    domain: APP_DOMAIN,
389b256929Sopenharmony_ci    name: APP_LOG_NAME,
399b256929Sopenharmony_ci    eventType: hiSysEvent.EventType.FAULT,
409b256929Sopenharmony_ci    params: logParam
419b256929Sopenharmony_ci  }
429b256929Sopenharmony_ci  hiSysEvent.write(sysEventInfo, (err, val) => {
439b256929Sopenharmony_ci    Log.showInfo(TAG, "fault log params is : " + JSON.stringify(sysEventInfo))
449b256929Sopenharmony_ci    Log.showInfo(TAG, `write fault log result: ${val}`)
459b256929Sopenharmony_ci  })
469b256929Sopenharmony_ci}
479b256929Sopenharmony_ci
489b256929Sopenharmony_ciexport function SysFaultLogger(logParam: LogParam) {
499b256929Sopenharmony_ci  return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
509b256929Sopenharmony_ci    const originalFunc = descriptor.value;
519b256929Sopenharmony_ci    descriptor.value = function(...args) {
529b256929Sopenharmony_ci      try {
539b256929Sopenharmony_ci        originalFunc.apply(this, args);
549b256929Sopenharmony_ci      }  catch (err: any) {
559b256929Sopenharmony_ci        Log.showInfo(TAG, "catch error in execute: " + propertyKey);
569b256929Sopenharmony_ci        WriteFaultLog(logParam);
579b256929Sopenharmony_ci      }
589b256929Sopenharmony_ci    };
599b256929Sopenharmony_ci  };
609b256929Sopenharmony_ci}