!1385 fix: fix freeze bug

Merge pull request !1385 from 严雪君/master
This commit is contained in:
openharmony_ci 2024-10-18 09:41:54 +00:00 committed by Gitee
commit 484c6c1ff5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 68 additions and 0 deletions

View File

@ -202,6 +202,13 @@ PowerErrors PowerMgrClient::WakeupDevice(WakeupDeviceType reason, const std::str
return proxy_->WakeupDevice(GetTickCount(), reason, detail);
}
void PowerMgrClient::WakeupDeviceAsync(WakeupDeviceType reason, const std::string& detail)
{
RETURN_IF(Connect() != ERR_OK);
POWER_HILOGD(FEATURE_WAKEUP, " Calling WakeupDeviceAsync success");
return proxy_->WakeupDeviceAsync(GetTickCount(), reason, detail);
}
bool PowerMgrClient::RefreshActivity(UserActivityType type)
{
RETURN_IF_WITH_RET(Connect() != ERR_OK, false);

View File

@ -59,6 +59,7 @@ public:
virtual PowerErrors SetSuspendTag(const std::string& tag) = 0;
virtual PowerErrors SuspendDevice(int64_t callTimeMs, SuspendDeviceType reason, bool suspendImmed) = 0;
virtual PowerErrors WakeupDevice(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details) = 0;
virtual void WakeupDeviceAsync(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details) = 0;
virtual bool RefreshActivity(int64_t callTimeMs, UserActivityType type, bool needChangeBacklight) = 0;
virtual PowerErrors OverrideScreenOffTime(int64_t timeout) = 0;
virtual PowerErrors RestoreScreenOffTime() = 0;

View File

@ -76,6 +76,14 @@ public:
PowerErrors WakeupDevice(WakeupDeviceType reason = WakeupDeviceType::WAKEUP_DEVICE_APPLICATION,
const std::string& detail = std::string("app call"));
/**
* Wake up the device and set the screen on async.
*
* @param reason The reason for waking up the device, such as powerkey/plugin/application.
*/
void WakeupDeviceAsync(WakeupDeviceType reason = WakeupDeviceType::WAKEUP_DEVICE_APPLICATION,
const std::string& detail = std::string("app call"));
/**
* Refresh the screentimeout time, and keep the screen on. RefreshActivity works only when the screen is on.
*

View File

@ -79,6 +79,7 @@ public:
virtual PowerErrors SetSuspendTag(const std::string& tag) override;
virtual PowerErrors SuspendDevice(int64_t callTimeMs, SuspendDeviceType reason, bool suspendImmed) override;
virtual PowerErrors WakeupDevice(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details) override;
virtual void WakeupDeviceAsync(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details) override {};
virtual bool RefreshActivity(int64_t callTimeMs, UserActivityType type, bool needChangeBacklight) override;
bool RefreshActivityInner(int64_t callTimeMs, UserActivityType type, bool needChangeBacklight);
virtual PowerErrors OverrideScreenOffTime(int64_t timeout) override;

View File

@ -61,6 +61,7 @@ public:
// Use for PowerStateMachine
virtual PowerErrors SuspendDevice(int64_t callTimeMs, SuspendDeviceType reason, bool suspendImmed) override;
virtual PowerErrors WakeupDevice(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details) override;
virtual void WakeupDeviceAsync(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details) override;
virtual bool RefreshActivity(int64_t callTimeMs, UserActivityType type, bool needChangeBacklight) override;
virtual PowerErrors OverrideScreenOffTime(int64_t timeout) override;
virtual PowerErrors RestoreScreenOffTime() override;

View File

@ -528,6 +528,32 @@ PowerErrors PowerMgrProxy::WakeupDevice(int64_t callTimeMs, WakeupDeviceType rea
return static_cast<PowerErrors>(error);
}
void PowerMgrProxy::WakeupDeviceAsync(int64_t callTimeMs, WakeupDeviceType reason, const std::string& details)
{
sptr<IRemoteObject> remote = Remote();
RETURN_IF(remote == nullptr);
MessageParcel data;
MessageParcel reply;
MessageOption option = { MessageOption::TF_ASYNC };
if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) {
POWER_HILOGE(FEATURE_WAKEUP, "Write descriptor failed");
return;
}
RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, Int64, callTimeMs);
RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, Uint32, static_cast<uint32_t>(reason));
RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, String16, Str8ToStr16(details));
int ret = remote->SendRequest(
static_cast<int>(PowerMgr::PowerMgrInterfaceCode::WAKEUP_DEVICE), data, reply, option);
if (ret != ERR_OK) {
POWER_HILOGE(FEATURE_WAKEUP, "%{public}s: SendRequest failed with ret=%{public}d", __func__, ret);
return;
}
}
bool PowerMgrProxy::RefreshActivity(int64_t callTimeMs, UserActivityType type, bool needChangeBacklight)
{
sptr<IRemoteObject> remote = Remote();

View File

@ -1326,4 +1326,28 @@ HWTEST_F(PowerMgrClientTest, PowerMgrClient054, TestSize.Level0)
POWER_HILOGD(LABEL_TEST, "PowerMgrClient054::fun is end!");
}
/**
* @tc.name: PowerMgrClient055
* @tc.desc: test WakeupDevice
* @tc.type: FUNC
* @tc.require: #IAXR0O
*/
HWTEST_F(PowerMgrClientTest, PowerMgrClient055, TestSize.Level0)
{
POWER_HILOGD(LABEL_TEST, "PowerMgrClient055::fun is start!");
auto& powerMgrClient = PowerMgrClient::GetInstance();
powerMgrClient.WakeupDevice();
// Suspend Device before test
powerMgrClient.SuspendDevice();
EXPECT_EQ(powerMgrClient.IsScreenOn(), false) << "PowerMgrClient055: Prepare Fail, Screen is On.";
powerMgrClient.WakeupDeviceAsync(WakeupDeviceType::WAKEUP_DEVICE_PEN);
sleep(1);
EXPECT_EQ(powerMgrClient.GetState(), PowerState::AWAKE);
EXPECT_EQ(powerMgrClient.IsScreenOn(), true) << "PowerMgrClient055: Wakeup Device Async Fail, Screen is Off";
POWER_HILOGD(LABEL_TEST, "PowerMgrClient055::fun is end!");
}
} // namespace