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
This commit is contained in:
parent
743a5ec96c
commit
8cca752b80
1 changed files with 11 additions and 0 deletions
11
fstrim.c
11
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 @@ static void *do_fstrim_filesystems(void *ignored)
|
|||
}
|
||||
SLOGI("Finished fstrim work.\n");
|
||||
|
||||
/* Release the wakelock that let us work */
|
||||
release_wake_lock(FSTRIM_WAKELOCK);
|
||||
|
||||
return (void *)ret;
|
||||
}
|
||||
|
||||
|
@ -90,6 +96,11 @@ int fstrim_filesystems(void)
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue