Merge "Enable libdemangle and libunwindstack on host bionic"
diff --git a/base/include/android-base/logging.h b/base/include/android-base/logging.h
index 548b286..f18cc0c 100644
--- a/base/include/android-base/logging.h
+++ b/base/include/android-base/logging.h
@@ -438,4 +438,14 @@
} // namespace base
} // namespace android
+namespace std {
+
+// Delete << with string* to avoid mistakes. The intention was most likely to print *string.
+// If you really want to print the pointer, consider static_cast<void*>.
+//
+// Note: for this to work, we need to have this in a namespace.
+std::ostream& operator<<(std::ostream& stream, const std::string* string_pointer) = delete;
+
+} // namespace std
+
#endif // ANDROID_BASE_LOGGING_H
diff --git a/bootstat/boot_event_record_store.cpp b/bootstat/boot_event_record_store.cpp
index 99d9405..e2a4b04 100644
--- a/bootstat/boot_event_record_store.cpp
+++ b/bootstat/boot_event_record_store.cpp
@@ -58,16 +58,15 @@
}
void BootEventRecordStore::AddBootEvent(const std::string& event) {
- auto uptime = std::chrono::duration_cast<std::chrono::seconds>(
- android::base::boot_clock::now().time_since_epoch());
- AddBootEventWithValue(event, uptime.count());
+ auto uptime = std::chrono::duration_cast<std::chrono::seconds>(
+ android::base::boot_clock::now().time_since_epoch());
+ AddBootEventWithValue(event, uptime.count());
}
// The implementation of AddBootEventValue makes use of the mtime file
// attribute to store the value associated with a boot event in order to
// optimize on-disk size requirements and small-file thrashing.
-void BootEventRecordStore::AddBootEventWithValue(
- const std::string& event, int32_t value) {
+void BootEventRecordStore::AddBootEventWithValue(const std::string& event, int32_t value) {
std::string record_path = GetBootEventPath(event);
int record_fd = creat(record_path.c_str(), S_IRUSR | S_IWUSR);
if (record_fd == -1) {
@@ -96,8 +95,7 @@
close(record_fd);
}
-bool BootEventRecordStore::GetBootEvent(
- const std::string& event, BootEventRecord* record) const {
+bool BootEventRecordStore::GetBootEvent(const std::string& event, BootEventRecord* record) const {
CHECK_NE(static_cast<BootEventRecord*>(nullptr), record);
CHECK(!event.empty());
@@ -112,8 +110,7 @@
return true;
}
-std::vector<BootEventRecordStore::BootEventRecord> BootEventRecordStore::
- GetAllBootEvents() const {
+std::vector<BootEventRecordStore::BootEventRecord> BootEventRecordStore::GetAllBootEvents() const {
std::vector<BootEventRecord> events;
std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(store_path_.c_str()), closedir);
@@ -147,8 +144,7 @@
store_path_ = path;
}
-std::string BootEventRecordStore::GetBootEventPath(
- const std::string& event) const {
+std::string BootEventRecordStore::GetBootEventPath(const std::string& event) const {
DCHECK_EQ('/', store_path_.back());
return store_path_ + event;
}
diff --git a/bootstat/boot_event_record_store.h b/bootstat/boot_event_record_store.h
index a2b8318..f872c85 100644
--- a/bootstat/boot_event_record_store.h
+++ b/bootstat/boot_event_record_store.h
@@ -17,12 +17,12 @@
#ifndef BOOT_EVENT_RECORD_STORE_H_
#define BOOT_EVENT_RECORD_STORE_H_
+#include <android-base/macros.h>
+#include <gtest/gtest_prod.h>
#include <cstdint>
#include <string>
#include <utility>
#include <vector>
-#include <android-base/macros.h>
-#include <gtest/gtest_prod.h>
// BootEventRecordStore manages the persistence of boot events to the record
// store and the retrieval of all boot event records from the store.
diff --git a/bootstat/boot_event_record_store_test.cpp b/bootstat/boot_event_record_store_test.cpp
index d98169b..4b7ab36 100644
--- a/bootstat/boot_event_record_store_test.cpp
+++ b/bootstat/boot_event_record_store_test.cpp
@@ -94,20 +94,16 @@
// Returns the time in seconds since boot.
time_t GetUptimeSeconds() {
- return std::chrono::duration_cast<std::chrono::seconds>(
- android::base::boot_clock::now().time_since_epoch())
- .count();
+ return std::chrono::duration_cast<std::chrono::seconds>(
+ android::base::boot_clock::now().time_since_epoch())
+ .count();
}
class BootEventRecordStoreTest : public ::testing::Test {
public:
- BootEventRecordStoreTest() {
- store_path_ = std::string(store_dir_.path) + "/";
- }
+ BootEventRecordStoreTest() { store_path_ = std::string(store_dir_.path) + "/"; }
- const std::string& GetStorePathForTesting() const {
- return store_path_;
- }
+ const std::string& GetStorePathForTesting() const { return store_path_; }
private:
void TearDown() {
@@ -159,9 +155,7 @@
store.AddBootEvent("triassic");
const std::string EXPECTED_NAMES[] = {
- "cretaceous",
- "jurassic",
- "triassic",
+ "cretaceous", "jurassic", "triassic",
};
auto events = store.GetAllBootEvents();
diff --git a/bootstat/boot_reason_test.sh b/bootstat/boot_reason_test.sh
index 4314271..b76011a 100755
--- a/bootstat/boot_reason_test.sh
+++ b/bootstat/boot_reason_test.sh
@@ -370,6 +370,7 @@
fast and fake (touch build_date on device to make it different)" ]
test_optional_ota() {
echo "INFO: expected duration of ${TEST} test about 45 seconds" >&2
+ echo "WARNING: ${TEST} requires userdebug build" >&2
adb shell su root touch /data/misc/bootstat/build_date >&2
adb reboot ota
wait_for_screen
@@ -425,6 +426,7 @@
a _real_ factory_reset is too destructive to the device." ]
test_factory_reset() {
echo "INFO: expected duration of ${TEST} test roughly 45 seconds" >&2
+ echo "WARNING: ${TEST} requires userdebug build" >&2
adb shell su root rm /data/misc/bootstat/build_date >&2
adb reboot >&2
wait_for_screen
@@ -479,7 +481,8 @@
[ "USAGE: test_battery
battery test (trick):
-- echo healthd: battery l=2 | adb shell su root tee /dev/kmsg ; adb reboot cold
+- echo healthd: battery l=2<space> | adb shell su root tee /dev/kmsg
+- adb reboot cold
- (wait until screen is up, boot has completed)
- adb shell getprop sys.boot.reason
- NB: should report reboot,battery, unless healthd managed to log
@@ -491,7 +494,7 @@
+ setprop logd.kernel false
+ rm /sys/fs/pstore/console-ramoops
+ rm /sys/fs/pstore/console-ramoops-0
- + write /dev/kmsg \"healthd: battery l=2
+ + write /dev/kmsg \"healthd: battery l=2${SPACE}
+\"
- adb reboot fs
- (wait until screen is up, boot has completed)
@@ -500,9 +503,10 @@
- (replace set logd.kernel true to the above, and retry test)" ]
test_battery() {
echo "INFO: expected duration of ${TEST} test roughly two minutes" >&2
+ echo "WARNING: ${TEST} requires userdebug build" >&2
# Send it _many_ times to combat devices with flakey pstore
for i in a b c d e f g h i j k l m n o p q r s t u v w x y z; do
- echo healthd: battery l=2 | adb shell su root tee /dev/kmsg >/dev/null
+ echo 'healthd: battery l=2 ' | adb shell su root tee /dev/kmsg >/dev/null
done
adb reboot cold >&2
adb wait-for-device
@@ -512,11 +516,11 @@
/proc/fs/pstore/console-ramoops-0 2>/dev/null |
grep 'healthd: battery l=' |
tail -1 |
- grep 'healthd: battery l=2' >/dev/null || (
+ grep 'healthd: battery l=2 ' >/dev/null || (
if ! EXPECT_PROPERTY sys.boot.reason reboot,battery >/dev/null 2>/dev/null; then
# retry
for i in a b c d e f g h i j k l m n o p q r s t u v w x y z; do
- echo healthd: battery l=2 | adb shell su root tee /dev/kmsg >/dev/null
+ echo 'healthd: battery l=2 ' | adb shell su root tee /dev/kmsg >/dev/null
done
adb reboot cold >&2
adb wait-for-device
@@ -550,6 +554,7 @@
- NB: should report kernel_panic,sysrq" ]
test_kernel_panic() {
echo "INFO: expected duration of ${TEST} test > 2 minutes" >&2
+ echo "WARNING: ${TEST} requires userdebug build" >&2
echo c | adb shell su root tee /proc/sysrq-trigger >/dev/null
wait_for_screen
EXPECT_PROPERTY sys.boot.reason kernel_panic,sysrq
@@ -640,6 +645,26 @@
report_bootstat_logs reboot,adb
}
+[ "USAGE: test_Its_Just_So_Hard_reboot
+
+Its Just So Hard reboot test:
+- adb shell reboot 'Its Just So Hard'
+- (wait until screen is up, boot has completed)
+- adb shell getprop sys.boot.reason
+- NB: should report reboot,its_just_so_hard
+- NB: expect log \"... I bootstat: Unknown boot reason: reboot,its_just_so_hard\"" ]
+test_Its_Just_So_Hard_reboot() {
+ echo "INFO: expected duration of ${TEST} test roughly 45 seconds" >&2
+ echo "INFO: ${TEST} cleanup requires userdebug build" >&2
+ adb shell 'reboot "Its Just So Hard"'
+ wait_for_screen
+ EXPECT_PROPERTY sys.boot.reason reboot,its_just_so_hard
+ EXPECT_PROPERTY persist.sys.boot.reason "reboot,Its Just So Hard"
+ adb shell su root setprop persist.sys.boot.reason reboot,its_just_so_hard
+ EXPECT_PROPERTY persist.sys.boot.reason reboot,its_just_so_hard
+ report_bootstat_logs reboot,its_just_so_hard
+}
+
[ "USAGE: ${0##*/} [-s SERIAL] [tests]
Mainline executive to run the above tests" ]
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp
index d4c45a2..e2202fd 100644
--- a/bootstat/bootstat.cpp
+++ b/bootstat/bootstat.cpp
@@ -19,8 +19,8 @@
// uploaded to Android log storage via Tron.
#include <getopt.h>
-#include <unistd.h>
#include <sys/klog.h>
+#include <unistd.h>
#include <chrono>
#include <cmath>
@@ -61,8 +61,7 @@
// Records the named boot |event| to the record store. If |value| is non-empty
// and is a proper string representation of an integer value, the converted
// integer value is associated with the boot event.
-void RecordBootEventFromCommandLine(
- const std::string& event, const std::string& value_str) {
+void RecordBootEventFromCommandLine(const std::string& event, const std::string& value_str) {
BootEventRecordStore boot_event_store;
if (!value_str.empty()) {
int32_t value = 0;
@@ -85,7 +84,7 @@
}
}
-void ShowHelp(const char *cmd) {
+void ShowHelp(const char* cmd) {
fprintf(stderr, "Usage: %s [options]\n", cmd);
fprintf(stderr,
"options include:\n"
@@ -101,7 +100,7 @@
// Constructs a readable, printable string from the givencommand line
// arguments.
-std::string GetCommandLine(int argc, char **argv) {
+std::string GetCommandLine(int argc, char** argv) {
std::string cmd;
for (int i = 0; i < argc; ++i) {
cmd += argv[i];
@@ -137,73 +136,73 @@
// the boot_reason metric may refer to this mapping to discern the histogram
// values.
const std::map<std::string, int32_t> kBootReasonMap = {
- {"unknown", kUnknownBootReason},
- {"normal", 2},
- {"recovery", 3},
- {"reboot", 4},
- {"PowerKey", 5},
- {"hard_reset", 6},
- {"kernel_panic", 7},
- {"rpm_err", 8},
- {"hw_reset", 9},
- {"tz_err", 10},
- {"adsp_err", 11},
- {"modem_err", 12},
- {"mba_err", 13},
- {"Watchdog", 14},
- {"Panic", 15},
- {"power_key", 16},
- {"power_on", 17},
- {"Reboot", 18},
- {"rtc", 19},
- {"edl", 20},
- {"oem_pon1", 21},
- {"oem_powerkey", 22},
- {"oem_unknown_reset", 23},
- {"srto: HWWDT reset SC", 24},
- {"srto: HWWDT reset platform", 25},
- {"srto: bootloader", 26},
- {"srto: kernel panic", 27},
- {"srto: kernel watchdog reset", 28},
- {"srto: normal", 29},
- {"srto: reboot", 30},
- {"srto: reboot-bootloader", 31},
- {"srto: security watchdog reset", 32},
- {"srto: wakesrc", 33},
- {"srto: watchdog", 34},
- {"srto:1-1", 35},
- {"srto:omap_hsmm", 36},
- {"srto:phy0", 37},
- {"srto:rtc0", 38},
- {"srto:touchpad", 39},
- {"watchdog", 40},
- {"watchdogr", 41},
- {"wdog_bark", 42},
- {"wdog_bite", 43},
- {"wdog_reset", 44},
- {"shutdown,", 45}, // Trailing comma is intentional.
- {"shutdown,userrequested", 46},
- {"reboot,bootloader", 47},
- {"reboot,cold", 48},
- {"reboot,recovery", 49},
- {"thermal_shutdown", 50},
- {"s3_wakeup", 51},
- {"kernel_panic,sysrq", 52},
- {"kernel_panic,NULL", 53},
- {"kernel_panic,BUG", 54},
- {"bootloader", 55},
- {"cold", 56},
- {"hard", 57},
- {"warm", 58},
- {"recovery", 59},
- {"thermal-shutdown", 60},
- {"shutdown,thermal", 61},
- {"shutdown,battery", 62},
- {"reboot,ota", 63},
- {"reboot,factory_reset", 64},
- {"reboot,", 65},
- {"reboot,shell", 66},
- {"reboot,adb", 67},
+ {"unknown", kUnknownBootReason},
+ {"normal", 2},
+ {"recovery", 3},
+ {"reboot", 4},
+ {"PowerKey", 5},
+ {"hard_reset", 6},
+ {"kernel_panic", 7},
+ {"rpm_err", 8},
+ {"hw_reset", 9},
+ {"tz_err", 10},
+ {"adsp_err", 11},
+ {"modem_err", 12},
+ {"mba_err", 13},
+ {"Watchdog", 14},
+ {"Panic", 15},
+ {"power_key", 16},
+ {"power_on", 17},
+ {"Reboot", 18},
+ {"rtc", 19},
+ {"edl", 20},
+ {"oem_pon1", 21},
+ {"oem_powerkey", 22},
+ {"oem_unknown_reset", 23},
+ {"srto: HWWDT reset SC", 24},
+ {"srto: HWWDT reset platform", 25},
+ {"srto: bootloader", 26},
+ {"srto: kernel panic", 27},
+ {"srto: kernel watchdog reset", 28},
+ {"srto: normal", 29},
+ {"srto: reboot", 30},
+ {"srto: reboot-bootloader", 31},
+ {"srto: security watchdog reset", 32},
+ {"srto: wakesrc", 33},
+ {"srto: watchdog", 34},
+ {"srto:1-1", 35},
+ {"srto:omap_hsmm", 36},
+ {"srto:phy0", 37},
+ {"srto:rtc0", 38},
+ {"srto:touchpad", 39},
+ {"watchdog", 40},
+ {"watchdogr", 41},
+ {"wdog_bark", 42},
+ {"wdog_bite", 43},
+ {"wdog_reset", 44},
+ {"shutdown,", 45}, // Trailing comma is intentional.
+ {"shutdown,userrequested", 46},
+ {"reboot,bootloader", 47},
+ {"reboot,cold", 48},
+ {"reboot,recovery", 49},
+ {"thermal_shutdown", 50},
+ {"s3_wakeup", 51},
+ {"kernel_panic,sysrq", 52},
+ {"kernel_panic,NULL", 53},
+ {"kernel_panic,BUG", 54},
+ {"bootloader", 55},
+ {"cold", 56},
+ {"hard", 57},
+ {"warm", 58},
+ {"recovery", 59},
+ {"thermal-shutdown", 60},
+ {"shutdown,thermal", 61},
+ {"shutdown,battery", 62},
+ {"reboot,ota", 63},
+ {"reboot,factory_reset", 64},
+ {"reboot,", 65},
+ {"reboot,shell", 66},
+ {"reboot,adb", 67},
};
// Converts a string value representing the reason the system booted to an
@@ -221,23 +220,25 @@
// Canonical list of supported primary reboot reasons.
const std::vector<const std::string> knownReasons = {
- // kernel
- "watchdog",
- "kernel_panic",
- // strong
- "recovery", // Should not happen from ro.boot.bootreason
- "bootloader", // Should not happen from ro.boot.bootreason
- // blunt
- "cold",
- "hard",
- "warm",
- "shutdown", // Can not happen from ro.boot.bootreason
- "reboot", // Default catch-all for anything unknown
+ // clang-format off
+ // kernel
+ "watchdog",
+ "kernel_panic",
+ // strong
+ "recovery", // Should not happen from ro.boot.bootreason
+ "bootloader", // Should not happen from ro.boot.bootreason
+ // blunt
+ "cold",
+ "hard",
+ "warm",
+ "shutdown", // Can not happen from ro.boot.bootreason
+ "reboot", // Default catch-all for anything unknown
+ // clang-format on
};
// Returns true if the supplied reason prefix is considered detailed enough.
bool isStrongRebootReason(const std::string& r) {
- for (auto &s : knownReasons) {
+ for (auto& s : knownReasons) {
if (s == "cold") break;
// Prefix defined as terminated by a nul or comma (,).
if (android::base::StartsWith(r, s.c_str()) &&
@@ -250,7 +251,7 @@
// Returns true if the supplied reason prefix is associated with the kernel.
bool isKernelRebootReason(const std::string& r) {
- for (auto &s : knownReasons) {
+ for (auto& s : knownReasons) {
if (s == "recovery") break;
// Prefix defined as terminated by a nul or comma (,).
if (android::base::StartsWith(r, s.c_str()) &&
@@ -263,7 +264,7 @@
// Returns true if the supplied reason prefix is considered known.
bool isKnownRebootReason(const std::string& r) {
- for (auto &s : knownReasons) {
+ for (auto& s : knownReasons) {
// Prefix defined as terminated by a nul or comma (,).
if (android::base::StartsWith(r, s.c_str()) &&
((r.length() == s.length()) || (r[s.length()] == ','))) {
@@ -277,7 +278,7 @@
bool isBluntRebootReason(const std::string& r) {
if (isStrongRebootReason(r)) return false;
- if (!isKnownRebootReason(r)) return true; // Can not support unknown as detail
+ if (!isKnownRebootReason(r)) return true; // Can not support unknown as detail
size_t pos = 0;
while ((pos = r.find(',', pos)) != std::string::npos) {
@@ -285,8 +286,8 @@
std::string next(r.substr(pos));
if (next.length() == 0) break;
if (next[0] == ',') continue;
- if (!isKnownRebootReason(next)) return false; // Unknown subreason is good.
- if (isStrongRebootReason(next)) return false; // eg: reboot,reboot
+ if (!isKnownRebootReason(next)) return false; // Unknown subreason is good.
+ if (isStrongRebootReason(next)) return false; // eg: reboot,reboot
}
return true;
}
@@ -320,8 +321,12 @@
// std::transform Helper callback functions:
// Converts a string value representing the reason the system booted to a
// string complying with Android system standard reason.
-char tounderline(char c) { return ::isblank(c) ? '_' : c; }
-char toprintable(char c) { return ::isprint(c) ? c : '?'; }
+char tounderline(char c) {
+ return ::isblank(c) ? '_' : c;
+}
+char toprintable(char c) {
+ return ::isprint(c) ? c : '?';
+}
const char system_reboot_reason_property[] = "sys.boot.reason";
const char last_reboot_reason_property[] = LAST_REBOOT_REASON_PROPERTY;
@@ -329,6 +334,8 @@
// Scrub, Sanitize, Standardize and Enhance the boot reason string supplied.
std::string BootReasonStrToReason(const std::string& boot_reason) {
+ static const size_t max_reason_length = 256;
+
std::string ret(GetProperty(system_reboot_reason_property));
std::string reason(boot_reason);
// If sys.boot.reason == ro.boot.bootreason, let's re-evaluate
@@ -345,9 +352,9 @@
if (ret == "") {
// Is the bootloader boot reason ro.boot.bootreason known?
std::vector<std::string> words(android::base::Split(reason, ",_-"));
- for (auto &s : knownReasons) {
+ for (auto& s : knownReasons) {
std::string blunt;
- for (auto &r : words) {
+ for (auto& r : words) {
if (r == s) {
if (isBluntRebootReason(s)) {
blunt = s;
@@ -368,17 +375,17 @@
// sense. In an ideal world, we would require those bootloaders
// to behave and follow our standards.
static const std::vector<std::pair<const std::string, const std::string>> aliasReasons = {
- {"watchdog", "wdog"},
- {"cold,powerkey", "powerkey"},
- {"kernel_panic", "panic"},
- {"shutdown,thermal", "thermal"},
- {"warm,s3_wakeup", "s3_wakeup"},
- {"hard,hw_reset", "hw_reset"},
- {"bootloader", ""},
+ {"watchdog", "wdog"},
+ {"cold,powerkey", "powerkey"},
+ {"kernel_panic", "panic"},
+ {"shutdown,thermal", "thermal"},
+ {"warm,s3_wakeup", "s3_wakeup"},
+ {"hard,hw_reset", "hw_reset"},
+ {"bootloader", ""},
};
// Either the primary or alias is found _somewhere_ in the reason string.
- for (auto &s : aliasReasons) {
+ for (auto& s : aliasReasons) {
if (reason.find(s.first) != std::string::npos) {
ret = s.first;
break;
@@ -423,9 +430,15 @@
size_t pos = content.rfind(cmd);
if (pos != std::string::npos) {
pos += strlen(cmd);
- std::string subReason(content.substr(pos));
- pos = subReason.find('\'');
- if (pos != std::string::npos) subReason.erase(pos);
+ std::string subReason(content.substr(pos, max_reason_length));
+ for (pos = 0; pos < subReason.length(); ++pos) {
+ char c = tounderline(subReason[pos]);
+ if (!::isprint(c) || (c == '\'')) {
+ subReason.erase(pos);
+ break;
+ }
+ subReason[pos] = ::tolower(c);
+ }
if (subReason != "") { // Will not land "reboot" as that is too blunt.
if (isKernelRebootReason(subReason)) {
ret = "reboot," + subReason; // User space can't talk kernel reasons.
@@ -453,23 +466,30 @@
if (isBluntRebootReason(ret)) {
// Heuristic to determine if shutdown possibly because of a dead battery?
// Really a hail-mary pass to find it in last klog content ...
- static const int battery_dead_threshold = 2; // percent
+ static const int battery_dead_threshold = 2; // percent
static const char battery[] = "healthd: battery l=";
size_t pos = content.rfind(battery); // last one
+ std::string digits;
if (pos != std::string::npos) {
- int level = atoi(content.substr(pos + strlen(battery)).c_str());
+ digits = content.substr(pos + strlen(battery));
+ }
+ char* endptr = NULL;
+ unsigned long long level = strtoull(digits.c_str(), &endptr, 10);
+ if ((level <= 100) && (endptr != digits.c_str()) && (*endptr == ' ')) {
LOG(INFO) << "Battery level at shutdown " << level << "%";
if (level <= battery_dead_threshold) {
ret = "shutdown,battery";
}
- } else { // Most likely
+ } else { // Most likely
+ digits = ""; // reset digits
+
// Content buffer no longer will have console data. Beware if more
// checks added below, that depend on parsing console content.
content = "";
LOG(DEBUG) << "Can not find last low battery in last console messages";
android_logcat_context ctx = create_android_logcat();
- FILE *fp = android_logcat_popen(&ctx, "logcat -b kernel -v brief -d");
+ FILE* fp = android_logcat_popen(&ctx, "logcat -b kernel -v brief -d");
if (fp != nullptr) {
android::base::ReadFdToString(fileno(fp), &content);
}
@@ -482,7 +502,7 @@
// Service logd.klog not running, go to smaller buffer in the kernel.
int rc = klogctl(KLOG_SIZE_BUFFER, nullptr, 0);
if (rc > 0) {
- ssize_t len = rc + 1024; // 1K Margin should it grow between calls.
+ ssize_t len = rc + 1024; // 1K Margin should it grow between calls.
std::unique_ptr<char[]> buf(new char[len]);
rc = klogctl(KLOG_READ_ALL, buf.get(), len);
if (rc < len) {
@@ -494,10 +514,13 @@
match = battery;
}
- pos = content.find(match); // The first one it finds.
+ pos = content.find(match); // The first one it finds.
if (pos != std::string::npos) {
- pos += strlen(match);
- int level = atoi(content.substr(pos).c_str());
+ digits = content.substr(pos + strlen(match));
+ }
+ endptr = NULL;
+ level = strtoull(digits.c_str(), &endptr, 10);
+ if ((level <= 100) && (endptr != digits.c_str()) && (*endptr == ' ')) {
LOG(INFO) << "Battery level at startup " << level << "%";
if (level <= battery_dead_threshold) {
ret = "shutdown,battery";
@@ -513,6 +536,10 @@
// Content buffer no longer will have console data. Beware if more
// checks added below, that depend on parsing console content.
content = GetProperty(last_reboot_reason_property);
+ // Cleanup last_boot_reason regarding acceptable character set
+ std::transform(content.begin(), content.end(), content.begin(), ::tolower);
+ std::transform(content.begin(), content.end(), content.begin(), tounderline);
+ std::transform(content.begin(), content.end(), content.begin(), toprintable);
// String is either "reboot,<reason>" or "shutdown,<reason>".
// We will set if default reasons, only override with detail if thermal.
@@ -580,7 +607,7 @@
if (!boot_event_store.GetBootEvent(kBuildDateKey, &record)) {
boot_complete_prefix = "factory_reset_" + boot_complete_prefix;
boot_event_store.AddBootEventWithValue(kBuildDateKey, build_date);
- LOG(INFO) << "Canonical boot reason: " << "reboot,factory_reset";
+ LOG(INFO) << "Canonical boot reason: reboot,factory_reset";
SetProperty(system_reboot_reason_property, "reboot,factory_reset");
if (GetProperty(bootloader_reboot_reason_property) == "") {
SetProperty(bootloader_reboot_reason_property, "reboot,factory_reset");
@@ -588,7 +615,7 @@
} else if (build_date != record.second) {
boot_complete_prefix = "ota_" + boot_complete_prefix;
boot_event_store.AddBootEventWithValue(kBuildDateKey, build_date);
- LOG(INFO) << "Canonical boot reason: " << "reboot,ota";
+ LOG(INFO) << "Canonical boot reason: reboot,ota";
SetProperty(system_reboot_reason_property, "reboot,ota");
if (GetProperty(bootloader_reboot_reason_property) == "") {
SetProperty(bootloader_reboot_reason_property, "reboot,ota");
@@ -599,8 +626,7 @@
}
// Records the value of a given ro.boottime.init property in milliseconds.
-void RecordInitBootTimeProp(
- BootEventRecordStore* boot_event_store, const char* property) {
+void RecordInitBootTimeProp(BootEventRecordStore* boot_event_store, const char* property) {
std::string value = GetProperty(property);
int32_t time_in_ms;
@@ -685,10 +711,8 @@
if (boot_event_store.GetBootEvent("last_boot_time_utc", &record)) {
time_t last_boot_time_utc = record.second;
- time_t time_since_last_boot = difftime(current_time_utc,
- last_boot_time_utc);
- boot_event_store.AddBootEventWithValue("time_since_last_boot",
- time_since_last_boot);
+ time_t time_since_last_boot = difftime(current_time_utc, last_boot_time_utc);
+ boot_event_store.AddBootEventWithValue("time_since_last_boot", time_since_last_boot);
}
boot_event_store.AddBootEventWithValue("last_boot_time_utc", current_time_utc);
@@ -714,8 +738,7 @@
boot_event_store.AddBootEventWithValue(boot_complete_prefix + "_post_decrypt",
boot_complete.count());
} else {
- boot_event_store.AddBootEventWithValue(boot_complete_prefix + "_no_encryption",
- uptime.count());
+ boot_event_store.AddBootEventWithValue(boot_complete_prefix + "_no_encryption", uptime.count());
}
// Record the total time from device startup to boot complete, regardless of
@@ -738,8 +761,7 @@
void RecordBootReason() {
const std::string reason(GetProperty(bootloader_reboot_reason_property));
android::metricslogger::LogMultiAction(android::metricslogger::ACTION_BOOT,
- android::metricslogger::FIELD_PLATFORM_REASON,
- reason);
+ android::metricslogger::FIELD_PLATFORM_REASON, reason);
// Log the raw bootloader_boot_reason property value.
int32_t boot_reason = BootReasonStrToEnum(reason);
@@ -769,21 +791,20 @@
if (current_time_utc < 0) {
// UMA does not display negative values in buckets, so convert to positive.
- android::metricslogger::LogHistogram(
- "factory_reset_current_time_failure", std::abs(current_time_utc));
+ android::metricslogger::LogHistogram("factory_reset_current_time_failure",
+ std::abs(current_time_utc));
// Logging via BootEventRecordStore to see if using android::metricslogger::LogHistogram
// is losing records somehow.
- boot_event_store.AddBootEventWithValue(
- "factory_reset_current_time_failure", std::abs(current_time_utc));
+ boot_event_store.AddBootEventWithValue("factory_reset_current_time_failure",
+ std::abs(current_time_utc));
return;
} else {
android::metricslogger::LogHistogram("factory_reset_current_time", current_time_utc);
// Logging via BootEventRecordStore to see if using android::metricslogger::LogHistogram
// is losing records somehow.
- boot_event_store.AddBootEventWithValue(
- "factory_reset_current_time", current_time_utc);
+ boot_event_store.AddBootEventWithValue("factory_reset_current_time", current_time_utc);
}
// The factory_reset boot event does not exist after the device is reset, so
@@ -803,18 +824,15 @@
// Logging via BootEventRecordStore to see if using android::metricslogger::LogHistogram
// is losing records somehow.
- boot_event_store.AddBootEventWithValue(
- "factory_reset_record_value", factory_reset_utc);
+ boot_event_store.AddBootEventWithValue("factory_reset_record_value", factory_reset_utc);
- time_t time_since_factory_reset = difftime(current_time_utc,
- factory_reset_utc);
- boot_event_store.AddBootEventWithValue("time_since_factory_reset",
- time_since_factory_reset);
+ time_t time_since_factory_reset = difftime(current_time_utc, factory_reset_utc);
+ boot_event_store.AddBootEventWithValue("time_since_factory_reset", time_since_factory_reset);
}
} // namespace
-int main(int argc, char **argv) {
+int main(int argc, char** argv) {
android::base::InitLogging(argv);
const std::string cmd_line = GetCommandLine(argc, argv);
@@ -826,15 +844,17 @@
static const char boot_reason_str[] = "record_boot_reason";
static const char factory_reset_str[] = "record_time_since_factory_reset";
static const struct option long_options[] = {
- { "help", no_argument, NULL, 'h' },
- { "log", no_argument, NULL, 'l' },
- { "print", no_argument, NULL, 'p' },
- { "record", required_argument, NULL, 'r' },
- { value_str, required_argument, NULL, 0 },
- { boot_complete_str, no_argument, NULL, 0 },
- { boot_reason_str, no_argument, NULL, 0 },
- { factory_reset_str, no_argument, NULL, 0 },
- { NULL, 0, NULL, 0 }
+ // clang-format off
+ { "help", no_argument, NULL, 'h' },
+ { "log", no_argument, NULL, 'l' },
+ { "print", no_argument, NULL, 'p' },
+ { "record", required_argument, NULL, 'r' },
+ { value_str, required_argument, NULL, 0 },
+ { boot_complete_str, no_argument, NULL, 0 },
+ { boot_reason_str, no_argument, NULL, 0 },
+ { factory_reset_str, no_argument, NULL, 0 },
+ { NULL, 0, NULL, 0 }
+ // clang-format on
};
std::string boot_event;
diff --git a/libion/ion_4.12.h b/libion/ion_4.12.h
new file mode 100644
index 0000000..6ae79d4
--- /dev/null
+++ b/libion/ion_4.12.h
@@ -0,0 +1,125 @@
+/*
+ * Adapted from drivers/staging/android/uapi/ion.h
+ *
+ * Copyright (C) 2011 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef _UAPI_LINUX_ION_NEW_H
+#define _UAPI_LINUX_ION_NEW_H
+
+#include <linux/ioctl.h>
+#include <linux/types.h>
+
+#define ION_NUM_HEAP_IDS (sizeof(unsigned int) * 8)
+
+/**
+ * DOC: Ion Userspace API
+ *
+ * create a client by opening /dev/ion
+ * most operations handled via following ioctls
+ *
+ */
+
+/**
+ * struct ion_new_allocation_data - metadata passed from userspace for allocations
+ * @len: size of the allocation
+ * @heap_id_mask: mask of heap ids to allocate from
+ * @flags: flags passed to heap
+ * @handle: pointer that will be populated with a cookie to use to
+ * refer to this allocation
+ *
+ * Provided by userspace as an argument to the ioctl - added _new to denote
+ * this belongs to the new ION interface.
+ */
+struct ion_new_allocation_data {
+ __u64 len;
+ __u32 heap_id_mask;
+ __u32 flags;
+ __u32 fd;
+ __u32 unused;
+};
+
+#define MAX_HEAP_NAME 32
+
+/**
+ * struct ion_heap_data - data about a heap
+ * @name - first 32 characters of the heap name
+ * @type - heap type
+ * @heap_id - heap id for the heap
+ */
+struct ion_heap_data {
+ char name[MAX_HEAP_NAME];
+ __u32 type;
+ __u32 heap_id;
+ __u32 reserved0;
+ __u32 reserved1;
+ __u32 reserved2;
+};
+
+/**
+ * struct ion_heap_query - collection of data about all heaps
+ * @cnt - total number of heaps to be copied
+ * @heaps - buffer to copy heap data
+ */
+struct ion_heap_query {
+ __u32 cnt; /* Total number of heaps to be copied */
+ __u32 reserved0; /* align to 64bits */
+ __u64 heaps; /* buffer to be populated */
+ __u32 reserved1;
+ __u32 reserved2;
+};
+
+#define ION_IOC_MAGIC 'I'
+
+/**
+ * DOC: ION_IOC_NEW_ALLOC - allocate memory
+ *
+ * Takes an ion_allocation_data struct and returns it with the handle field
+ * populated with the opaque handle for the allocation.
+ * TODO: This IOCTL will clash by design; however, only one of
+ * ION_IOC_ALLOC or ION_IOC_NEW_ALLOC paths will be exercised,
+ * so this should not conflict.
+ */
+#define ION_IOC_NEW_ALLOC _IOWR(ION_IOC_MAGIC, 0, struct ion_new_allocation_data)
+
+/**
+ * DOC: ION_IOC_FREE - free memory
+ *
+ * Takes an ion_handle_data struct and frees the handle.
+ *
+ * #define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
+ * This will come from the older kernels, so don't redefine here
+ */
+
+/**
+ * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
+ *
+ * Takes an ion_fd_data struct with the handle field populated with a valid
+ * opaque handle. Returns the struct with the fd field set to a file
+ * descriptor open in the current address space. This file descriptor
+ * can then be passed to another process. The corresponding opaque handle can
+ * be retrieved via ION_IOC_IMPORT.
+ *
+ * #define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
+ * This will come from the older kernels, so don't redefine here
+ */
+
+/**
+ * DOC: ION_IOC_HEAP_QUERY - information about available heaps
+ *
+ * Takes an ion_heap_query structure and populates information about
+ * available Ion heaps.
+ */
+#define ION_IOC_HEAP_QUERY _IOWR(ION_IOC_MAGIC, 8, struct ion_heap_query)
+
+#endif /* _UAPI_LINUX_ION_NEW_H */