summaryrefslogtreecommitdiff
path: root/cryptfs.cpp
diff options
context:
space:
mode:
authorTri Vo <trong@google.com>2019-06-18 15:33:01 -0700
committerTri Vo <trong@google.com>2019-06-18 15:34:12 -0700
commit242130f3f8180baef35649f350ca737d0b0c6ae3 (patch)
treebb61e5296a90fe48edefa4c85e5833017d6e18db /cryptfs.cpp
parent6c704f736c7cbf4fed12f97381ec978ea3b7ceb9 (diff)
downloadvold-242130f3f8180baef35649f350ca737d0b0c6ae3.tar.gz
vold: use RAII wake locks
Prevents wake lock leaks, e.g. b/133175847 Bug: 133175847 Test: boot blueline Change-Id: I62fd1c6c3abbfd35aebe11343abd717a7cf4eef7
Diffstat (limited to 'cryptfs.cpp')
-rw-r--r--cryptfs.cpp12
1 files changed, 2 insertions, 10 deletions
diff --git a/cryptfs.cpp b/cryptfs.cpp
index c5d0307a..7d59b2d5 100644
--- a/cryptfs.cpp
+++ b/cryptfs.cpp
@@ -2007,6 +2007,7 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) {
off64_t previously_encrypted_upto = 0;
bool rebootEncryption = false;
bool onlyCreateHeader = false;
+ std::unique_ptr<android::power::WakeLock> wakeLock = nullptr;
if (get_crypt_ftr_and_key(&crypt_ftr) == 0) {
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.
*/
snprintf(lockid, sizeof(lockid), "enablecrypto%d", (int)getpid());
- acquire_wake_lock(PARTIAL_WAKE_LOCK, lockid);
+ wakeLock = std::make_unique<android::power::WakeLock>(lockid);
/* The init files are setup to stop the class main and late start when
* vold sets trigger_shutdown_framework.
@@ -2254,7 +2255,6 @@ 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");
- release_wake_lock(lockid);
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");
@@ -2291,7 +2291,6 @@ int cryptfs_enable_internal(int crypt_type, const char* passwd, int no_ui) {
} else {
/* set property to trigger dialog */
property_set("vold.encrypt_progress", "error_partially_encrypted");
- release_wake_lock(lockid);
}
return -1;
}
@@ -2301,14 +2300,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.
*/
property_set("vold.encrypt_progress", "error_reboot_failed");
- release_wake_lock(lockid);
return rc;
error_unencrypted:
property_set("vold.encrypt_progress", "error_not_encrypted");
- if (lockid[0]) {
- release_wake_lock(lockid);
- }
return -1;
error_shutting_down:
@@ -2323,9 +2318,6 @@ error_shutting_down:
/* shouldn't get here */
property_set("vold.encrypt_progress", "error_shutting_down");
- if (lockid[0]) {
- release_wake_lock(lockid);
- }
return -1;
}