1 /*
2 * Copyright (C) 2023 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 "dev_info_mock.h"
17 #include "hal_error.h"
18 #include "hc_log.h"
19 #include "securec.h"
20
21 #define MOCK_STORAGE_FILE "/data/service/el1/public/deviceauthMock/hcgroup.dat"
22 #define MOCK_STORAGE_DIR "/data/service/el1/public/deviceauthMock"
23 #define MOCK_STORAGE_DIR_CE "/data/service/el1/public/deviceauthMock/ce"
24 #define MOCK_ACCOUNT_STORAGE_DIR "/data/service/el1/public/deviceauthMock/account"
25
26 static bool g_isClient = true;
27 static char *g_clientDevUdid = "5420459D93FE773F9945FD64277FBA2CAB8FB996DDC1D0B97676FBB1242B3930";
28 static char *g_serverDevUdid = "52E2706717D5C39D736E134CC1E3BE1BAA2AA52DB7C76A37C749558BD2E6492C";
29
SetDeviceStatus(bool isClient)30 void SetDeviceStatus(bool isClient)
31 {
32 g_isClient = isClient;
33 }
34
HcGetUdid(uint8_t * udid,int32_t udidLen)35 int32_t HcGetUdid(uint8_t *udid, int32_t udidLen)
36 {
37 if (udid == NULL || udidLen < INPUT_UDID_LEN || udidLen > MAX_INPUT_UDID_LEN) {
38 return HAL_ERR_INVALID_PARAM;
39 }
40 char *devUdid;
41 if (g_isClient) {
42 devUdid = g_clientDevUdid;
43 LOGI("Use mock client device udid.");
44 } else {
45 devUdid = g_serverDevUdid;
46 LOGI("Use mock server device udid.");
47 }
48 if (memcpy_s(udid, udidLen, devUdid, INPUT_UDID_LEN) != EOK) {
49 LOGE("Failed to copy udid!");
50 return HAL_FAILED;
51 }
52 return HAL_SUCCESS;
53 }
54
GetStoragePath(void)55 const char *GetStoragePath(void)
56 {
57 return MOCK_STORAGE_FILE;
58 }
59
GetStorageDirPathCe(void)60 const char *GetStorageDirPathCe(void)
61 {
62 return MOCK_STORAGE_DIR_CE;
63 }
64
GetStorageDirPath(void)65 const char *GetStorageDirPath(void)
66 {
67 return MOCK_STORAGE_DIR;
68 }
69
GetAccountStoragePath(void)70 const char *GetAccountStoragePath(void)
71 {
72 return MOCK_ACCOUNT_STORAGE_DIR;
73 }
74