• 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 
16 #include "thermal_mgr_dumper.h"
17 
18 #include "constants.h"
19 #include "thermal_common.h"
20 #include "thermal_service.h"
21 #include "action_popup.h"
22 
23 namespace OHOS {
24 namespace PowerMgr {
25 namespace {
26 constexpr const char* ARGS_HELP = "-h";
27 constexpr const char* ARGS_DIALOG = "-d";
28 constexpr const char* ARGS_THERMALINFO = "-t";
29 constexpr const char* ARGS_SCENE = "-s";
30 constexpr const char* ARGS_LEVEL = "-l";
31 constexpr const char* ARGS_ACTION = "-a";
32 constexpr const char* ARGS_POLICY = "-p";
33 constexpr const char* ARGS_IDLE = "-i";
34 }
35 
Dump(const std::vector<std::string> & args,std::string & result)36 bool ThermalMgrDumper::Dump(const std::vector<std::string>& args, std::string& result)
37 {
38     THERMAL_HILOGD(COMP_SVC, "Enter");
39     result.clear();
40     auto argc = args.size();
41     if ((argc == 0) || (args[0] == ARGS_HELP)) {
42         ShowUsage(result);
43         return true;
44     }
45 
46     auto tms = DelayedSpSingleton<ThermalService>::GetInstance();
47     if (tms == nullptr) {
48         return false;
49     }
50 
51     if (args[0] == ARGS_DIALOG) {
52         tms->GetActionPopup()->ShowThermalDialog(ActionPopup::TempStatus::HIGHER_TEMP);
53         return true;
54     }
55 
56     for (auto it = args.begin(); it != args.end(); it++) {
57         if (*it == ARGS_THERMALINFO) {
58             ShowThermalZoneInfo(result);
59         } else if (*it == ARGS_SCENE) {
60             std::shared_ptr<StateMachine> state = tms->GetStateMachineObj();
61             state->DumpState(result);
62         } else if (*it == ARGS_LEVEL) {
63             std::shared_ptr<ThermalPolicy> policy = tms->GetPolicy();
64             policy->DumpLevel(result);
65         } else if (*it == ARGS_ACTION) {
66             std::shared_ptr<ThermalActionManager> action = tms->GetActionManagerObj();
67             action->DumpAction(result);
68         } else if (*it == ARGS_POLICY) {
69             std::shared_ptr<ThermalPolicy> policy = tms->GetPolicy();
70             policy->DumpPolicy(result);
71         } else if (*it == ARGS_IDLE) {
72             std::shared_ptr<StateMachine> state = tms->GetStateMachineObj();
73             state->DumpIdle(result);
74         } else {
75             break;
76         }
77     }
78     return true;
79 }
80 
ShowThermalZoneInfo(std::string & result)81 void ThermalMgrDumper::ShowThermalZoneInfo(std::string& result)
82 {
83     auto tms = DelayedSpSingleton<ThermalService>::GetInstance();
84     if (tms == nullptr) {
85         THERMAL_HILOGE(COMP_SVC, "thermal service is nullptr");
86         return;
87     }
88     auto tzMap = tms->GetSubscriber()->GetSubscriberInfo();
89     for (auto& iter : tzMap) {
90         result.append("Type: ")
91             .append(iter.first)
92             .append("\n")
93             .append("Temperature: ")
94             .append(ToString(iter.second))
95             .append("\n");
96     }
97 }
98 
ShowUsage(std::string & result)99 void ThermalMgrDumper::ShowUsage(std::string& result)
100 {
101     result.append("Thermal manager dump options:\n")
102         .append("  [-h] \n")
103         .append("  description of the cmd option:\n")
104         .append("    -h: show this help.\n")
105         .append("    -d: show thermal level dialog.\n")
106         .append("    -t: show thermal zone data.\n")
107         .append("    -s: show thermal scene data.\n")
108         .append("    -l: show thermal level data.\n")
109         .append("    -a: show thermal action data.\n")
110         .append("    -p: show thermal policy data.\n")
111         .append("    -i: show thermal charging idle state data.\n");
112 }
113 } // namespace PowerMgr
114 } // namespace OHOS
115