• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ACCOUNT_STORAGE_DIR "/data/service/el1/public/deviceauthMock/account"
24 
25 static bool g_isClient = true;
26 static char *g_clientDevUdid = "5420459D93FE773F9945FD64277FBA2CAB8FB996DDC1D0B97676FBB1242B3930";
27 static char *g_serverDevUdid = "52E2706717D5C39D736E134CC1E3BE1BAA2AA52DB7C76A37C749558BD2E6492C";
28 
SetDeviceStatus(bool isClient)29 void SetDeviceStatus(bool isClient)
30 {
31     g_isClient = isClient;
32 }
33 
HcGetUdid(uint8_t * udid,int32_t udidLen)34 int32_t HcGetUdid(uint8_t *udid, int32_t udidLen)
35 {
36     if (udid == NULL || udidLen < INPUT_UDID_LEN || udidLen > MAX_INPUT_UDID_LEN) {
37         return HAL_ERR_INVALID_PARAM;
38     }
39     char *devUdid;
40     if (g_isClient) {
41         devUdid = g_clientDevUdid;
42         LOGI("Use mock client device udid.");
43     } else {
44         devUdid = g_serverDevUdid;
45         LOGI("Use mock server device udid.");
46     }
47     if (memcpy_s(udid, udidLen, devUdid, INPUT_UDID_LEN) != EOK) {
48         LOGE("Failed to copy udid!");
49         return HAL_FAILED;
50     }
51     return HAL_SUCCESS;
52 }
53 
GetStoragePath(void)54 const char *GetStoragePath(void)
55 {
56     return MOCK_STORAGE_FILE;
57 }
58 
GetStorageDirPath(void)59 const char *GetStorageDirPath(void)
60 {
61     return MOCK_STORAGE_DIR;
62 }
63 
GetAccountStoragePath(void)64 const char *GetAccountStoragePath(void)
65 {
66     return MOCK_ACCOUNT_STORAGE_DIR;
67 }
68