1/* 2 * Copyright (c) 2023 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 { Log } from './Log' 17import hiSysEvent from '@ohos.hiSysEvent' 18 19export default class ReportUtil { 20 static readonly OPEN_FAIL = { 21 domain: "CAMERA_APP", 22 name: "CAMERA_FAULT", 23 eventType: hiSysEvent.EventType.FAULT, 24 params: { 25 FAULT_ID: "OPEN_FAIL", 26 MSG: "Failed to open camera" 27 } 28 } 29 static readonly CAMERA_ERROR = { 30 domain: "CAMERA_APP", 31 name: "CAMERA_FAULT", 32 eventType: hiSysEvent.EventType.FAULT, 33 params: { 34 FAULT_ID: "CAMERA_ERROR", 35 MSG: "Error in camera operation" 36 } 37 } 38 static readonly CAPTURE_FAIL = { 39 domain: "CAMERA_APP", 40 name: "CAMERA_FAULT", 41 eventType: hiSysEvent.EventType.FAULT, 42 params: { 43 FAULT_ID: "CAPTURE_FAIL", 44 MSG: "Abnormal photographing" 45 } 46 } 47 static readonly SAVE_FAIL = { 48 domain: "CAMERA_APP", 49 name: "CAMERA_FAULT", 50 eventType: hiSysEvent.EventType.FAULT, 51 params: { 52 FAULT_ID: "SAVE_FAIL", 53 MSG: "Abnormal media drop" 54 } 55 } 56 static readonly SWITCH_TIMEOUT = { 57 domain: "CAMERA_APP", 58 name: "CAMERA_FAULT", 59 eventType: hiSysEvent.EventType.FAULT, 60 params: { 61 FAULT_ID: "SWITCH_TIMEOUT", 62 MSG: "Switch camera timeout" 63 } 64 } 65 static readonly START_RECORD_TIMEOUT = { 66 domain: "CAMERA_APP", 67 name: "CAMERA_FAULT", 68 eventType: hiSysEvent.EventType.FAULT, 69 params: { 70 FAULT_ID: "RECORD_TIMEOUT", 71 MSG: "Recording start timeout" 72 } 73 } 74 static readonly FINISH_RECORD_TIMEOUT = { 75 domain: "CAMERA_APP", 76 name: "CAMERA_FAULT", 77 eventType: hiSysEvent.EventType.FAULT, 78 params: { 79 FAULT_ID: "RECORD_TIMEOUT", 80 MSG: "Recording stop timeout" 81 } 82 } 83 static readonly START_TIMEOUT = { 84 domain: "CAMERA_APP", 85 name: "CAMERA_FAULT", 86 eventType: hiSysEvent.EventType.FAULT, 87 params: { 88 FAULT_ID: "START_TIMEOUT", 89 MSG: "Startup timeout" 90 } 91 } 92 static readonly CAPTURE_TIMEOUT = { 93 domain: "CAMERA_APP", 94 name: "CAMERA_FAULT", 95 eventType: hiSysEvent.EventType.FAULT, 96 params: { 97 FAULT_ID: "CAPTURE_TIMEOUT", 98 MSG: "Photo taking timeout" 99 } 100 } 101 102 static readonly CAPTURE = { 103 domain: "CAMERA_APP", 104 name: "CAMERA_BEHAVIOR", 105 eventType: hiSysEvent.EventType.BEHAVIOR, 106 params: { 107 BEHAVIOR_ID: "CAPTURE", 108 MSG: "take a picture" 109 } 110 } 111 static readonly VIDEO_RECORD = { 112 domain: "CAMERA_APP", 113 name: "CAMERA_BEHAVIOR", 114 eventType: hiSysEvent.EventType.BEHAVIOR, 115 params: { 116 BEHAVIOR_ID: "VIDEO_RECORD", 117 MSG: "recording" 118 } 119 } 120 static readonly STOP_RECORD = { 121 domain: "CAMERA_APP", 122 name: "CAMERA_BEHAVIOR", 123 eventType: hiSysEvent.EventType.BEHAVIOR, 124 params: { 125 BEHAVIOR_ID: "STOP_RECORD", 126 MSG: "Stop recording" 127 } 128 } 129 static readonly SWITCH_MODE = { 130 domain: "CAMERA_APP", 131 name: "CAMERA_BEHAVIOR", 132 eventType: hiSysEvent.EventType.BEHAVIOR, 133 params: { 134 BEHAVIOR_ID: "SWITCH_MODE", 135 MSG: "Switch mode" 136 } 137 } 138 static readonly SWITCH_CAMERA = { 139 domain: "CAMERA_APP", 140 name: "CAMERA_BEHAVIOR", 141 eventType: hiSysEvent.EventType.BEHAVIOR, 142 params: { 143 BEHAVIOR_ID: "SWITCH_CAMERA", 144 MSG: "Switch camera" 145 } 146 } 147 static readonly CLICK_THUMBNAIL = { 148 domain: "CAMERA_APP", 149 name: "CAMERA_BEHAVIOR", 150 eventType: hiSysEvent.EventType.BEHAVIOR, 151 params: { 152 BEHAVIOR_ID: "CLICK_THUMBNAIL", 153 MSG: "Click thumbnail" 154 } 155 } 156 static readonly CLICK_SETTINGS = { 157 domain: "CAMERA_APP", 158 name: "CAMERA_BEHAVIOR", 159 eventType: hiSysEvent.EventType.BEHAVIOR, 160 params: { 161 BEHAVIOR_ID: "CLICK_SETTINGS", 162 MSG: "Enter Settings" 163 } 164 } 165 166 static write(event: any) { 167 if (event) { 168 hiSysEvent.write(event, (err, val) => { 169 if (err) { 170 Log.error(`fail to return hiSysEvent.`) 171 return; 172 } 173 }) 174 } 175 } 176 177 static writeFaultLog(error) { 178 const sysEventInfo = { 179 domain: "CAMERA_APP", 180 name: "CAMERA_FAULT", 181 eventType: hiSysEvent.EventType.FAULT, 182 params: { 183 FAULT_ID: error?.code, 184 MSG: error?.message 185 } 186 } 187 hiSysEvent.write(sysEventInfo, (err, val) => { 188 if (err) { 189 Log.error(`fail to return hiSysEvent.`) 190 return; 191 } 192 }) 193 } 194}