• 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 
16 #include "nativetoken_hisysevent.h"
17 
18 #include "accesstoken_klog.h"
19 #include "hisysevent_c.h"
20 #include "securec.h"
21 
22 #define MSG_MAX_LEN 4096
23 
ReportNativeTokenExceptionEvent(int32_t sceneCode,int32_t errorCode,const char * errorMsg)24 void ReportNativeTokenExceptionEvent(int32_t sceneCode, int32_t errorCode, const char* errorMsg)
25 {
26     if (errorMsg == NULL || strlen(errorMsg) == 0) {
27         LOGC("Null or empty errorMsg.");
28         return;
29     }
30     char tempErrorMsg[MSG_MAX_LEN + 1] = {0};
31     if (strcpy_s(tempErrorMsg, sizeof(tempErrorMsg), errorMsg) != 0) {
32         LOGC("Failed to copy error message.");
33         return;
34     }
35     HiSysEventParam params[] = {
36         {
37             .name = "SCENE_CODE",
38             .t = HISYSEVENT_INT32,
39             .v = { .i32 = sceneCode },
40             .arraySize = 0,
41         },
42         {
43             .name = "ERROR_CODE",
44             .t = HISYSEVENT_INT32,
45             .v = { .i32 = errorCode },
46             .arraySize = 0,
47         },
48         {
49             .name = "ERROR_MSG",
50             .t = HISYSEVENT_STRING,
51             .v = { .s = tempErrorMsg },
52             .arraySize = 0,
53         },
54     };
55     OH_HiSysEvent_Write(ACCESS_TOKEND_DOMAIN, EVENT_NATIVE_TOKEN_EXCEPTION,
56         HISYSEVENT_FAULT, params, sizeof(params) / sizeof(params[0]));
57 }
58