• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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 { BigDataConstants, ReportToBigDataUtil } from '../../common/ReportToBigDataUtil';
17import DecryptContent from '../data/DecryptContent';
18import { BusinessError } from '@kit.BasicServicesKit';
19import { anonymizeUid, getBundleNameInfo, getCostTime } from '../../common/FileUtils/utils';
20import AppStorageConstant from '../../common/AppStorageConstant';
21
22const TAG: string = 'DlpFileOpenReport';
23
24export class DlpFileOpenReport {
25  private static getCommonMsg(code: number, decryptContent: DecryptContent):
26    Record<string, number | string | boolean> {
27    const msg: Record<string, number | string | boolean> = {
28      'ACCOUNT_TYPE': decryptContent.fileMetaInfo?.accountType ?? -1,
29      'FILE_SIZE': decryptContent.fileMetaInfo?.fileSize ?? -1,
30      'REAL_FILE_TYPE': decryptContent.fileMetaInfo?.fileType ?? '',
31      'RECV_USER_ID': decryptContent.dlpFile?.dlpProperty?.authUserList?.[0]?.authAccount ?
32        anonymizeUid(decryptContent.dlpFile.dlpProperty.authUserList[0].authAccount) ?? -1 : -1,
33      'ACCOUNT_STATUS': AppStorage.get('hiAccountStatus') ?? -1,
34      'PACK_METHOD': -1,
35      'OPERATION_COST': '',
36      'DECRYPTION_COST': getCostTime(AppStorage.get(AppStorageConstant.DECRYPTION_START_TIME)) ?? 0,
37      'FVERSIONID': 0,
38      'OPEN_FILE_FIRST_TIME': false,
39      'CODE': code,
40      'USER_ID': decryptContent.userId ?? -1,
41      'SANDBOX_PKGNAME': getBundleNameInfo(
42        decryptContent.openDlpFileData?.callerBundleName ?? '',
43        decryptContent.openDlpFileData?.sandboxBundleName ?? ''
44      ),
45      'SANDBOX_INDEX': decryptContent.appInfo?.appIndex ?? -1,
46    };
47    return msg;
48  }
49
50  public static reportDlpFileOpenSuccess(code: number, decryptContent: DecryptContent) {
51    const msg: Record<string, number | string | boolean> = DlpFileOpenReport.getCommonMsg(code, decryptContent);
52    ReportToBigDataUtil.report(BigDataConstants.DLP_FILE_OPEN_EVENT, msg);
53  }
54
55  public static sendDlpFileOpenFault(code: number, decryptContent: DecryptContent, busErr?: BusinessError) {
56    let msg: Record<string, number | string | boolean> = DlpFileOpenReport.getCommonMsg(code, decryptContent);
57    msg['REASON'] = busErr ? `errcode is ${busErr.code}, message is ${busErr.message}, data is ${busErr.data}` : '';
58    ReportToBigDataUtil.report(BigDataConstants.DLP_FILE_OPEN_EVENT, msg);
59  }
60}