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/IdleMaint.cpp b/IdleMaint.cpp
index 4c3041b..8005cf4 100644
--- a/IdleMaint.cpp
+++ b/IdleMaint.cpp
@@ -154,7 +154,10 @@
}
void Trim(const android::sp<android::os::IVoldTaskListener>& listener) {
- android::wakelock::WakeLock wl{kWakeLock};
+ auto wl = android::wakelock::WakeLock::tryGet(kWakeLock);
+ if (!wl.has_value()) {
+ return;
+ }
// Collect both fstab and vold volumes
std::list<std::string> paths;
@@ -414,7 +417,10 @@
LOG(DEBUG) << "idle maintenance started";
- android::wakelock::WakeLock wl{kWakeLock};
+ auto wl = android::wakelock::WakeLock::tryGet(kWakeLock);
+ if (!wl.has_value()) {
+ return android::UNEXPECTED_NULL;
+ }
std::list<std::string> paths;
addFromFstab(&paths, PathTypes::kBlkDevice);
@@ -448,7 +454,10 @@
}
int AbortIdleMaint(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::UNEXPECTED_NULL;
+ }
std::unique_lock<std::mutex> lk(cv_m);
if (idle_maint_stat != IdleMaintStats::kStopped) {