• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 <cstdio>
17 #include <string>
18 
19 #include "napi/native_api.h"
20 #include "napi/native_node_api.h"
21 #include "napi/native_common.h"
22 #include "parameter.h"
23 #include "sysversion.h"
24 #ifdef DEPENDENT_APPEXECFWK_BASE
25 #include "bundlemgr/bundle_mgr_proxy.h"
26 #endif
27 #include "iservice_registry.h"
28 #include "if_system_ability_manager.h"
29 #include "system_ability_definition.h"
30 #include "beget_ext.h"
31 #include "init_error.h"
32 #include "securec.h"
33 
34 #ifndef DEVICEINFO_JS_DOMAIN
35 #define DEVICEINFO_JS_DOMAIN (BASE_DOMAIN + 8)
36 #endif
37 
38 #ifndef DINFO_TAG
39 #define DINFO_TAG "DEVICEINFO_JS"
40 #endif
41 
42 #define DEVINFO_LOGV(fmt, ...) STARTUP_LOGV(DEVICEINFO_JS_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__)
43 #define DEVINFO_LOGI(fmt, ...) STARTUP_LOGI(DEVICEINFO_JS_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__)
44 #define DEVINFO_LOGW(fmt, ...) STARTUP_LOGW(DEVICEINFO_JS_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__)
45 #define DEVINFO_LOGE(fmt, ...) STARTUP_LOGE(DEVICEINFO_JS_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__)
46 
47 const int UDID_LEN = 65;
48 const int ODID_LEN = 37;
49 constexpr int DISK_SN_LEN = 20;
50 
51 typedef enum {
52     DEV_INFO_OK,
53     DEV_INFO_ENULLPTR,
54     DEV_INFO_EGETODID,
55     DEV_INFO_ESTRCOPY
56 } DevInfoError;
57 
58 typedef enum {
59     CLASS_LEVEL_HIGH,
60     CLASS_LEVEL_MEDIUM,
61     CLASS_LEVEL_LOW
62 } PerformanceClassLevel;
63 
GetDeviceType(napi_env env,napi_callback_info info)64 static napi_value GetDeviceType(napi_env env, napi_callback_info info)
65 {
66     napi_value deviceType = nullptr;
67     const char *value = GetDeviceType();
68     if (value == nullptr) {
69         value = "";
70     }
71 
72     NAPI_CALL(env, napi_create_string_utf8(env, value, strlen(value), &deviceType));
73     return deviceType;
74 }
75 
GetManufacture(napi_env env,napi_callback_info info)76 static napi_value GetManufacture(napi_env env, napi_callback_info info)
77 {
78     napi_value napiValue = nullptr;
79     const char *manfactureName = GetManufacture();
80     if (manfactureName == nullptr) {
81         manfactureName = "";
82     }
83 
84     NAPI_CALL(env, napi_create_string_utf8(env, manfactureName, strlen(manfactureName), &napiValue));
85     return napiValue;
86 }
87 
GetBrand(napi_env env,napi_callback_info info)88 static napi_value GetBrand(napi_env env, napi_callback_info info)
89 {
90     napi_value napiValue = nullptr;
91     const char *productBrand = GetBrand();
92     if (productBrand == nullptr) {
93         productBrand = "";
94     }
95 
96     NAPI_CALL(env, napi_create_string_utf8(env, productBrand, strlen(productBrand), &napiValue));
97     return napiValue;
98 }
99 
GetMarketName(napi_env env,napi_callback_info info)100 static napi_value GetMarketName(napi_env env, napi_callback_info info)
101 {
102     napi_value napiValue = nullptr;
103     const char *marketName = GetMarketName();
104     if (marketName == nullptr) {
105         marketName = "";
106     }
107 
108     NAPI_CALL(env, napi_create_string_utf8(env, marketName, strlen(marketName), &napiValue));
109     return napiValue;
110 }
111 
GetProductSeries(napi_env env,napi_callback_info info)112 static napi_value GetProductSeries(napi_env env, napi_callback_info info)
113 {
114     napi_value napiValue = nullptr;
115     const char *productSeries = GetProductSeries();
116     if (productSeries == nullptr) {
117         productSeries = "";
118     }
119 
120     NAPI_CALL(env, napi_create_string_utf8(env, productSeries, strlen(productSeries), &napiValue));
121     return napiValue;
122 }
123 
GetProductModel(napi_env env,napi_callback_info info)124 static napi_value GetProductModel(napi_env env, napi_callback_info info)
125 {
126     napi_value napiValue = nullptr;
127     const char *productModel = GetProductModel();
128     if (productModel == nullptr) {
129         productModel = "";
130     }
131 
132     NAPI_CALL(env, napi_create_string_utf8(env, productModel, strlen(productModel), &napiValue));
133     return napiValue;
134 }
135 
GetProductModelAlias(napi_env env,napi_callback_info info)136 static napi_value GetProductModelAlias(napi_env env, napi_callback_info info)
137 {
138     napi_value napiValue = nullptr;
139     const char *productModel = GetProductModelAlias();
140     if (productModel == nullptr) {
141         productModel = "";
142     }
143 
144     NAPI_CALL(env, napi_create_string_utf8(env, productModel, strlen(productModel), &napiValue));
145     return napiValue;
146 }
147 
GetSoftwareModel(napi_env env,napi_callback_info info)148 static napi_value GetSoftwareModel(napi_env env, napi_callback_info info)
149 {
150     napi_value napiValue = nullptr;
151     const char *softwareModel = GetSoftwareModel();
152     if (softwareModel == nullptr) {
153         softwareModel = "";
154     }
155 
156     NAPI_CALL(env, napi_create_string_utf8(env, softwareModel, strlen(softwareModel), &napiValue));
157     return napiValue;
158 }
159 
GetHardwareModel(napi_env env,napi_callback_info info)160 static napi_value GetHardwareModel(napi_env env, napi_callback_info info)
161 {
162     napi_value napiValue = nullptr;
163     const char *hardwareModel = GetHardwareModel();
164     if (hardwareModel == nullptr) {
165         hardwareModel = "";
166     }
167 
168     NAPI_CALL(env, napi_create_string_utf8(env, hardwareModel, strlen(hardwareModel), &napiValue));
169     return napiValue;
170 }
171 
GetHardwareProfile(napi_env env,napi_callback_info info)172 static napi_value GetHardwareProfile(napi_env env, napi_callback_info info)
173 {
174     napi_value napiValue = nullptr;
175     const char *hardwareProfile = GetHardwareProfile();
176     if (hardwareProfile == nullptr) {
177         hardwareProfile = "";
178     }
179 
180     NAPI_CALL(env, napi_create_string_utf8(env, hardwareProfile, strlen(hardwareProfile), &napiValue));
181     return napiValue;
182 }
183 
GetSerial(napi_env env,napi_callback_info info)184 static napi_value GetSerial(napi_env env, napi_callback_info info)
185 {
186     napi_value napiValue = nullptr;
187     const char *serialNumber = AclGetSerial();
188     if (serialNumber == nullptr) {
189         serialNumber = "";
190     }
191 
192     NAPI_CALL(env, napi_create_string_utf8(env, serialNumber, strlen(serialNumber), &napiValue));
193     return napiValue;
194 }
195 
GetBootloaderVersion(napi_env env,napi_callback_info info)196 static napi_value GetBootloaderVersion(napi_env env, napi_callback_info info)
197 {
198     napi_value napiValue = nullptr;
199     const char *bootloaderVersion = GetBootloaderVersion();
200     if (bootloaderVersion == nullptr) {
201         bootloaderVersion = "";
202     }
203 
204     NAPI_CALL(env, napi_create_string_utf8(env, bootloaderVersion, strlen(bootloaderVersion), &napiValue));
205     return napiValue;
206 }
207 
GetAbiList(napi_env env,napi_callback_info info)208 static napi_value GetAbiList(napi_env env, napi_callback_info info)
209 {
210     napi_value napiValue = nullptr;
211     const char *abiList = GetAbiList();
212     if (abiList == nullptr) {
213         abiList = "";
214     }
215 
216     NAPI_CALL(env, napi_create_string_utf8(env, abiList, strlen(abiList), &napiValue));
217     return napiValue;
218 }
219 
GetSecurityPatchTag(napi_env env,napi_callback_info info)220 static napi_value GetSecurityPatchTag(napi_env env, napi_callback_info info)
221 {
222     napi_value napiValue = nullptr;
223     const char *securityPatchTag = GetSecurityPatchTag();
224     if (securityPatchTag == nullptr) {
225         securityPatchTag = "";
226     }
227 
228     NAPI_CALL(env, napi_create_string_utf8(env, securityPatchTag, strlen(securityPatchTag), &napiValue));
229     return napiValue;
230 }
231 
GetDisplayVersion(napi_env env,napi_callback_info info)232 static napi_value GetDisplayVersion(napi_env env, napi_callback_info info)
233 {
234     napi_value napiValue = nullptr;
235     const char *productVersion = GetDisplayVersion();
236     if (productVersion == nullptr) {
237         productVersion = "";
238     }
239 
240     NAPI_CALL(env, napi_create_string_utf8(env, productVersion, strlen(productVersion), &napiValue));
241     return napiValue;
242 }
243 
GetIncrementalVersion(napi_env env,napi_callback_info info)244 static napi_value GetIncrementalVersion(napi_env env, napi_callback_info info)
245 {
246     napi_value napiValue = nullptr;
247     const char *incrementalVersion = GetIncrementalVersion();
248     if (incrementalVersion == nullptr) {
249         incrementalVersion = "";
250     }
251 
252     NAPI_CALL(env, napi_create_string_utf8(env, incrementalVersion, strlen(incrementalVersion), &napiValue));
253     return napiValue;
254 }
255 
GetOsReleaseType(napi_env env,napi_callback_info info)256 static napi_value GetOsReleaseType(napi_env env, napi_callback_info info)
257 {
258     napi_value napiValue = nullptr;
259     const char *osReleaseType = GetOsReleaseType();
260     if (osReleaseType == nullptr) {
261         osReleaseType = "";
262     }
263 
264     NAPI_CALL(env, napi_create_string_utf8(env, osReleaseType, strlen(osReleaseType), &napiValue));
265     return napiValue;
266 }
267 
GetOSFullName(napi_env env,napi_callback_info info)268 static napi_value GetOSFullName(napi_env env, napi_callback_info info)
269 {
270     napi_value napiValue = nullptr;
271     const char *osVersion = GetOSFullName();
272     if (osVersion == nullptr) {
273         osVersion = "";
274     }
275 
276     NAPI_CALL(env, napi_create_string_utf8(env, osVersion, strlen(osVersion), &napiValue));
277     return napiValue;
278 }
279 
GetMajorVersion(napi_env env,napi_callback_info info)280 static napi_value GetMajorVersion(napi_env env, napi_callback_info info)
281 {
282     napi_value napiValue = nullptr;
283     int majorVersion = GetMajorVersion();
284 
285     NAPI_CALL(env, napi_create_int32(env, majorVersion, &napiValue));
286     return napiValue;
287 }
288 
GetSeniorVersion(napi_env env,napi_callback_info info)289 static napi_value GetSeniorVersion(napi_env env, napi_callback_info info)
290 {
291     napi_value napiValue = nullptr;
292     int seniorVersion = GetSeniorVersion();
293 
294     NAPI_CALL(env, napi_create_int32(env, seniorVersion, &napiValue));
295     return napiValue;
296 }
297 
GetFeatureVersion(napi_env env,napi_callback_info info)298 static napi_value GetFeatureVersion(napi_env env, napi_callback_info info)
299 {
300     napi_value napiValue = nullptr;
301     int featureVersion = GetFeatureVersion();
302 
303     NAPI_CALL(env, napi_create_int32(env, featureVersion, &napiValue));
304     return napiValue;
305 }
306 
GetBuildVersion(napi_env env,napi_callback_info info)307 static napi_value GetBuildVersion(napi_env env, napi_callback_info info)
308 {
309     napi_value napiValue = nullptr;
310     int buildVersion = GetBuildVersion();
311 
312     NAPI_CALL(env, napi_create_int32(env, buildVersion, &napiValue));
313     return napiValue;
314 }
315 
GetSdkApiVersion(napi_env env,napi_callback_info info)316 static napi_value GetSdkApiVersion(napi_env env, napi_callback_info info)
317 {
318     napi_value napiValue = nullptr;
319     int sdkApiVersion = GetSdkApiVersion();
320 
321     NAPI_CALL(env, napi_create_int32(env, sdkApiVersion, &napiValue));
322     return napiValue;
323 }
GetSdkMinorApiVersion(napi_env env,napi_callback_info info)324 static napi_value GetSdkMinorApiVersion(napi_env env, napi_callback_info info)
325 {
326     napi_value napiValue = nullptr;
327     int sdkMinorApiVersion = GetSdkMinorApiVersion();
328 
329     NAPI_CALL(env, napi_create_int32(env, sdkMinorApiVersion, &napiValue));
330     return napiValue;
331 }
GetSdkPatchApiVersion(napi_env env,napi_callback_info info)332 static napi_value GetSdkPatchApiVersion(napi_env env, napi_callback_info info)
333 {
334     napi_value napiValue = nullptr;
335     int sdkPatchApiVersion = GetSdkPatchApiVersion();
336 
337     NAPI_CALL(env, napi_create_int32(env, sdkPatchApiVersion, &napiValue));
338     return napiValue;
339 }
340 
GetFirstApiVersion(napi_env env,napi_callback_info info)341 static napi_value GetFirstApiVersion(napi_env env, napi_callback_info info)
342 {
343     napi_value napiValue = nullptr;
344     int firstApiVersion = GetFirstApiVersion();
345 
346     NAPI_CALL(env, napi_create_int32(env, firstApiVersion, &napiValue));
347     return napiValue;
348 }
349 
GetVersionId(napi_env env,napi_callback_info info)350 static napi_value GetVersionId(napi_env env, napi_callback_info info)
351 {
352     napi_value napiValue = nullptr;
353     const char *versionId = GetVersionId();
354     if (versionId == nullptr) {
355         versionId = "";
356     }
357 
358     NAPI_CALL(env, napi_create_string_utf8(env, versionId, strlen(versionId), &napiValue));
359     return napiValue;
360 }
361 
GetBuildType(napi_env env,napi_callback_info info)362 static napi_value GetBuildType(napi_env env, napi_callback_info info)
363 {
364     napi_value napiValue = nullptr;
365     const char *buildType = GetBuildType();
366     if (buildType == nullptr) {
367         buildType = "";
368     }
369 
370     NAPI_CALL(env, napi_create_string_utf8(env, buildType, strlen(buildType), &napiValue));
371     return napiValue;
372 }
373 
GetBuildUser(napi_env env,napi_callback_info info)374 static napi_value GetBuildUser(napi_env env, napi_callback_info info)
375 {
376     napi_value napiValue = nullptr;
377     const char *buildUser = GetBuildUser();
378     if (buildUser == nullptr) {
379         buildUser = "";
380     }
381 
382     NAPI_CALL(env, napi_create_string_utf8(env, buildUser, strlen(buildUser), &napiValue));
383     return napiValue;
384 }
385 
GetBuildHost(napi_env env,napi_callback_info info)386 static napi_value GetBuildHost(napi_env env, napi_callback_info info)
387 {
388     napi_value napiValue = nullptr;
389     const char *buildHost = GetBuildHost();
390     if (buildHost == nullptr) {
391         buildHost = "";
392     }
393 
394     NAPI_CALL(env, napi_create_string_utf8(env, buildHost, strlen(buildHost), &napiValue));
395     return napiValue;
396 }
397 
GetBuildTime(napi_env env,napi_callback_info info)398 static napi_value GetBuildTime(napi_env env, napi_callback_info info)
399 {
400     napi_value napiValue = nullptr;
401     const char *buildTime = GetBuildTime();
402     if (buildTime == nullptr) {
403         buildTime = "";
404     }
405 
406     NAPI_CALL(env, napi_create_string_utf8(env, buildTime, strlen(buildTime), &napiValue));
407     return napiValue;
408 }
409 
GetBuildRootHash(napi_env env,napi_callback_info info)410 static napi_value GetBuildRootHash(napi_env env, napi_callback_info info)
411 {
412     napi_value napiValue = nullptr;
413     const char *buildRootHash = GetBuildRootHash();
414     if (buildRootHash == nullptr) {
415         buildRootHash = "";
416     }
417 
418     NAPI_CALL(env, napi_create_string_utf8(env, buildRootHash, strlen(buildRootHash), &napiValue));
419     return napiValue;
420 }
421 
GetDevUdid(napi_env env,napi_callback_info info)422 static napi_value GetDevUdid(napi_env env, napi_callback_info info)
423 {
424     napi_value napiValue = nullptr;
425     char localDeviceId[UDID_LEN] = {0};
426     AclGetDevUdid(localDeviceId, UDID_LEN);
427 
428     NAPI_CALL(env, napi_create_string_utf8(env, localDeviceId, strlen(localDeviceId), &napiValue));
429     return napiValue;
430 }
431 
NAPI_GetDistributionOSName(napi_env env,napi_callback_info info)432 static napi_value NAPI_GetDistributionOSName(napi_env env, napi_callback_info info)
433 {
434     napi_value napiValue = nullptr;
435     const char *val = GetDistributionOSName();
436 
437     NAPI_CALL(env, napi_create_string_utf8(env, val, strlen(val), &napiValue));
438     return napiValue;
439 }
440 
NAPI_GetDistributionOSVersion(napi_env env,napi_callback_info info)441 static napi_value NAPI_GetDistributionOSVersion(napi_env env, napi_callback_info info)
442 {
443     napi_value napiValue = nullptr;
444     const char *val = GetDistributionOSVersion();
445 
446     NAPI_CALL(env, napi_create_string_utf8(env, val, strlen(val), &napiValue));
447     return napiValue;
448 }
449 
NAPI_GetDistributionOSApiVersion(napi_env env,napi_callback_info info)450 static napi_value NAPI_GetDistributionOSApiVersion(napi_env env, napi_callback_info info)
451 {
452     napi_value napiValue = nullptr;
453     int sdkApiVersion = GetDistributionOSApiVersion();
454 
455     NAPI_CALL(env, napi_create_int32(env, sdkApiVersion, &napiValue));
456     return napiValue;
457 }
458 
NAPI_GetDistributionOSApiName(napi_env env,napi_callback_info info)459 static napi_value NAPI_GetDistributionOSApiName(napi_env env, napi_callback_info info)
460 {
461     napi_value napiValue = nullptr;
462     const char *val = GetDistributionOSApiName();
463 
464     NAPI_CALL(env, napi_create_string_utf8(env, val, strlen(val), &napiValue));
465     return napiValue;
466 }
467 
NAPI_GetDistributionOSReleaseType(napi_env env,napi_callback_info info)468 static napi_value NAPI_GetDistributionOSReleaseType(napi_env env, napi_callback_info info)
469 {
470     napi_value napiValue = nullptr;
471     const char *val = GetDistributionOSReleaseType();
472 
473     NAPI_CALL(env, napi_create_string_utf8(env, val, strlen(val), &napiValue));
474     return napiValue;
475 }
476 
AclGetDevOdid(char * odid,int size)477 static DevInfoError AclGetDevOdid(char *odid, int size)
478 {
479     DevInfoError ret = DEV_INFO_OK;
480     if (odid[0] != '\0') {
481         return DEV_INFO_OK;
482     }
483     auto systemAbilityManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
484     if (!systemAbilityManager) {
485         return DEV_INFO_ENULLPTR;
486     }
487 
488     auto remoteObject = systemAbilityManager->GetSystemAbility(OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
489     if (!remoteObject) {
490         return DEV_INFO_ENULLPTR;
491     }
492 
493 #ifdef DEPENDENT_APPEXECFWK_BASE
494     auto bundleMgrProxy = OHOS::iface_cast<OHOS::AppExecFwk::BundleMgrProxy>(remoteObject);
495     if (!bundleMgrProxy) {
496         return DEV_INFO_ENULLPTR;
497     }
498 
499     std::string odidStr;
500     if (bundleMgrProxy->GetOdid(odidStr) != 0) {
501         return DEV_INFO_EGETODID;
502     }
503 
504     if (strcpy_s(odid, size, odidStr.c_str()) != EOK) {
505         return DEV_INFO_ESTRCOPY;
506     }
507 #else
508     DEVINFO_LOGE("DEPENDENT_APPEXECFWK_BASE does not exist, The ODID could not be obtained");
509     ret = DEV_INFO_EGETODID;
510 #endif
511 
512     return ret;
513 }
514 
GetDevOdid(napi_env env,napi_callback_info info)515 static napi_value GetDevOdid(napi_env env, napi_callback_info info)
516 {
517     napi_value napiValue = nullptr;
518     static char odid[ODID_LEN] = {0};
519     DevInfoError ret = AclGetDevOdid(odid, ODID_LEN);
520     if (ret != DEV_INFO_OK) {
521         DEVINFO_LOGE("GetDevOdid ret:%d", ret);
522     }
523 
524     NAPI_CALL(env, napi_create_string_utf8(env, odid, strlen(odid), &napiValue));
525     return napiValue;
526 }
527 
GetDiskSN(napi_env env,napi_callback_info info)528 static napi_value GetDiskSN(napi_env env, napi_callback_info info)
529 {
530     napi_value napiValue = nullptr;
531     static char diskSN[DISK_SN_LEN] = {0};
532     AclGetDiskSN(diskSN, DISK_SN_LEN);
533 
534     NAPI_CALL(env, napi_create_string_utf8(env, diskSN, strlen(diskSN), &napiValue));
535     return napiValue;
536 }
537 
EnumLevelClassConstructor(napi_env env,napi_callback_info info)538 static napi_value EnumLevelClassConstructor(napi_env env, napi_callback_info info)
539 {
540     napi_value thisArg = nullptr;
541     void* data = nullptr;
542 
543     napi_get_cb_info(env, info, nullptr, nullptr, &thisArg, &data);
544 
545     napi_value global = nullptr;
546     napi_get_global(env, &global);
547 
548     return thisArg;
549 }
550 
CreateEnumLevelState(napi_env env,napi_value exports)551 static napi_value CreateEnumLevelState(napi_env env, napi_value exports)
552 {
553     napi_value high = nullptr;
554     napi_value medium = nullptr;
555     napi_value low = nullptr;
556 
557     napi_create_int32(env, (int32_t)PerformanceClassLevel::CLASS_LEVEL_HIGH, &high);
558     napi_create_int32(env, (int32_t)PerformanceClassLevel::CLASS_LEVEL_MEDIUM, &medium);
559     napi_create_int32(env, (int32_t)PerformanceClassLevel::CLASS_LEVEL_LOW, &low);
560 
561     napi_property_descriptor desc[] = {
562         DECLARE_NAPI_STATIC_PROPERTY("CLASS_LEVEL_HIGH", high),
563         DECLARE_NAPI_STATIC_PROPERTY("CLASS_LEVEL_MEDIUM", medium),
564         DECLARE_NAPI_STATIC_PROPERTY("CLASS_LEVEL_LOW", low),
565     };
566 
567     napi_value result = nullptr;
568     napi_define_class(env, "PerformanceClassLevel", NAPI_AUTO_LENGTH, EnumLevelClassConstructor, nullptr,
569         sizeof(desc) / sizeof(*desc), desc, &result);
570 
571     napi_set_named_property(env, exports, "PerformanceClassLevel", result);
572 
573     return exports;
574 }
575 
GetPerformanceClass(napi_env env,napi_callback_info info)576 static napi_value GetPerformanceClass(napi_env env, napi_callback_info info)
577 {
578     napi_value napiValue = nullptr;
579     int performanceClass = GetPerformanceClass();
580 
581     NAPI_CALL(env, napi_create_int32(env, performanceClass, &napiValue));
582     return napiValue;
583 }
584 
CreateDeviceTypes(napi_env env,napi_value exports)585 static napi_value CreateDeviceTypes(napi_env env, napi_value exports)
586 {
587     napi_value deviceTypes = nullptr;
588     napi_value typeDefault = nullptr;
589     napi_value typePhone = nullptr;
590     napi_value typeTablet = nullptr;
591     napi_value type2in1 = nullptr;
592     napi_value typeTv = nullptr;
593     napi_value typeWearable = nullptr;
594     napi_value typeCar = nullptr;
595 
596     napi_create_object(env, &deviceTypes);
597 
598     napi_create_string_utf8(env, "default", NAPI_AUTO_LENGTH, &typeDefault);
599     napi_create_string_utf8(env, "phone", NAPI_AUTO_LENGTH, &typePhone);
600     napi_create_string_utf8(env, "tablet", NAPI_AUTO_LENGTH, &typeTablet);
601     napi_create_string_utf8(env, "2in1", NAPI_AUTO_LENGTH, &type2in1);
602     napi_create_string_utf8(env, "tv", NAPI_AUTO_LENGTH, &typeTv);
603     napi_create_string_utf8(env, "wearable", NAPI_AUTO_LENGTH, &typeWearable);
604     napi_create_string_utf8(env, "car", NAPI_AUTO_LENGTH, &typeCar);
605 
606     napi_set_named_property(env, deviceTypes, "TYPE_DEFAULT", typeDefault);
607     napi_set_named_property(env, deviceTypes, "TYPE_PHONE", typePhone);
608     napi_set_named_property(env, deviceTypes, "TYPE_TABLET", typeTablet);
609     napi_set_named_property(env, deviceTypes, "TYPE_2IN1", type2in1);
610     napi_set_named_property(env, deviceTypes, "TYPE_TV", typeTv);
611     napi_set_named_property(env, deviceTypes, "TYPE_WEARABLE", typeWearable);
612     napi_set_named_property(env, deviceTypes, "TYPE_CAR", typeCar);
613 
614     napi_set_named_property(env, exports, "DeviceTypes", deviceTypes);
615 
616     return exports;
617 }
618 
619 EXTERN_C_START
620 /*
621  * Module init
622  */
Init(napi_env env,napi_value exports)623 static napi_value Init(napi_env env, napi_value exports)
624 {
625     /*
626      * Attribute definition
627      */
628     napi_property_descriptor desc[] = {
629         {"deviceType", nullptr, nullptr, GetDeviceType, nullptr, nullptr, napi_default, nullptr},
630         {"manufacture", nullptr, nullptr, GetManufacture, nullptr, nullptr, napi_default, nullptr},
631         {"brand", nullptr, nullptr, GetBrand, nullptr, nullptr, napi_default, nullptr},
632         {"marketName", nullptr, nullptr, GetMarketName, nullptr, nullptr, napi_default, nullptr},
633         {"productSeries", nullptr, nullptr, GetProductSeries, nullptr, nullptr, napi_default, nullptr},
634         {"productModel", nullptr, nullptr, GetProductModel, nullptr, nullptr, napi_default, nullptr},
635         {"softwareModel", nullptr, nullptr, GetSoftwareModel, nullptr, nullptr, napi_default, nullptr},
636         {"hardwareModel", nullptr, nullptr, GetHardwareModel, nullptr, nullptr, napi_default, nullptr},
637         {"hardwareProfile", nullptr, nullptr, GetHardwareProfile, nullptr, nullptr, napi_default, nullptr},
638         {"serial", nullptr, nullptr, GetSerial, nullptr, nullptr, napi_default, nullptr},
639         {"bootloaderVersion", nullptr, nullptr, GetBootloaderVersion, nullptr, nullptr, napi_default, nullptr},
640         {"abiList", nullptr, nullptr, GetAbiList, nullptr, nullptr, napi_default, nullptr},
641         {"securityPatchTag", nullptr, nullptr, GetSecurityPatchTag, nullptr, nullptr, napi_default, nullptr},
642         {"displayVersion", nullptr, nullptr, GetDisplayVersion, nullptr, nullptr, napi_default, nullptr},
643         {"incrementalVersion", nullptr, nullptr, GetIncrementalVersion, nullptr, nullptr, napi_default, nullptr},
644         {"osReleaseType", nullptr, nullptr, GetOsReleaseType, nullptr, nullptr, napi_default, nullptr},
645         {"osFullName", nullptr, nullptr, GetOSFullName, nullptr, nullptr, napi_default, nullptr},
646         {"majorVersion", nullptr, nullptr, GetMajorVersion, nullptr, nullptr, napi_default, nullptr},
647         {"seniorVersion", nullptr, nullptr, GetSeniorVersion, nullptr, nullptr, napi_default, nullptr},
648         {"featureVersion", nullptr, nullptr, GetFeatureVersion, nullptr, nullptr, napi_default, nullptr},
649         {"buildVersion", nullptr, nullptr, GetBuildVersion, nullptr, nullptr, napi_default, nullptr},
650         {"sdkApiVersion", nullptr, nullptr, GetSdkApiVersion, nullptr, nullptr, napi_default, nullptr},
651         {"sdkMinorApiVersion", nullptr, nullptr, GetSdkMinorApiVersion, nullptr, nullptr, napi_default, nullptr},
652         {"sdkPatchApiVersion", nullptr, nullptr, GetSdkPatchApiVersion, nullptr, nullptr, napi_default, nullptr},
653         {"firstApiVersion", nullptr, nullptr, GetFirstApiVersion, nullptr, nullptr, napi_default, nullptr},
654         {"versionId", nullptr, nullptr, GetVersionId, nullptr, nullptr, napi_default, nullptr},
655         {"buildType", nullptr, nullptr, GetBuildType, nullptr, nullptr, napi_default, nullptr},
656         {"buildUser", nullptr, nullptr, GetBuildUser, nullptr, nullptr, napi_default, nullptr},
657         {"buildHost", nullptr, nullptr, GetBuildHost, nullptr, nullptr, napi_default, nullptr},
658         {"buildTime", nullptr, nullptr, GetBuildTime, nullptr, nullptr, napi_default, nullptr},
659         {"buildRootHash", nullptr, nullptr, GetBuildRootHash, nullptr, nullptr, napi_default, nullptr},
660         {"udid", nullptr, nullptr, GetDevUdid, nullptr, nullptr, napi_default, nullptr},
661         {"distributionOSName", nullptr, nullptr, NAPI_GetDistributionOSName, nullptr, nullptr, napi_default, nullptr},
662         {"distributionOSVersion", nullptr, nullptr, NAPI_GetDistributionOSVersion, nullptr, nullptr, napi_default,
663             nullptr},
664         {"distributionOSApiVersion", nullptr, nullptr, NAPI_GetDistributionOSApiVersion, nullptr, nullptr,
665             napi_default, nullptr},
666         {"distributionOSApiName", nullptr, nullptr, NAPI_GetDistributionOSApiName, nullptr, nullptr, napi_default,
667             nullptr},
668         {"distributionOSReleaseType", nullptr, nullptr, NAPI_GetDistributionOSReleaseType, nullptr, nullptr,
669             napi_default, nullptr},
670         {"ODID", nullptr, nullptr, GetDevOdid, nullptr, nullptr, napi_default, nullptr},
671         {"productModelAlias", nullptr, nullptr, GetProductModelAlias, nullptr, nullptr, napi_default, nullptr},
672         {"diskSN", nullptr, nullptr, GetDiskSN, nullptr, nullptr, napi_default, nullptr},
673         {"performanceClass", nullptr, nullptr, GetPerformanceClass, nullptr, nullptr, napi_default, nullptr},
674     };
675     NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc));
676 
677     CreateEnumLevelState(env, exports);
678     CreateDeviceTypes(env, exports);
679 
680     return exports;
681 }
682 EXTERN_C_END
683 
684 /*
685  * Module definition
686  */
687 static napi_module _module = {
688     .nm_version = 1,
689     .nm_flags = 0,
690     .nm_filename = NULL,
691     .nm_register_func = Init,
692     .nm_modname = "deviceInfo",
693     .nm_priv = ((void *)0),
694     .reserved = { 0 }
695 };
696 /*
697  * Module registration function
698  */
RegisterModule(void)699 extern "C" __attribute__((constructor)) void RegisterModule(void)
700 {
701     napi_module_register(&_module);
702 }
703