diff --git a/services/time_manager/src/time_service_client.cpp b/services/time_manager/src/time_service_client.cpp index 0bd86b8..6a925bc 100644 --- a/services/time_manager/src/time_service_client.cpp +++ b/services/time_manager/src/time_service_client.cpp @@ -447,11 +447,7 @@ bool TimeServiceClient::ProxyTimer(int32_t uid, bool isProxy) TIME_HILOGE(TIME_MODULE_CLIENT, "ProxyTimer ConnectService failed."); return false; } - if (timeServiceProxy_->ProxyTimer(uid, isProxy) != ERR_OK) { - return false; - } - TIME_HILOGD(TIME_MODULE_CLIENT, "end"); - return true; + return timeServiceProxy_->ProxyTimer(uid, isProxy); } bool TimeServiceClient::ResetAllProxy() @@ -465,11 +461,7 @@ bool TimeServiceClient::ResetAllProxy() TIME_HILOGE(TIME_MODULE_CLIENT, "ResetAllProxy ConnectService failed."); return false; } - if (timeServiceProxy_->ResetAllProxy() != ERR_OK) { - return false; - } - TIME_HILOGD(TIME_MODULE_CLIENT, "end"); - return true; + return timeServiceProxy_->ResetAllProxy(); } } // namespace MiscServices } // namespace OHOS diff --git a/services/time_manager/test/unittest/src/time_service_test.cpp b/services/time_manager/test/unittest/src/time_service_test.cpp index d3c894b..dc65be3 100644 --- a/services/time_manager/test/unittest/src/time_service_test.cpp +++ b/services/time_manager/test/unittest/src/time_service_test.cpp @@ -15,6 +15,7 @@ #include #include #include +#include "ipc_skeleton.h" #include "timer_info_test.h" #include "time_service_test.h" @@ -306,3 +307,88 @@ HWTEST_F(TimeServiceTest, CreateTimer006, TestSize.Level0) ret = TimeServiceClient::GetInstance()->StopTimer(timerId1); EXPECT_FALSE(ret); } + +/** +* @tc.name: ProxyTimer001. +* @tc.desc: proxy timer. +* @tc.type: FUNC +*/ +HWTEST_F(TimeServiceTest, ProxyTimer001, TestSize.Level0) +{ + auto timerInfo = std::make_shared(); + timerInfo->SetType(1); + timerInfo->SetRepeat(true); + timerInfo->SetInterval(5000); + timerInfo->SetWantAgent(nullptr); + timerInfo->SetCallbackInfo(TimeOutCallback1); + + auto timerId1 = TimeServiceClient::GetInstance()->CreateTimer(timerInfo); + EXPECT_TRUE(timerId1 > 0); + auto ret = TimeServiceClient::GetInstance()->StartTimer(timerId1, 1000); + EXPECT_TRUE(ret); + int32_t uid = IPCSkeleton::GetCallingUid(); + ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, true); + EXPECT_TRUE(ret); + ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, false); + EXPECT_TRUE(ret); + ret = TimeServiceClient::GetInstance()->StopTimer(timerId1); + EXPECT_TRUE(ret); + ret = TimeServiceClient::GetInstance()->DestroyTimer(timerId1); + EXPECT_TRUE(ret); +} + +/** +* @tc.name: ProxyTimer002. +* @tc.desc: proxy timer. +* @tc.type: FUNC +*/ +HWTEST_F(TimeServiceTest, ProxyTimer002, TestSize.Level0) +{ + auto timerInfo = std::make_shared(); + timerInfo->SetType(1); + timerInfo->SetRepeat(true); + timerInfo->SetInterval(5000); + timerInfo->SetWantAgent(nullptr); + timerInfo->SetCallbackInfo(TimeOutCallback1); + + auto timerId1 = TimeServiceClient::GetInstance()->CreateTimer(timerInfo); + EXPECT_TRUE(timerId1 > 0); + auto ret = TimeServiceClient::GetInstance()->StartTimer(timerId1, 1000); + EXPECT_TRUE(ret); + int32_t uid = IPCSkeleton::GetCallingUid(); + ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, true); + EXPECT_TRUE(ret); + ret = TimeServiceClient::GetInstance()->ResetAllProxy(); + EXPECT_TRUE(ret); + ret = TimeServiceClient::GetInstance()->StopTimer(timerId1); + EXPECT_TRUE(ret); + ret = TimeServiceClient::GetInstance()->DestroyTimer(timerId1); + EXPECT_TRUE(ret); +} + +/** +* @tc.name: ProxyTimer003. +* @tc.desc: proxy timer. +* @tc.type: FUNC +*/ +HWTEST_F(TimeServiceTest, ProxyTimer003, TestSize.Level0) +{ + auto timerInfo = std::make_shared(); + timerInfo->SetType(1); + timerInfo->SetRepeat(true); + timerInfo->SetInterval(5000); + timerInfo->SetWantAgent(nullptr); + timerInfo->SetCallbackInfo(TimeOutCallback1); + + auto timerId1 = TimeServiceClient::GetInstance()->CreateTimer(timerInfo); + EXPECT_TRUE(timerId1 > 0); + auto ret = TimeServiceClient::GetInstance()->StartTimer(timerId1, 1000); + EXPECT_TRUE(ret); + int32_t uid = IPCSkeleton::GetCallingUid(); + ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, false); + EXPECT_FALSE(ret); + ret = TimeServiceClient::GetInstance()->StopTimer(timerId1); + EXPECT_TRUE(ret); + ret = TimeServiceClient::GetInstance()->DestroyTimer(timerId1); + EXPECT_TRUE(ret); +} \ No newline at end of file diff --git a/services/timer/include/timer_manager_interface.h b/services/timer/include/timer_manager_interface.h index d68ef8e..bf7dd2a 100644 --- a/services/timer/include/timer_manager_interface.h +++ b/services/timer/include/timer_manager_interface.h @@ -56,6 +56,8 @@ public: virtual bool StopTimer(uint64_t timerNumber) = 0; virtual bool DestroyTimer(uint64_t timerNumber) = 0; virtual ~ITimerManager() = default; + virtual bool ProxyTimer(int32_t uid, bool isProxy) = 0; + virtual bool ResetAllProxy() = 0; }; // ITimerManager } // MiscService } // OHOS