• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <iostream>
16 #include <fstream>
17 #include <unistd.h>
18 #include "include/sp_utils.h"
19 #include "include/Dubai.h"
20 #include "include/sp_log.h"
21 #include "include/common.h"
22 namespace OHOS {
23 namespace SmartPerf {
DumpDubaiBegin()24 void Dubai::DumpDubaiBegin()
25 {
26     std::string result;
27     std::string dumpBubaiB = HIDUMPER_CMD_MAP.at(HidumperCmd::DUMPER_DUBAI_B);
28     SPUtils::LoadCmd(dumpBubaiB, result);
29     LOGD("Dubai::DumpDubaiBegin");
30 }
DumpDubaiFinish()31 void Dubai::DumpDubaiFinish()
32 {
33     std::string result;
34     std::string dumpBubaiF = HIDUMPER_CMD_MAP.at(HidumperCmd::DUMPER_DUBAI_F);
35     SPUtils::LoadCmd(dumpBubaiF, result);
36     LOGD("Dubai::DumpDubaiFinish");
37 }
38 
MoveDubaiDb()39 void Dubai::MoveDubaiDb()
40 {
41     std::string result;
42     const std::string dubaiXpower = "/data/service/el2/100/xpower/dubai.db";
43     const std::string Database = "/data/app/el2/100/database/";
44     const std::string PkgEntry = "/entry/rdb";
45     const std::string cpDubai = "cp " + dubaiXpower + " " + Database + dubaiPkgName + PkgEntry;
46     const std::string dubaiPathChmod = "chmod 777 " + Database + dubaiPkgName + PkgEntry + "/dubai.db";
47     LOGD("cpDubai: (%s), dubaiPathChmod: (%s)",
48         cpDubai.c_str(), dubaiPathChmod.c_str());
49     if (!IsFileAccessible(dubaiXpower)) {
50         sleep(1);
51     }
52     SPUtils::LoadCmd(cpDubai, result);
53     if (result.empty()) {
54         LOGE("Dubai::Copy dubai.db failed");
55     } else {
56         SPUtils::LoadCmd(dubaiPathChmod, result);
57     }
58 }
59 
MoveDubaiDb(const std::string & path)60 void Dubai::MoveDubaiDb(const std::string &path)
61 {
62     std::string result;
63     const std::string dubaiLocalPath = "/data/local/tmp/dubai/";
64     SPUtils::CreateDir(dubaiLocalPath);
65     const std::string cpDubai = "cp " + path + " " + dubaiLocalPath;
66     const std::string dubaiPathChmod = "chmod 777 " + dubaiLocalPath + "dubai.db";
67     LOGD("cpDubai: (%s), dubaiPathChmod: (%s)",
68         cpDubai.c_str(), dubaiPathChmod.c_str());
69     if (!IsFileAccessible(path)) {
70         sleep(1);
71     }
72     SPUtils::LoadCmd(cpDubai, result);
73     if (dubaiLocalPath.empty()) {
74         LOGE("Dubai::Copy dubai.db failed");
75     } else {
76         SPUtils::LoadCmd(dubaiPathChmod, result);
77     }
78 }
79 
CallBeginAndFinish()80 void Dubai::CallBeginAndFinish()
81 {
82     DumpDubaiBegin();
83     DumpDubaiFinish();
84 }
85 
CallMoveDubaiDbFinished()86 std::string Dubai::CallMoveDubaiDbFinished()
87 {
88     std::string dubaiMoveFinish;
89     if (isDumpDubaiFinish) {
90         MoveDubaiDb();
91     }
92     dubaiMoveFinish = "get_dubai_db";
93     return dubaiMoveFinish;
94 }
95 
IsFileAccessible(const std::string & filename)96 bool Dubai::IsFileAccessible(const std::string &filename)
97 {
98     char duBaiRealPath[PATH_MAX] = {0x00};
99     if (realpath(filename.c_str(), duBaiRealPath) == nullptr) {
100         std::cout << "" << std::endl;
101     }
102     std::ifstream file(duBaiRealPath);
103     return file.good();
104 }
105 }
106 }