• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 <cstring>
17 
18 #include "parameter.h"
19 #include "securec.h"
20 #include <string>
21 
22 namespace OHOS {
23 namespace {
24 const char *DEVICE_TYPE_OF_PHONE = "phone";
25 const char *DEVICE_TYPE_OF_DEFAULT = "default";
26 const char *EMPTY_STRING = "";
27 const int DEFAULT_SDK_API = 9999;
28 const int32_t MAX_LEN = 40;
29 
30 char g_mockParam[MAX_LEN];
31 int g_mockRet = 0;
32 } // namespace
33 
34 char *g_testDeviceType = const_cast<char *>(EMPTY_STRING);
35 
GetDeviceType()36 char *GetDeviceType()
37 {
38     if (strcmp(g_testDeviceType, DEVICE_TYPE_OF_PHONE) == 0) {
39         return const_cast<char *>(DEVICE_TYPE_OF_PHONE);
40     }
41     if (strcmp(g_testDeviceType, DEVICE_TYPE_OF_DEFAULT) == 0) {
42         return const_cast<char *>(DEVICE_TYPE_OF_DEFAULT);
43     }
44 
45     return const_cast<char *>(EMPTY_STRING);
46 }
47 
GetSdkApiVersion()48 int GetSdkApiVersion()
49 {
50     return DEFAULT_SDK_API;
51 }
52 
GetParameter(const char * key,const char * def,char * value,int len)53 int GetParameter(const char *key, const char *def, char *value, int len)
54 {
55     if ((key != nullptr) && (value != nullptr) &&
56         (std::strcmp(key, "persist.bms.supportCompressNativeLibs") == 0)) {
57         char tmp[MAX_LEN] = "true";
58         if (strcpy_s(value, len, tmp) == 0) {
59             return 1;
60         }
61     }
62     if ((key != nullptr) && (value != nullptr) && strcpy_s(value, len, g_mockParam) == 0) {
63         return g_mockRet;
64     }
65     return g_mockRet;
66 }
67 
GetIntParameter(const char * key,int def)68 int GetIntParameter(const char *key, int def)
69 {
70     return def;
71 }
72 
GetAbiList(void)73 const char *GetAbiList(void)
74 {
75     return "arm64-v8a";
76 }
77 
SetParameter(const char * key,const char * value)78 int SetParameter(const char *key, const char *value)
79 {
80     return 0;
81 }
82 
GetDevUdid(char * udid,int size)83 int GetDevUdid(char *udid, int size)
84 {
85     return 0;
86 }
87 
SetBMSMockParameter(const char * param,int ret)88 void SetBMSMockParameter(const char *param, int ret)
89 {
90     g_mockRet = ret;
91     if (strcpy_s(g_mockParam, sizeof(g_mockParam), param) == 0) {
92         return;
93     }
94 }
95 } // OHOS