1 /* 2 * Copyright (c) 2021-2022 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 "power_mgr_dumper.h" 17 18 #include "power_mgr_service.h" 19 #include "system_suspend_controller.h" 20 21 namespace OHOS { 22 namespace PowerMgr { 23 namespace { 24 const std::string ARGS_ALL = "-a"; 25 const std::string ARGS_HELP = "-h"; 26 const std::string ARGS_RUNNINGLOCK = "-r"; 27 const std::string ARGS_STATE = "-s"; 28 const std::string ARGS_DIALOG = "-d"; 29 const std::string ARGS_REG_KEY = "-k"; 30 } 31 Dump(const std::vector<std::string> & args,std::string & result)32bool PowerMgrDumper::Dump(const std::vector<std::string>& args, std::string& result) 33 { 34 result.clear(); 35 auto argc = args.size(); 36 if ((argc == 0) || (args[0] == ARGS_HELP)) { 37 ShowUsage(result); 38 return true; 39 } 40 auto pms = DelayedSpSingleton<PowerMgrService>::GetInstance(); 41 if (pms == nullptr) { 42 return true; 43 } 44 if (args[0] == ARGS_DIALOG) { 45 pms->HandleShutdownRequest(); 46 return true; 47 } 48 if (args[0] == ARGS_REG_KEY) { 49 pms->KeyMonitorInit(); 50 return true; 51 } 52 for (auto it = args.begin(); it != args.end(); it++) { 53 if (*it == ARGS_RUNNINGLOCK) { 54 auto runningLockMgr = pms->GetRunningLockMgr(); 55 if (runningLockMgr == nullptr) { 56 continue; 57 } 58 runningLockMgr->DumpInfo(result); 59 } else if (*it == ARGS_STATE) { 60 auto stateMachine = pms->GetPowerStateMachine(); 61 if (stateMachine == nullptr) { 62 continue; 63 } 64 stateMachine->DumpInfo(result); 65 } else if (*it == ARGS_ALL) { 66 result.clear(); 67 auto stateMachine = pms->GetPowerStateMachine(); 68 if (stateMachine == nullptr) { 69 continue; 70 } 71 stateMachine->DumpInfo(result); 72 auto runningLockMgr = pms->GetRunningLockMgr(); 73 if (runningLockMgr == nullptr) { 74 continue; 75 } 76 runningLockMgr->DumpInfo(result); 77 break; 78 } 79 } 80 return true; 81 } 82 ShowUsage(std::string & result)83void PowerMgrDumper::ShowUsage(std::string& result) 84 { 85 result.append("Power manager dump options:\n") 86 .append(" [-h] [-runninglock]\n") 87 .append(" description of the cmd option:\n") 88 .append(" -a: show dump info of all power modules.\n") 89 .append(" -h: show this help.\n") 90 .append(" -r: show the information of runninglock.\n") 91 .append(" -s: show the information of power state machine.\n") 92 .append(" -d: show power off dialog.\n"); 93 } 94 } // namespace PowerMgr 95 } // namespace OHOS 96