Merge "Add missing host ldlibs"
diff --git a/adb/daemon/main.cpp b/adb/daemon/main.cpp
index 094988a..78434a0 100644
--- a/adb/daemon/main.cpp
+++ b/adb/daemon/main.cpp
@@ -35,7 +35,8 @@
#include <scoped_minijail.h>
#include "debuggerd/client.h"
-#include "private/android_filesystem_config.h"
+#include <private/android_filesystem_config.h>
+#include <private/android_logger.h>
#include "selinux/android.h"
#include "adb.h"
@@ -48,7 +49,7 @@
static void drop_capabilities_bounding_set_if_needed(struct minijail *j) {
#if defined(ALLOW_ADBD_ROOT)
- if (android::base::GetBoolProperty("ro.debuggable", false)) {
+ if (__android_log_is_debuggable()) {
return;
}
#endif
@@ -68,7 +69,7 @@
// ro.secure:
// Drop privileges by default. Set to 1 on userdebug and user builds.
bool ro_secure = android::base::GetBoolProperty("ro.secure", true);
- bool ro_debuggable = android::base::GetBoolProperty("ro.debuggable", false);
+ bool ro_debuggable = __android_log_is_debuggable();
// Drop privileges if ro.secure is set...
bool drop = ro_secure;
diff --git a/adb/services.cpp b/adb/services.cpp
index 0c3dd00..2fbc15a 100644
--- a/adb/services.cpp
+++ b/adb/services.cpp
@@ -38,8 +38,9 @@
#include <cutils/sockets.h>
#if !ADB_HOST
-#include "cutils/android_reboot.h"
#include <android-base/properties.h>
+#include <cutils/android_reboot.h>
+#include <private/android_logger.h>
#endif
#include "adb.h"
@@ -73,7 +74,7 @@
WriteFdExactly(fd, "adbd is already running as root\n");
adb_close(fd);
} else {
- if (!android::base::GetBoolProperty("ro.debuggable", false)) {
+ if (!__android_log_is_debuggable()) {
WriteFdExactly(fd, "adbd cannot run as root in production builds\n");
adb_close(fd);
return;
diff --git a/adb/set_verity_enable_state_service.cpp b/adb/set_verity_enable_state_service.cpp
index ae628e4..f9e028b 100644
--- a/adb/set_verity_enable_state_service.cpp
+++ b/adb/set_verity_enable_state_service.cpp
@@ -26,6 +26,7 @@
#include "android-base/properties.h"
#include "android-base/stringprintf.h"
+#include <private/android_logger.h>
#include "adb.h"
#include "adb_io.h"
@@ -102,8 +103,7 @@
WriteFdFmt(fd, "verity not enabled - ENG build\n");
return;
}
-
- if (!android::base::GetBoolProperty("ro.debuggable", false)) {
+ if (!__android_log_is_debuggable()) {
WriteFdFmt(fd, "verity cannot be disabled/enabled - USER build\n");
return;
}
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/sockets.cpp b/adb/sockets.cpp
index fff6049..3a57174 100644
--- a/adb/sockets.cpp
+++ b/adb/sockets.cpp
@@ -32,6 +32,7 @@
#if !ADB_HOST
#include <android-base/properties.h>
+#include <private/android_logger.h>
#endif
#include "adb.h"
@@ -416,12 +417,7 @@
D("LS(%d): bound to '%s' via %d", s->id, name, fd);
#if !ADB_HOST
- bool debuggable = false;
- if (!strncmp(name, "root:", 5)) {
- debuggable = android::base::GetBoolProperty("ro.debuggable", false);
- }
-
- if ((!strncmp(name, "root:", 5) && getuid() != 0 && debuggable) ||
+ if ((!strncmp(name, "root:", 5) && getuid() != 0 && __android_log_is_debuggable()) ||
(!strncmp(name, "unroot:", 7) && getuid() == 0) ||
!strncmp(name, "usb:", 4) ||
!strncmp(name, "tcpip:", 6)) {
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/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/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/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/Android.mk b/debuggerd/Android.mk
index 1fc850f..155b309 100644
--- a/debuggerd/Android.mk
+++ b/debuggerd/Android.mk
@@ -120,6 +120,7 @@
libbacktrace \
libbase \
libcutils \
+ liblog
debuggerd_c_includes := \
$(LOCAL_PATH)/test \
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..5ae66db 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>
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 c87182e..459e4cc 100644
--- a/debuggerd/tombstone.cpp
+++ b/debuggerd/tombstone.cpp
@@ -32,13 +32,14 @@
#include <memory>
#include <string>
-#include <android/log.h>
#include <android-base/stringprintf.h>
#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>
#include <selinux/android.h>
@@ -622,9 +623,7 @@
static void dump_crash(log_t* log, BacktraceMap* map, pid_t pid, pid_t tid,
const std::set<pid_t>& siblings, uintptr_t abort_msg_address) {
// don't copy log messages to tombstone unless this is a dev device
- char value[PROPERTY_VALUE_MAX];
- property_get("ro.debuggable", value, "0");
- bool want_logs = (value[0] == '1');
+ bool want_logs = __android_log_is_debuggable();
_LOG(log, logtype::HEADER,
"*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n");
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.c b/fs_mgr/fs_mgr.c
index 2ed6b91..d570255 100644
--- a/fs_mgr/fs_mgr.c
+++ b/fs_mgr/fs_mgr.c
@@ -41,6 +41,7 @@
#include <linux/loop.h>
#include <logwrap/logwrap.h>
#include <private/android_filesystem_config.h>
+#include <private/android_logger.h>
#include "fs_mgr_priv.h"
#include "fs_mgr_priv_verity.h"
@@ -260,15 +261,6 @@
return ret;
}
-static int device_is_debuggable() {
- int ret = -1;
- char value[PROP_VALUE_MAX];
- ret = __system_property_get("ro.debuggable", value);
- if (ret < 0)
- return ret;
- return strcmp(value, "1") ? 0 : 1;
-}
-
static int device_is_secure() {
int ret = -1;
char value[PROP_VALUE_MAX];
@@ -537,7 +529,7 @@
if ((fstab->recs[i].fs_mgr_flags & MF_VERIFY) && device_is_secure()) {
int rc = fs_mgr_setup_verity(&fstab->recs[i]);
- if (device_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) {
+ if (__android_log_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) {
INFO("Verity disabled");
} else if (rc != FS_MGR_SETUP_VERITY_SUCCESS) {
ERROR("Could not set up verified partition, skipping!\n");
@@ -699,7 +691,7 @@
if ((fstab->recs[i].fs_mgr_flags & MF_VERIFY) && device_is_secure()) {
int rc = fs_mgr_setup_verity(&fstab->recs[i]);
- if (device_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) {
+ if (__android_log_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) {
INFO("Verity disabled");
} else if (rc != FS_MGR_SETUP_VERITY_SUCCESS) {
ERROR("Could not set up verified partition, skipping!\n");
@@ -903,7 +895,7 @@
{
if ((fstab_rec->fs_mgr_flags & MF_VERIFY) && device_is_secure()) {
int rc = fs_mgr_setup_verity(fstab_rec);
- if (device_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) {
+ if (__android_log_is_debuggable() && rc == FS_MGR_SETUP_VERITY_DISABLED) {
INFO("Verity disabled");
return FS_MGR_EARLY_SETUP_VERITY_NO_VERITY;
} else if (rc == FS_MGR_SETUP_VERITY_SUCCESS) {
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/private/android_logger.h b/include/private/android_logger.h
index 141001c..02764d3 100644
--- a/include/private/android_logger.h
+++ b/include/private/android_logger.h
@@ -21,6 +21,7 @@
/* Android private interfaces */
+#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
@@ -130,6 +131,22 @@
int __android_log_security_bswrite(int32_t tag, const char *payload);
int __android_log_security(); /* Device Owner is present */
+int __android_log_is_debuggable();
+
+#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 __android_logger_property_get_bool(const char *key, int flag);
+
+#define LOG_BUFFER_SIZE (256 * 1024) /* Tuned with ro.logd.size per-platform */
+#define LOG_BUFFER_MIN_SIZE (64 * 1024UL)
+#define LOG_BUFFER_MAX_SIZE (256 * 1024 * 1024UL)
+unsigned long __android_logger_get_buffer_size(log_id_t logId);
+bool __android_logger_valid_buffer_size(unsigned long value);
+
#if defined(__cplusplus)
}
#endif
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/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/include/ziparchive/zip_archive.h b/include/ziparchive/zip_archive.h
index 4f68c3b..fc845a4 100644
--- a/include/ziparchive/zip_archive.h
+++ b/include/ziparchive/zip_archive.h
@@ -130,6 +130,8 @@
int32_t OpenArchiveFd(const int fd, const char* debugFileName,
ZipArchiveHandle *handle, bool assume_ownership = true);
+int32_t OpenArchiveFromMemory(void* address, size_t length, const char* debugFileName,
+ ZipArchiveHandle *handle);
/*
* Close archive, releasing resources associated with it. This will
* unmap the central directory of the zipfile and free all internal
@@ -214,6 +216,17 @@
const char* ErrorCodeString(int32_t error_code);
+#if !defined(_WIN32)
+typedef bool (*ProcessZipEntryFunction)(const uint8_t* buf, size_t buf_size, void* cookie);
+
+/*
+ * Stream the uncompressed data through the supplied function,
+ * passing cookie to it each time it gets called.
+*/
+int32_t ProcessZipEntryContents(ZipArchiveHandle handle, ZipEntry* entry,
+ ProcessZipEntryFunction func, void* cookie);
+#endif
+
__END_DECLS
#endif // LIBZIPARCHIVE_ZIPARCHIVE_H_
diff --git a/init/Android.mk b/init/Android.mk
index 704304e..1be064c 100644
--- a/init/Android.mk
+++ b/init/Android.mk
@@ -82,7 +82,7 @@
LOCAL_STATIC_LIBRARIES := \
libinit \
- libbootloader_message_writer \
+ libbootloader_message \
libfs_mgr \
libfec \
libfec_rs \
diff --git a/init/builtins.cpp b/init/builtins.cpp
index da4b84e..f37ccc2 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -46,7 +46,7 @@
#include <android-base/parseint.h>
#include <android-base/strings.h>
#include <android-base/stringprintf.h>
-#include <bootloader_message_writer.h>
+#include <bootloader_message/bootloader_message.h>
#include <cutils/partition_utils.h>
#include <cutils/android_reboot.h>
#include <ext4_utils/ext4_crypt.h>
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/sched_policy.c b/libcutils/sched_policy.c
index 2cc72a6..cab9263 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__))
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/libcutils/trace-dev.c b/libcutils/trace-dev.c
index dcd9582..113f423 100644
--- a/libcutils/trace-dev.c
+++ b/libcutils/trace-dev.c
@@ -26,10 +26,10 @@
#include <string.h>
#include <sys/types.h>
-#include <android/log.h>
#include <cutils/compiler.h>
#include <cutils/properties.h>
#include <cutils/trace.h>
+#include <private/android_logger.h>
/**
* Maximum size of a message that can be logged to the trace buffer.
@@ -86,16 +86,9 @@
// Determine whether application-level tracing is enabled for this process.
static bool atrace_is_app_tracing_enabled()
{
- bool sys_debuggable = false;
- char value[PROPERTY_VALUE_MAX];
+ bool sys_debuggable = __android_log_is_debuggable();
bool result = false;
- // Check whether the system is debuggable.
- property_get("ro.debuggable", value, "0");
- if (value[0] == '1') {
- sys_debuggable = true;
- }
-
if (sys_debuggable || atrace_is_debuggable) {
// Check whether tracing is enabled for this process.
FILE * file = fopen("/proc/self/cmdline", "re");
diff --git a/libion/ion.c b/libion/ion.c
index 424776a..4565efb 100644
--- a/libion/ion.c
+++ b/libion/ion.c
@@ -27,6 +27,7 @@
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/types.h>
+#include <unistd.h>
#include <android/log.h>
#include <ion/ion.h>
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 7bd1f83..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"
@@ -727,3 +731,8 @@
int logLevel = def;
return logLevel >= 0 && prio >= logLevel;
}
+
+LIBLOG_ABI_PRIVATE int __android_log_is_debuggable()
+{
+ return 1;
+}
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/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/log_is_loggable.c b/liblog/log_is_loggable.c
index 4af8507..132d96f 100644
--- a/liblog/log_is_loggable.c
+++ b/liblog/log_is_loggable.c
@@ -16,12 +16,16 @@
#include <ctype.h>
#include <pthread.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/_system_properties.h>
+#include <unistd.h>
#include <android/log.h>
+#include <log/logger.h>
+#include <private/android_logger.h>
#include "log_portability.h"
@@ -47,12 +51,16 @@
}
struct cache {
- const prop_info *pinfo;
+ const prop_info* pinfo;
uint32_t serial;
+};
+
+struct cache_char {
+ struct cache cache;
unsigned char c;
};
-static int check_cache(struct cache *cache)
+static int check_cache(struct cache* cache)
{
return cache->pinfo
&& __system_property_serial(cache->pinfo) != cache->serial;
@@ -61,18 +69,18 @@
#define BOOLEAN_TRUE 0xFF
#define BOOLEAN_FALSE 0xFE
-static void refresh_cache(struct cache *cache, const char *key)
+static void refresh_cache(struct cache_char* cache, const char* key)
{
char buf[PROP_VALUE_MAX];
- if (!cache->pinfo) {
- cache->pinfo = __system_property_find(key);
- if (!cache->pinfo) {
+ if (!cache->cache.pinfo) {
+ cache->cache.pinfo = __system_property_find(key);
+ if (!cache->cache.pinfo) {
return;
}
}
- cache->serial = __system_property_serial(cache->pinfo);
- __system_property_read(cache->pinfo, 0, buf);
+ cache->cache.serial = __system_property_serial(cache->cache.pinfo);
+ __system_property_read(cache->cache.pinfo, 0, buf);
switch(buf[0]) {
case 't': case 'T':
cache->c = strcasecmp(buf + 1, "rue") ? buf[0] : BOOLEAN_TRUE;
@@ -85,7 +93,7 @@
}
}
-static int __android_log_level(const char *tag, size_t len, int default_prio)
+static int __android_log_level(const char* tag, size_t len, int default_prio)
{
/* sizeof() is used on this array below */
static const char log_namespace[] = "persist.log.tag.";
@@ -93,8 +101,8 @@
/* calculate the size of our key temporary buffer */
const size_t taglen = tag ? len : 0;
/* sizeof(log_namespace) = strlen(log_namespace) + 1 */
- char key[sizeof(log_namespace) + taglen]; /* may be > PROPERTY_KEY_MAX */
- char *kp;
+ char key[sizeof(log_namespace) + taglen]; /* may be > PROP_NAME_MAX */
+ char* kp;
size_t i;
char c = 0;
/*
@@ -110,8 +118,8 @@
static uint32_t global_serial;
/* some compilers erroneously see uninitialized use. !not_locked */
uint32_t current_global_serial = 0;
- static struct cache tag_cache[2];
- static struct cache global_cache[2];
+ static struct cache_char tag_cache[2];
+ static struct cache_char global_cache[2];
int change_detected;
int global_change_detected;
int not_locked;
@@ -125,12 +133,12 @@
* check all known serial numbers to changes.
*/
for (i = 0; i < (sizeof(tag_cache) / sizeof(tag_cache[0])); ++i) {
- if (check_cache(&tag_cache[i])) {
+ if (check_cache(&tag_cache[i].cache)) {
change_detected = 1;
}
}
for (i = 0; i < (sizeof(global_cache) / sizeof(global_cache[0])); ++i) {
- if (check_cache(&global_cache[i])) {
+ if (check_cache(&global_cache[i].cache)) {
global_change_detected = 1;
}
}
@@ -154,7 +162,7 @@
|| ((len < sizeof(last_tag)) && last_tag[len])) {
/* invalidate log.tag.<tag> cache */
for (i = 0; i < (sizeof(tag_cache) / sizeof(tag_cache[0])); ++i) {
- tag_cache[i].pinfo = NULL;
+ tag_cache[i].cache.pinfo = NULL;
tag_cache[i].c = '\0';
}
last_tag[0] = '\0';
@@ -174,11 +182,11 @@
kp = key;
for (i = 0; i < (sizeof(tag_cache) / sizeof(tag_cache[0])); ++i) {
- struct cache *cache = &tag_cache[i];
- struct cache temp_cache;
+ struct cache_char* cache = &tag_cache[i];
+ struct cache_char temp_cache;
if (not_locked) {
- temp_cache.pinfo = NULL;
+ temp_cache.cache.pinfo = NULL;
temp_cache.c = '\0';
cache = &temp_cache;
}
@@ -212,13 +220,13 @@
kp = key;
for (i = 0; i < (sizeof(global_cache) / sizeof(global_cache[0])); ++i) {
- struct cache *cache = &global_cache[i];
- struct cache temp_cache;
+ struct cache_char* cache = &global_cache[i];
+ struct cache_char temp_cache;
if (not_locked) {
temp_cache = *cache;
- if (temp_cache.pinfo != cache->pinfo) { /* check atomic */
- temp_cache.pinfo = NULL;
+ if (temp_cache.cache.pinfo != cache->cache.pinfo) { /* check atomic */
+ temp_cache.cache.pinfo = NULL;
temp_cache.c = '\0';
}
cache = &temp_cache;
@@ -257,7 +265,7 @@
}
LIBLOG_ABI_PUBLIC int __android_log_is_loggable_len(int prio,
- const char *tag, size_t len,
+ const char* tag, size_t len,
int default_prio)
{
int logLevel = __android_log_level(tag, len, default_prio);
@@ -265,7 +273,7 @@
}
LIBLOG_ABI_PUBLIC int __android_log_is_loggable(int prio,
- const char *tag,
+ const char* tag,
int default_prio)
{
int logLevel = __android_log_level(tag,
@@ -274,21 +282,21 @@
return logLevel >= 0 && prio >= logLevel;
}
-LIBLOG_HIDDEN int __android_log_is_debuggable()
+LIBLOG_ABI_PRIVATE int __android_log_is_debuggable()
{
static uint32_t serial;
- static struct cache tag_cache;
+ static struct cache_char tag_cache;
static const char key[] = "ro.debuggable";
int ret;
if (tag_cache.c) { /* ro property does not change after set */
ret = tag_cache.c == '1';
} else if (lock()) {
- struct cache temp_cache = { NULL, -1, '\0' };
+ struct cache_char temp_cache = { { NULL, -1 }, '\0' };
refresh_cache(&temp_cache, key);
ret = temp_cache.c == '1';
} else {
- int change_detected = check_cache(&tag_cache);
+ int change_detected = check_cache(&tag_cache.cache);
uint32_t current_serial = __system_property_area_serial();
if (current_serial != serial) {
change_detected = 1;
@@ -310,17 +318,17 @@
* Since a change is rare, we will accept a trylock failure gracefully.
* Use a separate lock from is_loggable to keep contention down b/25563384.
*/
-struct cache2 {
+struct cache2_char {
pthread_mutex_t lock;
uint32_t serial;
- const char *key_persist;
- struct cache cache_persist;
- const char *key_ro;
- struct cache cache_ro;
- unsigned char (*const evaluate)(const struct cache2 *self);
+ const char* key_persist;
+ struct cache_char cache_persist;
+ const char* key_ro;
+ struct cache_char cache_ro;
+ unsigned char (*const evaluate)(const struct cache2_char *self);
};
-static inline unsigned char do_cache2(struct cache2 *self)
+static inline unsigned char do_cache2_char(struct cache2_char *self)
{
uint32_t current_serial;
int change_detected;
@@ -331,8 +339,8 @@
return self->evaluate(self);
}
- change_detected = check_cache(&self->cache_persist)
- || check_cache(&self->cache_ro);
+ change_detected = check_cache(&self->cache_persist.cache)
+ || check_cache(&self->cache_ro.cache);
current_serial = __system_property_area_serial();
if (current_serial != self->serial) {
change_detected = 1;
@@ -349,7 +357,7 @@
return c;
}
-static unsigned char evaluate_persist_ro(const struct cache2 *self)
+static unsigned char evaluate_persist_ro(const struct cache2_char *self)
{
unsigned char c = self->cache_persist.c;
@@ -366,17 +374,17 @@
*/
LIBLOG_ABI_PUBLIC clockid_t android_log_clockid()
{
- static struct cache2 clockid = {
+ static struct cache2_char clockid = {
PTHREAD_MUTEX_INITIALIZER,
0,
"persist.logd.timestamp",
- { NULL, -1, '\0' },
+ { { NULL, -1 }, '\0' },
"ro.logd.timestamp",
- { NULL, -1, '\0' },
+ { { NULL, -1 }, '\0' },
evaluate_persist_ro
};
- return (tolower(do_cache2(&clockid)) == 'm')
+ return (tolower(do_cache2_char(&clockid)) == 'm')
? CLOCK_MONOTONIC
: CLOCK_REALTIME;
}
@@ -385,7 +393,7 @@
* Security state generally remains constant, but the DO must be able
* to turn off logging should it become spammy after an attack is detected.
*/
-static unsigned char evaluate_security(const struct cache2 *self)
+static unsigned char evaluate_security(const struct cache2_char *self)
{
unsigned char c = self->cache_ro.c;
@@ -394,15 +402,265 @@
LIBLOG_ABI_PUBLIC int __android_log_security()
{
- static struct cache2 security = {
+ static struct cache2_char security = {
PTHREAD_MUTEX_INITIALIZER,
0,
"persist.logd.security",
- { NULL, -1, BOOLEAN_FALSE },
+ { { NULL, -1 }, BOOLEAN_FALSE },
"ro.device_owner",
- { NULL, -1, BOOLEAN_FALSE },
+ { { NULL, -1 }, BOOLEAN_FALSE },
evaluate_security
};
- return do_cache2(&security);
+ return do_cache2_char(&security);
+}
+
+/*
+ * Interface that represents the logd buffer size determination so that others
+ * need not guess our intentions.
+ */
+
+/* Property helper */
+static bool check_flag(const char* prop, const char* flag) {
+ const char* cp = strcasestr(prop, flag);
+ if (!cp) {
+ return false;
+ }
+ /* We only will document comma (,) */
+ static const char sep[] = ",:;|+ \t\f";
+ if ((cp != prop) && !strchr(sep, cp[-1])) {
+ return false;
+ }
+ cp += strlen(flag);
+ return !*cp || !!strchr(sep, *cp);
+}
+
+/* cache structure */
+struct cache_property {
+ struct cache cache;
+ char property[PROP_VALUE_MAX];
+};
+
+static void refresh_cache_property(struct cache_property* cache, const char* key)
+{
+ if (!cache->cache.pinfo) {
+ cache->cache.pinfo = __system_property_find(key);
+ if (!cache->cache.pinfo) {
+ return;
+ }
+ }
+ cache->cache.serial = __system_property_serial(cache->cache.pinfo);
+ __system_property_read(cache->cache.pinfo, 0, cache->property);
+}
+
+/* get boolean with the logger twist that supports eng adjustments */
+LIBLOG_ABI_PRIVATE bool __android_logger_property_get_bool(const char* key,
+ int flag)
+{
+ struct cache_property property = { { NULL, -1 }, { 0 } };
+ if (flag & BOOL_DEFAULT_FLAG_PERSIST) {
+ char newkey[PROP_NAME_MAX];
+ snprintf(newkey, sizeof(newkey), "ro.%s", key);
+ refresh_cache_property(&property, newkey);
+ property.cache.pinfo = NULL;
+ property.cache.serial = -1;
+ snprintf(newkey, sizeof(newkey), "persist.%s", key);
+ refresh_cache_property(&property, newkey);
+ property.cache.pinfo = NULL;
+ property.cache.serial = -1;
+ }
+
+ refresh_cache_property(&property, key);
+
+ if (check_flag(property.property, "true")) {
+ return true;
+ }
+ if (check_flag(property.property, "false")) {
+ return false;
+ }
+ if (check_flag(property.property, "eng")) {
+ flag |= BOOL_DEFAULT_FLAG_ENG;
+ }
+ /* this is really a "not" flag */
+ if (check_flag(property.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)
+ && __android_logger_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;
+}
+
+LIBLOG_ABI_PRIVATE bool __android_logger_valid_buffer_size(unsigned long value)
+{
+ static long pages, pagesize;
+ unsigned long maximum;
+
+ if ((value < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < value)) {
+ return false;
+ }
+
+ if (!pages) {
+ pages = sysconf(_SC_PHYS_PAGES);
+ }
+ if (pages < 1) {
+ return true;
+ }
+
+ if (!pagesize) {
+ pagesize = sysconf(_SC_PAGESIZE);
+ if (pagesize <= 1) {
+ pagesize = PAGE_SIZE;
+ }
+ }
+
+ /* maximum memory impact a somewhat arbitrary ~3% */
+ pages = (pages + 31) / 32;
+ maximum = pages * pagesize;
+
+ if ((maximum < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < maximum)) {
+ return true;
+ }
+
+ return value <= maximum;
+}
+
+struct cache2_property_size {
+ pthread_mutex_t lock;
+ uint32_t serial;
+ const char* key_persist;
+ struct cache_property cache_persist;
+ const char* key_ro;
+ struct cache_property cache_ro;
+ unsigned long (*const evaluate)(const struct cache2_property_size* self);
+};
+
+static inline unsigned long do_cache2_property_size(struct cache2_property_size* self)
+{
+ uint32_t current_serial;
+ int change_detected;
+ unsigned long v;
+
+ if (pthread_mutex_trylock(&self->lock)) {
+ /* We are willing to accept some race in this context */
+ return self->evaluate(self);
+ }
+
+ change_detected = check_cache(&self->cache_persist.cache)
+ || check_cache(&self->cache_ro.cache);
+ current_serial = __system_property_area_serial();
+ if (current_serial != self->serial) {
+ change_detected = 1;
+ }
+ if (change_detected) {
+ refresh_cache_property(&self->cache_persist, self->key_persist);
+ refresh_cache_property(&self->cache_ro, self->key_ro);
+ self->serial = current_serial;
+ }
+ v = self->evaluate(self);
+
+ pthread_mutex_unlock(&self->lock);
+
+ return v;
+}
+
+static unsigned long property_get_size_from_cache(const struct cache_property* cache)
+{
+ char* cp;
+ unsigned long value = strtoul(cache->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 (!__android_logger_valid_buffer_size(value)) {
+ value = 0;
+ }
+
+ return value;
+}
+
+static unsigned long evaluate_property_get_size(const struct cache2_property_size* self)
+{
+ unsigned long size = property_get_size_from_cache(&self->cache_persist);
+ if (size) {
+ return size;
+ }
+ return property_get_size_from_cache(&self->cache_ro);
+}
+
+LIBLOG_ABI_PRIVATE unsigned long __android_logger_get_buffer_size(log_id_t logId)
+{
+ static const char global_tunable[] = "persist.logd.size"; /* Settings App */
+ static const char global_default[] = "ro.logd.size"; /* BoardConfig.mk */
+ static struct cache2_property_size global = {
+ PTHREAD_MUTEX_INITIALIZER,
+ 0,
+ global_tunable,
+ { { NULL, -1 }, {} },
+ global_default,
+ { { NULL, -1 }, {} },
+ evaluate_property_get_size
+ };
+ char key_persist[PROP_NAME_MAX];
+ char key_ro[PROP_NAME_MAX];
+ struct cache2_property_size local = {
+ PTHREAD_MUTEX_INITIALIZER,
+ 0,
+ key_persist,
+ { { NULL, -1 }, {} },
+ key_ro,
+ { { NULL, -1 }, {} },
+ evaluate_property_get_size
+ };
+ unsigned long property_size, default_size;
+
+ default_size = do_cache2_property_size(&global);
+ if (!default_size) {
+ default_size = __android_logger_property_get_bool("ro.config.low_ram",
+ BOOL_DEFAULT_FALSE)
+ ? LOG_BUFFER_MIN_SIZE /* 64K */
+ : LOG_BUFFER_SIZE; /* 256K */
+ }
+
+ snprintf(key_persist, sizeof(key_persist), "%s.%s",
+ global_tunable, android_log_id_to_name(logId));
+ snprintf(key_ro, sizeof(key_ro), "%s.%s",
+ global_default, android_log_id_to_name(logId));
+ property_size = do_cache2_property_size(&local);
+
+ if (!property_size) {
+ property_size = default_size;
+ }
+
+ if (!property_size) {
+ property_size = LOG_BUFFER_SIZE;
+ }
+
+ return property_size;
}
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 d4f243a..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"
@@ -157,7 +157,6 @@
LIBLOG_HIDDEN void __android_log_lock();
LIBLOG_HIDDEN int __android_log_trylock();
LIBLOG_HIDDEN void __android_log_unlock();
-LIBLOG_HIDDEN int __android_log_is_debuggable();
__END_DECLS
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/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..52f28af 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>
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/testdata/dummy-update.zip b/libziparchive/testdata/dummy-update.zip
new file mode 100644
index 0000000..6976bf1
--- /dev/null
+++ b/libziparchive/testdata/dummy-update.zip
Binary files differ
diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc
index cc3f0e4..d36cc3f 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"
@@ -215,19 +217,14 @@
return 0;
}
-static int32_t MapCentralDirectory0(int fd, const char* debug_file_name,
- ZipArchive* archive, off64_t file_length,
- off64_t read_amount, uint8_t* scan_buffer) {
+static int32_t MapCentralDirectory0(const char* debug_file_name, ZipArchive* archive,
+ off64_t file_length, off64_t read_amount,
+ uint8_t* scan_buffer) {
const off64_t search_start = file_length - read_amount;
- if (lseek64(fd, search_start, SEEK_SET) != search_start) {
- ALOGW("Zip: seek %" PRId64 " failed: %s", static_cast<int64_t>(search_start),
- strerror(errno));
- return kIoError;
- }
- if (!android::base::ReadFully(fd, scan_buffer, static_cast<size_t>(read_amount))) {
- ALOGW("Zip: read %" PRId64 " failed: %s", static_cast<int64_t>(read_amount),
- strerror(errno));
+ if(!archive->mapped_zip.ReadAtOffset(scan_buffer, read_amount, search_start)) {
+ ALOGE("Zip: read %" PRId64 " from offset %" PRId64 " failed",
+ static_cast<int64_t>(read_amount), static_cast<int64_t>(search_start));
return kIoError;
}
@@ -287,9 +284,11 @@
* It all looks good. Create a mapping for the CD, and set the fields
* in archive.
*/
- if (!archive->directory_map.create(debug_file_name, fd,
- static_cast<off64_t>(eocd->cd_start_offset),
- static_cast<size_t>(eocd->cd_size), true /* read only */) ) {
+
+ if (!archive->InitializeCentralDirectory(debug_file_name,
+ static_cast<off64_t>(eocd->cd_start_offset),
+ static_cast<size_t>(eocd->cd_size))) {
+ ALOGE("Zip: failed to intialize central directory.\n");
return kMmapFailed;
}
@@ -304,18 +303,16 @@
*
* On success, returns 0 after populating fields from the EOCD area:
* directory_offset
- * directory_map
+ * directory_ptr
* num_entries
*/
-static int32_t MapCentralDirectory(int fd, const char* debug_file_name,
- ZipArchive* archive) {
+static int32_t MapCentralDirectory(const char* debug_file_name, ZipArchive* archive) {
// Test file length. We use lseek64 to make sure the file
// is small enough to be a zip file (Its size must be less than
// 0xffffffff bytes).
- off64_t file_length = lseek64(fd, 0, SEEK_END);
+ off64_t file_length = archive->mapped_zip.GetFileLength();
if (file_length == -1) {
- ALOGV("Zip: lseek on fd %d failed", fd);
return kInvalidFile;
}
@@ -346,11 +343,9 @@
read_amount = file_length;
}
- uint8_t* scan_buffer = reinterpret_cast<uint8_t*>(malloc(read_amount));
- int32_t result = MapCentralDirectory0(fd, debug_file_name, archive,
- file_length, read_amount, scan_buffer);
-
- free(scan_buffer);
+ std::vector<uint8_t> scan_buffer(read_amount);
+ int32_t result = MapCentralDirectory0(debug_file_name, archive, file_length, read_amount,
+ scan_buffer.data());
return result;
}
@@ -361,9 +356,8 @@
* Returns 0 on success.
*/
static int32_t ParseZipArchive(ZipArchive* archive) {
- const uint8_t* const cd_ptr =
- reinterpret_cast<const uint8_t*>(archive->directory_map.getDataPtr());
- const size_t cd_length = archive->directory_map.getDataLength();
+ const uint8_t* const cd_ptr = archive->central_directory.GetBasePtr();
+ const size_t cd_length = archive->central_directory.GetMapLength();
const uint16_t num_entries = archive->num_entries;
/*
@@ -437,7 +431,7 @@
static int32_t OpenArchiveInternal(ZipArchive* archive,
const char* debug_file_name) {
int32_t result = -1;
- if ((result = MapCentralDirectory(archive->fd, debug_file_name, archive))) {
+ if ((result = MapCentralDirectory(debug_file_name, archive)) != 0) {
return result;
}
@@ -468,6 +462,13 @@
return OpenArchiveInternal(archive, fileName);
}
+int32_t OpenArchiveFromMemory(void* address, size_t length, const char* debug_file_name,
+ ZipArchiveHandle *handle) {
+ ZipArchive* archive = new ZipArchive(address, length);
+ *handle = archive;
+ return OpenArchiveInternal(archive, debug_file_name);
+}
+
/*
* Close a ZipArchive, closing the file and freeing the contents.
*/
@@ -477,10 +478,10 @@
delete archive;
}
-static int32_t UpdateEntryFromDataDescriptor(int fd,
+static int32_t UpdateEntryFromDataDescriptor(MappedZipFile& mapped_zip,
ZipEntry *entry) {
uint8_t ddBuf[sizeof(DataDescriptor) + sizeof(DataDescriptor::kOptSignature)];
- if (!android::base::ReadFully(fd, ddBuf, sizeof(ddBuf))) {
+ if (!mapped_zip.ReadData(ddBuf, sizeof(ddBuf))) {
return kIoError;
}
@@ -495,23 +496,6 @@
return 0;
}
-// Attempts to read |len| bytes into |buf| at offset |off|.
-// On non-Windows platforms, callers are guaranteed that the |fd|
-// offset is unchanged and there is no side effect to this call.
-//
-// On Windows platforms this is not thread-safe.
-static inline bool ReadAtOffset(int fd, uint8_t* buf, size_t len, off64_t off) {
-#if !defined(_WIN32)
- return TEMP_FAILURE_RETRY(pread64(fd, buf, len, off));
-#else
- if (lseek64(fd, off, SEEK_SET) != off) {
- ALOGW("Zip: failed seek to offset %" PRId64, off);
- return false;
- }
- return android::base::ReadFully(fd, buf, len);
-#endif
-}
-
static int32_t FindEntry(const ZipArchive* archive, const int ent,
ZipEntry* data) {
const uint16_t nameLen = archive->hash_table[ent].name_length;
@@ -525,9 +509,8 @@
// This is the base of our mmapped region, we have to sanity check that
// the name that's in the hash table is a pointer to a location within
// this mapped region.
- const uint8_t* base_ptr = reinterpret_cast<const uint8_t*>(
- archive->directory_map.getDataPtr());
- if (ptr < base_ptr || ptr > base_ptr + archive->directory_map.getDataLength()) {
+ const uint8_t* base_ptr = archive->central_directory.GetBasePtr();
+ if (ptr < base_ptr || ptr > base_ptr + archive->central_directory.GetMapLength()) {
ALOGW("Zip: Invalid entry pointer");
return kInvalidOffset;
}
@@ -559,7 +542,7 @@
}
uint8_t lfh_buf[sizeof(LocalFileHeader)];
- if (!ReadAtOffset(archive->fd, lfh_buf, sizeof(lfh_buf), local_header_offset)) {
+ if (!archive->mapped_zip.ReadAtOffset(lfh_buf, sizeof(lfh_buf), local_header_offset)) {
ALOGW("Zip: failed reading lfh name from offset %" PRId64,
static_cast<int64_t>(local_header_offset));
return kIoError;
@@ -599,19 +582,16 @@
return kInvalidOffset;
}
- uint8_t* name_buf = reinterpret_cast<uint8_t*>(malloc(nameLen));
- if (!ReadAtOffset(archive->fd, name_buf, nameLen, name_offset)) {
+ std::vector<uint8_t> name_buf(nameLen);
+ if (!archive->mapped_zip.ReadAtOffset(name_buf.data(), nameLen, name_offset)) {
ALOGW("Zip: failed reading lfh name from offset %" PRId64, static_cast<int64_t>(name_offset));
- free(name_buf);
return kIoError;
}
- if (memcmp(archive->hash_table[ent].name, name_buf, nameLen)) {
- free(name_buf);
+ if (memcmp(archive->hash_table[ent].name, name_buf.data(), nameLen)) {
return kInconsistentInformation;
}
- free(name_buf);
} else {
ALOGW("Zip: lfh name did not match central directory.");
return kInconsistentInformation;
@@ -881,7 +861,7 @@
}
#pragma GCC diagnostic pop
-static int32_t InflateEntryToWriter(int fd, const ZipEntry* entry,
+static int32_t InflateEntryToWriter(MappedZipFile& mapped_zip, const ZipEntry* entry,
Writer* writer, uint64_t* crc_out) {
const size_t kBufSize = 32768;
std::vector<uint8_t> read_buf(kBufSize);
@@ -931,7 +911,7 @@
/* read as much as we can */
if (zstream.avail_in == 0) {
const size_t getSize = (compressed_length > kBufSize) ? kBufSize : compressed_length;
- if (!android::base::ReadFully(fd, read_buf.data(), getSize)) {
+ if (!mapped_zip.ReadData(read_buf.data(), getSize)) {
ALOGW("Zip: inflate read failed, getSize = %zu: %s", getSize, strerror(errno));
return kIoError;
}
@@ -979,7 +959,7 @@
return 0;
}
-static int32_t CopyEntryToWriter(int fd, const ZipEntry* entry, Writer* writer,
+static int32_t CopyEntryToWriter(MappedZipFile& mapped_zip, const ZipEntry* entry, Writer* writer,
uint64_t *crc_out) {
static const uint32_t kBufSize = 32768;
std::vector<uint8_t> buf(kBufSize);
@@ -993,7 +973,7 @@
// Safe conversion because kBufSize is narrow enough for a 32 bit signed
// value.
const size_t block_size = (remaining > kBufSize) ? kBufSize : remaining;
- if (!android::base::ReadFully(fd, buf.data(), block_size)) {
+ if (!mapped_zip.ReadData(buf.data(), block_size)) {
ALOGW("CopyFileToFile: copy read failed, block_size = %zu: %s", block_size, strerror(errno));
return kIoError;
}
@@ -1016,7 +996,7 @@
const uint16_t method = entry->method;
off64_t data_offset = entry->offset;
- if (lseek64(archive->fd, data_offset, SEEK_SET) != data_offset) {
+ if (!archive->mapped_zip.SeekToOffset(data_offset)) {
ALOGW("Zip: lseek to data at %" PRId64 " failed", static_cast<int64_t>(data_offset));
return kIoError;
}
@@ -1025,13 +1005,13 @@
int32_t return_value = -1;
uint64_t crc = 0;
if (method == kCompressStored) {
- return_value = CopyEntryToWriter(archive->fd, entry, writer, &crc);
+ return_value = CopyEntryToWriter(archive->mapped_zip, entry, writer, &crc);
} else if (method == kCompressDeflated) {
- return_value = InflateEntryToWriter(archive->fd, entry, writer, &crc);
+ return_value = InflateEntryToWriter(archive->mapped_zip, entry, writer, &crc);
}
if (!return_value && entry->has_data_descriptor) {
- return_value = UpdateEntryFromDataDescriptor(archive->fd, entry);
+ return_value = UpdateEntryFromDataDescriptor(archive->mapped_zip, entry);
if (return_value) {
return return_value;
}
@@ -1072,7 +1052,7 @@
}
int GetFileDescriptor(const ZipArchiveHandle handle) {
- return reinterpret_cast<ZipArchive*>(handle)->fd;
+ return reinterpret_cast<ZipArchive*>(handle)->mapped_zip.GetFileDescriptor();
}
ZipString::ZipString(const char* entry_name)
@@ -1081,3 +1061,143 @@
CHECK_LE(len, static_cast<size_t>(UINT16_MAX));
name_length = static_cast<uint16_t>(len);
}
+
+#if !defined(_WIN32)
+class ProcessWriter : public Writer {
+ public:
+ ProcessWriter(ProcessZipEntryFunction func, void* cookie) : Writer(),
+ proc_function_(func),
+ cookie_(cookie) {
+ }
+
+ virtual bool Append(uint8_t* buf, size_t buf_size) override {
+ return proc_function_(buf, buf_size, cookie_);
+ }
+
+ private:
+ ProcessZipEntryFunction proc_function_;
+ void* cookie_;
+};
+
+int32_t ProcessZipEntryContents(ZipArchiveHandle handle, ZipEntry* entry,
+ ProcessZipEntryFunction func, void* cookie) {
+ ProcessWriter writer(func, cookie);
+ return ExtractToWriter(handle, entry, &writer);
+}
+
+#endif //!defined(_WIN32)
+
+int MappedZipFile::GetFileDescriptor() const {
+ if (!has_fd_) {
+ ALOGW("Zip: MappedZipFile doesn't have a file descriptor.");
+ return -1;
+ }
+ return fd_;
+}
+
+void* MappedZipFile::GetBasePtr() const {
+ if (has_fd_) {
+ ALOGW("Zip: MappedZipFile doesn't have a base pointer.");
+ return nullptr;
+ }
+ return base_ptr_;
+}
+
+off64_t MappedZipFile::GetFileLength() const {
+ if (has_fd_) {
+ off64_t result = lseek64(fd_, 0, SEEK_END);
+ if (result == -1) {
+ ALOGE("Zip: lseek on fd %d failed: %s", fd_, strerror(errno));
+ }
+ return result;
+ } else {
+ if (base_ptr_ == nullptr) {
+ ALOGE("Zip: invalid file map\n");
+ return -1;
+ }
+ return static_cast<off64_t>(data_length_);
+ }
+}
+
+bool MappedZipFile::SeekToOffset(off64_t offset) {
+ if (has_fd_) {
+ if (lseek64(fd_, offset, SEEK_SET) != offset) {
+ ALOGE("Zip: lseek to %" PRId64 " failed: %s\n", offset, strerror(errno));
+ return false;
+ }
+ return true;
+ } else {
+ if (offset < 0 || offset > static_cast<off64_t>(data_length_)) {
+ ALOGE("Zip: invalid offset: %" PRId64 ", data length: %" PRId64 "\n" , offset,
+ data_length_);
+ return false;
+ }
+
+ read_pos_ = offset;
+ return true;
+ }
+}
+
+bool MappedZipFile::ReadData(uint8_t* buffer, size_t read_amount) {
+ if (has_fd_) {
+ if(!android::base::ReadFully(fd_, buffer, read_amount)) {
+ ALOGE("Zip: read from %d failed\n", fd_);
+ return false;
+ }
+ } else {
+ memcpy(buffer, static_cast<uint8_t*>(base_ptr_) + read_pos_, read_amount);
+ read_pos_ += read_amount;
+ }
+ return true;
+}
+
+// Attempts to read |len| bytes into |buf| at offset |off|.
+bool MappedZipFile::ReadAtOffset(uint8_t* buf, size_t len, off64_t off) {
+#if !defined(_WIN32)
+ if (has_fd_) {
+ if (static_cast<size_t>(TEMP_FAILURE_RETRY(pread64(fd_, buf, len, off))) != len) {
+ ALOGE("Zip: failed to read at offset %" PRId64 "\n", off);
+ return false;
+ }
+ return true;
+ }
+#endif
+ if (!SeekToOffset(off)) {
+ return false;
+ }
+ return ReadData(buf, len);
+
+}
+
+void CentralDirectory::Initialize(void* map_base_ptr, off64_t cd_start_offset, size_t cd_size) {
+ base_ptr_ = static_cast<uint8_t*>(map_base_ptr) + cd_start_offset;
+ length_ = cd_size;
+}
+
+bool ZipArchive::InitializeCentralDirectory(const char* debug_file_name, off64_t cd_start_offset,
+ size_t cd_size) {
+ if (mapped_zip.HasFd()) {
+ if (!directory_map->create(debug_file_name, mapped_zip.GetFileDescriptor(),
+ cd_start_offset, cd_size, true /* read only */)) {
+ return false;
+ }
+
+ CHECK_EQ(directory_map->getDataLength(), cd_size);
+ central_directory.Initialize(directory_map->getDataPtr(), 0/*offset*/, cd_size);
+ } else {
+ if (mapped_zip.GetBasePtr() == nullptr) {
+ ALOGE("Zip: Failed to map central directory, bad mapped_zip base pointer\n");
+ return false;
+ }
+ if (static_cast<off64_t>(cd_start_offset) + static_cast<off64_t>(cd_size) >
+ mapped_zip.GetFileLength()) {
+ ALOGE("Zip: Failed to map central directory, offset exceeds mapped memory region ("
+ "start_offset %" PRId64 ", cd_size %zu, mapped_region_size %" PRId64 ")",
+ static_cast<int64_t>(cd_start_offset), cd_size, mapped_zip.GetFileLength());
+ return false;
+ }
+
+ central_directory.Initialize(mapped_zip.GetBasePtr(), cd_start_offset, cd_size);
+ }
+ return true;
+}
diff --git a/libziparchive/zip_archive_private.h b/libziparchive/zip_archive_private.h
index ab52368..971db4f 100644
--- a/libziparchive/zip_archive_private.h
+++ b/libziparchive/zip_archive_private.h
@@ -21,17 +21,83 @@
#include <stdlib.h>
#include <unistd.h>
+#include <memory>
+#include <vector>
+
#include <utils/FileMap.h>
#include <ziparchive/zip_archive.h>
+class MappedZipFile {
+ public:
+ explicit MappedZipFile(const int fd) :
+ has_fd_(true),
+ fd_(fd),
+ base_ptr_(nullptr),
+ data_length_(0),
+ read_pos_(0) {}
+
+ explicit MappedZipFile(void* address, size_t length) :
+ has_fd_(false),
+ fd_(-1),
+ base_ptr_(address),
+ data_length_(static_cast<off64_t>(length)),
+ read_pos_(0) {}
+
+ bool HasFd() const {return has_fd_;}
+
+ int GetFileDescriptor() const;
+
+ void* GetBasePtr() const;
+
+ off64_t GetFileLength() const;
+
+ bool SeekToOffset(off64_t offset);
+
+ bool ReadData(uint8_t* buffer, size_t read_amount);
+
+ bool ReadAtOffset(uint8_t* buf, size_t len, off64_t off);
+
+ private:
+ // If has_fd_ is true, fd is valid and we'll read contents of a zip archive
+ // from the file. Otherwise, we're opening the archive from a memory mapped
+ // file. In that case, base_ptr_ points to the start of the memory region and
+ // data_length_ defines the file length.
+ const bool has_fd_;
+
+ const int fd_;
+
+ void* const base_ptr_;
+ const off64_t data_length_;
+ // read_pos_ is the offset to the base_ptr_ where we read data from.
+ size_t read_pos_;
+};
+
+class CentralDirectory {
+ public:
+ CentralDirectory(void) :
+ base_ptr_(nullptr),
+ length_(0) {}
+
+ const uint8_t* GetBasePtr() const {return base_ptr_;}
+
+ size_t GetMapLength() const {return length_;}
+
+ void Initialize(void* map_base_ptr, off64_t cd_start_offset, size_t cd_size);
+
+ private:
+ const uint8_t* base_ptr_;
+ size_t length_;
+};
+
struct ZipArchive {
// open Zip archive
- const int fd;
+ mutable MappedZipFile mapped_zip;
const bool close_file;
// mapped central directory area
off64_t directory_offset;
- android::FileMap directory_map;
+ CentralDirectory central_directory;
+ std::unique_ptr<android::FileMap> directory_map;
// number of entries in the Zip archive
uint16_t num_entries;
@@ -44,20 +110,36 @@
ZipString* hash_table;
ZipArchive(const int fd, bool assume_ownership) :
- fd(fd),
- close_file(assume_ownership),
- directory_offset(0),
- num_entries(0),
- hash_table_size(0),
- hash_table(NULL) {}
+ mapped_zip(fd),
+ close_file(assume_ownership),
+ directory_offset(0),
+ central_directory(),
+ directory_map(new android::FileMap()),
+ num_entries(0),
+ hash_table_size(0),
+ hash_table(nullptr) {}
+
+ ZipArchive(void* address, size_t length) :
+ mapped_zip(address, length),
+ close_file(false),
+ directory_offset(0),
+ central_directory(),
+ directory_map(new android::FileMap()),
+ num_entries(0),
+ hash_table_size(0),
+ hash_table(nullptr) {}
~ZipArchive() {
- if (close_file && fd >= 0) {
- close(fd);
+ if (close_file && mapped_zip.GetFileDescriptor() >= 0) {
+ close(mapped_zip.GetFileDescriptor());
}
free(hash_table);
}
+
+ bool InitializeCentralDirectory(const char* debug_file_name, off64_t cd_start_offset,
+ size_t cd_size);
+
};
#endif // LIBZIPARCHIVE_ZIPARCHIVE_PRIVATE_H_
diff --git a/libziparchive/zip_archive_stream_entry.cc b/libziparchive/zip_archive_stream_entry.cc
index 41988bc..64b24c3 100644
--- a/libziparchive/zip_archive_stream_entry.cc
+++ b/libziparchive/zip_archive_stream_entry.cc
@@ -39,7 +39,7 @@
bool ZipArchiveStreamEntry::Init(const ZipEntry& entry) {
ZipArchive* archive = reinterpret_cast<ZipArchive*>(handle_);
off64_t data_offset = entry.offset;
- if (lseek64(archive->fd, data_offset, SEEK_SET) != data_offset) {
+ if (!archive->mapped_zip.SeekToOffset(data_offset)) {
ALOGW("lseek to data at %" PRId64 " failed: %s", data_offset, strerror(errno));
return false;
}
@@ -88,7 +88,7 @@
size_t bytes = (length_ > data_.size()) ? data_.size() : length_;
ZipArchive* archive = reinterpret_cast<ZipArchive*>(handle_);
errno = 0;
- if (!android::base::ReadFully(archive->fd, data_.data(), bytes)) {
+ if (!archive->mapped_zip.ReadData(data_.data(), bytes)) {
if (errno != 0) {
ALOGE("Error reading from archive fd: %s", strerror(errno));
} else {
@@ -209,7 +209,7 @@
size_t bytes = (compressed_length_ > in_.size()) ? in_.size() : compressed_length_;
ZipArchive* archive = reinterpret_cast<ZipArchive*>(handle_);
errno = 0;
- if (!android::base::ReadFully(archive->fd, in_.data(), bytes)) {
+ if (!archive->mapped_zip.ReadData(in_.data(), bytes)) {
if (errno != 0) {
ALOGE("Error reading from archive fd: %s", strerror(errno));
} else {
diff --git a/libziparchive/zip_archive_test.cc b/libziparchive/zip_archive_test.cc
index 6aee1bb..9dd6cc0 100644
--- a/libziparchive/zip_archive_test.cc
+++ b/libziparchive/zip_archive_test.cc
@@ -26,7 +26,9 @@
#include <android-base/file.h>
#include <android-base/test_utils.h>
+#include <android-base/unique_fd.h>
#include <gtest/gtest.h>
+#include <utils/FileMap.h>
#include <ziparchive/zip_archive.h>
#include <ziparchive/zip_archive_stream_entry.h>
@@ -36,6 +38,7 @@
static const std::string kValidZip = "valid.zip";
static const std::string kLargeZip = "large.zip";
static const std::string kBadCrcZip = "bad_crc.zip";
+static const std::string kUpdateZip = "dummy-update.zip";
static const std::vector<uint8_t> kATxtContents {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
@@ -494,6 +497,32 @@
lseek64(tmp_file.fd, 0, SEEK_END));
}
+#if !defined(_WIN32)
+TEST(ziparchive, OpenFromMemory) {
+ const std::string zip_path = test_data_dir + "/" + kUpdateZip;
+ android::base::unique_fd fd(open(zip_path.c_str(), O_RDONLY | O_BINARY));
+ ASSERT_NE(-1, fd);
+ struct stat sb;
+ ASSERT_EQ(0, fstat(fd, &sb));
+
+ // Memory map the file first and open the archive from the memory region.
+ android::FileMap file_map;
+ file_map.create(zip_path.c_str(), fd, 0/*offset*/, sb.st_size, true);
+ ZipArchiveHandle handle;
+ ASSERT_EQ(0, OpenArchiveFromMemory(file_map.getDataPtr(), file_map.getDataLength(),
+ zip_path.c_str(), &handle));
+
+ // Assert one entry can be found and extracted correctly.
+ std::string BINARY_PATH("META-INF/com/google/android/update-binary");
+ ZipString binary_path(BINARY_PATH.c_str());
+ ZipEntry binary_entry;
+ ASSERT_EQ(0, FindEntry(handle, binary_path, &binary_entry));
+ TemporaryFile tmp_binary;
+ ASSERT_NE(-1, tmp_binary.fd);
+ ASSERT_EQ(0, ExtractEntryToFile(handle, &binary_entry, tmp_binary.fd));
+}
+#endif
+
static void ZipArchiveStreamTest(
ZipArchiveHandle& handle, const std::string& entry_name, bool raw,
bool verified, ZipEntry* entry, std::vector<uint8_t>* read_data) {
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/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..5554d53 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);
}
}
@@ -880,7 +787,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/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 a0cea25..0cb26dc 100644
--- a/logd/main.cpp
+++ b/logd/main.cpp
@@ -44,6 +44,7 @@
#include <log/event_tag_map.h>
#include <packagelistparser/packagelistparser.h>
#include <private/android_filesystem_config.h>
+#include <private/android_logger.h>
#include <scoped_minijail.h>
#include <utils/threads.h>
@@ -130,60 +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) {
- property_get("ro.debuggable", property, "");
- if (strcmp(property, "1")) {
- 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) {
@@ -367,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);
}
@@ -451,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();
}
@@ -489,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/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>