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
GetStorageDirPathCe(void)72 const char *GetStorageDirPathCe(void)
73 {
74 return "/data/service/el1/public/deviceauthMock/ce";
75 }
76
GetStorageDirPath(void)77 const char *GetStorageDirPath(void)
78 {
79 #ifndef LITE_DEVICE
80 const char *storageFile = "/data/service/el1/public/deviceauthMock";
81 #else
82 const char *storageFile = "/storage/deviceauth";
83 #endif
84 LOGI("[OS]: storageDirFile: %s", storageFile);
85 return storageFile;
86 }
87
GetAccountStoragePath(void)88 const char *GetAccountStoragePath(void)
89 {
90 if (g_isAccountStorageTest) {
91 return NULL;
92 }
93 #ifndef LITE_DEVICE
94 const char *storageFile = "/data/service/el1/public/deviceauthMock/account";
95 #else
96 const char *storageFile = "/storage/deviceauth/account";
97 #endif
98 LOGI("[OS]: Account storage dir: %s", storageFile);
99 return storageFile;
100 }
101
GetPseudonymStoragePath(void)102 const char *GetPseudonymStoragePath(void)
103 {
104 #ifndef LITE_DEVICE
105 const char *storageFile = "/data/service/el1/public/deviceauth/pseudonym";
106 #else
107 const char *storageFile = "/storage/deviceauth/pseudonym";
108 #endif
109 return storageFile;
110 }
111
112 #ifdef __cplusplus
113 }
114 #endif
115