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 } 30 Dump(const std::vector<std::string> & args,std::string & result)31bool ThermalMgrDumper::Dump(const std::vector<std::string>& args, std::string& result) 32 { 33 THERMAL_HILOGD(COMP_SVC, "Enter"); 34 result.clear(); 35 auto argc = args.size(); 36 if ((argc == 0) || (args[0] == ARGS_HELP)) { 37 ShowUsage(result); 38 return true; 39 } 40 41 auto tms = DelayedSpSingleton<ThermalService>::GetInstance(); 42 if (tms == nullptr) { 43 return false; 44 } 45 46 if (args[0] == ARGS_DIALOG) { 47 tms->GetActionPopup()->ShowThermalDialog(ActionPopup::TempStatus::HIGHER_TEMP); 48 return true; 49 } 50 51 for (auto it = args.begin(); it != args.end(); it++) { 52 if (*it == ARGS_THERMALINFO) { 53 ShowThermalZoneInfo(result); 54 } else { 55 break; 56 } 57 } 58 return true; 59 } 60 ShowThermalZoneInfo(std::string & result)61void ThermalMgrDumper::ShowThermalZoneInfo(std::string& result) 62 { 63 auto tms = DelayedSpSingleton<ThermalService>::GetInstance(); 64 if (tms == nullptr) { 65 THERMAL_HILOGE(COMP_SVC, "thermal service is nullptr"); 66 return; 67 } 68 auto tzMap = tms->GetSubscriber()->GetSubscriberInfo(); 69 for (auto& iter : tzMap) { 70 result.append("Type: ") 71 .append(iter.first) 72 .append("\n") 73 .append("Temperature: ") 74 .append(ToString(iter.second)) 75 .append("\n"); 76 } 77 } 78 ShowUsage(std::string & result)79void ThermalMgrDumper::ShowUsage(std::string& result) 80 { 81 result.append("Thermal manager dump options:\n") 82 .append(" [-h] \n") 83 .append(" description of the cmd option:\n") 84 .append(" -h: show this help.\n") 85 .append(" -d: show thermal level dialog.\n") 86 .append(" -t: show thermal zone data.\n"); 87 } 88 } // namespace PowerMgr 89 } // namespace OHOS 90