vold: Use Wakelock::tryGet()
Acquiring a wakelock can fail if the suspend service is unavailable.
Explicitly check that wakelock was acquired before performing
operations that require the device to stay on.
Bug: b/179229598
Test: Boot test on Pixel 4 device
Change-Id: If30087223e44098801a31d1bfd239ac22e891abe
diff --git a/MoveStorage.cpp b/MoveStorage.cpp
index 3f636a2..54e28a9 100644
--- a/MoveStorage.cpp
+++ b/MoveStorage.cpp
@@ -256,7 +256,10 @@
void MoveStorage(const std::shared_ptr<VolumeBase>& from, const std::shared_ptr<VolumeBase>& to,
const android::sp<android::os::IVoldTaskListener>& listener) {
- android::wakelock::WakeLock wl{kWakeLock};
+ auto wl = android::wakelock::WakeLock::tryGet(kWakeLock);
+ if (!wl.has_value()) {
+ return;
+ }
android::os::PersistableBundle extras;
status_t res = moveStorageInternal(from, to, listener);