• 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 <sstream>
17 #include <fstream>
18 #include <unistd.h>
19 #include "include/sp_utils.h"
20 #include "include/Dubai.h"
21 #include "include/sp_log.h"
22 #include "include/common.h"
23 namespace OHOS {
24 namespace SmartPerf {
DumpDubaiBegin()25 void Dubai::DumpDubaiBegin()
26 {
27     std::string result;
28     std::string dumpBubaiB = HIDUMPER_CMD_MAP.at(HidumperCmd::DUMPER_DUBAI_B);
29     SPUtils::LoadCmd(dumpBubaiB, result);
30     LOGD("Dubai::DumpDubaiBegin");
31 }
DumpDubaiFinish()32 void Dubai::DumpDubaiFinish()
33 {
34     std::string result;
35     std::string dumpBubaiF = HIDUMPER_CMD_MAP.at(HidumperCmd::DUMPER_DUBAI_F);
36     SPUtils::LoadCmd(dumpBubaiF, result);
37     LOGD("Dubai::DumpDubaiFinish");
38 }
39 
MoveDubaiDb()40 void Dubai::MoveDubaiDb()
41 {
42     std::string result;
43     const std::string dubaiXpower = "/data/service/el2/100/xpower/dubai.db";
44     const std::string Database = "/data/app/el2/100/database/";
45     const std::string PkgEntry = "/entry/rdb";
46     const std::string cpDubai = "cp " + dubaiXpower + " " + Database + dubaiPkgName + PkgEntry;
47     const std::string dubaiPathChmod = "chmod 777 " + Database + dubaiPkgName + PkgEntry + "/dubai.db";
48     LOGD("cpDubai: (%s), dubaiPathChmod: (%s)",
49         cpDubai.c_str(), dubaiPathChmod.c_str());
50     if (!IsFileAccessible(dubaiXpower)) {
51         sleep(1);
52     }
53     SPUtils::LoadCmd(cpDubai, result);
54     if (result.empty()) {
55         LOGE("Dubai::Copy dubai.db failed");
56     } else {
57         SPUtils::LoadCmd(dubaiPathChmod, result);
58     }
59 }
60 
CallBeginAndFinish()61 void Dubai::CallBeginAndFinish()
62 {
63     DumpDubaiBegin();
64     DumpDubaiFinish();
65 }
66 
CallMoveDubaiDbFinished()67 std::string Dubai::CallMoveDubaiDbFinished()
68 {
69     std::string dubaiMoveFinish;
70     if (isDumpDubaiFinish) {
71         MoveDubaiDb();
72     }
73     dubaiMoveFinish = "get_dubai_db";
74     return dubaiMoveFinish;
75 }
76 
IsFileAccessible(const std::string & filename)77 bool Dubai::IsFileAccessible(const std::string &filename)
78 {
79     std::ifstream file(filename);
80     return file.good();
81 }
82 }
83 }
84