diff options
author | Mark Salyzyn <salyzyn@google.com> | 2016-04-05 23:11:11 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-04-05 23:11:11 +0000 |
commit | 23702b538b3a02ca35f24c55d406a7cc7b14641f (patch) | |
tree | 93330e9ece68c4a1c2d127fa5d4f3cd68a030016 /init/builtins.cpp | |
parent | 34dcdd8075a0c12de552219d4f326bccd1c8fe62 (diff) | |
parent | adf1cdeda07acfa6fc96627f8d4fca5b98bb7428 (diff) |
Merge "init: turn off backlight when performing shutdown cleanup"
am: adf1cde
* commit 'adf1cdeda07acfa6fc96627f8d4fca5b98bb7428':
init: turn off backlight when performing shutdown cleanup
Change-Id: I8267dbbca11d41042e51d3fb89355e46b5cf4a81
Diffstat (limited to 'init/builtins.cpp')
-rw-r--r-- | init/builtins.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/init/builtins.cpp b/init/builtins.cpp index b3bd41801..95e4c8804 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -16,6 +16,7 @@ #include "builtins.h" +#include <dirent.h> #include <errno.h> #include <fcntl.h> #include <mntent.h> @@ -41,6 +42,7 @@ #include <selinux/label.h> #include <fs_mgr.h> +#include <android-base/file.h> #include <android-base/parseint.h> #include <android-base/stringprintf.h> #include <cutils/partition_utils.h> @@ -106,6 +108,32 @@ done: return ret; } +// Turn off backlight while we are performing power down cleanup activities. +static void turnOffBacklight() { + static const char off[] = "0"; + + android::base::WriteStringToFile(off, "/sys/class/leds/lcd-backlight/brightness"); + + static const char backlightDir[] = "/sys/class/backlight"; + std::unique_ptr<DIR, int(*)(DIR*)> dir(opendir(backlightDir), closedir); + if (!dir) { + return; + } + + struct dirent *dp; + while ((dp = readdir(dir.get())) != NULL) { + if (((dp->d_type != DT_DIR) && (dp->d_type != DT_LNK)) || + (dp->d_name[0] == '.')) { + continue; + } + + std::string fileName = android::base::StringPrintf("%s/%s/brightness", + backlightDir, + dp->d_name); + android::base::WriteStringToFile(off, fileName); + } +} + static void unmount_and_fsck(const struct mntent *entry) { if (strcmp(entry->mnt_type, "f2fs") && strcmp(entry->mnt_type, "ext4")) return; @@ -140,6 +168,8 @@ static void unmount_and_fsck(const struct mntent *entry) { svc->Start(); } + turnOffBacklight(); + int count = 0; while (count++ < UNMOUNT_CHECK_TIMES) { int fd = TEMP_FAILURE_RETRY(open(entry->mnt_fsname, O_RDONLY | O_EXCL)); |