Merge "Stop writing NUL bytes in adbkey.pub."
diff --git a/adb/commandline.cpp b/adb/commandline.cpp
index 5f55ab9..b8f790d 100644
--- a/adb/commandline.cpp
+++ b/adb/commandline.cpp
@@ -68,20 +68,17 @@
static int install_app_legacy(TransportType t, const char* serial, int argc, const char** argv);
static int uninstall_app_legacy(TransportType t, const char* serial, int argc, const char** argv);
-static auto& gProductOutPath = *new std::string();
extern int gListenAll;
DefaultStandardStreamsCallback DEFAULT_STANDARD_STREAMS_CALLBACK(nullptr, nullptr);
-static std::string product_file(const char *extra) {
- if (gProductOutPath.empty()) {
- fprintf(stderr, "adb: Product directory not specified; "
- "use -p or define ANDROID_PRODUCT_OUT\n");
+static std::string product_file(const char* file) {
+ const char* ANDROID_PRODUCT_OUT = getenv("ANDROID_PRODUCT_OUT");
+ if (ANDROID_PRODUCT_OUT == nullptr) {
+ fprintf(stderr, "adb: product directory not specified; set $ANDROID_PRODUCT_OUT\n");
exit(1);
}
-
- return android::base::StringPrintf("%s%s%s",
- gProductOutPath.c_str(), OS_PATH_SEPARATOR_STR, extra);
+ return android::base::StringPrintf("%s%s%s", ANDROID_PRODUCT_OUT, OS_PATH_SEPARATOR_STR, file);
}
static void help() {
@@ -92,11 +89,7 @@
" -a listen on all network interfaces, not just localhost\n"
" -d use USB device (error if multiple devices connected)\n"
" -e use TCP/IP device (error if multiple TCP/IP devices available)\n"
- " -s SERIAL\n"
- " use device with given serial number (overrides $ANDROID_SERIAL)\n"
- " -p PRODUCT\n"
- " name or path ('angler'/'out/target/product/angler');\n"
- " default $ANDROID_PRODUCT_OUT\n"
+ " -s SERIAL use device with given serial (overrides $ANDROID_SERIAL)\n"
" -H name of adb server host [default=localhost]\n"
" -P port of adb server [default=5037]\n"
" -L SOCKET listen on given socket for adb server [default=tcp:localhost:5037]\n"
@@ -138,9 +131,8 @@
" pull [-a] REMOTE... LOCAL\n"
" copy files/dirs from device\n"
" -a: preserve file timestamp and mode\n"
- " sync [DIR]\n"
- " copy all changed files to device; if DIR is \"system\", \"vendor\", \"oem\",\n"
- " or \"data\", only sync that partition (default all)\n"
+ " sync [system|vendor|oem|data|all]\n"
+ " sync a local build from $ANDROID_PRODUCT_OUT to the device (default all)\n"
" -l: list but don't copy\n"
"\n"
"shell:\n"
@@ -1254,66 +1246,6 @@
return 0;
}
-/* <hint> may be:
- * - A simple product name
- * e.g., "sooner"
- * - A relative path from the CWD to the ANDROID_PRODUCT_OUT dir
- * e.g., "out/target/product/sooner"
- * - An absolute path to the PRODUCT_OUT dir
- * e.g., "/src/device/out/target/product/sooner"
- *
- * Given <hint>, try to construct an absolute path to the
- * ANDROID_PRODUCT_OUT dir.
- */
-static std::string find_product_out_path(const std::string& hint) {
- if (hint.empty()) {
- return "";
- }
-
- // If it's already absolute, don't bother doing any work.
- if (adb_is_absolute_host_path(hint.c_str())) {
- return hint;
- }
-
- // If any of the OS_PATH_SEPARATORS is found, assume it's a relative path;
- // make it absolute.
- // NOLINT: Do not complain if OS_PATH_SEPARATORS has only one character.
- if (hint.find_first_of(OS_PATH_SEPARATORS) != std::string::npos) { // NOLINT
- std::string cwd;
- if (!getcwd(&cwd)) {
- perror("adb: getcwd failed");
- return "";
- }
- return android::base::StringPrintf("%s%c%s", cwd.c_str(), OS_PATH_SEPARATOR, hint.c_str());
- }
-
- // It's a string without any slashes. Try to do something with it.
- //
- // Try to find the root of the build tree, and build a PRODUCT_OUT
- // path from there.
- char* top = getenv("ANDROID_BUILD_TOP");
- if (top == nullptr) {
- fprintf(stderr, "adb: ANDROID_BUILD_TOP not set!\n");
- return "";
- }
-
- std::string path = top;
- path += OS_PATH_SEPARATOR_STR;
- path += "out";
- path += OS_PATH_SEPARATOR_STR;
- path += "target";
- path += OS_PATH_SEPARATOR_STR;
- path += "product";
- path += OS_PATH_SEPARATOR_STR;
- path += hint;
- if (!directory_exists(path)) {
- fprintf(stderr, "adb: Couldn't find a product dir based on -p %s; "
- "\"%s\" doesn't exist\n", hint.c_str(), path.c_str());
- return "";
- }
- return path;
-}
-
static void parse_push_pull_args(const char** arg, int narg,
std::vector<const char*>* srcs,
const char** dst, bool* copy_attrs) {
@@ -1404,17 +1336,6 @@
signal(SIGPIPE, SIG_IGN);
#endif
- // If defined, this should be an absolute path to
- // the directory containing all of the various system images
- // for a particular product. If not defined, and the adb
- // command requires this information, then the user must
- // specify the path using "-p".
- char* ANDROID_PRODUCT_OUT = getenv("ANDROID_PRODUCT_OUT");
- if (ANDROID_PRODUCT_OUT != nullptr) {
- gProductOutPath = ANDROID_PRODUCT_OUT;
- }
- // TODO: also try TARGET_PRODUCT/TARGET_DEVICE as a hint
-
const char* server_host_str = nullptr;
const char* server_port_str = nullptr;
const char* server_socket_str = nullptr;
@@ -1440,21 +1361,6 @@
fprintf(stderr, "adb: invalid reply fd \"%s\"\n", reply_fd_str);
return 1;
}
- } else if (!strncmp(argv[0], "-p", 2)) {
- const char* product = nullptr;
- if (argv[0][2] == '\0') {
- if (argc < 2) return syntax_error("-p requires an argument");
- product = argv[1];
- argc--;
- argv++;
- } else {
- product = argv[0] + 2;
- }
- gProductOutPath = find_product_out_path(product);
- if (gProductOutPath.empty()) {
- fprintf(stderr, "adb: could not resolve \"-p %s\"\n", product);
- return 1;
- }
} else if (argv[0][0]=='-' && argv[0][1]=='s') {
if (isdigit(argv[0][2])) {
serial = argv[0] + 2;
@@ -1833,6 +1739,8 @@
return syntax_error("adb sync [-l] [PARTITION]");
}
+ if (src == "all") src = "";
+
if (src != "" &&
src != "system" && src != "data" && src != "vendor" && src != "oem") {
return syntax_error("don't know how to sync %s partition", src.c_str());
diff --git a/base/utf8.cpp b/base/utf8.cpp
old mode 100755
new mode 100644
diff --git a/base/utf8_test.cpp b/base/utf8_test.cpp
old mode 100755
new mode 100644
diff --git a/init/Android.mk b/init/Android.mk
index de3d076..537bbee 100644
--- a/init/Android.mk
+++ b/init/Android.mk
@@ -145,6 +145,7 @@
init_parser_test.cpp \
init_test.cpp \
property_service_test.cpp \
+ service_test.cpp \
util_test.cpp \
LOCAL_SHARED_LIBRARIES += \
diff --git a/init/devices.cpp b/init/devices.cpp
index 07d28d0..11687f0 100644
--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -47,7 +47,6 @@
#include <cutils/uevent.h>
#include <private/android_filesystem_config.h>
#include <selinux/android.h>
-#include <selinux/avc.h>
#include <selinux/label.h>
#include <selinux/selinux.h>
@@ -783,15 +782,6 @@
{
coldboot_action_t ret = handle_device_fd_with(
[&](uevent* uevent) -> coldboot_action_t {
- if (selinux_status_updated() > 0) {
- struct selabel_handle *sehandle2;
- sehandle2 = selinux_android_file_context_handle();
- if (sehandle2) {
- selabel_close(sehandle);
- sehandle = sehandle2;
- }
- }
-
// default is to always create the devices
coldboot_action_t act = COLDBOOT_CREATE;
if (fn) {
@@ -881,7 +871,6 @@
return;
}
fcntl(device_fd, F_SETFL, O_NONBLOCK);
- selinux_status_open(true);
}
if (access(COLDBOOT_DONE, F_OK) == 0) {
@@ -915,7 +904,6 @@
void device_close() {
platform_devices.clear();
device_fd.reset();
- selinux_status_close();
}
int get_device_fd() {
diff --git a/init/service.cpp b/init/service.cpp
index 39f6709..3a9f622 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -158,6 +158,7 @@
namespace_flags_(0),
seclabel_(""),
onrestart_(false, "<Service '" + name + "' onrestart>", 0),
+ keychord_id_(0),
ioprio_class_(IoSchedClass_NONE),
ioprio_pri_(0),
priority_(0),
@@ -182,6 +183,7 @@
namespace_flags_(namespace_flags),
seclabel_(seclabel),
onrestart_(false, "<Service '" + name + "' onrestart>", 0),
+ keychord_id_(0),
ioprio_class_(IoSchedClass_NONE),
ioprio_pri_(0),
priority_(0),
diff --git a/init/service.h b/init/service.h
index 634fe4e..426577f 100644
--- a/init/service.h
+++ b/init/service.h
@@ -94,14 +94,19 @@
const std::set<std::string>& classnames() const { return classnames_; }
unsigned flags() const { return flags_; }
pid_t pid() const { return pid_; }
+ int crash_count() const { return crash_count_; }
uid_t uid() const { return uid_; }
gid_t gid() const { return gid_; }
- int priority() const { return priority_; }
+ unsigned namespace_flags() const { return namespace_flags_; }
const std::vector<gid_t>& supp_gids() const { return supp_gids_; }
const std::string& seclabel() const { return seclabel_; }
const std::vector<int>& keycodes() const { return keycodes_; }
int keychord_id() const { return keychord_id_; }
void set_keychord_id(int keychord_id) { keychord_id_ = keychord_id; }
+ IoSchedClass ioprio_class() const { return ioprio_class_; }
+ int ioprio_pri() const { return ioprio_pri_; }
+ int priority() const { return priority_; }
+ int oom_score_adjust() const { return oom_score_adjust_; }
const std::vector<std::string>& args() const { return args_; }
private:
@@ -181,6 +186,9 @@
public:
static ServiceManager& GetInstance();
+ // Exposed for testing
+ ServiceManager();
+
void AddService(std::unique_ptr<Service> service);
Service* MakeExecOneshotService(const std::vector<std::string>& args);
bool Exec(const std::vector<std::string>& args);
@@ -199,8 +207,6 @@
void DumpState() const;
private:
- ServiceManager();
-
// Cleans up a child process that exited.
// Returns true iff a children was cleaned up.
bool ReapOneProcess();
diff --git a/init/service_test.cpp b/init/service_test.cpp
new file mode 100644
index 0000000..4493f25
--- /dev/null
+++ b/init/service_test.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 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 "service.h"
+
+#include <algorithm>
+#include <memory>
+#include <type_traits>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+TEST(service, pod_initialized) {
+ constexpr auto memory_size = sizeof(Service);
+ alignas(alignof(Service)) char old_memory[memory_size];
+
+ for (std::size_t i = 0; i < memory_size; ++i) {
+ old_memory[i] = 0xFF;
+ }
+
+ std::vector<std::string> dummy_args{"/bin/test"};
+ Service* service_in_old_memory = new (old_memory) Service("test_old_memory", dummy_args);
+
+ EXPECT_EQ(0U, service_in_old_memory->flags());
+ EXPECT_EQ(0, service_in_old_memory->pid());
+ EXPECT_EQ(0, service_in_old_memory->crash_count());
+ EXPECT_EQ(0U, service_in_old_memory->uid());
+ EXPECT_EQ(0U, service_in_old_memory->gid());
+ EXPECT_EQ(0U, service_in_old_memory->namespace_flags());
+ EXPECT_EQ(0, service_in_old_memory->keychord_id());
+ EXPECT_EQ(IoSchedClass_NONE, service_in_old_memory->ioprio_class());
+ EXPECT_EQ(0, service_in_old_memory->ioprio_pri());
+ EXPECT_EQ(0, service_in_old_memory->priority());
+ EXPECT_EQ(-1000, service_in_old_memory->oom_score_adjust());
+
+ for (std::size_t i = 0; i < memory_size; ++i) {
+ old_memory[i] = 0xFF;
+ }
+
+ Service* service_in_old_memory2 = new (old_memory)
+ Service("test_old_memory", 0U, 0U, 0U, std::vector<gid_t>(), CapSet(), 0U, "", dummy_args);
+
+ EXPECT_EQ(0U, service_in_old_memory2->flags());
+ EXPECT_EQ(0, service_in_old_memory2->pid());
+ EXPECT_EQ(0, service_in_old_memory2->crash_count());
+ EXPECT_EQ(0U, service_in_old_memory2->uid());
+ EXPECT_EQ(0U, service_in_old_memory2->gid());
+ EXPECT_EQ(0U, service_in_old_memory2->namespace_flags());
+ EXPECT_EQ(0, service_in_old_memory2->keychord_id());
+ EXPECT_EQ(IoSchedClass_NONE, service_in_old_memory2->ioprio_class());
+ EXPECT_EQ(0, service_in_old_memory2->ioprio_pri());
+ EXPECT_EQ(0, service_in_old_memory2->priority());
+ EXPECT_EQ(-1000, service_in_old_memory2->oom_score_adjust());
+}
diff --git a/init/ueventd.cpp b/init/ueventd.cpp
index 963cc4d..8c0c574 100644
--- a/init/ueventd.cpp
+++ b/init/ueventd.cpp
@@ -33,9 +33,6 @@
#include "log.h"
#include "util.h"
-template <bool sysfs>
-static bool ParseSingleLine(std::vector<std::string>&& line, std::string* err);
-
int ueventd_main(int argc, char **argv)
{
/*
diff --git a/libcutils/fs_config.c b/libcutils/fs_config.c
index e1e8c8d..e4541f7 100644
--- a/libcutils/fs_config.c
+++ b/libcutils/fs_config.c
@@ -140,8 +140,14 @@
{ 00600, AID_ROOT, AID_ROOT, 0, "odm/default.prop" },
{ 00444, AID_ROOT, AID_ROOT, 0, odm_conf_dir + 1 },
{ 00444, AID_ROOT, AID_ROOT, 0, odm_conf_file + 1 },
+ { 00600, AID_ROOT, AID_ROOT, 0, "system/odm/build.prop" },
+ { 00600, AID_ROOT, AID_ROOT, 0, "system/odm/default.prop" },
+ { 00444, AID_ROOT, AID_ROOT, 0, "system/odm/etc/fs_config_dirs" },
+ { 00444, AID_ROOT, AID_ROOT, 0, "system/odm/etc/fs_config_files" },
{ 00444, AID_ROOT, AID_ROOT, 0, oem_conf_dir + 1 },
{ 00444, AID_ROOT, AID_ROOT, 0, oem_conf_file + 1 },
+ { 00444, AID_ROOT, AID_ROOT, 0, "system/oem/etc/fs_config_dirs" },
+ { 00444, AID_ROOT, AID_ROOT, 0, "system/oem/etc/fs_config_files" },
{ 00750, AID_ROOT, AID_SHELL, 0, "sbin/fs_mgr" },
{ 00755, AID_ROOT, AID_SHELL, 0, "system/bin/crash_dump32" },
{ 00755, AID_ROOT, AID_SHELL, 0, "system/bin/crash_dump64" },
@@ -158,6 +164,10 @@
{ 00555, AID_ROOT, AID_ROOT, 0, "system/etc/ppp/*" },
{ 00555, AID_ROOT, AID_ROOT, 0, "system/etc/rc.*" },
{ 00440, AID_ROOT, AID_ROOT, 0, "system/etc/recovery.img" },
+ { 00600, AID_ROOT, AID_ROOT, 0, "system/vendor/build.prop" },
+ { 00600, AID_ROOT, AID_ROOT, 0, "system/vendor/default.prop" },
+ { 00444, AID_ROOT, AID_ROOT, 0, "system/vendor/etc/fs_config_dirs" },
+ { 00444, AID_ROOT, AID_ROOT, 0, "system/vendor/etc/fs_config_files" },
{ 00600, AID_ROOT, AID_ROOT, 0, "vendor/build.prop" },
{ 00600, AID_ROOT, AID_ROOT, 0, "vendor/default.prop" },
{ 00444, AID_ROOT, AID_ROOT, 0, ven_conf_dir + 1 },
@@ -193,11 +203,17 @@
* Support RT scheduling in Bluetooth */
{ 00700, AID_BLUETOOTH, AID_BLUETOOTH, CAP_MASK_LONG(CAP_NET_ADMIN) |
CAP_MASK_LONG(CAP_SYS_NICE),
+ "system/vendor/bin/hw/android.hardware.bluetooth@1.0-service" },
+ { 00700, AID_BLUETOOTH, AID_BLUETOOTH, CAP_MASK_LONG(CAP_NET_ADMIN) |
+ CAP_MASK_LONG(CAP_SYS_NICE),
"vendor/bin/hw/android.hardware.bluetooth@1.0-service" },
/* Support wifi_hal_legacy administering a network interface. */
{ 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) |
CAP_MASK_LONG(CAP_NET_RAW),
+ "system/vendor/bin/hw/android.hardware.wifi@1.0-service" },
+ { 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) |
+ CAP_MASK_LONG(CAP_NET_RAW),
"vendor/bin/hw/android.hardware.wifi@1.0-service" },
/* A non-privileged zygote that spawns
diff --git a/libcutils/sched_policy.cpp b/libcutils/sched_policy.cpp
index 217733a..e29a844 100644
--- a/libcutils/sched_policy.cpp
+++ b/libcutils/sched_policy.cpp
@@ -343,16 +343,25 @@
static void set_timerslack_ns(int tid, unsigned long long slack) {
// v4.6+ kernels support the /proc/<tid>/timerslack_ns interface.
// TODO: once we've backported this, log if the open(2) fails.
- char buf[64];
- snprintf(buf, sizeof(buf), "/proc/%d/timerslack_ns", tid);
- int fd = open(buf, O_WRONLY | O_CLOEXEC);
- if (fd != -1) {
- int len = snprintf(buf, sizeof(buf), "%llu", slack);
- if (write(fd, buf, len) != len) {
- SLOGE("set_timerslack_ns write failed: %s\n", strerror(errno));
+ if (__sys_supports_timerslack) {
+ char buf[64];
+ snprintf(buf, sizeof(buf), "/proc/%d/timerslack_ns", tid);
+ int fd = open(buf, O_WRONLY | O_CLOEXEC);
+ if (fd != -1) {
+ int len = snprintf(buf, sizeof(buf), "%llu", slack);
+ if (write(fd, buf, len) != len) {
+ SLOGE("set_timerslack_ns write failed: %s\n", strerror(errno));
+ }
+ close(fd);
+ return;
}
- close(fd);
- return;
+ }
+
+ // TODO: Remove when /proc/<tid>/timerslack_ns interface is backported.
+ if ((tid == 0) || (tid == gettid())) {
+ if (prctl(PR_SET_TIMERSLACK, slack) == -1) {
+ SLOGE("set_timerslack_ns prctl failed: %s\n", strerror(errno));
+ }
}
}
@@ -431,10 +440,7 @@
}
- if (__sys_supports_timerslack) {
- set_timerslack_ns(tid, policy == SP_BACKGROUND ?
- TIMER_SLACK_BG : TIMER_SLACK_FG);
- }
+ set_timerslack_ns(tid, policy == SP_BACKGROUND ? TIMER_SLACK_BG : TIMER_SLACK_FG);
return 0;
}
diff --git a/logd/Android.mk b/logd/Android.mk
index 9211037..fb51992 100644
--- a/logd/Android.mk
+++ b/logd/Android.mk
@@ -2,12 +2,9 @@
include $(CLEAR_VARS)
-LOCAL_MODULE:= logd
-
-LOCAL_INIT_RC := logd.rc
+LOCAL_MODULE:= liblogd
LOCAL_SRC_FILES := \
- main.cpp \
LogCommand.cpp \
CommandListener.cpp \
LogListener.cpp \
@@ -15,6 +12,7 @@
FlushCommand.cpp \
LogBuffer.cpp \
LogBufferElement.cpp \
+ LogBufferInterface.cpp \
LogTimes.cpp \
LogStatistics.cpp \
LogWhiteBlackList.cpp \
@@ -25,12 +23,9 @@
event.logtags
LOCAL_SHARED_LIBRARIES := \
- libsysutils \
- liblog \
- libcutils \
- libbase \
- libpackagelistparser \
- libcap
+ libbase
+
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
# This is what we want to do:
# event_logtags = $(shell \
@@ -46,6 +41,30 @@
LOCAL_CFLAGS := -Werror $(event_flag)
+include $(BUILD_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE:= logd
+
+LOCAL_INIT_RC := logd.rc
+
+LOCAL_SRC_FILES := \
+ main.cpp
+
+LOCAL_STATIC_LIBRARIES := \
+ liblogd
+
+LOCAL_SHARED_LIBRARIES := \
+ libsysutils \
+ liblog \
+ libcutils \
+ libbase \
+ libpackagelistparser \
+ libcap
+
+LOCAL_CFLAGS := -Werror
+
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h
index 51edd86..e597754 100644
--- a/logd/LogBuffer.h
+++ b/logd/LogBuffer.h
@@ -27,6 +27,7 @@
#include <sysutils/SocketClient.h>
#include "LogBufferElement.h"
+#include "LogBufferInterface.h"
#include "LogStatistics.h"
#include "LogTags.h"
#include "LogTimes.h"
@@ -74,7 +75,7 @@
typedef std::list<LogBufferElement*> LogBufferElementCollection;
-class LogBuffer {
+class LogBuffer : public LogBufferInterface {
LogBufferElementCollection mLogElements;
pthread_rwlock_t mLogElementsLock;
@@ -107,14 +108,14 @@
LastLogTimes& mTimes;
explicit LogBuffer(LastLogTimes* times);
- ~LogBuffer();
+ ~LogBuffer() override;
void init();
bool isMonotonic() {
return monotonic;
}
int log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, pid_t tid,
- const char* msg, unsigned short len);
+ const char* msg, unsigned short len) override;
// lastTid is an optional context to help detect if the last previous
// valid message was from the same source so we can differentiate chatty
// filter types (identical or expired)
diff --git a/logd/LogBufferInterface.cpp b/logd/LogBufferInterface.cpp
new file mode 100644
index 0000000..3cb2b89
--- /dev/null
+++ b/logd/LogBufferInterface.cpp
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2017 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 "LogBufferInterface.h"
+
+LogBufferInterface::LogBufferInterface() {
+}
+LogBufferInterface::~LogBufferInterface() {
+}
\ No newline at end of file
diff --git a/logd/LogBufferInterface.h b/logd/LogBufferInterface.h
new file mode 100644
index 0000000..7d82b91
--- /dev/null
+++ b/logd/LogBufferInterface.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2012-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 _LOGD_LOG_BUFFER_INTERFACE_H__
+#define _LOGD_LOG_BUFFER_INTERFACE_H__
+
+#include <sys/types.h>
+
+#include <android-base/macros.h>
+#include <log/log_id.h>
+#include <log/log_time.h>
+
+// Abstract interface that handles log when log available.
+class LogBufferInterface {
+ public:
+ LogBufferInterface();
+ virtual ~LogBufferInterface();
+ // Handles a log entry when available in LogListener.
+ // Returns the size of the handled log message.
+ virtual int log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid,
+ pid_t tid, const char* msg, unsigned short len) = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LogBufferInterface);
+};
+
+#endif // _LOGD_LOG_BUFFER_INTERFACE_H__
diff --git a/logd/LogListener.cpp b/logd/LogListener.cpp
index dadc75f..709646e 100644
--- a/logd/LogListener.cpp
+++ b/logd/LogListener.cpp
@@ -30,7 +30,7 @@
#include "LogListener.h"
#include "LogUtils.h"
-LogListener::LogListener(LogBuffer* buf, LogReader* reader)
+LogListener::LogListener(LogBufferInterface* buf, LogReader* reader)
: SocketListener(getLogSocket(), false), logbuf(buf), reader(reader) {
}
@@ -102,11 +102,14 @@
// NB: hdr.msg_flags & MSG_TRUNC is not tested, silently passing a
// truncated message to the logs.
- if (logbuf->log((log_id_t)header->id, header->realtime, cred->uid,
- cred->pid, header->tid, msg,
- ((size_t)n <= USHRT_MAX) ? (unsigned short)n : USHRT_MAX) >=
- 0) {
- reader->notifyNewLog();
+ if (logbuf != nullptr) {
+ int res = logbuf->log(
+ (log_id_t)header->id, header->realtime, cred->uid, cred->pid,
+ header->tid, msg,
+ ((size_t)n <= USHRT_MAX) ? (unsigned short)n : USHRT_MAX);
+ if (res > 0 && reader != nullptr) {
+ reader->notifyNewLog();
+ }
}
return true;
diff --git a/logd/LogListener.h b/logd/LogListener.h
index 2973b8b..e16c5fb 100644
--- a/logd/LogListener.h
+++ b/logd/LogListener.h
@@ -21,11 +21,11 @@
#include "LogReader.h"
class LogListener : public SocketListener {
- LogBuffer* logbuf;
+ LogBufferInterface* logbuf;
LogReader* reader;
public:
- LogListener(LogBuffer* buf, LogReader* reader);
+ LogListener(LogBufferInterface* buf, LogReader* reader /* nullable */);
protected:
virtual bool onDataAvailable(SocketClient* cli);