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 "cellular_data_dump_helper.h" 17 18 #include "cellular_data_service.h" 19 #include "core_service_client.h" 20 #include "enum_convert.h" 21 #include "telephony_types.h" 22 23 namespace OHOS { 24 namespace Telephony { CellularDataDumpHelper()25CellularDataDumpHelper::CellularDataDumpHelper() {} 26 Dump(const std::vector<std::string> & args,std::string & result) const27bool CellularDataDumpHelper::Dump(const std::vector<std::string> &args, std::string &result) const 28 { 29 result.clear(); 30 for (int32_t i = 0; i < (int32_t)args.size() - 1; i++) { 31 if (args[i] == "cellular_data" && args[i + 1] == "--help") { 32 ShowHelp(result); 33 return true; 34 } 35 } 36 ShowCellularDataInfo(result); 37 return true; 38 } 39 HasSimCard(const int32_t slotId) const40bool CellularDataDumpHelper::HasSimCard(const int32_t slotId) const 41 { 42 bool hasSimCard = false; 43 DelayedRefSingleton<CoreServiceClient>::GetInstance().HasSimCard(slotId, hasSimCard); 44 return hasSimCard; 45 } 46 ShowHelp(std::string & result) const47void CellularDataDumpHelper::ShowHelp(std::string &result) const 48 { 49 result.append("CellularData:\n"); 50 result.append("Usage:dump <command> [options]\n"); 51 result.append("Description:\n"); 52 result.append("-cellular_data_info "); 53 result.append("dump all cellular_data information in the system\n"); 54 result.append("-output_slot "); 55 result.append("default_slot_Id\n"); 56 result.append("-output_state_machine"); 57 result.append("Output state machine information and status\n"); 58 result.append("-dataflow_info"); 59 result.append("output_data_flow_info\n"); 60 result.append("-show_log_level "); 61 result.append("show cellular_data SA's log level\n"); 62 result.append("-set_log_level <level> "); 63 result.append("set cellular_data SA's log level\n"); 64 result.append("-perf_dump "); 65 result.append("dump performance statistics\n"); 66 } 67 ShowCellularDataInfo(std::string & result) const68void CellularDataDumpHelper::ShowCellularDataInfo(std::string &result) const 69 { 70 CellularDataService &dataService = DelayedRefSingleton<CellularDataService>::GetInstance(); 71 result.append("Ohos cellular data service: \n"); 72 result.append("BeginTime : "); 73 result.append(dataService.GetBeginTime()); 74 result.append("\n"); 75 result.append("EndTime : "); 76 result.append(dataService.GetEndTime()); 77 result.append("\n"); 78 result.append("SpendTime : "); 79 result.append(std::to_string(dataService.GetSpendTime())); 80 result.append("\n"); 81 result.append("CellularDataSlotId : "); 82 result.append(dataService.GetCellularDataSlotIdDump()); 83 result.append("\n"); 84 result.append("StateMachineCurrentStatus : "); 85 result.append(dataService.GetStateMachineCurrentStatusDump()); 86 result.append("\n"); 87 result.append("FlowDataInfo : "); 88 result.append(dataService.GetFlowDataInfoDump()); 89 result.append("\n"); 90 result.append("ServiceRunningState : "); 91 result.append(std::to_string(dataService.GetServiceRunningState())); 92 result.append("\n"); 93 bool dataRoamingEnabled = false; 94 for (int32_t i = 0; i < SIM_SLOT_COUNT; i++) { 95 if (HasSimCard(i)) { 96 result.append("SlotId : "); 97 result.append(std::to_string(i)); 98 result.append("\n"); 99 result.append("CellularDataRoamingEnabled : "); 100 dataService.IsCellularDataRoamingEnabled(i, dataRoamingEnabled); 101 result.append(GetBoolValue(dataRoamingEnabled)); 102 result.append("\n"); 103 } 104 } 105 bool dataEnabled = false; 106 result.append("CellularDataEnabled : "); 107 dataService.IsCellularDataEnabled(dataEnabled); 108 result.append(GetBoolValue(dataEnabled)); 109 result.append("\n"); 110 result.append("CellularDataState : "); 111 result.append(GetCellularDataConnectionState(dataService.GetCellularDataState())); 112 result.append("\n"); 113 } 114 } // namespace Telephony 115 } // namespace OHOS