1 /*
2  * Copyright (C) 2021 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 "executor/api_dumper.h"
17 #include <sstream>
18 #include "parameter.h"
19 
20 namespace OHOS {
21 namespace HiviewDFX {
APIDumper()22 APIDumper::APIDumper()
23 {
24 }
25 
~APIDumper()26 APIDumper::~APIDumper()
27 {
28 }
29 
PreExecute(const std::shared_ptr<DumperParameter> & parameter,StringMatrix dumpDatas)30 DumpStatus APIDumper::PreExecute(const std::shared_ptr<DumperParameter>& parameter,
31     StringMatrix dumpDatas)
32 {
33     if (dumpDatas.get()) {
34         result_ = dumpDatas;
35         return DumpStatus::DUMP_OK;
36     }
37     return DumpStatus::DUMP_FAIL;
38 }
39 
Execute()40 DumpStatus APIDumper::Execute()
41 {
42     DUMPER_HILOGI(MODULE_COMMON, "info|APIDumper Execute");
43     AddApiRetIntoResult(GetDisplayVersion(), "BuildId");
44     AddApiRetIntoResult(GetOsReleaseType(), "RleaseType");
45     AddApiRetIntoResult(GetVersionId(), "OsVersion");
46     AddApiRetIntoResult(GetDeviceType(), "DeviceType");
47     AddApiRetIntoResult(GetManufacture(), "Manufacture");
48     AddApiRetIntoResult(GetBrand(), "Brand");
49     AddApiRetIntoResult(GetMarketName(), "MarketName");
50     AddApiRetIntoResult(GetProductSeries(), "ProductSeries");
51     AddApiRetIntoResult(GetProductModel(), "ProductModel");
52     AddApiRetIntoResult(GetSoftwareModel(), "SoftwareModel");
53     AddApiRetIntoResult(GetHardwareModel(), "HardwareModel");
54     AddApiRetIntoResult(GetHardwareProfile(), "HardwareProfile");
55     AddApiRetIntoResult(GetBootloaderVersion(), "BootLoaderVersion");
56     AddApiRetIntoResult(GetAbiList(), "ABIList");
57     AddApiRetIntoResult(GetSecurityPatchTag(), "SecurityPatch");
58     AddApiRetIntoResult(GetIncrementalVersion(), "IncrementalVersion");
59     AddApiRetIntoResult(GetOSFullName(), "OSFullName");
60     AddApiRetIntoResult(GetSdkApiVersion(), "SDKAPIVersion");
61     AddApiRetIntoResult(GetFirstApiVersion(), "FirstAPIVersion");
62     AddApiRetIntoResult(GetBuildRootHash(), "BuildHash");
63     AddApiRetIntoResult(GetBuildType(), "BuildType");
64     AddApiRetIntoResult(GetBuildUser(), "BuildUser");
65     AddApiRetIntoResult(GetBuildHost(), "BuildHost");
66     AddApiRetIntoResult(GetBuildTime(), "BuildTime");
67     DUMPER_HILOGI(MODULE_COMMON, "info|APIDumper Execute end");
68     return DumpStatus::DUMP_OK;
69 }
70 
AddApiRetIntoResult(const char * content,const std::string & title)71 void APIDumper::AddApiRetIntoResult(const char* content, const std::string& title)
72 {
73     if (content) {
74         std::ostringstream s;
75         s << title <<": "<< content;
76         std::vector<std::string> line_vector;
77         line_vector.push_back(s.str());
78         result_->push_back(line_vector);
79     }
80 }
81 
AddApiRetIntoResult(int content,const std::string & title)82 void APIDumper::AddApiRetIntoResult(int content, const std::string& title)
83 {
84     std::ostringstream s;
85     s << title <<": "<< content;
86     std::vector<std::string> line_vector;
87     line_vector.push_back(s.str());
88     result_->push_back(line_vector);
89 }
90 
AfterExecute()91 DumpStatus APIDumper::AfterExecute()
92 {
93     return DumpStatus::DUMP_OK;
94 }
95 } // namespace HiviewDFX
96 } // namespace OHOS
97