• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "sms_dump_helper.h"
17 
18 #include "core_service_client.h"
19 #include "sms_service.h"
20 #include "telephony_log_wrapper.h"
21 
22 namespace OHOS {
23 namespace Telephony {
Dump(const std::vector<std::string> & args,std::string & result) const24 bool SmsDumpHelper::Dump(const std::vector<std::string> &args, std::string &result) const
25 {
26     result.clear();
27     ShowHelp(result);
28     ShowSmsInfo(result);
29     return true;
30 }
31 
SmsDumpHelper()32 SmsDumpHelper::SmsDumpHelper()
33 {
34     TELEPHONY_LOGI("SmsDumpHelper() entry.");
35 }
36 
to_utf8(std::u16string str16)37 static std::string to_utf8(std::u16string str16)
38 {
39     return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> {}.to_bytes(str16);
40 }
41 
WhetherHasSimCard(const int32_t slotId) const42 bool SmsDumpHelper::WhetherHasSimCard(const int32_t slotId) const
43 {
44     bool hasSimCard = false;
45     DelayedRefSingleton<CoreServiceClient>::GetInstance().HasSimCard(slotId, hasSimCard);
46     return hasSimCard;
47 }
48 
ShowHelp(std::string & result) const49 void SmsDumpHelper::ShowHelp(std::string &result) const
50 {
51     result.append("Usage:dump <command> [options]\n")
52         .append("Description:\n")
53         .append("-sms_mms_info          ")
54         .append("dump all sms_mms information in the system\n")
55         .append("-output_slot        ")
56         .append("default_slot_Id\n")
57         .append("-output_service_state")
58         .append("Output service state information\n");
59 }
60 
ShowSmsInfo(std::string & result) const61 void SmsDumpHelper::ShowSmsInfo(std::string &result) const
62 {
63     result.append("SmsService: \n");
64     result.append("BindTime = ");
65     result.append(DelayedSingleton<SmsService>::GetInstance()->GetBindTime());
66     result.append("\n");
67     result.append("SpendTime = ");
68     result.append(std::to_string(DelayedSingleton<SmsService>::GetInstance()->GetSpendTime()));
69     result.append("\n");
70     result.append("EndTime = ");
71     result.append(std::to_string(DelayedSingleton<SmsService>::GetInstance()->GetEndTime()));
72     result.append("\n");
73     result.append("ServiceRunningState: ");
74     result.append(std::to_string(DelayedSingleton<SmsService>::GetInstance()->GetServiceRunningState()));
75     result.append("\n");
76     result.append("DefaultSmsSlotId = ");
77     result.append(std::to_string(DelayedSingleton<SmsService>::GetInstance()->GetDefaultSmsSlotId()));
78     result.append("\n");
79     result.append("HasSmsCapability = ");
80     result.append(std::to_string(DelayedSingleton<SmsService>::GetInstance()->HasSmsCapability()));
81     result.append("\n");
82     for (int32_t i = 0; i < SIM_SLOT_COUNT; i++) {
83         if (WhetherHasSimCard(i)) {
84             result.append("SlotId = ");
85             result.append(std::to_string(i));
86             result.append("\n");
87             result.append("IsImsSmsSupported = ");
88             bool isSupported = false;
89             DelayedSingleton<SmsService>::GetInstance()->IsImsSmsSupported(i, isSupported);
90             result.append(std::to_string(isSupported));
91             result.append("\n");
92             result.append("ImsShortMessageFormat = ");
93             std::u16string format;
94             DelayedSingleton<SmsService>::GetInstance()->GetImsShortMessageFormat(format);
95             result.append(to_utf8(format));
96             result.append("\n");
97         }
98     }
99 }
100 } // namespace Telephony
101 } // namespace OHOS
102