aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkatao2017-12-07 21:02:43 -0600
committerkatao2017-12-14 07:09:52 -0600
commitc35c1b079756e239ac4812ea6c4695aa6f710729 (patch)
treef1895e154d30671a8cf303d5abe2f670f15fb462
parent3fe230a1e47863e43fec629a2cfe1f51915e9f32 (diff)
downloadplatform-bootable-recovery-c35c1b079756e239ac4812ea6c4695aa6f710729.tar.gz
platform-bootable-recovery-c35c1b079756e239ac4812ea6c4695aa6f710729.tar.xz
platform-bootable-recovery-c35c1b079756e239ac4812ea6c4695aa6f710729.zip
recovery: Porting screensave mode for new platform.
On new board platform the brightness path of sys/class/leds/lcd-backlight is deprecated,instead of /sys/class/backlight/panel0-backlight/. Test: reboot into recovery on sdm845. Change-Id: Idf0027ab888f9f982a8eef7de230ce3635e7c300 Signed-off-by: katao <katao@xiaomi.com>
-rw-r--r--ui.cpp23
-rw-r--r--ui.h2
2 files changed, 19 insertions, 6 deletions
diff --git a/ui.cpp b/ui.cpp
index baf6d108..3c9ded73 100644
--- a/ui.cpp
+++ b/ui.cpp
@@ -48,10 +48,16 @@
48static constexpr int UI_WAIT_KEY_TIMEOUT_SEC = 120; 48static constexpr int UI_WAIT_KEY_TIMEOUT_SEC = 120;
49static constexpr const char* BRIGHTNESS_FILE = "/sys/class/leds/lcd-backlight/brightness"; 49static constexpr const char* BRIGHTNESS_FILE = "/sys/class/leds/lcd-backlight/brightness";
50static constexpr const char* MAX_BRIGHTNESS_FILE = "/sys/class/leds/lcd-backlight/max_brightness"; 50static constexpr const char* MAX_BRIGHTNESS_FILE = "/sys/class/leds/lcd-backlight/max_brightness";
51static constexpr const char* BRIGHTNESS_FILE_SDM =
52 "/sys/class/backlight/panel0-backlight/brightness";
53static constexpr const char* MAX_BRIGHTNESS_FILE_SDM =
54 "/sys/class/backlight/panel0-backlight/max_brightness";
51 55
52RecoveryUI::RecoveryUI() 56RecoveryUI::RecoveryUI()
53 : brightness_normal_(50), 57 : brightness_normal_(50),
54 brightness_dimmed_(25), 58 brightness_dimmed_(25),
59 brightness_file_(BRIGHTNESS_FILE),
60 max_brightness_file_(MAX_BRIGHTNESS_FILE),
55 touch_screen_allowed_(false), 61 touch_screen_allowed_(false),
56 kTouchLowThreshold(RECOVERY_UI_TOUCH_LOW_THRESHOLD), 62 kTouchLowThreshold(RECOVERY_UI_TOUCH_LOW_THRESHOLD),
57 kTouchHighThreshold(RECOVERY_UI_TOUCH_HIGH_THRESHOLD), 63 kTouchHighThreshold(RECOVERY_UI_TOUCH_HIGH_THRESHOLD),
@@ -101,12 +107,17 @@ bool RecoveryUI::InitScreensaver() {
101 if (brightness_normal_ == 0 || brightness_dimmed_ > brightness_normal_) { 107 if (brightness_normal_ == 0 || brightness_dimmed_ > brightness_normal_) {
102 return false; 108 return false;
103 } 109 }
104 110 if (access(brightness_file_.c_str(), R_OK | W_OK)) {
111 brightness_file_ = BRIGHTNESS_FILE_SDM;
112 }
113 if (access(max_brightness_file_.c_str(), R_OK)) {
114 max_brightness_file_ = MAX_BRIGHTNESS_FILE_SDM;
115 }
105 // Set the initial brightness level based on the max brightness. Note that reading the initial 116 // Set the initial brightness level based on the max brightness. Note that reading the initial
106 // value from BRIGHTNESS_FILE doesn't give the actual brightness value (bullhead, sailfish), so 117 // value from BRIGHTNESS_FILE doesn't give the actual brightness value (bullhead, sailfish), so
107 // we don't have a good way to query the default value. 118 // we don't have a good way to query the default value.
108 std::string content; 119 std::string content;
109 if (!android::base::ReadFileToString(MAX_BRIGHTNESS_FILE, &content)) { 120 if (!android::base::ReadFileToString(max_brightness_file_, &content)) {
110 PLOG(WARNING) << "Failed to read max brightness"; 121 PLOG(WARNING) << "Failed to read max brightness";
111 return false; 122 return false;
112 } 123 }
@@ -120,7 +131,7 @@ bool RecoveryUI::InitScreensaver() {
120 brightness_normal_value_ = max_value * brightness_normal_ / 100.0; 131 brightness_normal_value_ = max_value * brightness_normal_ / 100.0;
121 brightness_dimmed_value_ = max_value * brightness_dimmed_ / 100.0; 132 brightness_dimmed_value_ = max_value * brightness_dimmed_ / 100.0;
122 if (!android::base::WriteStringToFile(std::to_string(brightness_normal_value_), 133 if (!android::base::WriteStringToFile(std::to_string(brightness_normal_value_),
123 BRIGHTNESS_FILE)) { 134 brightness_file_)) {
124 PLOG(WARNING) << "Failed to set brightness"; 135 PLOG(WARNING) << "Failed to set brightness";
125 return false; 136 return false;
126 } 137 }
@@ -430,13 +441,13 @@ int RecoveryUI::WaitKey() {
430 // Lower the brightness level: NORMAL -> DIMMED; DIMMED -> OFF. 441 // Lower the brightness level: NORMAL -> DIMMED; DIMMED -> OFF.
431 if (screensaver_state_ == ScreensaverState::NORMAL) { 442 if (screensaver_state_ == ScreensaverState::NORMAL) {
432 if (android::base::WriteStringToFile(std::to_string(brightness_dimmed_value_), 443 if (android::base::WriteStringToFile(std::to_string(brightness_dimmed_value_),
433 BRIGHTNESS_FILE)) { 444 brightness_file_)) {
434 LOG(INFO) << "Brightness: " << brightness_dimmed_value_ << " (" << brightness_dimmed_ 445 LOG(INFO) << "Brightness: " << brightness_dimmed_value_ << " (" << brightness_dimmed_
435 << "%)"; 446 << "%)";
436 screensaver_state_ = ScreensaverState::DIMMED; 447 screensaver_state_ = ScreensaverState::DIMMED;
437 } 448 }
438 } else if (screensaver_state_ == ScreensaverState::DIMMED) { 449 } else if (screensaver_state_ == ScreensaverState::DIMMED) {
439 if (android::base::WriteStringToFile("0", BRIGHTNESS_FILE)) { 450 if (android::base::WriteStringToFile("0", brightness_file_)) {
440 LOG(INFO) << "Brightness: 0 (off)"; 451 LOG(INFO) << "Brightness: 0 (off)";
441 screensaver_state_ = ScreensaverState::OFF; 452 screensaver_state_ = ScreensaverState::OFF;
442 } 453 }
@@ -451,7 +462,7 @@ int RecoveryUI::WaitKey() {
451 462
452 // Reset the brightness to normal. 463 // Reset the brightness to normal.
453 if (android::base::WriteStringToFile(std::to_string(brightness_normal_value_), 464 if (android::base::WriteStringToFile(std::to_string(brightness_normal_value_),
454 BRIGHTNESS_FILE)) { 465 brightness_file_)) {
455 screensaver_state_ = ScreensaverState::NORMAL; 466 screensaver_state_ = ScreensaverState::NORMAL;
456 LOG(INFO) << "Brightness: " << brightness_normal_value_ << " (" << brightness_normal_ 467 LOG(INFO) << "Brightness: " << brightness_normal_value_ << " (" << brightness_normal_
457 << "%)"; 468 << "%)";
diff --git a/ui.h b/ui.h
index 4086023a..4c54d691 100644
--- a/ui.h
+++ b/ui.h
@@ -148,6 +148,8 @@ class RecoveryUI {
148 // be configured via subclassing. Setting brightness_normal_ to 0 to disable screensaver. 148 // be configured via subclassing. Setting brightness_normal_ to 0 to disable screensaver.
149 unsigned int brightness_normal_; 149 unsigned int brightness_normal_;
150 unsigned int brightness_dimmed_; 150 unsigned int brightness_dimmed_;
151 std::string brightness_file_;
152 std::string max_brightness_file_;
151 153
152 // Whether we should listen for touch inputs (default: false). 154 // Whether we should listen for touch inputs (default: false).
153 bool touch_screen_allowed_; 155 bool touch_screen_allowed_;