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 }
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 }
37
MoveDubaiDb()38 void Dubai::MoveDubaiDb()
39 {
40 std::string result;
41 const std::string dubaiXpower = "/data/service/el2/100/xpower/dubai.db";
42 const std::string Database = "/data/app/el2/100/database/";
43 const std::string PkgEntry = "/entry/rdb";
44 const std::string cpDubai = "cp " + dubaiXpower + " " + Database + dubaiPkgName + PkgEntry;
45 const std::string dubaiPathChmod = "chmod 777 " + Database + dubaiPkgName + PkgEntry + "/dubai.db";
46 LOGD("cpDubai: (%s), dubaiPathChmod: (%s)",
47 cpDubai.c_str(), dubaiPathChmod.c_str());
48 if (!IsFileAccessible(dubaiXpower)) {
49 sleep(1);
50 }
51 SPUtils::LoadCmd(cpDubai, result);
52 if (result.empty()) {
53 LOGE("Dubai::Copy dubai.db failed");
54 } else {
55 SPUtils::LoadCmd(dubaiPathChmod, result);
56 }
57 }
58
CallBeginAndFinish()59 void Dubai::CallBeginAndFinish()
60 {
61 DumpDubaiBegin();
62 DumpDubaiFinish();
63 }
64
CallMoveDubaiDbFinished()65 std::string Dubai::CallMoveDubaiDbFinished()
66 {
67 std::string dubaiMoveFinish;
68 if (isDumpDubaiFinish) {
69 MoveDubaiDb();
70 }
71 dubaiMoveFinish = "get_dubai_db";
72 return dubaiMoveFinish;
73 }
74
IsFileAccessible(const std::string & filename)75 bool Dubai::IsFileAccessible(const std::string &filename)
76 {
77 std::ifstream file(filename);
78 return file.good();
79 }
80 }
81 }
82