mirror of
https://gitee.com/openharmony/powermgr_power_manager
synced 2024-11-23 07:00:22 +00:00
commit
484c6c1ff5
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user