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