diff --git a/frameworks/native/src/cellular_call_proxy.cpp b/frameworks/native/src/cellular_call_proxy.cpp index 6f9881d5ff7fb8075fd94241dac52cd86ff17867..c9295553924054bc0a304309f4108ad16f90ad63 100644 --- a/frameworks/native/src/cellular_call_proxy.cpp +++ b/frameworks/native/src/cellular_call_proxy.cpp @@ -1688,5 +1688,31 @@ int32_t CellularCallProxy::SendUssdResponse(int32_t slotId, const std::string &c } return ret; } + +bool CellularCallProxy::IsMmiCode(int32_t slotId, std::string &number) +{ + MessageOption option; + MessageParcel in; + MessageParcel out; + int32_t result = TELEPHONY_SUCCESS; + result = SetCommonParamForMessageParcel(slotId, in); + if (result != TELEPHONY_SUCCESS) { + return false; + } + if (!in.WriteString(number)) { + return false; + } + auto remote = Remote(); + if (remote == nullptr) { + TELEPHONY_LOGE("function Remote() return nullptr!"); + return false; + } + int32_t ret = remote->SendRequest(static_cast(CellularCallInterfaceCode::IS_MMI_CODE), + in, out, option); + if (ret == ERR_NONE) { + return out.ReadBool(); + } + return false; +} } // namespace Telephony } // namespace OHOS diff --git a/interfaces/innerkits/cellular_call_interface.h b/interfaces/innerkits/cellular_call_interface.h index edc9ea4ce911065ded80277054a727dca68fce98..8c6a09b0de433163d64959de07e9089da25bdc79 100644 --- a/interfaces/innerkits/cellular_call_interface.h +++ b/interfaces/innerkits/cellular_call_interface.h @@ -554,6 +554,15 @@ public: */ virtual int32_t SendUssdResponse(int32_t slotId, const std::string &content) = 0; + /** + * @brief is mmi code + * + * @param slotId[in] the slot id + * @param number[in] the phone number + * @return Returns true on phone number is mmi code, else return false. + */ + virtual bool IsMmiCode(int32_t slotId, std::string &number) = 0; + public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Telephony.CellularCallInterface"); }; diff --git a/interfaces/innerkits/cellular_call_ipc_interface_code.h b/interfaces/innerkits/cellular_call_ipc_interface_code.h index 9fe5d89a78206a3f975883015d8ec53c7de34ed8..78de4a5229c1e0005a5b4fc428a0aacb57b5e687 100644 --- a/interfaces/innerkits/cellular_call_ipc_interface_code.h +++ b/interfaces/innerkits/cellular_call_ipc_interface_code.h @@ -62,6 +62,7 @@ enum class CellularCallInterfaceCode { SET_CALL_RESTRICTION_PWD, GET_VIDEO_CALL_WAITING, SEND_USSD_RESPONSE, + IS_MMI_CODE, /****************** config ******************/ SET_DOMAIN_PREFERENCE_MODE = 300, diff --git a/interfaces/innerkits/cellular_call_proxy.h b/interfaces/innerkits/cellular_call_proxy.h index 4a29628c075ac1fe442b24dc0d82ac8bc12174f8..7cb1189a70d742f750e8baebc87da25bfff4792d 100644 --- a/interfaces/innerkits/cellular_call_proxy.h +++ b/interfaces/innerkits/cellular_call_proxy.h @@ -565,6 +565,15 @@ public: */ int32_t SendUssdResponse(int32_t slotId, const std::string &content) override; + /** + * @brief is mmi code + * + * @param slotId[in] the slot id + * @param number[in] the phone number + * @return Returns true on phone number is mmi code, else return false. + */ + bool IsMmiCode(int32_t slotId, std::string &number) override; + private: /** * @brief SetCommonParamForMessageParcel, set common param for MessageParcel diff --git a/services/call/src/call_request_process.cpp b/services/call/src/call_request_process.cpp index 3bd18c84d0808e21d7522ba558dfa25b29d6c33e..362cb5a8e94d9cdc2387c3540dc06e20efba6d01 100644 --- a/services/call/src/call_request_process.cpp +++ b/services/call/src/call_request_process.cpp @@ -834,7 +834,7 @@ int32_t CallRequestProcess::CarrierDialProcess(DialParaInfo &info) std::string tempNumber = info.number; bool isMMiCode = false; if (!info.isEcc) { - isMMiCode = DelayedSingleton::GetInstance()->IsMMICode(newPhoneNum); + isMMiCode = DelayedSingleton::GetInstance()->IsMmiCode(info.accountId, newPhoneNum); } if (!isMMiCode) { isFirstDialCallAdded_ = false; diff --git a/services/telephony_interaction/include/cellular_call_connection.h b/services/telephony_interaction/include/cellular_call_connection.h index 8347c5474f1feb9c18ab4afa00324bb1e2302d82..a6f936049ad0be8dc7438dc68d03e1b90e417923 100644 --- a/services/telephony_interaction/include/cellular_call_connection.h +++ b/services/telephony_interaction/include/cellular_call_connection.h @@ -572,6 +572,15 @@ public: */ int32_t SendUssdResponse(int32_t slotId, const std::string &content); + /** + * @brief is mmi code + * + * @param slotId[in] the slot id + * @param number[in] the phone number + * @return Returns true on phone number is mmi code, else return false. + */ + bool IsMmiCode(int32_t slotId, std::string &number); + private: int32_t ConnectService(); int32_t RegisterCallBackFun(); diff --git a/services/telephony_interaction/src/cellular_call_connection.cpp b/services/telephony_interaction/src/cellular_call_connection.cpp index 0c95f45e3427cfa78233e043a656e167325bd67f..b29251e1a8a7fbcd6bf9da7cd5138fcfd0660fc9 100644 --- a/services/telephony_interaction/src/cellular_call_connection.cpp +++ b/services/telephony_interaction/src/cellular_call_connection.cpp @@ -1008,5 +1008,14 @@ int32_t CellularCallConnection::SendUssdResponse(int32_t slotId, const std::stri } return TELEPHONY_SUCCESS; } + +bool CellularCallConnection::IsMmiCode(int32_t slotId, std::string &number) +{ + if (ReConnectService() != TELEPHONY_SUCCESS) { + TELEPHONY_LOGE("ipc reconnect failed!"); + return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL; + } + return cellularCallInterfacePtr_->IsMmiCode(slotId, number); +} } // namespace Telephony } // namespace OHOS diff --git a/test/unittest/call_manager_zero_gtest/src/zero_branch1_test.cpp b/test/unittest/call_manager_zero_gtest/src/zero_branch1_test.cpp index 5b779d9dd4387522dc553947f32b4ee4418ed425..9a33fb37766b60d851c82abf895d12ee28818af7 100644 --- a/test/unittest/call_manager_zero_gtest/src/zero_branch1_test.cpp +++ b/test/unittest/call_manager_zero_gtest/src/zero_branch1_test.cpp @@ -1132,10 +1132,10 @@ HWTEST_F(ZeroBranch2Test, Telephony_CallDialog_001, Function | MediumTest | Leve */ HWTEST_F(ZeroBranch2Test, Telephony_CallNumberUtils_003, Function | MediumTest | Level1) { - auto callNumUtils = DelayedSingleton::GetInstance(); - EXPECT_NE(callNumUtils, nullptr); + auto cellularCallConnection = DelayedSingleton::GetInstance(); + EXPECT_NE(cellularCallConnection, nullptr); std::string dialStr = ""; - ASSERT_FALSE(callNumUtils->IsMMICode(dialStr)); + ASSERT_FALSE(cellularCallConnection->IsMmiCode(0, dialStr)); DialParaInfo dialInfo; sptr call = new IMSCall(dialInfo); call->callId_ = 1; @@ -1145,34 +1145,34 @@ HWTEST_F(ZeroBranch2Test, Telephony_CallNumberUtils_003, Function | MediumTest | call->SetCallType(CallType::TYPE_IMS); CallObjectManager::AddOneCallObject(call); dialStr = "333"; - ASSERT_FALSE(callNumUtils->IsMMICode(dialStr)); + ASSERT_FALSE(cellularCallConnection->IsMmiCode(0,dialStr)); dialStr = "33"; - ASSERT_TRUE(callNumUtils->IsMMICode(dialStr)); + ASSERT_TRUE(cellularCallConnection->IsMmiCode(0, dialStr)); CallObjectManager::DeleteOneCallObject(call); dialStr = "333"; - ASSERT_FALSE(callNumUtils->IsMMICode(dialStr)); + ASSERT_FALSE(cellularCallConnection->IsMmiCode(0, dialStr)); dialStr = "12"; - ASSERT_FALSE(callNumUtils->IsMMICode(dialStr)); + ASSERT_FALSE(cellularCallConnection->IsMmiCode(0, dialStr)); dialStr = "1*"; - ASSERT_TRUE(callNumUtils->IsMMICode(dialStr)); + ASSERT_TRUE(cellularCallConnection->IsMmiCode(0, dialStr)); dialStr = "*1"; - ASSERT_TRUE(callNumUtils->IsMMICode(dialStr)); + ASSERT_TRUE(cellularCallConnection->IsMmiCode(0, dialStr)); dialStr = "**"; - ASSERT_TRUE(callNumUtils->IsMMICode(dialStr)); + ASSERT_TRUE(cellularCallConnection->IsMmiCode(0, dialStr)); dialStr = "33"; - ASSERT_TRUE(callNumUtils->IsMMICode(dialStr)); + ASSERT_TRUE(cellularCallConnection->IsMmiCode(0, dialStr)); dialStr = "*21*10086#"; - ASSERT_TRUE(callNumUtils->IsMMICode(dialStr)); + ASSERT_TRUE(cellularCallConnection->IsMmiCode(0, dialStr)); dialStr = "10086"; - ASSERT_FALSE(callNumUtils->IsMMICode(dialStr)); + ASSERT_FALSE(cellularCallConnection->IsMmiCode(0, dialStr)); dialStr = "*30#10086"; - ASSERT_FALSE(callNumUtils->IsMMICode(dialStr)); + ASSERT_FALSE(cellularCallConnection->IsMmiCode(0, dialStr)); dialStr = "*33##123#"; - ASSERT_FALSE(callNumUtils->IsMMICode(dialStr)); + ASSERT_FALSE(cellularCallConnection->IsMmiCode(0, dialStr)); dialStr = "*10086#"; - ASSERT_TRUE(callNumUtils->IsMMICode(dialStr)); + ASSERT_TRUE(cellularCallConnection->IsMmiCode(0, dialStr)); dialStr = "#10086#"; - ASSERT_TRUE(callNumUtils->IsMMICode(dialStr)); + ASSERT_TRUE(cellularCallConnection->IsMmiCode(0, dialStr)); } } // namespace Telephony } // namespace OHOS diff --git a/utils/include/call_number_utils.h b/utils/include/call_number_utils.h index 3ed5e6c05eb6a1080246764619fe75bb7248023c..8a6d8e35c5d811feeb9a9c720bf78be5a92d99c5 100644 --- a/utils/include/call_number_utils.h +++ b/utils/include/call_number_utils.h @@ -25,19 +25,6 @@ namespace OHOS { namespace Telephony { -/** - * 3GPP TS 22.030 V4.0.0 (2001-03) 6.5.2 Structure of the MMI - * The following sequence of functions shall be used for the control of Supplementary Services: - * SELECT: Entry of the procedure information (may be a digit or a sequence of characters). - * SEND: Transmission of the information to the network. - * INDICATION: Call progress indications. - */ -struct MMIData { - std::string actionString = ""; - std::string serviceCode = ""; - std::string dialString = ""; -}; - class CallNumberUtils { DECLARE_DELAYED_SINGLETON(CallNumberUtils) public: @@ -56,8 +43,6 @@ public: int32_t CheckNumberIsEmergency(const std::string &phoneNumber, const int32_t slotId, bool &enabled); bool IsValidSlotId(int32_t slotId) const; int32_t IsCarrierVtConfig(const int32_t slotId, bool &enabled); - bool IsMMICode(std::string &number); - bool RegexMatchMmi(const std::string &number); std::string RemoveSeparatorsPhoneNumber(const std::string &phoneString); std::string RemovePostDialPhoneNumber(const std::string &phoneString); bool HasAlphabetInPhoneNum(const std::string &inputValue); @@ -69,14 +54,10 @@ public: void YellowPageAndMarkUpdate(const sptr &callObjectPtr); private: void ProcessSpace(std::string &number); - bool IsShortCode(const std::string &number); - bool IsShortCodeWithCellularCall(const std::string &number); - bool IsShortCodeWithoutCellularCall(const std::string &number); private: static const int16_t HAS_A_SLOT = 1; static const int16_t HAS_TWO_SLOT = 2; - MMIData mmiData_; }; } // namespace Telephony } // namespace OHOS diff --git a/utils/src/call_number_utils.cpp b/utils/src/call_number_utils.cpp index a1530da3573748ec02d8ebf10ec1df52ce1b0fda..b62a67b131f0f12e60547b617cda381498325f2c 100644 --- a/utils/src/call_number_utils.cpp +++ b/utils/src/call_number_utils.cpp @@ -32,8 +32,6 @@ namespace OHOS { namespace Telephony { -const int32_t MAX_LENGTH_SHORT_CODE = 2; - CallNumberUtils::CallNumberUtils() {} CallNumberUtils::~CallNumberUtils() {} @@ -181,63 +179,6 @@ bool CallNumberUtils::IsValidSlotId(int32_t slotId) const return false; } -bool CallNumberUtils::IsMMICode(std::string &number) -{ - if (number.empty()) { - TELEPHONY_LOGE("number is empty."); - return false; - } - if (IsShortCode(number)) { - TELEPHONY_LOGI("number is shortCode."); - return true; - } - if (RegexMatchMmi(number)) { - if (!mmiData_.serviceCode.empty() && !mmiData_.dialString.empty() && - (mmiData_.actionString == "*" || mmiData_.actionString == "#")) { - number = mmiData_.dialString; - TELEPHONY_LOGI("change number for dial"); - return false; - } - return true; - } - - if ((number.front() == '*' || number.front() == '#') && number.back() == '#') { - TELEPHONY_LOGI("number start with * or # and end with #"); - return true; - } - - return false; -} - -bool CallNumberUtils::RegexMatchMmi(const std::string &number) -{ - std::string symbols = - "((\\*|#|\\*#|\\*\\*|##)(\\d{2,3})(\\*([^*#]*)(\\*([^*#]*)(\\*([^*#]*)(\\*([^*#]*))?)?)?)?#)(.*)"; - std::regex pattern(symbols); - std::smatch results; - if (regex_match(number, results, pattern)) { - TELEPHONY_LOGI("regex_match true"); - /** - * The following sequence of functions shall be used for the control of Supplementary Services: - * SELECT: Entry of the procedure information (may be a digit or a sequence of characters). - * SEND: Transmission of the information to the network. - * INDICATION: Call progress indications. - */ - int32_t action = 2; - // 3GPP TS 22.030 V4.0.0 (2001-03) 6.5.2 Structure of the MMI - // This structure consists of the following parts: - // Service Code, SC( (2 or 3 digits) - // Supplementary Information, SI (variable length). - int32_t serviceCode = 3; - int32_t dialingNumber = 12; - mmiData_.actionString = results.str(action); - mmiData_.serviceCode = results.str(serviceCode); - mmiData_.dialString = results.str(dialingNumber); - return true; - } - return false; -} - std::string CallNumberUtils::RemoveSeparatorsPhoneNumber(const std::string &phoneString) { std::string newString; @@ -441,32 +382,5 @@ int32_t CallNumberUtils::QueryYellowPageAndMarkInfo(NumberMarkInfo &numberMarkIn } return TELEPHONY_SUCCESS; } - -bool CallNumberUtils::IsShortCode(const std::string &number) -{ - if (CallObjectManager::HasCellularCallExist()) { - return IsShortCodeWithCellularCall(number); - } - return IsShortCodeWithoutCellularCall(number); -} - -bool CallNumberUtils::IsShortCodeWithoutCellularCall(const std::string &number) -{ - if (number.length() > MAX_LENGTH_SHORT_CODE) { - return false; - } - if (number[0] == '1' && std::isdigit(number[1])) { - return false; - } - return true; -} - -bool CallNumberUtils::IsShortCodeWithCellularCall(const std::string &number) -{ - if (number.length() < 1 || number.length() > MAX_LENGTH_SHORT_CODE) { - return false; - } - return true; -} } // namespace Telephony } // namespace OHOS