adb: fix race condition in test_non_interactive_sigint.
am: e76b9f3dde
Change-Id: Ib2b6c1118cb48c337c12efbd223c87fee76837f2
diff --git a/adb/bugreport.cpp b/adb/bugreport.cpp
index 24be529..c348dd5 100644
--- a/adb/bugreport.cpp
+++ b/adb/bugreport.cpp
@@ -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 @@
//
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);
}
diff --git a/adb/commandline.cpp b/adb/commandline.cpp
index 54e254a..fe5d280 100644
--- a/adb/commandline.cpp
+++ b/adb/commandline.cpp
@@ -686,100 +686,100 @@
static int adb_shell(int argc, const char** argv) {
FeatureSet features;
std::string error;
-
if (!adb_get_feature_set(&features, &error)) {
fprintf(stderr, "error: %s\n", error.c_str());
return 1;
}
- bool use_shell_protocol = CanUseFeature(features, kFeatureShell2);
- if (!use_shell_protocol) {
- D("shell protocol not supported, using raw data transfer");
- } else {
- D("using shell protocol");
- }
+ enum PtyAllocationMode { kPtyAuto, kPtyNo, kPtyYes, kPtyDefinitely };
+
+ // Defaults.
+ char escape_char = '~'; // -e
+ bool use_shell_protocol = CanUseFeature(features, kFeatureShell2); // -x
+ PtyAllocationMode tty = use_shell_protocol ? kPtyAuto : kPtyDefinitely; // -t/-T
// Parse shell-specific command-line options.
- // argv[0] is always "shell".
- --argc;
- ++argv;
- int t_arg_count = 0;
- char escape_char = '~';
- while (argc) {
- if (!strcmp(argv[0], "-e")) {
- if (argc < 2 || !(strlen(argv[1]) == 1 || strcmp(argv[1], "none") == 0)) {
- fprintf(stderr, "error: -e requires a single-character argument or 'none'\n");
+ argv[0] = "adb shell"; // So getopt(3) error messages start "adb shell".
+ optind = 1; // argv[0] is always "shell", so set `optind` appropriately.
+ int opt;
+ while ((opt = getopt(argc, const_cast<char**>(argv), "+e:ntTx")) != -1) {
+ switch (opt) {
+ case 'e':
+ if (!(strlen(optarg) == 1 || strcmp(optarg, "none") == 0)) {
+ fprintf(stderr, "error: -e requires a single-character argument or 'none'\n");
+ return 1;
+ }
+ escape_char = (strcmp(optarg, "none") == 0) ? 0 : optarg[0];
+ break;
+ case 'n':
+ close_stdin();
+ break;
+ case 'x':
+ // This option basically asks for historical behavior, so set options that
+ // correspond to the historical defaults. This is slightly weird in that -Tx
+ // is fine (because we'll undo the -T) but -xT isn't, but that does seem to
+ // be our least worst choice...
+ use_shell_protocol = false;
+ tty = kPtyDefinitely;
+ escape_char = '~';
+ break;
+ case 't':
+ // Like ssh, -t arguments are cumulative so that multiple -t's
+ // are needed to force a PTY.
+ tty = (tty >= kPtyYes) ? kPtyDefinitely : kPtyYes;
+ break;
+ case 'T':
+ tty = kPtyNo;
+ break;
+ default:
+ // getopt(3) already printed an error message for us.
return 1;
- }
- escape_char = (strcmp(argv[1], "none") == 0) ? 0 : argv[1][0];
- argc -= 2;
- argv += 2;
- } else if (!strcmp(argv[0], "-T") || !strcmp(argv[0], "-t")) {
- // Like ssh, -t arguments are cumulative so that multiple -t's
- // are needed to force a PTY.
- if (argv[0][1] == 't') {
- ++t_arg_count;
- } else {
- t_arg_count = -1;
- }
- --argc;
- ++argv;
- } else if (!strcmp(argv[0], "-x")) {
- use_shell_protocol = false;
- --argc;
- ++argv;
- } else if (!strcmp(argv[0], "-n")) {
- close_stdin();
-
- --argc;
- ++argv;
- } else {
- break;
}
}
- // Legacy shell protocol requires a remote PTY to close the subprocess properly which creates
- // some weird interactions with -tT.
- if (!use_shell_protocol && t_arg_count != 0) {
- if (!CanUseFeature(features, kFeatureShell2)) {
- fprintf(stderr, "error: target doesn't support PTY args -Tt\n");
- } else {
- fprintf(stderr, "error: PTY args -Tt cannot be used with -x\n");
- }
- return 1;
- }
+ bool is_interactive = (optind == argc);
- std::string shell_type_arg;
- if (CanUseFeature(features, kFeatureShell2)) {
- if (t_arg_count < 0) {
+ std::string shell_type_arg = kShellServiceArgPty;
+ if (tty == kPtyNo) {
+ shell_type_arg = kShellServiceArgRaw;
+ } else if (tty == kPtyAuto) {
+ // If stdin isn't a TTY, default to a raw shell; this lets
+ // things like `adb shell < my_script.sh` work as expected.
+ // Non-interactive shells should also not have a pty.
+ if (!unix_isatty(STDIN_FILENO) || !is_interactive) {
shell_type_arg = kShellServiceArgRaw;
- } else if (t_arg_count == 0) {
- // If stdin isn't a TTY, default to a raw shell; this lets
- // things like `adb shell < my_script.sh` work as expected.
- // Otherwise leave |shell_type_arg| blank which uses PTY for
- // interactive shells and raw for non-interactive.
- if (!unix_isatty(STDIN_FILENO)) {
- shell_type_arg = kShellServiceArgRaw;
- }
- } else if (t_arg_count == 1) {
- // A single -t arg isn't enough to override implicit -T.
- if (!unix_isatty(STDIN_FILENO)) {
- fprintf(stderr,
- "Remote PTY will not be allocated because stdin is not a terminal.\n"
- "Use multiple -t options to force remote PTY allocation.\n");
- shell_type_arg = kShellServiceArgRaw;
- } else {
- shell_type_arg = kShellServiceArgPty;
- }
+ }
+ } else if (tty == kPtyYes) {
+ // A single -t arg isn't enough to override implicit -T.
+ if (!unix_isatty(STDIN_FILENO)) {
+ fprintf(stderr,
+ "Remote PTY will not be allocated because stdin is not a terminal.\n"
+ "Use multiple -t options to force remote PTY allocation.\n");
+ shell_type_arg = kShellServiceArgRaw;
+ }
+ }
+
+ D("shell -e 0x%x t=%d use_shell_protocol=%s shell_type_arg=%s\n",
+ escape_char, tty,
+ use_shell_protocol ? "true" : "false",
+ (shell_type_arg == kShellServiceArgPty) ? "pty" : "raw");
+
+ // Raw mode is only supported when talking to a new device *and* using the shell protocol.
+ if (!use_shell_protocol) {
+ if (shell_type_arg != kShellServiceArgPty) {
+ fprintf(stderr, "error: %s only supports allocating a pty\n",
+ !CanUseFeature(features, kFeatureShell2) ? "device" : "-x");
+ return 1;
} else {
- shell_type_arg = kShellServiceArgPty;
+ // If we're not using the shell protocol, the type argument must be empty.
+ shell_type_arg = "";
}
}
std::string command;
- if (argc) {
+ if (optind < argc) {
// We don't escape here, just like ssh(1). http://b/20564385.
- command = android::base::Join(std::vector<const char*>(argv, argv + argc), ' ');
+ command = android::base::Join(std::vector<const char*>(argv + optind, argv + argc), ' ');
}
return RemoteShell(use_shell_protocol, shell_type_arg, escape_char, command);
@@ -1401,7 +1401,7 @@
return !CanUseFeature(features, kFeatureCmd);
}
-int adb_commandline(int argc, const char **argv) {
+int adb_commandline(int argc, const char** argv) {
int no_daemon = 0;
int is_daemon = 0;
int is_server = 0;
diff --git a/adb/shell_service_protocol_test.cpp b/adb/shell_service_protocol_test.cpp
index a826035..b0fa3ed 100644
--- a/adb/shell_service_protocol_test.cpp
+++ b/adb/shell_service_protocol_test.cpp
@@ -86,9 +86,10 @@
namespace {
-// Returns true if the packet contains the given values.
+// Returns true if the packet contains the given values. `data` can't be null.
bool PacketEquals(const ShellProtocol* protocol, ShellProtocol::Id id,
const void* data, size_t data_length) {
+ // Note that passing memcmp null is bad, even if data_length is 0.
return (protocol->id() == id &&
protocol->data_length() == data_length &&
!memcmp(data, protocol->data(), data_length));
@@ -130,7 +131,8 @@
ASSERT_TRUE(write_protocol_->Write(id, 0));
ASSERT_TRUE(read_protocol_->Read());
- ASSERT_TRUE(PacketEquals(read_protocol_, id, nullptr, 0));
+ char buf[1];
+ ASSERT_TRUE(PacketEquals(read_protocol_, id, buf, 0));
}
// Tests exit code packets.
diff --git a/adb/test_device.py b/adb/test_device.py
index 2f2a823..ac7cf3b 100644
--- a/adb/test_device.py
+++ b/adb/test_device.py
@@ -371,15 +371,8 @@
def test_pty_logic(self):
"""Tests that a PTY is allocated when it should be.
- PTY allocation behavior should match ssh; some behavior requires
- a terminal stdin to test so this test will be skipped if stdin
- is not a terminal.
+ PTY allocation behavior should match ssh.
"""
- if not self.device.has_shell_protocol():
- raise unittest.SkipTest('PTY arguments unsupported on this device')
- if not os.isatty(sys.stdin.fileno()):
- raise unittest.SkipTest('PTY tests require stdin terminal')
-
def check_pty(args):
"""Checks adb shell PTY allocation.
@@ -409,16 +402,34 @@
# -T: never allocate PTY.
self.assertEqual((False, False), check_pty(['-T']))
- # No args: PTY only if stdin is a terminal and shell is interactive,
- # which is difficult to reliably test from a script.
- self.assertEqual((False, False), check_pty([]))
+ # These tests require a new device.
+ if self.device.has_shell_protocol() and os.isatty(sys.stdin.fileno()):
+ # No args: PTY only if stdin is a terminal and shell is interactive,
+ # which is difficult to reliably test from a script.
+ self.assertEqual((False, False), check_pty([]))
- # -t: PTY if stdin is a terminal.
- self.assertEqual((True, False), check_pty(['-t']))
+ # -t: PTY if stdin is a terminal.
+ self.assertEqual((True, False), check_pty(['-t']))
# -t -t: always allocate PTY.
self.assertEqual((True, True), check_pty(['-t', '-t']))
+ # -tt: always allocate PTY, POSIX style (http://b/32216152).
+ self.assertEqual((True, True), check_pty(['-tt']))
+
+ # -ttt: ssh has weird even/odd behavior with multiple -t flags, but
+ # we follow the man page instead.
+ self.assertEqual((True, True), check_pty(['-ttt']))
+
+ # -ttx: -x and -tt aren't incompatible (though -Tx would be an error).
+ self.assertEqual((True, True), check_pty(['-ttx']))
+
+ # -Ttt: -tt cancels out -T.
+ self.assertEqual((True, True), check_pty(['-Ttt']))
+
+ # -ttT: -T cancels out -tt.
+ self.assertEqual((False, False), check_pty(['-ttT']))
+
def test_shell_protocol(self):
"""Tests the shell protocol on the device.
diff --git a/base/Android.bp b/base/Android.bp
index 88d8ad1..e6ad15b 100644
--- a/base/Android.bp
+++ b/base/Android.bp
@@ -73,6 +73,7 @@
"errors_test.cpp",
"file_test.cpp",
"logging_test.cpp",
+ "parsedouble_test.cpp",
"parseint_test.cpp",
"parsenetaddress_test.cpp",
"quick_exit_test.cpp",
diff --git a/base/include/android-base/parsedouble.h b/base/include/android-base/parsedouble.h
new file mode 100644
index 0000000..daa6902
--- /dev/null
+++ b/base/include/android-base/parsedouble.h
@@ -0,0 +1,50 @@
+/*
+ * 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 ANDROID_BASE_PARSEDOUBLE_H
+#define ANDROID_BASE_PARSEDOUBLE_H
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include <limits>
+
+namespace android {
+namespace base {
+
+// Parse double value in the string 's' and sets 'out' to that value.
+// Optionally allows the caller to define a 'min' and 'max' beyond which
+// otherwise valid values will be rejected. Returns boolean success.
+static inline bool ParseDouble(const char* s, double* out,
+ double min = std::numeric_limits<double>::lowest(),
+ double max = std::numeric_limits<double>::max()) {
+ errno = 0;
+ char* end;
+ double result = strtod(s, &end);
+ if (errno != 0 || s == end || *end != '\0') {
+ return false;
+ }
+ if (result < min || max < result) {
+ return false;
+ }
+ *out = result;
+ return true;
+}
+
+} // namespace base
+} // namespace android
+
+#endif // ANDROID_BASE_PARSEDOUBLE_H
diff --git a/base/include/android-base/test_utils.h b/base/include/android-base/test_utils.h
index 4ea3c8e..c0bf0c1 100644
--- a/base/include/android-base/test_utils.h
+++ b/base/include/android-base/test_utils.h
@@ -48,4 +48,21 @@
DISALLOW_COPY_AND_ASSIGN(TemporaryDir);
};
+class CapturedStderr {
+ public:
+ CapturedStderr();
+ ~CapturedStderr();
+
+ int fd() const;
+
+ private:
+ void init();
+ void reset();
+
+ TemporaryFile temp_file_;
+ int old_stderr_;
+
+ DISALLOW_COPY_AND_ASSIGN(CapturedStderr);
+};
+
#endif // ANDROID_BASE_TEST_UTILS_H
diff --git a/base/logging.cpp b/base/logging.cpp
index dab86fe..cbc3c8a 100644
--- a/base/logging.cpp
+++ b/base/logging.cpp
@@ -45,7 +45,7 @@
// Headers for LogMessage::LogLine.
#ifdef __ANDROID__
-#include <android/log.h>
+#include <log/log.h>
#include <android/set_abort_message.h>
#else
#include <sys/types.h>
diff --git a/base/logging_test.cpp b/base/logging_test.cpp
index 1ee181a..2d9c2ba 100644
--- a/base/logging_test.cpp
+++ b/base/logging_test.cpp
@@ -37,42 +37,6 @@
#define HOST_TEST(suite, name) TEST(suite, name)
#endif
-class CapturedStderr {
- public:
- CapturedStderr() : old_stderr_(-1) {
- init();
- }
-
- ~CapturedStderr() {
- reset();
- }
-
- int fd() const {
- return temp_file_.fd;
- }
-
- private:
- void init() {
-#if defined(_WIN32)
- // On Windows, stderr is often buffered, so make sure it is unbuffered so
- // that we can immediately read back what was written to stderr.
- ASSERT_EQ(0, setvbuf(stderr, NULL, _IONBF, 0));
-#endif
- old_stderr_ = dup(STDERR_FILENO);
- ASSERT_NE(-1, old_stderr_);
- ASSERT_NE(-1, dup2(fd(), STDERR_FILENO));
- }
-
- void reset() {
- ASSERT_NE(-1, dup2(old_stderr_, STDERR_FILENO));
- ASSERT_EQ(0, close(old_stderr_));
- // Note: cannot restore prior setvbuf() setting.
- }
-
- TemporaryFile temp_file_;
- int old_stderr_;
-};
-
#if defined(_WIN32)
static void ExitSignalAbortHandler(int) {
_exit(3);
diff --git a/base/parsedouble_test.cpp b/base/parsedouble_test.cpp
new file mode 100644
index 0000000..8734c42
--- /dev/null
+++ b/base/parsedouble_test.cpp
@@ -0,0 +1,38 @@
+/*
+ * 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 "android-base/parsedouble.h"
+
+#include <gtest/gtest.h>
+
+TEST(parsedouble, smoke) {
+ double d;
+ ASSERT_FALSE(android::base::ParseDouble("", &d));
+ ASSERT_FALSE(android::base::ParseDouble("x", &d));
+ ASSERT_FALSE(android::base::ParseDouble("123.4x", &d));
+
+ ASSERT_TRUE(android::base::ParseDouble("123.4", &d));
+ ASSERT_DOUBLE_EQ(123.4, d);
+ ASSERT_TRUE(android::base::ParseDouble("-123.4", &d));
+ ASSERT_DOUBLE_EQ(-123.4, d);
+
+ ASSERT_TRUE(android::base::ParseDouble("0", &d, 0.0));
+ ASSERT_DOUBLE_EQ(0.0, d);
+ ASSERT_FALSE(android::base::ParseDouble("0", &d, 1e-9));
+ ASSERT_FALSE(android::base::ParseDouble("3.0", &d, -1.0, 2.0));
+ ASSERT_TRUE(android::base::ParseDouble("1.0", &d, 0.0, 2.0));
+ ASSERT_DOUBLE_EQ(1.0, d);
+}
diff --git a/base/test_utils.cpp b/base/test_utils.cpp
index 635af6c..3b3d698 100644
--- a/base/test_utils.cpp
+++ b/base/test_utils.cpp
@@ -102,3 +102,32 @@
OS_PATH_SEPARATOR);
return (mkdtemp(path) != nullptr);
}
+
+CapturedStderr::CapturedStderr() : old_stderr_(-1) {
+ init();
+}
+
+CapturedStderr::~CapturedStderr() {
+ reset();
+}
+
+int CapturedStderr::fd() const {
+ return temp_file_.fd;
+}
+
+void CapturedStderr::init() {
+#if defined(_WIN32)
+ // On Windows, stderr is often buffered, so make sure it is unbuffered so
+ // that we can immediately read back what was written to stderr.
+ CHECK_EQ(0, setvbuf(stderr, NULL, _IONBF, 0));
+#endif
+ old_stderr_ = dup(STDERR_FILENO);
+ CHECK_NE(-1, old_stderr_);
+ CHECK_NE(-1, dup2(fd(), STDERR_FILENO));
+}
+
+void CapturedStderr::reset() {
+ CHECK_NE(-1, dup2(old_stderr_, STDERR_FILENO));
+ CHECK_EQ(0, close(old_stderr_));
+ // Note: cannot restore prior setvbuf() setting.
+}
diff --git a/bootstat/event_log_list_builder.cpp b/bootstat/event_log_list_builder.cpp
index a6af13e..ce540a0 100644
--- a/bootstat/event_log_list_builder.cpp
+++ b/bootstat/event_log_list_builder.cpp
@@ -20,7 +20,7 @@
#include <memory>
#include <string>
-#include <android/log.h>
+#include <log/log.h>
#include <android-base/logging.h>
namespace {
diff --git a/bootstat/event_log_list_builder_test.cpp b/bootstat/event_log_list_builder_test.cpp
index 8f7f323..25909b0 100644
--- a/bootstat/event_log_list_builder_test.cpp
+++ b/bootstat/event_log_list_builder_test.cpp
@@ -18,9 +18,9 @@
#include <inttypes.h>
-#include <android/log.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+#include <log/log.h>
using testing::ElementsAreArray;
diff --git a/bootstat/histogram_logger.cpp b/bootstat/histogram_logger.cpp
index 3144d8b..4f2386c 100644
--- a/bootstat/histogram_logger.cpp
+++ b/bootstat/histogram_logger.cpp
@@ -19,8 +19,8 @@
#include <cstdlib>
#include <memory>
-#include <android/log.h>
#include <android-base/logging.h>
+#include <log/log.h>
#include "event_log_list_builder.h"
diff --git a/debuggerd/crasher.cpp b/debuggerd/crasher.cpp
index cfcc26e..3db67b3 100644
--- a/debuggerd/crasher.cpp
+++ b/debuggerd/crasher.cpp
@@ -1,3 +1,21 @@
+/*
+ * Copyright 2006, 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.
+ */
+
+#define LOG_TAG "crasher"
+
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
diff --git a/debuggerd/debuggerd.cpp b/debuggerd/debuggerd.cpp
index b8a62a5..867fd29 100644
--- a/debuggerd/debuggerd.cpp
+++ b/debuggerd/debuggerd.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "debuggerd"
+
#include <arpa/inet.h>
#include <dirent.h>
#include <elf.h>
@@ -182,6 +184,16 @@
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);
@@ -224,16 +236,13 @@
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,
@@ -410,10 +419,31 @@
}
#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);
@@ -440,7 +470,7 @@
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;
}
@@ -566,11 +596,33 @@
// 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);
diff --git a/debuggerd/getevent.cpp b/debuggerd/getevent.cpp
index dfa7bec..dbb878a 100644
--- a/debuggerd/getevent.cpp
+++ b/debuggerd/getevent.cpp
@@ -26,6 +26,7 @@
#include <sys/ioctl.h>
#include <sys/limits.h>
#include <sys/poll.h>
+#include <unistd.h>
#include <memory>
diff --git a/debuggerd/signal_sender.cpp b/debuggerd/signal_sender.cpp
index 3adbef2..7fe4dee 100644
--- a/debuggerd/signal_sender.cpp
+++ b/debuggerd/signal_sender.cpp
@@ -14,7 +14,10 @@
* limitations under the License.
*/
+#define LOG_TAG "debuggerd-signal"
+
#include <errno.h>
+#include <pthread.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
diff --git a/debuggerd/test/log_fake.cpp b/debuggerd/test/log_fake.cpp
index 59910ad..3336bcb 100644
--- a/debuggerd/test/log_fake.cpp
+++ b/debuggerd/test/log_fake.cpp
@@ -19,8 +19,8 @@
#include <string>
-#include <android/log.h>
#include <android-base/stringprintf.h>
+#include <log/log.h>
// Forward declarations.
class Backtrace;
diff --git a/debuggerd/tombstone.cpp b/debuggerd/tombstone.cpp
index e2461c0..459e4cc 100644
--- a/debuggerd/tombstone.cpp
+++ b/debuggerd/tombstone.cpp
@@ -36,6 +36,7 @@
#include <backtrace/Backtrace.h>
#include <backtrace/BacktraceMap.h>
#include <cutils/properties.h>
+#include <log/log.h>
#include <log/logprint.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
diff --git a/debuggerd/utility.cpp b/debuggerd/utility.cpp
index e334e71..419d36c 100644
--- a/debuggerd/utility.cpp
+++ b/debuggerd/utility.cpp
@@ -27,9 +27,9 @@
#include <string>
-#include <android/log.h>
#include <android-base/stringprintf.h>
#include <backtrace/Backtrace.h>
+#include <log/log.h>
// Whitelist output desired in the logcat output.
bool is_allowed_in_logcat(enum logtype ltype) {
diff --git a/fs_mgr/fs_mgr_fstab.c b/fs_mgr/fs_mgr_fstab.c
index 313bc5a..f03b2dd 100644
--- a/fs_mgr/fs_mgr_fstab.c
+++ b/fs_mgr/fs_mgr_fstab.c
@@ -32,11 +32,12 @@
int partnum;
int swap_prio;
unsigned int zram_size;
+ unsigned int file_encryption_mode;
};
struct flag_list {
const char *name;
- unsigned flag;
+ unsigned int flag;
};
static struct flag_list mount_flags[] = {
@@ -63,7 +64,7 @@
{ "check", MF_CHECK },
{ "encryptable=",MF_CRYPT },
{ "forceencrypt=",MF_FORCECRYPT },
- { "fileencryption",MF_FILEENCRYPTION },
+ { "fileencryption=",MF_FILEENCRYPTION },
{ "forcefdeorfbe=",MF_FORCEFDEORFBE },
{ "nonremovable",MF_NONREMOVABLE },
{ "voldmanaged=",MF_VOLDMANAGED},
@@ -82,6 +83,15 @@
{ 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;
@@ -148,6 +158,21 @@
* 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.
@@ -330,6 +355,7 @@
fstab->recs[cnt].partnum = flag_vals.partnum;
fstab->recs[cnt].swap_prio = flag_vals.swap_prio;
fstab->recs[cnt].zram_size = flag_vals.zram_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 */
@@ -488,6 +514,17 @@
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;
diff --git a/fs_mgr/fs_mgr_verity.cpp b/fs_mgr/fs_mgr_verity.cpp
index 767b3b3..7fe6763 100644
--- a/fs_mgr/fs_mgr_verity.cpp
+++ b/fs_mgr/fs_mgr_verity.cpp
@@ -181,7 +181,7 @@
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;
@@ -773,8 +773,9 @@
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;
@@ -802,6 +803,9 @@
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) {
@@ -814,7 +818,12 @@
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)) {
@@ -825,7 +834,9 @@
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;
diff --git a/fs_mgr/include/fs_mgr.h b/fs_mgr/include/fs_mgr.h
index c0116ef..b43847c 100644
--- a/fs_mgr/include/fs_mgr.h
+++ b/fs_mgr/include/fs_mgr.h
@@ -74,6 +74,7 @@
int partnum;
int swap_prio;
unsigned int zram_size;
+ unsigned int file_encryption_mode;
};
// Callback function for verity status
@@ -95,6 +96,7 @@
#define FS_MGR_DOMNT_FAILED (-1)
#define FS_MGR_DOMNT_BUSY (-2)
+
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);
@@ -112,6 +114,7 @@
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);
diff --git a/healthd/Android.mk b/healthd/Android.mk
index deebed5..7c5e35b 100644
--- a/healthd/Android.mk
+++ b/healthd/Android.mk
@@ -21,6 +21,36 @@
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)
LOCAL_CHARGER_NO_UI := true
@@ -32,7 +62,7 @@
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 @@
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 @@
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
diff --git a/healthd/AnimationParser.cpp b/healthd/AnimationParser.cpp
new file mode 100644
index 0000000..864038b
--- /dev/null
+++ b/healthd/AnimationParser.cpp
@@ -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
diff --git a/healthd/AnimationParser.h b/healthd/AnimationParser.h
new file mode 100644
index 0000000..bc00845
--- /dev/null
+++ b/healthd/AnimationParser.h
@@ -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
diff --git a/healthd/animation.h b/healthd/animation.h
new file mode 100644
index 0000000..562b689
--- /dev/null
+++ b/healthd/animation.h
@@ -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
diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp
index 612885b..36c4664 100644
--- a/healthd/healthd_mode_charger.cpp
+++ b/healthd/healthd_mode_charger.cpp
@@ -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 @@
#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 @@
#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 @@
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;
@@ -257,13 +271,13 @@
static int draw_text(const char *str, int x, int y)
{
- int str_len_px = gr_measure(str);
+ int str_len_px = gr_measure(gr_sys_font(), str);
if (x < 0)
x = (gr_fb_width() - str_len_px) / 2;
if (y < 0)
y = (gr_fb_height() - char_height) / 2;
- gr_text(x, y, str, 0);
+ gr_text(gr_sys_font(), x, y, str, 0);
return y + char_height;
}
@@ -273,8 +287,79 @@
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 @@
{
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_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 @@
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 @@
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);
@@ -364,7 +468,8 @@
}
gr_init();
- gr_font_size(&char_width, &char_height);
+ 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 @@
}
/* 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 @@
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 @@
/* 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 @@
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 @@
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 @@
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 @@
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;
diff --git a/healthd/tests/Android.mk b/healthd/tests/Android.mk
new file mode 100644
index 0000000..87e8862
--- /dev/null
+++ b/healthd/tests/Android.mk
@@ -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)
diff --git a/healthd/tests/AnimationParser_test.cpp b/healthd/tests/AnimationParser_test.cpp
new file mode 100644
index 0000000..2fc3185
--- /dev/null
+++ b/healthd/tests/AnimationParser_test.cpp
@@ -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);
+}
diff --git a/include/android/log.h b/include/android/log.h
index 9b26839..5673357 100644
--- a/include/android/log.h
+++ b/include/android/log.h
@@ -67,25 +67,55 @@
* NOTE: These functions MUST be implemented by /system/lib/liblog.so
*/
-#if !defined(_WIN32)
-#include <pthread.h>
-#endif
#include <stdarg.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <log/uio.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
+ * This file uses ", ## __VA_ARGS__" zero-argument token pasting to
+ * work around issues with debug-only syntax errors in assertions
+ * that are missing format strings. See commit
+ * 19299904343daf191267564fe32e6cd5c165cd42
+ */
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
+#endif
+
+#ifndef __predict_false
+#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
+#endif
+
+/*
+ * LOG_TAG is the local tag used for the following simplified
+ * logging macros. You must set this preprocessor definition,
+ * or more tenuously supply a variable definition, before using
+ * the macros.
+ */
+
+/*
+ * Normally we strip the effects of ALOGV (VERBOSE messages),
+ * LOG_FATAL and LOG_FATAL_IF (FATAL assert messages) from the
+ * release builds be defining NDEBUG. You can modify this (for
+ * example with "#define LOG_NDEBUG 0" at the top of your source
+ * file) to change that behavior.
+ */
+
+#ifndef LOG_NDEBUG
+#ifdef NDEBUG
+#define LOG_NDEBUG 1
+#else
+#define LOG_NDEBUG 0
+#endif
+#endif
+
+/*
* Android log priority values, in ascending priority order.
*/
+#ifndef __android_LogPriority_defined
+#define __android_LogPriority_defined
typedef enum android_LogPriority {
ANDROID_LOG_UNKNOWN = 0,
ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */
@@ -97,21 +127,20 @@
ANDROID_LOG_FATAL,
ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */
} android_LogPriority;
-
-/*
- * Release any logger resources (a new log write will immediately re-acquire)
- */
-void __android_log_close();
+#endif
/*
* Send a simple string to the log.
*/
-int __android_log_write(int prio, const char *tag, const char *text);
+int __android_log_write(int prio, const char* tag, const char* text);
+
+#define android_writeLog(prio, tag, text) \
+ __android_log_write(prio, tag, text)
/*
* Send a formatted string to the log, used like printf(fmt,...)
*/
-int __android_log_print(int prio, const char *tag, const char *fmt, ...)
+int __android_log_print(int prio, const char* tag, const char* fmt, ...)
#if defined(__GNUC__)
#ifdef __USE_MINGW_ANSI_STDIO
#if __USE_MINGW_ANSI_STDIO
@@ -125,19 +154,53 @@
#endif
;
+#define android_printLog(prio, tag, ...) \
+ __android_log_print(prio, tag, __VA_ARGS__)
+
+/*
+ * Log macro that allows you to specify a number for the priority.
+ */
+#ifndef LOG_PRI
+#define LOG_PRI(priority, tag, ...) \
+ android_printLog(priority, tag, __VA_ARGS__)
+#endif
+
/*
* A variant of __android_log_print() that takes a va_list to list
* additional parameters.
*/
-int __android_log_vprint(int prio, const char *tag,
- const char *fmt, va_list ap);
+int __android_log_vprint(int prio, const char* tag,
+ const char* fmt, va_list ap)
+#if defined(__GNUC__)
+#ifdef __USE_MINGW_ANSI_STDIO
+#if __USE_MINGW_ANSI_STDIO
+ __attribute__ ((format(gnu_printf, 3, 0)))
+#else
+ __attribute__ ((format(printf, 3, 0)))
+#endif
+#else
+ __attribute__ ((format(printf, 3, 0)))
+#endif
+#endif
+ ;
+
+#define android_vprintLog(prio, cond, tag, ...) \
+ __android_log_vprint(prio, tag, __VA_ARGS__)
+
+/*
+ * Log macro that allows you to pass in a varargs ("args" is a va_list).
+ */
+#ifndef LOG_PRI_VA
+#define LOG_PRI_VA(priority, tag, fmt, args) \
+ android_vprintLog(priority, NULL, tag, fmt, args)
+#endif
/*
* Log an assertion failure and abort the process to have a chance
* to inspect it if a debugger is attached. This uses the FATAL priority.
*/
-void __android_log_assert(const char *cond, const char *tag,
- const char *fmt, ...)
+void __android_log_assert(const char* cond, const char* tag,
+ const char* fmt, ...)
#if defined(__GNUC__)
__attribute__ ((__noreturn__))
#ifdef __USE_MINGW_ANSI_STDIO
@@ -152,74 +215,91 @@
#endif
;
-//
-// C/C++ logging functions. See the logging documentation for API details.
-//
-// We'd like these to be available from C code (in case we import some from
-// somewhere), so this has a C interface.
-//
-// The output will be correct when the log file is shared between multiple
-// threads and/or multiple processes so long as the operating system
-// supports O_APPEND. These calls have mutex-protected data structures
-// and so are NOT reentrant. Do not use LOG in a signal handler.
-//
+/* XXX Macros to work around syntax errors in places where format string
+ * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
+ * (happens only in debug builds).
+ */
-// This file uses ", ## __VA_ARGS__" zero-argument token pasting to
-// work around issues with debug-only syntax errors in assertions
-// that are missing format strings. See commit
-// 19299904343daf191267564fe32e6cd5c165cd42
-#if defined(__clang__)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
-#endif
+/* Returns 2nd arg. Used to substitute default value if caller's vararg list
+ * is empty.
+ */
+#define __android_second(dummy, second, ...) second
-int __android_log_bwrite(int32_t tag, const void *payload, size_t len);
-int __android_log_btwrite(int32_t tag, char type, const void *payload,
- size_t len);
-int __android_log_bswrite(int32_t tag, const char *payload);
+/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
+ * returns nothing.
+ */
+#define __android_rest(first, ...) , ## __VA_ARGS__
-// ---------------------------------------------------------------------
+#define android_printAssert(cond, tag, ...) \
+ __android_log_assert(cond, tag, \
+ __android_second(0, ## __VA_ARGS__, NULL) __android_rest(__VA_ARGS__))
/*
- * Normally we strip ALOGV (VERBOSE messages) from release builds.
- * You can modify this (for example with "#define LOG_NDEBUG 0"
- * at the top of your source file) to change that behavior.
+ * Log a fatal error. If the given condition fails, this stops program
+ * execution like a normal assertion, but also generating the given message.
+ * It is NOT stripped from release builds. Note that the condition test
+ * is -inverted- from the normal assert() semantics.
*/
-#ifndef LOG_NDEBUG
-#ifdef NDEBUG
-#define LOG_NDEBUG 1
+#ifndef LOG_ALWAYS_FATAL_IF
+#define LOG_ALWAYS_FATAL_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+#ifndef LOG_ALWAYS_FATAL
+#define LOG_ALWAYS_FATAL(...) \
+ ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
+#endif
+
+/*
+ * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
+ * are stripped out of release builds.
+ */
+
+#if LOG_NDEBUG
+
+#ifndef LOG_FATAL_IF
+#define LOG_FATAL_IF(cond, ...) ((void)0)
+#endif
+#ifndef LOG_FATAL
+#define LOG_FATAL(...) ((void)0)
+#endif
+
#else
-#define LOG_NDEBUG 0
+
+#ifndef LOG_FATAL_IF
+#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
#endif
+#ifndef LOG_FATAL
+#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
+#endif
+
#endif
/*
- * This is the local tag used for the following simplified
- * logging macros. You can change this preprocessor definition
- * before using the other macros to change the tag.
+ * Assertion that generates a log message when the assertion fails.
+ * Stripped out of release builds. Uses the current LOG_TAG.
*/
-#ifndef LOG_TAG
-#define LOG_TAG NULL
+#ifndef ALOG_ASSERT
+#define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
#endif
-// ---------------------------------------------------------------------
-
-#ifndef __predict_false
-#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
-#endif
+/* --------------------------------------------------------------------- */
/*
- * -DLINT_RLOG in sources that you want to enforce that all logging
- * goes to the radio log buffer. If any logging goes to any of the other
- * log buffers, there will be a compile or link error to highlight the
- * problem. This is not a replacement for a full audit of the code since
- * this only catches compiled code, not ifdef'd debug code. Options to
- * defining this, either temporarily to do a spot check, or permanently
- * to enforce, in all the communications trees; We have hopes to ensure
- * that by supplying just the radio log buffer that the communications
- * teams will have their one-stop shop for triaging issues.
+ * C/C++ logging functions. See the logging documentation for API details.
+ *
+ * We'd like these to be available from C code (in case we import some from
+ * somewhere), so this has a C interface.
+ *
+ * The output will be correct when the log file is shared between multiple
+ * threads and/or multiple processes so long as the operating system
+ * supports O_APPEND. These calls have mutex-protected data structures
+ * and so are NOT reentrant. Do not use LOG in a signal handler.
*/
-#ifndef LINT_RLOG
+
+/* --------------------------------------------------------------------- */
/*
* Simplified macro to send a verbose log message using the current LOG_TAG.
@@ -300,7 +380,7 @@
: (void)0 )
#endif
-// ---------------------------------------------------------------------
+/* --------------------------------------------------------------------- */
/*
* Conditional based on whether the current LOG_TAG is enabled at
@@ -346,236 +426,7 @@
#define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
#endif
-
-// ---------------------------------------------------------------------
-
-/*
- * Simplified macro to send a verbose system log message using the current LOG_TAG.
- */
-#ifndef SLOGV
-#define __SLOGV(...) \
- ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
-#if LOG_NDEBUG
-#define SLOGV(...) do { if (0) { __SLOGV(__VA_ARGS__); } } while (0)
-#else
-#define SLOGV(...) __SLOGV(__VA_ARGS__)
-#endif
-#endif
-
-#ifndef SLOGV_IF
-#if LOG_NDEBUG
-#define SLOGV_IF(cond, ...) ((void)0)
-#else
-#define SLOGV_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-#endif
-
-/*
- * Simplified macro to send a debug system log message using the current LOG_TAG.
- */
-#ifndef SLOGD
-#define SLOGD(...) \
- ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef SLOGD_IF
-#define SLOGD_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send an info system log message using the current LOG_TAG.
- */
-#ifndef SLOGI
-#define SLOGI(...) \
- ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef SLOGI_IF
-#define SLOGI_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send a warning system log message using the current LOG_TAG.
- */
-#ifndef SLOGW
-#define SLOGW(...) \
- ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef SLOGW_IF
-#define SLOGW_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send an error system log message using the current LOG_TAG.
- */
-#ifndef SLOGE
-#define SLOGE(...) \
- ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef SLOGE_IF
-#define SLOGE_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-#endif /* !LINT_RLOG */
-
-// ---------------------------------------------------------------------
-
-/*
- * Simplified macro to send a verbose radio log message using the current LOG_TAG.
- */
-#ifndef RLOGV
-#define __RLOGV(...) \
- ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
-#if LOG_NDEBUG
-#define RLOGV(...) do { if (0) { __RLOGV(__VA_ARGS__); } } while (0)
-#else
-#define RLOGV(...) __RLOGV(__VA_ARGS__)
-#endif
-#endif
-
-#ifndef RLOGV_IF
-#if LOG_NDEBUG
-#define RLOGV_IF(cond, ...) ((void)0)
-#else
-#define RLOGV_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-#endif
-
-/*
- * Simplified macro to send a debug radio log message using the current LOG_TAG.
- */
-#ifndef RLOGD
-#define RLOGD(...) \
- ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef RLOGD_IF
-#define RLOGD_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send an info radio log message using the current LOG_TAG.
- */
-#ifndef RLOGI
-#define RLOGI(...) \
- ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef RLOGI_IF
-#define RLOGI_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send a warning radio log message using the current LOG_TAG.
- */
-#ifndef RLOGW
-#define RLOGW(...) \
- ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef RLOGW_IF
-#define RLOGW_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send an error radio log message using the current LOG_TAG.
- */
-#ifndef RLOGE
-#define RLOGE(...) \
- ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef RLOGE_IF
-#define RLOGE_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-
-// ---------------------------------------------------------------------
-
-/*
- * Log a fatal error. If the given condition fails, this stops program
- * execution like a normal assertion, but also generating the given message.
- * It is NOT stripped from release builds. Note that the condition test
- * is -inverted- from the normal assert() semantics.
- */
-#ifndef LOG_ALWAYS_FATAL_IF
-#define LOG_ALWAYS_FATAL_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-#ifndef LOG_ALWAYS_FATAL
-#define LOG_ALWAYS_FATAL(...) \
- ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
-#endif
-
-/*
- * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
- * are stripped out of release builds.
- */
-#if LOG_NDEBUG
-
-#ifndef LOG_FATAL_IF
-#define LOG_FATAL_IF(cond, ...) ((void)0)
-#endif
-#ifndef LOG_FATAL
-#define LOG_FATAL(...) ((void)0)
-#endif
-
-#else
-
-#ifndef LOG_FATAL_IF
-#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
-#endif
-#ifndef LOG_FATAL
-#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
-#endif
-
-#endif
-
-/*
- * Assertion that generates a log message when the assertion fails.
- * Stripped out of release builds. Uses the current LOG_TAG.
- */
-#ifndef ALOG_ASSERT
-#define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
-//#define ALOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
-#endif
-
-// ---------------------------------------------------------------------
+/* --------------------------------------------------------------------- */
/*
* Basic log message macro.
@@ -591,22 +442,6 @@
#endif
/*
- * Log macro that allows you to specify a number for the priority.
- */
-#ifndef LOG_PRI
-#define LOG_PRI(priority, tag, ...) \
- android_printLog(priority, tag, __VA_ARGS__)
-#endif
-
-/*
- * Log macro that allows you to pass in a varargs ("args" is a va_list).
- */
-#ifndef LOG_PRI_VA
-#define LOG_PRI_VA(priority, tag, fmt, args) \
- android_vprintLog(priority, NULL, tag, fmt, args)
-#endif
-
-/*
* Conditional given a desired logging priority and tag.
*/
#ifndef IF_ALOG
@@ -614,181 +449,7 @@
if (android_testLog(ANDROID_##priority, tag))
#endif
-// ---------------------------------------------------------------------
-
-/*
- * Event logging.
- */
-
-/*
- * Event log entry types.
- */
-typedef enum {
- /* Special markers for android_log_list_element type */
- EVENT_TYPE_LIST_STOP = '\n', /* declare end of list */
- EVENT_TYPE_UNKNOWN = '?', /* protocol error */
-
- /* must match with declaration in java/android/android/util/EventLog.java */
- EVENT_TYPE_INT = 0, /* uint32_t */
- EVENT_TYPE_LONG = 1, /* uint64_t */
- EVENT_TYPE_STRING = 2,
- EVENT_TYPE_LIST = 3,
- EVENT_TYPE_FLOAT = 4,
-} AndroidEventLogType;
-#define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType)
-#define typeof_AndroidEventLogType unsigned char
-
-#ifndef LOG_EVENT_INT
-#define LOG_EVENT_INT(_tag, _value) { \
- int intBuf = _value; \
- (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
- sizeof(intBuf)); \
- }
-#endif
-#ifndef LOG_EVENT_LONG
-#define LOG_EVENT_LONG(_tag, _value) { \
- long long longBuf = _value; \
- (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
- sizeof(longBuf)); \
- }
-#endif
-#ifndef LOG_EVENT_FLOAT
-#define LOG_EVENT_FLOAT(_tag, _value) { \
- float floatBuf = _value; \
- (void) android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf, \
- sizeof(floatBuf)); \
- }
-#endif
-#ifndef LOG_EVENT_STRING
-#define LOG_EVENT_STRING(_tag, _value) \
- (void) __android_log_bswrite(_tag, _value);
-#endif
-
-typedef enum log_id {
- LOG_ID_MIN = 0,
-
-#ifndef LINT_RLOG
- LOG_ID_MAIN = 0,
-#endif
- LOG_ID_RADIO = 1,
-#ifndef LINT_RLOG
- LOG_ID_EVENTS = 2,
- LOG_ID_SYSTEM = 3,
- LOG_ID_CRASH = 4,
- LOG_ID_SECURITY = 5,
- LOG_ID_KERNEL = 6, /* place last, third-parties can not use it */
-#endif
-
- LOG_ID_MAX
-} log_id_t;
-#define sizeof_log_id_t sizeof(typeof_log_id_t)
-#define typeof_log_id_t unsigned char
-
-/* For manipulating lists of events. */
-
-#define ANDROID_MAX_LIST_NEST_DEPTH 8
-
-/*
- * The opaque context used to manipulate lists of events.
- */
-typedef struct android_log_context_internal *android_log_context;
-
-/*
- * Elements returned when reading a list of events.
- */
-typedef struct {
- AndroidEventLogType type;
- uint16_t complete;
- uint16_t len;
- union {
- int32_t int32;
- int64_t int64;
- char *string;
- float float32;
- } data;
-} android_log_list_element;
-
-/*
- * Creates a context associated with an event tag to write elements to
- * the list of events.
- */
-android_log_context create_android_logger(uint32_t tag);
-
-/* All lists must be braced by a begin and end call */
-/*
- * NB: If the first level braces are missing when specifying multiple
- * elements, we will manufacturer a list to embrace it for your API
- * convenience. For a single element, it will remain solitary.
- */
-int android_log_write_list_begin(android_log_context ctx);
-int android_log_write_list_end(android_log_context ctx);
-
-int android_log_write_int32(android_log_context ctx, int32_t value);
-int android_log_write_int64(android_log_context ctx, int64_t value);
-int android_log_write_string8(android_log_context ctx, const char *value);
-int android_log_write_string8_len(android_log_context ctx,
- const char *value, size_t maxlen);
-int android_log_write_float32(android_log_context ctx, float value);
-
-/* Submit the composed list context to the specified logger id */
-/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */
-int android_log_write_list(android_log_context ctx, log_id_t id);
-
-/*
- * Creates a context from a raw buffer representing a list of events to be read.
- */
-android_log_context create_android_log_parser(const char *msg, size_t len);
-
-android_log_list_element android_log_read_next(android_log_context ctx);
-android_log_list_element android_log_peek_next(android_log_context ctx);
-
-/* Finished with reader or writer context */
-int android_log_destroy(android_log_context *ctx);
-
-/*
- * ===========================================================================
- *
- * The stuff in the rest of this file should not be used directly.
- */
-
-#define android_printLog(prio, tag, ...) \
- __android_log_print(prio, tag, __VA_ARGS__)
-
-#define android_vprintLog(prio, cond, tag, ...) \
- __android_log_vprint(prio, tag, __VA_ARGS__)
-
-/* XXX Macros to work around syntax errors in places where format string
- * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
- * (happens only in debug builds).
- */
-
-/* Returns 2nd arg. Used to substitute default value if caller's vararg list
- * is empty.
- */
-#define __android_second(dummy, second, ...) second
-
-/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
- * returns nothing.
- */
-#define __android_rest(first, ...) , ## __VA_ARGS__
-
-#define android_printAssert(cond, tag, ...) \
- __android_log_assert(cond, tag, \
- __android_second(0, ## __VA_ARGS__, NULL) __android_rest(__VA_ARGS__))
-
-#define android_writeLog(prio, tag, text) \
- __android_log_write(prio, tag, text)
-
-#define android_bWriteLog(tag, payload, len) \
- __android_log_bwrite(tag, payload, len)
-#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.
@@ -798,6 +459,35 @@
* IF_ALOG as a convenient means to reimplement their policy
* over Android.
*/
+
+#ifndef __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE
+#ifndef __ANDROID_API__
+#define __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE 2
+#elif __ANDROID_API__ > 24 /* > Nougat */
+#define __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE 2
+#elif __ANDROID_API__ > 22 /* > Lollipop */
+#define __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE 1
+#else
+#define __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE 0
+#endif
+#endif
+
+#if __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE
+
+/*
+ * Use the per-tag properties "log.tag.<tagname>" to generate a runtime
+ * result of non-zero to expose a log. prio is ANDROID_LOG_VERBOSE to
+ * ANDROID_LOG_FATAL. default_prio if no property. Undefined behavior if
+ * any other value.
+ */
+int __android_log_is_loggable(int prio, const char* tag, int default_prio);
+
+#if __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE > 1
+#include <sys/types.h>
+
+int __android_log_is_loggable_len(int prio, const char* tag, size_t len,
+ int default_prio);
+
#if LOG_NDEBUG /* Production */
#define android_testLog(prio, tag) \
(__android_log_is_loggable_len(prio, tag, (tag && *tag) ? strlen(tag) : 0, \
@@ -808,27 +498,23 @@
ANDROID_LOG_VERBOSE) != 0)
#endif
-/*
- * Use the per-tag properties "log.tag.<tagname>" to generate a runtime
- * result of non-zero to expose a log. prio is ANDROID_LOG_VERBOSE to
- * ANDROID_LOG_FATAL. default_prio if no property. Undefined behavior if
- * any other value.
- */
-int __android_log_is_loggable(int prio, const char *tag, int default_prio);
-int __android_log_is_loggable_len(int prio, const char *tag, size_t len, int default_prio);
+#else
-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.
- */
-int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
-int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
-#if defined(__GNUC__)
- __attribute__((__format__(printf, 4, 5)))
+#if LOG_NDEBUG /* Production */
+#define android_testLog(prio, tag) \
+ (__android_log_is_loggable(prio, tag, ANDROID_LOG_DEBUG) != 0)
+#else
+#define android_testLog(prio, tag) \
+ (__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE) != 0)
#endif
- ;
+
+#endif
+
+#else /* __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE */
+
+#define android_testLog(prio, tag) (1)
+
+#endif /* !__ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE */
#if defined(__clang__)
#pragma clang diagnostic pop
diff --git a/include/cutils/log.h b/include/cutils/log.h
index ffb8268..0e0248e 100644
--- a/include/cutils/log.h
+++ b/include/cutils/log.h
@@ -1 +1 @@
-#include <android/log.h>
+#include <log/log.h>
diff --git a/include/cutils/trace.h b/include/cutils/trace.h
index dc3833f..0f00417 100644
--- a/include/cutils/trace.h
+++ b/include/cutils/trace.h
@@ -70,7 +70,8 @@
#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)
diff --git a/include/log/log.h b/include/log/log.h
index ffb8268..4777ae5 100644
--- a/include/log/log.h
+++ b/include/log/log.h
@@ -1 +1,465 @@
+/*
+ * Copyright (C) 2005-2014 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 _LIBS_LOG_LOG_H
+#define _LIBS_LOG_LOG_H
+
+/* Too many in the ecosystem assume these are included */
+#if !defined(_WIN32)
+#include <pthread.h>
+#endif
+#include <stdint.h> /* uint16_t, int32_t */
+#include <stdio.h>
+#include <sys/types.h>
+#include <time.h> /* clock_gettime */
+#include <unistd.h>
+
+#include <log/uio.h> /* helper to define iovec for portability */
+
#include <android/log.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * LOG_TAG is the local tag used for the following simplified
+ * logging macros. You can change this preprocessor definition
+ * before using the other macros to change the tag.
+ */
+
+#ifndef LOG_TAG
+#define LOG_TAG NULL
+#endif
+
+/* --------------------------------------------------------------------- */
+
+/*
+ * This file uses ", ## __VA_ARGS__" zero-argument token pasting to
+ * work around issues with debug-only syntax errors in assertions
+ * that are missing format strings. See commit
+ * 19299904343daf191267564fe32e6cd5c165cd42
+ */
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
+#endif
+
+/*
+ * Send a simple string to the log.
+ */
+int __android_log_buf_write(int bufID, int prio, const char* tag, const char* text);
+int __android_log_buf_print(int bufID, int prio, const char* tag, const char* fmt, ...)
+#if defined(__GNUC__)
+ __attribute__((__format__(printf, 4, 5)))
+#endif
+ ;
+
+/*
+ * Simplified macro to send a verbose system log message using current LOG_TAG.
+ */
+#ifndef SLOGV
+#define __SLOGV(...) \
+ ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
+#if LOG_NDEBUG
+#define SLOGV(...) do { if (0) { __SLOGV(__VA_ARGS__); } } while (0)
+#else
+#define SLOGV(...) __SLOGV(__VA_ARGS__)
+#endif
+#endif
+
+#ifndef SLOGV_IF
+#if LOG_NDEBUG
+#define SLOGV_IF(cond, ...) ((void)0)
+#else
+#define SLOGV_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+#endif
+
+/*
+ * Simplified macro to send a debug system log message using current LOG_TAG.
+ */
+#ifndef SLOGD
+#define SLOGD(...) \
+ ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef SLOGD_IF
+#define SLOGD_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send an info system log message using current LOG_TAG.
+ */
+#ifndef SLOGI
+#define SLOGI(...) \
+ ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef SLOGI_IF
+#define SLOGI_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send a warning system log message using current LOG_TAG.
+ */
+#ifndef SLOGW
+#define SLOGW(...) \
+ ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef SLOGW_IF
+#define SLOGW_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send an error system log message using current LOG_TAG.
+ */
+#ifndef SLOGE
+#define SLOGE(...) \
+ ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef SLOGE_IF
+#define SLOGE_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/* --------------------------------------------------------------------- */
+
+/*
+ * Simplified macro to send a verbose radio log message using current LOG_TAG.
+ */
+#ifndef RLOGV
+#define __RLOGV(...) \
+ ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
+#if LOG_NDEBUG
+#define RLOGV(...) do { if (0) { __RLOGV(__VA_ARGS__); } } while (0)
+#else
+#define RLOGV(...) __RLOGV(__VA_ARGS__)
+#endif
+#endif
+
+#ifndef RLOGV_IF
+#if LOG_NDEBUG
+#define RLOGV_IF(cond, ...) ((void)0)
+#else
+#define RLOGV_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+#endif
+
+/*
+ * Simplified macro to send a debug radio log message using current LOG_TAG.
+ */
+#ifndef RLOGD
+#define RLOGD(...) \
+ ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef RLOGD_IF
+#define RLOGD_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send an info radio log message using current LOG_TAG.
+ */
+#ifndef RLOGI
+#define RLOGI(...) \
+ ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef RLOGI_IF
+#define RLOGI_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send a warning radio log message using current LOG_TAG.
+ */
+#ifndef RLOGW
+#define RLOGW(...) \
+ ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef RLOGW_IF
+#define RLOGW_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send an error radio log message using current LOG_TAG.
+ */
+#ifndef RLOGE
+#define RLOGE(...) \
+ ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef RLOGE_IF
+#define RLOGE_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/* --------------------------------------------------------------------- */
+
+/*
+ * Event logging.
+ */
+
+/*
+ * The following should not be used directly.
+ */
+
+int __android_log_bwrite(int32_t tag, const void* payload, size_t len);
+int __android_log_btwrite(int32_t tag, char type, const void* payload,
+ size_t len);
+int __android_log_bswrite(int32_t tag, const char* payload);
+
+#define android_bWriteLog(tag, payload, len) \
+ __android_log_bwrite(tag, payload, len)
+#define android_btWriteLog(tag, type, payload, len) \
+ __android_log_btwrite(tag, type, payload, len)
+
+/*
+ * Event log entry types.
+ */
+#ifndef __AndroidEventLogType_defined
+#define __AndroidEventLogType_defined
+typedef enum {
+ /* Special markers for android_log_list_element type */
+ EVENT_TYPE_LIST_STOP = '\n', /* declare end of list */
+ EVENT_TYPE_UNKNOWN = '?', /* protocol error */
+
+ /* must match with declaration in java/android/android/util/EventLog.java */
+ EVENT_TYPE_INT = 0, /* int32_t */
+ EVENT_TYPE_LONG = 1, /* int64_t */
+ EVENT_TYPE_STRING = 2,
+ EVENT_TYPE_LIST = 3,
+ EVENT_TYPE_FLOAT = 4,
+} AndroidEventLogType;
+#endif
+#define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType)
+#define typeof_AndroidEventLogType unsigned char
+
+#ifndef LOG_EVENT_INT
+#define LOG_EVENT_INT(_tag, _value) { \
+ int intBuf = _value; \
+ (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
+ sizeof(intBuf)); \
+ }
+#endif
+#ifndef LOG_EVENT_LONG
+#define LOG_EVENT_LONG(_tag, _value) { \
+ long long longBuf = _value; \
+ (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
+ sizeof(longBuf)); \
+ }
+#endif
+#ifndef LOG_EVENT_FLOAT
+#define LOG_EVENT_FLOAT(_tag, _value) { \
+ float floatBuf = _value; \
+ (void) android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf, \
+ sizeof(floatBuf)); \
+ }
+#endif
+#ifndef LOG_EVENT_STRING
+#define LOG_EVENT_STRING(_tag, _value) \
+ (void) __android_log_bswrite(_tag, _value);
+#endif
+
+#ifndef log_id_t_defined
+#define log_id_t_defined
+typedef enum log_id {
+ LOG_ID_MIN = 0,
+
+ LOG_ID_MAIN = 0,
+ LOG_ID_RADIO = 1,
+ LOG_ID_EVENTS = 2,
+ LOG_ID_SYSTEM = 3,
+ LOG_ID_CRASH = 4,
+ LOG_ID_SECURITY = 5,
+ LOG_ID_KERNEL = 6, /* place last, third-parties can not use it */
+
+ LOG_ID_MAX
+} log_id_t;
+#endif
+#define sizeof_log_id_t sizeof(typeof_log_id_t)
+#define typeof_log_id_t unsigned char
+
+/* --------------------------------------------------------------------- */
+
+#ifndef __ANDROID_USE_LIBLOG_EVENT_INTERFACE
+#ifndef __ANDROID_API__
+#define __ANDROID_USE_LIBLOG_EVENT_INTERFACE 1
+#elif __ANDROID_API__ > 23 /* > Marshmallow */
+#define __ANDROID_USE_LIBLOG_EVENT_INTERFACE 1
+#else
+#define __ANDROID_USE_LIBLOG_EVENT_INTERFACE 0
+#endif
+#endif
+
+#if __ANDROID_USE_LIBLOG_EVENT_INTERFACE
+
+/* For manipulating lists of events. */
+
+#define ANDROID_MAX_LIST_NEST_DEPTH 8
+
+/*
+ * The opaque context used to manipulate lists of events.
+ */
+#ifndef __android_log_context_defined
+#define __android_log_context_defined
+typedef struct android_log_context_internal* android_log_context;
+#endif
+
+/*
+ * Elements returned when reading a list of events.
+ */
+#ifndef __android_log_list_element_defined
+#define __android_log_list_element_defined
+typedef struct {
+ AndroidEventLogType type;
+ uint16_t complete;
+ uint16_t len;
+ union {
+ int32_t int32;
+ int64_t int64;
+ char* string;
+ float float32;
+ } data;
+} android_log_list_element;
+#endif
+
+/*
+ * Creates a context associated with an event tag to write elements to
+ * the list of events.
+ */
+android_log_context create_android_logger(uint32_t tag);
+
+/* All lists must be braced by a begin and end call */
+/*
+ * NB: If the first level braces are missing when specifying multiple
+ * elements, we will manufacturer a list to embrace it for your API
+ * convenience. For a single element, it will remain solitary.
+ */
+int android_log_write_list_begin(android_log_context ctx);
+int android_log_write_list_end(android_log_context ctx);
+
+int android_log_write_int32(android_log_context ctx, int32_t value);
+int android_log_write_int64(android_log_context ctx, int64_t value);
+int android_log_write_string8(android_log_context ctx, const char* value);
+int android_log_write_string8_len(android_log_context ctx,
+ const char* value, size_t maxlen);
+int android_log_write_float32(android_log_context ctx, float value);
+
+/* Submit the composed list context to the specified logger id */
+/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */
+int android_log_write_list(android_log_context ctx, log_id_t id);
+
+/*
+ * Creates a context from a raw buffer representing a list of events to be read.
+ */
+android_log_context create_android_log_parser(const char* msg, size_t len);
+
+android_log_list_element android_log_read_next(android_log_context ctx);
+android_log_list_element android_log_peek_next(android_log_context ctx);
+
+/* Finished with reader or writer context */
+int android_log_destroy(android_log_context* ctx);
+
+#endif /* __ANDROID_USE_LIBLOG_EVENT_INTERFACE */
+
+/* --------------------------------------------------------------------- */
+
+#ifndef _ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE
+#ifndef __ANDROID_API__
+#define __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE 1
+#elif __ANDROID_API__ > 22 /* > Lollipop */
+#define __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE 1
+#else
+#define __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE 0
+#endif
+#endif
+
+#if __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE
+
+#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)
+
+int __android_log_error_write(int tag, const char* subTag, int32_t uid,
+ const char* data, uint32_t dataLen);
+
+#endif /* __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE */
+
+/* --------------------------------------------------------------------- */
+
+#ifndef __ANDROID_USE_LIBLOG_CLOSE_INTERFACE
+#ifndef __ANDROID_API__
+#define __ANDROID_USE_LIBLOG_CLOSE_INTERFACE 1
+#elif __ANDROID_API__ > 18 /* > JellyBean */
+#define __ANDROID_USE_LIBLOG_CLOSE_INTERFACE 1
+#else
+#define __ANDROID_USE_LIBLOG_CLOSE_INTERFACE 0
+#endif
+#endif
+
+#if __ANDROID_USE_LIBLOG_CLOSE_INTERFACE
+/*
+ * Release any logger resources (a new log write will immediately re-acquire)
+ *
+ * May be used to clean up File descriptors after a Fork, the resources are
+ * all O_CLOEXEC so wil self clean on exec().
+ */
+void __android_log_close();
+#endif
+
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _LIBS_LOG_LOG_H */
diff --git a/include/log/logger.h b/include/log/logger.h
index 46587fb..65b38de 100644
--- a/include/log/logger.h
+++ b/include/log/logger.h
@@ -17,7 +17,7 @@
#include <string>
#endif
-#include <android/log.h>
+#include <log/log.h>
#ifdef __cplusplus
extern "C" {
diff --git a/include/system/window.h b/include/system/window.h
index 49ab4dc..f439705 100644
--- a/include/system/window.h
+++ b/include/system/window.h
@@ -287,6 +287,16 @@
* 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 @@
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 @@
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 */
diff --git a/include/sysutils/FrameworkListener.h b/include/sysutils/FrameworkListener.h
index 18049cd..2137069 100644
--- a/include/sysutils/FrameworkListener.h
+++ b/include/sysutils/FrameworkListener.h
@@ -32,6 +32,7 @@
int mCommandCount;
bool mWithSeq;
FrameworkCommandCollection *mCommands;
+ bool mSkipToNextNullByte;
public:
FrameworkListener(const char *socketName);
diff --git a/include/utils/Log.h b/include/utils/Log.h
index 6ef3fa3..5276a49 100644
--- a/include/utils/Log.h
+++ b/include/utils/Log.h
@@ -30,7 +30,7 @@
#include <sys/types.h>
-#include <android/log.h>
+#include <log/log.h>
#ifdef __cplusplus
diff --git a/include/utils/Mutex.h b/include/utils/Mutex.h
index 8c4683c..d106185 100644
--- a/include/utils/Mutex.h
+++ b/include/utils/Mutex.h
@@ -64,13 +64,18 @@
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 @@
}
#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),
diff --git a/include/utils/SortedVector.h b/include/utils/SortedVector.h
index 9f2ec02..86f3496 100644
--- a/include/utils/SortedVector.h
+++ b/include/utils/SortedVector.h
@@ -21,7 +21,7 @@
#include <stdint.h>
#include <sys/types.h>
-#include <android/log.h>
+#include <log/log.h>
#include <utils/TypeHelpers.h>
#include <utils/Vector.h>
#include <utils/VectorImpl.h>
diff --git a/include/utils/Vector.h b/include/utils/Vector.h
index 6c1931e..28a77b8 100644
--- a/include/utils/Vector.h
+++ b/include/utils/Vector.h
@@ -22,7 +22,7 @@
#include <new>
-#include <android/log.h>
+#include <log/log.h>
#include <utils/TypeHelpers.h>
#include <utils/VectorImpl.h>
diff --git a/init/builtins.cpp b/init/builtins.cpp
index f37ccc2..0206644 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -346,6 +346,11 @@
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;
@@ -907,8 +912,12 @@
int ret = 0;
for (auto it = std::next(args.begin()); it != args.end(); ++it) {
- if (restorecon_recursive(it->c_str()) < 0)
+ /* The contents of CE paths are encrypted on FBE devices until user
+ * credentials are presented (filenames inside are mangled), so we need
+ * to delay restorecon of those until vold explicitly requests it. */
+ if (restorecon_recursive_skipce(it->c_str()) < 0) {
ret = -errno;
+ }
}
return ret;
}
@@ -1010,6 +1019,7 @@
{"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}},
diff --git a/init/keychords.cpp b/init/keychords.cpp
index 1cfdd80..3dbb2f0 100644
--- a/init/keychords.cpp
+++ b/init/keychords.cpp
@@ -78,11 +78,13 @@
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";
}
}
diff --git a/init/readme.txt b/init/readme.txt
index 26225b2..77e5de2 100644
--- a/init/readme.txt
+++ b/init/readme.txt
@@ -382,6 +382,9 @@
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.
diff --git a/init/service.cpp b/init/service.cpp
index 22fb013..685befd 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -996,7 +996,7 @@
}
bool ServiceParser::IsValidName(const std::string& name) const {
- if (name.size() > 16) {
+ if (name.size() > PROP_NAME_MAX - sizeof("init.svc.")) {
return false;
}
for (const auto& c : name) {
diff --git a/init/util.cpp b/init/util.cpp
index e451edd..660a66f 100644
--- a/init/util.cpp
+++ b/init/util.cpp
@@ -328,6 +328,12 @@
return selinux_android_restorecon(pathname, SELINUX_ANDROID_RESTORECON_RECURSE);
}
+int restorecon_recursive_skipce(const char* pathname)
+{
+ return selinux_android_restorecon(pathname,
+ SELINUX_ANDROID_RESTORECON_RECURSE | SELINUX_ANDROID_RESTORECON_SKIPCE);
+}
+
/*
* Writes hex_len hex characters (1/2 byte) to hex from bytes.
*/
diff --git a/init/util.h b/init/util.h
index 5fcbdf0..b83b9a0 100644
--- a/init/util.h
+++ b/init/util.h
@@ -57,6 +57,7 @@
int make_dir(const char *path, mode_t mode);
int restorecon(const char *pathname);
int restorecon_recursive(const char *pathname);
+int restorecon_recursive_skipce(const char *pathname);
std::string bytes_to_hex(const uint8_t *bytes, size_t bytes_len);
bool is_dir(const char* pathname);
bool expand_props(const std::string& src, std::string* dst);
diff --git a/libbacktrace/Android.bp b/libbacktrace/Android.bp
index 85b5597..5c72234 100644
--- a/libbacktrace/Android.bp
+++ b/libbacktrace/Android.bp
@@ -92,6 +92,7 @@
],
static_libs: ["libcutils"],
+ host_ldlibs: ["-lrt"],
},
android: {
srcs: libbacktrace_sources,
diff --git a/libbacktrace/BacktraceMap.cpp b/libbacktrace/BacktraceMap.cpp
index 19ea1e3..4496375 100644
--- a/libbacktrace/BacktraceMap.cpp
+++ b/libbacktrace/BacktraceMap.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "backtrace-map"
+
#include <ctype.h>
#include <inttypes.h>
#include <stdint.h>
diff --git a/libcutils/dlmalloc_stubs.c b/libcutils/dlmalloc_stubs.c
index 86fc880..6c07bed 100644
--- a/libcutils/dlmalloc_stubs.c
+++ b/libcutils/dlmalloc_stubs.c
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "dlmalloc-stubs"
+
#include "android/log.h"
#define UNUSED __attribute__((__unused__))
diff --git a/libcutils/fs.c b/libcutils/fs.c
index 1622ed9..c49233e 100644
--- a/libcutils/fs.c
+++ b/libcutils/fs.c
@@ -25,6 +25,7 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
diff --git a/libcutils/fs_config.c b/libcutils/fs_config.c
index 3116236..4e62d74 100644
--- a/libcutils/fs_config.c
+++ b/libcutils/fs_config.c
@@ -91,6 +91,7 @@
{ 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" },
@@ -142,6 +143,9 @@
{ 00750, AID_ROOT, AID_SHELL, CAP_MASK_LONG(CAP_SETUID) | CAP_MASK_LONG(CAP_SETGID), "system/bin/run-as" },
{ 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), "system/bin/hostapd" },
diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c
index 2cc72a6..5c5f3a5 100644
--- a/libcutils/sched_policy.c
+++ b/libcutils/sched_policy.c
@@ -23,7 +23,7 @@
#include <string.h>
#include <unistd.h>
-#include <android/log.h>
+#include <log/log.h>
#include <cutils/sched_policy.h>
#define UNUSED __attribute__((__unused__))
@@ -64,9 +64,12 @@
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 @@
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 @@
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 @@
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 @@
#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 @@
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;
diff --git a/libcutils/sockets_unix.cpp b/libcutils/sockets_unix.cpp
index e51a1c7..3545403 100644
--- a/libcutils/sockets_unix.cpp
+++ b/libcutils/sockets_unix.cpp
@@ -14,7 +14,11 @@
* limitations under the License.
*/
+#define LOG_TAG "socket-unix"
+
#include <sys/uio.h>
+#include <time.h>
+#include <unistd.h>
#include <android/log.h>
#include <cutils/sockets.h>
diff --git a/libion/ion.c b/libion/ion.c
index 424776a..2db8845 100644
--- a/libion/ion.c
+++ b/libion/ion.c
@@ -27,13 +27,14 @@
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/types.h>
+#include <unistd.h>
#include <android/log.h>
#include <ion/ion.h>
int ion_open()
{
- int fd = open("/dev/ion", O_RDWR);
+ int fd = open("/dev/ion", O_RDONLY);
if (fd < 0)
ALOGE("open /dev/ion failed!\n");
return fd;
diff --git a/libion/tests/device_test.cpp b/libion/tests/device_test.cpp
index 0be52bf..eb3f7b6 100644
--- a/libion/tests/device_test.cpp
+++ b/libion/tests/device_test.cpp
@@ -46,7 +46,7 @@
void Device::SetUp()
{
IonAllHeapsTest::SetUp();
- m_deviceFd = open("/dev/ion-test", O_RDWR);
+ m_deviceFd = open("/dev/ion-test", O_RDONLY);
ASSERT_GE(m_deviceFd, 0);
}
diff --git a/liblog/Android.bp b/liblog/Android.bp
index bbaced5..16aa4fa 100644
--- a/liblog/Android.bp
+++ b/liblog/Android.bp
@@ -104,6 +104,7 @@
from: "legacy-ndk-includes",
to: "android",
srcs: ["legacy-ndk-includes/log.h"],
+ license: "NOTICE",
}
ndk_library {
diff --git a/liblog/README b/liblog/README
index eefa80f..dd37832 100644
--- a/liblog/README
+++ b/liblog/README
@@ -1,12 +1,18 @@
-LIBLOG(3) Android NDK Programming Manual LIBLOG(3)
+LIBLOG(3) Android Internal NDK Programming Manual LIBLOG(3)
NAME
- liblog - Android NDK logger interfaces
+ liblog - Android Internal NDK logger interfaces
SYNOPSIS
- #include <android/log.h>
+ /*
+ * Please limit to 24 characters for runtime is loggable,
+ * 16 characters for persist is loggable, and logcat pretty
+ * alignment with limit of 7 characters.
+ */
+ #define LOG_TAG "yourtag"
+ #include <log/log.h>
ALOG(android_priority, tag, format, ...)
IF_ALOG(android_priority, tag)
@@ -66,21 +72,44 @@
int android_logger_get_log_readable_size(struct logger *logger)
int android_logger_get_log_version(struct logger *logger)
- struct logger_list *android_logger_list_alloc(int mode, unsigned int
- tail, pid_t pid)
- struct logger *android_logger_open(struct logger_list *logger_list,
- log_id_t id)
- struct logger_list *android_logger_list_open(log_id_t id, int mode,
- unsigned int tail, pid_t pid)
-
- int android_logger_list_read(struct logger_list *logger_list, struct
- log_msg *log_msg
-
+ struct logger_list *android_logger_list_alloc(int mode,
+ unsigned int tail,
+ pid_t pid)
+ struct logger *android_logger_open(struct logger_list *logger_list,
+ log_id_t id)
+ struct logger_list *android_logger_list_open(log_id_t id, int mode,
+ unsigned int tail,
+ pid_t pid)
+ int android_logger_list_read(struct logger_list *logger_list,
+ struct log_msg *log_msg)
void android_logger_list_free(struct logger_list *logger_list)
log_id_t android_name_to_log_id(const char *logName)
const char *android_log_id_to_name(log_id_t log_id)
+ android_log_context create_android_logger(uint32_t tag)
+
+ int android_log_write_list_begin(android_log_context ctx)
+ int android_log_write_list_end(android_log_context ctx)
+
+ int android_log_write_int32(android_log_context ctx, int32_t value)
+ int android_log_write_int64(android_log_context ctx, int64_t value)
+ int android_log_write_string8(android_log_context ctx,
+ const char *value)
+ int android_log_write_string8_len(android_log_context ctx,
+ const char *value, size_t maxlen)
+ int android_log_write_float32(android_log_context ctx, float value)
+
+ int android_log_write_list(android_log_context ctx,
+ log_id_t id = LOG_ID_EVENTS)
+
+ android_log_context create_android_log_parser(const char *msg,
+ size_t len)
+ android_log_list_element android_log_read_next(android_log_context ctx)
+ android_log_list_element android_log_peek_next(android_log_context ctx)
+
+ int android_log_destroy(android_log_context *ctx)
+
Link with -llog
DESCRIPTION
@@ -163,8 +192,8 @@
library retries on EINTR, -EINTR should never be returned.
SEE ALSO
- syslogd(8)
+ syslogd(8), klogd, auditd(8)
- 24 Jan 2014 LIBLOG(3)
+ 17 Oct 2016 LIBLOG(3)
diff --git a/liblog/event_tag_map.c b/liblog/event_tag_map.c
index 6705fb2..0e5a281 100644
--- a/liblog/event_tag_map.c
+++ b/liblog/event_tag_map.c
@@ -19,6 +19,7 @@
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
diff --git a/liblog/fake_log_device.c b/liblog/fake_log_device.c
index 5f7f05b..4939221 100644
--- a/liblog/fake_log_device.c
+++ b/liblog/fake_log_device.c
@@ -25,10 +25,14 @@
#if !defined(_WIN32)
#include <pthread.h>
#endif
+#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <android/log.h>
+#include <log/uio.h>
#include "fake_log_device.h"
#include "log_portability.h"
diff --git a/liblog/fake_writer.c b/liblog/fake_writer.c
index 47935e3..dab8bc5 100644
--- a/liblog/fake_writer.c
+++ b/liblog/fake_writer.c
@@ -18,7 +18,7 @@
#include <fcntl.h>
#include <unistd.h>
-#include <android/log.h>
+#include <log/log.h>
#include "config_write.h"
#include "fake_log_device.h"
diff --git a/liblog/liblog.map.txt b/liblog/liblog.map.txt
index 5f19cc1..599dc90 100644
--- a/liblog/liblog.map.txt
+++ b/liblog/liblog.map.txt
@@ -1,14 +1,19 @@
LIBLOG {
global:
__android_log_assert;
- __android_log_btwrite;
- __android_log_buf_print; # introduced-arm=21 introduced-arm64=21 introduced-mips=9 introduced-mips64=21 introduced-x86=9 introduced-x86_64=21
- __android_log_buf_write; # introduced-arm=21 introduced-arm64=21 introduced-mips=9 introduced-mips64=21 introduced-x86=9 introduced-x86_64=21
- __android_log_bwrite;
- __android_log_dev_available;
__android_log_print;
__android_log_vprint;
__android_log_write;
local:
*;
};
+
+LIBLOG_M {
+ global:
+ __android_log_is_loggable;
+};
+
+LIBLOG_O {
+ global:
+ __android_log_is_loggable_len;
+};
diff --git a/liblog/log_event_write.c b/liblog/log_event_write.c
index 8c8a9a1..7262fc5 100644
--- a/liblog/log_event_write.c
+++ b/liblog/log_event_write.c
@@ -15,8 +15,9 @@
*/
#include <errno.h>
+#include <stdint.h>
-#include <android/log.h>
+#include <log/log.h>
#include "log_portability.h"
diff --git a/liblog/logd_reader.c b/liblog/logd_reader.c
index 71ff075..99d7fea 100644
--- a/liblog/logd_reader.c
+++ b/liblog/logd_reader.c
@@ -31,9 +31,7 @@
#include <time.h>
#include <unistd.h>
-#include <android/log.h>
#include <cutils/sockets.h>
-#include <log/logger.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
diff --git a/liblog/logd_writer.c b/liblog/logd_writer.c
index 2913507..8fdfb92 100644
--- a/liblog/logd_writer.c
+++ b/liblog/logd_writer.c
@@ -32,7 +32,6 @@
#include <unistd.h>
#include <cutils/sockets.h>
-#include <log/logger.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
diff --git a/liblog/logger.h b/liblog/logger.h
index d2aebcb..fb47786 100644
--- a/liblog/logger.h
+++ b/liblog/logger.h
@@ -19,11 +19,11 @@
#include <stdatomic.h>
#include <stdbool.h>
-#include <log/uio.h>
#include <android/log.h>
#include <cutils/list.h>
#include <log/logger.h>
+#include <log/uio.h>
#include "log_portability.h"
diff --git a/liblog/logger_read.c b/liblog/logger_read.c
index d979e22..c3cb7ad 100644
--- a/liblog/logger_read.c
+++ b/liblog/logger_read.c
@@ -25,7 +25,6 @@
#include <android/log.h>
#include <cutils/list.h>
-#include <log/logger.h>
#include <private/android_filesystem_config.h>
#include "config_read.h"
diff --git a/liblog/logger_write.c b/liblog/logger_write.c
index 1e56b27..c481e36 100644
--- a/liblog/logger_write.c
+++ b/liblog/logger_write.c
@@ -24,9 +24,7 @@
#include <android/set_abort_message.h>
#endif
-#include <android/log.h>
#include <log/event_tag_map.h>
-#include <log/logger.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
diff --git a/liblog/pmsg_writer.c b/liblog/pmsg_writer.c
index b3c4a1a..c1c068e 100644
--- a/liblog/pmsg_writer.c
+++ b/liblog/pmsg_writer.c
@@ -26,9 +26,6 @@
#include <sys/types.h>
#include <time.h>
-#include <android/log.h>
-#include <log/logger.h>
-
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
diff --git a/liblog/tests/liblog_benchmark.cpp b/liblog/tests/liblog_benchmark.cpp
index cd012ce..44045c3 100644
--- a/liblog/tests/liblog_benchmark.cpp
+++ b/liblog/tests/liblog_benchmark.cpp
@@ -20,9 +20,7 @@
#include <sys/types.h>
#include <unistd.h>
-#include <android/log.h>
#include <cutils/sockets.h>
-#include <log/logger.h>
#include <private/android_logger.h>
#include "benchmark.h"
diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp
index 7db048d..fd38849 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -27,12 +27,10 @@
#include <string>
-#include <android/log.h>
#include <android-base/file.h>
#include <android-base/stringprintf.h>
#include <cutils/properties.h>
#include <gtest/gtest.h>
-#include <log/logger.h>
#include <log/logprint.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
diff --git a/libnativebridge/native_bridge.cc b/libnativebridge/native_bridge.cc
index 9f9c83f..32b2d27 100644
--- a/libnativebridge/native_bridge.cc
+++ b/libnativebridge/native_bridge.cc
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "nativebridge"
+
#include "nativebridge/native_bridge.h"
#include <dlfcn.h>
@@ -22,6 +24,7 @@
#include <stdio.h>
#include <sys/mount.h>
#include <sys/stat.h>
+#include <unistd.h>
#include <cstring>
diff --git a/libpixelflinger/codeflinger/ARMAssemblerInterface.cpp b/libpixelflinger/codeflinger/ARMAssemblerInterface.cpp
index 67eba80..e212f1b 100644
--- a/libpixelflinger/codeflinger/ARMAssemblerInterface.cpp
+++ b/libpixelflinger/codeflinger/ARMAssemblerInterface.cpp
@@ -14,6 +14,7 @@
** See the License for the specific language governing permissions and
** limitations under the License.
*/
+#define LOG_TAG "pixelflinger-code"
#include <errno.h>
#include <stdint.h>
diff --git a/libpixelflinger/codeflinger/blending.cpp b/libpixelflinger/codeflinger/blending.cpp
index d4aa475..092f140 100644
--- a/libpixelflinger/codeflinger/blending.cpp
+++ b/libpixelflinger/codeflinger/blending.cpp
@@ -15,6 +15,8 @@
** limitations under the License.
*/
+#define LOG_TAG "pixelflinger-code"
+
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
diff --git a/libpixelflinger/codeflinger/load_store.cpp b/libpixelflinger/codeflinger/load_store.cpp
index d68f6dc..b8a0e55 100644
--- a/libpixelflinger/codeflinger/load_store.cpp
+++ b/libpixelflinger/codeflinger/load_store.cpp
@@ -15,6 +15,8 @@
** limitations under the License.
*/
+#define LOG_TAG "pixelflinger-code"
+
#include <assert.h>
#include <stdio.h>
diff --git a/libpixelflinger/codeflinger/texturing.cpp b/libpixelflinger/codeflinger/texturing.cpp
index d66981d..f4f4657 100644
--- a/libpixelflinger/codeflinger/texturing.cpp
+++ b/libpixelflinger/codeflinger/texturing.cpp
@@ -15,6 +15,8 @@
** limitations under the License.
*/
+#define LOG_TAG "pixelflinger-code"
+
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
diff --git a/libpixelflinger/trap.cpp b/libpixelflinger/trap.cpp
index f00e50a..fa6338a 100644
--- a/libpixelflinger/trap.cpp
+++ b/libpixelflinger/trap.cpp
@@ -15,6 +15,8 @@
** limitations under the License.
*/
+#define LOG_TAG "pixelflinger-trap"
+
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/libsuspend/autosuspend_wakeup_count.c b/libsuspend/autosuspend_wakeup_count.c
index d3fb45f..3457d5b 100644
--- a/libsuspend/autosuspend_wakeup_count.c
+++ b/libsuspend/autosuspend_wakeup_count.c
@@ -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 @@
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 @@
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 @@
} 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) {
diff --git a/libsysutils/src/FrameworkCommand.cpp b/libsysutils/src/FrameworkCommand.cpp
index dccacda..a6c4abc 100644
--- a/libsysutils/src/FrameworkCommand.cpp
+++ b/libsysutils/src/FrameworkCommand.cpp
@@ -18,7 +18,7 @@
#include <errno.h>
-#include <android/log.h>
+#include <log/log.h>
#include <sysutils/FrameworkCommand.h>
#define UNUSED __attribute__((unused))
diff --git a/libsysutils/src/FrameworkListener.cpp b/libsysutils/src/FrameworkListener.cpp
index b96174a..1b6076f 100644
--- a/libsysutils/src/FrameworkListener.cpp
+++ b/libsysutils/src/FrameworkListener.cpp
@@ -19,8 +19,9 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
-#include <android/log.h>
+#include <log/log.h>
#include <sysutils/FrameworkCommand.h>
#include <sysutils/FrameworkListener.h>
#include <sysutils/SocketClient.h>
@@ -49,6 +50,7 @@
errorRate = 0;
mCommandCount = 0;
mWithSeq = withSeq;
+ mSkipToNextNullByte = false;
}
bool FrameworkListener::onDataAvailable(SocketClient *c) {
@@ -59,10 +61,15 @@
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;
@@ -70,11 +77,16 @@
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;
}
diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp
index b787692..fef801a 100644
--- a/libsysutils/src/NetlinkEvent.cpp
+++ b/libsysutils/src/NetlinkEvent.cpp
@@ -41,7 +41,7 @@
const int LOCAL_QLOG_NL_EVENT = 112;
const int LOCAL_NFLOG_PACKET = NFNL_SUBSYS_ULOG << 8 | NFULNL_MSG_PACKET;
-#include <android/log.h>
+#include <log/log.h>
#include <sysutils/NetlinkEvent.h>
NetlinkEvent::NetlinkEvent() {
diff --git a/libsysutils/src/NetlinkListener.cpp b/libsysutils/src/NetlinkListener.cpp
index 1c4c7df..896dad3 100644
--- a/libsysutils/src/NetlinkListener.cpp
+++ b/libsysutils/src/NetlinkListener.cpp
@@ -20,11 +20,12 @@
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
+#include <unistd.h>
#include <linux/netlink.h> /* out of order because must follow sys/socket.h */
-#include <android/log.h>
#include <cutils/uevent.h>
+#include <log/log.h>
#include <sysutils/NetlinkEvent.h>
#if 1
diff --git a/libsysutils/src/ServiceManager.cpp b/libsysutils/src/ServiceManager.cpp
index 1abe988..13bac09 100644
--- a/libsysutils/src/ServiceManager.cpp
+++ b/libsysutils/src/ServiceManager.cpp
@@ -17,10 +17,12 @@
#define LOG_TAG "Service"
#include <errno.h>
+#include <stdio.h>
#include <string.h>
+#include <unistd.h>
-#include <android/log.h>
#include <cutils/properties.h>
+#include <log/log.h>
#include <sysutils/ServiceManager.h>
ServiceManager::ServiceManager() {
diff --git a/libsysutils/src/SocketClient.cpp b/libsysutils/src/SocketClient.cpp
index 02505d3..971f908 100644
--- a/libsysutils/src/SocketClient.cpp
+++ b/libsysutils/src/SocketClient.cpp
@@ -25,8 +25,9 @@
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
+#include <unistd.h>
-#include <android/log.h>
+#include <log/log.h>
#include <sysutils/SocketClient.h>
SocketClient::SocketClient(int socket, bool owned) {
diff --git a/libsysutils/src/SocketListener.cpp b/libsysutils/src/SocketListener.cpp
index 6a676a9..3f8f3db 100644
--- a/libsysutils/src/SocketListener.cpp
+++ b/libsysutils/src/SocketListener.cpp
@@ -24,9 +24,10 @@
#include <sys/time.h>
#include <sys/types.h>
#include <sys/un.h>
+#include <unistd.h>
-#include <android/log.h>
#include <cutils/sockets.h>
+#include <log/log.h>
#include <sysutils/SocketListener.h>
#include <sysutils/SocketClient.h>
diff --git a/libutils/SharedBuffer.cpp b/libutils/SharedBuffer.cpp
index 2b3690c..269326a 100644
--- a/libutils/SharedBuffer.cpp
+++ b/libutils/SharedBuffer.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "sharedbuffer"
+
#include <stdlib.h>
#include <string.h>
diff --git a/libutils/Unicode.cpp b/libutils/Unicode.cpp
index 0652101..c32f462 100644
--- a/libutils/Unicode.cpp
+++ b/libutils/Unicode.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "unicode"
+
#include <limits.h>
#include <stddef.h>
diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc
index b00557c..a07df30 100644
--- a/libziparchive/zip_archive.cc
+++ b/libziparchive/zip_archive.cc
@@ -18,6 +18,8 @@
* Read-only access to Zip archives, with minimal heap allocation.
*/
+#define LOG_TAG "ziparchive"
+
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
@@ -30,11 +32,11 @@
#include <memory>
#include <vector>
-#include <android/log.h>
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/macros.h> // TEMP_FAILURE_RETRY may or may not be in unistd
#include <android-base/memory.h>
+#include <log/log.h>
#include <utils/Compat.h>
#include <utils/FileMap.h>
#include "ziparchive/zip_archive.h"
@@ -265,9 +267,14 @@
* 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) {
diff --git a/lmkd/lmkd.c b/lmkd/lmkd.c
index 107aa3e..49746b3 100644
--- a/lmkd/lmkd.c
+++ b/lmkd/lmkd.c
@@ -18,6 +18,7 @@
#include <arpa/inet.h>
#include <errno.h>
+#include <sched.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
diff --git a/logcat/logcatd.rc b/logcat/logcatd.rc
index 1da1942..b082a64 100644
--- a/logcat/logcatd.rc
+++ b/logcat/logcatd.rc
@@ -35,7 +35,8 @@
# 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
diff --git a/logd/LogAudit.cpp b/logd/LogAudit.cpp
index cc140b0..3811daa 100644
--- a/logd/LogAudit.cpp
+++ b/logd/LogAudit.cpp
@@ -25,7 +25,6 @@
#include <sys/uio.h>
#include <syslog.h>
-#include <log/logger.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp
index 7f5fe4f..aff8a46 100644
--- a/logd/LogBuffer.cpp
+++ b/logd/LogBuffer.cpp
@@ -25,114 +25,21 @@
#include <unordered_map>
#include <cutils/properties.h>
-#include <log/logger.h>
+#include <private/android_logger.h>
#include "LogBuffer.h"
#include "LogKlog.h"
#include "LogReader.h"
// Default
-#define LOG_BUFFER_SIZE (256 * 1024) // Tuned with ro.logd.size per-platform
#define log_buffer_size(id) mMaxSize[id]
-#define LOG_BUFFER_MIN_SIZE (64 * 1024UL)
-#define LOG_BUFFER_MAX_SIZE (256 * 1024 * 1024UL)
-
-static bool valid_size(unsigned long value) {
- if ((value < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < value)) {
- return false;
- }
-
- long pages = sysconf(_SC_PHYS_PAGES);
- if (pages < 1) {
- return true;
- }
-
- long pagesize = sysconf(_SC_PAGESIZE);
- if (pagesize <= 1) {
- pagesize = PAGE_SIZE;
- }
-
- // maximum memory impact a somewhat arbitrary ~3%
- pages = (pages + 31) / 32;
- unsigned long maximum = pages * pagesize;
-
- if ((maximum < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < maximum)) {
- return true;
- }
-
- return value <= maximum;
-}
-
-static unsigned long property_get_size(const char *key) {
- char property[PROPERTY_VALUE_MAX];
- property_get(key, property, "");
-
- char *cp;
- unsigned long value = strtoul(property, &cp, 10);
-
- switch(*cp) {
- case 'm':
- case 'M':
- value *= 1024;
- /* FALLTHRU */
- case 'k':
- case 'K':
- value *= 1024;
- /* FALLTHRU */
- case '\0':
- break;
-
- default:
- value = 0;
- }
-
- if (!valid_size(value)) {
- value = 0;
- }
-
- return value;
-}
void LogBuffer::init() {
- static const char global_tuneable[] = "persist.logd.size"; // Settings App
- static const char global_default[] = "ro.logd.size"; // BoardConfig.mk
-
- unsigned long default_size = property_get_size(global_tuneable);
- if (!default_size) {
- default_size = property_get_size(global_default);
- if (!default_size) {
- default_size = property_get_bool("ro.config.low_ram",
- BOOL_DEFAULT_FALSE)
- ? LOG_BUFFER_MIN_SIZE // 64K
- : LOG_BUFFER_SIZE; // 256K
- }
- }
-
log_id_for_each(i) {
mLastSet[i] = false;
mLast[i] = mLogElements.begin();
- char key[PROP_NAME_MAX];
-
- snprintf(key, sizeof(key), "%s.%s",
- global_tuneable, android_log_id_to_name(i));
- unsigned long property_size = property_get_size(key);
-
- if (!property_size) {
- snprintf(key, sizeof(key), "%s.%s",
- global_default, android_log_id_to_name(i));
- property_size = property_get_size(key);
- }
-
- if (!property_size) {
- property_size = default_size;
- }
-
- if (!property_size) {
- property_size = LOG_BUFFER_SIZE;
- }
-
- if (setSize(i, property_size)) {
+ if (setSize(i, __android_logger_get_buffer_size(i))) {
setSize(i, LOG_BUFFER_MIN_SIZE);
}
}
@@ -315,6 +222,9 @@
LogBufferElement *element = *it;
log_id_t id = element->getLogId();
+ // Remove iterator references in the various lists that will become stale
+ // after the element is erased from the main logging list.
+
{ // start of scope for found iterator
int key = ((id == LOG_ID_EVENTS) || (id == LOG_ID_SECURITY)) ?
element->getTag() : element->getUid();
@@ -324,7 +234,8 @@
}
}
- if ((id != LOG_ID_EVENTS) && (id != LOG_ID_SECURITY) && (element->getUid() == AID_SYSTEM)) {
+ if ((id != LOG_ID_EVENTS) && (id != LOG_ID_SECURITY)) {
+ // element->getUid() may not be AID_SYSTEM for next-best-watermark.
// start of scope for pid found iterator
LogBufferPidIteratorMap::iterator found =
mLastWorstPidOfSystem[id].find(element->getPid());
@@ -594,7 +505,7 @@
it = found->second;
}
}
- if (worstPid) {
+ if (worstPid) { // Only set if !LOG_ID_EVENTS and !LOG_ID_SECURITY
// begin scope for pid worst found iterator
LogBufferPidIteratorMap::iterator found
= mLastWorstPidOfSystem[id].find(worstPid);
@@ -627,6 +538,7 @@
++it;
continue;
}
+ // below this point element->getLogId() == id
if (leading && (!mLastSet[id] || ((*mLast[id])->getLogId() != id))) {
mLast[id] = it;
@@ -683,6 +595,8 @@
&& ((!gc && (element->getPid() == worstPid))
|| (mLastWorstPidOfSystem[id].find(element->getPid())
== mLastWorstPidOfSystem[id].end()))) {
+ // element->getUid() may not be AID_SYSTEM, next best
+ // watermark if current one empty.
mLastWorstPidOfSystem[id][element->getPid()] = it;
}
if ((!gc && !worstPid && (key == worst))
@@ -700,6 +614,8 @@
++it;
continue;
}
+ // key == worst below here
+ // If worstPid set, then element->getPid() == worstPid below here
pruneRows--;
if (pruneRows == 0) {
@@ -723,6 +639,8 @@
if (worstPid && (!gc
|| (mLastWorstPidOfSystem[id].find(worstPid)
== mLastWorstPidOfSystem[id].end()))) {
+ // element->getUid() may not be AID_SYSTEM, next best
+ // watermark if current one empty.
mLastWorstPidOfSystem[id][worstPid] = it;
}
if ((!gc && !worstPid) ||
@@ -880,7 +798,7 @@
// set the total space allocated to "id"
int LogBuffer::setSize(log_id_t id, unsigned long size) {
// Reasonable limits ...
- if (!valid_size(size)) {
+ if (!__android_logger_valid_buffer_size(size)) {
return -1;
}
pthread_mutex_lock(&mLogElementsLock);
diff --git a/logd/LogBufferElement.cpp b/logd/LogBufferElement.cpp
index e5de11d..a939002 100644
--- a/logd/LogBufferElement.cpp
+++ b/logd/LogBufferElement.cpp
@@ -22,7 +22,6 @@
#include <time.h>
#include <unistd.h>
-#include <log/logger.h>
#include <private/android_logger.h>
#include "LogBuffer.h"
diff --git a/logd/LogKlog.cpp b/logd/LogKlog.cpp
index ef6c1ae..c7506ef 100644
--- a/logd/LogKlog.cpp
+++ b/logd/LogKlog.cpp
@@ -402,7 +402,32 @@
}
}
-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 @@
}
// 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) {
diff --git a/logd/LogKlog.h b/logd/LogKlog.h
index 6e150e7..c0c1223 100644
--- a/logd/LogKlog.h
+++ b/logd/LogKlog.h
@@ -51,7 +51,7 @@
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);
diff --git a/logd/LogListener.cpp b/logd/LogListener.cpp
index 61b7fd8..4a30e6d 100644
--- a/logd/LogListener.cpp
+++ b/logd/LogListener.cpp
@@ -23,7 +23,6 @@
#include <unistd.h>
#include <cutils/sockets.h>
-#include <log/logger.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
diff --git a/logd/LogUtils.h b/logd/LogUtils.h
index 6db4c51..d6b3dc6 100644
--- a/logd/LogUtils.h
+++ b/logd/LogUtils.h
@@ -20,8 +20,8 @@
#include <sys/cdefs.h>
#include <sys/types.h>
-#include <android/log.h>
#include <sysutils/SocketClient.h>
+#include <log/log.h>
// Hijack this header as a common include file used by most all sources
// to report some utilities defined here and there.
@@ -45,16 +45,6 @@
bool clientHasLogCredentials(uid_t uid, gid_t gid, pid_t pid);
bool clientHasLogCredentials(SocketClient *cli);
-// Furnished in main.cpp
-#define BOOL_DEFAULT_FLAG_TRUE_FALSE 0x1
-#define BOOL_DEFAULT_FALSE 0x0 // false if property not present
-#define BOOL_DEFAULT_TRUE 0x1 // true if property not present
-#define BOOL_DEFAULT_FLAG_PERSIST 0x2 // <key>, persist.<key>, ro.<key>
-#define BOOL_DEFAULT_FLAG_ENG 0x4 // off for user
-#define BOOL_DEFAULT_FLAG_SVELTE 0x8 // off for low_ram
-
-bool property_get_bool(const char *key, int def);
-
static inline bool worstUidEnabledForLogid(log_id_t id) {
return (id == LOG_ID_MAIN) || (id == LOG_ID_SYSTEM) ||
(id == LOG_ID_RADIO) || (id == LOG_ID_EVENTS);
diff --git a/logd/libaudit.c b/logd/libaudit.c
index 288a052..d2b212e 100644
--- a/logd/libaudit.c
+++ b/logd/libaudit.c
@@ -18,26 +18,20 @@
*
*/
-#define LOG_TAG "libaudit"
-
#include <errno.h>
#include <string.h>
#include <unistd.h>
-#include <android/log.h>
-
#include "libaudit.h"
/**
* Waits for an ack from the kernel
* @param fd
* The netlink socket fd
- * @param seq
- * The current sequence number were acking on
* @return
* This function returns 0 on success, else -errno.
*/
-static int get_ack(int fd, int16_t seq)
+static int get_ack(int fd)
{
int rc;
struct audit_message rep;
@@ -60,11 +54,6 @@
}
}
- if ((int16_t)rep.nlh.nlmsg_seq != seq) {
- SLOGW("Expected sequence number between user space and kernel space is out of skew, "
- "expected %u got %u", seq, rep.nlh.nlmsg_seq);
- }
-
return 0;
}
@@ -109,7 +98,6 @@
/* Ensure the message is not too big */
if (NLMSG_SPACE(size) > MAX_AUDIT_MESSAGE_LENGTH) {
- SLOGE("netlink message is too large");
return -EINVAL;
}
@@ -140,7 +128,6 @@
/* Not all the bytes were sent */
if (rc < 0) {
rc = -errno;
- SLOGE("Error sending data over the netlink socket: %s", strerror(-errno));
goto out;
} else if ((uint32_t) rc != req.nlh.nlmsg_len) {
rc = -EPROTO;
@@ -148,7 +135,7 @@
}
/* We sent all the bytes, get the ack */
- rc = get_ack(fd, sequence);
+ rc = get_ack(fd);
/* If the ack failed, return the error, else return the sequence number */
rc = (rc == 0) ? (int) sequence : rc;
@@ -156,7 +143,6 @@
out:
/* Don't let sequence roll to negative */
if (sequence < 0) {
- SLOGW("Auditd to Kernel sequence number has rolled over");
sequence = 0;
}
@@ -183,7 +169,6 @@
/* Let the kernel know this pid will be registering for audit events */
rc = audit_send(fd, AUDIT_SET, &status, sizeof(status));
if (rc < 0) {
- SLOGE("Could net set pid for audit events, error: %s", strerror(-rc));
return rc;
}
@@ -241,25 +226,21 @@
/* If request is non blocking and errno is EAGAIN, just return 0 */
return 0;
}
- SLOGE("Error receiving from netlink socket, error: %s", strerror(-rc));
return rc;
}
if (nladdrlen != sizeof(nladdr)) {
- SLOGE("Protocol fault, error: %s", strerror(EPROTO));
return -EPROTO;
}
/* Make sure the netlink message was not spoof'd */
if (nladdr.nl_pid) {
- SLOGE("Invalid netlink pid received, expected 0 got: %d", nladdr.nl_pid);
return -EINVAL;
}
/* Check if the reply from the kernel was ok */
if (!NLMSG_OK(&rep->nlh, (size_t)len)) {
rc = (len == sizeof(*rep)) ? -EFBIG : -EBADE;
- SLOGE("Bad kernel response %s", strerror(-rc));
}
return rc;
@@ -267,9 +248,5 @@
void audit_close(int fd)
{
- int rc = close(fd);
- if (rc < 0) {
- SLOGE("Attempting to close invalid fd %d, error: %s", fd, strerror(errno));
- }
- return;
+ close(fd);
}
diff --git a/logd/main.cpp b/logd/main.cpp
index c47f396..0cb26dc 100644
--- a/logd/main.cpp
+++ b/logd/main.cpp
@@ -131,57 +131,6 @@
return !*cp || !!strchr(sep, *cp);
}
-bool property_get_bool(const char *key, int flag) {
- char def[PROPERTY_VALUE_MAX];
- char property[PROPERTY_VALUE_MAX];
- def[0] = '\0';
- if (flag & BOOL_DEFAULT_FLAG_PERSIST) {
- char newkey[PROPERTY_KEY_MAX];
- snprintf(newkey, sizeof(newkey), "ro.%s", key);
- property_get(newkey, property, "");
- // persist properties set by /data require inoculation with
- // logd-reinit. They may be set in init.rc early and function, but
- // otherwise are defunct unless reset. Do not rely on persist
- // properties for startup-only keys unless you are willing to restart
- // logd daemon (not advised).
- snprintf(newkey, sizeof(newkey), "persist.%s", key);
- property_get(newkey, def, property);
- }
-
- property_get(key, property, def);
-
- if (check_flag(property, "true")) {
- return true;
- }
- if (check_flag(property, "false")) {
- return false;
- }
- if (check_flag(property, "eng")) {
- flag |= BOOL_DEFAULT_FLAG_ENG;
- }
- // this is really a "not" flag
- if (check_flag(property, "svelte")) {
- flag |= BOOL_DEFAULT_FLAG_SVELTE;
- }
-
- // Sanity Check
- if (flag & (BOOL_DEFAULT_FLAG_SVELTE | BOOL_DEFAULT_FLAG_ENG)) {
- flag &= ~BOOL_DEFAULT_FLAG_TRUE_FALSE;
- flag |= BOOL_DEFAULT_TRUE;
- }
-
- if ((flag & BOOL_DEFAULT_FLAG_SVELTE)
- && property_get_bool("ro.config.low_ram",
- BOOL_DEFAULT_FALSE)) {
- return false;
- }
- if ((flag & BOOL_DEFAULT_FLAG_ENG) && !__android_log_is_debuggable()) {
- return false;
- }
-
- return (flag & BOOL_DEFAULT_FLAG_TRUE_FALSE) != BOOL_DEFAULT_FALSE;
-}
-
static int fdDmesg = -1;
void android::prdebug(const char *fmt, ...) {
if (fdDmesg < 0) {
@@ -365,11 +314,11 @@
// transitory per-client threads are created for each reader.
int main(int argc, char *argv[]) {
int fdPmesg = -1;
- bool klogd = property_get_bool("logd.kernel",
- BOOL_DEFAULT_TRUE |
- BOOL_DEFAULT_FLAG_PERSIST |
- BOOL_DEFAULT_FLAG_ENG |
- BOOL_DEFAULT_FLAG_SVELTE);
+ bool klogd = __android_logger_property_get_bool("logd.kernel",
+ BOOL_DEFAULT_TRUE |
+ BOOL_DEFAULT_FLAG_PERSIST |
+ BOOL_DEFAULT_FLAG_ENG |
+ BOOL_DEFAULT_FLAG_SVELTE);
if (klogd) {
fdPmesg = open("/proc/kmsg", O_RDONLY | O_NDELAY);
}
@@ -449,11 +398,11 @@
signal(SIGHUP, reinit_signal_handler);
- if (property_get_bool("logd.statistics",
- BOOL_DEFAULT_TRUE |
- BOOL_DEFAULT_FLAG_PERSIST |
- BOOL_DEFAULT_FLAG_ENG |
- BOOL_DEFAULT_FLAG_SVELTE)) {
+ if (__android_logger_property_get_bool("logd.statistics",
+ BOOL_DEFAULT_TRUE |
+ BOOL_DEFAULT_FLAG_PERSIST |
+ BOOL_DEFAULT_FLAG_ENG |
+ BOOL_DEFAULT_FLAG_SVELTE)) {
logBuf->enableStatistics();
}
@@ -487,17 +436,17 @@
// initiated log messages. New log entries are added to LogBuffer
// and LogReader is notified to send updates to connected clients.
- bool auditd = property_get_bool("logd.auditd",
- BOOL_DEFAULT_TRUE |
- BOOL_DEFAULT_FLAG_PERSIST);
+ bool auditd = __android_logger_property_get_bool("logd.auditd",
+ BOOL_DEFAULT_TRUE |
+ BOOL_DEFAULT_FLAG_PERSIST);
LogAudit *al = NULL;
if (auditd) {
al = new LogAudit(logBuf, reader,
- property_get_bool("logd.auditd.dmesg",
- BOOL_DEFAULT_TRUE |
- BOOL_DEFAULT_FLAG_PERSIST)
- ? fdDmesg
- : -1);
+ __android_logger_property_get_bool(
+ "logd.auditd.dmesg",
+ BOOL_DEFAULT_TRUE | BOOL_DEFAULT_FLAG_PERSIST)
+ ? fdDmesg
+ : -1);
}
LogKlog *kl = NULL;
diff --git a/rootdir/Android.mk b/rootdir/Android.mk
index e060a2c..aa5a520 100644
--- a/rootdir/Android.mk
+++ b/rootdir/Android.mk
@@ -26,6 +26,7 @@
#######################################
# asan.options
ifneq ($(filter address,$(SANITIZE_TARGET)),)
+
include $(CLEAR_VARS)
LOCAL_MODULE := asan.options
@@ -34,6 +35,72 @@
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 @@
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 /sys/kernel/debug $(TARGET_ROOT_OUT)/d; \
ln -sf /storage/self/primary $(TARGET_ROOT_OUT)/sdcard
@@ -63,6 +130,11 @@
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),\
diff --git a/rootdir/asan.options b/rootdir/asan.options
index 43896a1..d728f12 100644
--- a/rootdir/asan.options
+++ b/rootdir/asan.options
@@ -3,3 +3,5 @@
alloc_dealloc_mismatch=0
allocator_may_return_null=1
detect_container_overflow=0
+abort_on_error=1
+include_if_exists=/system/asan.options.%b
diff --git a/rootdir/asan.options.off.template b/rootdir/asan.options.off.template
new file mode 100644
index 0000000..59a1249
--- /dev/null
+++ b/rootdir/asan.options.off.template
@@ -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
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 50ee110..64151b7 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -50,12 +50,20 @@
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 @@
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 @@
# 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
@@ -283,6 +294,7 @@
trigger early-boot
trigger boot
+
on post-fs
start logd
# once everything is setup, no need to modify /
@@ -411,6 +423,10 @@
# 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
@@ -455,6 +471,11 @@
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.
@@ -562,7 +583,7 @@
on nonencrypted
# A/B update verifier that marks a successful boot.
- exec - root -- /system/bin/update_verifier nonencrypted
+ exec - root cache -- /system/bin/update_verifier nonencrypted
class_start main
class_start late_start
@@ -585,12 +606,12 @@
on property:vold.decrypt=trigger_restart_min_framework
# A/B update verifier that marks a successful boot.
- exec - root -- /system/bin/update_verifier trigger_restart_min_framework
+ exec - root cache -- /system/bin/update_verifier trigger_restart_min_framework
class_start main
on property:vold.decrypt=trigger_restart_framework
# A/B update verifier that marks a successful boot.
- exec - root -- /system/bin/update_verifier trigger_restart_framework
+ exec - root cache -- /system/bin/update_verifier trigger_restart_framework
class_start main
class_start late_start
diff --git a/rootdir/init.usb.rc b/rootdir/init.usb.rc
index 1fd1e2a..915d159 100644
--- a/rootdir/init.usb.rc
+++ b/rootdir/init.usb.rc
@@ -103,7 +103,7 @@
# 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}
#
diff --git a/rootdir/init.zygote32.rc b/rootdir/init.zygote32.rc
index 807f9bc..2d7d5c2 100644
--- a/rootdir/init.zygote32.rc
+++ b/rootdir/init.zygote32.rc
@@ -8,4 +8,4 @@
onrestart restart cameraserver
onrestart restart media
onrestart restart netd
- writepid /dev/cpuset/foreground/tasks /dev/stune/foreground/tasks
+ writepid /dev/cpuset/foreground/tasks
diff --git a/rootdir/init.zygote32_64.rc b/rootdir/init.zygote32_64.rc
index 3bfa0af..4156847 100644
--- a/rootdir/init.zygote32_64.rc
+++ b/rootdir/init.zygote32_64.rc
@@ -15,4 +15,4 @@
priority -20
socket zygote_secondary stream 660 root system
onrestart restart zygote
- writepid /dev/cpuset/foreground/tasks /dev/stune/foreground/tasks
+ writepid /dev/cpuset/foreground/tasks
diff --git a/rootdir/init.zygote64.rc b/rootdir/init.zygote64.rc
index 13ffd7e..8584cbb 100644
--- a/rootdir/init.zygote64.rc
+++ b/rootdir/init.zygote64.rc
@@ -8,4 +8,4 @@
onrestart restart cameraserver
onrestart restart media
onrestart restart netd
- writepid /dev/cpuset/foreground/tasks /dev/stune/foreground/tasks
+ writepid /dev/cpuset/foreground/tasks
diff --git a/rootdir/init.zygote64_32.rc b/rootdir/init.zygote64_32.rc
index 5640490..27eaa66 100644
--- a/rootdir/init.zygote64_32.rc
+++ b/rootdir/init.zygote64_32.rc
@@ -15,4 +15,4 @@
priority -20
socket zygote_secondary stream 660 root system
onrestart restart zygote
- writepid /dev/cpuset/foreground/tasks /dev/stune/foreground/tasks
+ writepid /dev/cpuset/foreground/tasks
diff --git a/sdcard/fuse.cpp b/sdcard/fuse.cpp
index d4c51fd..4f1ca0d 100644
--- a/sdcard/fuse.cpp
+++ b/sdcard/fuse.cpp
@@ -1026,7 +1026,13 @@
}
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 @@
}
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;
}
@@ -1273,6 +1285,11 @@
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;
diff --git a/trusty/gatekeeper/trusty_gatekeeper_ipc.c b/trusty/gatekeeper/trusty_gatekeeper_ipc.c
index ae536c5..45e65a7 100644
--- a/trusty/gatekeeper/trusty_gatekeeper_ipc.c
+++ b/trusty/gatekeeper/trusty_gatekeeper_ipc.c
@@ -17,8 +17,10 @@
#define LOG_TAG "TrustyGateKeeper"
#include <errno.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <android/log.h>
#include <trusty/tipc.h>
diff --git a/trusty/keymaster/trusty_keymaster_ipc.c b/trusty/keymaster/trusty_keymaster_ipc.c
index 0159bce..8755093 100644
--- a/trusty/keymaster/trusty_keymaster_ipc.c
+++ b/trusty/keymaster/trusty_keymaster_ipc.c
@@ -21,6 +21,7 @@
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <android/log.h>
#include <trusty/tipc.h>
diff --git a/trusty/libtrusty/trusty.c b/trusty/libtrusty/trusty.c
index ba16bee..2398a53 100644
--- a/trusty/libtrusty/trusty.c
+++ b/trusty/libtrusty/trusty.c
@@ -22,6 +22,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
#include <android/log.h>
diff --git a/trusty/nvram/trusty_nvram_implementation.cpp b/trusty/nvram/trusty_nvram_implementation.cpp
index caa25ab..ddaf333 100644
--- a/trusty/nvram/trusty_nvram_implementation.cpp
+++ b/trusty/nvram/trusty_nvram_implementation.cpp
@@ -20,6 +20,7 @@
#include <errno.h>
#include <string.h>
+#include <unistd.h>
#include <android/log.h>
#include <hardware/nvram.h>
diff --git a/trusty/storage/proxy/ipc.c b/trusty/storage/proxy/ipc.c
index b4748e2..57cf600 100644
--- a/trusty/storage/proxy/ipc.c
+++ b/trusty/storage/proxy/ipc.c
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/uio.h>
+#include <unistd.h>
#include <trusty/tipc.h>
diff --git a/trusty/storage/proxy/rpmb.c b/trusty/storage/proxy/rpmb.c
index 9130458..9c79105 100644
--- a/trusty/storage/proxy/rpmb.c
+++ b/trusty/storage/proxy/rpmb.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
+#include <unistd.h>
#include <linux/major.h>
#include <linux/mmc/ioctl.h>