1/** 2 * Copyright (c) 2024-2024 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 hiSysEvent from '@ohos.hiSysEvent'; 17import { BusinessError } from '@ohos.base'; 18import Logger from './Logger'; 19import HiSysEventConstant from '../constants/HiSysEventConstant'; 20import GetSelfBundleInfoUtils from './GetSelfBundleInfoUtils'; 21 22const TAG = 'HiSysEventUtil'; 23 24export default class HiSysEventUtil { 25 private constructor() { 26 } 27 28 /** 29 * Access framework access application click event management 30 * 31 * @params { clickedBundleName } Click on the application package name 32 */ 33 static async reportAccessClick(clickedBundleName: string): Promise<void> { 34 Logger.info(TAG, 'reportAccessClick start.') 35 let versionName: string = await GetSelfBundleInfoUtils.getVersionName(); 36 let eventParams: Record<string, string | number> = { 37 'PNAMEID': HiSysEventConstant.BUNDLE_NAME, 38 'PVERSIONID': versionName, 39 'CLICK_ITEM': clickedBundleName, 40 }; 41 HiSysEventUtil.report(HiSysEventConstant.EVENT_DOMAIN, 42 HiSysEventConstant.ACCESS_CLICK_EVENT_NAME, hiSysEvent.EventType.BEHAVIOR, eventParams); 43 } 44 45 /** 46 * Access my location information and click on the management event 47 * @params { operation } LOCATION 48 */ 49 static async reportLocationClick(operation: string): Promise<void> { 50 Logger.info(TAG, 'reportLocationClick start.') 51 let versionName: string = await GetSelfBundleInfoUtils.getVersionName(); 52 let eventParams: Record<string, string | number> = { 53 'PNAMEID': HiSysEventConstant.BUNDLE_NAME, 54 'PVERSIONID': versionName, 55 'OPERATION': operation, 56 }; 57 HiSysEventUtil.report(HiSysEventConstant.EVENT_DOMAIN, 58 HiSysEventConstant.MAIN_PERMISSION_LIST_EVENT_NAME, hiSysEvent.EventType.BEHAVIOR, eventParams); 59 } 60 61 /** 62 * Access My Location Information Switch Click on Dotting Event 63 * @params { checkedState } Position information switch status; 1: On 0: Off 64 */ 65 static async reportLocationFlagClick(checkedState: number) { 66 let versionName: string = await GetSelfBundleInfoUtils.getVersionName(); 67 let eventParams: Record<string, string | number> = { 68 'PNAMEID': HiSysEventConstant.BUNDLE_NAME, 69 'PVERSIONID': versionName, 70 'NEW_CHECKED_STATE': checkedState, 71 }; 72 HiSysEventUtil.report(HiSysEventConstant.EVENT_DOMAIN, 73 HiSysEventConstant.PERMISSION_PAGE_LOCATION_EVENT_NAME, hiSysEvent.EventType.BEHAVIOR, eventParams); 74 } 75 76 /** 77 * Click on the interface to operate the dots 78 * 79 * @param eventName Event Name 80 * @param params parameter 81 */ 82 static async reportClick(eventName: string, params: Record<string, string | number>): Promise<void> { 83 let versionName: string = await GetSelfBundleInfoUtils.getVersionName(); 84 params['PNAMEID'] = HiSysEventConstant.BUNDLE_NAME; 85 params['PVERSIONID'] = versionName; 86 let eventParams: Record<string, string | number> = params; 87 HiSysEventUtil.report(HiSysEventConstant.EVENT_DOMAIN, eventName, hiSysEvent.EventType.BEHAVIOR, eventParams); 88 } 89 90 private static report(domain: string, name: string, eventType: hiSysEvent.EventType, params: Object): void { 91 Logger.info( 92 TAG, `start to report domain: ${domain},eventName: ${name},eventType: ${eventType}, reportData: ${params}`); 93 const sysEventInfo: hiSysEvent.SysEventInfo = { 94 domain: domain, 95 name: name, 96 eventType: eventType, 97 params: params 98 }; 99 hiSysEvent.write(sysEventInfo).then( 100 () => { 101 Logger.info(TAG, `HiSysEventUtil reportHiSysEvent ${sysEventInfo.name} success.`); 102 } 103 ).catch( 104 (err: BusinessError) => { 105 Logger.error(TAG, `error code: ${err.code}, error msg: ${err.message}`); 106 } 107 ) 108 } 109} 110