From 3bd4bf92a34a766ad9ae900b128ea60fe93b46e9 Mon Sep 17 00:00:00 2001 From: xujunyang Date: Thu, 3 Jul 2025 21:26:40 +0800 Subject: [PATCH] Revert "!1032 update services/timer/src/timer_proxy.cpp." This reverts commit 8fedcd57c5f72d1bdfda57cb108858238425d985, reversing changes made to c1dc62047c91e054f5c1e3c3577ae6b705a54f64. Signed-off-by: xujunyang --- services/timer/include/timer_info.h | 1 - services/timer/src/timer_info.cpp | 25 ++----------------- services/timer/src/timer_proxy.cpp | 7 ++---- .../src/time_service_timer_test.cpp | 22 ---------------- 4 files changed, 4 insertions(+), 51 deletions(-) diff --git a/services/timer/include/timer_info.h b/services/timer/include/timer_info.h index d30c5ed8..2d8d68c1 100644 --- a/services/timer/include/timer_info.h +++ b/services/timer/include/timer_info.h @@ -89,7 +89,6 @@ public: bool RestoreProxyTimer(); bool AdjustTimer(const std::chrono::steady_clock::time_point &now, const uint32_t interval, const uint32_t delta); bool RestoreAdjustTimer(); - bool ChangeStatusToAdjust(); private: bool RestoreTimer(); }; diff --git a/services/timer/src/timer_info.cpp b/services/timer/src/timer_info.cpp index 1405d3ad..b1c56cda 100644 --- a/services/timer/src/timer_info.cpp +++ b/services/timer/src/timer_info.cpp @@ -199,42 +199,21 @@ bool TimerInfo::RestoreProxyTimer() return RestoreTimer(); } -bool TimerInfo::ChangeStatusToAdjust() -{ - //Change timer state - switch (state) { - case INIT: - case ADJUST: - state = ADJUST; - return true; - case PROXY: - TIME_HILOGD(TIME_MODULE_SERVICE, "Adjust timer in proxy state, id: %{public}" PRIu64 "", id); - break; - default: - TIME_HILOGD(TIME_MODULE_SERVICE, "Error state, id: %{public}" PRIu64 ", state: %{public}d", id, state); - } - return false; -} - bool TimerInfo::AdjustTimer(const std::chrono::steady_clock::time_point &now, const uint32_t interval, const uint32_t delta) { - if (!ChangeStatusToAdjust()) { - return false; - } - CalculateOriWhenElapsed(); auto oldWhenElapsed = whenElapsed; auto oldMaxWhenElapsed = maxWhenElapsed; std::chrono::duration> halfIntervalSec(interval); std::chrono::duration> intervalSec(interval); std::chrono::duration> deltaSec(delta); - auto oldTimeSec = std::chrono::duration_cast(originWhenElapsed.time_since_epoch()); + auto oldTimeSec = std::chrono::duration_cast(whenElapsed.time_since_epoch()); auto timeSec = ((oldTimeSec + halfIntervalSec) / intervalSec) * intervalSec + deltaSec; whenElapsed = std::chrono::steady_clock::time_point(timeSec); if (windowLength == std::chrono::milliseconds::zero()) { maxWhenElapsed = whenElapsed; } else { - auto oldMaxTimeSec = std::chrono::duration_cast(originMaxWhenElapsed.time_since_epoch()); + auto oldMaxTimeSec = std::chrono::duration_cast(maxWhenElapsed.time_since_epoch()); auto maxTimeSec = ((oldMaxTimeSec + halfIntervalSec) / intervalSec) * intervalSec + deltaSec; maxWhenElapsed = std::chrono::steady_clock::time_point(maxTimeSec); } diff --git a/services/timer/src/timer_proxy.cpp b/services/timer/src/timer_proxy.cpp index f3bec86a..87c6ede2 100644 --- a/services/timer/src/timer_proxy.cpp +++ b/services/timer/src/timer_proxy.cpp @@ -112,11 +112,8 @@ bool TimerProxy::UpdateAdjustWhenElapsed(const std::chrono::steady_clock::time_p TIME_HILOGD(TIME_MODULE_SERVICE, "adjust single time id: %{public}" PRId64 ", " "uid: %{public}d, bundleName: %{public}s", timer->id, timer->uid, timer->bundleName.c_str()); - auto ret = timer->AdjustTimer(now, interval, delta); - if (ret) { - adjustTimers_.insert(timer->id); - } - return ret; + adjustTimers_.insert(timer->id); + return timer->AdjustTimer(now, interval, delta); } bool TimerProxy::RestoreAdjustWhenElapsed(std::shared_ptr &timer) diff --git a/test/unittest/service_test/src/time_service_timer_test.cpp b/test/unittest/service_test/src/time_service_timer_test.cpp index 705b2361..a6d6857b 100644 --- a/test/unittest/service_test/src/time_service_timer_test.cpp +++ b/test/unittest/service_test/src/time_service_timer_test.cpp @@ -2072,28 +2072,6 @@ HWTEST_F(TimeServiceTimerTest, ReschedulePowerOnTimerLocked001, TestSize.Level0) } #endif -/** -* @tc.name: TimerInfo010. -* @tc.desc: test ChangeStatusToAdjust. -* @tc.type: FUNC -*/ -HWTEST_F(TimeServiceTimerTest, TimerInfo010, TestSize.Level0) -{ - auto zero = milliseconds(0); - std::chrono::steady_clock::time_point empty (zero); - auto timerInfo = TimerInfo("", 0, ITimerManager::ELAPSED_REALTIME, zero, empty, zero, empty, zero, nullptr, - nullptr, 0, false, 0, 0, ""); - EXPECT_EQ(timerInfo.state, TimerInfo::TimerState::INIT); - auto timePoint = std::chrono::steady_clock::now(); - timerInfo.AdjustTimer(timePoint, 1, 0); - EXPECT_TRUE(timerInfo.ChangeStatusToAdjust()); - EXPECT_EQ(timerInfo.state, TimerInfo::TimerState::ADJUST); - - timerInfo.ProxyTimer(empty, milliseconds(3000)); - EXPECT_EQ(timerInfo.state, TimerInfo::TimerState::PROXY); - EXPECT_FALSE(timerInfo.ChangeStatusToAdjust()); -} - /** * @tc.name: ResetAllProxy001. * @tc.desc: test RefreshNetworkTimeByTimer. -- Gitee