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 BEGET_LOGI("AclGetDevUdid %s", udid);
46 return ret;
47 }
48
AclGetSerial(void)49 const char *AclGetSerial(void)
50 {
51 static char serialNumber[MAX_SERIAL_LEN] = {"1234567890"};
52 #ifdef PARAM_FEATURE_DEVICEINFO
53 std::string result = {};
54 OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance();
55 int ret = instance.GetSerialID(result);
56 if (ret == 0) {
57 ret = strcpy_s(serialNumber, sizeof(serialNumber), result.c_str());
58 BEGET_ERROR_CHECK(ret == 0, return nullptr, "Failed to copy");
59 }
60 #else
61 const char *tmpSerial = GetSerial_();
62 if (tmpSerial != nullptr) {
63 int ret = strcpy_s(serialNumber, sizeof(serialNumber), tmpSerial);
64 BEGET_ERROR_CHECK(ret == 0, return nullptr, "Failed to copy");
65 }
66 #endif
67 BEGET_LOGI("AclGetSerial %s", serialNumber);
68 return serialNumber;
69 }
70
71 #ifdef __cplusplus
72 #if __cplusplus
73 }
74 #endif
75 #endif /* __cplusplus */