Commit 62c3647e authored by Alex Lau's avatar Alex Lau Committed by Chromium LUCI CQ

arc: only suspend ARCVM after SuspendImminent

It's possible that Android calls the provided suspend callback after
SuspendDone is received, which would result in a suspended VM on
a resumed device. This CL adds a flag to check that SuspendDone was
not observed after a SuspendImminent before suspending.

Bug: b:174969196
Test: powerd_dbus_suspend
Change-Id: I1ac72bb0a88bb30c8bd3f7202f877b6d19b915b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2578560Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Commit-Queue: Alex Lau <alexlau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835998}
parent fdb73a33
......@@ -178,6 +178,7 @@ void ArcPowerBridge::OnConnectionClosed() {
void ArcPowerBridge::SuspendImminent(
power_manager::SuspendImminent::Reason reason) {
is_suspending_ = true;
mojom::PowerInstance* power_instance =
ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service_->power(), Suspend);
if (!power_instance)
......@@ -191,7 +192,12 @@ void ArcPowerBridge::SuspendImminent(
}
void ArcPowerBridge::OnAndroidSuspendReady(base::UnguessableToken token) {
if (arc::IsArcVmEnabled()) {
// For the ARCVM case, we only want to suspend the VM if a suspend is still
// underway ie. if SuspendImminent was observed without a subsequent
// SuspendDone. Otherwise, skip suspending the VM but still call
// UnblockSuspend to fulfill the contract and to align with ARC container's
// behavior.
if (arc::IsArcVmEnabled() && is_suspending_) {
vm_tools::concierge::SuspendVmRequest request;
request.set_name(kArcVmName);
request.set_owner_id(user_id_hash_);
......@@ -215,6 +221,7 @@ void ArcPowerBridge::OnConciergeSuspendVmResponse(
}
void ArcPowerBridge::SuspendDone(base::TimeDelta sleep_duration) {
is_suspending_ = false;
if (arc::IsArcVmEnabled()) {
vm_tools::concierge::ResumeVmRequest request;
request.set_name(kArcVmName);
......
......@@ -141,6 +141,11 @@ class ArcPowerBridge : public KeyedService,
// List of observers.
base::ObserverList<Observer> observer_list_;
// Represents whether a device suspend is currently underway, ie. a
// SuspendImminent event has been observed, but a SuspendDone event has not
// yet been observed.
bool is_suspending_ = false;
base::WeakPtrFactory<ArcPowerBridge> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ArcPowerBridge);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment