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 "telephony_state_registry_dump_helper.h"
17
18 #include "core_service_client.h"
19 #include "telephony_types.h"
20 #include "enum_convert.h"
21
22 namespace OHOS {
23 namespace Telephony {
Dump(const std::vector<std::string> & args,std::vector<TelephonyStateRegistryRecord> & stateRecords,std::string & result) const24 bool TelephonyStateRegistryDumpHelper::Dump(const std::vector<std::string> &args,
25 std::vector<TelephonyStateRegistryRecord> &stateRecords, std::string &result) const
26 {
27 result.clear();
28 ShowTelephonyChangeState(result);
29 return ShowTelephonyStateRegistryInfo(stateRecords, result);
30 }
31
TelephonyStateRegistryDumpHelper()32 TelephonyStateRegistryDumpHelper::TelephonyStateRegistryDumpHelper() {}
33
WhetherHasSimCard(const int32_t slotId) const34 bool TelephonyStateRegistryDumpHelper::WhetherHasSimCard(const int32_t slotId) const
35 {
36 bool hasSimCard = false;
37 DelayedRefSingleton<CoreServiceClient>::GetInstance().HasSimCard(slotId, hasSimCard);
38 return hasSimCard;
39 }
40
ShowTelephonyStateRegistryInfo(std::vector<TelephonyStateRegistryRecord> & stateRecords,std::string & result) const41 bool TelephonyStateRegistryDumpHelper::ShowTelephonyStateRegistryInfo(
42 std::vector<TelephonyStateRegistryRecord> &stateRecords, std::string &result) const
43 {
44 result.append("registrations: count= ").append(std::to_string(stateRecords.size())).append("\n");
45 if (!stateRecords.empty()) {
46 for (const auto &item : stateRecords) {
47 if (item.IsExistStateListener(TelephonyObserverBroker::OBSERVER_MASK_DATA_CONNECTION_STATE)) {
48 result.append("CellularDataConnectState Register: ");
49 } else if (item.IsExistStateListener(TelephonyObserverBroker::OBSERVER_MASK_DATA_FLOW)) {
50 result.append("CellularDataFlow Register: ");
51 } else if (item.IsExistStateListener(TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE)) {
52 result.append("CallState Register: ");
53 } else if (item.IsExistStateListener(TelephonyObserverBroker::OBSERVER_MASK_SIM_STATE)) {
54 result.append("SimState Register: ");
55 } else if (item.IsExistStateListener(TelephonyObserverBroker::OBSERVER_MASK_SIGNAL_STRENGTHS)) {
56 result.append("SignalInfo Register: ");
57 } else if (item.IsExistStateListener(TelephonyObserverBroker::OBSERVER_MASK_CELL_INFO)) {
58 result.append("CellInfo Register: ");
59 } else if (item.IsExistStateListener(TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE)) {
60 result.append("NetworkState Register: ");
61 } else {
62 result.append("Unknown Subscriber: ");
63 }
64 result.append("\n").append(" { ");
65 result.append("package: ").append(item.bundleName_);
66 result.append(" pid: ").append(std::to_string(item.pid_));
67 result.append(" mask: ").append(std::to_string(item.mask_));
68 result.append(" slotId: ").append(std::to_string(item.slotId_));
69 result.append(" }");
70 result.append("\n");
71 }
72 }
73 return true;
74 }
75
ShowTelephonyChangeState(std::string & result) const76 void TelephonyStateRegistryDumpHelper::ShowTelephonyChangeState(std::string &result) const
77 {
78 std::shared_ptr<TelephonyStateRegistryService> service =
79 DelayedSingleton<TelephonyStateRegistryService>::GetInstance();
80 if (service == nullptr) {
81 TELEPHONY_LOGE("Get state registry service failed");
82 return;
83 }
84 result.append("TelephonyStateRegistry BindStartTime = ");
85 result.append(service->GetBindStartTime());
86 result.append("\n");
87 result.append("TelephonyStateRegistry BindEndTime = ");
88 result.append(service->GetBindEndTime());
89 result.append("\n");
90 result.append("TelephonyStateRegistry BindSpendTime = ");
91 result.append(service->GetBindSpendTime());
92 result.append("\n");
93 result.append("TelephonyStateRegistry ServiceRunningState = ");
94 result.append(std::to_string(service->GetServiceRunningState()));
95 result.append("\n");
96 for (int32_t i = 0; i < SIM_SLOT_COUNT; i++) {
97 if (WhetherHasSimCard(i)) {
98 result.append("SlotId = ");
99 result.append(std::to_string(i));
100 result.append("\n");
101 result.append("SimState = ");
102 result.append(GetSimState(service->GetSimState(i)));
103 result.append("\n");
104 result.append("CardType = ");
105 result.append(GetCardType(service->GetCardType(i)));
106 result.append("\n");
107 result.append("LockReason = ");
108 result.append(GetLockReason(service->GetLockReason(i)));
109 result.append("\n");
110 result.append("CallState = ");
111 result.append(GetCallState(service->GetCallState(i)));
112 result.append("\n");
113 result.append("CellularDataConnectionState = ");
114 result.append(GetCellularDataConnectionState(service->GetCellularDataConnectionState(i)));
115 result.append("\n");
116 result.append("CellularDataFlow = ");
117 result.append(GetCellularDataFlow(service->GetCellularDataFlow(i)));
118 result.append("\n");
119 result.append("CellularDataConnectionNetworkType = ");
120 result.append(GetCellularDataConnectionNetworkType(service->GetCellularDataConnectionNetworkType(i)));
121 result.append("\n");
122 }
123 }
124 }
125 } // namespace Telephony
126 } // namespace OHOS
127