am 5d4c68e4: Have vold grab a partial wakelock when encrypting

* commit '5d4c68e40700424b65a4331be75620706a0dd49c':
  Have vold grab a partial wakelock when encrypting
diff --git a/Android.mk b/Android.mk
index 3b96aab..48df613 100644
--- a/Android.mk
+++ b/Android.mk
@@ -33,6 +33,7 @@
 	libsysutils \
 	libcutils \
 	libdiskconfig \
+	libhardware_legacy \
 	libcrypto
 
 include $(CLEAR_VARS)
diff --git a/cryptfs.c b/cryptfs.c
index afba726..f57b717 100644
--- a/cryptfs.c
+++ b/cryptfs.c
@@ -41,6 +41,7 @@
 #define LOG_TAG "Cryptfs"
 #include "cutils/log.h"
 #include "cutils/properties.h"
+#include "hardware_legacy/power.h"
 
 #define DM_CRYPT_BUF_SIZE 4096
 #define DATA_MNT_POINT "/data"
@@ -897,6 +898,7 @@
     struct crypt_mnt_ftr crypt_ftr;
     char tmpfs_options[80];
     char encrypted_state[32];
+    char lockid[32] = { 0 };
 
     property_get("ro.crypto.state", encrypted_state, "");
     if (strcmp(encrypted_state, "unencrypted")) {
@@ -936,6 +938,13 @@
         }
     }
 
+    /* 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, 32, "enablecrypto%d", (int) getpid());
+    acquire_wake_lock(PARTIAL_WAKE_LOCK, lockid);
+
     /* The init files are setup to stop the class main and late start when
      * vold sets trigger_shutdown_framework.
      */
@@ -1020,6 +1029,7 @@
         reboot(LINUX_REBOOT_CMD_RESTART);
     } else {
         property_set("vold.encrypt_progress", "error_partially_encrypted");
+        release_wake_lock(lockid);
         return -1;
     }
 
@@ -1028,10 +1038,14 @@
      * 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:
@@ -1045,6 +1059,9 @@
 
     /* shouldn't get here */
     property_set("vold.encrypt_progress", "error_shutting_down");
+    if (lockid[0]) {
+        release_wake_lock(lockid);
+    }
     return -1;
 }