• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "softbus_adapter_hiview.h"
17 
18 #include <cstdlib>
19 #include "hiview.h"
20 #include "parameter.h"
21 #include "securec.h"
22 #include "softbus_adapter_log.h"
23 #include "softbus_adapter_mem.h"
24 
25 #define PROP_USER_TYPE "ro.logsystem.usertype"
26 #define PROP_USER_TYPE_VALUE_LEN 8
27 #define PROP_USER_TYPE_CHANA_BETA 3
28 
SoftBusGetLogSysType(void)29 SoftBusLogSysType SoftBusGetLogSysType(void)
30 {
31     static SoftBusLogSysType userType = SOFTBUS_LOG_SYS_UNKNOWN;
32     static bool isUserTypeObtained = false;
33 
34     if (isUserTypeObtained) {
35         return userType;
36     }
37 
38     char value[PROP_USER_TYPE_VALUE_LEN] = {0};
39     int32_t ret = GetParameter(PROP_USER_TYPE, "", value, sizeof(value));
40     if (ret < 0) {
41         HILOG_ERROR(SOFTBUS_HILOG_ID, "GetProp: [%{public}s] fail(ret=%{public}d)", PROP_USER_TYPE, ret);
42         return SOFTBUS_LOG_SYS_UNKNOWN;
43     }
44     isUserTypeObtained = true;
45     HILOG_INFO(SOFTBUS_HILOG_ID, "GetProp: [%{public}s]: [%{public}s]", PROP_USER_TYPE, value);
46 
47     // is beta or not: 1 china release, 3 china beta, 5 oversea beta, 6 oversea release
48     if (atoi(value) == PROP_USER_TYPE_CHANA_BETA) {
49         userType = SOFTBUS_LOG_SYS_BETA;
50         return userType;
51     }
52     userType = SOFTBUS_LOG_SYS_RELEASE;
53     return userType;
54 }
55 
SoftBusGenHiviewHash(const char * deviceId,char * buf,uint32_t size)56 void SoftBusGenHiviewHash(const char *deviceId, char *buf, uint32_t size)
57 {
58     if (deviceId == nullptr || buf == NULL || size < HiView::DEFAULT_TRUNCATED_LENGTH) {
59         HILOG_ERROR(SOFTBUS_HILOG_ID, "HiView::genTruncatedHash invalid param");
60         return;
61     }
62     std::string input(deviceId);
63     std::string hash = HiView::GenTruncatedHash(input, HiView::ALGORITHM_SHA_256, HiView::DEFAULT_TRUNCATED_LENGTH);
64     if (hash.empty()) {
65         HILOG_ERROR(SOFTBUS_HILOG_ID, "HiView::genTruncatedHash return empty hash");
66         return;
67     }
68     if (strcpy_s(buf, size, hash.c_str()) != EOK) {
69         HILOG_ERROR(SOFTBUS_HILOG_ID, "HiView::genTruncatedHash strcpy_s fail");
70         return;
71     }
72 }