• 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 <iostream>
17 #include <string>
18 #include <vector>
19 #include <cstring>
20 #include <fstream>
21 #include <utility>
22 
23 #include "parameter.h"
24 #include "devattest_interface.h"
25 
26 const int DEVATTEST_SUESS = 0;
27 const int UDIDSIZE_LEN = 64;
28 
29 using namespace std;
30 
31 std::vector<std::pair<const char*, const char*>> myVector;
32 char buffer1[50];
33 char buffer2[50];
34 char buffer3[50];
35 char buffer4[50];
36 
37 template<typename KeyType, typename ValueType>
WriteTexToFile(const std::string & filename,const std::string & text1,const std::vector<std::pair<KeyType,ValueType>> & kvPairs,const std::string & text2)38 void WriteTexToFile(const std::string& filename, const std::string& text1,
39                     const std::vector<std::pair<KeyType, ValueType>>& kvPairs,
40                     const std::string& text2) {
41     std::ofstream outFile(filename, std::ios::out | std::ios::trunc);
42     if (!outFile.is_open()) {
43         std::cerr << "[ERROR] Not open or create file : " << filename << std::endl;
44         return;
45     }
46 
47     outFile << text1 << std::endl;
48     for (const auto& pair : kvPairs) {
49         outFile << pair.first << " = " << pair.second << std::endl;
50     }
51     outFile << text2 << std::endl;
52 }
53 
IntToConstCharPtrSafe(int num,char * buffer,size_t bufferSize)54 void IntToConstCharPtrSafe(int num, char* buffer, size_t bufferSize) {
55     std::snprintf(buffer, bufferSize, "%d", num);
56 }
57 
ObtainProductParms1(void)58 void ObtainProductParms1(void)
59 {
60     const char *productType = GetDeviceType();
61     printf("Device Type = %s\n", productType);
62     myVector.emplace_back("Device Type", productType);
63 
64     const char *securityPatchTag = GetSecurityPatchTag();
65     printf("Security Patch = %s\n", securityPatchTag);
66     myVector.emplace_back("Security Patch", securityPatchTag);
67 
68     const char *osName = GetOSFullName();
69     printf("OsFullName = %s\n", osName);
70     myVector.emplace_back("OsFullName", osName);
71 
72     const char *displayVersion = GetDisplayVersion();
73     printf("DisplayVersion = %s\n", displayVersion);
74     myVector.emplace_back("DisplayVersion", displayVersion);
75 
76     const char *versionId = GetVersionId();
77     printf("VersionID = %s\n", versionId);
78     myVector.emplace_back("VersionID", versionId);
79 
80     AttestResultInfo attestResultInfo = {0};
81     attestResultInfo.ticket = NULL;
82     int32_t retStatus = GetAttestStatus(&attestResultInfo);
83     printf("authResult = %d\n", attestResultInfo.authResult);
84     printf("softwareResult = %d\n", attestResultInfo.softwareResult);
85     IntToConstCharPtrSafe(attestResultInfo.authResult, buffer1, sizeof(buffer1));
86     const char* authResult1 = buffer1;
87     IntToConstCharPtrSafe(attestResultInfo.softwareResult, buffer2, sizeof(buffer2));
88     const char* softwareResult1 = buffer2;
89     myVector.emplace_back("authResult", authResult1);
90     myVector.emplace_back("softwareResult", softwareResult1);
91 }
92 
ObtainProductParms2(void)93 void ObtainProductParms2(void)
94 {
95     char udid[UDIDSIZE_LEN + 1] = {0};
96     int retUdid = GetDevUdid(udid, UDIDSIZE_LEN + 1);
97     printf("DevUdid = %s\n", udid);
98     size_t length = std::strlen(udid) + 1;
99     char* udid1 = new char[length];
100     std::strcpy(udid1, udid);
101     myVector.emplace_back("DevUdid", udid1);
102 
103     const char *manuFacture = GetManufacture();
104     printf("manuFacture = %s\n", manuFacture);
105     myVector.emplace_back("manuFacture", manuFacture);
106 
107     const char *productModel = GetProductModel();
108     printf("productModel = %s\n", productModel);
109     myVector.emplace_back("productModel", productModel);
110 
111     const char *serial = GetSerial();
112     printf("serial = %s\n", serial);
113     myVector.emplace_back("serial", serial);
114 
115     const char *brand = GetBrand();
116     printf("brand = %s\n", brand);
117     myVector.emplace_back("brand", brand);
118 
119     const char *productSeries = GetProductSeries();
120     printf("productSeries = %s\n", productSeries);
121     myVector.emplace_back("productSeries", productSeries);
122 }
123 
ObtainProductParms3(void)124 void ObtainProductParms3(void)
125 {
126     const char *softwareModel = GetSoftwareModel();
127     printf("softwareModel = %s\n", softwareModel);
128     myVector.emplace_back("softwareModel", softwareModel);
129 
130     const char *hardWareModel = GetHardwareModel();
131     printf("HardwareModel = %s\n", hardWareModel);
132     myVector.emplace_back("HardwareModel", hardWareModel);
133 
134     const char *buildRootHash = GetBuildRootHash();
135     printf("BuildRootHash = %s\n", buildRootHash);
136     myVector.emplace_back("BuildRootHash", buildRootHash);
137 
138     const char *marketName = GetMarketName();
139     printf("marketName = %s\n", marketName);
140     myVector.emplace_back("marketName", marketName);
141 
142     int sdkApiVersion = GetSdkApiVersion();
143     printf("SdkApiVersion = %d\n", sdkApiVersion);
144     IntToConstCharPtrSafe(sdkApiVersion, buffer4, sizeof(buffer4));
145     const char* sdkApiVersion1 = buffer4;
146     myVector.emplace_back("SdkApiVersion", sdkApiVersion1);
147 
148     int firstApiVersion = GetFirstApiVersion();
149     printf("firstApiVersion = %d\n", firstApiVersion);
150     IntToConstCharPtrSafe(firstApiVersion, buffer3, sizeof(buffer3));
151     const char* firstApiVersion1 = buffer3;
152     myVector.emplace_back("firstApiVersion", firstApiVersion1);
153 }
154 
ObtainProductParms4(void)155 void ObtainProductParms4(void)
156 {
157     const char *bootloaderVersion = GetBootloaderVersion();
158     printf("bootloaderVersion = %s\n", bootloaderVersion);
159     myVector.emplace_back("bootloaderVersion", bootloaderVersion);
160 
161     const char *incrementalVersion = GetIncrementalVersion();
162     printf("incrementalVersion = %s\n", incrementalVersion);
163     myVector.emplace_back("incrementalVersion", incrementalVersion);
164 
165     const char *buildType = GetBuildType();
166     printf("buildType = %s\n", buildType);
167     myVector.emplace_back("buildType", buildType);
168 
169     const char *buildUser = GetBuildUser();
170     printf("buildUser = %s\n", buildUser);
171     myVector.emplace_back("buildUser", buildUser);
172 
173     const char *buildHost = GetBuildHost();
174     printf("buildHost = %s\n", buildHost);
175     myVector.emplace_back("buildHost", buildHost);
176 
177     const char *buildTime = GetBuildTime();
178     printf("buildTime = %s\n", buildTime);
179     myVector.emplace_back("buildTime", buildTime);
180 
181     const char *abiList = GetAbiList();
182     printf("AbiList = %s\n", abiList);
183     myVector.emplace_back("AbiList", abiList);
184 }
185 
main()186 int main()
187 {
188     printf("******To Obtain Product Params Start******\n");
189     ObtainProductParms1();
190     ObtainProductParms2();
191     ObtainProductParms3();
192     ObtainProductParms4();
193     printf("******To Obtain Product Params End  ******\n");
194 
195     std::string text1 = "******To Obtain Product Params Start******";
196     std::string text2 = "******To Obtain Product Params End  ******";
197 
198     WriteTexToFile("querySmall.txt", text1, myVector, text2);
199     return 0;
200 }
201