1 /*
2 * Copyright (C) 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 "core_service_dump_helper.h"
17
18 #include "core_service.h"
19 #include "enum_convert.h"
20 #include "signal_info.h"
21 #include "signal_information.h"
22 #include "core_manager_inner.h"
23
24 namespace OHOS {
25 namespace Telephony {
Dump(const std::vector<std::string> & args,std::string & result) const26 bool CoreServiceDumpHelper::Dump(const std::vector<std::string> &args, std::string &result) const
27 {
28 result.clear();
29 ShowHelp(result);
30 ShowCoreServiceTimeInfo(result);
31 ShowCoreServiceInfo(result);
32 return true;
33 }
34
ShowHelp(std::string & result) const35 void CoreServiceDumpHelper::ShowHelp(std::string &result) const
36 {
37 result.append("CoreService:\n")
38 .append("Usage:dump <command> [options]\n")
39 .append("Description:\n")
40 .append("-core_service_info ")
41 .append("dump all core_service information in the system\n")
42 .append("-input_simulate <event> ")
43 .append("simulate event from ohos core_service, supported events: login/logout/token_invalid\n")
44 .append("-output_simulate <event> ")
45 .append("simulate event output\n")
46 .append("-show_log_level ")
47 .append("show core_service SA's log level\n")
48 .append("-set_log_level <level> ")
49 .append("set core_service SA's log level\n")
50 .append("-perf_dump ")
51 .append("dump performance statistics\n");
52 }
53
to_utf8(std::u16string str16)54 static std::string to_utf8(std::u16string str16)
55 {
56 return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> {}.to_bytes(str16);
57 }
58
ShowCoreServiceTimeInfo(std::string & result) const59 void CoreServiceDumpHelper::ShowCoreServiceTimeInfo(std::string &result) const
60 {
61 result.append("Ohos core_service service:\n");
62 result.append("BindTime = ");
63 result.append(std::to_string(DelayedSingleton<CoreService>::GetInstance()->GetBindTime()));
64 result.append("\nEndTime = ");
65 result.append(std::to_string(DelayedSingleton<CoreService>::GetInstance()->GetEndTime()));
66 result.append("\nSpendTime = ");
67 result.append(std::to_string(DelayedSingleton<CoreService>::GetInstance()->GetSpendTime()));
68 result.append("\n");
69 }
70
ShowCoreServiceInfo(std::string & result) const71 void CoreServiceDumpHelper::ShowCoreServiceInfo(std::string &result) const
72 {
73 for (int32_t i = 0; i < SIM_SLOT_COUNT; i++) {
74 bool hasSimCard = false;
75 CoreManagerInner::GetInstance().HasSimCard(i, hasSimCard);
76 if (hasSimCard) {
77 result.append("SlotId = ");
78 result.append(std::to_string(i));
79 result.append("\nIsSimActive = ");
80 result.append(GetBoolValue(CoreManagerInner::GetInstance().IsSimActive(i)));
81 result.append("\nIsNrSupported = ");
82 result.append(GetBoolValue(DelayedSingleton<CoreService>::GetInstance()->IsNrSupported(i)));
83 result.append("\nSignalLevel = ");
84 std::vector<sptr<SignalInformation>> signals;
85 DelayedSingleton<CoreService>::GetInstance()->GetSignalInfoList(i, signals);
86 if (signals.size() != 0 && signals[0] != nullptr) {
87 result.append(std::to_string(signals[0]->GetSignalLevel()));
88 }
89 result.append("\nCardType = ");
90 CardType cardType = CardType::UNKNOWN_CARD;
91 DelayedSingleton<CoreService>::GetInstance()->GetCardType(i, cardType);
92 result.append(GetCardType(static_cast<int32_t>(cardType)));
93 result.append("\nSimState = ");
94 SimState simState = SimState::SIM_STATE_UNKNOWN;
95 CoreManagerInner::GetInstance().GetSimState(i, simState);
96 result.append(GetSimState(static_cast<int32_t>(simState)));
97 result.append("\nSpn = ");
98 std::u16string spn;
99 DelayedSingleton<CoreService>::GetInstance()->GetSimSpn(i, spn);
100 result.append(to_utf8(spn));
101 result.append("\nOperatorName = ");
102 std::u16string operatorName;
103 DelayedSingleton<CoreService>::GetInstance()->GetOperatorName(i, operatorName);
104 result.append(to_utf8(operatorName));
105 int32_t csRadioTech = 0;
106 int32_t psRadioTech = 0;
107 DelayedSingleton<CoreService>::GetInstance()->GetPsRadioTech(i, psRadioTech);
108 DelayedSingleton<CoreService>::GetInstance()->GetCsRadioTech(i, csRadioTech);
109 result.append("\nPsRadioTech = ");
110 result.append(GetCellularDataConnectionNetworkType(psRadioTech));
111 result.append("\nCsRadioTech = ");
112 result.append(GetCellularDataConnectionNetworkType(csRadioTech));
113 result.append("\n");
114 }
115 }
116 result.append("\n");
117 }
118 } // namespace Telephony
119 } // namespace OHOS