Grab a partial wakelock when doing fstrim

Fstrim can take a while, so grab a wakelock so it finishes now,
not when the user picks up the device and wakes it back up.

This change does not protect against multiple calls to fstrim
before the first one completes.  When the first one completes, it
will release the wakelock, and the device will go to sleep.
However, normal usage is this will not be invoked by the framework
more than once a day, so this should not be an issue.

Bug: 8781133

Change-Id: I8065d1380eaf52ca8a7ca308af66fb6e86d60a66
diff --git a/fstrim.c b/fstrim.c
index 1ffd312..a9f5f0a 100644
--- a/fstrim.c
+++ b/fstrim.c
@@ -26,6 +26,9 @@
 #include <pthread.h>
 #define LOG_TAG "fstrim"
 #include "cutils/log.h"
+#include "hardware_legacy/power.h"
+
+#define FSTRIM_WAKELOCK "dofstrim"
 
 static void *do_fstrim_filesystems(void *ignored)
 {
@@ -82,6 +85,9 @@
     }
     SLOGI("Finished fstrim work.\n");
 
+    /* Release the wakelock that let us work */
+    release_wake_lock(FSTRIM_WAKELOCK);
+
     return (void *)ret;
 }
 
@@ -90,6 +96,11 @@
     pthread_t t;
     int ret;
 
+    /* Get a wakelock as this may take a while, and we don't want the
+     * device to sleep on us.
+     */
+    acquire_wake_lock(PARTIAL_WAKE_LOCK, FSTRIM_WAKELOCK);
+
     /* Depending on the emmc chip and size, this can take upwards
      * of a few minutes.  If done in the same thread as the caller
      * of this function, that would block vold from accepting any