vold: use RAII wake locks
Prevents wake lock leaks, e.g. b/133175847 Bug: 133175847 Test: boot blueline Change-Id: Icda4c81e00a61adec6a12c61c329867fef284dc5
This commit is contained in:
parent
2ebb5c5b96
commit
15bbe22879
4 changed files with 12 additions and 28 deletions
|
@ -23,8 +23,8 @@
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
|
|
||||||
#include <cutils/iosched_policy.h>
|
#include <cutils/iosched_policy.h>
|
||||||
#include <hardware_legacy/power.h>
|
|
||||||
#include <private/android_filesystem_config.h>
|
#include <private/android_filesystem_config.h>
|
||||||
|
#include <wakelock/wakelock.h>
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ static status_t benchmarkInternal(const std::string& rootPath,
|
||||||
void Benchmark(const std::string& path,
|
void Benchmark(const std::string& path,
|
||||||
const android::sp<android::os::IVoldTaskListener>& listener) {
|
const android::sp<android::os::IVoldTaskListener>& listener) {
|
||||||
std::lock_guard<std::mutex> lock(kBenchmarkLock);
|
std::lock_guard<std::mutex> lock(kBenchmarkLock);
|
||||||
acquire_wake_lock(PARTIAL_WAKE_LOCK, kWakeLock);
|
android::wakelock::WakeLock wl{kWakeLock};
|
||||||
|
|
||||||
PerformanceBoost boost;
|
PerformanceBoost boost;
|
||||||
android::os::PersistableBundle extras;
|
android::os::PersistableBundle extras;
|
||||||
|
@ -190,8 +190,6 @@ void Benchmark(const std::string& path,
|
||||||
if (listener) {
|
if (listener) {
|
||||||
listener->onFinished(res, extras);
|
listener->onFinished(res, extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
release_wake_lock(kWakeLock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace vold
|
} // namespace vold
|
||||||
|
|
|
@ -29,8 +29,8 @@
|
||||||
#include <android-base/strings.h>
|
#include <android-base/strings.h>
|
||||||
#include <android/hardware/health/storage/1.0/IStorage.h>
|
#include <android/hardware/health/storage/1.0/IStorage.h>
|
||||||
#include <fs_mgr.h>
|
#include <fs_mgr.h>
|
||||||
#include <hardware_legacy/power.h>
|
|
||||||
#include <private/android_filesystem_config.h>
|
#include <private/android_filesystem_config.h>
|
||||||
|
#include <wakelock/wakelock.h>
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -145,7 +145,7 @@ static void addFromFstab(std::list<std::string>* paths, PathTypes path_type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Trim(const android::sp<android::os::IVoldTaskListener>& listener) {
|
void Trim(const android::sp<android::os::IVoldTaskListener>& listener) {
|
||||||
acquire_wake_lock(PARTIAL_WAKE_LOCK, kWakeLock);
|
android::wakelock::WakeLock wl{kWakeLock};
|
||||||
|
|
||||||
// Collect both fstab and vold volumes
|
// Collect both fstab and vold volumes
|
||||||
std::list<std::string> paths;
|
std::list<std::string> paths;
|
||||||
|
@ -195,7 +195,6 @@ void Trim(const android::sp<android::os::IVoldTaskListener>& listener) {
|
||||||
listener->onFinished(0, extras);
|
listener->onFinished(0, extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
release_wake_lock(kWakeLock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool waitForGc(const std::list<std::string>& paths) {
|
static bool waitForGc(const std::list<std::string>& paths) {
|
||||||
|
@ -370,7 +369,7 @@ int RunIdleMaint(const android::sp<android::os::IVoldTaskListener>& listener) {
|
||||||
|
|
||||||
LOG(DEBUG) << "idle maintenance started";
|
LOG(DEBUG) << "idle maintenance started";
|
||||||
|
|
||||||
acquire_wake_lock(PARTIAL_WAKE_LOCK, kWakeLock);
|
android::wakelock::WakeLock wl{kWakeLock};
|
||||||
|
|
||||||
std::list<std::string> paths;
|
std::list<std::string> paths;
|
||||||
addFromFstab(&paths, PathTypes::kBlkDevice);
|
addFromFstab(&paths, PathTypes::kBlkDevice);
|
||||||
|
@ -400,13 +399,11 @@ int RunIdleMaint(const android::sp<android::os::IVoldTaskListener>& listener) {
|
||||||
|
|
||||||
LOG(DEBUG) << "idle maintenance completed";
|
LOG(DEBUG) << "idle maintenance completed";
|
||||||
|
|
||||||
release_wake_lock(kWakeLock);
|
|
||||||
|
|
||||||
return android::OK;
|
return android::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AbortIdleMaint(const android::sp<android::os::IVoldTaskListener>& listener) {
|
int AbortIdleMaint(const android::sp<android::os::IVoldTaskListener>& listener) {
|
||||||
acquire_wake_lock(PARTIAL_WAKE_LOCK, kWakeLock);
|
android::wakelock::WakeLock wl{kWakeLock};
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lk(cv_m);
|
std::unique_lock<std::mutex> lk(cv_m);
|
||||||
if (idle_maint_stat != IdleMaintStats::kStopped) {
|
if (idle_maint_stat != IdleMaintStats::kStopped) {
|
||||||
|
@ -424,8 +421,6 @@ int AbortIdleMaint(const android::sp<android::os::IVoldTaskListener>& listener)
|
||||||
listener->onFinished(0, extras);
|
listener->onFinished(0, extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
release_wake_lock(kWakeLock);
|
|
||||||
|
|
||||||
LOG(DEBUG) << "idle maintenance stopped";
|
LOG(DEBUG) << "idle maintenance stopped";
|
||||||
|
|
||||||
return android::OK;
|
return android::OK;
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
#include <android-base/properties.h>
|
#include <android-base/properties.h>
|
||||||
#include <android-base/stringprintf.h>
|
#include <android-base/stringprintf.h>
|
||||||
#include <hardware_legacy/power.h>
|
|
||||||
#include <private/android_filesystem_config.h>
|
#include <private/android_filesystem_config.h>
|
||||||
|
#include <wakelock/wakelock.h>
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
@ -258,15 +258,13 @@ fail:
|
||||||
|
|
||||||
void MoveStorage(const std::shared_ptr<VolumeBase>& from, const std::shared_ptr<VolumeBase>& to,
|
void MoveStorage(const std::shared_ptr<VolumeBase>& from, const std::shared_ptr<VolumeBase>& to,
|
||||||
const android::sp<android::os::IVoldTaskListener>& listener) {
|
const android::sp<android::os::IVoldTaskListener>& listener) {
|
||||||
acquire_wake_lock(PARTIAL_WAKE_LOCK, kWakeLock);
|
android::wakelock::WakeLock wl{kWakeLock};
|
||||||
|
|
||||||
android::os::PersistableBundle extras;
|
android::os::PersistableBundle extras;
|
||||||
status_t res = moveStorageInternal(from, to, listener);
|
status_t res = moveStorageInternal(from, to, listener);
|
||||||
if (listener) {
|
if (listener) {
|
||||||
listener->onFinished(res, extras);
|
listener->onFinished(res, extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
release_wake_lock(kWakeLock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace vold
|
} // namespace vold
|
||||||
|
|
15
cryptfs.cpp
15
cryptfs.cpp
|
@ -44,13 +44,13 @@
|
||||||
#include <f2fs_sparseblock.h>
|
#include <f2fs_sparseblock.h>
|
||||||
#include <fs_mgr.h>
|
#include <fs_mgr.h>
|
||||||
#include <fscrypt/fscrypt.h>
|
#include <fscrypt/fscrypt.h>
|
||||||
#include <hardware_legacy/power.h>
|
|
||||||
#include <libdm/dm.h>
|
#include <libdm/dm.h>
|
||||||
#include <log/log.h>
|
#include <log/log.h>
|
||||||
#include <logwrap/logwrap.h>
|
#include <logwrap/logwrap.h>
|
||||||
#include <openssl/evp.h>
|
#include <openssl/evp.h>
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
#include <selinux/selinux.h>
|
#include <selinux/selinux.h>
|
||||||
|
#include <wakelock/wakelock.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -2007,6 +2007,7 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) {
|
||||||
off64_t previously_encrypted_upto = 0;
|
off64_t previously_encrypted_upto = 0;
|
||||||
bool rebootEncryption = false;
|
bool rebootEncryption = false;
|
||||||
bool onlyCreateHeader = false;
|
bool onlyCreateHeader = false;
|
||||||
|
std::unique_ptr<android::wakelock::WakeLock> wakeLock = nullptr;
|
||||||
|
|
||||||
if (get_crypt_ftr_and_key(&crypt_ftr) == 0) {
|
if (get_crypt_ftr_and_key(&crypt_ftr) == 0) {
|
||||||
if (crypt_ftr.flags & CRYPT_ENCRYPTION_IN_PROGRESS) {
|
if (crypt_ftr.flags & CRYPT_ENCRYPTION_IN_PROGRESS) {
|
||||||
|
@ -2073,7 +2074,7 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) {
|
||||||
* wants to keep the screen on, it can grab a full wakelock.
|
* wants to keep the screen on, it can grab a full wakelock.
|
||||||
*/
|
*/
|
||||||
snprintf(lockid, sizeof(lockid), "enablecrypto%d", (int)getpid());
|
snprintf(lockid, sizeof(lockid), "enablecrypto%d", (int)getpid());
|
||||||
acquire_wake_lock(PARTIAL_WAKE_LOCK, lockid);
|
wakeLock = std::make_unique<android::wakelock::WakeLock>(lockid);
|
||||||
|
|
||||||
/* The init files are setup to stop the class main and late start when
|
/* The init files are setup to stop the class main and late start when
|
||||||
* vold sets trigger_shutdown_framework.
|
* vold sets trigger_shutdown_framework.
|
||||||
|
@ -2254,7 +2255,7 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) {
|
||||||
/* default encryption - continue first boot sequence */
|
/* default encryption - continue first boot sequence */
|
||||||
property_set("ro.crypto.state", "encrypted");
|
property_set("ro.crypto.state", "encrypted");
|
||||||
property_set("ro.crypto.type", "block");
|
property_set("ro.crypto.type", "block");
|
||||||
release_wake_lock(lockid);
|
wakeLock.reset(nullptr);
|
||||||
if (rebootEncryption && crypt_ftr.crypt_type != CRYPT_TYPE_DEFAULT) {
|
if (rebootEncryption && crypt_ftr.crypt_type != CRYPT_TYPE_DEFAULT) {
|
||||||
// Bring up cryptkeeper that will check the password and set it
|
// Bring up cryptkeeper that will check the password and set it
|
||||||
property_set("vold.decrypt", "trigger_shutdown_framework");
|
property_set("vold.decrypt", "trigger_shutdown_framework");
|
||||||
|
@ -2291,7 +2292,6 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) {
|
||||||
} else {
|
} else {
|
||||||
/* set property to trigger dialog */
|
/* set property to trigger dialog */
|
||||||
property_set("vold.encrypt_progress", "error_partially_encrypted");
|
property_set("vold.encrypt_progress", "error_partially_encrypted");
|
||||||
release_wake_lock(lockid);
|
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -2301,14 +2301,10 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) {
|
||||||
* Set the property and return. Hope the framework can deal with it.
|
* Set the property and return. Hope the framework can deal with it.
|
||||||
*/
|
*/
|
||||||
property_set("vold.encrypt_progress", "error_reboot_failed");
|
property_set("vold.encrypt_progress", "error_reboot_failed");
|
||||||
release_wake_lock(lockid);
|
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
error_unencrypted:
|
error_unencrypted:
|
||||||
property_set("vold.encrypt_progress", "error_not_encrypted");
|
property_set("vold.encrypt_progress", "error_not_encrypted");
|
||||||
if (lockid[0]) {
|
|
||||||
release_wake_lock(lockid);
|
|
||||||
}
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
error_shutting_down:
|
error_shutting_down:
|
||||||
|
@ -2323,9 +2319,6 @@ error_shutting_down:
|
||||||
|
|
||||||
/* shouldn't get here */
|
/* shouldn't get here */
|
||||||
property_set("vold.encrypt_progress", "error_shutting_down");
|
property_set("vold.encrypt_progress", "error_shutting_down");
|
||||||
if (lockid[0]) {
|
|
||||||
release_wake_lock(lockid);
|
|
||||||
}
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue