1 /*
2  * Copyright (c) 2022 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 <cstdlib>
17 #include <cstdint>
18 
19 #include "begetctl.h"
20 #include "shell.h"
21 #include "shell_utils.h"
22 #include "parameter.h"
23 #include "parameters.h"
24 #include "sysversion.h"
25 
26 using SysParaInfoItem = struct {
27     char *infoName;
28     const char *(*getInfoValue)(void);
29 };
30 
31 static const SysParaInfoItem SYSPARA_LIST[] = {
32     {(char *)"DeviceType", GetDeviceType},
33     {(char *)"Manufacture", GetManufacture},
34     {(char *)"Brand", GetBrand},
35     {(char *)"MarketName", GetMarketName},
36     {(char *)"ProductSeries", GetProductSeries},
37     {(char *)"ProductModel", GetProductModel},
38     {(char *)"ProductModelAlias", GetProductModel},
39     {(char *)"SoftwareModel", GetSoftwareModel},
40     {(char *)"HardwareModel", GetHardwareModel},
41     {(char *)"Serial", GetSerial},
42     {(char *)"OSFullName", GetOSFullName},
43     {(char *)"DisplayVersion", GetDisplayVersion},
44     {(char *)"BootloaderVersion", GetBootloaderVersion},
45     {(char *)"GetSecurityPatchTag", GetSecurityPatchTag},
46     {(char *)"AbiList", GetAbiList},
47     {(char *)"IncrementalVersion", GetIncrementalVersion},
48     {(char *)"VersionId", GetVersionId},
49     {(char *)"BuildType", GetBuildType},
50     {(char *)"BuildUser", GetBuildUser},
51     {(char *)"BuildHost", GetBuildHost},
52     {(char *)"BuildTime", GetBuildTime},
53     {(char *)"BuildRootHash", GetBuildRootHash},
54     {(char *)"GetOsReleaseType", GetOsReleaseType},
55     {(char *)"GetHardwareProfile", GetHardwareProfile},
56 };
57 
SysParaApiDumpCmd(BShellHandle shell,int32_t argc,char * argv[])58 static int32_t SysParaApiDumpCmd(BShellHandle shell, int32_t argc, char *argv[])
59 {
60     int index = 0;
61     int dumpInfoItemNum = (sizeof(SYSPARA_LIST) / sizeof(SYSPARA_LIST[0]));
62     const char *temp = nullptr;
63     BShellEnvOutput(shell, const_cast<char *>("Begin dump syspara\r\n"));
64     BShellEnvOutput(shell, const_cast<char *>("=======================\r\n"));
65     while (index < dumpInfoItemNum) {
66         temp = SYSPARA_LIST[index].getInfoValue();
67         BShellEnvOutput(shell, const_cast<char *>("%s:%s\r\n"), SYSPARA_LIST[index].infoName, temp);
68         index++;
69     }
70     BShellEnvOutput(shell, const_cast<char *>("FirstApiVersion:%d\r\n"), GetFirstApiVersion());
71     BShellEnvOutput(shell, const_cast<char *>("GetSerial:%s\r\n"), GetSerial());
72 #ifndef OHOS_LITE
73     BShellEnvOutput(shell, const_cast<char *>("acl serial:%s\r\n"), AclGetSerial());
74 #endif
75     char udid[65] = {0};
76     GetDevUdid(udid, sizeof(udid));
77     BShellEnvOutput(shell, const_cast<char *>("GetDevUdid:%s\r\n"), udid);
78 #ifndef OHOS_LITE
79     AclGetDevUdid(udid, sizeof(udid));
80     BShellEnvOutput(shell, const_cast<char *>("Acl devUdid:%s\r\n"), udid);
81 #endif
82     BShellEnvOutput(shell, const_cast<char *>("Version:%d.%d.%d.%d\r\n"),
83         GetMajorVersion(), GetSeniorVersion(), GetFeatureVersion(), GetBuildVersion());
84     BShellEnvOutput(shell, const_cast<char *>("GetSdkApiVersion:%d\r\n"), GetSdkApiVersion());
85     BShellEnvOutput(shell, const_cast<char *>("GetSystemCommitId:%lld\r\n"), GetSystemCommitId());
86     BShellEnvOutput(shell, const_cast<char *>("=======================\r\n"));
87     BShellEnvOutput(shell, const_cast<char *>("End dump syspara\r\n"));
88     return 0;
89 }
90 
MODULE_CONSTRUCTOR(void)91 MODULE_CONSTRUCTOR(void)
92 {
93     const CmdInfo infos[] = {
94         {
95             const_cast<char *>("dump"), SysParaApiDumpCmd, const_cast<char *>("dump api"),
96             const_cast<char *>("dump api"), const_cast<char *>("dump api")
97         },
98     };
99     for (size_t i = 0; i < sizeof(infos) / sizeof(infos[0]); i++) {
100         BShellEnvRegisterCmd(GetShellHandle(), &infos[i]);
101     }
102 }
103