Merge remote-tracking branch 'goog/stage-aosp-master' into HEAD

This commit is contained in:
Bill Yi 2016-12-06 15:07:48 -08:00
commit a794775592
40 changed files with 1169 additions and 306 deletions

View file

@ -21,7 +21,6 @@
#include <string>
#include <vector>
#include <android-base/parseint.h>
#include <android-base/strings.h>
#include "sysdeps.h"
@ -144,11 +143,9 @@ class BugreportStandardStreamsCallback : public StandardStreamsCallbackInterface
//
size_t idx1 = line.rfind(BUGZ_PROGRESS_PREFIX) + strlen(BUGZ_PROGRESS_PREFIX);
size_t idx2 = line.rfind(BUGZ_PROGRESS_SEPARATOR);
int progress, total;
if (android::base::ParseInt(line.substr(idx1, (idx2 - idx1)), &progress) &&
android::base::ParseInt(line.substr(idx2 + 1), &total)) {
br_->UpdateProgress(line_message_, progress, total);
}
int progress = std::stoi(line.substr(idx1, (idx2 - idx1)));
int total = std::stoi(line.substr(idx2 + 1));
br_->UpdateProgress(line_message_, progress, total);
} else {
invalid_lines_.push_back(line);
}

View file

@ -185,6 +185,16 @@ out:
return allowed;
}
static bool pid_contains_tid(pid_t pid, pid_t tid) {
char task_path[PATH_MAX];
if (snprintf(task_path, PATH_MAX, "/proc/%d/task/%d", pid, tid) >= PATH_MAX) {
ALOGE("debuggerd: task path overflow (pid = %d, tid = %d)\n", pid, tid);
exit(1);
}
return access(task_path, F_OK) == 0;
}
static int read_request(int fd, debugger_request_t* out_request) {
ucred cr;
socklen_t len = sizeof(cr);
@ -227,16 +237,13 @@ static int read_request(int fd, debugger_request_t* out_request) {
if (msg.action == DEBUGGER_ACTION_CRASH) {
// Ensure that the tid reported by the crashing process is valid.
char buf[64];
struct stat s;
snprintf(buf, sizeof buf, "/proc/%d/task/%d", out_request->pid, out_request->tid);
if (stat(buf, &s)) {
ALOGE("tid %d does not exist in pid %d. ignoring debug request\n",
out_request->tid, out_request->pid);
// This check needs to happen again after ptracing the requested thread to prevent a race.
if (!pid_contains_tid(out_request->pid, out_request->tid)) {
ALOGE("tid %d does not exist in pid %d. ignoring debug request\n", out_request->tid,
out_request->pid);
return -1;
}
} else if (cr.uid == 0
|| (cr.uid == AID_SYSTEM && msg.action == DEBUGGER_ACTION_DUMP_BACKTRACE)) {
} else if (cr.uid == 0 || (cr.uid == AID_SYSTEM && msg.action == DEBUGGER_ACTION_DUMP_BACKTRACE)) {
// Only root or system can ask us to attach to any process and dump it explicitly.
// However, system is only allowed to collect backtraces but cannot dump tombstones.
status = get_process_info(out_request->tid, &out_request->pid,
@ -413,10 +420,31 @@ static void redirect_to_32(int fd, debugger_request_t* request) {
}
#endif
static void ptrace_siblings(pid_t pid, pid_t main_tid, pid_t ignore_tid, std::set<pid_t>& tids) {
char task_path[64];
// Attach to a thread, and verify that it's still a member of the given process
static bool ptrace_attach_thread(pid_t pid, pid_t tid) {
if (ptrace(PTRACE_ATTACH, tid, 0, 0) != 0) {
return false;
}
snprintf(task_path, sizeof(task_path), "/proc/%d/task", pid);
// Make sure that the task we attached to is actually part of the pid we're dumping.
if (!pid_contains_tid(pid, tid)) {
if (ptrace(PTRACE_DETACH, tid, 0, 0) != 0) {
ALOGE("debuggerd: failed to detach from thread '%d'", tid);
exit(1);
}
return false;
}
return true;
}
static void ptrace_siblings(pid_t pid, pid_t main_tid, pid_t ignore_tid, std::set<pid_t>& tids) {
char task_path[PATH_MAX];
if (snprintf(task_path, PATH_MAX, "/proc/%d/task", pid) >= PATH_MAX) {
ALOGE("debuggerd: task path overflow (pid = %d)\n", pid);
abort();
}
std::unique_ptr<DIR, int (*)(DIR*)> d(opendir(task_path), closedir);
@ -443,7 +471,7 @@ static void ptrace_siblings(pid_t pid, pid_t main_tid, pid_t ignore_tid, std::se
continue;
}
if (ptrace(PTRACE_ATTACH, tid, 0, 0) < 0) {
if (!ptrace_attach_thread(pid, tid)) {
ALOGE("debuggerd: ptrace attach to %d failed: %s", tid, strerror(errno));
continue;
}
@ -572,11 +600,33 @@ static void worker_process(int fd, debugger_request_t& request) {
// debugger_signal_handler().
// Attach to the target process.
if (ptrace(PTRACE_ATTACH, request.tid, 0, 0) != 0) {
if (!ptrace_attach_thread(request.pid, request.tid)) {
ALOGE("debuggerd: ptrace attach failed: %s", strerror(errno));
exit(1);
}
// DEBUGGER_ACTION_CRASH requests can come from arbitrary processes and the tid field in the
// request is sent from the other side. If an attacker can cause a process to be spawned with the
// pid of their process, they could trick debuggerd into dumping that process by exiting after
// sending the request. Validate the trusted request.uid/gid to defend against this.
if (request.action == DEBUGGER_ACTION_CRASH) {
pid_t pid;
uid_t uid;
gid_t gid;
if (get_process_info(request.tid, &pid, &uid, &gid) != 0) {
ALOGE("debuggerd: failed to get process info for tid '%d'", request.tid);
exit(1);
}
if (pid != request.pid || uid != request.uid || gid != request.gid) {
ALOGE(
"debuggerd: attached task %d does not match request: "
"expected pid=%d,uid=%d,gid=%d, actual pid=%d,uid=%d,gid=%d",
request.tid, request.pid, request.uid, request.gid, pid, uid, gid);
exit(1);
}
}
// Don't attach to the sibling threads if we want to attach gdb.
// Supposedly, it makes the process less reliable.
bool attach_gdb = should_attach_gdb(request);

View file

@ -22,7 +22,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/swap.h>
@ -39,7 +38,6 @@
#include <ext4_utils/ext4_sb.h>
#include <ext4_utils/ext4_utils.h>
#include <ext4_utils/wipe.h>
#include <linux/fs.h>
#include <linux/loop.h>
#include <logwrap/logwrap.h>
#include <private/android_filesystem_config.h>
@ -52,9 +50,8 @@
#define KEY_IN_FOOTER "footer"
#define E2FSCK_BIN "/system/bin/e2fsck"
#define F2FS_FSCK_BIN "/system/bin/fsck.f2fs"
#define F2FS_FSCK_BIN "/system/bin/fsck.f2fs"
#define MKSWAP_BIN "/system/bin/mkswap"
#define TUNE2FS_BIN "/system/bin/tune2fs"
#define FSCK_LOG_FILE "/dev/fscklogs/log"
@ -183,99 +180,6 @@ static void check_fs(char *blk_device, char *fs_type, char *target)
return;
}
/* Function to read the primary superblock */
static int read_super_block(int fd, struct ext4_super_block *sb)
{
off64_t ret;
ret = lseek64(fd, 1024, SEEK_SET);
if (ret < 0)
return ret;
ret = read(fd, sb, sizeof(*sb));
if (ret < 0)
return ret;
if (ret != sizeof(*sb))
return ret;
return 0;
}
static ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es)
{
return ((ext4_fsblk_t)le32_to_cpu(es->s_blocks_count_hi) << 32) |
le32_to_cpu(es->s_blocks_count_lo);
}
static ext4_fsblk_t ext4_r_blocks_count(struct ext4_super_block *es)
{
return ((ext4_fsblk_t)le32_to_cpu(es->s_r_blocks_count_hi) << 32) |
le32_to_cpu(es->s_r_blocks_count_lo);
}
static void do_reserved_size(char *blk_device, char *fs_type, struct fstab_rec *rec)
{
/* Check for the types of filesystems we know how to check */
if (!strcmp(fs_type, "ext2") || !strcmp(fs_type, "ext3") || !strcmp(fs_type, "ext4")) {
/*
* Some system images do not have tune2fs for licensing reasons
* Detect these and skip reserve blocks.
*/
if (access(TUNE2FS_BIN, X_OK)) {
ERROR("Not running %s on %s (executable not in system image)\n",
TUNE2FS_BIN, blk_device);
} else {
INFO("Running %s on %s\n", TUNE2FS_BIN, blk_device);
int status = 0;
int ret = 0;
unsigned long reserved_blocks = 0;
int fd = TEMP_FAILURE_RETRY(open(blk_device, O_RDONLY | O_CLOEXEC));
if (fd >= 0) {
struct ext4_super_block sb;
ret = read_super_block(fd, &sb);
if (ret < 0) {
ERROR("Can't read '%s' super block: %s\n", blk_device, strerror(errno));
goto out;
}
reserved_blocks = rec->reserved_size / EXT4_BLOCK_SIZE(&sb);
unsigned long reserved_threshold = ext4_blocks_count(&sb) * 0.02;
if (reserved_threshold < reserved_blocks) {
WARNING("Reserved blocks %lu is too large\n", reserved_blocks);
reserved_blocks = reserved_threshold;
}
if (ext4_r_blocks_count(&sb) == reserved_blocks) {
INFO("Have reserved same blocks\n");
goto out;
}
} else {
ERROR("Failed to open '%s': %s\n", blk_device, strerror(errno));
return;
}
char buf[16] = {0};
snprintf(buf, sizeof (buf), "-r %lu", reserved_blocks);
char *tune2fs_argv[] = {
TUNE2FS_BIN,
buf,
blk_device,
};
ret = android_fork_execvp_ext(ARRAY_SIZE(tune2fs_argv), tune2fs_argv,
&status, true, LOG_KLOG | LOG_FILE,
true, NULL, NULL, 0);
if (ret < 0) {
/* No need to check for error in fork, we can't really handle it now */
ERROR("Failed trying to run %s\n", TUNE2FS_BIN);
}
out:
close(fd);
}
}
}
static void remove_trailing_slashes(char *n)
{
int len;
@ -338,7 +242,7 @@ static int __mount(const char *source, const char *target, const struct fstab_re
return ret;
}
static int fs_match(const char *in1, const char *in2)
static int fs_match(char *in1, char *in2)
{
char *n1;
char *n2;
@ -421,12 +325,6 @@ static int mount_with_alternatives(struct fstab *fstab, int start_idx, int *end_
check_fs(fstab->recs[i].blk_device, fstab->recs[i].fs_type,
fstab->recs[i].mount_point);
}
if (fstab->recs[i].fs_mgr_flags & MF_RESERVEDSIZE) {
do_reserved_size(fstab->recs[i].blk_device, fstab->recs[i].fs_type,
&fstab->recs[i]);
}
if (!__mount(fstab->recs[i].blk_device, fstab->recs[i].mount_point, &fstab->recs[i])) {
*attempted_idx = i;
mounted = 1;
@ -754,7 +652,7 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode)
* If multiple fstab entries are to be mounted on "n_name", it will try to mount each one
* in turn, and stop on 1st success, or no more match.
*/
int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device,
int fs_mgr_do_mount(struct fstab *fstab, char *n_name, char *n_blk_device,
char *tmp_mount_point)
{
int i = 0;
@ -792,10 +690,6 @@ int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device,
fstab->recs[i].mount_point);
}
if (fstab->recs[i].fs_mgr_flags & MF_RESERVEDSIZE) {
do_reserved_size(n_blk_device, fstab->recs[i].fs_type, &fstab->recs[i]);
}
if ((fstab->recs[i].fs_mgr_flags & MF_VERIFY) && device_is_secure()) {
int rc = fs_mgr_setup_verity(&fstab->recs[i]);
if (__android_log_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) {

View file

@ -33,12 +33,12 @@ struct fs_mgr_flag_values {
int swap_prio;
int max_comp_streams;
unsigned int zram_size;
uint64_t reserved_size;
unsigned int file_encryption_mode;
};
struct flag_list {
const char *name;
unsigned flag;
unsigned int flag;
};
static struct flag_list mount_flags[] = {
@ -65,7 +65,7 @@ static struct flag_list fs_mgr_flags[] = {
{ "check", MF_CHECK },
{ "encryptable=",MF_CRYPT },
{ "forceencrypt=",MF_FORCECRYPT },
{ "fileencryption",MF_FILEENCRYPTION },
{ "fileencryption=",MF_FILEENCRYPTION },
{ "forcefdeorfbe=",MF_FORCEFDEORFBE },
{ "nonremovable",MF_NONREMOVABLE },
{ "voldmanaged=",MF_VOLDMANAGED},
@ -81,11 +81,19 @@ static struct flag_list fs_mgr_flags[] = {
{ "slotselect", MF_SLOTSELECT },
{ "nofail", MF_NOFAIL },
{ "latemount", MF_LATEMOUNT },
{ "reservedsize=", MF_RESERVEDSIZE },
{ "defaults", 0 },
{ 0, 0 },
};
#define EM_SOFTWARE 1
#define EM_ICE 2
static struct flag_list encryption_modes[] = {
{"software", EM_SOFTWARE},
{"ice", EM_ICE},
{0, 0}
};
static uint64_t calculate_zram_size(unsigned int percentage)
{
uint64_t total;
@ -99,20 +107,6 @@ static uint64_t calculate_zram_size(unsigned int percentage)
return total;
}
static uint64_t parse_size(const char *arg)
{
char *endptr;
uint64_t size = strtoull(arg, &endptr, 10);
if (*endptr == 'k' || *endptr == 'K')
size *= 1024LL;
else if (*endptr == 'm' || *endptr == 'M')
size *= 1024LL * 1024LL;
else if (*endptr == 'g' || *endptr == 'G')
size *= 1024LL * 1024LL * 1024LL;
return size;
}
static int parse_flags(char *flags, struct flag_list *fl,
struct fs_mgr_flag_values *flag_vals,
char *fs_options, int fs_options_len)
@ -166,6 +160,21 @@ static int parse_flags(char *flags, struct flag_list *fl,
* location of the keys. Get it and return it.
*/
flag_vals->key_loc = strdup(strchr(p, '=') + 1);
flag_vals->file_encryption_mode = EM_SOFTWARE;
} else if ((fl[i].flag == MF_FILEENCRYPTION) && flag_vals) {
/* The fileencryption flag is followed by an = and the
* type of the encryption. Get it and return it.
*/
const struct flag_list *j;
const char *mode = strchr(p, '=') + 1;
for (j = encryption_modes; j->name; ++j) {
if (!strcmp(mode, j->name)) {
flag_vals->file_encryption_mode = j->flag;
}
}
if (flag_vals->file_encryption_mode == 0) {
ERROR("Unknown file encryption mode: %s\n", mode);
}
} else if ((fl[i].flag == MF_LENGTH) && flag_vals) {
/* The length flag is followed by an = and the
* size of the partition. Get it and return it.
@ -207,11 +216,6 @@ static int parse_flags(char *flags, struct flag_list *fl,
flag_vals->zram_size = calculate_zram_size(val);
else
flag_vals->zram_size = val;
} else if ((fl[i].flag == MF_RESERVEDSIZE) && flag_vals) {
/* The reserved flag is followed by an = and the
* reserved size of the partition. Get it and return it.
*/
flag_vals->reserved_size = parse_size(strchr(p, '=') + 1);
}
break;
}
@ -356,7 +360,7 @@ struct fstab *fs_mgr_read_fstab_file(FILE *fstab_file)
fstab->recs[cnt].swap_prio = flag_vals.swap_prio;
fstab->recs[cnt].max_comp_streams = flag_vals.max_comp_streams;
fstab->recs[cnt].zram_size = flag_vals.zram_size;
fstab->recs[cnt].reserved_size = flag_vals.reserved_size;
fstab->recs[cnt].file_encryption_mode = flag_vals.file_encryption_mode;
cnt++;
}
/* If an A/B partition, modify block device to be the real block device */
@ -515,6 +519,17 @@ int fs_mgr_is_file_encrypted(const struct fstab_rec *fstab)
return fstab->fs_mgr_flags & MF_FILEENCRYPTION;
}
const char* fs_mgr_get_file_encryption_mode(const struct fstab_rec *fstab)
{
const struct flag_list *j;
for (j = encryption_modes; j->name; ++j) {
if (fstab->file_encryption_mode == j->flag) {
return j->name;
}
}
return NULL;
}
int fs_mgr_is_convertible_to_fbe(const struct fstab_rec *fstab)
{
return fstab->fs_mgr_flags & MF_FORCEFDEORFBE;

View file

@ -14,17 +14,12 @@
* limitations under the License.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libgen.h>
#include "fs_mgr_priv.h"
#ifdef _LIBGEN_H
#warning "libgen.h must not be included"
#endif
char *me = "";
static void usage(void)
@ -37,10 +32,10 @@ static void usage(void)
* and exit the program, do not return to the caller.
* Return the number of argv[] entries consumed.
*/
static void parse_options(int argc, char * const argv[], int *a_flag, int *u_flag, int *n_flag,
const char **n_name, const char **n_blk_dev)
static void parse_options(int argc, char *argv[], int *a_flag, int *u_flag, int *n_flag,
char **n_name, char **n_blk_dev)
{
me = basename(argv[0]);
me = basename(strdup(argv[0]));
if (argc <= 1) {
usage();
@ -80,14 +75,14 @@ static void parse_options(int argc, char * const argv[], int *a_flag, int *u_fla
return;
}
int main(int argc, char * const argv[])
int main(int argc, char *argv[])
{
int a_flag=0;
int u_flag=0;
int n_flag=0;
const char *n_name=NULL;
const char *n_blk_dev=NULL;
const char *fstab_file=NULL;
char *n_name=NULL;
char *n_blk_dev=NULL;
char *fstab_file=NULL;
struct fstab *fstab=NULL;
klog_set_level(6);
@ -102,7 +97,7 @@ int main(int argc, char * const argv[])
if (a_flag) {
return fs_mgr_mount_all(fstab, MOUNT_MODE_DEFAULT);
} else if (n_flag) {
return fs_mgr_do_mount(fstab, n_name, (char *)n_blk_dev, 0);
return fs_mgr_do_mount(fstab, n_name, n_blk_dev, 0);
} else if (u_flag) {
return fs_mgr_unmount_all(fstab);
} else {

View file

@ -86,7 +86,6 @@ __BEGIN_DECLS
#define MF_LATEMOUNT 0x20000
#define MF_NOFAIL 0x40000
#define MF_MAX_COMP_STREAMS 0x100000
#define MF_RESERVEDSIZE 0x200000
#define DM_BUF_SIZE 4096

View file

@ -181,7 +181,7 @@ static int invalidate_table(char *table, size_t table_length)
return -1;
}
static void verity_ioctl_init(struct dm_ioctl *io, char *name, unsigned flags)
static void verity_ioctl_init(struct dm_ioctl *io, const char *name, unsigned flags)
{
memset(io, 0, DM_BUF_SIZE);
io->data_size = DM_BUF_SIZE;
@ -784,8 +784,9 @@ out:
int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback)
{
alignas(dm_ioctl) char buffer[DM_BUF_SIZE];
bool system_root = false;
char fstab_filename[PROPERTY_VALUE_MAX + sizeof(FSTAB_PREFIX)];
char *mount_point;
const char *mount_point;
char propbuf[PROPERTY_VALUE_MAX];
char *status;
int fd = -1;
@ -813,6 +814,9 @@ int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback)
property_get("ro.hardware", propbuf, "");
snprintf(fstab_filename, sizeof(fstab_filename), FSTAB_PREFIX"%s", propbuf);
property_get("ro.build.system_root_image", propbuf, "");
system_root = !strcmp(propbuf, "true");
fstab = fs_mgr_read_fstab(fstab_filename);
if (!fstab) {
@ -825,7 +829,12 @@ int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback)
continue;
}
mount_point = basename(fstab->recs[i].mount_point);
if (system_root && !strcmp(fstab->recs[i].mount_point, "/")) {
mount_point = "system";
} else {
mount_point = basename(fstab->recs[i].mount_point);
}
verity_ioctl_init(io, mount_point, 0);
if (ioctl(fd, DM_TABLE_STATUS, io)) {
@ -836,7 +845,9 @@ int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback)
status = &buffer[io->data_start + sizeof(struct dm_target_spec)];
callback(&fstab->recs[i], mount_point, mode, *status);
if (*status == 'C' || *status == 'V') {
callback(&fstab->recs[i], mount_point, mode, *status);
}
}
rc = 0;

View file

@ -75,7 +75,7 @@ struct fstab_rec {
int swap_prio;
int max_comp_streams;
unsigned int zram_size;
uint64_t reserved_size;
unsigned int file_encryption_mode;
};
// Callback function for verity status
@ -97,7 +97,8 @@ int fs_mgr_mount_all(struct fstab *fstab, int mount_mode);
#define FS_MGR_DOMNT_FAILED (-1)
#define FS_MGR_DOMNT_BUSY (-2)
int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device,
int fs_mgr_do_mount(struct fstab *fstab, char *n_name, char *n_blk_device,
char *tmp_mount_point);
int fs_mgr_do_tmpfs_mount(char *n_name);
int fs_mgr_unmount_all(struct fstab *fstab);
@ -114,6 +115,7 @@ int fs_mgr_is_nonremovable(const struct fstab_rec *fstab);
int fs_mgr_is_verified(const struct fstab_rec *fstab);
int fs_mgr_is_encryptable(const struct fstab_rec *fstab);
int fs_mgr_is_file_encrypted(const struct fstab_rec *fstab);
const char* fs_mgr_get_file_encryption_mode(const struct fstab_rec *fstab);
int fs_mgr_is_convertible_to_fbe(const struct fstab_rec *fstab);
int fs_mgr_is_noemulatedsd(const struct fstab_rec *fstab);
int fs_mgr_is_notrim(struct fstab_rec *fstab);

View file

@ -20,6 +20,36 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
LOCAL_STATIC_LIBRARIES := libutils libbase libbinder
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
healthd_mode_android.cpp \
healthd_mode_charger.cpp \
AnimationParser.cpp \
BatteryPropertiesRegistrar.cpp \
LOCAL_MODULE := libhealthd_internal
LOCAL_C_INCLUDES := bootable/recovery
LOCAL_EXPORT_C_INCLUDE_DIRS := \
$(LOCAL_PATH) \
$(LOCAL_PATH)/include \
LOCAL_STATIC_LIBRARIES := \
libbatterymonitor \
libbatteryservice \
libbinder \
libminui \
libpng \
libz \
libutils \
libbase \
libcutils \
liblog \
libm \
libc \
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
ifeq ($(strip $(BOARD_CHARGER_NO_UI)),true)
@ -32,7 +62,7 @@ endif
LOCAL_SRC_FILES := \
healthd.cpp \
healthd_mode_android.cpp \
BatteryPropertiesRegistrar.cpp
BatteryPropertiesRegistrar.cpp \
ifneq ($(strip $(LOCAL_CHARGER_NO_UI)),true)
LOCAL_SRC_FILES += healthd_mode_charger.cpp
@ -60,13 +90,28 @@ endif
LOCAL_C_INCLUDES := bootable/recovery $(LOCAL_PATH)/include
LOCAL_STATIC_LIBRARIES := libbatterymonitor libbatteryservice libbinder libbase
LOCAL_STATIC_LIBRARIES := \
libhealthd_internal \
libbatterymonitor \
libbatteryservice \
libbinder \
libbase \
ifneq ($(strip $(LOCAL_CHARGER_NO_UI)),true)
LOCAL_STATIC_LIBRARIES += libminui libpng libz
LOCAL_STATIC_LIBRARIES += \
libminui \
libpng \
libz \
endif
LOCAL_STATIC_LIBRARIES += libutils libcutils liblog libm libc
LOCAL_STATIC_LIBRARIES += \
libutils \
libcutils \
liblog \
libm \
libc \
ifeq ($(strip $(BOARD_CHARGER_ENABLE_SUSPEND)),true)
LOCAL_STATIC_LIBRARIES += libsuspend
@ -84,7 +129,7 @@ include $(BUILD_EXECUTABLE)
ifneq ($(strip $(LOCAL_CHARGER_NO_UI)),true)
define _add-charger-image
include $$(CLEAR_VARS)
LOCAL_MODULE := system_core_charger_$(notdir $(1))
LOCAL_MODULE := system_core_charger_res_images_$(notdir $(1))
LOCAL_MODULE_STEM := $(notdir $(1))
_img_modules += $$(LOCAL_MODULE)
LOCAL_SRC_FILES := $1

141
healthd/AnimationParser.cpp Normal file
View file

@ -0,0 +1,141 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* 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.
*/
#include "AnimationParser.h"
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <cutils/klog.h>
#include "animation.h"
#define LOGE(x...) do { KLOG_ERROR("charger", x); } while (0)
#define LOGW(x...) do { KLOG_WARNING("charger", x); } while (0)
#define LOGV(x...) do { KLOG_DEBUG("charger", x); } while (0)
namespace android {
// Lines consisting of only whitespace or whitespace followed by '#' can be ignored.
bool can_ignore_line(const char* str) {
for (int i = 0; str[i] != '\0' && str[i] != '#'; i++) {
if (!isspace(str[i])) return false;
}
return true;
}
bool remove_prefix(const std::string& line, const char* prefix, const char** rest) {
const char* str = line.c_str();
int start;
char c;
std::string format = base::StringPrintf(" %s%%n%%c", prefix);
if (sscanf(str, format.c_str(), &start, &c) != 1) {
return false;
}
*rest = &str[start];
return true;
}
bool parse_text_field(const char* in, animation::text_field* field) {
int* x = &field->pos_x;
int* y = &field->pos_y;
int* r = &field->color_r;
int* g = &field->color_g;
int* b = &field->color_b;
int* a = &field->color_a;
int start = 0, end = 0;
if (sscanf(in, "c c %d %d %d %d %n%*s%n", r, g, b, a, &start, &end) == 4) {
*x = CENTER_VAL;
*y = CENTER_VAL;
} else if (sscanf(in, "c %d %d %d %d %d %n%*s%n", y, r, g, b, a, &start, &end) == 5) {
*x = CENTER_VAL;
} else if (sscanf(in, "%d c %d %d %d %d %n%*s%n", x, r, g, b, a, &start, &end) == 5) {
*y = CENTER_VAL;
} else if (sscanf(in, "%d %d %d %d %d %d %n%*s%n", x, y, r, g, b, a, &start, &end) != 6) {
return false;
}
if (end == 0) return false;
field->font_file.assign(&in[start], end - start);
return true;
}
bool parse_animation_desc(const std::string& content, animation* anim) {
static constexpr const char* animation_prefix = "animation: ";
static constexpr const char* fail_prefix = "fail: ";
static constexpr const char* clock_prefix = "clock_display: ";
static constexpr const char* percent_prefix = "percent_display: ";
static constexpr const char* frame_prefix = "frame: ";
std::vector<animation::frame> frames;
for (const auto& line : base::Split(content, "\n")) {
animation::frame frame;
const char* rest;
if (can_ignore_line(line.c_str())) {
continue;
} else if (remove_prefix(line, animation_prefix, &rest)) {
int start = 0, end = 0;
if (sscanf(rest, "%d %d %n%*s%n", &anim->num_cycles, &anim->first_frame_repeats,
&start, &end) != 2 ||
end == 0) {
LOGE("Bad animation format: %s\n", line.c_str());
return false;
} else {
anim->animation_file.assign(&rest[start], end - start);
}
} else if (remove_prefix(line, fail_prefix, &rest)) {
anim->fail_file.assign(rest);
} else if (remove_prefix(line, clock_prefix, &rest)) {
if (!parse_text_field(rest, &anim->text_clock)) {
LOGE("Bad clock_display format: %s\n", line.c_str());
return false;
}
} else if (remove_prefix(line, percent_prefix, &rest)) {
if (!parse_text_field(rest, &anim->text_percent)) {
LOGE("Bad percent_display format: %s\n", line.c_str());
return false;
}
} else if (sscanf(line.c_str(), " frame: %d %d %d",
&frame.disp_time, &frame.min_level, &frame.max_level) == 3) {
frames.push_back(std::move(frame));
} else {
LOGE("Malformed animation description line: %s\n", line.c_str());
return false;
}
}
if (anim->animation_file.empty() || frames.empty()) {
LOGE("Bad animation description. Provide the 'animation: ' line and at least one 'frame: ' "
"line.\n");
return false;
}
anim->num_frames = frames.size();
anim->frames = new animation::frame[frames.size()];
std::copy(frames.begin(), frames.end(), anim->frames);
return true;
}
} // namespace android

31
healthd/AnimationParser.h Normal file
View file

@ -0,0 +1,31 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* 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.
*/
#ifndef HEALTHD_ANIMATION_PARSER_H
#define HEALTHD_ANIMATION_PARSER_H
#include "animation.h"
namespace android {
bool parse_animation_desc(const std::string& content, animation* anim);
bool can_ignore_line(const char* str);
bool remove_prefix(const std::string& str, const char* prefix, const char** rest);
bool parse_text_field(const char* in, animation::text_field* field);
} // namespace android
#endif // HEALTHD_ANIMATION_PARSER_H

73
healthd/animation.h Normal file
View file

@ -0,0 +1,73 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* 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.
*/
#ifndef HEALTHD_ANIMATION_H
#define HEALTHD_ANIMATION_H
#include <inttypes.h>
#include <string>
struct GRSurface;
struct GRFont;
namespace android {
#define CENTER_VAL INT_MAX
struct animation {
struct frame {
int disp_time;
int min_level;
int max_level;
GRSurface* surface;
};
struct text_field {
std::string font_file;
int pos_x;
int pos_y;
int color_r;
int color_g;
int color_b;
int color_a;
GRFont* font;
};
std::string animation_file;
std::string fail_file;
text_field text_clock;
text_field text_percent;
bool run;
frame* frames;
int cur_frame;
int num_frames;
int first_frame_repeats; // Number of times to repeat the first frame in the current cycle
int cur_cycle;
int num_cycles; // Number of cycles to complete before blanking the screen
int cur_level; // current battery level being animated (0-100)
int cur_status; // current battery status - see BatteryService.h for BATTERY_STATUS_*
};
}
#endif // HEALTHD_ANIMATION_H

View file

@ -30,6 +30,9 @@
#include <time.h>
#include <unistd.h>
#include <android-base/file.h>
#include <android-base/stringprintf.h>
#include <sys/socket.h>
#include <linux/netlink.h>
@ -44,10 +47,14 @@
#include <suspend/autosuspend.h>
#endif
#include "animation.h"
#include "AnimationParser.h"
#include "minui/minui.h"
#include <healthd/healthd.h>
using namespace android;
char *locale;
#ifndef max
@ -67,8 +74,6 @@ char *locale;
#define POWER_ON_KEY_TIME (2 * MSEC_PER_SEC)
#define UNPLUGGED_SHUTDOWN_TIME (10 * MSEC_PER_SEC)
#define BATTERY_FULL_THRESH 95
#define LAST_KMSG_PATH "/proc/last_kmsg"
#define LAST_KMSG_PSTORE_PATH "/sys/fs/pstore/console-ramoops"
#define LAST_KMSG_MAX_SZ (32 * 1024)
@ -77,34 +82,14 @@ char *locale;
#define LOGW(x...) do { KLOG_WARNING("charger", x); } while (0)
#define LOGV(x...) do { KLOG_DEBUG("charger", x); } while (0)
static constexpr const char* animation_desc_path = "/res/values/charger/animation.txt";
struct key_state {
bool pending;
bool down;
int64_t timestamp;
};
struct frame {
int disp_time;
int min_capacity;
bool level_only;
GRSurface* surface;
};
struct animation {
bool run;
struct frame *frames;
int cur_frame;
int num_frames;
int cur_cycle;
int num_cycles;
/* current capacity being animated */
int capacity;
};
struct charger {
bool have_battery_state;
bool charger_connected;
@ -119,54 +104,83 @@ struct charger {
int boot_min_cap;
};
static struct frame batt_anim_frames[] = {
static const struct 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,
},
.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,
};
static struct animation::frame default_animation_frames[] = {
{
.disp_time = 750,
.min_capacity = 0,
.level_only = false,
.min_level = 0,
.max_level = 19,
.surface = NULL,
},
{
.disp_time = 750,
.min_capacity = 20,
.level_only = false,
.min_level = 0,
.max_level = 39,
.surface = NULL,
},
{
.disp_time = 750,
.min_capacity = 40,
.level_only = false,
.min_level = 0,
.max_level = 59,
.surface = NULL,
},
{
.disp_time = 750,
.min_capacity = 60,
.level_only = false,
.min_level = 0,
.max_level = 79,
.surface = NULL,
},
{
.disp_time = 750,
.min_capacity = 80,
.level_only = true,
.min_level = 80,
.max_level = 95,
.surface = NULL,
},
{
.disp_time = 750,
.min_capacity = BATTERY_FULL_THRESH,
.level_only = false,
.min_level = 0,
.max_level = 100,
.surface = NULL,
},
};
static struct animation battery_animation = {
.run = false,
.frames = batt_anim_frames,
.cur_frame = 0,
.num_frames = ARRAY_SIZE(batt_anim_frames),
.cur_cycle = 0,
.num_cycles = 3,
.capacity = 0,
};
static struct animation battery_animation = BASE_ANIMATION;
static struct charger charger_state;
static struct healthd_config *healthd_config;
@ -273,8 +287,79 @@ static void android_green(void)
gr_color(0xa4, 0xc6, 0x39, 255);
}
// Negative x or y coordinates position the text away from the opposite edge that positive ones do.
void determine_xy(const animation::text_field& field, const int length, int* x, int* y)
{
*x = field.pos_x;
*y = field.pos_y;
int str_len_px = length * field.font->char_width;
if (field.pos_x == CENTER_VAL) {
*x = (gr_fb_width() - str_len_px) / 2;
} else if (field.pos_x >= 0) {
*x = field.pos_x;
} else { // position from max edge
*x = gr_fb_width() + field.pos_x - str_len_px;
}
if (field.pos_y == CENTER_VAL) {
*y = (gr_fb_height() - field.font->char_height) / 2;
} else if (field.pos_y >= 0) {
*y = field.pos_y;
} else { // position from max edge
*y = gr_fb_height() + field.pos_y - field.font->char_height;
}
}
static void draw_clock(const animation& anim)
{
static constexpr char CLOCK_FORMAT[] = "%H:%M";
static constexpr int CLOCK_LENGTH = 6;
const animation::text_field& field = anim.text_clock;
if (field.font == nullptr || field.font->char_width == 0 || field.font->char_height == 0) return;
time_t rawtime;
time(&rawtime);
struct tm* time_info = localtime(&rawtime);
char clock_str[CLOCK_LENGTH];
size_t length = strftime(clock_str, CLOCK_LENGTH, CLOCK_FORMAT, time_info);
if (length != CLOCK_LENGTH - 1) {
LOGE("Could not format time\n");
return;
}
int x, y;
determine_xy(field, length, &x, &y);
LOGV("drawing clock %s %d %d\n", clock_str, x, y);
gr_color(field.color_r, field.color_g, field.color_b, field.color_a);
gr_text(field.font, x, y, clock_str, false);
}
static void draw_percent(const animation& anim)
{
if (anim.cur_level <= 0 || anim.cur_status != BATTERY_STATUS_CHARGING) return;
const animation::text_field& field = anim.text_percent;
if (field.font == nullptr || field.font->char_width == 0 || field.font->char_height == 0) {
return;
}
std::string str = base::StringPrintf("%d%%", anim.cur_level);
int x, y;
determine_xy(field, str.size(), &x, &y);
LOGV("drawing percent %s %d %d\n", str.c_str(), x, y);
gr_color(field.color_r, field.color_g, field.color_b, field.color_a);
gr_text(field.font, x, y, str.c_str(), false);
}
/* returns the last y-offset of where the surface ends */
static int draw_surface_centered(struct charger* /*charger*/, GRSurface* surface)
static int draw_surface_centered(GRSurface* surface)
{
int w;
int h;
@ -295,7 +380,7 @@ static void draw_unknown(struct charger *charger)
{
int y;
if (charger->surf_unknown) {
draw_surface_centered(charger, charger->surf_unknown);
draw_surface_centered(charger->surf_unknown);
} else {
android_green();
y = draw_text("Charging!", -1, -1);
@ -303,17 +388,19 @@ static void draw_unknown(struct charger *charger)
}
}
static void draw_battery(struct charger *charger)
static void draw_battery(const struct charger* charger)
{
struct animation *batt_anim = charger->batt_anim;
struct frame *frame = &batt_anim->frames[batt_anim->cur_frame];
const struct animation& anim = *charger->batt_anim;
const struct animation::frame& frame = anim.frames[anim.cur_frame];
if (batt_anim->num_frames != 0) {
draw_surface_centered(charger, frame->surface);
if (anim.num_frames != 0) {
draw_surface_centered(frame.surface);
LOGV("drawing frame #%d min_cap=%d time=%d\n",
batt_anim->cur_frame, frame->min_capacity,
frame->disp_time);
anim.cur_frame, frame.min_level,
frame.disp_time);
}
draw_clock(anim);
draw_percent(anim);
}
static void redraw_screen(struct charger *charger)
@ -323,7 +410,7 @@ static void redraw_screen(struct charger *charger)
clear_screen();
/* try to display *something* */
if (batt_anim->capacity < 0 || batt_anim->num_frames == 0)
if (batt_anim->cur_level < 0 || batt_anim->num_frames == 0)
draw_unknown(charger);
else
draw_battery(charger);
@ -342,16 +429,33 @@ static void reset_animation(struct animation *anim)
anim->run = false;
}
static void init_status_display(struct animation* anim)
{
int res;
if (!anim->text_clock.font_file.empty()) {
if ((res =
gr_init_font(anim->text_clock.font_file.c_str(), &anim->text_clock.font)) < 0) {
LOGE("Could not load time font (%d)\n", res);
}
}
if (!anim->text_percent.font_file.empty()) {
if ((res =
gr_init_font(anim->text_percent.font_file.c_str(), &anim->text_percent.font)) < 0) {
LOGE("Could not load percent font (%d)\n", res);
}
}
}
static void update_screen_state(struct charger *charger, int64_t now)
{
struct animation *batt_anim = charger->batt_anim;
int disp_time;
if (!batt_anim->run || now < charger->next_screen_transition)
return;
if (!batt_anim->run || now < charger->next_screen_transition) return;
if (!minui_inited) {
if (healthd_config && healthd_config->screen_on) {
if (!healthd_config->screen_on(batt_prop)) {
LOGV("[%" PRId64 "] leave screen off\n", now);
@ -365,6 +469,7 @@ static void update_screen_state(struct charger *charger, int64_t now)
gr_init();
gr_font_size(gr_sys_font(), &char_width, &char_height);
init_status_display(batt_anim);
#ifndef CHARGER_DISABLE_INIT_BLANK
gr_fb_blank(true);
@ -373,7 +478,7 @@ static void update_screen_state(struct charger *charger, int64_t now)
}
/* animation is over, blank screen and leave */
if (batt_anim->cur_cycle == batt_anim->num_cycles) {
if (batt_anim->num_cycles > 0 && batt_anim->cur_cycle == batt_anim->num_cycles) {
reset_animation(batt_anim);
charger->next_screen_transition = -1;
gr_fb_blank(true);
@ -389,21 +494,24 @@ static void update_screen_state(struct charger *charger, int64_t now)
if (batt_anim->cur_frame == 0) {
LOGV("[%" PRId64 "] animation starting\n", now);
if (batt_prop && batt_prop->batteryLevel >= 0 && batt_anim->num_frames != 0) {
int i;
if (batt_prop) {
batt_anim->cur_level = batt_prop->batteryLevel;
batt_anim->cur_status = batt_prop->batteryStatus;
if (batt_prop->batteryLevel >= 0 && batt_anim->num_frames != 0) {
/* 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;
}
}
/* find first frame given current capacity */
for (i = 1; i < batt_anim->num_frames; i++) {
if (batt_prop->batteryLevel < batt_anim->frames[i].min_capacity)
break;
// repeat the first frame first_frame_repeats times
disp_time = batt_anim->frames[batt_anim->cur_frame].disp_time *
batt_anim->first_frame_repeats;
}
batt_anim->cur_frame = i - 1;
/* show the first frame for twice as long */
disp_time = batt_anim->frames[batt_anim->cur_frame].disp_time * 2;
}
if (batt_prop)
batt_anim->capacity = batt_prop->batteryLevel;
}
/* unblank the screen on first cycle */
@ -416,8 +524,8 @@ static void update_screen_state(struct charger *charger, int64_t now)
/* if we don't have anim frames, we only have one image, so just bump
* the cycle counter and exit
*/
if (batt_anim->num_frames == 0 || batt_anim->capacity < 0) {
LOGV("[%" PRId64 "] animation missing or unknown battery status\n", now);
if (batt_anim->num_frames == 0 || batt_anim->cur_level < 0) {
LOGW("[%" PRId64 "] animation missing or unknown battery status\n", now);
charger->next_screen_transition = now + BATTERY_UNKNOWN_TIME;
batt_anim->cur_cycle++;
return;
@ -432,12 +540,11 @@ static void update_screen_state(struct charger *charger, int64_t now)
if (charger->charger_connected) {
batt_anim->cur_frame++;
/* if the frame is used for level-only, that is only show it when it's
* the current level, skip it during the animation.
*/
while (batt_anim->cur_frame < batt_anim->num_frames &&
batt_anim->frames[batt_anim->cur_frame].level_only)
(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++;
}
if (batt_anim->cur_frame >= batt_anim->num_frames) {
batt_anim->cur_cycle++;
batt_anim->cur_frame = 0;
@ -521,7 +628,7 @@ static void process_key(struct charger *charger, int code, int64_t now)
LOGW("[%" PRId64 "] booting from charger mode\n", now);
property_set("sys.boot_from_charger_mode", "1");
} else {
if (charger->batt_anim->capacity >= charger->boot_min_cap) {
if (charger->batt_anim->cur_level >= charger->boot_min_cap) {
LOGW("[%" PRId64 "] rebooting\n", now);
android_reboot(ANDROID_RB_RESTART, 0, 0);
} else {
@ -672,6 +779,52 @@ static void charger_event_handler(uint32_t /*epevents*/)
ev_dispatch();
}
animation* init_animation()
{
bool parse_success;
std::string content;
if (base::ReadFileToString(animation_desc_path, &content)) {
parse_success = parse_animation_desc(content, &battery_animation);
} else {
LOGW("Could not open animation description at %s\n", animation_desc_path);
parse_success = false;
}
if (!parse_success) {
LOGW("Could not parse animation description. Using default animation.\n");
battery_animation = BASE_ANIMATION;
battery_animation.animation_file.assign("charger/battery_scale");
battery_animation.frames = default_animation_frames;
battery_animation.num_frames = ARRAY_SIZE(default_animation_frames);
}
if (battery_animation.fail_file.empty()) {
battery_animation.fail_file.assign("charger/battery_fail");
}
LOGV("Animation Description:\n");
LOGV(" animation: %d %d '%s' (%d)\n",
battery_animation.num_cycles, battery_animation.first_frame_repeats,
battery_animation.animation_file.c_str(), battery_animation.num_frames);
LOGV(" fail_file: '%s'\n", battery_animation.fail_file.c_str());
LOGV(" clock: %d %d %d %d %d %d '%s'\n",
battery_animation.text_clock.pos_x, battery_animation.text_clock.pos_y,
battery_animation.text_clock.color_r, battery_animation.text_clock.color_g,
battery_animation.text_clock.color_b, battery_animation.text_clock.color_a,
battery_animation.text_clock.font_file.c_str());
LOGV(" percent: %d %d %d %d %d %d '%s'\n",
battery_animation.text_percent.pos_x, battery_animation.text_percent.pos_y,
battery_animation.text_percent.color_r, battery_animation.text_percent.color_g,
battery_animation.text_percent.color_b, battery_animation.text_percent.color_a,
battery_animation.text_percent.font_file.c_str());
for (int i = 0; i < battery_animation.num_frames; i++) {
LOGV(" frame %.2d: %d %d %d\n", i, battery_animation.frames[i].disp_time,
battery_animation.frames[i].min_level, battery_animation.frames[i].max_level);
}
return &battery_animation;
}
void healthd_mode_charger_init(struct healthd_config* config)
{
int ret;
@ -689,35 +842,39 @@ void healthd_mode_charger_init(struct healthd_config* config)
healthd_register_event(epollfd, charger_event_handler);
}
ret = res_create_display_surface("charger/battery_fail", &charger->surf_unknown);
if (ret < 0) {
LOGE("Cannot load battery_fail image\n");
charger->surf_unknown = NULL;
}
struct animation* anim = init_animation();
charger->batt_anim = anim;
charger->batt_anim = &battery_animation;
ret = res_create_display_surface(anim->fail_file.c_str(), &charger->surf_unknown);
if (ret < 0) {
LOGE("Cannot load custom battery_fail image. Reverting to built in.\n");
ret = res_create_display_surface("charger/battery_fail", &charger->surf_unknown);
if (ret < 0) {
LOGE("Cannot load built in battery_fail image\n");
charger->surf_unknown = NULL;
}
}
GRSurface** scale_frames;
int scale_count;
int scale_fps; // Not in use (charger/battery_scale doesn't have FPS text
// chunk). We are using hard-coded frame.disp_time instead.
ret = res_create_multi_display_surface("charger/battery_scale", &scale_count, &scale_fps,
&scale_frames);
ret = res_create_multi_display_surface(anim->animation_file.c_str(),
&scale_count, &scale_fps, &scale_frames);
if (ret < 0) {
LOGE("Cannot load battery_scale image\n");
charger->batt_anim->num_frames = 0;
charger->batt_anim->num_cycles = 1;
} else if (scale_count != charger->batt_anim->num_frames) {
anim->num_frames = 0;
anim->num_cycles = 1;
} else if (scale_count != anim->num_frames) {
LOGE("battery_scale image has unexpected frame count (%d, expected %d)\n",
scale_count, charger->batt_anim->num_frames);
charger->batt_anim->num_frames = 0;
charger->batt_anim->num_cycles = 1;
scale_count, anim->num_frames);
anim->num_frames = 0;
anim->num_cycles = 1;
} else {
for (i = 0; i < charger->batt_anim->num_frames; i++) {
charger->batt_anim->frames[i].surface = scale_frames[i];
for (i = 0; i < anim->num_frames; i++) {
anim->frames[i].surface = scale_frames[i];
}
}
ev_sync_key_state(set_key_callback, charger);
charger->next_screen_transition = -1;

21
healthd/tests/Android.mk Normal file
View file

@ -0,0 +1,21 @@
# Copyright 2016 The Android Open Source Project
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
AnimationParser_test.cpp \
LOCAL_MODULE := healthd_test
LOCAL_MODULE_TAGS := tests
LOCAL_STATIC_LIBRARIES := \
libhealthd_internal \
LOCAL_SHARED_LIBRARIES := \
liblog \
libbase \
libcutils \
include $(BUILD_NATIVE_TEST)

View file

@ -0,0 +1,192 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* 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.
*/
#include "AnimationParser.h"
#include <gtest/gtest.h>
using namespace android;
TEST(AnimationParserTest, Test_can_ignore_line) {
EXPECT_TRUE(can_ignore_line(""));
EXPECT_TRUE(can_ignore_line(" "));
EXPECT_TRUE(can_ignore_line("#"));
EXPECT_TRUE(can_ignore_line(" # comment"));
EXPECT_FALSE(can_ignore_line("text"));
EXPECT_FALSE(can_ignore_line("text # comment"));
EXPECT_FALSE(can_ignore_line(" text"));
EXPECT_FALSE(can_ignore_line(" text # comment"));
}
TEST(AnimationParserTest, Test_remove_prefix) {
static const char TEST_STRING[] = "abcdef";
const char* rest = nullptr;
EXPECT_FALSE(remove_prefix(TEST_STRING, "def", &rest));
// Ignore strings that only consist of the prefix
EXPECT_FALSE(remove_prefix(TEST_STRING, TEST_STRING, &rest));
EXPECT_TRUE(remove_prefix(TEST_STRING, "abc", &rest));
EXPECT_STREQ("def", rest);
EXPECT_TRUE(remove_prefix(" abcdef", "abc", &rest));
EXPECT_STREQ("def", rest);
}
TEST(AnimationParserTest, Test_parse_text_field) {
static const char TEST_FILE_NAME[] = "font_file";
static const int TEST_X = 3;
static const int TEST_Y = 6;
static const int TEST_R = 1;
static const int TEST_G = 2;
static const int TEST_B = 4;
static const int TEST_A = 8;
static const char TEST_XCENT_YCENT[] = "c c 1 2 4 8 font_file ";
static const char TEST_XCENT_YVAL[] = "c 6 1 2 4 8 font_file ";
static const char TEST_XVAL_YCENT[] = "3 c 1 2 4 8 font_file ";
static const char TEST_XVAL_YVAL[] = "3 6 1 2 4 8 font_file ";
static const char TEST_BAD_MISSING[] = "c c 1 2 4 font_file";
static const char TEST_BAD_NO_FILE[] = "c c 1 2 4 8";
animation::text_field out;
EXPECT_TRUE(parse_text_field(TEST_XCENT_YCENT, &out));
EXPECT_EQ(CENTER_VAL, out.pos_x);
EXPECT_EQ(CENTER_VAL, out.pos_y);
EXPECT_EQ(TEST_R, out.color_r);
EXPECT_EQ(TEST_G, out.color_g);
EXPECT_EQ(TEST_B, out.color_b);
EXPECT_EQ(TEST_A, out.color_a);
EXPECT_STREQ(TEST_FILE_NAME, out.font_file.c_str());
EXPECT_TRUE(parse_text_field(TEST_XCENT_YVAL, &out));
EXPECT_EQ(CENTER_VAL, out.pos_x);
EXPECT_EQ(TEST_Y, out.pos_y);
EXPECT_EQ(TEST_R, out.color_r);
EXPECT_EQ(TEST_G, out.color_g);
EXPECT_EQ(TEST_B, out.color_b);
EXPECT_EQ(TEST_A, out.color_a);
EXPECT_STREQ(TEST_FILE_NAME, out.font_file.c_str());
EXPECT_TRUE(parse_text_field(TEST_XVAL_YCENT, &out));
EXPECT_EQ(TEST_X, out.pos_x);
EXPECT_EQ(CENTER_VAL, out.pos_y);
EXPECT_EQ(TEST_R, out.color_r);
EXPECT_EQ(TEST_G, out.color_g);
EXPECT_EQ(TEST_B, out.color_b);
EXPECT_EQ(TEST_A, out.color_a);
EXPECT_STREQ(TEST_FILE_NAME, out.font_file.c_str());
EXPECT_TRUE(parse_text_field(TEST_XVAL_YVAL, &out));
EXPECT_EQ(TEST_X, out.pos_x);
EXPECT_EQ(TEST_Y, out.pos_y);
EXPECT_EQ(TEST_R, out.color_r);
EXPECT_EQ(TEST_G, out.color_g);
EXPECT_EQ(TEST_B, out.color_b);
EXPECT_EQ(TEST_A, out.color_a);
EXPECT_STREQ(TEST_FILE_NAME, out.font_file.c_str());
EXPECT_FALSE(parse_text_field(TEST_BAD_MISSING, &out));
EXPECT_FALSE(parse_text_field(TEST_BAD_NO_FILE, &out));
}
TEST(AnimationParserTest, Test_parse_animation_desc_basic) {
static const char TEST_ANIMATION[] = R"desc(
# Basic animation
animation: 5 1 test/animation_file
frame: 1000 0 100
)desc";
animation anim;
EXPECT_TRUE(parse_animation_desc(TEST_ANIMATION, &anim));
}
TEST(AnimationParserTest, Test_parse_animation_desc_bad_no_animation_line) {
static const char TEST_ANIMATION[] = R"desc(
# Bad animation
frame: 1000 90 10
)desc";
animation anim;
EXPECT_FALSE(parse_animation_desc(TEST_ANIMATION, &anim));
}
TEST(AnimationParserTest, Test_parse_animation_desc_bad_no_frame) {
static const char TEST_ANIMATION[] = R"desc(
# Bad animation
animation: 5 1 test/animation_file
)desc";
animation anim;
EXPECT_FALSE(parse_animation_desc(TEST_ANIMATION, &anim));
}
TEST(AnimationParserTest, Test_parse_animation_desc_bad_animation_line_format) {
static const char TEST_ANIMATION[] = R"desc(
# Bad animation
animation: 5 1
frame: 1000 90 10
)desc";
animation anim;
EXPECT_FALSE(parse_animation_desc(TEST_ANIMATION, &anim));
}
TEST(AnimationParserTest, Test_parse_animation_desc_full) {
static const char TEST_ANIMATION[] = R"desc(
# Full animation
animation: 5 1 test/animation_file
clock_display: 11 12 13 14 15 16 test/time_font
percent_display: 21 22 23 24 25 26 test/percent_font
frame: 10 20 30
frame: 40 50 60
)desc";
animation anim;
EXPECT_TRUE(parse_animation_desc(TEST_ANIMATION, &anim));
EXPECT_EQ(5, anim.num_cycles);
EXPECT_EQ(1, anim.first_frame_repeats);
EXPECT_STREQ("test/animation_file", anim.animation_file.c_str());
EXPECT_EQ(11, anim.text_clock.pos_x);
EXPECT_EQ(12, anim.text_clock.pos_y);
EXPECT_EQ(13, anim.text_clock.color_r);
EXPECT_EQ(14, anim.text_clock.color_g);
EXPECT_EQ(15, anim.text_clock.color_b);
EXPECT_EQ(16, anim.text_clock.color_a);
EXPECT_STREQ("test/time_font", anim.text_clock.font_file.c_str());
EXPECT_EQ(21, anim.text_percent.pos_x);
EXPECT_EQ(22, anim.text_percent.pos_y);
EXPECT_EQ(23, anim.text_percent.color_r);
EXPECT_EQ(24, anim.text_percent.color_g);
EXPECT_EQ(25, anim.text_percent.color_b);
EXPECT_EQ(26, anim.text_percent.color_a);
EXPECT_STREQ("test/percent_font", anim.text_percent.font_file.c_str());
EXPECT_EQ(2, anim.num_frames);
EXPECT_EQ(10, anim.frames[0].disp_time);
EXPECT_EQ(20, anim.frames[0].min_level);
EXPECT_EQ(30, anim.frames[0].max_level);
EXPECT_EQ(40, anim.frames[1].disp_time);
EXPECT_EQ(50, anim.frames[1].min_level);
EXPECT_EQ(60, anim.frames[1].max_level);
}

View file

@ -70,7 +70,8 @@ __BEGIN_DECLS
#define ATRACE_TAG_PACKAGE_MANAGER (1<<18)
#define ATRACE_TAG_SYSTEM_SERVER (1<<19)
#define ATRACE_TAG_DATABASE (1<<20)
#define ATRACE_TAG_LAST ATRACE_TAG_DATABASE
#define ATRACE_TAG_NETWORK (1<<21)
#define ATRACE_TAG_LAST ATRACE_TAG_NETWORK
// Reserved for initialization.
#define ATRACE_TAG_NOT_READY (1ULL<<63)

View file

@ -287,6 +287,16 @@ enum {
* age will be 0.
*/
NATIVE_WINDOW_BUFFER_AGE = 13,
/*
* Returns the duration of the last dequeueBuffer call in microseconds
*/
NATIVE_WINDOW_LAST_DEQUEUE_DURATION = 14,
/*
* Returns the duration of the last queueBuffer call in microseconds
*/
NATIVE_WINDOW_LAST_QUEUE_DURATION = 15,
};
/* Valid operations for the (*perform)() hook.
@ -323,6 +333,7 @@ enum {
NATIVE_WINDOW_SET_SURFACE_DAMAGE = 20, /* private */
NATIVE_WINDOW_SET_SHARED_BUFFER_MODE = 21,
NATIVE_WINDOW_SET_AUTO_REFRESH = 22,
NATIVE_WINDOW_GET_FRAME_TIMESTAMPS = 23,
};
/* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
@ -985,6 +996,18 @@ static inline int native_window_set_auto_refresh(
return window->perform(window, NATIVE_WINDOW_SET_AUTO_REFRESH, autoRefresh);
}
static inline int native_window_get_frame_timestamps(
struct ANativeWindow* window, uint32_t framesAgo,
int64_t* outPostedTime, int64_t* outAcquireTime,
int64_t* outRefreshStartTime, int64_t* outGlCompositionDoneTime,
int64_t* outDisplayRetireTime, int64_t* outReleaseTime)
{
return window->perform(window, NATIVE_WINDOW_GET_FRAME_TIMESTAMPS,
framesAgo, outPostedTime, outAcquireTime, outRefreshStartTime,
outGlCompositionDoneTime, outDisplayRetireTime, outReleaseTime);
}
__END_DECLS
#endif /* SYSTEM_CORE_INCLUDE_ANDROID_WINDOW_H */

View file

@ -32,6 +32,7 @@ private:
int mCommandCount;
bool mWithSeq;
FrameworkCommandCollection *mCommands;
bool mSkipToNextNullByte;
public:
FrameworkListener(const char *socketName);

View file

@ -64,13 +64,18 @@ public:
status_t tryLock();
#if defined(__ANDROID__)
// lock the mutex, but don't wait longer than timeoutMilliseconds.
// Lock the mutex, but don't wait longer than timeoutNs (relative time).
// Returns 0 on success, TIMED_OUT for failure due to timeout expiration.
//
// OSX doesn't have pthread_mutex_timedlock() or equivalent. To keep
// capabilities consistent across host OSes, this method is only available
// when building Android binaries.
status_t timedLock(nsecs_t timeoutMilliseconds);
//
// FIXME?: pthread_mutex_timedlock is based on CLOCK_REALTIME,
// which is subject to NTP adjustments, and includes time during suspend,
// so a timeout may occur even though no processes could run.
// Not holding a partial wakelock may lead to a system suspend.
status_t timedLock(nsecs_t timeoutNs);
#endif
// Manages the mutex automatically. It'll be locked when Autolock is
@ -134,6 +139,7 @@ inline status_t Mutex::tryLock() {
}
#if defined(__ANDROID__)
inline status_t Mutex::timedLock(nsecs_t timeoutNs) {
timeoutNs += systemTime(SYSTEM_TIME_REALTIME);
const struct timespec ts = {
/* .tv_sec = */ static_cast<time_t>(timeoutNs / 1000000000),
/* .tv_nsec = */ static_cast<long>(timeoutNs % 1000000000),

View file

@ -345,6 +345,11 @@ static int do_mkdir(const std::vector<std::string>& args) {
return 0;
}
/* umount <path> */
static int do_umount(const std::vector<std::string>& args) {
return umount(args[1].c_str());
}
static struct {
const char *name;
unsigned flag;
@ -1045,6 +1050,7 @@ BuiltinFunctionMap::Map& BuiltinFunctionMap::map() const {
{"mkdir", {1, 4, do_mkdir}},
{"mount_all", {1, kMax, do_mount_all}},
{"mount", {3, kMax, do_mount}},
{"umount", {1, 1, do_umount}},
{"powerctl", {1, 1, do_powerctl}},
{"restart", {1, 1, do_restart}},
{"restorecon", {1, kMax, do_restorecon}},

View file

@ -78,11 +78,13 @@ static void handle_keychord() {
if (adb_enabled == "running") {
Service* svc = ServiceManager::GetInstance().FindServiceByKeychord(id);
if (svc) {
LOG(INFO) << "Starting service " << svc->name() << " from keychord...";
LOG(INFO) << "Starting service " << svc->name() << " from keychord " << id;
svc->Start();
} else {
LOG(ERROR) << "service for keychord " << id << " not found";
LOG(ERROR) << "Service for keychord " << id << " not found";
}
} else {
LOG(WARNING) << "Not starting service for keychord " << id << " because ADB is disabled";
}
}

View file

@ -395,6 +395,9 @@ trigger <event>
Trigger an event. Used to queue an action from another
action.
umount <path>
Unmount the filesystem mounted at that path.
verity_load_state
Internal implementation detail used to load dm-verity state.

View file

@ -91,6 +91,7 @@ static const struct fs_path_config android_dirs[] = {
{ 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/Music" },
{ 00750, AID_ROOT, AID_SHELL, 0, "data/nativetest" },
{ 00750, AID_ROOT, AID_SHELL, 0, "data/nativetest64" },
{ 00775, AID_ROOT, AID_ROOT, 0, "data/preloads" },
{ 00771, AID_SYSTEM, AID_SYSTEM, 0, "data" },
{ 00755, AID_ROOT, AID_SYSTEM, 0, "mnt" },
{ 00755, AID_ROOT, AID_ROOT, 0, "root" },
@ -149,6 +150,9 @@ static const struct fs_path_config android_files[] = {
{ 00700, AID_SYSTEM, AID_SHELL, CAP_MASK_LONG(CAP_BLOCK_SUSPEND),
"system/bin/inputflinger" },
/* Support FIFO scheduling mode in SurfaceFlinger. */
{ 00755, AID_SYSTEM, AID_GRAPHICS, CAP_MASK_LONG(CAP_SYS_NICE), "system/bin/surfaceflinger" },
/* Support hostapd administering a network interface. */
{ 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) |
CAP_MASK_LONG(CAP_NET_RAW),

View file

@ -64,9 +64,12 @@ static int system_bg_cpuset_fd = -1;
static int bg_cpuset_fd = -1;
static int fg_cpuset_fd = -1;
static int ta_cpuset_fd = -1; // special cpuset for top app
#endif
// File descriptors open to /dev/stune/../tasks, setup by initialize, or -1 on error
static int bg_schedboost_fd = -1;
static int fg_schedboost_fd = -1;
#endif
static int ta_schedboost_fd = -1;
/* Add tid to the scheduling group defined by the policy */
static int add_tid_to_cgroup(int tid, int fd)
@ -136,9 +139,11 @@ static void __initialize(void) {
ta_cpuset_fd = open(filename, O_WRONLY | O_CLOEXEC);
#ifdef USE_SCHEDBOOST
filename = "/dev/stune/top-app/tasks";
ta_schedboost_fd = open(filename, O_WRONLY | O_CLOEXEC);
filename = "/dev/stune/foreground/tasks";
fg_schedboost_fd = open(filename, O_WRONLY | O_CLOEXEC);
filename = "/dev/stune/tasks";
filename = "/dev/stune/background/tasks";
bg_schedboost_fd = open(filename, O_WRONLY | O_CLOEXEC);
#endif
}
@ -300,11 +305,10 @@ int set_cpuset_policy(int tid, SchedPolicy policy)
break;
case SP_TOP_APP :
fd = ta_cpuset_fd;
boost_fd = fg_schedboost_fd;
boost_fd = ta_schedboost_fd;
break;
case SP_SYSTEM:
fd = system_bg_cpuset_fd;
boost_fd = bg_schedboost_fd;
break;
default:
boost_fd = fd = -1;
@ -316,10 +320,12 @@ int set_cpuset_policy(int tid, SchedPolicy policy)
return -errno;
}
#ifdef USE_SCHEDBOOST
if (boost_fd > 0 && add_tid_to_cgroup(tid, boost_fd) != 0) {
if (errno != ESRCH && errno != ENOENT)
return -errno;
}
#endif
return 0;
#endif
@ -391,19 +397,26 @@ int set_sched_policy(int tid, SchedPolicy policy)
#endif
if (__sys_supports_schedgroups) {
int fd;
int fd = -1;
int boost_fd = -1;
switch (policy) {
case SP_BACKGROUND:
fd = bg_cgroup_fd;
boost_fd = bg_schedboost_fd;
break;
case SP_FOREGROUND:
case SP_AUDIO_APP:
case SP_AUDIO_SYS:
fd = fg_cgroup_fd;
boost_fd = fg_schedboost_fd;
break;
case SP_TOP_APP:
fd = fg_cgroup_fd;
boost_fd = ta_schedboost_fd;
break;
default:
fd = -1;
boost_fd = -1;
break;
}
@ -412,6 +425,13 @@ int set_sched_policy(int tid, SchedPolicy policy)
if (errno != ESRCH && errno != ENOENT)
return -errno;
}
#ifdef USE_SCHEDBOOST
if (boost_fd > 0 && add_tid_to_cgroup(tid, boost_fd) != 0) {
if (errno != ESRCH && errno != ENOENT)
return -errno;
}
#endif
} else {
struct sched_param param;

View file

@ -24,6 +24,7 @@
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@ -35,12 +36,24 @@
#define SYS_POWER_STATE "/sys/power/state"
#define SYS_POWER_WAKEUP_COUNT "/sys/power/wakeup_count"
#define BASE_SLEEP_TIME 100000
static int state_fd;
static int wakeup_count_fd;
static pthread_t suspend_thread;
static sem_t suspend_lockout;
static const char *sleep_state = "mem";
static void (*wakeup_func)(bool success) = NULL;
static int sleep_time = BASE_SLEEP_TIME;
static void update_sleep_time(bool success) {
if (success) {
sleep_time = BASE_SLEEP_TIME;
return;
}
// double sleep time after each failure up to one minute
sleep_time = MIN(sleep_time * 2, 60000000);
}
static void *suspend_thread_func(void *arg __attribute__((unused)))
{
@ -48,10 +61,12 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
char wakeup_count[20];
int wakeup_count_len;
int ret;
bool success;
bool success = true;
while (1) {
usleep(100000);
update_sleep_time(success);
usleep(sleep_time);
success = false;
ALOGV("%s: read wakeup_count\n", __func__);
lseek(wakeup_count_fd, 0, SEEK_SET);
wakeup_count_len = TEMP_FAILURE_RETRY(read(wakeup_count_fd, wakeup_count,
@ -75,7 +90,6 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
continue;
}
success = true;
ALOGV("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count);
ret = TEMP_FAILURE_RETRY(write(wakeup_count_fd, wakeup_count, wakeup_count_len));
if (ret < 0) {
@ -84,8 +98,8 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
} else {
ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE);
ret = TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state)));
if (ret < 0) {
success = false;
if (ret >= 0) {
success = true;
}
void (*func)(bool success) = wakeup_func;
if (func != NULL) {

View file

@ -50,6 +50,7 @@ void FrameworkListener::init(const char *socketName UNUSED, bool withSeq) {
errorRate = 0;
mCommandCount = 0;
mWithSeq = withSeq;
mSkipToNextNullByte = false;
}
bool FrameworkListener::onDataAvailable(SocketClient *c) {
@ -60,10 +61,15 @@ bool FrameworkListener::onDataAvailable(SocketClient *c) {
if (len < 0) {
SLOGE("read() failed (%s)", strerror(errno));
return false;
} else if (!len)
} else if (!len) {
return false;
if(buffer[len-1] != '\0')
} else if (buffer[len-1] != '\0') {
SLOGW("String is not zero-terminated");
android_errorWriteLog(0x534e4554, "29831647");
c->sendMsg(500, "Command too large for buffer", false);
mSkipToNextNullByte = true;
return false;
}
int offset = 0;
int i;
@ -71,11 +77,16 @@ bool FrameworkListener::onDataAvailable(SocketClient *c) {
for (i = 0; i < len; i++) {
if (buffer[i] == '\0') {
/* IMPORTANT: dispatchCommand() expects a zero-terminated string */
dispatchCommand(c, buffer + offset);
if (mSkipToNextNullByte) {
mSkipToNextNullByte = false;
} else {
dispatchCommand(c, buffer + offset);
}
offset = i + 1;
}
}
mSkipToNextNullByte = false;
return true;
}

View file

@ -267,9 +267,14 @@ static int32_t MapCentralDirectory0(const char* debug_file_name, ZipArchive* arc
* Grab the CD offset and size, and the number of entries in the
* archive and verify that they look reasonable.
*/
if (eocd->cd_start_offset + eocd->cd_size > eocd_offset) {
if (static_cast<off64_t>(eocd->cd_start_offset) + eocd->cd_size > eocd_offset) {
ALOGW("Zip: bad offsets (dir %" PRIu32 ", size %" PRIu32 ", eocd %" PRId64 ")",
eocd->cd_start_offset, eocd->cd_size, static_cast<int64_t>(eocd_offset));
#if defined(__ANDROID__)
if (eocd->cd_start_offset + eocd->cd_size <= eocd_offset) {
android_errorWriteLog(0x534e4554, "31251826");
}
#endif
return kInvalidOffset;
}
if (eocd->num_records == 0) {

View file

@ -35,7 +35,8 @@ on property:logd.logpersistd.enable=true && property:logd.logpersistd=logcatd
# all exec/services are called with umask(077), so no gain beyond 0700
mkdir /data/misc/logd 0700 logd log
# logd for write to /data/misc/logd, log group for read from pstore (-L)
exec - logd log -- /system/bin/logcat -L -b ${logd.logpersistd.buffer:-all} -v threadtime -v usec -v printable -D -f /data/misc/logd/logcat -r 1024 -n ${logd.logpersistd.size:-256} --id=${ro.build.id}
# b/28788401 b/30041146 b/30612424
# exec - logd log -- /system/bin/logcat -L -b ${logd.logpersistd.buffer:-all} -v threadtime -v usec -v printable -D -f /data/misc/logd/logcat -r 1024 -n ${logd.logpersistd.size:-256} --id=${ro.build.id}
start logcatd
# stop logcatd service and clear data

View file

@ -402,7 +402,32 @@ void LogKlog::sniffTime(log_time &now,
}
}
pid_t LogKlog::sniffPid(const char *cp, size_t len) {
pid_t LogKlog::sniffPid(const char **buf, size_t len) {
const char *cp = *buf;
// HTC kernels with modified printk "c0 1648 "
if ((len > 9) &&
(cp[0] == 'c') &&
isdigit(cp[1]) &&
(isdigit(cp[2]) || (cp[2] == ' ')) &&
(cp[3] == ' ')) {
bool gotDigit = false;
int i;
for (i = 4; i < 9; ++i) {
if (isdigit(cp[i])) {
gotDigit = true;
} else if (gotDigit || (cp[i] != ' ')) {
break;
}
}
if ((i == 9) && (cp[i] == ' ')) {
int pid = 0;
char dummy;
if (sscanf(cp + 4, "%d%c", &pid, &dummy) == 2) {
*buf = cp + 10; // skip-it-all
return pid;
}
}
}
while (len) {
// Mediatek kernels with modified printk
if (*cp == '[') {
@ -588,7 +613,7 @@ int LogKlog::log(const char *buf, size_t len) {
}
// Parse pid, tid and uid
const pid_t pid = sniffPid(p, len - (p - buf));
const pid_t pid = sniffPid(&p, len - (p - buf));
const pid_t tid = pid;
uid_t uid = AID_ROOT;
if (pid) {

View file

@ -51,7 +51,7 @@ public:
protected:
void sniffTime(log_time &now, const char **buf, size_t len, bool reverse);
pid_t sniffPid(const char *buf, size_t len);
pid_t sniffPid(const char **buf, size_t len);
void calculateCorrection(const log_time &monotonic,
const char *real_string, size_t len);
virtual bool onDataAvailable(SocketClient *cli);

View file

@ -26,6 +26,7 @@ include $(BUILD_PREBUILT)
#######################################
# asan.options
ifneq ($(filter address,$(SANITIZE_TARGET)),)
include $(CLEAR_VARS)
LOCAL_MODULE := asan.options
@ -34,6 +35,72 @@ LOCAL_SRC_FILES := $(LOCAL_MODULE)
LOCAL_MODULE_PATH := $(TARGET_OUT)
include $(BUILD_PREBUILT)
# Modules for asan.options.X files.
ASAN_OPTIONS_FILES :=
define create-asan-options-module
include $$(CLEAR_VARS)
LOCAL_MODULE := asan.options.$(1)
ASAN_OPTIONS_FILES += asan.options.$(1)
LOCAL_MODULE_CLASS := ETC
# The asan.options.off.template tries to turn off as much of ASAN as is possible.
LOCAL_SRC_FILES := asan.options.off.template
LOCAL_MODULE_PATH := $(TARGET_OUT)
include $$(BUILD_PREBUILT)
endef
# Pretty comprehensive set of native services. This list is helpful if all that's to be checked is an
# app.
ifeq ($(SANITIZE_LITE),true)
SANITIZE_ASAN_OPTIONS_FOR := \
adbd \
ATFWD-daemon \
audioserver \
bridgemgrd \
cameraserver \
cnd \
debuggerd \
debuggerd64 \
dex2oat \
drmserver \
fingerprintd \
gatekeeperd \
installd \
keystore \
lmkd \
logcat \
logd \
lowi-server \
media.codec \
mediadrmserver \
media.extractor \
mediaserver \
mm-qcamera-daemon \
mpdecision \
netmgrd \
perfd \
perfprofd \
qmuxd \
qseecomd \
rild \
sdcard \
servicemanager \
slim_daemon \
surfaceflinger \
thermal-engine \
time_daemon \
update_engine \
vold \
wpa_supplicant \
zip
endif
ifneq ($(SANITIZE_ASAN_OPTIONS_FOR),)
$(foreach binary, $(SANITIZE_ASAN_OPTIONS_FOR), $(eval $(call create-asan-options-module,$(binary))))
endif
endif
#######################################
@ -47,14 +114,14 @@ LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
EXPORT_GLOBAL_ASAN_OPTIONS :=
ifneq ($(filter address,$(SANITIZE_TARGET)),)
EXPORT_GLOBAL_ASAN_OPTIONS := export ASAN_OPTIONS include=/system/asan.options
LOCAL_REQUIRED_MODULES := asan.options
LOCAL_REQUIRED_MODULES := asan.options $(ASAN_OPTIONS_FILES)
endif
# Put it here instead of in init.rc module definition,
# because init.rc is conditionally included.
#
# create some directories (some are mount points) and symlinks
LOCAL_POST_INSTALL_CMD := mkdir -p $(addprefix $(TARGET_ROOT_OUT)/, \
sbin dev proc sys system data oem acct cache config storage mnt root $(BOARD_ROOT_EXTRA_FOLDERS)); \
sbin dev proc sys system data oem acct config storage mnt root $(BOARD_ROOT_EXTRA_FOLDERS)); \
ln -sf /system/etc $(TARGET_ROOT_OUT)/etc; \
ln -sf /data/user_de/0/com.android.shell/files/bugreports $(TARGET_ROOT_OUT)/bugreports; \
ln -sf /sys/kernel/debug $(TARGET_ROOT_OUT)/d; \
@ -64,6 +131,11 @@ ifdef BOARD_USES_VENDORIMAGE
else
LOCAL_POST_INSTALL_CMD += ; ln -sf /system/vendor $(TARGET_ROOT_OUT)/vendor
endif
ifdef BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE
LOCAL_POST_INSTALL_CMD += ; mkdir -p $(TARGET_ROOT_OUT)/cache
else
LOCAL_POST_INSTALL_CMD += ; ln -sf /data/cache $(TARGET_ROOT_OUT)/cache
endif
ifdef BOARD_ROOT_EXTRA_SYMLINKS
# BOARD_ROOT_EXTRA_SYMLINKS is a list of <target>:<link_name>.
LOCAL_POST_INSTALL_CMD += $(foreach s, $(BOARD_ROOT_EXTRA_SYMLINKS),\

View file

@ -3,3 +3,5 @@ detect_odr_violation=0
alloc_dealloc_mismatch=0
allocator_may_return_null=1
detect_container_overflow=0
abort_on_error=1
include_if_exists=/system/asan.options.%b

View file

@ -0,0 +1,7 @@
quarantine_size_mb=0
max_redzone=16
poison_heap=false
poison_partial=false
poison_array_cookie=false
alloc_dealloc_mismatch=false
new_delete_type_mismatch=false

View file

@ -50,12 +50,20 @@ on init
mkdir /dev/stune
mount cgroup none /dev/stune schedtune
mkdir /dev/stune/foreground
mkdir /dev/stune/background
mkdir /dev/stune/top-app
chown system system /dev/stune
chown system system /dev/stune/foreground
chown system system /dev/stune/background
chown system system /dev/stune/top-app
chown system system /dev/stune/tasks
chown system system /dev/stune/foreground/tasks
chown system system /dev/stune/background/tasks
chown system system /dev/stune/top-app/tasks
chmod 0664 /dev/stune/tasks
chmod 0664 /dev/stune/foreground/tasks
chmod 0664 /dev/stune/background/tasks
chmod 0664 /dev/stune/top-app/tasks
# Mount staging areas for devices managed by vold
# See storage config details at http://source.android.com/tech/storage/
@ -134,16 +142,17 @@ on init
chown system system /dev/cpuctl
chown system system /dev/cpuctl/tasks
chmod 0666 /dev/cpuctl/tasks
write /dev/cpuctl/cpu.rt_runtime_us 800000
write /dev/cpuctl/cpu.rt_period_us 1000000
write /dev/cpuctl/cpu.rt_runtime_us 950000
mkdir /dev/cpuctl/bg_non_interactive
chown system system /dev/cpuctl/bg_non_interactive/tasks
chmod 0666 /dev/cpuctl/bg_non_interactive/tasks
# 5.0 %
write /dev/cpuctl/bg_non_interactive/cpu.shares 52
write /dev/cpuctl/bg_non_interactive/cpu.rt_runtime_us 700000
write /dev/cpuctl/bg_non_interactive/cpu.rt_period_us 1000000
# active FIFO threads will never be in BG
write /dev/cpuctl/bg_non_interactive/cpu.rt_runtime_us 10000
# sets up initial cpusets for ActivityManager
mkdir /dev/cpuset
@ -225,6 +234,8 @@ on init
# expecting it to point to /proc/self/fd
symlink /proc/self/fd /dev/fd
export DOWNLOAD_CACHE /data/cache
# set RLIMIT_NICE to allow priorities from 19 to -20
setrlimit 13 40 40
@ -412,6 +423,10 @@ on post-fs-data
# create the A/B OTA directory, so as to enforce our permissions
mkdir /data/ota 0771 root root
# create the OTA package directory. It will be accessed by GmsCore (cache
# group), update_engine and update_verifier.
mkdir /data/ota_package 0770 system cache
# create resource-cache and double-check the perms
mkdir /data/resource-cache 0771 system system
chown system system /data/resource-cache
@ -452,6 +467,11 @@ on post-fs-data
mkdir /data/media 0770 media_rw media_rw
mkdir /data/media/obb 0770 media_rw media_rw
mkdir /data/cache 0770 system cache
mkdir /data/cache/recovery 0770 system cache
mkdir /data/cache/backup_stage 0700 system system
mkdir /data/cache/backup 0700 system system
init_user0
# Set SELinux security contexts on upgrade or policy update.

View file

@ -103,7 +103,7 @@ on property:sys.usb.config=accessory,audio_source,adb && property:sys.usb.config
# Used to set USB configuration at boot and to switch the configuration
# when changing the default configuration
on property:persist.sys.usb.config=*
on boot && property:persist.sys.usb.config=*
setprop sys.usb.config ${persist.sys.usb.config}
#

View file

@ -10,4 +10,4 @@ service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-sys
onrestart restart cameraserver
onrestart restart media
onrestart restart netd
writepid /dev/cpuset/foreground/tasks /dev/stune/foreground/tasks
writepid /dev/cpuset/foreground/tasks

View file

@ -19,4 +19,4 @@ service zygote_secondary /system/bin/app_process64 -Xzygote /system/bin --zygote
group root readproc
socket zygote_secondary stream 660 root system
onrestart restart zygote
writepid /dev/cpuset/foreground/tasks /dev/stune/foreground/tasks
writepid /dev/cpuset/foreground/tasks

View file

@ -10,4 +10,4 @@ service zygote /system/bin/app_process64 -Xzygote /system/bin --zygote --start-s
onrestart restart cameraserver
onrestart restart media
onrestart restart netd
writepid /dev/cpuset/foreground/tasks /dev/stune/foreground/tasks
writepid /dev/cpuset/foreground/tasks

View file

@ -19,4 +19,4 @@ service zygote_secondary /system/bin/app_process32 -Xzygote /system/bin --zygote
group root readproc
socket zygote_secondary stream 660 root system
onrestart restart zygote
writepid /dev/cpuset/foreground/tasks /dev/stune/foreground/tasks
writepid /dev/cpuset/foreground/tasks

View file

@ -1026,7 +1026,13 @@ static int handle_open(struct fuse* fuse, struct fuse_handler* handler,
}
out.fh = ptr_to_id(h);
out.open_flags = 0;
#ifdef FUSE_SHORTCIRCUIT
out.lower_fd = h->fd;
#else
out.padding = 0;
#endif
fuse_reply(fuse, hdr->unique, &out, sizeof(out));
return NO_STATUS;
}
@ -1190,7 +1196,13 @@ static int handle_opendir(struct fuse* fuse, struct fuse_handler* handler,
}
out.fh = ptr_to_id(h);
out.open_flags = 0;
#ifdef FUSE_SHORTCIRCUIT
out.lower_fd = -1;
#else
out.padding = 0;
#endif
fuse_reply(fuse, hdr->unique, &out, sizeof(out));
return NO_STATUS;
}
@ -1270,6 +1282,11 @@ static int handle_init(struct fuse* fuse, struct fuse_handler* handler,
out.major = FUSE_KERNEL_VERSION;
out.max_readahead = req->max_readahead;
out.flags = FUSE_ATOMIC_O_TRUNC | FUSE_BIG_WRITES;
#ifdef FUSE_SHORTCIRCUIT
out.flags |= FUSE_SHORTCIRCUIT;
#endif
out.max_background = 32;
out.congestion_threshold = 32;
out.max_write = MAX_WRITE;