2011-08-30 17:46:09 +00:00
|
|
|
/*
|
2017-07-13 22:10:35 +00:00
|
|
|
* Copyright (C) 2011-2017 The Android Open Source Project
|
2011-08-30 17:46:09 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-10-21 00:15:32 +00:00
|
|
|
#include <charger/healthd_mode_charger.h>
|
2019-10-09 00:27:11 +00:00
|
|
|
|
2011-08-30 17:46:09 +00:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2014-05-16 00:49:06 +00:00
|
|
|
#include <inttypes.h>
|
2011-08-30 17:46:09 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2013-09-09 19:09:08 +00:00
|
|
|
#include <sys/epoll.h>
|
2011-08-30 17:46:09 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
#include <optional>
|
2017-01-19 06:54:54 +00:00
|
|
|
|
2016-08-11 22:29:50 +00:00
|
|
|
#include <android-base/file.h>
|
charger: Load default resources from /system
When charger resources are missing from /product, before this change,
images are loaded from /res/images/charger. After this change, charger
first checks if the resource exists at that location, and if not, use
resource under /system/etc/res/images/charger.
On devices that uses resources from /product, this change has no effect.
On devices that uses resources from /res,
- if an old image is mounted at /, charger continues to load resources
from /res.
- if a new image is mounted at /, that is, battery_fail and
battery_scale may not exist under /res, charger loads them from /system.
There are no font files installed by modules defined here, so any
device-specific font files stay at /res.
Also create virtual function wrappers over minui APIs to be mocked
later.
See next change on moving battery_scale and battery_fail images to
/system.
Test: build and inspect system/etc/res/images/charger
Bug: 143907179
Change-Id: I4895b9602274fa4a1ebb4d7d3b842622b81b7b51
2020-08-05 23:15:15 +00:00
|
|
|
#include <android-base/logging.h>
|
2017-06-27 16:19:09 +00:00
|
|
|
#include <android-base/macros.h>
|
charger: Load default resources from /system
When charger resources are missing from /product, before this change,
images are loaded from /res/images/charger. After this change, charger
first checks if the resource exists at that location, and if not, use
resource under /system/etc/res/images/charger.
On devices that uses resources from /product, this change has no effect.
On devices that uses resources from /res,
- if an old image is mounted at /, charger continues to load resources
from /res.
- if a new image is mounted at /, that is, battery_fail and
battery_scale may not exist under /res, charger loads them from /system.
There are no font files installed by modules defined here, so any
device-specific font files stay at /res.
Also create virtual function wrappers over minui APIs to be mocked
later.
See next change on moving battery_scale and battery_fail images to
/system.
Test: build and inspect system/etc/res/images/charger
Bug: 143907179
Change-Id: I4895b9602274fa4a1ebb4d7d3b842622b81b7b51
2020-08-05 23:15:15 +00:00
|
|
|
#include <android-base/strings.h>
|
2016-08-11 22:29:50 +00:00
|
|
|
|
2012-09-12 01:52:40 +00:00
|
|
|
#include <linux/netlink.h>
|
2017-07-13 22:10:35 +00:00
|
|
|
#include <sys/socket.h>
|
2012-09-12 01:52:40 +00:00
|
|
|
|
2019-03-26 01:09:35 +00:00
|
|
|
#include <cutils/android_get_control_file.h>
|
2011-08-30 17:46:09 +00:00
|
|
|
#include <cutils/klog.h>
|
2011-09-30 00:20:07 +00:00
|
|
|
#include <cutils/misc.h>
|
2014-06-16 22:06:21 +00:00
|
|
|
#include <cutils/properties.h>
|
2017-07-13 22:10:35 +00:00
|
|
|
#include <cutils/uevent.h>
|
2017-01-31 23:51:50 +00:00
|
|
|
#include <sys/reboot.h>
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2012-11-16 01:03:03 +00:00
|
|
|
#include <suspend/autosuspend.h>
|
|
|
|
|
2016-08-11 22:29:50 +00:00
|
|
|
#include "AnimationParser.h"
|
2017-07-13 22:10:35 +00:00
|
|
|
#include "healthd_draw.h"
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2021-10-21 00:15:32 +00:00
|
|
|
#include <aidl/android/hardware/health/BatteryStatus.h>
|
|
|
|
#include <health/HealthLoop.h>
|
2016-02-17 20:21:34 +00:00
|
|
|
#include <healthd/healthd.h>
|
2013-09-09 19:09:08 +00:00
|
|
|
|
2021-10-21 05:18:16 +00:00
|
|
|
#if !defined(__ANDROID_VNDK__)
|
|
|
|
#include "charger.sysprop.h"
|
|
|
|
#endif
|
|
|
|
|
charger: Load default resources from /system
When charger resources are missing from /product, before this change,
images are loaded from /res/images/charger. After this change, charger
first checks if the resource exists at that location, and if not, use
resource under /system/etc/res/images/charger.
On devices that uses resources from /product, this change has no effect.
On devices that uses resources from /res,
- if an old image is mounted at /, charger continues to load resources
from /res.
- if a new image is mounted at /, that is, battery_fail and
battery_scale may not exist under /res, charger loads them from /system.
There are no font files installed by modules defined here, so any
device-specific font files stay at /res.
Also create virtual function wrappers over minui APIs to be mocked
later.
See next change on moving battery_scale and battery_fail images to
/system.
Test: build and inspect system/etc/res/images/charger
Bug: 143907179
Change-Id: I4895b9602274fa4a1ebb4d7d3b842622b81b7b51
2020-08-05 23:15:15 +00:00
|
|
|
using std::string_literals::operator""s;
|
2016-08-11 22:29:50 +00:00
|
|
|
using namespace android;
|
2021-10-21 00:15:32 +00:00
|
|
|
using aidl::android::hardware::health::BatteryStatus;
|
2019-10-09 00:27:11 +00:00
|
|
|
using android::hardware::health::HealthLoop;
|
2016-08-11 22:29:50 +00:00
|
|
|
|
2018-09-11 17:46:35 +00:00
|
|
|
// main healthd loop
|
|
|
|
extern int healthd_main(void);
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
// minui globals
|
2017-07-13 22:10:35 +00:00
|
|
|
char* locale;
|
2014-02-13 20:25:21 +00:00
|
|
|
|
2011-08-30 17:46:09 +00:00
|
|
|
#ifndef max
|
2017-07-13 22:10:35 +00:00
|
|
|
#define max(a, b) ((a) > (b) ? (a) : (b))
|
2011-08-30 17:46:09 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef min
|
2017-07-13 22:10:35 +00:00
|
|
|
#define min(a, b) ((a) < (b) ? (a) : (b))
|
2011-08-30 17:46:09 +00:00
|
|
|
#endif
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
2011-09-22 22:49:04 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
#define MSEC_PER_SEC (1000LL)
|
|
|
|
#define NSEC_PER_MSEC (1000000LL)
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
#define BATTERY_UNKNOWN_TIME (2 * MSEC_PER_SEC)
|
|
|
|
#define POWER_ON_KEY_TIME (2 * MSEC_PER_SEC)
|
2011-08-30 17:46:09 +00:00
|
|
|
#define UNPLUGGED_SHUTDOWN_TIME (10 * MSEC_PER_SEC)
|
2018-07-17 09:49:34 +00:00
|
|
|
#define UNPLUGGED_DISPLAY_TIME (3 * MSEC_PER_SEC)
|
2019-02-15 02:50:58 +00:00
|
|
|
#define MAX_BATT_LEVEL_WAIT_TIME (3 * MSEC_PER_SEC)
|
2019-03-31 09:22:47 +00:00
|
|
|
#define UNPLUGGED_SHUTDOWN_TIME_PROP "ro.product.charger.unplugged_shutdown_time"
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
#define LAST_KMSG_MAX_SZ (32 * 1024)
|
2011-09-30 00:20:07 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
#define LOGE(x...) KLOG_ERROR("charger", x);
|
|
|
|
#define LOGW(x...) KLOG_WARNING("charger", x);
|
|
|
|
#define LOGV(x...) KLOG_DEBUG("charger", x);
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
namespace android {
|
|
|
|
|
2021-10-27 00:20:25 +00:00
|
|
|
#if defined(__ANDROID_VNDK__)
|
|
|
|
static constexpr const char* vendor_animation_desc_path =
|
|
|
|
"/vendor/etc/res/values/charger/animation.txt";
|
|
|
|
static constexpr const char* vendor_animation_root = "/vendor/etc/res/images/";
|
|
|
|
static constexpr const char* vendor_default_animation_root = "/vendor/etc/res/images/default/";
|
|
|
|
#else
|
|
|
|
|
charger: Load default resources from /system
When charger resources are missing from /product, before this change,
images are loaded from /res/images/charger. After this change, charger
first checks if the resource exists at that location, and if not, use
resource under /system/etc/res/images/charger.
On devices that uses resources from /product, this change has no effect.
On devices that uses resources from /res,
- if an old image is mounted at /, charger continues to load resources
from /res.
- if a new image is mounted at /, that is, battery_fail and
battery_scale may not exist under /res, charger loads them from /system.
There are no font files installed by modules defined here, so any
device-specific font files stay at /res.
Also create virtual function wrappers over minui APIs to be mocked
later.
See next change on moving battery_scale and battery_fail images to
/system.
Test: build and inspect system/etc/res/images/charger
Bug: 143907179
Change-Id: I4895b9602274fa4a1ebb4d7d3b842622b81b7b51
2020-08-05 23:15:15 +00:00
|
|
|
// Legacy animation resources are loaded from this directory.
|
|
|
|
static constexpr const char* legacy_animation_root = "/res/images/";
|
|
|
|
|
|
|
|
// Built-in animation resources are loaded from this directory.
|
|
|
|
static constexpr const char* system_animation_root = "/system/etc/res/images/";
|
|
|
|
|
|
|
|
// Resources in /product/etc/res overrides resources in /res and /system/etc/res.
|
2019-01-28 20:55:54 +00:00
|
|
|
// If the device is using the Generic System Image (GSI), resources may exist in
|
|
|
|
// both paths.
|
|
|
|
static constexpr const char* product_animation_desc_path =
|
|
|
|
"/product/etc/res/values/charger/animation.txt";
|
|
|
|
static constexpr const char* product_animation_root = "/product/etc/res/images/";
|
|
|
|
static constexpr const char* animation_desc_path = "/res/values/charger/animation.txt";
|
2021-10-27 00:20:25 +00:00
|
|
|
#endif
|
2016-08-11 22:29:50 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static const animation BASE_ANIMATION = {
|
|
|
|
.text_clock =
|
|
|
|
{
|
|
|
|
.pos_x = 0,
|
|
|
|
.pos_y = 0,
|
|
|
|
|
|
|
|
.color_r = 255,
|
|
|
|
.color_g = 255,
|
|
|
|
.color_b = 255,
|
|
|
|
.color_a = 255,
|
|
|
|
|
|
|
|
.font = nullptr,
|
|
|
|
},
|
|
|
|
.text_percent =
|
|
|
|
{
|
|
|
|
.pos_x = 0,
|
|
|
|
.pos_y = 0,
|
|
|
|
|
|
|
|
.color_r = 255,
|
|
|
|
.color_g = 255,
|
|
|
|
.color_b = 255,
|
|
|
|
.color_a = 255,
|
|
|
|
},
|
2016-08-11 22:29:50 +00:00
|
|
|
|
|
|
|
.run = false,
|
|
|
|
|
|
|
|
.frames = nullptr,
|
|
|
|
.cur_frame = 0,
|
|
|
|
.num_frames = 0,
|
|
|
|
.first_frame_repeats = 2,
|
|
|
|
|
|
|
|
.cur_cycle = 0,
|
|
|
|
.num_cycles = 3,
|
|
|
|
|
|
|
|
.cur_level = 0,
|
|
|
|
.cur_status = BATTERY_STATUS_UNKNOWN,
|
|
|
|
};
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
void Charger::InitDefaultAnimationFrames() {
|
|
|
|
owned_frames_ = {
|
|
|
|
{
|
|
|
|
.disp_time = 750,
|
|
|
|
.min_level = 0,
|
|
|
|
.max_level = 19,
|
|
|
|
.surface = NULL,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.disp_time = 750,
|
|
|
|
.min_level = 0,
|
|
|
|
.max_level = 39,
|
|
|
|
.surface = NULL,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.disp_time = 750,
|
|
|
|
.min_level = 0,
|
|
|
|
.max_level = 59,
|
|
|
|
.surface = NULL,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.disp_time = 750,
|
|
|
|
.min_level = 0,
|
|
|
|
.max_level = 79,
|
|
|
|
.surface = NULL,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.disp_time = 750,
|
|
|
|
.min_level = 80,
|
|
|
|
.max_level = 95,
|
|
|
|
.surface = NULL,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.disp_time = 750,
|
|
|
|
.min_level = 0,
|
|
|
|
.max_level = 100,
|
|
|
|
.surface = NULL,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2011-09-22 22:49:04 +00:00
|
|
|
|
2021-10-21 00:15:32 +00:00
|
|
|
Charger::Charger(ChargerConfigurationInterface* configuration)
|
|
|
|
: batt_anim_(BASE_ANIMATION), configuration_(configuration) {}
|
2011-09-22 22:49:04 +00:00
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
Charger::~Charger() {}
|
2011-08-30 17:46:09 +00:00
|
|
|
|
|
|
|
/* current time in milliseconds */
|
2017-07-13 22:10:35 +00:00
|
|
|
static int64_t curr_time_ms() {
|
|
|
|
timespec tm;
|
2011-08-30 17:46:09 +00:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &tm);
|
|
|
|
return tm.tv_sec * MSEC_PER_SEC + (tm.tv_nsec / NSEC_PER_MSEC);
|
|
|
|
}
|
|
|
|
|
2011-09-30 00:20:07 +00:00
|
|
|
#define MAX_KLOG_WRITE_BUF_SZ 256
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static void dump_last_kmsg(void) {
|
2019-03-26 01:09:35 +00:00
|
|
|
std::string buf;
|
2017-07-13 22:10:35 +00:00
|
|
|
char* ptr;
|
2019-03-26 01:09:35 +00:00
|
|
|
size_t len;
|
2011-09-30 00:20:07 +00:00
|
|
|
|
2014-09-23 21:54:24 +00:00
|
|
|
LOGW("*************** LAST KMSG ***************\n");
|
2017-06-27 16:19:09 +00:00
|
|
|
const char* kmsg[] = {
|
|
|
|
// clang-format off
|
|
|
|
"/sys/fs/pstore/console-ramoops-0",
|
|
|
|
"/sys/fs/pstore/console-ramoops",
|
|
|
|
"/proc/last_kmsg",
|
|
|
|
// clang-format on
|
|
|
|
};
|
2019-03-26 01:09:35 +00:00
|
|
|
for (size_t i = 0; i < arraysize(kmsg) && buf.empty(); ++i) {
|
|
|
|
auto fd = android_get_control_file(kmsg[i]);
|
|
|
|
if (fd >= 0) {
|
|
|
|
android::base::ReadFdToString(fd, &buf);
|
|
|
|
} else {
|
|
|
|
android::base::ReadFileToString(kmsg[i], &buf);
|
|
|
|
}
|
2017-06-27 16:19:09 +00:00
|
|
|
}
|
2013-11-23 01:52:59 +00:00
|
|
|
|
2019-03-26 01:09:35 +00:00
|
|
|
if (buf.empty()) {
|
2017-06-27 16:19:09 +00:00
|
|
|
LOGW("last_kmsg not found. Cold reset?\n");
|
|
|
|
goto out;
|
2011-09-30 00:20:07 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 01:09:35 +00:00
|
|
|
len = min(buf.size(), LAST_KMSG_MAX_SZ);
|
|
|
|
ptr = &buf[buf.size() - len];
|
2011-09-30 00:20:07 +00:00
|
|
|
|
|
|
|
while (len > 0) {
|
2019-03-26 01:09:35 +00:00
|
|
|
size_t cnt = min(len, MAX_KLOG_WRITE_BUF_SZ);
|
2011-09-30 00:20:07 +00:00
|
|
|
char yoink;
|
2017-07-13 22:10:35 +00:00
|
|
|
char* nl;
|
2011-09-30 00:20:07 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
nl = (char*)memrchr(ptr, '\n', cnt - 1);
|
|
|
|
if (nl) cnt = nl - ptr + 1;
|
2011-09-30 00:20:07 +00:00
|
|
|
|
|
|
|
yoink = ptr[cnt];
|
|
|
|
ptr[cnt] = '\0';
|
2014-09-23 21:54:24 +00:00
|
|
|
klog_write(6, "<4>%s", ptr);
|
2011-09-30 00:20:07 +00:00
|
|
|
ptr[cnt] = yoink;
|
|
|
|
|
|
|
|
len -= cnt;
|
|
|
|
ptr += cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2014-09-23 21:54:24 +00:00
|
|
|
LOGW("************* END LAST KMSG *************\n");
|
2011-09-30 00:20:07 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 05:51:29 +00:00
|
|
|
int Charger::RequestEnableSuspend() {
|
|
|
|
if (!configuration_->ChargerEnableSuspend()) {
|
2019-07-03 18:07:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2021-10-27 05:51:29 +00:00
|
|
|
return autosuspend_enable();
|
|
|
|
}
|
2019-07-03 18:07:37 +00:00
|
|
|
|
2021-10-27 05:51:29 +00:00
|
|
|
int Charger::RequestDisableSuspend() {
|
|
|
|
if (!configuration_->ChargerEnableSuspend()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return autosuspend_disable();
|
2012-11-16 01:03:03 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static void kick_animation(animation* anim) {
|
2011-09-22 22:49:04 +00:00
|
|
|
anim->run = true;
|
|
|
|
}
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
static void reset_animation(animation* anim) {
|
2011-09-22 22:49:04 +00:00
|
|
|
anim->cur_cycle = 0;
|
|
|
|
anim->cur_frame = 0;
|
|
|
|
anim->run = false;
|
|
|
|
}
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
void Charger::UpdateScreenState(int64_t now) {
|
2011-09-22 22:49:04 +00:00
|
|
|
int disp_time;
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
if (!batt_anim_.run || now < next_screen_transition_) return;
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2019-02-15 02:50:58 +00:00
|
|
|
// If battery level is not ready, keep checking in the defined time
|
2021-10-21 00:15:32 +00:00
|
|
|
if (health_info_.battery_level == 0 && health_info_.battery_status == BatteryStatus::UNKNOWN) {
|
2019-10-09 00:27:11 +00:00
|
|
|
if (wait_batt_level_timestamp_ == 0) {
|
2019-02-15 02:50:58 +00:00
|
|
|
// Set max delay time and skip drawing screen
|
2019-10-09 00:27:11 +00:00
|
|
|
wait_batt_level_timestamp_ = now + MAX_BATT_LEVEL_WAIT_TIME;
|
2019-02-15 02:50:58 +00:00
|
|
|
LOGV("[%" PRId64 "] wait for battery capacity ready\n", now);
|
|
|
|
return;
|
2019-10-09 00:27:11 +00:00
|
|
|
} else if (now <= wait_batt_level_timestamp_) {
|
2019-02-15 02:50:58 +00:00
|
|
|
// Do nothing, keep waiting
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// If timeout and battery level is still not ready, draw unknown battery
|
|
|
|
}
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
if (healthd_draw_ == nullptr) {
|
2021-10-21 00:15:32 +00:00
|
|
|
std::optional<bool> out_screen_on = configuration_->ChargerShouldKeepScreenOn();
|
2019-10-09 00:27:11 +00:00
|
|
|
if (out_screen_on.has_value()) {
|
|
|
|
if (!*out_screen_on) {
|
2014-09-26 02:44:42 +00:00
|
|
|
LOGV("[%" PRId64 "] leave screen off\n", now);
|
2019-10-09 00:27:11 +00:00
|
|
|
batt_anim_.run = false;
|
|
|
|
next_screen_transition_ = -1;
|
2021-10-21 00:15:32 +00:00
|
|
|
if (configuration_->ChargerIsOnline()) {
|
2021-10-27 05:51:29 +00:00
|
|
|
RequestEnableSuspend();
|
2021-10-21 00:15:32 +00:00
|
|
|
}
|
2014-09-26 02:44:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-06-30 20:15:05 +00:00
|
|
|
}
|
|
|
|
|
2021-08-31 08:22:25 +00:00
|
|
|
healthd_draw_ = HealthdDraw::Create(&batt_anim_);
|
|
|
|
if (healthd_draw_ == nullptr) return;
|
2014-06-30 20:15:05 +00:00
|
|
|
|
2021-10-21 05:18:16 +00:00
|
|
|
#if !defined(__ANDROID_VNDK__)
|
2019-07-03 18:07:37 +00:00
|
|
|
if (android::sysprop::ChargerProperties::disable_init_blank().value_or(false)) {
|
2019-10-09 00:27:11 +00:00
|
|
|
healthd_draw_->blank_screen(true);
|
|
|
|
screen_blanked_ = true;
|
2019-07-03 18:07:37 +00:00
|
|
|
}
|
2021-10-21 05:18:16 +00:00
|
|
|
#endif
|
2014-06-30 20:15:05 +00:00
|
|
|
}
|
|
|
|
|
2011-09-22 22:49:04 +00:00
|
|
|
/* animation is over, blank screen and leave */
|
2019-10-09 00:27:11 +00:00
|
|
|
if (batt_anim_.num_cycles > 0 && batt_anim_.cur_cycle == batt_anim_.num_cycles) {
|
|
|
|
reset_animation(&batt_anim_);
|
|
|
|
next_screen_transition_ = -1;
|
|
|
|
healthd_draw_->blank_screen(true);
|
|
|
|
screen_blanked_ = true;
|
2014-05-16 00:49:06 +00:00
|
|
|
LOGV("[%" PRId64 "] animation done\n", now);
|
2021-10-21 00:15:32 +00:00
|
|
|
if (configuration_->ChargerIsOnline()) {
|
2021-10-27 05:51:29 +00:00
|
|
|
RequestEnableSuspend();
|
2021-10-21 00:15:32 +00:00
|
|
|
}
|
2011-09-22 22:49:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
disp_time = batt_anim_.frames[batt_anim_.cur_frame].disp_time;
|
2011-09-22 22:49:04 +00:00
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
if (screen_blanked_) {
|
|
|
|
healthd_draw_->blank_screen(false);
|
|
|
|
screen_blanked_ = false;
|
2018-07-17 09:49:34 +00:00
|
|
|
}
|
2018-05-23 22:48:46 +00:00
|
|
|
|
2011-09-22 22:49:04 +00:00
|
|
|
/* animation starting, set up the animation */
|
2019-10-09 00:27:11 +00:00
|
|
|
if (batt_anim_.cur_frame == 0) {
|
2014-05-16 00:49:06 +00:00
|
|
|
LOGV("[%" PRId64 "] animation starting\n", now);
|
2021-10-21 00:15:32 +00:00
|
|
|
batt_anim_.cur_level = health_info_.battery_level;
|
|
|
|
batt_anim_.cur_status = (int)health_info_.battery_status;
|
|
|
|
if (health_info_.battery_level >= 0 && batt_anim_.num_frames != 0) {
|
2019-10-09 00:27:11 +00:00
|
|
|
/* find first frame given current battery level */
|
|
|
|
for (int i = 0; i < batt_anim_.num_frames; i++) {
|
|
|
|
if (batt_anim_.cur_level >= batt_anim_.frames[i].min_level &&
|
|
|
|
batt_anim_.cur_level <= batt_anim_.frames[i].max_level) {
|
|
|
|
batt_anim_.cur_frame = i;
|
|
|
|
break;
|
2018-07-17 09:49:34 +00:00
|
|
|
}
|
2019-10-09 00:27:11 +00:00
|
|
|
}
|
2018-07-17 09:49:34 +00:00
|
|
|
|
2021-10-21 00:15:32 +00:00
|
|
|
if (configuration_->ChargerIsOnline()) {
|
2019-10-09 00:27:11 +00:00
|
|
|
// repeat the first frame first_frame_repeats times
|
|
|
|
disp_time = batt_anim_.frames[batt_anim_.cur_frame].disp_time *
|
|
|
|
batt_anim_.first_frame_repeats;
|
|
|
|
} else {
|
|
|
|
disp_time = UNPLUGGED_DISPLAY_TIME / batt_anim_.num_cycles;
|
2011-09-22 22:49:04 +00:00
|
|
|
}
|
2019-10-09 00:27:11 +00:00
|
|
|
|
|
|
|
LOGV("cur_frame=%d disp_time=%d\n", batt_anim_.cur_frame, disp_time);
|
2011-09-22 22:49:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw the new frame (@ cur_frame) */
|
2019-10-09 00:27:11 +00:00
|
|
|
healthd_draw_->redraw_screen(&batt_anim_, surf_unknown_);
|
2011-09-22 22:49:04 +00:00
|
|
|
|
|
|
|
/* if we don't have anim frames, we only have one image, so just bump
|
|
|
|
* the cycle counter and exit
|
|
|
|
*/
|
2019-10-09 00:27:11 +00:00
|
|
|
if (batt_anim_.num_frames == 0 || batt_anim_.cur_level < 0) {
|
2016-08-11 22:29:50 +00:00
|
|
|
LOGW("[%" PRId64 "] animation missing or unknown battery status\n", now);
|
2019-10-09 00:27:11 +00:00
|
|
|
next_screen_transition_ = now + BATTERY_UNKNOWN_TIME;
|
|
|
|
batt_anim_.cur_cycle++;
|
2011-09-22 22:49:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* schedule next screen transition */
|
2019-10-09 00:27:11 +00:00
|
|
|
next_screen_transition_ = curr_time_ms() + disp_time;
|
2011-09-22 22:49:04 +00:00
|
|
|
|
2014-06-23 18:13:15 +00:00
|
|
|
/* advance frame cntr to the next valid frame only if we are charging
|
2011-09-22 22:49:04 +00:00
|
|
|
* if necessary, advance cycle cntr, and reset frame cntr
|
|
|
|
*/
|
2021-10-21 00:15:32 +00:00
|
|
|
if (configuration_->ChargerIsOnline()) {
|
2019-10-09 00:27:11 +00:00
|
|
|
batt_anim_.cur_frame++;
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
while (batt_anim_.cur_frame < batt_anim_.num_frames &&
|
|
|
|
(batt_anim_.cur_level < batt_anim_.frames[batt_anim_.cur_frame].min_level ||
|
|
|
|
batt_anim_.cur_level > batt_anim_.frames[batt_anim_.cur_frame].max_level)) {
|
|
|
|
batt_anim_.cur_frame++;
|
2016-08-11 22:29:50 +00:00
|
|
|
}
|
2019-10-09 00:27:11 +00:00
|
|
|
if (batt_anim_.cur_frame >= batt_anim_.num_frames) {
|
|
|
|
batt_anim_.cur_cycle++;
|
|
|
|
batt_anim_.cur_frame = 0;
|
2014-06-23 18:13:15 +00:00
|
|
|
|
|
|
|
/* don't reset the cycle counter, since we use that as a signal
|
|
|
|
* in a test above to check if animation is over
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Stop animating if we're not charging.
|
|
|
|
* If we stop it immediately instead of going through this loop, then
|
|
|
|
* the animation would stop somewhere in the middle.
|
|
|
|
*/
|
2019-10-09 00:27:11 +00:00
|
|
|
batt_anim_.cur_frame = 0;
|
|
|
|
batt_anim_.cur_cycle++;
|
2011-09-22 22:49:04 +00:00
|
|
|
}
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
int Charger::SetKeyCallback(int code, int value) {
|
2011-10-12 23:16:05 +00:00
|
|
|
int64_t now = curr_time_ms();
|
|
|
|
int down = !!value;
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
if (code > KEY_MAX) return -1;
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2011-10-12 23:18:23 +00:00
|
|
|
/* ignore events that don't modify our state */
|
2019-10-09 00:27:11 +00:00
|
|
|
if (keys_[code].down == down) return 0;
|
2011-10-12 23:18:23 +00:00
|
|
|
|
2011-08-30 17:46:09 +00:00
|
|
|
/* only record the down even timestamp, as the amount
|
|
|
|
* of time the key spent not being pressed is not useful */
|
2019-10-09 00:27:11 +00:00
|
|
|
if (down) keys_[code].timestamp = now;
|
|
|
|
keys_[code].down = down;
|
|
|
|
keys_[code].pending = true;
|
2011-08-30 17:46:09 +00:00
|
|
|
if (down) {
|
2014-05-16 00:49:06 +00:00
|
|
|
LOGV("[%" PRId64 "] key[%d] down\n", now, code);
|
2011-08-30 17:46:09 +00:00
|
|
|
} else {
|
2019-10-09 00:27:11 +00:00
|
|
|
int64_t duration = now - keys_[code].timestamp;
|
2011-08-30 17:46:09 +00:00
|
|
|
int64_t secs = duration / 1000;
|
|
|
|
int64_t msecs = duration - secs * 1000;
|
2017-07-13 22:10:35 +00:00
|
|
|
LOGV("[%" PRId64 "] key[%d] up (was down for %" PRId64 ".%" PRId64 "sec)\n", now, code,
|
|
|
|
secs, msecs);
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
2011-10-12 23:16:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
void Charger::UpdateInputState(input_event* ev) {
|
2017-07-13 22:10:35 +00:00
|
|
|
if (ev->type != EV_KEY) return;
|
2019-10-09 00:27:11 +00:00
|
|
|
SetKeyCallback(ev->code, ev->value);
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
void Charger::SetNextKeyCheck(key_state* key, int64_t timeout) {
|
2011-08-30 17:46:09 +00:00
|
|
|
int64_t then = key->timestamp + timeout;
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
if (next_key_check_ == -1 || then < next_key_check_) next_key_check_ = then;
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
void Charger::ProcessKey(int code, int64_t now) {
|
|
|
|
key_state* key = &keys_[code];
|
2011-08-30 17:46:09 +00:00
|
|
|
|
|
|
|
if (code == KEY_POWER) {
|
|
|
|
if (key->down) {
|
|
|
|
int64_t reboot_timeout = key->timestamp + POWER_ON_KEY_TIME;
|
|
|
|
if (now >= reboot_timeout) {
|
2014-06-16 22:06:21 +00:00
|
|
|
/* We do not currently support booting from charger mode on
|
|
|
|
all devices. Check the property and continue booting or reboot
|
|
|
|
accordingly. */
|
|
|
|
if (property_get_bool("ro.enable_boot_charger_mode", false)) {
|
2014-09-23 21:54:24 +00:00
|
|
|
LOGW("[%" PRId64 "] booting from charger mode\n", now);
|
2014-06-16 22:06:21 +00:00
|
|
|
property_set("sys.boot_from_charger_mode", "1");
|
|
|
|
} else {
|
2019-10-09 00:27:11 +00:00
|
|
|
if (batt_anim_.cur_level >= boot_min_cap_) {
|
2014-10-22 01:24:11 +00:00
|
|
|
LOGW("[%" PRId64 "] rebooting\n", now);
|
2017-01-31 23:51:50 +00:00
|
|
|
reboot(RB_AUTOBOOT);
|
2014-10-22 01:24:11 +00:00
|
|
|
} else {
|
2017-07-13 22:10:35 +00:00
|
|
|
LOGV("[%" PRId64
|
|
|
|
"] ignore power-button press, battery level "
|
|
|
|
"less than minimum\n",
|
|
|
|
now);
|
2014-10-22 01:24:11 +00:00
|
|
|
}
|
2014-06-16 22:06:21 +00:00
|
|
|
}
|
2011-08-30 17:46:09 +00:00
|
|
|
} else {
|
|
|
|
/* if the key is pressed but timeout hasn't expired,
|
|
|
|
* make sure we wake up at the right-ish time to check
|
|
|
|
*/
|
2019-10-09 00:27:11 +00:00
|
|
|
SetNextKeyCheck(key, POWER_ON_KEY_TIME);
|
2014-10-22 21:16:35 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
/* Turn on the display and kick animation on power-key press
|
|
|
|
* rather than on key release
|
|
|
|
*/
|
2019-10-09 00:27:11 +00:00
|
|
|
kick_animation(&batt_anim_);
|
2021-10-27 05:51:29 +00:00
|
|
|
RequestDisableSuspend();
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* if the power key got released, force screen state cycle */
|
2012-11-16 01:03:03 +00:00
|
|
|
if (key->pending) {
|
2019-10-09 00:27:11 +00:00
|
|
|
kick_animation(&batt_anim_);
|
2021-10-27 05:51:29 +00:00
|
|
|
RequestDisableSuspend();
|
2012-11-16 01:03:03 +00:00
|
|
|
}
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
key->pending = false;
|
|
|
|
}
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
void Charger::HandleInputState(int64_t now) {
|
|
|
|
ProcessKey(KEY_POWER, now);
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
if (next_key_check_ != -1 && now > next_key_check_) next_key_check_ = -1;
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
void Charger::HandlePowerSupplyState(int64_t now) {
|
2019-03-31 09:22:47 +00:00
|
|
|
int timer_shutdown = UNPLUGGED_SHUTDOWN_TIME;
|
2019-10-09 00:27:11 +00:00
|
|
|
if (!have_battery_state_) return;
|
2013-09-09 19:09:08 +00:00
|
|
|
|
2021-10-21 00:15:32 +00:00
|
|
|
if (!configuration_->ChargerIsOnline()) {
|
2021-10-27 05:51:29 +00:00
|
|
|
RequestDisableSuspend();
|
2019-10-09 00:27:11 +00:00
|
|
|
if (next_pwr_check_ == -1) {
|
2018-07-17 09:49:34 +00:00
|
|
|
/* Last cycle would have stopped at the extreme top of battery-icon
|
|
|
|
* Need to show the correct level corresponding to capacity.
|
|
|
|
*
|
2019-10-09 00:27:11 +00:00
|
|
|
* Reset next_screen_transition_ to update screen immediately.
|
2018-07-17 09:49:34 +00:00
|
|
|
* Reset & kick animation to show complete animation cycles
|
|
|
|
* when charger disconnected.
|
|
|
|
*/
|
2019-03-31 09:22:47 +00:00
|
|
|
timer_shutdown =
|
|
|
|
property_get_int32(UNPLUGGED_SHUTDOWN_TIME_PROP, UNPLUGGED_SHUTDOWN_TIME);
|
2019-10-09 00:27:11 +00:00
|
|
|
next_screen_transition_ = now - 1;
|
|
|
|
reset_animation(&batt_anim_);
|
|
|
|
kick_animation(&batt_anim_);
|
|
|
|
next_pwr_check_ = now + timer_shutdown;
|
2014-09-23 21:54:24 +00:00
|
|
|
LOGW("[%" PRId64 "] device unplugged: shutting down in %" PRId64 " (@ %" PRId64 ")\n",
|
2019-10-09 00:27:11 +00:00
|
|
|
now, (int64_t)timer_shutdown, next_pwr_check_);
|
|
|
|
} else if (now >= next_pwr_check_) {
|
2014-09-23 21:54:24 +00:00
|
|
|
LOGW("[%" PRId64 "] shutting down\n", now);
|
2017-01-31 23:51:50 +00:00
|
|
|
reboot(RB_POWER_OFF);
|
2011-08-30 17:46:09 +00:00
|
|
|
} else {
|
|
|
|
/* otherwise we already have a shutdown timer scheduled */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* online supply present, reset shutdown timer if set */
|
2019-10-09 00:27:11 +00:00
|
|
|
if (next_pwr_check_ != -1) {
|
|
|
|
/* Reset next_screen_transition_ to update screen immediately.
|
2018-07-17 09:49:34 +00:00
|
|
|
* Reset & kick animation to show complete animation cycles
|
|
|
|
* when charger connected again.
|
|
|
|
*/
|
2021-10-27 05:51:29 +00:00
|
|
|
RequestDisableSuspend();
|
2019-10-09 00:27:11 +00:00
|
|
|
next_screen_transition_ = now - 1;
|
|
|
|
reset_animation(&batt_anim_);
|
|
|
|
kick_animation(&batt_anim_);
|
2018-07-17 09:49:34 +00:00
|
|
|
LOGW("[%" PRId64 "] device plugged in: shutdown cancelled\n", now);
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
2019-10-09 00:27:11 +00:00
|
|
|
next_pwr_check_ = -1;
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-21 00:15:32 +00:00
|
|
|
void Charger::OnHeartbeat() {
|
2019-10-09 00:27:11 +00:00
|
|
|
// charger* charger = &charger_state;
|
2013-09-09 19:09:08 +00:00
|
|
|
int64_t now = curr_time_ms();
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
HandleInputState(now);
|
|
|
|
HandlePowerSupplyState(now);
|
2013-09-09 19:09:08 +00:00
|
|
|
|
|
|
|
/* do screen update last in case any of the above want to start
|
|
|
|
* screen transitions (animations, etc)
|
|
|
|
*/
|
2019-10-09 00:27:11 +00:00
|
|
|
UpdateScreenState(now);
|
2013-09-09 19:09:08 +00:00
|
|
|
}
|
|
|
|
|
2021-10-21 00:15:32 +00:00
|
|
|
void Charger::OnHealthInfoChanged(const ChargerHealthInfo& health_info) {
|
2019-10-09 00:27:11 +00:00
|
|
|
if (!have_battery_state_) {
|
|
|
|
have_battery_state_ = true;
|
|
|
|
next_screen_transition_ = curr_time_ms() - 1;
|
2021-10-27 05:51:29 +00:00
|
|
|
RequestDisableSuspend();
|
2019-10-09 00:27:11 +00:00
|
|
|
reset_animation(&batt_anim_);
|
|
|
|
kick_animation(&batt_anim_);
|
2013-09-09 19:09:08 +00:00
|
|
|
}
|
2021-10-21 00:15:32 +00:00
|
|
|
health_info_ = health_info;
|
2013-09-09 19:09:08 +00:00
|
|
|
}
|
|
|
|
|
2021-10-21 00:15:32 +00:00
|
|
|
int Charger::OnPrepareToWait(void) {
|
2013-09-09 19:09:08 +00:00
|
|
|
int64_t now = curr_time_ms();
|
2011-08-30 17:46:09 +00:00
|
|
|
int64_t next_event = INT64_MAX;
|
|
|
|
int64_t timeout;
|
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
LOGV("[%" PRId64 "] next screen: %" PRId64 " next key: %" PRId64 " next pwr: %" PRId64 "\n",
|
2019-10-09 00:27:11 +00:00
|
|
|
now, next_screen_transition_, next_key_check_, next_pwr_check_);
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
if (next_screen_transition_ != -1) next_event = next_screen_transition_;
|
|
|
|
if (next_key_check_ != -1 && next_key_check_ < next_event) next_event = next_key_check_;
|
|
|
|
if (next_pwr_check_ != -1 && next_pwr_check_ < next_event) next_event = next_pwr_check_;
|
2011-08-30 17:46:09 +00:00
|
|
|
|
|
|
|
if (next_event != -1 && next_event != INT64_MAX)
|
|
|
|
timeout = max(0, next_event - now);
|
|
|
|
else
|
|
|
|
timeout = -1;
|
2013-09-09 19:09:08 +00:00
|
|
|
|
2017-07-13 22:10:35 +00:00
|
|
|
return (int)timeout;
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
int Charger::InputCallback(int fd, unsigned int epevents) {
|
2017-07-13 22:10:35 +00:00
|
|
|
input_event ev;
|
2011-08-30 17:46:09 +00:00
|
|
|
int ret;
|
|
|
|
|
2013-09-09 19:09:08 +00:00
|
|
|
ret = ev_get_input(fd, epevents, &ev);
|
2017-07-13 22:10:35 +00:00
|
|
|
if (ret) return -1;
|
2019-10-09 00:27:11 +00:00
|
|
|
UpdateInputState(&ev);
|
2011-08-30 17:46:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
static void charger_event_handler(HealthLoop* /*charger_loop*/, uint32_t /*epevents*/) {
|
2011-08-30 17:46:09 +00:00
|
|
|
int ret;
|
|
|
|
|
2013-09-09 19:09:08 +00:00
|
|
|
ret = ev_wait(-1);
|
2017-07-13 22:10:35 +00:00
|
|
|
if (!ret) ev_dispatch();
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
void Charger::InitAnimation() {
|
2016-08-11 22:29:50 +00:00
|
|
|
bool parse_success;
|
|
|
|
|
|
|
|
std::string content;
|
2021-10-27 00:20:25 +00:00
|
|
|
|
|
|
|
#if defined(__ANDROID_VNDK__)
|
|
|
|
if (base::ReadFileToString(vendor_animation_desc_path, &content)) {
|
|
|
|
parse_success = parse_animation_desc(content, &batt_anim_);
|
|
|
|
batt_anim_.set_resource_root(vendor_animation_root);
|
|
|
|
} else {
|
|
|
|
LOGW("Could not open animation description at %s\n", vendor_animation_desc_path);
|
|
|
|
parse_success = false;
|
|
|
|
}
|
|
|
|
#else
|
2019-01-28 20:55:54 +00:00
|
|
|
if (base::ReadFileToString(product_animation_desc_path, &content)) {
|
2019-10-09 00:27:11 +00:00
|
|
|
parse_success = parse_animation_desc(content, &batt_anim_);
|
|
|
|
batt_anim_.set_resource_root(product_animation_root);
|
2019-01-28 20:55:54 +00:00
|
|
|
} else if (base::ReadFileToString(animation_desc_path, &content)) {
|
2019-10-09 00:27:11 +00:00
|
|
|
parse_success = parse_animation_desc(content, &batt_anim_);
|
charger: Load default resources from /system
When charger resources are missing from /product, before this change,
images are loaded from /res/images/charger. After this change, charger
first checks if the resource exists at that location, and if not, use
resource under /system/etc/res/images/charger.
On devices that uses resources from /product, this change has no effect.
On devices that uses resources from /res,
- if an old image is mounted at /, charger continues to load resources
from /res.
- if a new image is mounted at /, that is, battery_fail and
battery_scale may not exist under /res, charger loads them from /system.
There are no font files installed by modules defined here, so any
device-specific font files stay at /res.
Also create virtual function wrappers over minui APIs to be mocked
later.
See next change on moving battery_scale and battery_fail images to
/system.
Test: build and inspect system/etc/res/images/charger
Bug: 143907179
Change-Id: I4895b9602274fa4a1ebb4d7d3b842622b81b7b51
2020-08-05 23:15:15 +00:00
|
|
|
// Fallback resources always exist in system_animation_root. On legacy devices with an old
|
|
|
|
// ramdisk image, resources may be overridden under root. For example,
|
|
|
|
// /res/images/charger/battery_fail.png may not be the same as
|
|
|
|
// system/core/healthd/images/battery_fail.png in the source tree, but is a device-specific
|
|
|
|
// image. Hence, load from /res, and fall back to /system/etc/res.
|
|
|
|
batt_anim_.set_resource_root(legacy_animation_root, system_animation_root);
|
2016-08-11 22:29:50 +00:00
|
|
|
} else {
|
|
|
|
LOGW("Could not open animation description at %s\n", animation_desc_path);
|
|
|
|
parse_success = false;
|
|
|
|
}
|
2021-10-27 00:20:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__ANDROID_VNDK__)
|
|
|
|
auto default_animation_root = vendor_default_animation_root;
|
|
|
|
#else
|
|
|
|
auto default_animation_root = system_animation_root;
|
|
|
|
#endif
|
2016-08-11 22:29:50 +00:00
|
|
|
|
|
|
|
if (!parse_success) {
|
2021-10-27 00:20:25 +00:00
|
|
|
LOGW("Could not parse animation description. "
|
|
|
|
"Using default animation with resources at %s\n",
|
|
|
|
default_animation_root);
|
2019-10-09 00:27:11 +00:00
|
|
|
batt_anim_ = BASE_ANIMATION;
|
2021-10-27 00:20:25 +00:00
|
|
|
batt_anim_.animation_file.assign(default_animation_root + "charger/battery_scale.png"s);
|
2019-10-09 00:27:11 +00:00
|
|
|
InitDefaultAnimationFrames();
|
|
|
|
batt_anim_.frames = owned_frames_.data();
|
|
|
|
batt_anim_.num_frames = owned_frames_.size();
|
2016-08-11 22:29:50 +00:00
|
|
|
}
|
2019-10-09 00:27:11 +00:00
|
|
|
if (batt_anim_.fail_file.empty()) {
|
2021-10-27 00:20:25 +00:00
|
|
|
batt_anim_.fail_file.assign(default_animation_root + "charger/battery_fail.png"s);
|
2016-08-11 22:29:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LOGV("Animation Description:\n");
|
2019-10-09 00:27:11 +00:00
|
|
|
LOGV(" animation: %d %d '%s' (%d)\n", batt_anim_.num_cycles, batt_anim_.first_frame_repeats,
|
|
|
|
batt_anim_.animation_file.c_str(), batt_anim_.num_frames);
|
|
|
|
LOGV(" fail_file: '%s'\n", batt_anim_.fail_file.c_str());
|
|
|
|
LOGV(" clock: %d %d %d %d %d %d '%s'\n", batt_anim_.text_clock.pos_x,
|
|
|
|
batt_anim_.text_clock.pos_y, batt_anim_.text_clock.color_r, batt_anim_.text_clock.color_g,
|
|
|
|
batt_anim_.text_clock.color_b, batt_anim_.text_clock.color_a,
|
|
|
|
batt_anim_.text_clock.font_file.c_str());
|
|
|
|
LOGV(" percent: %d %d %d %d %d %d '%s'\n", batt_anim_.text_percent.pos_x,
|
|
|
|
batt_anim_.text_percent.pos_y, batt_anim_.text_percent.color_r,
|
|
|
|
batt_anim_.text_percent.color_g, batt_anim_.text_percent.color_b,
|
|
|
|
batt_anim_.text_percent.color_a, batt_anim_.text_percent.font_file.c_str());
|
|
|
|
for (int i = 0; i < batt_anim_.num_frames; i++) {
|
|
|
|
LOGV(" frame %.2d: %d %d %d\n", i, batt_anim_.frames[i].disp_time,
|
|
|
|
batt_anim_.frames[i].min_level, batt_anim_.frames[i].max_level);
|
2016-08-11 22:29:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-21 00:15:32 +00:00
|
|
|
void Charger::OnInit(struct healthd_config* config) {
|
2011-08-30 17:46:09 +00:00
|
|
|
int ret;
|
2011-09-22 22:49:04 +00:00
|
|
|
int i;
|
2013-09-09 19:09:08 +00:00
|
|
|
int epollfd;
|
2011-08-30 17:46:09 +00:00
|
|
|
|
2011-09-30 00:20:07 +00:00
|
|
|
dump_last_kmsg();
|
|
|
|
|
2014-09-23 21:54:24 +00:00
|
|
|
LOGW("--------------- STARTING CHARGER MODE ---------------\n");
|
2011-09-30 00:20:07 +00:00
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
ret = ev_init(
|
|
|
|
std::bind(&Charger::InputCallback, this, std::placeholders::_1, std::placeholders::_2));
|
2013-09-09 19:09:08 +00:00
|
|
|
if (!ret) {
|
|
|
|
epollfd = ev_get_epollfd();
|
2021-10-21 00:15:32 +00:00
|
|
|
configuration_->ChargerRegisterEvent(epollfd, &charger_event_handler, EVENT_WAKEUP_FD);
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
InitAnimation();
|
2016-08-11 22:29:50 +00:00
|
|
|
|
2020-08-12 14:03:50 +00:00
|
|
|
ret = CreateDisplaySurface(batt_anim_.fail_file, &surf_unknown_);
|
2011-08-30 17:46:09 +00:00
|
|
|
if (ret < 0) {
|
2021-10-27 00:20:25 +00:00
|
|
|
#if !defined(__ANDROID_VNDK__)
|
2018-05-23 22:48:46 +00:00
|
|
|
LOGE("Cannot load custom battery_fail image. Reverting to built in: %d\n", ret);
|
charger: Load default resources from /system
When charger resources are missing from /product, before this change,
images are loaded from /res/images/charger. After this change, charger
first checks if the resource exists at that location, and if not, use
resource under /system/etc/res/images/charger.
On devices that uses resources from /product, this change has no effect.
On devices that uses resources from /res,
- if an old image is mounted at /, charger continues to load resources
from /res.
- if a new image is mounted at /, that is, battery_fail and
battery_scale may not exist under /res, charger loads them from /system.
There are no font files installed by modules defined here, so any
device-specific font files stay at /res.
Also create virtual function wrappers over minui APIs to be mocked
later.
See next change on moving battery_scale and battery_fail images to
/system.
Test: build and inspect system/etc/res/images/charger
Bug: 143907179
Change-Id: I4895b9602274fa4a1ebb4d7d3b842622b81b7b51
2020-08-05 23:15:15 +00:00
|
|
|
ret = CreateDisplaySurface((system_animation_root + "charger/battery_fail.png"s).c_str(),
|
|
|
|
&surf_unknown_);
|
2021-10-27 00:20:25 +00:00
|
|
|
#endif
|
2016-08-11 22:29:50 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
LOGE("Cannot load built in battery_fail image\n");
|
2019-10-09 00:27:11 +00:00
|
|
|
surf_unknown_ = NULL;
|
2016-08-11 22:29:50 +00:00
|
|
|
}
|
2011-09-22 22:49:04 +00:00
|
|
|
}
|
|
|
|
|
2015-04-15 17:25:55 +00:00
|
|
|
GRSurface** scale_frames;
|
2014-03-11 15:42:09 +00:00
|
|
|
int scale_count;
|
2015-12-16 18:57:10 +00:00
|
|
|
int scale_fps; // Not in use (charger/battery_scale doesn't have FPS text
|
|
|
|
// chunk). We are using hard-coded frame.disp_time instead.
|
2020-08-12 14:03:50 +00:00
|
|
|
ret = CreateMultiDisplaySurface(batt_anim_.animation_file, &scale_count, &scale_fps,
|
charger: Load default resources from /system
When charger resources are missing from /product, before this change,
images are loaded from /res/images/charger. After this change, charger
first checks if the resource exists at that location, and if not, use
resource under /system/etc/res/images/charger.
On devices that uses resources from /product, this change has no effect.
On devices that uses resources from /res,
- if an old image is mounted at /, charger continues to load resources
from /res.
- if a new image is mounted at /, that is, battery_fail and
battery_scale may not exist under /res, charger loads them from /system.
There are no font files installed by modules defined here, so any
device-specific font files stay at /res.
Also create virtual function wrappers over minui APIs to be mocked
later.
See next change on moving battery_scale and battery_fail images to
/system.
Test: build and inspect system/etc/res/images/charger
Bug: 143907179
Change-Id: I4895b9602274fa4a1ebb4d7d3b842622b81b7b51
2020-08-05 23:15:15 +00:00
|
|
|
&scale_frames);
|
2014-03-11 15:42:09 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
LOGE("Cannot load battery_scale image\n");
|
2019-10-09 00:27:11 +00:00
|
|
|
batt_anim_.num_frames = 0;
|
|
|
|
batt_anim_.num_cycles = 1;
|
|
|
|
} else if (scale_count != batt_anim_.num_frames) {
|
2017-07-13 22:10:35 +00:00
|
|
|
LOGE("battery_scale image has unexpected frame count (%d, expected %d)\n", scale_count,
|
2019-10-09 00:27:11 +00:00
|
|
|
batt_anim_.num_frames);
|
|
|
|
batt_anim_.num_frames = 0;
|
|
|
|
batt_anim_.num_cycles = 1;
|
2014-03-11 15:42:09 +00:00
|
|
|
} else {
|
2019-10-09 00:27:11 +00:00
|
|
|
for (i = 0; i < batt_anim_.num_frames; i++) {
|
|
|
|
batt_anim_.frames[i].surface = scale_frames[i];
|
2011-09-22 22:49:04 +00:00
|
|
|
}
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
2019-10-09 00:27:11 +00:00
|
|
|
ev_sync_key_state(std::bind(&Charger::SetKeyCallback, this, std::placeholders::_1,
|
|
|
|
std::placeholders::_2));
|
2011-10-12 23:16:05 +00:00
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
next_screen_transition_ = -1;
|
|
|
|
next_key_check_ = -1;
|
|
|
|
next_pwr_check_ = -1;
|
|
|
|
wait_batt_level_timestamp_ = 0;
|
2017-11-08 18:57:52 +00:00
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
// Retrieve healthd_config from the existing health HAL.
|
2021-10-21 00:15:32 +00:00
|
|
|
configuration_->ChargerInitConfig(config);
|
2017-11-08 18:57:52 +00:00
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
boot_min_cap_ = config->boot_min_cap;
|
2011-08-30 17:46:09 +00:00
|
|
|
}
|
2018-09-11 17:46:35 +00:00
|
|
|
|
charger: Load default resources from /system
When charger resources are missing from /product, before this change,
images are loaded from /res/images/charger. After this change, charger
first checks if the resource exists at that location, and if not, use
resource under /system/etc/res/images/charger.
On devices that uses resources from /product, this change has no effect.
On devices that uses resources from /res,
- if an old image is mounted at /, charger continues to load resources
from /res.
- if a new image is mounted at /, that is, battery_fail and
battery_scale may not exist under /res, charger loads them from /system.
There are no font files installed by modules defined here, so any
device-specific font files stay at /res.
Also create virtual function wrappers over minui APIs to be mocked
later.
See next change on moving battery_scale and battery_fail images to
/system.
Test: build and inspect system/etc/res/images/charger
Bug: 143907179
Change-Id: I4895b9602274fa4a1ebb4d7d3b842622b81b7b51
2020-08-05 23:15:15 +00:00
|
|
|
int Charger::CreateDisplaySurface(const std::string& name, GRSurface** surface) {
|
|
|
|
return res_create_display_surface(name.c_str(), surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Charger::CreateMultiDisplaySurface(const std::string& name, int* frames, int* fps,
|
|
|
|
GRSurface*** surface) {
|
|
|
|
return res_create_multi_display_surface(name.c_str(), frames, fps, surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_resource_root_for(const std::string& root, const std::string& backup_root,
|
|
|
|
std::string* value) {
|
|
|
|
if (value->empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string new_value = root + *value + ".png";
|
|
|
|
// If |backup_root| is provided, additionally check whether the file under |root| is
|
|
|
|
// accessible or not. If not accessible, fallback to file under |backup_root|.
|
|
|
|
if (!backup_root.empty() && access(new_value.data(), F_OK) == -1) {
|
|
|
|
new_value = backup_root + *value + ".png";
|
|
|
|
}
|
|
|
|
|
|
|
|
*value = new_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void animation::set_resource_root(const std::string& root, const std::string& backup_root) {
|
|
|
|
CHECK(android::base::StartsWith(root, "/") && android::base::EndsWith(root, "/"))
|
|
|
|
<< "animation root " << root << " must start and end with /";
|
|
|
|
CHECK(backup_root.empty() || (android::base::StartsWith(backup_root, "/") &&
|
|
|
|
android::base::EndsWith(backup_root, "/")))
|
|
|
|
<< "animation backup root " << backup_root << " must start and end with /";
|
|
|
|
set_resource_root_for(root, backup_root, &animation_file);
|
|
|
|
set_resource_root_for(root, backup_root, &fail_file);
|
|
|
|
set_resource_root_for(root, backup_root, &text_clock.font_file);
|
|
|
|
set_resource_root_for(root, backup_root, &text_percent.font_file);
|
|
|
|
}
|
|
|
|
|
2019-10-09 00:27:11 +00:00
|
|
|
} // namespace android
|