diff --git a/frameworks/ets/taihe/power/idl/ohos.power.taihe b/frameworks/ets/taihe/power/idl/ohos.power.taihe index ff6a90b56e3059a66d9c44c4d19a7ecd3515fad4..ab3a9fe0f20442da60a95c2de53a1bc6c2a507c7 100644 --- a/frameworks/ets/taihe/power/idl/ohos.power.taihe +++ b/frameworks/ets/taihe/power/idl/ohos.power.taihe @@ -40,9 +40,12 @@ function Hibernate(clearMemory: bool): void; function SetScreenOffTime(timeout: i64): void; +function RefreshActivity(reason: String): void; + enum DevicePowerMode : i32 { MODE_NORMAL = 600, MODE_POWER_SAVE, MODE_PERFORMANCE, - MODE_EXTREME_POWER_SAVE + MODE_EXTREME_POWER_SAVE, + MODE_CUSTOM_POWER_SAVE = 650 } \ No newline at end of file diff --git a/frameworks/ets/taihe/power/src/ohos.power.impl.cpp b/frameworks/ets/taihe/power/src/ohos.power.impl.cpp index 25547fd89651370a086c6730ccc5c6ea46c13554..706ac2b8b4072dc233a19fc29c46c950734cd6af 100644 --- a/frameworks/ets/taihe/power/src/ohos.power.impl.cpp +++ b/frameworks/ets/taihe/power/src/ohos.power.impl.cpp @@ -36,7 +36,8 @@ std::map g_errorTable = { {PowerErrors::ERR_CONNECTION_FAIL, "Failed to connect to the service."}, {PowerErrors::ERR_PERMISSION_DENIED, "Permission is denied" }, {PowerErrors::ERR_SYSTEM_API_DENIED, "System permission is denied" }, - {PowerErrors::ERR_PARAM_INVALID, "Invalid input parameter." } + {PowerErrors::ERR_PARAM_INVALID, "Invalid input parameter." }, + {PowerErrors::ERR_FREQUENT_FUNCTION_CALL, "Frequent function calls." } }; static PowerMgrClient& g_powerMgrClient = PowerMgrClient::GetInstance(); constexpr int32_t RESTORE_DEFAULT_SCREENOFF_TIME = -1; @@ -143,9 +144,13 @@ DevicePowerMode GetPowerMode() case PowerMode::EXTREME_POWER_SAVE_MODE: deviceMode = DevicePowerMode::key_t::MODE_EXTREME_POWER_SAVE; break; + case PowerMode::CUSTOM_POWER_SAVE_MODE: + deviceMode = DevicePowerMode::key_t::MODE_CUSTOM_POWER_SAVE; + break; default: POWER_HILOGE(FEATURE_POWER_MODE, "Unknown mode"); } + POWER_HILOGD(FEATURE_POWER_MODE, "%{public}s mode: %{public}d", __func__, static_cast(mode)); return deviceMode; } @@ -197,6 +202,16 @@ void SetScreenOffTime(int64_t timeout) taihe::set_business_error(static_cast(code), g_errorTable[code]); } } + +void RefreshActivity(string_view reason) +{ + PowerErrors code = g_powerMgrClient.RefreshActivity( + UserActivityType::USER_ACTIVITY_TYPE_APPLICATION, std::string(reason)); + if (code != PowerErrors::ERR_OK) { + POWER_HILOGE(FEATURE_ACTIVITY, "RefreshActivity failed. code:%{public}d", static_cast(code)); + taihe::set_business_error(static_cast(code), g_errorTable[code]); + } +} } // namespace // Since these macros are auto-generate, lint will cause false positive @@ -211,4 +226,5 @@ TH_EXPORT_CPP_API_SetPowerModeSync(SetPowerModeSync); TH_EXPORT_CPP_API_IsStandby(IsStandby); TH_EXPORT_CPP_API_Hibernate(Hibernate); TH_EXPORT_CPP_API_SetScreenOffTime(SetScreenOffTime); +TH_EXPORT_CPP_API_RefreshActivity(RefreshActivity); // NOLINTEND \ No newline at end of file diff --git a/frameworks/ets/taihe/power/test/unittest/power_taihe_native_test.cpp b/frameworks/ets/taihe/power/test/unittest/power_taihe_native_test.cpp index 27716027934f649668d6b1111e82d5d0f17fbac6..d2005943064f26267a68d1e151ad9a22f754fc00 100644 --- a/frameworks/ets/taihe/power/test/unittest/power_taihe_native_test.cpp +++ b/frameworks/ets/taihe/power/test/unittest/power_taihe_native_test.cpp @@ -107,6 +107,12 @@ PowerErrors PowerMgrClient::OverrideScreenOffTime(int64_t timeout, const std::st g_pass = true; return g_error; } + +PowerErrors PowerMgrClient::RefreshActivity(UserActivityType type, const std::string& refreshReason) +{ + g_pass = true; + return g_error; +} } // namespace OHOS::PowerMgr namespace { @@ -206,6 +212,8 @@ HWTEST_F(PowerTaiheNativeTest, PowerTaiheNativeTest_004, TestSize.Level1) GetPowerMode(); g_mode = PowerMode::EXTREME_POWER_SAVE_MODE; GetPowerMode(); + g_mode = PowerMode::CUSTOM_POWER_SAVE_MODE; + GetPowerMode(); g_mode = static_cast(0); GetPowerMode(); EXPECT_TRUE(g_pass); @@ -315,5 +323,22 @@ HWTEST_F(PowerTaiheNativeTest, PowerTaiheNativeTest_008, TestSize.Level1) EXPECT_TRUE(g_pass); POWER_HILOGI(LABEL_TEST, "PowerTaiheNativeTest_008 end"); } + +/** + * @tc.name: PowerTaiheNativeTest_009 + * @tc.desc: test power taihe native + * @tc.type: FUNC + * @tc.require: issue#ICTIYR + */ +HWTEST_F(PowerTaiheNativeTest, PowerTaiheNativeTest_009, TestSize.Level1) +{ + POWER_HILOGI(LABEL_TEST, "PowerTaiheNativeTest_009 start"); + RefreshActivity("PowerTaiheNativeTest_009"); + g_error = PowerErrors::ERR_FREQUENT_FUNCTION_CALL; + RefreshActivity("PowerTaiheNativeTest_009"); + EXPECT_TRUE(g_errCode == static_cast(PowerErrors::ERR_FREQUENT_FUNCTION_CALL)); + EXPECT_TRUE(g_pass); + POWER_HILOGI(LABEL_TEST, "PowerTaiheNativeTest_009 end"); +} } // namespace