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_call_dump_helper.h"
17 
18 #include "cellular_call_service.h"
19 #include "core_service_client.h"
20 #include "module_service_utils.h"
21 #include "standardize_utils.h"
22 
23 namespace OHOS {
24 namespace Telephony {
Dump(const std::vector<std::string> & args,std::string & result) const25 bool CellularCallDumpHelper::Dump(const std::vector<std::string> &args, std::string &result) const
26 {
27     result.clear();
28     ShowHelp(result);
29     ShowCellularCallInfo(result);
30     return true;
31 }
32 
WhetherHasSimCard(const int32_t slotId) const33 bool CellularCallDumpHelper::WhetherHasSimCard(const int32_t slotId) const
34 {
35     bool hasSimCard = false;
36     DelayedRefSingleton<CoreServiceClient>::GetInstance().HasSimCard(slotId, hasSimCard);
37     return hasSimCard;
38 }
39 
ShowHelp(std::string & result) const40 void CellularCallDumpHelper::ShowHelp(std::string &result) const
41 {
42     result.append("Usage       : dump <command> [options]\n")
43         .append("Description :\n")
44         .append("    -cellular_call_info      : ")
45         .append("dump all cellular_call information in the system\n");
46 }
47 
ShowCellularCallInfo(std::string & result) const48 void CellularCallDumpHelper::ShowCellularCallInfo(std::string &result) const
49 {
50     result.append("\n*******************CellularCallInfo*********************\n");
51     result.append("CellularCallBindTime      : ")
52         .append(DelayedSingleton<CellularCallService>::GetInstance()->GetBindTime())
53         .append("\n");
54     result.append("CellularCallEndTime       : ")
55         .append(DelayedSingleton<CellularCallService>::GetInstance()->GetEndTime())
56         .append("\n");
57     result.append("CellularCallSpendTime     : ")
58         .append(DelayedSingleton<CellularCallService>::GetInstance()->GetSpendTime())
59         .append("\n");
60     result.append("ServiceRunningState       : ")
61         .append(std::to_string(DelayedSingleton<CellularCallService>::GetInstance()->GetServiceRunningState()))
62         .append("\n");
63     result.append("SrvccState                : ")
64         .append(std::to_string(DelayedSingleton<CellularCallService>::GetInstance()->GetSrvccState()))
65         .append("\n");
66 
67     for (int32_t i = 0; i < SIM_SLOT_COUNT; i++) {
68         if (WhetherHasSimCard(i)) {
69             result.append("SlotId                    : ")
70                 .append(std::to_string(i))
71                 .append("\n");
72             CellularCallConfig config;
73             bool imsSwitchStatus = false;
74             config.GetImsSwitchStatus(i, imsSwitchStatus);
75             result.append("ImsServiceRunningState    : ")
76                 .append(std::to_string(imsSwitchStatus))
77                 .append("\n");
78             result.append("DomainPreferenceMode      : ")
79                 .append(std::to_string(config.GetPreferenceMode(i)))
80                 .append("\n");
81             result.append("VoiceActivationState      : ")
82                 .append(std::to_string(config.GetForceVolteSwitchOnConfig(i)))
83                 .append("\n");
84         }
85     }
86 }
87 } // namespace Telephony
88 } // namespace OHOS