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 "hc_dev_info_mock.h"
17 #include "hal_error.h"
18 #include "hc_log.h"
19 #include "securec.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 static bool g_isClient = true;
26 static char *g_clientDevUdid = "5420459D93FE773F9945FD64277FBA2CAB8FB996DDC1D0B97676FBB1242B3930";
27 static char *g_serverDevUdid = "52E2706717D5C39D736E134CC1E3BE1BAA2AA52DB7C76A37C749558BD2E6492C";
28
29 static bool g_isAccountStorageTest = false;
30
SetDeviceStatus(bool isClient)31 void SetDeviceStatus(bool isClient)
32 {
33 g_isClient = isClient;
34 }
35
SetAccountStorageTest(bool isAccountStorageTest)36 void SetAccountStorageTest(bool isAccountStorageTest)
37 {
38 g_isAccountStorageTest = isAccountStorageTest;
39 }
40
HcGetUdid(uint8_t * udid,int32_t udidLen)41 int32_t HcGetUdid(uint8_t *udid, int32_t udidLen)
42 {
43 if (udid == NULL || udidLen < INPUT_UDID_LEN || udidLen > MAX_INPUT_UDID_LEN) {
44 return HAL_ERR_INVALID_PARAM;
45 }
46 char *devUdid;
47 if (g_isClient) {
48 devUdid = g_clientDevUdid;
49 LOGI("Use mock client device udid.");
50 } else {
51 devUdid = g_serverDevUdid;
52 LOGI("Use mock server device udid.");
53 }
54 if (memcpy_s(udid, udidLen, devUdid, INPUT_UDID_LEN) != EOK) {
55 LOGE("Failed to copy udid!");
56 return HAL_FAILED;
57 }
58 return HAL_SUCCESS;
59 }
60
GetStoragePath(void)61 const char *GetStoragePath(void)
62 {
63 #ifndef LITE_DEVICE
64 const char *storageFile = "/data/service/el1/public/deviceauthMock/hcgroup.dat";
65 #else
66 const char *storageFile = "/storage/deviceauth/hcgroup.dat";
67 #endif
68 LOGI("[OS]: storageFile: %s", storageFile);
69 return storageFile;
70 }
71
GetStorageDirPath(void)72 const char *GetStorageDirPath(void)
73 {
74 #ifndef LITE_DEVICE
75 const char *storageFile = "/data/service/el1/public/deviceauthMock";
76 #else
77 const char *storageFile = "/storage/deviceauth";
78 #endif
79 LOGI("[OS]: storageDirFile: %s", storageFile);
80 return storageFile;
81 }
82
GetAccountStoragePath(void)83 const char *GetAccountStoragePath(void)
84 {
85 if (g_isAccountStorageTest) {
86 return NULL;
87 }
88 #ifndef LITE_DEVICE
89 const char *storageFile = "/data/service/el1/public/deviceauthMock/account";
90 #else
91 const char *storageFile = "/storage/deviceauth/account";
92 #endif
93 LOGI("[OS]: Account storage dir: %s", storageFile);
94 return storageFile;
95 }
96
GetPseudonymStoragePath(void)97 const char *GetPseudonymStoragePath(void)
98 {
99 #ifndef LITE_DEVICE
100 const char *storageFile = "/data/service/el1/public/deviceauth/pseudonym";
101 #else
102 const char *storageFile = "/storage/deviceauth/pseudonym";
103 #endif
104 return storageFile;
105 }
106
107 #ifdef __cplusplus
108 }
109 #endif
110