diff --git a/BUILD.gn b/BUILD.gn index 4aea17523763393ef9913bcaeb66666fab16cb78..728a16c2f065cad50d0f2cd847f1bc3bafccb200 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -18,6 +18,7 @@ declare_args() { !defined(global_parts_info.hiviewdfx_hicollie)) { telephony_cellular_data_hicollie_able = false } + cellular_data_feature_base_power_improvement = false } telephony_extra_defines = [] @@ -32,10 +33,6 @@ if (defined(global_parts_info) && TELEPHONY_EXT_WRAPPER_ROOT = "services/telephony_ext_wrapper" DATA_SERVICE_EXT_WRAPPER_ROOT = "services/data_service_ext_wrapper" -declare_args() { - cellular_data_feature_base_power_improvement = true -} - ohos_shared_library("tel_cellular_data") { sanitize = { cfi = true diff --git a/frameworks/js/napi/src/cellular_data_handler.cpp b/frameworks/js/napi/src/cellular_data_handler.cpp index 88879940c4726191dae159237acc98a9f0913de6..3b0641165b3397884a4b72e28008065af53d3e17 100644 --- a/frameworks/js/napi/src/cellular_data_handler.cpp +++ b/frameworks/js/napi/src/cellular_data_handler.cpp @@ -1064,12 +1064,6 @@ void CellularDataHandler::HandleDisconnectDataCompleteForMmsType(sptr SetDataPermittedForMms(false); RemoveEvent(CellularDataEventCode::MSG_RESUME_DATA_PERMITTED_TIMEOUT); } -#ifdef BASE_POWER_IMPROVEMENT - if (strEnterSubscriber_ != nullptr && strEnterSubscriber_->powerSaveFlag_) { - strEnterSubscriber_->FinishTelePowerEvent(); - strEnterSubscriber_->powerSaveFlag_ = false; - } -#endif } void CellularDataHandler::RetryOrClearConnection(const sptr &apnHolder, DisConnectionReason reason, diff --git a/services/include/cellular_data_power_save_mode_subscriber.h b/services/include/cellular_data_power_save_mode_subscriber.h index 43de4735e7e144462fcecc413bdb7fd6f7575140..873095c4320bb94eab553c45611c8dc06deba22e 100644 --- a/services/include/cellular_data_power_save_mode_subscriber.h +++ b/services/include/cellular_data_power_save_mode_subscriber.h @@ -1,43 +1,42 @@ -/* - * Copyright (C) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DATA_CONNECTION_POWER_STR_MANAGER_H -#define DATA_CONNECTION_POWER_STR_MANAGER_H - -#include "common_event_subscriber.h" - -namespace OHOS { -namespace Telephony { -class CellularDataHandler; -class CellularDataPowerSaveModeSubscriber : public EventFwk::CommonEventSubscriber { -public: - explicit CellularDataPowerSaveModeSubscriber( - const EventFwk::CommonEventSubscribeInfo &info, std::weak_ptr &handler) - : CommonEventSubscriber(info), powerSaveModeCellularDataHandler_(handler) {} - ~CellularDataPowerSaveModeSubscriber() = default; - void OnReceiveEvent(const EventFwk::CommonEventData &data) override; - bool FinishTelePowerEvent(); - static inline bool powerSaveFlag_ = false; -private: - void HandleEnterStrEvent(std::string &action); - void HandleExitStrEvent(std::string &action); - std::shared_ptr strAsyncCommonEvent_ = nullptr; - std::weak_ptr powerSaveModeCellularDataHandler_; - static inline std::string lastMsg = ""; - static inline bool savedCellularDataStatus_ = true; -}; -} // namespace Telephony -} // namespace OHOS -#endif \ No newline at end of file +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DATA_CONNECTION_POWER_STR_MANAGER_H +#define DATA_CONNECTION_POWER_STR_MANAGER_H + +#include "common_event_subscriber.h" + +namespace OHOS { +namespace Telephony { +class CellularDataHandler; +class CellularDataPowerSaveModeSubscriber : public EventFwk::CommonEventSubscriber { +public: + explicit CellularDataPowerSaveModeSubscriber( + const EventFwk::CommonEventSubscribeInfo &info, std::weak_ptr &handler) + : CommonEventSubscriber(info), powerSaveModeCellularDataHandler_(handler) {} + ~CellularDataPowerSaveModeSubscriber() = default; + void OnReceiveEvent(const EventFwk::CommonEventData &data) override; + bool FinishTelePowerCommonEvent(); +private: + void HandleEnterStrEvent(std::string &action); + void HandleExitStrEvent(std::string &action); + std::shared_ptr strAsyncCommonEvent_ = nullptr; + std::weak_ptr powerSaveModeCellularDataHandler_; + static inline std::string lastMsg = ""; + static inline bool savedCellularDataStatus_ = true; +}; +} // namespace Telephony +} // namespace OHOS +#endif diff --git a/services/src/cellular_data_power_save_mode_subscriber.cpp b/services/src/cellular_data_power_save_mode_subscriber.cpp index 4bef80f6b62c01fcfaa8fc83eb56b43ba0b1b5e8..c36bb372df0eaf5c64d85307405eb98ef10ca483 100644 --- a/services/src/cellular_data_power_save_mode_subscriber.cpp +++ b/services/src/cellular_data_power_save_mode_subscriber.cpp @@ -30,8 +30,13 @@ void CellularDataPowerSaveModeSubscriber::OnReceiveEvent(const EventFwk::CommonE HandleEnterStrEvent(action); } else if (action == EXIT_STR_TELEPHONY_NOTIFY) { TELEPHONY_LOGI("Exit str mode"); - HandleExitStrEvent(action); + int32_t reason = data.GetCode(); + // process only in user operation + if (reason == 1) { + HandleExitStrEvent(action); + } } + FinishTelePowerCommonEvent(); } void CellularDataPowerSaveModeSubscriber::HandleEnterStrEvent(std::string &action) @@ -40,23 +45,19 @@ void CellularDataPowerSaveModeSubscriber::HandleEnterStrEvent(std::string &actio if (action != lastMsg) { auto powerSaveModeCellularDataHandler = powerSaveModeCellularDataHandler_.lock(); if (powerSaveModeCellularDataHandler != nullptr) { + powerSaveModeCellularDataHandler->ClearAllConnections(DisConnectionReason::REASON_CLEAR_CONNECTION); int32_t ret = powerSaveModeCellularDataHandler->IsCellularDataEnabled(savedCellularDataStatus_); TELEPHONY_LOGI("Backup cellular status = %{public}d, ret = %{public}d", savedCellularDataStatus_, ret); - // ensure HandleDisconnectDataCompleteForMmsType reply event only in enter str mode - powerSaveFlag_ = true; powerSaveModeCellularDataHandler->SetCellularDataEnable(false); } } else { TELEPHONY_LOGI("Recv same msg in succession lastMsg:%{public}s", lastMsg.c_str()); - FinishTelePowerEvent(); } lastMsg = ENTER_STR_TELEPHONY_NOTIFY; } void CellularDataPowerSaveModeSubscriber::HandleExitStrEvent(std::string &action) { - // reply common event firt due to activate cellular too slow - FinishTelePowerEvent(); if (action != lastMsg) { auto powerSaveModeCellularDataHandler = powerSaveModeCellularDataHandler_.lock(); if (powerSaveModeCellularDataHandler != nullptr) { @@ -69,12 +70,12 @@ void CellularDataPowerSaveModeSubscriber::HandleExitStrEvent(std::string &action lastMsg = EXIT_STR_TELEPHONY_NOTIFY; } -bool CellularDataPowerSaveModeSubscriber::FinishTelePowerEvent() +bool CellularDataPowerSaveModeSubscriber::FinishTelePowerCommonEvent() { bool replyRet = false; if (strAsyncCommonEvent_ != nullptr) { replyRet = strAsyncCommonEvent_->FinishCommonEvent(); - TELEPHONY_LOGI("FinishTelePowerEvent replyRet = %{public}d", replyRet); + TELEPHONY_LOGI("FinishTelePowerCommonEvent replyRet = %{public}d", replyRet); } else { TELEPHONY_LOGE("strAsyncCommonEvent_ is nullptr"); } diff --git a/test/cellular_data_handler_test.cpp b/test/cellular_data_handler_test.cpp index 2e805013855d8952f73144d9938b424c1a011f7d..584f042758bebf345166cf184304af57ea8dc864 100644 --- a/test/cellular_data_handler_test.cpp +++ b/test/cellular_data_handler_test.cpp @@ -1162,40 +1162,5 @@ HWTEST_F(CellularDataHandlerTest, IsCellularDataEnabledTest001, Function | Mediu cellularDataHandler->dataSwitchSettings_->lastQryRet_ = TELEPHONY_ERR_SUCCESS; EXPECT_EQ(cellularDataHandler->IsCellularDataEnabled(isDataEnabled), TELEPHONY_ERR_SUCCESS); } - -/** -@tc.number Telephony_HandleDisconnectDataCompleteForMmsType -@tc.name HandleDisconnectDataCompleteForMmsType -@tc.desc Function test -*/ -#ifdef BASE_POWER_IMPROVEMENT -HWTEST_F(CellularDataHandlerTest, HandleDisconnectDataCompleteForMmsTypeTest001, Function | MediumTest | Level1) -{ - int32_t slotId = 0; - EventFwk::MatchingSkills matchingSkills; - EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); - auto cellularDataHandler = std::make_shared(subscriberInfo, slotId); - cellularDataHandler->Init(); - cellularDataHandler->SubscribeTelePowerEvent(); - cellularDataHandler->strEnterSubscriber_->powerSaveFlag_ = true; - std::string apnType = DATA_CONTEXT_ROLE_MMS; - sptr apnHolder = new ApnHolder(apnType, slotId); - cellularDataHandler->HandleDisconnectDataCompleteForMmsType(apnHolder); - EXPECT_EQ(cellularDataHandler->strEnterSubscriber_->powerSaveFlag_, false); -} - -HWTEST_F(CellularDataHandlerTest, HandleDisconnectDataCompleteForMmsTypeTest002, Function | MediumTest | Level1) -{ - int32_t slotId = 0; - EventFwk::MatchingSkills matchingSkills; - EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); - auto cellularDataHandler = std::make_shared(subscriberInfo, slotId); - cellularDataHandler->Init(); - std::string apnType = DATA_CONTEXT_ROLE_MMS; - sptr apnHolder = new ApnHolder(apnType, slotId); - cellularDataHandler->HandleDisconnectDataCompleteForMmsType(apnHolder); - EXPECT_EQ(cellularDataHandler->strEnterSubscriber_, nullptr); -} -#endif } // namespace Telephony } // namespace OHOS \ No newline at end of file diff --git a/test/cellular_data_power_save_mode_subscriber_test.cpp b/test/cellular_data_power_save_mode_subscriber_test.cpp index 14ef5462753ebc98b4ada1dc7fc59e241643fe7b..3c9d99008235b4362e007b908a5e2819abf96ce7 100644 --- a/test/cellular_data_power_save_mode_subscriber_test.cpp +++ b/test/cellular_data_power_save_mode_subscriber_test.cpp @@ -45,7 +45,7 @@ HWTEST_F(CellularDataPowerSaveModeSubscriberTest, CellularDataPowerSaveModeSubsc auto subscriber = cellularDataHandler->strEnterSubscriber_; cellularDataHandler = nullptr; subscriber->HandleEnterStrEvent(action); - EXPECT_EQ(subscriber->powerSaveFlag_, false); + EXPECT_EQ(subscriber->GetPowerSaveFlag(), false); } HWTEST_F(CellularDataPowerSaveModeSubscriberTest, CellularDataPowerSaveModeSubscriber_02, @@ -74,6 +74,7 @@ HWTEST_F(CellularDataPowerSaveModeSubscriberTest, CellularDataPowerSaveModeSubsc auto want = EventFwk::Want(); want.SetAction(EXIT_STR_TELEPHONY_NOTIFY); auto event = EventFwk::CommonEventData(want); + event.SetCode(1); cellularDataHandler->strExitSubscriber_->OnReceiveEvent(event); EXPECT_EQ(cellularDataHandler->strExitSubscriber_->lastMsg, EXIT_STR_TELEPHONY_NOTIFY); } @@ -105,6 +106,7 @@ HWTEST_F(CellularDataPowerSaveModeSubscriberTest, CellularDataPowerSaveModeSubsc auto want = EventFwk::Want(); want.SetAction(EXIT_STR_TELEPHONY_NOTIFY); auto event = EventFwk::CommonEventData(want); + event.SetCode(1); cellularDataHandler->strExitSubscriber_->OnReceiveEvent(event); cellularDataHandler->strExitSubscriber_->OnReceiveEvent(event); EXPECT_EQ(cellularDataHandler->strExitSubscriber_->lastMsg, EXIT_STR_TELEPHONY_NOTIFY); @@ -126,7 +128,7 @@ HWTEST_F(CellularDataPowerSaveModeSubscriberTest, CellularDataPowerSaveModeSubsc cellularDataHandler->strEnterSubscriber_->strAsyncCommonEvent_ = std::make_shared(resultCode, resultData, ordered, sticky, token); auto want = EventFwk::Want(); - bool ret = cellularDataHandler->strEnterSubscriber_->FinishTelePowerEvent(); + bool ret = cellularDataHandler->strEnterSubscriber_->FinishTelePowerCommonEvent(); EXPECT_EQ(ret, false); } @@ -139,7 +141,7 @@ HWTEST_F(CellularDataPowerSaveModeSubscriberTest, CellularDataPowerSaveModeSubsc auto cellularDataHandler = std::make_shared(subscriberInfo, 0); cellularDataHandler->SubscribeTelePowerEvent(); cellularDataHandler->strEnterSubscriber_->strAsyncCommonEvent_ = nullptr; - bool ret = cellularDataHandler->strEnterSubscriber_->FinishTelePowerEvent(); + bool ret = cellularDataHandler->strEnterSubscriber_->FinishTelePowerCommonEvent(); EXPECT_EQ(ret, false); }