Merge "vold: Use Wakelock::tryGet()"

This commit is contained in:
Kalesh Singh 2021-02-24 18:49:58 +00:00 committed by Gerrit Code Review
commit 8439ab27d6
4 changed files with 31 additions and 14 deletions

View file

@ -181,7 +181,10 @@ static status_t benchmarkInternal(const std::string& rootPath,
void Benchmark(const std::string& path,
const android::sp<android::os::IVoldTaskListener>& listener) {
std::lock_guard<std::mutex> lock(kBenchmarkLock);
android::wakelock::WakeLock wl{kWakeLock};
auto wl = android::wakelock::WakeLock::tryGet(kWakeLock);
if (!wl.has_value()) {
return;
}
PerformanceBoost boost;
android::os::PersistableBundle extras;

View file

@ -154,7 +154,10 @@ static void addFromFstab(std::list<std::string>* paths, PathTypes path_type) {
}
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 @@ int RunIdleMaint(const android::sp<android::os::IVoldTaskListener>& listener) {
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 RunIdleMaint(const android::sp<android::os::IVoldTaskListener>& listener) {
}
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) {

View file

@ -256,7 +256,10 @@ fail:
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);

View file

@ -2083,7 +2083,16 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) {
int num_vols;
bool rebootEncryption = false;
bool onlyCreateHeader = false;
std::unique_ptr<android::wakelock::WakeLock> wakeLock = nullptr;
/* Get a wakelock as this may take a while, and we don't want the
* device to sleep on us. We'll grab a partial wakelock, and if the UI
* wants to keep the screen on, it can grab a full wakelock.
*/
snprintf(lockid, sizeof(lockid), "enablecrypto%d", (int)getpid());
auto wl = android::wakelock::WakeLock::tryGet(lockid);
if (!wl.has_value()) {
return android::UNEXPECTED_NULL;
}
if (get_crypt_ftr_and_key(&crypt_ftr) == 0) {
if (crypt_ftr.flags & CRYPT_FORCE_ENCRYPTION) {
@ -2132,13 +2141,6 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) {
}
}
/* Get a wakelock as this may take a while, and we don't want the
* device to sleep on us. We'll grab a partial wakelock, and if the UI
* wants to keep the screen on, it can grab a full wakelock.
*/
snprintf(lockid, sizeof(lockid), "enablecrypto%d", (int)getpid());
wakeLock = std::make_unique<android::wakelock::WakeLock>(lockid);
/* The init files are setup to stop the class main and late start when
* vold sets trigger_shutdown_framework.
*/
@ -2291,7 +2293,7 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) {
/* default encryption - continue first boot sequence */
property_set("ro.crypto.state", "encrypted");
property_set("ro.crypto.type", "block");
wakeLock.reset(nullptr);
wl.reset();
if (rebootEncryption && crypt_ftr.crypt_type != CRYPT_TYPE_DEFAULT) {
// Bring up cryptkeeper that will check the password and set it
property_set("vold.decrypt", "trigger_shutdown_framework");