1 /*
2 * Copyright (C) 2021-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 "control_base.h"
17
18 #include "cellular_call_hisysevent.h"
19 #include "cellular_call_service.h"
20 #include "module_service_utils.h"
21 #include "standardize_utils.h"
22
23 namespace OHOS {
24 namespace Telephony {
DialPreJudgment(const CellularCallInfo & callInfo)25 int32_t ControlBase::DialPreJudgment(const CellularCallInfo &callInfo)
26 {
27 std::string dialString(callInfo.phoneNum);
28 if (dialString.empty()) {
29 TELEPHONY_LOGE("DialPreJudgment return, dialString is empty.");
30 CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.accountId, static_cast<int32_t>(callInfo.callType),
31 callInfo.videoState, CALL_ERR_PHONE_NUMBER_EMPTY, "dialString is empty");
32 return CALL_ERR_PHONE_NUMBER_EMPTY;
33 }
34
35 ModuleServiceUtils moduleServiceUtils;
36 if (!moduleServiceUtils.GetRadioState(callInfo.slotId)) {
37 TELEPHONY_LOGE("DialPreJudgment return, radio state error.");
38 CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.accountId, static_cast<int32_t>(callInfo.callType),
39 callInfo.videoState, CALL_ERR_GET_RADIO_STATE_FAILED, "radio state error");
40 return CALL_ERR_GET_RADIO_STATE_FAILED;
41 }
42 return TELEPHONY_SUCCESS;
43 }
44
IsNeedExecuteMMI(int32_t slotId,std::string & phoneString,CLIRMode & clirMode)45 bool ControlBase::IsNeedExecuteMMI(int32_t slotId, std::string &phoneString, CLIRMode &clirMode)
46 {
47 TELEPHONY_LOGI("IsNeedExecuteMMI start");
48 // Also supplementary services may be controlled using dial command according to 3GPP TS 22.030 [19].
49 // An example of call forwarding on no reply for telephony with the adjustment of the
50 // no reply condition timer on 25 seconds:
51 // Parse the MMI code from the string
52 std::unique_ptr<MMICodeUtils> mmiCodeUtils = std::make_unique<MMICodeUtils>();
53 // Parse the MMI code from the string
54 if (mmiCodeUtils == nullptr) {
55 TELEPHONY_LOGE("IsNeedExecuteMMI return, mmiCodeUtils is nullptr");
56 return false;
57 }
58 if (!mmiCodeUtils->IsNeedExecuteMmi(phoneString)) {
59 TELEPHONY_LOGI("IsNeedExecuteMMI return, isn't need to execute mmi");
60 return false;
61 }
62 if (mmiCodeUtils->GetMMIData().serviceCode == "30" && !mmiCodeUtils->GetMMIData().dialString.empty()) {
63 TELEPHONY_LOGI("IsNeedExecuteMMI, handle additional CLIR mode");
64 if (mmiCodeUtils->GetMMIData().actionString == "*") {
65 phoneString = mmiCodeUtils->GetMMIData().dialString;
66 clirMode = CLIRMode::TRANSFER;
67 return false;
68 } else if (mmiCodeUtils->GetMMIData().actionString == "#") {
69 phoneString = mmiCodeUtils->GetMMIData().dialString;
70 clirMode = CLIRMode::INHIBITION;
71 return false;
72 }
73 }
74 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
75 TELEPHONY_LOGI("IsNeedExecuteMMI return, GetInstance is nullptr");
76 return false;
77 }
78 if (DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId) == nullptr) {
79 TELEPHONY_LOGI("IsNeedExecuteMMI return, GetHandler is nullptr");
80 return false;
81 }
82 return DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId)->SendEvent(
83 MMIHandlerId::EVENT_MMI_Id, mmiCodeUtils);
84 }
85
IsDtmfKey(char c) const86 bool ControlBase::IsDtmfKey(char c) const
87 {
88 /**
89 * 1. <DTMF>. A single ASCII character in the set 0 9, #,*,A D. This is interpreted as a single ASCII character
90 * whose duration is set by the +VTD command. NOTE 2: In GSM this operates only in voice mode.
91 */
92 return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'D') || c == '*' || c == '#';
93 }
94
SetHangupReportIgnoredFlag(bool ignored)95 void ControlBase::SetHangupReportIgnoredFlag(bool ignored)
96 {
97 TELEPHONY_LOGI("SetHangupReportIgnoredFlag ignored:%{public}d", ignored);
98 isIgnoredHangupReport_ = ignored;
99 }
100 } // namespace Telephony
101 } // namespace OHOS
102