diff options
author | Yongqin Liu <yongqin.liu@linaro.org> | 2016-12-04 13:04:31 +0000 |
---|---|---|
committer | Linaro Android Code Review <android-review@review.linaro.org> | 2016-12-04 13:04:31 +0000 |
commit | bc549ae9f77ac59903f4e46ee0735c3cb123c3b0 (patch) | |
tree | d9e0c236b2b8355c936515e655abbb0819a20aff | |
parent | 3a31e47b1c16a0094f9d70062ce9130dd4e831d0 (diff) | |
parent | 9b3c7ad27ff0819c0a81f9d3f41b13fb8e8961a5 (diff) | |
download | core-linaro-android-6.0.tar.gz |
Merge "libbacktrace: workaround for compiling with linaro 5.3 gcc" into linaro-android-6.0linaro-android-6.0
-rw-r--r-- | debuggerd/debuggerd.cpp | 2 | ||||
-rw-r--r-- | healthd/BatteryMonitor.cpp | 19 | ||||
-rw-r--r-- | healthd/BatteryMonitor.h | 1 | ||||
-rw-r--r-- | include/log/log.h | 9 | ||||
-rw-r--r-- | init/bootchart.cpp | 2 | ||||
-rw-r--r-- | libbacktrace/Android.build.mk | 3 | ||||
-rw-r--r-- | liblog/Android.mk | 2 | ||||
-rw-r--r-- | liblog/log_event_write.c | 88 | ||||
-rw-r--r-- | liblog/tests/liblog_test.cpp | 396 | ||||
-rw-r--r-- | logd/LogBuffer.cpp | 5 | ||||
-rw-r--r-- | rootdir/init.rc | 24 |
11 files changed, 536 insertions, 15 deletions
diff --git a/debuggerd/debuggerd.cpp b/debuggerd/debuggerd.cpp index b84a4e587..9c8a41e61 100644 --- a/debuggerd/debuggerd.cpp +++ b/debuggerd/debuggerd.cpp @@ -538,7 +538,7 @@ static int do_server() { return 1; fcntl(s, F_SETFD, FD_CLOEXEC); - ALOGI("debuggerd: " __DATE__ " " __TIME__ "\n"); + ALOGI("debuggerd: starting\n"); for (;;) { sockaddr addr; diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index 1cad427bd..396dfef5a 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -39,6 +39,7 @@ #define POWER_SUPPLY_SYSFS_PATH "/sys/class/" POWER_SUPPLY_SUBSYSTEM #define FAKE_BATTERY_CAPACITY 42 #define FAKE_BATTERY_TEMPERATURE 424 +#define ALWAYS_PLUGGED_CAPACITY 100 namespace android { @@ -199,6 +200,15 @@ bool BatteryMonitor::update(void) { mBatteryFixedTemperature : getIntField(mHealthdConfig->batteryTemperaturePath); + // For devices which do not have battery and are always plugged + // into power souce. + if (mAlwaysPluggedDevice) { + props.chargerAcOnline = true; + props.batteryPresent = true; + props.batteryStatus = BATTERY_STATUS_CHARGING; + props.batteryHealth = BATTERY_HEALTH_GOOD; + } + const int SIZE = 128; char buf[SIZE]; String8 btech; @@ -542,8 +552,15 @@ void BatteryMonitor::init(struct healthd_config *hc) { closedir(dir); } - if (!mChargerNames.size()) + // This indicates that there is no charger driver registered. + // Typically the case for devices which do not have a battery and + // and are always plugged into AC mains. + if (!mChargerNames.size()) { KLOG_ERROR(LOG_TAG, "No charger supplies found\n"); + mBatteryFixedCapacity = ALWAYS_PLUGGED_CAPACITY; + mBatteryFixedTemperature = FAKE_BATTERY_TEMPERATURE; + mAlwaysPluggedDevice = true; + } if (!mBatteryDevicePresent) { KLOG_WARNING(LOG_TAG, "No battery devices found\n"); hc->periodic_chores_interval_fast = -1; diff --git a/healthd/BatteryMonitor.h b/healthd/BatteryMonitor.h index 3425f2771..a61171fc6 100644 --- a/healthd/BatteryMonitor.h +++ b/healthd/BatteryMonitor.h @@ -46,6 +46,7 @@ class BatteryMonitor { struct healthd_config *mHealthdConfig; Vector<String8> mChargerNames; bool mBatteryDevicePresent; + bool mAlwaysPluggedDevice; int mBatteryFixedCapacity; int mBatteryFixedTemperature; struct BatteryProperties props; diff --git a/include/log/log.h b/include/log/log.h index 0b175749c..1cdf7bc49 100644 --- a/include/log/log.h +++ b/include/log/log.h @@ -563,6 +563,12 @@ typedef enum { #define android_btWriteLog(tag, type, payload, len) \ __android_log_btwrite(tag, type, payload, len) +#define android_errorWriteLog(tag, subTag) \ + __android_log_error_write(tag, subTag, -1, NULL, 0) + +#define android_errorWriteWithInfoLog(tag, subTag, uid, data, dataLen) \ + __android_log_error_write(tag, subTag, uid, data, dataLen) + /* * IF_ALOG uses android_testLog, but IF_ALOG can be overridden. * android_testLog will remain constant in its purpose as a wrapper @@ -612,6 +618,9 @@ typedef enum log_id { */ int __android_log_is_loggable(int prio, const char *tag, int def); +int __android_log_error_write(int tag, const char *subTag, int32_t uid, const char *data, + uint32_t dataLen); + /* * Send a simple string to the log. */ diff --git a/init/bootchart.cpp b/init/bootchart.cpp index 95687cbd0..df8359dad 100644 --- a/init/bootchart.cpp +++ b/init/bootchart.cpp @@ -89,7 +89,7 @@ static void log_header() { if (out == NULL) { return; } - fprintf(out, "version = Android init 0.8 " __TIME__ "\n"); + fprintf(out, "version = Android init 0.8\n"); fprintf(out, "title = Boot chart for Android (%s)\n", date); fprintf(out, "system.uname = %s %s %s %s\n", uts.sysname, uts.release, uts.version, uts.machine); fprintf(out, "system.release = %s\n", fingerprint); diff --git a/libbacktrace/Android.build.mk b/libbacktrace/Android.build.mk index 35fed6df5..8c9345c59 100644 --- a/libbacktrace/Android.build.mk +++ b/libbacktrace/Android.build.mk @@ -70,6 +70,9 @@ LOCAL_LDLIBS := \ $($(module)_ldlibs_$(build_type)) \ ifeq ($(build_type),target) +LOCAL_CFLAGS_arm += \ + -O0 \ + include $(BUILD_$(build_target)) endif diff --git a/liblog/Android.mk b/liblog/Android.mk index d7766f544..115dd79b3 100644 --- a/liblog/Android.mk +++ b/liblog/Android.mk @@ -25,7 +25,7 @@ include $(CLEAR_VARS) liblog_cflags := -DLIBLOG_LOG_TAG=1005 ifneq ($(TARGET_USES_LOGD),false) -liblog_sources := logd_write.c +liblog_sources := logd_write.c log_event_write.c else liblog_sources := logd_write_kern.c endif diff --git a/liblog/log_event_write.c b/liblog/log_event_write.c new file mode 100644 index 000000000..0bc42d548 --- /dev/null +++ b/liblog/log_event_write.c @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2015 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 <errno.h> +#include <string.h> + +#include <log/log.h> +#include <log/logger.h> + +#define MAX_EVENT_PAYLOAD 512 +#define MAX_SUBTAG_LEN 32 + +static inline void copy4LE(uint8_t *buf, size_t pos, int val) +{ + buf[pos] = val & 0xFF; + buf[pos+1] = (val >> 8) & 0xFF; + buf[pos+2] = (val >> 16) & 0xFF; + buf[pos+3] = (val >> 24) & 0xFF; +} + +int __android_log_error_write(int tag, const char *subTag, int32_t uid, const char *data, + uint32_t dataLen) +{ + uint8_t buf[MAX_EVENT_PAYLOAD]; + size_t pos = 0; + uint32_t subTagLen = 0; + uint32_t roomLeftForData = 0; + + if ((subTag == NULL) || ((data == NULL) && (dataLen != 0))) return -EINVAL; + + subTagLen = strlen(subTag); + + // Truncate subtags that are too long. + subTagLen = subTagLen > MAX_SUBTAG_LEN ? MAX_SUBTAG_LEN : subTagLen; + + // Truncate dataLen if it is too long. + roomLeftForData = MAX_EVENT_PAYLOAD - + (1 + // EVENT_TYPE_LIST + 1 + // Number of elements in list + 1 + // EVENT_TYPE_STRING + sizeof(subTagLen) + + subTagLen + + 1 + // EVENT_TYPE_INT + sizeof(uid) + + 1 + // EVENT_TYPE_STRING + sizeof(dataLen)); + dataLen = dataLen > roomLeftForData ? roomLeftForData : dataLen; + + buf[pos++] = EVENT_TYPE_LIST; + buf[pos++] = 3; // Number of elements in the list (subTag, uid, data) + + // Write sub tag. + buf[pos++] = EVENT_TYPE_STRING; + copy4LE(buf, pos, subTagLen); + pos += 4; + memcpy(&buf[pos], subTag, subTagLen); + pos += subTagLen; + + // Write UID. + buf[pos++] = EVENT_TYPE_INT; + copy4LE(buf, pos, uid); + pos += 4; + + // Write data. + buf[pos++] = EVENT_TYPE_STRING; + copy4LE(buf, pos, dataLen); + pos += 4; + if (dataLen != 0) + { + memcpy(&buf[pos], data, dataLen); + pos += dataLen; + } + + return __android_log_bwrite(tag, buf, pos); +} diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp index abe023974..c98704139 100644 --- a/liblog/tests/liblog_test.cpp +++ b/liblog/tests/liblog_test.cpp @@ -17,6 +17,7 @@ #include <fcntl.h> #include <inttypes.h> #include <signal.h> +#include <string.h> #include <cutils/properties.h> #include <gtest/gtest.h> @@ -876,3 +877,398 @@ TEST(liblog, is_loggable) { property_set(key, hold[2]); property_set(key + base_offset, hold[3]); } + +static inline int32_t get4LE(const char* src) +{ + return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24); +} + +TEST(liblog, android_errorWriteWithInfoLog__android_logger_list_read__typical) { + const int TAG = 123456781; + const char SUBTAG[] = "test-subtag"; + const int UID = -1; + const int DATA_LEN = 200; + struct logger_list *logger_list; + + pid_t pid = getpid(); + + ASSERT_TRUE(NULL != (logger_list = android_logger_list_open( + LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid))); + + ASSERT_LT(0, android_errorWriteWithInfoLog( + TAG, SUBTAG, UID, max_payload_buf, DATA_LEN)); + + sleep(2); + + int count = 0; + + for (;;) { + log_msg log_msg; + if (android_logger_list_read(logger_list, &log_msg) <= 0) { + break; + } + + char *eventData = log_msg.msg(); + + // Tag + int tag = get4LE(eventData); + eventData += 4; + + if (tag != TAG) { + continue; + } + + // List type + ASSERT_EQ(EVENT_TYPE_LIST, eventData[0]); + eventData++; + + // Number of elements in list + ASSERT_EQ(3, eventData[0]); + eventData++; + + // Element #1: string type for subtag + ASSERT_EQ(EVENT_TYPE_STRING, eventData[0]); + eventData++; + + ASSERT_EQ((int) strlen(SUBTAG), get4LE(eventData)); + eventData +=4; + + if (memcmp(SUBTAG, eventData, strlen(SUBTAG))) { + continue; + } + eventData += strlen(SUBTAG); + + // Element #2: int type for uid + ASSERT_EQ(EVENT_TYPE_INT, eventData[0]); + eventData++; + + ASSERT_EQ(UID, get4LE(eventData)); + eventData += 4; + + // Element #3: string type for data + ASSERT_EQ(EVENT_TYPE_STRING, eventData[0]); + eventData++; + + ASSERT_EQ(DATA_LEN, get4LE(eventData)); + eventData += 4; + + if (memcmp(max_payload_buf, eventData, DATA_LEN)) { + continue; + } + + ++count; + } + + EXPECT_EQ(1, count); + + android_logger_list_close(logger_list); +} + +TEST(liblog, android_errorWriteWithInfoLog__android_logger_list_read__data_too_large) { + const int TAG = 123456782; + const char SUBTAG[] = "test-subtag"; + const int UID = -1; + const int DATA_LEN = sizeof(max_payload_buf); + struct logger_list *logger_list; + + pid_t pid = getpid(); + + ASSERT_TRUE(NULL != (logger_list = android_logger_list_open( + LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid))); + + ASSERT_LT(0, android_errorWriteWithInfoLog( + TAG, SUBTAG, UID, max_payload_buf, DATA_LEN)); + + sleep(2); + + int count = 0; + + for (;;) { + log_msg log_msg; + if (android_logger_list_read(logger_list, &log_msg) <= 0) { + break; + } + + char *eventData = log_msg.msg(); + char *original = eventData; + + // Tag + int tag = get4LE(eventData); + eventData += 4; + + if (tag != TAG) { + continue; + } + + // List type + ASSERT_EQ(EVENT_TYPE_LIST, eventData[0]); + eventData++; + + // Number of elements in list + ASSERT_EQ(3, eventData[0]); + eventData++; + + // Element #1: string type for subtag + ASSERT_EQ(EVENT_TYPE_STRING, eventData[0]); + eventData++; + + ASSERT_EQ((int) strlen(SUBTAG), get4LE(eventData)); + eventData +=4; + + if (memcmp(SUBTAG, eventData, strlen(SUBTAG))) { + continue; + } + eventData += strlen(SUBTAG); + + // Element #2: int type for uid + ASSERT_EQ(EVENT_TYPE_INT, eventData[0]); + eventData++; + + ASSERT_EQ(UID, get4LE(eventData)); + eventData += 4; + + // Element #3: string type for data + ASSERT_EQ(EVENT_TYPE_STRING, eventData[0]); + eventData++; + + size_t dataLen = get4LE(eventData); + eventData += 4; + + if (memcmp(max_payload_buf, eventData, dataLen)) { + continue; + } + eventData += dataLen; + + // 4 bytes for the tag, and 512 bytes for the log since the max_payload_buf should be + // truncated. + ASSERT_EQ(4 + 512, eventData - original); + + ++count; + } + + EXPECT_EQ(1, count); + + android_logger_list_close(logger_list); +} + +TEST(liblog, android_errorWriteWithInfoLog__android_logger_list_read__null_data) { + const int TAG = 123456783; + const char SUBTAG[] = "test-subtag"; + const int UID = -1; + const int DATA_LEN = 200; + struct logger_list *logger_list; + + pid_t pid = getpid(); + + ASSERT_TRUE(NULL != (logger_list = android_logger_list_open( + LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid))); + + ASSERT_GT(0, android_errorWriteWithInfoLog( + TAG, SUBTAG, UID, NULL, DATA_LEN)); + + sleep(2); + + int count = 0; + + for (;;) { + log_msg log_msg; + if (android_logger_list_read(logger_list, &log_msg) <= 0) { + break; + } + + char *eventData = log_msg.msg(); + + // Tag + int tag = get4LE(eventData); + eventData += 4; + + if (tag == TAG) { + // This tag should not have been written because the data was null + count++; + break; + } + } + + EXPECT_EQ(0, count); + + android_logger_list_close(logger_list); +} + +TEST(liblog, android_errorWriteWithInfoLog__android_logger_list_read__subtag_too_long) { + const int TAG = 123456784; + const char SUBTAG[] = "abcdefghijklmnopqrstuvwxyz now i know my abc"; + const int UID = -1; + const int DATA_LEN = 200; + struct logger_list *logger_list; + + pid_t pid = getpid(); + + ASSERT_TRUE(NULL != (logger_list = android_logger_list_open( + LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid))); + + ASSERT_LT(0, android_errorWriteWithInfoLog( + TAG, SUBTAG, UID, max_payload_buf, DATA_LEN)); + + sleep(2); + + int count = 0; + + for (;;) { + log_msg log_msg; + if (android_logger_list_read(logger_list, &log_msg) <= 0) { + break; + } + + char *eventData = log_msg.msg(); + + // Tag + int tag = get4LE(eventData); + eventData += 4; + + if (tag != TAG) { + continue; + } + + // List type + ASSERT_EQ(EVENT_TYPE_LIST, eventData[0]); + eventData++; + + // Number of elements in list + ASSERT_EQ(3, eventData[0]); + eventData++; + + // Element #1: string type for subtag + ASSERT_EQ(EVENT_TYPE_STRING, eventData[0]); + eventData++; + + // The subtag is longer than 32 and should be truncated to that. + ASSERT_EQ(32, get4LE(eventData)); + eventData +=4; + + if (memcmp(SUBTAG, eventData, 32)) { + continue; + } + eventData += 32; + + // Element #2: int type for uid + ASSERT_EQ(EVENT_TYPE_INT, eventData[0]); + eventData++; + + ASSERT_EQ(UID, get4LE(eventData)); + eventData += 4; + + // Element #3: string type for data + ASSERT_EQ(EVENT_TYPE_STRING, eventData[0]); + eventData++; + + ASSERT_EQ(DATA_LEN, get4LE(eventData)); + eventData += 4; + + if (memcmp(max_payload_buf, eventData, DATA_LEN)) { + continue; + } + + ++count; + } + + EXPECT_EQ(1, count); + + android_logger_list_close(logger_list); +} + +TEST(liblog, android_errorWriteLog__android_logger_list_read__success) { + const int TAG = 123456785; + const char SUBTAG[] = "test-subtag"; + struct logger_list *logger_list; + + pid_t pid = getpid(); + + ASSERT_TRUE(NULL != (logger_list = android_logger_list_open( + LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid))); + + ASSERT_LT(0, android_errorWriteLog(TAG, SUBTAG)); + + sleep(2); + + int count = 0; + + for (;;) { + log_msg log_msg; + if (android_logger_list_read(logger_list, &log_msg) <= 0) { + break; + } + + char *eventData = log_msg.msg(); + + // Tag + int tag = get4LE(eventData); + eventData += 4; + + if (tag != TAG) { + continue; + } + + // List type + ASSERT_EQ(EVENT_TYPE_LIST, eventData[0]); + eventData++; + + // Number of elements in list + ASSERT_EQ(3, eventData[0]); + eventData++; + + // Element #1: string type for subtag + ASSERT_EQ(EVENT_TYPE_STRING, eventData[0]); + eventData++; + + ASSERT_EQ((int) strlen(SUBTAG), get4LE(eventData)); + eventData +=4; + + if (memcmp(SUBTAG, eventData, strlen(SUBTAG))) { + continue; + } + ++count; + } + + EXPECT_EQ(1, count); + + android_logger_list_close(logger_list); +} + +TEST(liblog, android_errorWriteLog__android_logger_list_read__null_subtag) { + const int TAG = 123456786; + struct logger_list *logger_list; + + pid_t pid = getpid(); + + ASSERT_TRUE(NULL != (logger_list = android_logger_list_open( + LOG_ID_EVENTS, ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, 1000, pid))); + + ASSERT_GT(0, android_errorWriteLog(TAG, NULL)); + + sleep(2); + + int count = 0; + + for (;;) { + log_msg log_msg; + if (android_logger_list_read(logger_list, &log_msg) <= 0) { + break; + } + + char *eventData = log_msg.msg(); + + // Tag + int tag = get4LE(eventData); + eventData += 4; + + if (tag == TAG) { + // This tag should not have been written because the data was null + count++; + break; + } + } + + EXPECT_EQ(0, count); + + android_logger_list_close(logger_list); +} diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index 559fa2e65..d72a78c0f 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -435,7 +435,10 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { worst_sizes = sorted[0]->getSizes(); // Calculate threshold as 12.5% of available storage size_t threshold = log_buffer_size(id) / 8; - if (worst_sizes > threshold) { + if ((worst_sizes > threshold) + // Allow time horizon to extend roughly tenfold, assume + // average entry length is 100 characters. + && (worst_sizes > (10 * sorted[0]->getDropped()))) { worst = sorted[0]->getKey(); second_worst_sizes = sorted[1]->getSizes(); if (second_worst_sizes < threshold) { diff --git a/rootdir/init.rc b/rootdir/init.rc index 8ea72e833..317207c70 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -140,23 +140,27 @@ on init # sets up initial cpusets for ActivityManager mkdir /dev/cpuset mount cpuset none /dev/cpuset + + # this ensures that the cpusets are present and usable, but the device's + # init.rc must actually set the correct cpus mkdir /dev/cpuset/foreground + write /dev/cpuset/foreground/cpus 0 + write /dev/cpuset/foreground/mems 0 mkdir /dev/cpuset/foreground/boost + write /dev/cpuset/foreground/boost/cpus 0 + write /dev/cpuset/foreground/boost/mems 0 mkdir /dev/cpuset/background + write /dev/cpuset/background/cpus 0 + write /dev/cpuset/background/mems 0 + # system-background is for system tasks that should only run on # little cores, not on bigs - # to be used only by init, so don't change the permissions + # to be used only by init, so don't change system-bg permissions mkdir /dev/cpuset/system-background - # this ensures that the cpusets are present and usable, but the device's - # init.rc must actually set the correct cpus - write /dev/cpuset/foreground/cpus 0 - write /dev/cpuset/foreground/boost/cpus 0 - write /dev/cpuset/background/cpus 0 write /dev/cpuset/system-background/cpus 0 - write /dev/cpuset/foreground/mems 0 - write /dev/cpuset/foreground/boost/mems 0 - write /dev/cpuset/background/mems 0 write /dev/cpuset/system-background/mems 0 + + # change permissions for all cpusets we'll touch at runtime chown system system /dev/cpuset chown system system /dev/cpuset/foreground chown system system /dev/cpuset/foreground/boost @@ -663,7 +667,7 @@ service defaultcrypto /system/bin/vdc --wait cryptfs mountdefaultencrypted # encryption) or trigger_restart_min_framework (other encryption) # One shot invocation to encrypt unencrypted volumes -service encrypt /system/bin/vdc --wait cryptfs enablecrypto inplace default +service encrypt /system/bin/vdc --wait cryptfs enablecrypto inplace default noui disabled oneshot # vold will set vold.decrypt to trigger_restart_framework (default |