1 /*
2  * Copyright (c) 2021 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 #include "beget_ext.h"
16 #ifdef PARAM_FEATURE_DEVICEINFO
17 #include "device_info_kits.h"
18 #endif
19 #include "param_comm.h"
20 #include "securec.h"
21 #include "sysparam_errno.h"
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif /* __cplusplus */
28 
AclGetDevUdid(char * udid,int size)29 int AclGetDevUdid(char *udid, int size)
30 {
31     if (udid == nullptr || size < UDID_LEN) {
32         return SYSPARAM_INVALID_INPUT;
33     }
34     (void)memset_s(udid, size, 0, size);
35 #ifdef PARAM_FEATURE_DEVICEINFO
36     std::string result = {};
37     OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance();
38     int ret = instance.GetUdid(result);
39     if (ret == 0) {
40         ret = strcpy_s(udid, size, result.c_str());
41     }
42 #else
43     int ret = GetDevUdid_(udid, size);
44 #endif
45     return ret;
46 }
47 
AclGetSerial(void)48 const char *AclGetSerial(void)
49 {
50     static char serialNumber[MAX_SERIAL_LEN] = {0};
51 #ifdef PARAM_FEATURE_DEVICEINFO
52     std::string result = {};
53     OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance();
54     int ret = instance.GetSerialID(result);
55     if (ret == 0) {
56         ret = strcpy_s(serialNumber, sizeof(serialNumber), result.c_str());
57         BEGET_ERROR_CHECK(ret == 0, return nullptr, "Failed to copy");
58     }
59 #else
60     const char *tmpSerial = GetSerial_();
61     if (tmpSerial != nullptr) {
62         int ret = strcpy_s(serialNumber, sizeof(serialNumber), tmpSerial);
63         BEGET_ERROR_CHECK(ret == 0, return nullptr, "Failed to copy");
64     }
65 #endif
66     return serialNumber;
67 }
68 
69 #ifdef __cplusplus
70 #if __cplusplus
71 }
72 #endif
73 #endif /* __cplusplus */
74