1 /*
2 * Copyright (c) 2020 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 <string>
17 #include <new>
18 #include "global.h"
19 #include "nativeapi_common.h"
20 #include "nativeapi_config.h"
21 #include "parameter.h"
22 #include "sysversion.h"
23
24 static constexpr int MAX_BUFFER = 65;
25 namespace OHOS {
26 namespace ACELite {
JSGetDeviceType(void)27 JSIValue JSGetDeviceType(void)
28 {
29 const char *value = GetDeviceType();
30 if (value == nullptr) {
31 value = "";
32 }
33
34 JSIValue deviceType = JSI::CreateString(value);
35 return deviceType;
36 }
37
JSGetManufacture(void)38 JSIValue JSGetManufacture(void)
39 {
40 const char *value = GetManufacture();
41 if (value == nullptr) {
42 value = "";
43 }
44
45 JSIValue manfactureName = JSI::CreateString(value);
46 return manfactureName;
47 }
48
JSGetBrand(void)49 JSIValue JSGetBrand(void)
50 {
51 const char *value = GetBrand();
52 if (value == nullptr) {
53 value = "";
54 }
55
56 JSIValue productBrand = JSI::CreateString(value);
57 return productBrand;
58 }
59
JSGetMarketName(void)60 JSIValue JSGetMarketName(void)
61 {
62 const char *value = GetMarketName();
63 if (value == nullptr) {
64 value = "";
65 }
66
67 JSIValue marketName = JSI::CreateString(value);
68 return marketName;
69 }
70
JSGetProductSeries(void)71 JSIValue JSGetProductSeries(void)
72 {
73 const char *value = GetProductSeries();
74 if (value == nullptr) {
75 value = "";
76 }
77
78 JSIValue productSeries = JSI::CreateString(value);
79 return productSeries;
80 }
81
JSGetProductModel(void)82 JSIValue JSGetProductModel(void)
83 {
84 const char *value = GetProductModel();
85 if (value == nullptr) {
86 value = "";
87 }
88
89 JSIValue productModel = JSI::CreateString(value);
90 return productModel;
91 }
92
JSGetSoftwareModel(void)93 JSIValue JSGetSoftwareModel(void)
94 {
95 const char *value = GetSoftwareModel();
96 if (value == nullptr) {
97 value = "";
98 }
99
100 JSIValue softwareModel = JSI::CreateString(value);
101 return softwareModel;
102 }
103
JSGetHardwareModel(void)104 JSIValue JSGetHardwareModel(void)
105 {
106 const char *value = GetHardwareModel();
107 if (value == nullptr) {
108 value = "";
109 }
110
111 JSIValue hardwareModel = JSI::CreateString(value);
112 return hardwareModel;
113 }
114
JSGetHardwareProfile(void)115 JSIValue JSGetHardwareProfile(void)
116 {
117 const char *value = GetHardwareProfile();
118 if (value == nullptr) {
119 value = "";
120 }
121
122 JSIValue hardwareProfile = JSI::CreateString(value);
123 return hardwareProfile;
124 }
125
JSGetSerial(void)126 JSIValue JSGetSerial(void)
127 {
128 const char *value = GetSerial();
129 if (value == nullptr) {
130 value = "";
131 }
132
133 JSIValue serialNumber = JSI::CreateString(value);
134 return serialNumber;
135 }
136
JSGetBootloaderVersion(void)137 JSIValue JSGetBootloaderVersion(void)
138 {
139 const char *value = GetBootloaderVersion();
140 if (value == nullptr) {
141 value = "";
142 }
143
144 JSIValue bootloaderVersion = JSI::CreateString(value);
145 return bootloaderVersion;
146 }
147
JSGetAbiList(void)148 JSIValue JSGetAbiList(void)
149 {
150 const char *value = GetAbiList();
151 if (value == nullptr) {
152 value = "";
153 }
154
155 JSIValue abiList = JSI::CreateString(value);
156 return abiList;
157 }
158
JSGetSecurityPatchTag(void)159 JSIValue JSGetSecurityPatchTag(void)
160 {
161 const char *value = GetSecurityPatchTag();
162 if (value == nullptr) {
163 value = "";
164 }
165
166 JSIValue securityPatchTag = JSI::CreateString(value);
167 return securityPatchTag;
168 }
169
JSGetDisplayVersion(void)170 JSIValue JSGetDisplayVersion(void)
171 {
172 const char *value = GetDisplayVersion();
173 if (value == nullptr) {
174 value = "";
175 }
176
177 JSIValue productVersion = JSI::CreateString(value);
178 return productVersion;
179 }
180
JSGetIncrementalVersion(void)181 JSIValue JSGetIncrementalVersion(void)
182 {
183 const char *value = GetIncrementalVersion();
184 if (value == nullptr) {
185 value = "";
186 }
187
188 JSIValue incrementalVersion = JSI::CreateString(value);
189 return incrementalVersion;
190 }
191
JSGetOsReleaseType(void)192 JSIValue JSGetOsReleaseType(void)
193 {
194 const char *value = GetOsReleaseType();
195 if (value == nullptr) {
196 value = "";
197 }
198
199 JSIValue osReleaseType = JSI::CreateString(value);
200 return osReleaseType;
201 }
202
JSGetOSFullName(void)203 JSIValue JSGetOSFullName(void)
204 {
205 const char *value = GetOSFullName();
206 if (value == nullptr) {
207 value = "";
208 }
209 JSIValue osVersion = JSI::CreateString(value);
210 return osVersion;
211 }
212
JSGetMajorVersion(void)213 JSIValue JSGetMajorVersion(void)
214 {
215 int value = GetMajorVersion();
216 JSIValue majorVersion = JSI::CreateUndefined();
217 if (value < 0) {
218 return majorVersion;
219 }
220
221 majorVersion = JSI::CreateString(std::to_string(value).c_str());
222 return majorVersion;
223 }
224
JSGetSeniorVersion(void)225 JSIValue JSGetSeniorVersion(void)
226 {
227 int value = GetSeniorVersion();
228 JSIValue seniorVersion = JSI::CreateUndefined();
229 if (value < 0) {
230 return seniorVersion;
231 }
232
233 seniorVersion = JSI::CreateString(std::to_string(value).c_str());
234 return seniorVersion;
235 }
236
JSGetFeatureVersion(void)237 JSIValue JSGetFeatureVersion(void)
238 {
239 int value = GetFeatureVersion();
240 JSIValue featureVersion = JSI::CreateUndefined();
241 if (value < 0) {
242 return featureVersion;
243 }
244
245 featureVersion = JSI::CreateString(std::to_string(value).c_str());
246 return featureVersion;
247 }
248
JSGetBuildVersion(void)249 JSIValue JSGetBuildVersion(void)
250 {
251 int value = GetBuildVersion();
252 JSIValue buildVersion = JSI::CreateUndefined();
253 if (value < 0) {
254 return buildVersion;
255 }
256
257 buildVersion = JSI::CreateString(std::to_string(value).c_str());
258 return buildVersion;
259 }
260
JSGetSdkApiVersion(void)261 JSIValue JSGetSdkApiVersion(void)
262 {
263 int value = GetSdkApiVersion();
264 JSIValue sdkApiVersion = JSI::CreateUndefined();
265 if (value < 0) {
266 return sdkApiVersion;
267 }
268
269 sdkApiVersion = JSI::CreateString(std::to_string(value).c_str());
270 return sdkApiVersion;
271 }
272
JSGetFirstApiVersion(void)273 JSIValue JSGetFirstApiVersion(void)
274 {
275 int value = GetFirstApiVersion();
276 JSIValue firstApiVersion = JSI::CreateUndefined();
277 if (value < 0) {
278 return firstApiVersion;
279 }
280
281 firstApiVersion = JSI::CreateString(std::to_string(value).c_str());
282 return firstApiVersion;
283 }
284
JSGetVersionId(void)285 JSIValue JSGetVersionId(void)
286 {
287 const char *value = GetVersionId();
288 if (value == nullptr) {
289 value = "";
290 }
291
292 JSIValue versionId = JSI::CreateString(value);
293 return versionId;
294 }
295
JSGetBuildType(void)296 JSIValue JSGetBuildType(void)
297 {
298 const char *value = GetBuildType();
299 if (value == nullptr) {
300 value = "";
301 }
302
303 JSIValue buildType = JSI::CreateString(value);
304 return buildType;
305 }
306
JSGetBuildUser(void)307 JSIValue JSGetBuildUser(void)
308 {
309 const char *value = GetBuildUser();
310 if (value == nullptr) {
311 value = "";
312 }
313
314 JSIValue buildUser = JSI::CreateString(value);
315 return buildUser;
316 }
317
JSGetBuildHost(void)318 JSIValue JSGetBuildHost(void)
319 {
320 const char *value = GetBuildHost();
321 if (value == nullptr) {
322 value = "";
323 }
324
325 JSIValue buildHost = JSI::CreateString(value);
326 return buildHost;
327 }
328
JSGetBuildTime(void)329 JSIValue JSGetBuildTime(void)
330 {
331 const char *value = GetBuildTime();
332 if (value == nullptr) {
333 value = "";
334 }
335
336 JSIValue buildTime = JSI::CreateString(value);
337 return buildTime;
338 }
339
JSGetBuildRootHash(void)340 JSIValue JSGetBuildRootHash(void)
341 {
342 const char *value = GetBuildRootHash();
343 if (value == nullptr) {
344 value = "";
345 }
346
347 JSIValue buildRootHash = JSI::CreateString(value);
348 return buildRootHash;
349 }
350
JSGetDevUdid(void)351 JSIValue JSGetDevUdid(void)
352 {
353 char buffer[MAX_BUFFER] = { 0 };
354 int value = GetDevUdid(buffer, sizeof(buffer));
355 JSIValue udid = JSI::CreateUndefined();
356 if (value < 0) {
357 return udid;
358 }
359
360 udid = JSI::CreateString(std::to_string(value).c_str());
361 return udid;
362 }
363
JSGetDistributionOSName(void)364 JSIValue JSGetDistributionOSName(void)
365 {
366 const char *value = GetDistributionOSName();
367 if (value == nullptr) {
368 value = "";
369 }
370 JSIValue distributionOSName = JSI::CreateString(value);
371 return distributionOSName;
372 }
373
JSGetDistributionOSVersion(void)374 JSIValue JSGetDistributionOSVersion(void)
375 {
376 const char *value = GetDistributionOSVersion();
377 if (value == nullptr) {
378 value = "";
379 }
380 JSIValue distributionOSVersion = JSI::CreateString(value);
381 return distributionOSVersion;
382 }
383
JSGetDistributionOSApiVersion(void)384 JSIValue JSGetDistributionOSApiVersion(void)
385 {
386 int value = GetDistributionOSApiVersion();
387 JSIValue distributionOSApiVersion = JSI::CreateUndefined();
388 if (value < 0) {
389 return distributionOSApiVersion;
390 }
391
392 distributionOSApiVersion = JSI::CreateString(std::to_string(value).c_str());
393 return distributionOSApiVersion;
394 }
395
JSGetDistributionOSReleaseType(void)396 JSIValue JSGetDistributionOSReleaseType(void)
397 {
398 const char *value = GetDistributionOSReleaseType();
399 if (value == nullptr) {
400 value = "";
401 }
402 JSIValue distributionOSReleaseType = JSI::CreateString(value);
403 return distributionOSReleaseType;
404 }
405
InitDeviceInfoModule(JSIValue exports)406 void InitDeviceInfoModule(JSIValue exports)
407 {
408 JSI::SetNamedProperty(exports, "deviceType", JSGetDeviceType());
409 JSI::SetNamedProperty(exports, "manufacture", JSGetManufacture());
410 JSI::SetNamedProperty(exports, "brand", JSGetBrand());
411 JSI::SetNamedProperty(exports, "marketName", JSGetMarketName());
412 JSI::SetNamedProperty(exports, "productSeries", JSGetProductSeries());
413 JSI::SetNamedProperty(exports, "productModel", JSGetProductModel());
414 JSI::SetNamedProperty(exports, "softwareModel", JSGetSoftwareModel());
415 JSI::SetNamedProperty(exports, "hardwareModel", JSGetHardwareModel());
416 JSI::SetNamedProperty(exports, "hardwareProfile", JSGetHardwareProfile());
417 JSI::SetNamedProperty(exports, "serial", JSGetSerial());
418 JSI::SetNamedProperty(exports, "bootloaderVersion", JSGetBootloaderVersion());
419 JSI::SetNamedProperty(exports, "abiList", JSGetAbiList());
420 JSI::SetNamedProperty(exports, "securityPatchTag", JSGetSecurityPatchTag());
421 JSI::SetNamedProperty(exports, "displayVersion", JSGetDisplayVersion());
422 JSI::SetNamedProperty(exports, "incrementalVersion", JSGetIncrementalVersion());
423 JSI::SetNamedProperty(exports, "osReleaseType", JSGetOsReleaseType());
424 JSI::SetNamedProperty(exports, "osFullName", JSGetOSFullName());
425 JSI::SetNamedProperty(exports, "majorVersion", JSGetMajorVersion());
426 JSI::SetNamedProperty(exports, "seniorVersion", JSGetSeniorVersion());
427 JSI::SetNamedProperty(exports, "featureVersion", JSGetFeatureVersion());
428 JSI::SetNamedProperty(exports, "buildVersion", JSGetBuildVersion());
429 JSI::SetNamedProperty(exports, "sdkApiVersion", JSGetSdkApiVersion());
430 JSI::SetNamedProperty(exports, "firstApiVersion", JSGetFirstApiVersion());
431 JSI::SetNamedProperty(exports, "versionId", JSGetVersionId());
432 JSI::SetNamedProperty(exports, "buildType", JSGetBuildType());
433 JSI::SetNamedProperty(exports, "buildUser", JSGetBuildUser());
434 JSI::SetNamedProperty(exports, "buildHost", JSGetBuildHost());
435 JSI::SetNamedProperty(exports, "buildTime", JSGetBuildTime());
436 JSI::SetNamedProperty(exports, "buildRootHash", JSGetBuildRootHash());
437 JSI::SetNamedProperty(exports, "udid", JSGetDevUdid());
438 JSI::SetNamedProperty(exports, "distributionOSName", JSGetDistributionOSName());
439 JSI::SetNamedProperty(exports, "distributionOSVersion", JSGetDistributionOSVersion());
440 JSI::SetNamedProperty(exports, "distributionOSApiVersion", JSGetDistributionOSApiVersion());
441 JSI::SetNamedProperty(exports, "distributionOSReleaseType", JSGetDistributionOSReleaseType());
442 }
443 } // ACELite
444 } // OHOS
445