Merge "libsparse: Add .csv and sha1 options for simg_dump.py"
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..949a7fe
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,22 @@
+// 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.
+
+ndk_headers {
+ name: "liblog_headers",
+ from: "include/android",
+ to: "android",
+ srcs: ["include/android/log.h"],
+}
+
+optional_subdirs = ["*"]
diff --git a/CleanSpec.mk b/CleanSpec.mk
index 31e60ca..5b5eff4 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -59,3 +59,4 @@
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/hw/gatekeeper.$(TARGET_DEVICE).so)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib64/hw/gatekeeper.$(TARGET_DEVICE).so)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/root/vendor)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/root/init.rc)
diff --git a/adb/Android.mk b/adb/Android.mk
index b2a0dc4..0114ca3 100644
--- a/adb/Android.mk
+++ b/adb/Android.mk
@@ -62,6 +62,7 @@
adb_listeners_test.cpp \
adb_utils_test.cpp \
fdevent_test.cpp \
+ socket_spec_test.cpp \
socket_test.cpp \
sysdeps_test.cpp \
sysdeps/stat_test.cpp \
diff --git a/adb/adb.cpp b/adb/adb.cpp
index 056dbef..9ae3f1c 100644
--- a/adb/adb.cpp
+++ b/adb/adb.cpp
@@ -48,9 +48,9 @@
#include "transport.h"
#if !ADB_HOST
-#include <cutils/properties.h>
#include <sys/capability.h>
#include <sys/mount.h>
+#include <android-base/properties.h>
#endif
std::string adb_version() {
@@ -200,11 +200,9 @@
"ro.product.device",
};
- for (const auto& prop_name : cnxn_props) {
- char value[PROPERTY_VALUE_MAX];
- property_get(prop_name, value, "");
- connection_properties.push_back(
- android::base::StringPrintf("%s=%s", prop_name, value));
+ for (const auto& prop : cnxn_props) {
+ std::string value = std::string(prop) + "=" + android::base::GetProperty(prop, "");
+ connection_properties.push_back(value);
}
#endif
diff --git a/adb/adb_trace.cpp b/adb/adb_trace.cpp
index 62900c0..369dec9 100644
--- a/adb/adb_trace.cpp
+++ b/adb/adb_trace.cpp
@@ -27,7 +27,7 @@
#include "adb.h"
#if !ADB_HOST
-#include <cutils/properties.h>
+#include <android-base/properties.h>
#endif
#if !ADB_HOST
@@ -88,19 +88,11 @@
return std::string(setting);
}
-#if !ADB_HOST
-std::string get_trace_setting_from_prop() {
- char buf[PROPERTY_VALUE_MAX];
- property_get("persist.adb.trace_mask", buf, "");
- return std::string(buf);
-}
-#endif
-
std::string get_trace_setting() {
#if ADB_HOST
return get_trace_setting_from_env();
#else
- return get_trace_setting_from_prop();
+ return android::base::GetProperty("persist.adb.trace_mask", "");
#endif
}
diff --git a/adb/adb_utils.cpp b/adb/adb_utils.cpp
index db39ef4..5a3b401 100644
--- a/adb/adb_utils.cpp
+++ b/adb/adb_utils.cpp
@@ -26,6 +26,7 @@
#include <unistd.h>
#include <algorithm>
+#include <mutex>
#include <vector>
#include <android-base/logging.h>
@@ -47,8 +48,6 @@
#include <pwd.h>
#endif
-ADB_MUTEX_DEFINE(basename_lock);
-ADB_MUTEX_DEFINE(dirname_lock);
#if defined(_WIN32)
constexpr char kNullFileName[] = "NUL";
@@ -102,13 +101,15 @@
}
std::string adb_basename(const std::string& path) {
+ static std::mutex& basename_lock = *new std::mutex();
+
// Copy path because basename may modify the string passed in.
std::string result(path);
// Use lock because basename() may write to a process global and return a
// pointer to that. Note that this locking strategy only works if all other
- // callers to dirname in the process also grab this same lock.
- adb_mutex_lock(&basename_lock);
+ // callers to basename in the process also grab this same lock.
+ std::lock_guard<std::mutex> lock(basename_lock);
// Note that if std::string uses copy-on-write strings, &str[0] will cause
// the copy to be made, so there is no chance of us accidentally writing to
@@ -119,19 +120,19 @@
// before leaving the lock.
result.assign(name);
- adb_mutex_unlock(&basename_lock);
-
return result;
}
std::string adb_dirname(const std::string& path) {
+ static std::mutex& dirname_lock = *new std::mutex();
+
// Copy path because dirname may modify the string passed in.
std::string result(path);
// Use lock because dirname() may write to a process global and return a
// pointer to that. Note that this locking strategy only works if all other
// callers to dirname in the process also grab this same lock.
- adb_mutex_lock(&dirname_lock);
+ std::lock_guard<std::mutex> lock(dirname_lock);
// Note that if std::string uses copy-on-write strings, &str[0] will cause
// the copy to be made, so there is no chance of us accidentally writing to
@@ -142,8 +143,6 @@
// before leaving the lock.
result.assign(parent);
- adb_mutex_unlock(&dirname_lock);
-
return result;
}
diff --git a/adb/client/main.cpp b/adb/client/main.cpp
index 571c227..4ec0fc2 100644
--- a/adb/client/main.cpp
+++ b/adb/client/main.cpp
@@ -129,7 +129,9 @@
// Start a new session for the daemon. Do this here instead of after the fork so
// that a ctrl-c between the "starting server" and "done starting server" messages
// gets a chance to terminate the server.
- if (setsid() == -1) {
+ // setsid will fail with EPERM if it's already been a lead process of new session.
+ // Ignore such error.
+ if (setsid() == -1 && errno != EPERM) {
fatal("setsid() failed: %s", strerror(errno));
}
#endif
@@ -170,7 +172,6 @@
}
int main(int argc, char** argv) {
- adb_sysdeps_init();
adb_trace_init(argv);
return adb_commandline(argc - 1, const_cast<const char**>(argv + 1));
}
diff --git a/adb/commandline.cpp b/adb/commandline.cpp
index a9185a0..54e254a 100644
--- a/adb/commandline.cpp
+++ b/adb/commandline.cpp
@@ -83,181 +83,149 @@
}
static void help() {
- fprintf(stderr, "%s\n", adb_version().c_str());
+ fprintf(stdout, "%s\n", adb_version().c_str());
// clang-format off
- fprintf(stderr,
- " -a - directs adb to listen on all interfaces for a connection\n"
- " -d - directs command to the only connected USB device\n"
- " returns an error if more than one USB device is present.\n"
- " -e - directs command to the only running emulator.\n"
- " returns an error if more than one emulator is running.\n"
- " -s <specific device> - directs command to the device or emulator with the given\n"
- " serial number or qualifier. Overrides ANDROID_SERIAL\n"
- " environment variable.\n"
- " -p <product name or path> - simple product name like 'sooner', or\n"
- " a relative/absolute path to a product\n"
- " out directory like 'out/target/product/sooner'.\n"
- " If -p is not specified, the ANDROID_PRODUCT_OUT\n"
- " environment variable is used, which must\n"
- " be an absolute path.\n"
- " -H - Name of adb server host (default: localhost)\n"
- " -P - Port of adb server (default: 5037)\n"
- " -L <socket> - listen on socket specifier for the adb server\n"
- " (default: tcp:localhost:5037)\n"
- " devices [-l] - list all connected devices\n"
- " ('-l' will also list device qualifiers)\n"
- " connect <host>[:<port>] - connect to a device via TCP/IP\n"
- " Port 5555 is used by default if no port number is specified.\n"
- " disconnect [<host>[:<port>]] - disconnect from a TCP/IP device.\n"
- " Port 5555 is used by default if no port number is specified.\n"
- " Using this command with no additional arguments\n"
- " will disconnect from all connected TCP/IP devices.\n"
+ fprintf(stdout,
+ "global options:\n"
+ " -a listen on all network interfaces, not just localhost\n"
+ " -d use USB device (error if multiple devices connected)\n"
+ " -e use emulator (error if multiple emulators running)\n"
+ " -s SERIAL\n"
+ " use device/emulator 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"
+ " -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"
"\n"
- "device commands:\n"
- " adb push <local>... <remote>\n"
- " - copy files/dirs to device\n"
- " adb pull [-a] <remote>... <local>\n"
- " - copy files/dirs from device\n"
- " (-a preserves file timestamp and mode)\n"
- " adb sync [ <directory> ] - copy host->device only if changed\n"
- " (-l means list but don't copy)\n"
- " adb shell [-e escape] [-n] [-Tt] [-x] [command]\n"
- " - run remote shell command (interactive shell if no command given)\n"
- " (-e: choose escape character, or \"none\"; default '~')\n"
- " (-n: don't read from stdin)\n"
- " (-T: disable PTY allocation)\n"
- " (-t: force PTY allocation)\n"
- " (-x: disable remote exit codes and stdout/stderr separation)\n"
- " adb emu <command> - run emulator console command\n"
- " adb logcat [ <filter-spec> ] - View device log\n"
- " adb forward --list - list all forward socket connections.\n"
- " the format is a list of lines with the following format:\n"
- " <serial> \" \" <local> \" \" <remote> \"\\n\"\n"
- " adb forward <local> <remote> - forward socket connections\n"
- " forward specs are one of: \n"
- " tcp:<port> (<local> may be \"tcp:0\" to pick any open port)\n"
- " localabstract:<unix domain socket name>\n"
- " localreserved:<unix domain socket name>\n"
- " localfilesystem:<unix domain socket name>\n"
- " dev:<character device name>\n"
- " jdwp:<process pid> (remote only)\n"
- " adb forward --no-rebind <local> <remote>\n"
- " - same as 'adb forward <local> <remote>' but fails\n"
- " if <local> is already forwarded\n"
- " adb forward --remove <local> - remove a specific forward socket connection\n"
- " adb forward --remove-all - remove all forward socket connections\n"
- " adb reverse --list - list all reverse socket connections from device\n"
- " adb reverse <remote> <local> - reverse socket connections\n"
- " reverse specs are one of:\n"
- " tcp:<port> (<remote> may be \"tcp:0\" to pick any open port)\n"
- " localabstract:<unix domain socket name>\n"
- " localreserved:<unix domain socket name>\n"
- " localfilesystem:<unix domain socket name>\n"
- " adb reverse --no-rebind <remote> <local>\n"
- " - same as 'adb reverse <remote> <local>' but fails\n"
- " if <remote> is already reversed.\n"
- " adb reverse --remove <remote>\n"
- " - remove a specific reversed socket connection\n"
- " adb reverse --remove-all - remove all reversed socket connections from device\n"
- " adb jdwp - list PIDs of processes hosting a JDWP transport\n"
- " adb install [-lrtsdg] <file>\n"
- " - push this package file to the device and install it\n"
- " (-l: forward lock application)\n"
- " (-r: replace existing application)\n"
- " (-t: allow test packages)\n"
- " (-s: install application on sdcard)\n"
- " (-d: allow version code downgrade (debuggable packages only))\n"
- " (-g: grant all runtime permissions)\n"
- " adb install-multiple [-lrtsdpg] <file...>\n"
- " - push this package file to the device and install it\n"
- " (-l: forward lock application)\n"
- " (-r: replace existing application)\n"
- " (-t: allow test packages)\n"
- " (-s: install application on sdcard)\n"
- " (-d: allow version code downgrade (debuggable packages only))\n"
- " (-p: partial application install)\n"
- " (-g: grant all runtime permissions)\n"
- " adb uninstall [-k] <package> - remove this app package from the device\n"
- " ('-k' means keep the data and cache directories)\n"
- " adb bugreport [<path>] - return all information from the device that should be included in a zipped bug report.\n"
- " If <path> is a file, the bug report will be saved as that file.\n"
- " If <path> is a directory, the bug report will be saved in that directory with the name provided by the device.\n"
- " If <path> is omitted, the bug report will be saved in the current directory with the name provided by the device.\n"
- " NOTE: if the device does not support zipped bug reports, the bug report will be output on stdout.\n"
- " adb backup [-f <file>] [-apk|-noapk] [-obb|-noobb] [-shared|-noshared] [-all] [-system|-nosystem] [<packages...>]\n"
- " - write an archive of the device's data to <file>.\n"
- " If no -f option is supplied then the data is written\n"
- " to \"backup.ab\" in the current directory.\n"
- " (-apk|-noapk enable/disable backup of the .apks themselves\n"
- " in the archive; the default is noapk.)\n"
- " (-obb|-noobb enable/disable backup of any installed apk expansion\n"
- " (aka .obb) files associated with each application; the default\n"
- " is noobb.)\n"
- " (-shared|-noshared enable/disable backup of the device's\n"
- " shared storage / SD card contents; the default is noshared.)\n"
- " (-all means to back up all installed applications)\n"
- " (-system|-nosystem toggles whether -all automatically includes\n"
- " system applications; the default is to include system apps)\n"
- " (<packages...> is the list of applications to be backed up. If\n"
- " the -all or -shared flags are passed, then the package\n"
- " list is optional. Applications explicitly given on the\n"
- " command line will be included even if -nosystem would\n"
- " ordinarily cause them to be omitted.)\n"
- "\n"
- " adb restore <file> - restore device contents from the <file> backup archive\n"
- "\n"
- " adb disable-verity - disable dm-verity checking on USERDEBUG builds\n"
- " adb enable-verity - re-enable dm-verity checking on USERDEBUG builds\n"
- " adb keygen <file> - generate adb public/private key. The private key is stored in <file>,\n"
- " and the public key is stored in <file>.pub. Any existing files\n"
- " are overwritten.\n"
- " adb help - show this help message\n"
- " adb version - show version num\n"
- "\n"
- "scripting:\n"
- " adb wait-for[-<transport>]-<state>\n"
- " - wait for device to be in the given state:\n"
- " device, recovery, sideload, or bootloader\n"
- " Transport is: usb, local or any [default=any]\n"
- " adb start-server - ensure that there is a server running\n"
- " adb kill-server - kill the server if it is running\n"
- " adb get-state - prints: offline | bootloader | device\n"
- " adb get-serialno - prints: <serial-number>\n"
- " adb get-devpath - prints: <device-path>\n"
- " adb remount - remounts the /system, /vendor (if present) and /oem (if present) partitions on the device read-write\n"
- " adb reboot [bootloader|recovery]\n"
- " - reboots the device, optionally into the bootloader or recovery program.\n"
- " adb reboot sideload - reboots the device into the sideload mode in recovery program (adb root required).\n"
- " adb reboot sideload-auto-reboot\n"
- " - reboots into the sideload mode, then reboots automatically after the sideload regardless of the result.\n"
- " adb sideload <file> - sideloads the given package\n"
- " adb root - restarts the adbd daemon with root permissions\n"
- " adb unroot - restarts the adbd daemon without root permissions\n"
- " adb usb - restarts the adbd daemon listening on USB\n"
- " adb tcpip <port> - restarts the adbd daemon listening on TCP on the specified port\n"
+ "general commands:\n"
+ " devices [-l] list connected devices (-l for long output)\n"
+ " help show this help message\n"
+ " version show version num\n"
"\n"
"networking:\n"
- " adb ppp <tty> [parameters] - Run PPP over USB.\n"
- " Note: you should not automatically start a PPP connection.\n"
- " <tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1\n"
- " [parameters] - Eg. defaultroute debug dump local notty usepeerdns\n"
+ " connect HOST[:PORT] connect to a device via TCP/IP [default port=5555]\n"
+ " disconnect [HOST[:PORT]]\n"
+ " disconnect from given TCP/IP device [default port=5555], or all\n"
+ " forward --list list all forward socket connections\n"
+ " forward [--no-rebind] LOCAL REMOTE\n"
+ " forward socket connection using:\n"
+ " tcp:<port> (<local> may be \"tcp:0\" to pick any open port)\n"
+ " localabstract:<unix domain socket name>\n"
+ " localreserved:<unix domain socket name>\n"
+ " localfilesystem:<unix domain socket name>\n"
+ " dev:<character device name>\n"
+ " jdwp:<process pid> (remote only)\n"
+ " forward --remove LOCAL remove specific forward socket connection\n"
+ " forward --remove-all remove all forward socket connections\n"
+ " ppp TTY [PARAMETER...] run PPP over USB\n"
+ " reverse --list list all reverse socket connections from device\n"
+ " reverse [--no-rebind] REMOTE LOCAL\n"
+ " reverse socket connection using:\n"
+ " tcp:<port> (<remote> may be \"tcp:0\" to pick any open port)\n"
+ " localabstract:<unix domain socket name>\n"
+ " localreserved:<unix domain socket name>\n"
+ " localfilesystem:<unix domain socket name>\n"
+ " reverse --remove REMOTE remove specific reverse socket connection\n"
+ " reverse --remove-all remove all reverse socket connections from device\n"
"\n"
- "adb sync notes: adb sync [ <directory> ]\n"
- " <localdir> can be interpreted in several ways:\n"
+ "file transfer:\n"
+ " push LOCAL... REMOTE\n"
+ " copy local files/directories to device\n"
+ " 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"
+ " -l: list but don't copy\n"
"\n"
- " - If <directory> is not specified, /system, /vendor (if present), /oem (if present) and /data partitions will be updated.\n"
+ "shell:\n"
+ " shell [-e ESCAPE] [-n] [-Tt] [-x] [COMMAND...]\n"
+ " run remote shell command (interactive shell if no command given)\n"
+ " -e: choose escape character, or \"none\"; default '~'\n"
+ " -n: don't read from stdin\n"
+ " -T: disable PTY allocation\n"
+ " -t: force PTY allocation\n"
+ " -x: disable remote exit codes and stdout/stderr separation\n"
+ " emu COMMAND run emulator console command\n"
"\n"
- " - If it is \"system\", \"vendor\", \"oem\" or \"data\", only the corresponding partition\n"
- " is updated.\n"
+ "app installation:\n"
+ " install [-lrtsdg] PACKAGE\n"
+ " install-multiple [-lrtsdpg] PACKAGE...\n"
+ " push package(s) to the device and install them\n"
+ " -l: forward lock application\n"
+ " -r: replace existing application\n"
+ " -t: allow test packages\n"
+ " -s: install application on sdcard\n"
+ " -d: allow version code downgrade (debuggable packages only)\n"
+ " -p: partial application install (install-multiple only)\n"
+ " -g: grant all runtime permissions\n"
+ " uninstall [-k] PACKAGE\n"
+ " remove this app package from the device\n"
+ " '-k': keep the data and cache directories\n"
+ "\n"
+ "backup/restore:\n"
+ " backup [-f FILE] [-apk|-noapk] [-obb|-noobb] [-shared|-noshared] [-all] [-system|-nosystem] [PACKAGE...]\n"
+ " write an archive of the device's data to FILE [default=backup.adb]\n"
+ " package list optional if -all/-shared are supplied\n"
+ " -apk/-noapk: do/don't back up .apk files (default -noapk)\n"
+ " -obb/-noobb: do/don't back up .obb files (default -noobb)\n"
+ " -shared|-noshared: do/don't back up shared storage (default -noshared)\n"
+ " -all: back up all installed applications\n"
+ " -system|-nosystem: include system apps in -all (default -system)\n"
+ " restore FILE restore device contents from FILE\n"
+ "\n"
+ "debugging:\n"
+ " bugreport [PATH]\n"
+ " write bugreport to given PATH [default=bugreport.zip];\n"
+ " if PATH is a directory, the bug report is saved in that directory.\n"
+ " devices that don't support zipped bug reports output to stdout.\n"
+ " jdwp list pids of processes hosting a JDWP transport\n"
+ " logcat show device log (logcat --help for more)\n"
+ "\n"
+ "security:\n"
+ " disable-verity disable dm-verity checking on userdebug builds\n"
+ " enable-verity re-enable dm-verity checking on userdebug builds\n"
+ " keygen FILE\n"
+ " generate adb public/private key; private key stored in FILE,\n"
+ " public key stored in FILE.pub (existing files overwritten)\n"
+ "\n"
+ "scripting:\n"
+ " wait-for[-TRANSPORT]-STATE\n"
+ " wait for device to be in the given state\n"
+ " State: device, recovery, sideload, or bootloader\n"
+ " Transport: usb, local, or any [default=any]\n"
+ " get-state print offline | bootloader | device\n"
+ " get-serialno print <serial-number>\n"
+ " get-devpath print <device-path>\n"
+ " remount\n"
+ " remount /system, /vendor, and /oem partitions read-write\n"
+ " reboot [bootloader|recovery|sideload|sideload-auto-reboot]\n"
+ " reboot the device; defaults to booting system image but\n"
+ " supports bootloader and recovery too. sideload reboots\n"
+ " into recovery and automatically starts sideload mode,\n"
+ " sideload-auto-reboot is the same but reboots after sideloading.\n"
+ " sideload OTAPACKAGE sideload the given full OTA package\n"
+ " root restart adbd with root permissions\n"
+ " unroot restart adbd without root permissions\n"
+ " usb restart adb server listening on USB\n"
+ " tcpip PORT restart adb server listening on TCP on PORT\n"
"\n"
"internal debugging:\n"
- " adb reconnect Kick current connection from host side and make it reconnect.\n"
- " adb reconnect device Kick current connection from device side and make it reconnect.\n"
+ " start-server ensure that there is a server running\n"
+ " kill-server kill the server if it is running\n"
+ " reconnect kick connection from host side to force reconnect\n"
+ " reconnect device kick connection from device side to force reconnect\n"
+ "\n"
"environment variables:\n"
- " ADB_TRACE - Print debug information. A comma separated list of the following values\n"
- " 1 or all, adb, sockets, packets, rwx, usb, sync, sysdeps, transport, jdwp\n"
- " ANDROID_SERIAL - The serial number to connect to. -s takes priority over this if given.\n"
- " ANDROID_LOG_TAGS - When used with the logcat option, only these debug tags are printed.\n");
+ " $ADB_TRACE\n"
+ " comma-separated list of debug info to log:\n"
+ " all,adb,sockets,packets,rwx,usb,sync,sysdeps,transport,jdwp\n"
+ " $ADB_VENDOR_KEYS colon-separated list of keys (files or directories)\n"
+ " $ANDROID_SERIAL serial number to connect to (see -s)\n"
+ " $ANDROID_LOG_TAGS tags to be used by logcat (see logcat --help)\n");
// clang-format on
}
diff --git a/adb/daemon/main.cpp b/adb/daemon/main.cpp
index b54243e..094988a 100644
--- a/adb/daemon/main.cpp
+++ b/adb/daemon/main.cpp
@@ -29,11 +29,11 @@
#include <android-base/logging.h>
#include <android-base/macros.h>
+#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <libminijail.h>
#include <scoped_minijail.h>
-#include "cutils/properties.h"
#include "debuggerd/client.h"
#include "private/android_filesystem_config.h"
#include "selinux/android.h"
@@ -48,9 +48,7 @@
static void drop_capabilities_bounding_set_if_needed(struct minijail *j) {
#if defined(ALLOW_ADBD_ROOT)
- char value[PROPERTY_VALUE_MAX];
- property_get("ro.debuggable", value, "");
- if (strcmp(value, "1") == 0) {
+ if (android::base::GetBoolProperty("ro.debuggable", false)) {
return;
}
#endif
@@ -59,8 +57,6 @@
static bool should_drop_privileges() {
#if defined(ALLOW_ADBD_ROOT)
- char value[PROPERTY_VALUE_MAX];
-
// The properties that affect `adb root` and `adb unroot` are ro.secure and
// ro.debuggable. In this context the names don't make the expected behavior
// particularly obvious.
@@ -71,24 +67,19 @@
//
// ro.secure:
// Drop privileges by default. Set to 1 on userdebug and user builds.
- property_get("ro.secure", value, "1");
- bool ro_secure = (strcmp(value, "1") == 0);
-
- property_get("ro.debuggable", value, "");
- bool ro_debuggable = (strcmp(value, "1") == 0);
+ bool ro_secure = android::base::GetBoolProperty("ro.secure", true);
+ bool ro_debuggable = android::base::GetBoolProperty("ro.debuggable", false);
// Drop privileges if ro.secure is set...
bool drop = ro_secure;
- property_get("service.adb.root", value, "");
- bool adb_root = (strcmp(value, "1") == 0);
- bool adb_unroot = (strcmp(value, "0") == 0);
-
// ... except "adb root" lets you keep privileges in a debuggable build.
+ std::string prop = android::base::GetProperty("service.adb.root", "");
+ bool adb_root = (prop == "1");
+ bool adb_unroot = (prop == "0");
if (ro_debuggable && adb_root) {
drop = false;
}
-
// ... and "adb unroot" lets you explicitly drop privileges.
if (adb_unroot) {
drop = true;
@@ -159,7 +150,7 @@
// descriptor will always be open.
adbd_cloexec_auth_socket();
- if (ALLOW_ADBD_NO_AUTH && property_get_bool("ro.adb.secure", 0) == 0) {
+ if (ALLOW_ADBD_NO_AUTH && !android::base::GetBoolProperty("ro.adb.secure", false)) {
auth_required = false;
}
@@ -187,14 +178,13 @@
// If one of these properties is set, also listen on that port.
// If one of the properties isn't set and we couldn't listen on usb, listen
// on the default port.
- char prop_port[PROPERTY_VALUE_MAX];
- property_get("service.adb.tcp.port", prop_port, "");
- if (prop_port[0] == '\0') {
- property_get("persist.adb.tcp.port", prop_port, "");
+ std::string prop_port = android::base::GetProperty("service.adb.tcp.port", "");
+ if (prop_port.empty()) {
+ prop_port = android::base::GetProperty("persist.adb.tcp.port", "");
}
int port;
- if (sscanf(prop_port, "%d", &port) == 1 && port > 0) {
+ if (sscanf(prop_port.c_str(), "%d", &port) == 1 && port > 0) {
D("using port=%d", port);
// Listen on TCP port specified by service.adb.tcp.port property.
local_init(port);
diff --git a/adb/file_sync_service.cpp b/adb/file_sync_service.cpp
index 14c26cb..2dfad94 100644
--- a/adb/file_sync_service.cpp
+++ b/adb/file_sync_service.cpp
@@ -31,17 +31,17 @@
#include <unistd.h>
#include <utime.h>
+#include <android/log.h>
+#include <android-base/stringprintf.h>
+#include <android-base/strings.h>
+#include <private/android_filesystem_config.h>
+#include <selinux/android.h>
+
#include "adb.h"
#include "adb_io.h"
#include "adb_utils.h"
-#include "private/android_filesystem_config.h"
#include "security_log_tags.h"
-#include <android-base/stringprintf.h>
-#include <android-base/strings.h>
-#include <log/log.h>
-#include <selinux/android.h>
-
static bool should_use_fs_config(const std::string& path) {
// TODO: use fs_config to configure permissions on /data.
return android::base::StartsWith(path, "/system/") ||
diff --git a/adb/mutex_list.h b/adb/mutex_list.h
deleted file mode 100644
index 4a188ee..0000000
--- a/adb/mutex_list.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/* the list of mutexes used by adb */
-/* #ifndef __MUTEX_LIST_H
- * Do not use an include-guard. This file is included once to declare the locks
- * and once in win32 to actually do the runtime initialization.
- */
-#ifndef ADB_MUTEX
-#error ADB_MUTEX not defined when including this file
-#endif
-ADB_MUTEX(basename_lock)
-ADB_MUTEX(dirname_lock)
-ADB_MUTEX(transport_lock)
-#if ADB_HOST
-ADB_MUTEX(local_transports_lock)
-#endif
-ADB_MUTEX(usb_lock)
-
-#undef ADB_MUTEX
diff --git a/adb/remount_service.cpp b/adb/remount_service.cpp
index 8f1c9b0..5ca73cc 100644
--- a/adb/remount_service.cpp
+++ b/adb/remount_service.cpp
@@ -29,10 +29,11 @@
#include <string>
+#include <android-base/properties.h>
+
#include "adb.h"
#include "adb_io.h"
#include "adb_utils.h"
-#include "cutils/properties.h"
#include "fs_mgr.h"
// Returns the device used to mount a directory in /proc/mounts.
@@ -53,10 +54,7 @@
// Returns the device used to mount a directory in the fstab.
static std::string find_fstab_mount(const char* dir) {
- char propbuf[PROPERTY_VALUE_MAX];
-
- property_get("ro.hardware", propbuf, "");
- std::string fstab_filename = std::string("/fstab.") + propbuf;
+ std::string fstab_filename = "/fstab." + android::base::GetProperty("ro.hardware", "");
struct fstab* fstab = fs_mgr_read_fstab(fstab_filename.c_str());
struct fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab, dir);
std::string dev = rec ? std::string(rec->blk_device) : "";
@@ -113,12 +111,8 @@
return;
}
- char prop_buf[PROPERTY_VALUE_MAX];
- property_get("partition.system.verified", prop_buf, "");
- bool system_verified = (strlen(prop_buf) > 0);
-
- property_get("partition.vendor.verified", prop_buf, "");
- bool vendor_verified = (strlen(prop_buf) > 0);
+ bool system_verified = !(android::base::GetProperty("partition.system.verified", "").empty());
+ bool vendor_verified = !(android::base::GetProperty("partition.vendor.verified", "").empty());
if (system_verified || vendor_verified) {
// Allow remount but warn of likely bad effects
@@ -136,9 +130,7 @@
}
bool success = true;
- property_get("ro.build.system_root_image", prop_buf, "");
- bool system_root = !strcmp(prop_buf, "true");
- if (system_root) {
+ if (android::base::GetBoolProperty("ro.build.system_root_image", false)) {
success &= remount_partition(fd, "/");
} else {
success &= remount_partition(fd, "/system");
diff --git a/adb/services.cpp b/adb/services.cpp
index 2207a3e..0c3dd00 100644
--- a/adb/services.cpp
+++ b/adb/services.cpp
@@ -39,7 +39,7 @@
#if !ADB_HOST
#include "cutils/android_reboot.h"
-#include "cutils/properties.h"
+#include <android-base/properties.h>
#endif
#include "adb.h"
@@ -73,15 +73,13 @@
WriteFdExactly(fd, "adbd is already running as root\n");
adb_close(fd);
} else {
- char value[PROPERTY_VALUE_MAX];
- property_get("ro.debuggable", value, "");
- if (strcmp(value, "1") != 0) {
+ if (!android::base::GetBoolProperty("ro.debuggable", false)) {
WriteFdExactly(fd, "adbd cannot run as root in production builds\n");
adb_close(fd);
return;
}
- property_set("service.adb.root", "1");
+ android::base::SetProperty("service.adb.root", "1");
WriteFdExactly(fd, "restarting adbd as root\n");
adb_close(fd);
}
@@ -92,7 +90,7 @@
WriteFdExactly(fd, "adbd not running as root\n");
adb_close(fd);
} else {
- property_set("service.adb.root", "0");
+ android::base::SetProperty("service.adb.root", "0");
WriteFdExactly(fd, "restarting adbd as non root\n");
adb_close(fd);
}
@@ -106,15 +104,13 @@
return;
}
- char value[PROPERTY_VALUE_MAX];
- snprintf(value, sizeof(value), "%d", port);
- property_set("service.adb.tcp.port", value);
+ android::base::SetProperty("service.adb.tcp.port", android::base::StringPrintf("%d", port));
WriteFdFmt(fd, "restarting in TCP mode port: %d\n", port);
adb_close(fd);
}
void restart_usb_service(int fd, void *cookie) {
- property_set("service.adb.tcp.port", "0");
+ android::base::SetProperty("service.adb.tcp.port", "0");
WriteFdExactly(fd, "restarting in USB mode\n");
adb_close(fd);
}
@@ -155,16 +151,9 @@
sync();
- char property_val[PROPERTY_VALUE_MAX];
- int ret = snprintf(property_val, sizeof(property_val), "reboot,%s", reboot_arg);
- if (ret >= static_cast<int>(sizeof(property_val))) {
- WriteFdFmt(fd, "reboot string too long: %d\n", ret);
- return false;
- }
-
- ret = property_set(ANDROID_RB_PROPERTY, property_val);
- if (ret < 0) {
- WriteFdFmt(fd, "reboot failed: %d\n", ret);
+ std::string reboot_string = android::base::StringPrintf("reboot,%s", reboot_arg);
+ if (!android::base::SetProperty(ANDROID_RB_PROPERTY, reboot_string)) {
+ WriteFdFmt(fd, "reboot (%s) failed\n", reboot_string.c_str());
return false;
}
diff --git a/adb/set_verity_enable_state_service.cpp b/adb/set_verity_enable_state_service.cpp
index f5188e9..ae628e4 100644
--- a/adb/set_verity_enable_state_service.cpp
+++ b/adb/set_verity_enable_state_service.cpp
@@ -24,16 +24,17 @@
#include <stdio.h>
#include <sys/stat.h>
-#include "cutils/properties.h"
+#include "android-base/properties.h"
+#include "android-base/stringprintf.h"
#include "adb.h"
#include "adb_io.h"
+#include "adb_unique_fd.h"
#include "fs_mgr.h"
#include "remount_service.h"
#include "fec/io.h"
-#define FSTAB_PREFIX "/fstab."
struct fstab *fstab;
#ifdef ALLOW_ADBD_DISABLE_VERITY
@@ -88,56 +89,46 @@
return 0;
}
-void set_verity_enabled_state_service(int fd, void* cookie)
-{
+void set_verity_enabled_state_service(int fd, void* cookie) {
+ unique_fd closer(fd);
+
bool enable = (cookie != NULL);
- if (kAllowDisableVerity) {
- char fstab_filename[PROPERTY_VALUE_MAX + sizeof(FSTAB_PREFIX)];
- char propbuf[PROPERTY_VALUE_MAX];
- int i;
- bool any_changed = false;
-
- property_get("ro.secure", propbuf, "0");
- if (strcmp(propbuf, "1")) {
- WriteFdFmt(fd, "verity not enabled - ENG build\n");
- goto errout;
- }
-
- property_get("ro.debuggable", propbuf, "0");
- if (strcmp(propbuf, "1")) {
- WriteFdFmt(fd, "verity cannot be disabled/enabled - USER build\n");
- goto errout;
- }
-
- property_get("ro.hardware", propbuf, "");
- snprintf(fstab_filename, sizeof(fstab_filename), FSTAB_PREFIX"%s",
- propbuf);
-
- fstab = fs_mgr_read_fstab(fstab_filename);
- if (!fstab) {
- WriteFdFmt(fd, "Failed to open %s\nMaybe run adb root?\n", fstab_filename);
- goto errout;
- }
-
- /* Loop through entries looking for ones that vold manages */
- for (i = 0; i < fstab->num_entries; i++) {
- if(fs_mgr_is_verified(&fstab->recs[i])) {
- if (!set_verity_enabled_state(fd, fstab->recs[i].blk_device,
- fstab->recs[i].mount_point,
- enable)) {
- any_changed = true;
- }
- }
- }
-
- if (any_changed) {
- WriteFdFmt(fd, "Now reboot your device for settings to take effect\n");
- }
- } else {
+ if (!kAllowDisableVerity) {
WriteFdFmt(fd, "%s-verity only works for userdebug builds\n",
enable ? "enable" : "disable");
}
-errout:
- adb_close(fd);
+ if (!android::base::GetBoolProperty("ro.secure", false)) {
+ WriteFdFmt(fd, "verity not enabled - ENG build\n");
+ return;
+ }
+
+ if (!android::base::GetBoolProperty("ro.debuggable", false)) {
+ WriteFdFmt(fd, "verity cannot be disabled/enabled - USER build\n");
+ return;
+ }
+
+ std::string fstab_filename = "/fstab." + android::base::GetProperty("ro.hardware", "");
+
+ fstab = fs_mgr_read_fstab(fstab_filename.c_str());
+ if (!fstab) {
+ WriteFdFmt(fd, "Failed to open %s\nMaybe run adb root?\n", fstab_filename.c_str());
+ return;
+ }
+
+ // Loop through entries looking for ones that vold manages.
+ bool any_changed = false;
+ for (int i = 0; i < fstab->num_entries; i++) {
+ if (fs_mgr_is_verified(&fstab->recs[i])) {
+ if (!set_verity_enabled_state(fd, fstab->recs[i].blk_device,
+ fstab->recs[i].mount_point,
+ enable)) {
+ any_changed = true;
+ }
+ }
+ }
+
+ if (any_changed) {
+ WriteFdFmt(fd, "Now reboot your device for settings to take effect\n");
+ }
}
diff --git a/adb/shell_service.cpp b/adb/shell_service.cpp
index 01e206a..7b00d9d 100644
--- a/adb/shell_service.cpp
+++ b/adb/shell_service.cpp
@@ -92,10 +92,10 @@
#include <unordered_map>
#include <vector>
+#include <android/log.h>
#include <android-base/logging.h>
#include <android-base/stringprintf.h>
#include <paths.h>
-#include <log/log.h>
#include "adb.h"
#include "adb_io.h"
@@ -493,10 +493,10 @@
// We also need to close the pipes connected to the child process
// so that if it ignores SIGHUP and continues to write data it
// won't fill up the pipe and block.
- stdinout_sfd_.clear();
- stderr_sfd_.clear();
+ stdinout_sfd_.reset();
+ stderr_sfd_.reset();
}
- dead_sfd->clear();
+ dead_sfd->reset();
}
}
}
diff --git a/adb/socket_spec.cpp b/adb/socket_spec.cpp
index 18e6e6d..14eb16b 100644
--- a/adb/socket_spec.cpp
+++ b/adb/socket_spec.cpp
@@ -20,6 +20,8 @@
#include <unordered_map>
#include <vector>
+#include <android-base/parseint.h>
+#include <android-base/parsenetaddress.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <cutils/sockets.h>
@@ -62,55 +64,47 @@
{ "localfilesystem", { ANDROID_SOCKET_NAMESPACE_FILESYSTEM, !ADB_WINDOWS } },
});
-static bool parse_tcp_spec(const std::string& spec, std::string* hostname, int* port,
+bool parse_tcp_socket_spec(const std::string& spec, std::string* hostname, int* port,
std::string* error) {
- std::vector<std::string> fragments = android::base::Split(spec, ":");
- if (fragments.size() == 1 || fragments.size() > 3) {
- *error = StringPrintf("invalid tcp specification: '%s'", spec.c_str());
- return false;
- }
-
- if (fragments[0] != "tcp") {
+ if (!StartsWith(spec, "tcp:")) {
*error = StringPrintf("specification is not tcp: '%s'", spec.c_str());
return false;
}
- // strtol accepts leading whitespace.
- const std::string& port_str = fragments.back();
- if (port_str.empty() || port_str[0] < '0' || port_str[0] > '9') {
- *error = StringPrintf("invalid port '%s'", port_str.c_str());
- return false;
- }
+ std::string hostname_value;
+ int port_value;
- char* parsed_end;
- long parsed_port = strtol(port_str.c_str(), &parsed_end, 10);
- if (*parsed_end != '\0') {
- *error = StringPrintf("trailing chars in port: '%s'", port_str.c_str());
- return false;
- }
- if (parsed_port > 65535) {
- *error = StringPrintf("invalid port %ld", parsed_port);
- return false;
- }
-
- // tcp:123 is valid, tcp::123 isn't.
- if (fragments.size() == 2) {
- // Empty hostname.
- if (hostname) {
- *hostname = "";
- }
- } else {
- if (fragments[1].empty()) {
- *error = StringPrintf("empty host in '%s'", spec.c_str());
+ // If the spec is tcp:<port>, parse it ourselves.
+ // Otherwise, delegate to android::base::ParseNetAddress.
+ if (android::base::ParseInt(&spec[4], &port_value)) {
+ // Do the range checking ourselves, because ParseInt rejects 'tcp:65536' and 'tcp:foo:1234'
+ // identically.
+ if (port_value < 0 || port_value > 65535) {
+ *error = StringPrintf("bad port number '%d'", port_value);
return false;
}
- if (hostname) {
- *hostname = fragments[1];
+ } else {
+ std::string addr = spec.substr(4);
+ port_value = -1;
+
+ // FIXME: ParseNetAddress rejects port 0. This currently doesn't hurt, because listening
+ // on an address that isn't 'localhost' is unsupported.
+ if (!android::base::ParseNetAddress(addr, &hostname_value, &port_value, nullptr, error)) {
+ return false;
}
+
+ if (port_value == -1) {
+ *error = StringPrintf("missing port in specification: '%s'", spec.c_str());
+ return false;
+ }
+ }
+
+ if (hostname) {
+ *hostname = std::move(hostname_value);
}
if (port) {
- *port = parsed_port;
+ *port = port_value;
}
return true;
@@ -141,7 +135,7 @@
std::string error;
std::string hostname;
- if (!parse_tcp_spec(spec, &hostname, nullptr, &error)) {
+ if (!parse_tcp_socket_spec(spec, &hostname, nullptr, &error)) {
return false;
}
return tcp_host_is_local(hostname);
@@ -151,7 +145,7 @@
if (StartsWith(spec, "tcp:")) {
std::string hostname;
int port;
- if (!parse_tcp_spec(spec, &hostname, &port, error)) {
+ if (!parse_tcp_socket_spec(spec, &hostname, &port, error)) {
return -1;
}
@@ -196,7 +190,7 @@
if (StartsWith(spec, "tcp:")) {
std::string hostname;
int port;
- if (!parse_tcp_spec(spec, &hostname, &port, error)) {
+ if (!parse_tcp_socket_spec(spec, &hostname, &port, error)) {
return -1;
}
diff --git a/adb/socket_spec.h b/adb/socket_spec.h
index 6302da5..6920e91 100644
--- a/adb/socket_spec.h
+++ b/adb/socket_spec.h
@@ -25,3 +25,7 @@
int socket_spec_connect(const std::string& spec, std::string* error);
int socket_spec_listen(const std::string& spec, std::string* error,
int* resolved_tcp_port = nullptr);
+
+// Exposed for testing.
+bool parse_tcp_socket_spec(const std::string& spec, std::string* hostname, int* port,
+ std::string* error);
diff --git a/adb/socket_spec_test.cpp b/adb/socket_spec_test.cpp
new file mode 100644
index 0000000..40ce21c
--- /dev/null
+++ b/adb/socket_spec_test.cpp
@@ -0,0 +1,54 @@
+/*
+ * 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 "socket_spec.h"
+
+#include <string>
+
+#include <gtest/gtest.h>
+
+TEST(socket_spec, parse_tcp_socket_spec) {
+ std::string hostname, error;
+ int port;
+ EXPECT_TRUE(parse_tcp_socket_spec("tcp:5037", &hostname, &port, &error));
+ EXPECT_EQ("", hostname);
+ EXPECT_EQ(5037, port);
+
+ // Bad ports:
+ EXPECT_FALSE(parse_tcp_socket_spec("tcp:", &hostname, &port, &error));
+ EXPECT_FALSE(parse_tcp_socket_spec("tcp:-1", &hostname, &port, &error));
+ EXPECT_FALSE(parse_tcp_socket_spec("tcp:65536", &hostname, &port, &error));
+
+ EXPECT_TRUE(parse_tcp_socket_spec("tcp:localhost:1234", &hostname, &port, &error));
+ EXPECT_EQ("localhost", hostname);
+ EXPECT_EQ(1234, port);
+
+ EXPECT_FALSE(parse_tcp_socket_spec("tcp:localhost", &hostname, &port, &error));
+ EXPECT_FALSE(parse_tcp_socket_spec("tcp:localhost:", &hostname, &port, &error));
+ EXPECT_FALSE(parse_tcp_socket_spec("tcp:localhost:-1", &hostname, &port, &error));
+ EXPECT_FALSE(parse_tcp_socket_spec("tcp:localhost:65536", &hostname, &port, &error));
+
+ // IPv6:
+ EXPECT_TRUE(parse_tcp_socket_spec("tcp:[::1]:1234", &hostname, &port, &error));
+ EXPECT_EQ("::1", hostname);
+ EXPECT_EQ(1234, port);
+
+ EXPECT_FALSE(parse_tcp_socket_spec("tcp:[::1]", &hostname, &port, &error));
+ EXPECT_FALSE(parse_tcp_socket_spec("tcp:[::1]:", &hostname, &port, &error));
+ EXPECT_FALSE(parse_tcp_socket_spec("tcp:[::1]:-1", &hostname, &port, &error));
+ EXPECT_FALSE(parse_tcp_socket_spec("tcp:::1", &hostname, &port, &error));
+ EXPECT_FALSE(parse_tcp_socket_spec("tcp:::1:1234", &hostname, &port, &error));
+}
diff --git a/adb/socket_test.cpp b/adb/socket_test.cpp
index 2bb01a3..5e79b5e 100644
--- a/adb/socket_test.cpp
+++ b/adb/socket_test.cpp
@@ -307,6 +307,17 @@
// Don't register a port unless it's all numbers and ends with ':'.
VerifySkipHostSerial(protocol + "foo:123", ":123");
VerifySkipHostSerial(protocol + "foo:123bar:baz", ":123bar:baz");
+
+ VerifySkipHostSerial(protocol + "100.100.100.100:5555:foo", ":foo");
+ VerifySkipHostSerial(protocol + "[0123:4567:89ab:CDEF:0:9:a:f]:5555:foo", ":foo");
+ VerifySkipHostSerial(protocol + "[::1]:5555:foo", ":foo");
+
+ // If we can't find both [] then treat it as a normal serial with [ in it.
+ VerifySkipHostSerial(protocol + "[0123:foo", ":foo");
+
+ // Don't be fooled by random IPv6 addresses in the command string.
+ VerifySkipHostSerial(protocol + "foo:ping [0123:4567:89ab:CDEF:0:9:a:f]:5555",
+ ":ping [0123:4567:89ab:CDEF:0:9:a:f]:5555");
}
}
diff --git a/adb/sockets.cpp b/adb/sockets.cpp
index abba745..b809c4f 100644
--- a/adb/sockets.cpp
+++ b/adb/sockets.cpp
@@ -31,7 +31,7 @@
#include <vector>
#if !ADB_HOST
-#include "cutils/properties.h"
+#include <android-base/properties.h>
#endif
#include "adb.h"
@@ -416,12 +416,12 @@
D("LS(%d): bound to '%s' via %d", s->id, name, fd);
#if !ADB_HOST
- char debug[PROPERTY_VALUE_MAX];
+ bool debuggable = false;
if (!strncmp(name, "root:", 5)) {
- property_get("ro.debuggable", debug, "");
+ debuggable = android::base::GetBoolProperty("ro.debuggable", false);
}
- if ((!strncmp(name, "root:", 5) && getuid() != 0 && strcmp(debug, "1") == 0) ||
+ if ((!strncmp(name, "root:", 5) && getuid() != 0 && debuggable) ||
(!strncmp(name, "unroot:", 7) && getuid() == 0) ||
!strncmp(name, "usb:", 4) ||
!strncmp(name, "tcpip:", 6)) {
@@ -622,21 +622,32 @@
service += 4;
}
- char* first_colon = strchr(service, ':');
- if (!first_colon) {
+ // Check for an IPv6 address. `adb connect` creates the serial number from the canonical
+ // network address so it will always have the [] delimiters.
+ if (service[0] == '[') {
+ char* ipv6_end = strchr(service, ']');
+ if (ipv6_end != nullptr) {
+ service = ipv6_end;
+ }
+ }
+
+ // The next colon we find must either begin the port field or the command field.
+ char* colon_ptr = strchr(service, ':');
+ if (!colon_ptr) {
// No colon in service string.
return nullptr;
}
- char* serial_end = first_colon;
+ // If the next field is only decimal digits and ends with another colon, it's a port.
+ char* serial_end = colon_ptr;
if (isdigit(serial_end[1])) {
serial_end++;
while (*serial_end && isdigit(*serial_end)) {
serial_end++;
}
if (*serial_end != ':') {
- // Something other than numbers was found, reset the end.
- serial_end = first_colon;
+ // Something other than "<port>:" was found, this must be the command field instead.
+ serial_end = colon_ptr;
}
}
return serial_end;
diff --git a/adb/sysdeps.h b/adb/sysdeps.h
index 8d99722..3ed589c 100644
--- a/adb/sysdeps.h
+++ b/adb/sysdeps.h
@@ -97,27 +97,6 @@
return c == '\\' || c == '/';
}
-typedef CRITICAL_SECTION adb_mutex_t;
-
-#define ADB_MUTEX_DEFINE(x) adb_mutex_t x
-
-/* declare all mutexes */
-/* For win32, adb_sysdeps_init() will do the mutex runtime initialization. */
-#define ADB_MUTEX(x) extern adb_mutex_t x;
-#include "mutex_list.h"
-
-extern void adb_sysdeps_init(void);
-
-static __inline__ void adb_mutex_lock( adb_mutex_t* lock )
-{
- EnterCriticalSection( lock );
-}
-
-static __inline__ void adb_mutex_unlock( adb_mutex_t* lock )
-{
- LeaveCriticalSection( lock );
-}
-
typedef void (*adb_thread_func_t)(void* arg);
typedef HANDLE adb_thread_t;
@@ -476,27 +455,6 @@
return c == '/';
}
-typedef pthread_mutex_t adb_mutex_t;
-
-#define ADB_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
-#define adb_mutex_init pthread_mutex_init
-#define adb_mutex_lock pthread_mutex_lock
-#define adb_mutex_unlock pthread_mutex_unlock
-#define adb_mutex_destroy pthread_mutex_destroy
-
-#define ADB_MUTEX_DEFINE(m) adb_mutex_t m = PTHREAD_MUTEX_INITIALIZER
-
-#define adb_cond_t pthread_cond_t
-#define adb_cond_init pthread_cond_init
-#define adb_cond_wait pthread_cond_wait
-#define adb_cond_broadcast pthread_cond_broadcast
-#define adb_cond_signal pthread_cond_signal
-#define adb_cond_destroy pthread_cond_destroy
-
-/* declare all mutexes */
-#define ADB_MUTEX(x) extern adb_mutex_t x;
-#include "mutex_list.h"
-
static __inline__ void close_on_exec(int fd)
{
fcntl( fd, F_SETFD, FD_CLOEXEC );
@@ -818,10 +776,6 @@
#undef mkdir
#define mkdir ___xxx_mkdir
-static __inline__ void adb_sysdeps_init(void)
-{
-}
-
static __inline__ int adb_is_absolute_host_path(const char* path) {
return path[0] == '/';
}
diff --git a/adb/sysdeps_test.cpp b/adb/sysdeps_test.cpp
index f871675..9f77942 100644
--- a/adb/sysdeps_test.cpp
+++ b/adb/sysdeps_test.cpp
@@ -269,17 +269,6 @@
m.unlock();
}
-// Our implementation on Windows aborts on double lock.
-#if defined(_WIN32)
-TEST(sysdeps_mutex, mutex_reentrant_lock) {
- std::mutex &m = *new std::mutex();
-
- m.lock();
- ASSERT_FALSE(m.try_lock());
- EXPECT_DEATH(m.lock(), "non-recursive mutex locked reentrantly");
-}
-#endif
-
TEST(sysdeps_mutex, recursive_mutex_smoke) {
static std::recursive_mutex &m = *new std::recursive_mutex();
diff --git a/adb/sysdeps_win32.cpp b/adb/sysdeps_win32.cpp
index 5fda27b..4dd549d 100644
--- a/adb/sysdeps_win32.cpp
+++ b/adb/sysdeps_win32.cpp
@@ -27,6 +27,7 @@
#include <algorithm>
#include <memory>
+#include <mutex>
#include <string>
#include <unordered_map>
#include <vector>
@@ -137,7 +138,7 @@
#define WIN32_FH_BASE 2048
#define WIN32_MAX_FHS 2048
-static adb_mutex_t _win32_lock;
+static std::mutex& _win32_lock = *new std::mutex();
static FHRec _win32_fhs[ WIN32_MAX_FHS ];
static int _win32_fh_next; // where to start search for free FHRec
@@ -182,27 +183,24 @@
{
FH f = NULL;
- adb_mutex_lock( &_win32_lock );
+ std::lock_guard<std::mutex> lock(_win32_lock);
for (int i = _win32_fh_next; i < WIN32_MAX_FHS; ++i) {
if (_win32_fhs[i].clazz == NULL) {
f = &_win32_fhs[i];
_win32_fh_next = i + 1;
- goto Exit;
+ f->clazz = clazz;
+ f->used = 1;
+ f->eof = 0;
+ f->name[0] = '\0';
+ clazz->_fh_init(f);
+ return f;
}
}
- D( "_fh_alloc: no more free file descriptors" );
- errno = EMFILE; // Too many open files
-Exit:
- if (f) {
- f->clazz = clazz;
- f->used = 1;
- f->eof = 0;
- f->name[0] = '\0';
- clazz->_fh_init(f);
- }
- adb_mutex_unlock( &_win32_lock );
- return f;
+
+ D("_fh_alloc: no more free file descriptors");
+ errno = EMFILE; // Too many open files
+ return nullptr;
}
@@ -211,7 +209,7 @@
{
// Use lock so that closing only happens once and so that _fh_alloc can't
// allocate a FH that we're in the middle of closing.
- adb_mutex_lock(&_win32_lock);
+ std::lock_guard<std::mutex> lock(_win32_lock);
int offset = f - _win32_fhs;
if (_win32_fh_next > offset) {
@@ -225,7 +223,6 @@
f->used = 0;
f->clazz = NULL;
}
- adb_mutex_unlock(&_win32_lock);
return 0;
}
@@ -1234,17 +1231,6 @@
return true;
}
-static adb_mutex_t g_console_output_buffer_lock;
-
-void
-adb_sysdeps_init( void )
-{
-#define ADB_MUTEX(x) InitializeCriticalSection( & x );
-#include "mutex_list.h"
- InitializeCriticalSection( &_win32_lock );
- InitializeCriticalSection( &g_console_output_buffer_lock );
-}
-
/**************************************************************************/
/**************************************************************************/
/***** *****/
@@ -2437,12 +2423,13 @@
// Bytes that have not yet been output to the console because they are incomplete UTF-8 sequences.
// Note that we use only one buffer even though stderr and stdout are logically separate streams.
// This matches the behavior of Linux.
-// Protected by g_console_output_buffer_lock.
-static auto& g_console_output_buffer = *new std::vector<char>();
// Internal helper function to write UTF-8 bytes to a console. Returns -1 on error.
static int _console_write_utf8(const char* const buf, const size_t buf_size, FILE* stream,
HANDLE console) {
+ static std::mutex& console_output_buffer_lock = *new std::mutex();
+ static auto& console_output_buffer = *new std::vector<char>();
+
const int saved_errno = errno;
std::vector<char> combined_buffer;
@@ -2450,24 +2437,25 @@
const char* utf8;
size_t utf8_size;
- adb_mutex_lock(&g_console_output_buffer_lock);
- if (g_console_output_buffer.empty()) {
- // If g_console_output_buffer doesn't have a buffered up incomplete UTF-8 sequence (the
- // common case with plain ASCII), parse buf directly.
- utf8 = buf;
- utf8_size = internal::ParseCompleteUTF8(buf, buf + buf_size, &g_console_output_buffer);
- } else {
- // If g_console_output_buffer has a buffered up incomplete UTF-8 sequence, move it to
- // combined_buffer (and effectively clear g_console_output_buffer) and append buf to
- // combined_buffer, then parse it all together.
- combined_buffer.swap(g_console_output_buffer);
- combined_buffer.insert(combined_buffer.end(), buf, buf + buf_size);
+ {
+ std::lock_guard<std::mutex> lock(console_output_buffer_lock);
+ if (console_output_buffer.empty()) {
+ // If console_output_buffer doesn't have a buffered up incomplete UTF-8 sequence (the
+ // common case with plain ASCII), parse buf directly.
+ utf8 = buf;
+ utf8_size = internal::ParseCompleteUTF8(buf, buf + buf_size, &console_output_buffer);
+ } else {
+ // If console_output_buffer has a buffered up incomplete UTF-8 sequence, move it to
+ // combined_buffer (and effectively clear console_output_buffer) and append buf to
+ // combined_buffer, then parse it all together.
+ combined_buffer.swap(console_output_buffer);
+ combined_buffer.insert(combined_buffer.end(), buf, buf + buf_size);
- utf8 = combined_buffer.data();
- utf8_size = internal::ParseCompleteUTF8(utf8, utf8 + combined_buffer.size(),
- &g_console_output_buffer);
+ utf8 = combined_buffer.data();
+ utf8_size = internal::ParseCompleteUTF8(utf8, utf8 + combined_buffer.size(),
+ &console_output_buffer);
+ }
}
- adb_mutex_unlock(&g_console_output_buffer_lock);
std::wstring utf16;
diff --git a/adb/transport.cpp b/adb/transport.cpp
index 3eaeb06..87712fc 100644
--- a/adb/transport.cpp
+++ b/adb/transport.cpp
@@ -28,6 +28,7 @@
#include <algorithm>
#include <list>
+#include <mutex>
#include <android-base/logging.h>
#include <android-base/parsenetaddress.h>
@@ -44,7 +45,7 @@
static auto& transport_list = *new std::list<atransport*>();
static auto& pending_list = *new std::list<atransport*>();
-ADB_MUTEX_DEFINE( transport_lock );
+static std::mutex& transport_lock = *new std::mutex();
const char* const kFeatureShell2 = "shell_v2";
const char* const kFeatureCmd = "cmd";
@@ -297,13 +298,12 @@
}
void kick_transport(atransport* t) {
- adb_mutex_lock(&transport_lock);
+ std::lock_guard<std::mutex> lock(transport_lock);
// As kick_transport() can be called from threads without guarantee that t is valid,
// check if the transport is in transport_list first.
if (std::find(transport_list.begin(), transport_list.end(), t) != transport_list.end()) {
t->Kick();
}
- adb_mutex_unlock(&transport_lock);
}
static int transport_registration_send = -1;
@@ -333,7 +333,7 @@
device_tracker** pnode = &device_tracker_list;
device_tracker* node = *pnode;
- adb_mutex_lock( &transport_lock );
+ std::lock_guard<std::mutex> lock(transport_lock);
while (node) {
if (node == tracker) {
*pnode = node->next;
@@ -342,7 +342,6 @@
pnode = &node->next;
node = *pnode;
}
- adb_mutex_unlock( &transport_lock );
}
static void
@@ -504,9 +503,10 @@
fdevent_remove(&(t->transport_fde));
adb_close(t->fd);
- adb_mutex_lock(&transport_lock);
- transport_list.remove(t);
- adb_mutex_unlock(&transport_lock);
+ {
+ std::lock_guard<std::mutex> lock(transport_lock);
+ transport_list.remove(t);
+ }
if (t->product)
free(t->product);
@@ -555,10 +555,11 @@
}
}
- adb_mutex_lock(&transport_lock);
- pending_list.remove(t);
- transport_list.push_front(t);
- adb_mutex_unlock(&transport_lock);
+ {
+ std::lock_guard<std::mutex> lock(transport_lock);
+ pending_list.remove(t);
+ transport_list.push_front(t);
+ }
update_transports();
}
@@ -609,7 +610,8 @@
static void transport_unref(atransport* t) {
CHECK(t != nullptr);
- adb_mutex_lock(&transport_lock);
+
+ std::lock_guard<std::mutex> lock(transport_lock);
CHECK_GT(t->ref_count, 0u);
t->ref_count--;
if (t->ref_count == 0) {
@@ -619,7 +621,6 @@
} else {
D("transport: %s unref (count=%zu)", t->serial, t->ref_count);
}
- adb_mutex_unlock(&transport_lock);
}
static int qual_match(const char *to_test,
@@ -665,7 +666,7 @@
*error_out = "no devices found";
}
- adb_mutex_lock(&transport_lock);
+ std::unique_lock<std::mutex> lock(transport_lock);
for (const auto& t : transport_list) {
if (t->connection_state == kCsNoPerm) {
#if ADB_HOST
@@ -713,7 +714,7 @@
}
}
}
- adb_mutex_unlock(&transport_lock);
+ lock.unlock();
// Don't return unauthorized devices; the caller can't do anything with them.
if (result && result->connection_state == kCsUnauthorized) {
@@ -914,21 +915,20 @@
std::string list_transports(bool long_listing) {
std::string result;
- adb_mutex_lock(&transport_lock);
+
+ std::lock_guard<std::mutex> lock(transport_lock);
for (const auto& t : transport_list) {
append_transport(t, &result, long_listing);
}
- adb_mutex_unlock(&transport_lock);
return result;
}
/* hack for osx */
void close_usb_devices() {
- adb_mutex_lock(&transport_lock);
+ std::lock_guard<std::mutex> lock(transport_lock);
for (const auto& t : transport_list) {
t->Kick();
}
- adb_mutex_unlock(&transport_lock);
}
#endif // ADB_HOST
@@ -947,10 +947,9 @@
return -1;
}
- adb_mutex_lock(&transport_lock);
+ std::unique_lock<std::mutex> lock(transport_lock);
for (const auto& transport : pending_list) {
if (transport->serial && strcmp(serial, transport->serial) == 0) {
- adb_mutex_unlock(&transport_lock);
VLOG(TRANSPORT) << "socket transport " << transport->serial
<< " is already in pending_list and fails to register";
delete t;
@@ -960,7 +959,6 @@
for (const auto& transport : transport_list) {
if (transport->serial && strcmp(serial, transport->serial) == 0) {
- adb_mutex_unlock(&transport_lock);
VLOG(TRANSPORT) << "socket transport " << transport->serial
<< " is already in transport_list and fails to register";
delete t;
@@ -970,7 +968,8 @@
pending_list.push_front(t);
t->serial = strdup(serial);
- adb_mutex_unlock(&transport_lock);
+
+ lock.unlock();
register_transport(t);
return 0;
@@ -980,20 +979,19 @@
atransport *find_transport(const char *serial) {
atransport* result = nullptr;
- adb_mutex_lock(&transport_lock);
+ std::lock_guard<std::mutex> lock(transport_lock);
for (auto& t : transport_list) {
if (t->serial && strcmp(serial, t->serial) == 0) {
result = t;
break;
}
}
- adb_mutex_unlock(&transport_lock);
return result;
}
void kick_all_tcp_devices() {
- adb_mutex_lock(&transport_lock);
+ std::lock_guard<std::mutex> lock(transport_lock);
for (auto& t : transport_list) {
if (t->IsTcpDevice()) {
// Kicking breaks the read_transport thread of this transport out of any read, then
@@ -1003,7 +1001,6 @@
t->Kick();
}
}
- adb_mutex_unlock(&transport_lock);
}
#endif
@@ -1023,20 +1020,20 @@
t->devpath = strdup(devpath);
}
- adb_mutex_lock(&transport_lock);
- pending_list.push_front(t);
- adb_mutex_unlock(&transport_lock);
+ {
+ std::lock_guard<std::mutex> lock(transport_lock);
+ pending_list.push_front(t);
+ }
register_transport(t);
}
// This should only be used for transports with connection_state == kCsNoPerm.
void unregister_usb_transport(usb_handle *usb) {
- adb_mutex_lock(&transport_lock);
+ std::lock_guard<std::mutex> lock(transport_lock);
transport_list.remove_if([usb](atransport* t) {
return t->usb == usb && t->connection_state == kCsNoPerm;
});
- adb_mutex_unlock(&transport_lock);
}
int check_header(apacket *p, atransport *t)
diff --git a/adb/transport_local.cpp b/adb/transport_local.cpp
index 89e950d..a94b41e 100644
--- a/adb/transport_local.cpp
+++ b/adb/transport_local.cpp
@@ -26,13 +26,14 @@
#include <sys/types.h>
#include <condition_variable>
+#include <mutex>
#include <vector>
#include <android-base/stringprintf.h>
#include <cutils/sockets.h>
#if !ADB_HOST
-#include "cutils/properties.h"
+#include <android-base/properties.h>
#endif
#include "adb.h"
@@ -47,7 +48,7 @@
// connected.
#define ADB_LOCAL_TRANSPORT_MAX 16
-ADB_MUTEX_DEFINE(local_transports_lock);
+static std::mutex& local_transports_lock = *new std::mutex();
/* we keep a list of opened transports. The atransport struct knows to which
* local transport it is connected. The list is used to detect when we're
@@ -355,15 +356,13 @@
func = client_socket_thread;
debug_name = "client";
#else
- /* For the adbd daemon in the system image we need to distinguish
- * between the device, and the emulator. */
- char is_qemu[PROPERTY_VALUE_MAX];
- property_get("ro.kernel.qemu", is_qemu, "");
- if (!strcmp(is_qemu, "1")) {
- /* Running inside the emulator: use QEMUD pipe as the transport. */
+ // For the adbd daemon in the system image we need to distinguish
+ // between the device, and the emulator.
+ if (android::base::GetBoolProperty("ro.kernel.qemu", false)) {
+ // Running inside the emulator: use QEMUD pipe as the transport.
func = qemu_socket_thread;
} else {
- /* Running inside the device: use TCP socket as the transport. */
+ // Running inside the device: use TCP socket as the transport.
func = server_socket_thread;
}
debug_name = "server";
@@ -384,14 +383,13 @@
#if ADB_HOST
int nn;
- adb_mutex_lock( &local_transports_lock );
+ std::lock_guard<std::mutex> lock(local_transports_lock);
for (nn = 0; nn < ADB_LOCAL_TRANSPORT_MAX; nn++) {
if (local_transports[nn] == t) {
local_transports[nn] = NULL;
break;
}
}
- adb_mutex_unlock( &local_transports_lock );
#endif
}
@@ -435,9 +433,8 @@
atransport* find_emulator_transport_by_adb_port(int adb_port)
{
- adb_mutex_lock( &local_transports_lock );
+ std::lock_guard<std::mutex> lock(local_transports_lock);
atransport* result = find_emulator_transport_by_adb_port_locked(adb_port);
- adb_mutex_unlock( &local_transports_lock );
return result;
}
@@ -455,9 +452,8 @@
int get_available_local_transport_index()
{
- adb_mutex_lock( &local_transports_lock );
+ std::lock_guard<std::mutex> lock(local_transports_lock);
int result = get_available_local_transport_index_locked();
- adb_mutex_unlock( &local_transports_lock );
return result;
}
#endif
@@ -477,26 +473,20 @@
#if ADB_HOST
if (local) {
- adb_mutex_lock( &local_transports_lock );
- {
- t->SetLocalPortForEmulator(adb_port);
- atransport* existing_transport =
- find_emulator_transport_by_adb_port_locked(adb_port);
- int index = get_available_local_transport_index_locked();
- if (existing_transport != NULL) {
- D("local transport for port %d already registered (%p)?",
- adb_port, existing_transport);
- fail = -1;
- } else if (index < 0) {
- // Too many emulators.
- D("cannot register more emulators. Maximum is %d",
- ADB_LOCAL_TRANSPORT_MAX);
- fail = -1;
- } else {
- local_transports[index] = t;
- }
- }
- adb_mutex_unlock( &local_transports_lock );
+ std::lock_guard<std::mutex> lock(local_transports_lock);
+ t->SetLocalPortForEmulator(adb_port);
+ atransport* existing_transport = find_emulator_transport_by_adb_port_locked(adb_port);
+ int index = get_available_local_transport_index_locked();
+ if (existing_transport != NULL) {
+ D("local transport for port %d already registered (%p)?", adb_port, existing_transport);
+ fail = -1;
+ } else if (index < 0) {
+ // Too many emulators.
+ D("cannot register more emulators. Maximum is %d", ADB_LOCAL_TRANSPORT_MAX);
+ fail = -1;
+ } else {
+ local_transports[index] = t;
+ }
}
#endif
return fail;
diff --git a/adb/transport_test.cpp b/adb/transport_test.cpp
index a6db07a..8b38e03 100644
--- a/adb/transport_test.cpp
+++ b/adb/transport_test.cpp
@@ -20,27 +20,6 @@
#include "adb.h"
-class TransportSetup {
-public:
- TransportSetup() {
-#ifdef _WIN32
- // Use extern instead of including sysdeps.h which brings in various macros
- // that conflict with APIs used in this file.
- extern void adb_sysdeps_init(void);
- adb_sysdeps_init();
-#else
- // adb_sysdeps_init() is an inline function that we cannot link against.
-#endif
- }
-};
-
-// Static initializer will call adb_sysdeps_init() before main() to initialize
-// the transport mutex before it is used in the tests. Alternatives would be to
-// use __attribute__((constructor)) here or to use that or a static initializer
-// for adb_sysdeps_init() itself in sysdeps_win32.cpp (caveats of unclear
-// init order), or to use a test fixture whose SetUp() could do the init once.
-static TransportSetup g_TransportSetup;
-
TEST(transport, kick_transport) {
atransport t;
static size_t kick_count;
diff --git a/adb/usb_linux_client.cpp b/adb/usb_linux_client.cpp
index 0ba6b4b..6de10f5 100644
--- a/adb/usb_linux_client.cpp
+++ b/adb/usb_linux_client.cpp
@@ -18,7 +18,6 @@
#include "sysdeps.h"
-#include <cutils/properties.h>
#include <dirent.h>
#include <errno.h>
#include <linux/usb/ch9.h>
@@ -32,8 +31,11 @@
#include <algorithm>
#include <atomic>
+#include <condition_variable>
+#include <mutex>
#include <android-base/logging.h>
+#include <android-base/properties.h>
#include "adb.h"
#include "transport.h"
@@ -54,12 +56,14 @@
static int dummy_fd = -1;
-struct usb_handle
-{
- adb_cond_t notify;
- adb_mutex_t lock;
- bool open_new_connection;
+struct usb_handle {
+ usb_handle() : kicked(false) {
+ }
+
+ std::condition_variable notify;
+ std::mutex lock;
std::atomic<bool> kicked;
+ bool open_new_connection = true;
int (*write)(usb_handle *h, const void *data, int len);
int (*read)(usb_handle *h, void *data, int len);
@@ -67,12 +71,12 @@
void (*close)(usb_handle *h);
// Legacy f_adb
- int fd;
+ int fd = -1;
// FunctionFS
- int control;
- int bulk_out; /* "out" from the host's perspective => source for adbd */
- int bulk_in; /* "in" from the host's perspective => sink for adbd */
+ int control = -1;
+ int bulk_out = -1; /* "out" from the host's perspective => source for adbd */
+ int bulk_in = -1; /* "in" from the host's perspective => sink for adbd */
};
struct func_desc {
@@ -248,12 +252,12 @@
while (true) {
// wait until the USB device needs opening
- adb_mutex_lock(&usb->lock);
+ std::unique_lock<std::mutex> lock(usb->lock);
while (!usb->open_new_connection) {
- adb_cond_wait(&usb->notify, &usb->lock);
+ usb->notify.wait(lock);
}
usb->open_new_connection = false;
- adb_mutex_unlock(&usb->lock);
+ lock.unlock();
D("[ usb_thread - opening device ]");
do {
@@ -339,27 +343,20 @@
h->kicked = false;
adb_close(h->fd);
// Notify usb_adb_open_thread to open a new connection.
- adb_mutex_lock(&h->lock);
+ h->lock.lock();
h->open_new_connection = true;
- adb_cond_signal(&h->notify);
- adb_mutex_unlock(&h->lock);
+ h->lock.unlock();
+ h->notify.notify_one();
}
static void usb_adb_init()
{
- usb_handle* h = reinterpret_cast<usb_handle*>(calloc(1, sizeof(usb_handle)));
- if (h == nullptr) fatal("couldn't allocate usb_handle");
+ usb_handle* h = new usb_handle();
h->write = usb_adb_write;
h->read = usb_adb_read;
h->kick = usb_adb_kick;
h->close = usb_adb_close;
- h->kicked = false;
- h->fd = -1;
-
- h->open_new_connection = true;
- adb_cond_init(&h->notify, 0);
- adb_mutex_init(&h->lock, 0);
// Open the file /dev/android_adb_enable to trigger
// the enabling of the adb USB function in the kernel.
@@ -468,12 +465,12 @@
while (true) {
// wait until the USB device needs opening
- adb_mutex_lock(&usb->lock);
+ std::unique_lock<std::mutex> lock(usb->lock);
while (!usb->open_new_connection) {
- adb_cond_wait(&usb->notify, &usb->lock);
+ usb->notify.wait(lock);
}
usb->open_new_connection = false;
- adb_mutex_unlock(&usb->lock);
+ lock.unlock();
while (true) {
if (init_functionfs(usb)) {
@@ -481,7 +478,7 @@
}
adb_sleep_ms(1000);
}
- property_set("sys.usb.ffs.ready", "1");
+ android::base::SetProperty("sys.usb.ffs.ready", "1");
D("[ usb_thread - registering device ]");
register_usb_transport(usb, 0, 0, 1);
@@ -557,31 +554,22 @@
adb_close(h->bulk_out);
adb_close(h->bulk_in);
// Notify usb_adb_open_thread to open a new connection.
- adb_mutex_lock(&h->lock);
+ h->lock.lock();
h->open_new_connection = true;
- adb_cond_signal(&h->notify);
- adb_mutex_unlock(&h->lock);
+ h->lock.unlock();
+ h->notify.notify_one();
}
static void usb_ffs_init()
{
D("[ usb_init - using FunctionFS ]");
- usb_handle* h = reinterpret_cast<usb_handle*>(calloc(1, sizeof(usb_handle)));
- if (h == nullptr) fatal("couldn't allocate usb_handle");
+ usb_handle* h = new usb_handle();
h->write = usb_ffs_write;
h->read = usb_ffs_read;
h->kick = usb_ffs_kick;
h->close = usb_ffs_close;
- h->kicked = false;
- h->control = -1;
- h->bulk_out = -1;
- h->bulk_out = -1;
-
- h->open_new_connection = true;
- adb_cond_init(&h->notify, 0);
- adb_mutex_init(&h->lock, 0);
D("[ usb_init - starting thread ]");
if (!adb_thread_create(usb_ffs_open_thread, h)) {
@@ -608,6 +596,7 @@
{
return h->read(h, data, len);
}
+
int usb_close(usb_handle *h)
{
h->close(h);
diff --git a/adb/usb_osx.cpp b/adb/usb_osx.cpp
index ddde454..adcbb3e 100644
--- a/adb/usb_osx.cpp
+++ b/adb/usb_osx.cpp
@@ -177,6 +177,7 @@
kr = (*iface)->GetDevice(iface, &usbDevice);
if (kIOReturnSuccess != kr || !usbDevice) {
LOG(ERROR) << "Couldn't grab device from interface (" << std::hex << kr << ")";
+ (*iface)->Release(iface);
continue;
}
@@ -191,6 +192,7 @@
(void)IOObjectRelease(usbDevice);
if ((kIOReturnSuccess != kr) || (!plugInInterface)) {
LOG(ERROR) << "Unable to create a device plug-in (" << std::hex << kr << ")";
+ (*iface)->Release(iface);
continue;
}
@@ -200,6 +202,7 @@
(*plugInInterface)->Release(plugInInterface);
if (result || !dev) {
LOG(ERROR) << "Couldn't create a device interface (" << std::hex << result << ")";
+ (*iface)->Release(iface);
continue;
}
@@ -211,6 +214,8 @@
if (kr == KERN_SUCCESS) {
devpath = android::base::StringPrintf("usb:%" PRIu32 "X", locationId);
if (IsKnownDevice(devpath)) {
+ (*dev)->Release(dev);
+ (*iface)->Release(iface);
continue;
}
}
diff --git a/adb/usb_windows.cpp b/adb/usb_windows.cpp
index 8ecca37..4649454 100644
--- a/adb/usb_windows.cpp
+++ b/adb/usb_windows.cpp
@@ -19,13 +19,17 @@
#include "sysdeps.h"
#include <winsock2.h> // winsock.h *must* be included before windows.h.
-#include <adb_api.h>
+#include <windows.h>
+#include <usb100.h>
+#include <winerror.h>
+
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
-#include <usb100.h>
-#include <windows.h>
-#include <winerror.h>
+
+#include <mutex>
+
+#include <adb_api.h>
#include <android-base/errors.h>
@@ -73,7 +77,7 @@
};
/// Locker for the list of opened usb handles
-ADB_MUTEX_DEFINE( usb_lock );
+static std::mutex& usb_lock = *new std::mutex();
/// Checks if there is opened usb handle in handle_list for this device.
int known_device(const wchar_t* dev_name);
@@ -141,9 +145,8 @@
int ret = 0;
if (NULL != dev_name) {
- adb_mutex_lock(&usb_lock);
+ std::lock_guard<std::mutex> lock(usb_lock);
ret = known_device_locked(dev_name);
- adb_mutex_unlock(&usb_lock);
}
return ret;
@@ -153,11 +156,10 @@
if (NULL == handle)
return 0;
- adb_mutex_lock(&usb_lock);
+ std::lock_guard<std::mutex> lock(usb_lock);
// Check if device is already in the list
if (known_device_locked(handle->interface_name)) {
- adb_mutex_unlock(&usb_lock);
return 0;
}
@@ -167,8 +169,6 @@
handle->prev->next = handle;
handle->next->prev = handle;
- adb_mutex_unlock(&usb_lock);
-
return 1;
}
@@ -493,11 +493,8 @@
void usb_kick(usb_handle* handle) {
D("usb_kick");
if (NULL != handle) {
- adb_mutex_lock(&usb_lock);
-
+ std::lock_guard<std::mutex> lock(usb_lock);
usb_kick_locked(handle);
-
- adb_mutex_unlock(&usb_lock);
} else {
errno = EINVAL;
}
@@ -508,17 +505,17 @@
if (NULL != handle) {
// Remove handle from the list
- adb_mutex_lock(&usb_lock);
+ {
+ std::lock_guard<std::mutex> lock(usb_lock);
- if ((handle->next != handle) && (handle->prev != handle)) {
- handle->next->prev = handle->prev;
- handle->prev->next = handle->next;
- handle->prev = handle;
- handle->next = handle;
+ if ((handle->next != handle) && (handle->prev != handle)) {
+ handle->next->prev = handle->prev;
+ handle->prev->next = handle->next;
+ handle->prev = handle;
+ handle->next = handle;
+ }
}
- adb_mutex_unlock(&usb_lock);
-
// Cleanup handle
usb_cleanup_handle(handle);
free(handle);
@@ -651,9 +648,8 @@
static void kick_devices() {
// Need to acquire lock to safely walk the list which might be modified
// by another thread.
- adb_mutex_lock(&usb_lock);
+ std::lock_guard<std::mutex> lock(usb_lock);
for (usb_handle* usb = handle_list.next; usb != &handle_list; usb = usb->next) {
usb_kick_locked(usb);
}
- adb_mutex_unlock(&usb_lock);
}
diff --git a/adf/libadfhwc/Android.bp b/adf/libadfhwc/Android.bp
index 86f0c9c..57a8d76 100644
--- a/adf/libadfhwc/Android.bp
+++ b/adf/libadfhwc/Android.bp
@@ -21,7 +21,7 @@
"libutils",
],
cflags: [
- "-DLOG_TAG=\\\"adfhwc\\\"",
+ "-DLOG_TAG=\"adfhwc\"",
"-Werror",
],
local_include_dirs: ["include"],
diff --git a/adf/libadfhwc/adfhwc.cpp b/adf/libadfhwc/adfhwc.cpp
index 21f245e..7d5b555 100644
--- a/adf/libadfhwc/adfhwc.cpp
+++ b/adf/libadfhwc/adfhwc.cpp
@@ -20,12 +20,12 @@
#include <pthread.h>
#include <sys/resource.h>
+#include <android/log.h>
+#include <utils/Vector.h>
+
#include <adf/adf.h>
#include <adfhwc/adfhwc.h>
-#include <cutils/log.h>
-#include <utils/Vector.h>
-
struct adf_hwc_helper {
adf_hwc_event_callbacks const *event_cb;
void *event_cb_data;
diff --git a/base/Android.bp b/base/Android.bp
index e260412..88d8ad1 100644
--- a/base/Android.bp
+++ b/base/Android.bp
@@ -39,7 +39,10 @@
shared_libs: ["liblog"],
target: {
android: {
- srcs: ["errors_unix.cpp"],
+ srcs: [
+ "errors_unix.cpp",
+ "properties.cpp",
+ ],
cppflags: ["-Wexit-time-destructors"],
},
darwin: {
@@ -78,6 +81,9 @@
"test_main.cpp",
],
target: {
+ android: {
+ srcs: ["properties_test.cpp"],
+ },
windows: {
srcs: ["utf8_test.cpp"],
enabled: true,
diff --git a/base/include/android-base/logging.h b/base/include/android-base/logging.h
index e8b445f..50677a3 100644
--- a/base/include/android-base/logging.h
+++ b/base/include/android-base/logging.h
@@ -120,6 +120,39 @@
DISALLOW_COPY_AND_ASSIGN(ErrnoRestorer);
};
+// A helper macro that produces an expression that accepts both a qualified name and an
+// unqualified name for a LogSeverity, and returns a LogSeverity value.
+// Note: DO NOT USE DIRECTLY. This is an implementation detail.
+#define SEVERITY_LAMBDA(severity) ([&]() { \
+ using ::android::base::VERBOSE; \
+ using ::android::base::DEBUG; \
+ using ::android::base::INFO; \
+ using ::android::base::WARNING; \
+ using ::android::base::ERROR; \
+ using ::android::base::FATAL_WITHOUT_ABORT; \
+ using ::android::base::FATAL; \
+ return (severity); }())
+
+// Defines whether the given severity will be logged or silently swallowed.
+#define WOULD_LOG(severity) \
+ UNLIKELY((SEVERITY_LAMBDA(severity)) >= ::android::base::GetMinimumLogSeverity())
+
+// Get an ostream that can be used for logging at the given severity and to the default
+// destination.
+//
+// Notes:
+// 1) This will not check whether the severity is high enough. One should use WOULD_LOG to filter
+// usage manually.
+// 2) This does not save and restore errno.
+#define LOG_STREAM(severity) LOG_STREAM_TO(DEFAULT, severity)
+
+// Get an ostream that can be used for logging at the given severity and to the
+// given destination. The same notes as for LOG_STREAM apply.
+#define LOG_STREAM_TO(dest, severity) \
+ ::android::base::LogMessage(__FILE__, __LINE__, \
+ ::android::base::dest, \
+ SEVERITY_LAMBDA(severity), -1).stream()
+
// Logs a message to logcat on Android otherwise to stderr. If the severity is
// FATAL it also causes an abort. For example:
//
@@ -132,24 +165,23 @@
// else statement after LOG() macro, it won't bind to the if statement in the macro.
// do-while(0) statement doesn't work here. Because we need to support << operator
// following the macro, like "LOG(DEBUG) << xxx;".
-#define LOG_TO(dest, severity) \
- UNLIKELY(::android::base::severity >= ::android::base::GetMinimumLogSeverity()) && \
- ::android::base::ErrnoRestorer() && \
- ::android::base::LogMessage(__FILE__, __LINE__, \
- ::android::base::dest, \
- ::android::base::severity, -1).stream()
+
+#define LOG_TO(dest, severity) \
+ WOULD_LOG(severity) && \
+ ::android::base::ErrnoRestorer() && \
+ LOG_STREAM_TO(dest, severity)
// A variant of LOG that also logs the current errno value. To be used when
// library calls fail.
#define PLOG(severity) PLOG_TO(DEFAULT, severity)
// Behaves like PLOG, but logs to the specified log ID.
-#define PLOG_TO(dest, severity) \
- UNLIKELY(::android::base::severity >= ::android::base::GetMinimumLogSeverity()) && \
- ::android::base::ErrnoRestorer() && \
- ::android::base::LogMessage(__FILE__, __LINE__, \
- ::android::base::dest, \
- ::android::base::severity, errno).stream()
+#define PLOG_TO(dest, severity) \
+ WOULD_LOG(SEVERITY_LAMBDA(severity)) && \
+ ::android::base::ErrnoRestorer() && \
+ ::android::base::LogMessage(__FILE__, __LINE__, \
+ ::android::base::dest, \
+ SEVERITY_LAMBDA(severity), errno).stream()
// Marker that code is yet to be implemented.
#define UNIMPLEMENTED(level) \
diff --git a/base/include/android-base/properties.h b/base/include/android-base/properties.h
new file mode 100644
index 0000000..95d1b6a
--- /dev/null
+++ b/base/include/android-base/properties.h
@@ -0,0 +1,64 @@
+/*
+ * 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_PROPERTIES_H
+#define ANDROID_BASE_PROPERTIES_H
+
+#include <sys/cdefs.h>
+
+#if !defined(__BIONIC__)
+#error Only bionic supports system properties.
+#endif
+
+#include <limits>
+#include <string>
+
+namespace android {
+namespace base {
+
+// Returns the current value of the system property `key`,
+// or `default_value` if the property is empty or doesn't exist.
+std::string GetProperty(const std::string& key, const std::string& default_value);
+
+// Returns true if the system property `key` has the value "1", "y", "yes", "on", or "true",
+// false for "0", "n", "no", "off", or "false", or `default_value` otherwise.
+bool GetBoolProperty(const std::string& key, bool default_value);
+
+// Returns the signed integer corresponding to the system property `key`.
+// If the property is empty, doesn't exist, doesn't have an integer value, or is outside
+// the optional bounds, returns `default_value`.
+template <typename T> T GetIntProperty(const std::string& key,
+ T default_value,
+ T min = std::numeric_limits<T>::min(),
+ T max = std::numeric_limits<T>::max());
+
+// Returns the unsigned integer corresponding to the system property `key`.
+// If the property is empty, doesn't exist, doesn't have an integer value, or is outside
+// the optional bound, returns `default_value`.
+template <typename T> T GetUintProperty(const std::string& key,
+ T default_value,
+ T max = std::numeric_limits<T>::max());
+
+// Sets the system property `key` to `value`.
+// Note that system property setting is inherently asynchronous so a return value of `true`
+// isn't particularly meaningful, and immediately reading back the value won't necessarily
+// tell you whether or not your call succeeded. A `false` return value definitely means failure.
+bool SetProperty(const std::string& key, const std::string& value);
+
+} // namespace base
+} // namespace android
+
+#endif // ANDROID_BASE_MEMORY_H
diff --git a/base/include/android-base/unique_fd.h b/base/include/android-base/unique_fd.h
index c323311..6cfcfcd 100644
--- a/base/include/android-base/unique_fd.h
+++ b/base/include/android-base/unique_fd.h
@@ -55,7 +55,7 @@
unique_fd_impl() : value_(-1) {}
explicit unique_fd_impl(int value) : value_(value) {}
- ~unique_fd_impl() { clear(); }
+ ~unique_fd_impl() { reset(); }
unique_fd_impl(unique_fd_impl&& other) : value_(other.release()) {}
unique_fd_impl& operator=(unique_fd_impl&& s) {
@@ -63,17 +63,13 @@
return *this;
}
- void reset(int new_value) {
+ void reset(int new_value = -1) {
if (value_ != -1) {
Closer::Close(value_);
}
value_ = new_value;
}
- void clear() {
- reset(-1);
- }
-
int get() const { return value_; }
operator int() const { return get(); }
diff --git a/base/logging.cpp b/base/logging.cpp
index 77a0a43..ece10ec 100644
--- a/base/logging.cpp
+++ b/base/logging.cpp
@@ -43,18 +43,18 @@
#include <utility>
#include <vector>
-#include "android-base/macros.h"
-#include "android-base/strings.h"
-
// Headers for LogMessage::LogLine.
#ifdef __ANDROID__
+#include <android/log.h>
#include <android/set_abort_message.h>
-#include "log/log.h"
#else
#include <sys/types.h>
#include <unistd.h>
#endif
+#include <android-base/macros.h>
+#include <android-base/strings.h>
+
// For gettid.
#if defined(__APPLE__)
#include "AvailabilityMacros.h" // For MAC_OS_X_VERSION_MAX_ALLOWED
@@ -390,6 +390,11 @@
}
LogMessage::~LogMessage() {
+ // Check severity again. This is duplicate work wrt/ LOG macros, but not LOG_STREAM.
+ if (!WOULD_LOG(data_->GetSeverity())) {
+ return;
+ }
+
// Finish constructing the message.
if (data_->GetError() != -1) {
data_->GetBuffer() << ": " << strerror(data_->GetError());
diff --git a/base/logging_test.cpp b/base/logging_test.cpp
index 8813525..9fc7736 100644
--- a/base/logging_test.cpp
+++ b/base/logging_test.cpp
@@ -142,6 +142,92 @@
// we don't get more bit-rot).
}
+
+#define CHECK_WOULD_LOG_DISABLED(severity) \
+ static_assert(android::base::severity < android::base::FATAL, "Bad input"); \
+ for (size_t i = static_cast<size_t>(android::base::severity) + 1; \
+ i <= static_cast<size_t>(android::base::FATAL); \
+ ++i) { \
+ { \
+ android::base::ScopedLogSeverity sls2(static_cast<android::base::LogSeverity>(i)); \
+ EXPECT_FALSE(WOULD_LOG(severity)) << i; \
+ } \
+ { \
+ android::base::ScopedLogSeverity sls2(static_cast<android::base::LogSeverity>(i)); \
+ EXPECT_FALSE(WOULD_LOG(::android::base::severity)) << i; \
+ } \
+ } \
+
+#define CHECK_WOULD_LOG_ENABLED(severity) \
+ for (size_t i = static_cast<size_t>(android::base::VERBOSE); \
+ i <= static_cast<size_t>(android::base::severity); \
+ ++i) { \
+ { \
+ android::base::ScopedLogSeverity sls2(static_cast<android::base::LogSeverity>(i)); \
+ EXPECT_TRUE(WOULD_LOG(severity)) << i; \
+ } \
+ { \
+ android::base::ScopedLogSeverity sls2(static_cast<android::base::LogSeverity>(i)); \
+ EXPECT_TRUE(WOULD_LOG(::android::base::severity)) << i; \
+ } \
+ } \
+
+TEST(logging, WOULD_LOG_FATAL) {
+ CHECK_WOULD_LOG_ENABLED(FATAL);
+}
+
+TEST(logging, WOULD_LOG_FATAL_WITHOUT_ABORT_disabled) {
+ CHECK_WOULD_LOG_DISABLED(FATAL_WITHOUT_ABORT);
+}
+
+TEST(logging, WOULD_LOG_FATAL_WITHOUT_ABORT_enabled) {
+ CHECK_WOULD_LOG_ENABLED(FATAL_WITHOUT_ABORT);
+}
+
+TEST(logging, WOULD_LOG_ERROR_disabled) {
+ CHECK_WOULD_LOG_DISABLED(ERROR);
+}
+
+TEST(logging, WOULD_LOG_ERROR_enabled) {
+ CHECK_WOULD_LOG_ENABLED(ERROR);
+}
+
+TEST(logging, WOULD_LOG_WARNING_disabled) {
+ CHECK_WOULD_LOG_DISABLED(WARNING);
+}
+
+TEST(logging, WOULD_LOG_WARNING_enabled) {
+ CHECK_WOULD_LOG_ENABLED(WARNING);
+}
+
+TEST(logging, WOULD_LOG_INFO_disabled) {
+ CHECK_WOULD_LOG_DISABLED(INFO);
+}
+
+TEST(logging, WOULD_LOG_INFO_enabled) {
+ CHECK_WOULD_LOG_ENABLED(INFO);
+}
+
+TEST(logging, WOULD_LOG_DEBUG_disabled) {
+ CHECK_WOULD_LOG_DISABLED(DEBUG);
+}
+
+TEST(logging, WOULD_LOG_DEBUG_enabled) {
+ CHECK_WOULD_LOG_ENABLED(DEBUG);
+}
+
+TEST(logging, WOULD_LOG_VERBOSE_disabled) {
+ CHECK_WOULD_LOG_DISABLED(VERBOSE);
+}
+
+TEST(logging, WOULD_LOG_VERBOSE_enabled) {
+ CHECK_WOULD_LOG_ENABLED(VERBOSE);
+}
+
+#undef CHECK_WOULD_LOG_DISABLED
+#undef CHECK_WOULD_LOG_ENABLED
+
+
static std::string make_log_pattern(android::base::LogSeverity severity,
const char* message) {
static const char log_characters[] = "VDIWEFF";
@@ -154,18 +240,6 @@
log_char, basename(&holder[0]), message);
}
-#define CHECK_LOG_DISABLED(severity) \
- android::base::ScopedLogSeverity sls1(android::base::FATAL); \
- CapturedStderr cap1; \
- LOG(severity) << "foo bar"; \
- ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \
-
-#define CHECK_LOG_ENABLED(severity) \
- android::base::ScopedLogSeverity sls2(android::base::severity); \
- CapturedStderr cap2; \
- LOG(severity) << "foobar"; \
- CheckMessage(cap2, android::base::severity, "foobar"); \
-
static void CheckMessage(const CapturedStderr& cap,
android::base::LogSeverity severity, const char* expected) {
std::string output;
@@ -184,8 +258,118 @@
#endif
}
+
+#define CHECK_LOG_STREAM_DISABLED(severity) \
+ { \
+ android::base::ScopedLogSeverity sls1(android::base::FATAL); \
+ CapturedStderr cap1; \
+ LOG_STREAM(severity) << "foo bar"; \
+ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \
+ } \
+ { \
+ android::base::ScopedLogSeverity sls1(android::base::FATAL); \
+ CapturedStderr cap1; \
+ LOG_STREAM(::android::base::severity) << "foo bar"; \
+ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \
+ } \
+
+#define CHECK_LOG_STREAM_ENABLED(severity) \
+ { \
+ android::base::ScopedLogSeverity sls2(android::base::severity); \
+ CapturedStderr cap2; \
+ LOG_STREAM(severity) << "foobar"; \
+ CheckMessage(cap2, android::base::severity, "foobar"); \
+ } \
+ { \
+ android::base::ScopedLogSeverity sls2(android::base::severity); \
+ CapturedStderr cap2; \
+ LOG_STREAM(::android::base::severity) << "foobar"; \
+ CheckMessage(cap2, android::base::severity, "foobar"); \
+ } \
+
+TEST(logging, LOG_STREAM_FATAL_WITHOUT_ABORT_disabled) {
+ CHECK_LOG_STREAM_DISABLED(FATAL_WITHOUT_ABORT);
+}
+
+TEST(logging, LOG_STREAM_FATAL_WITHOUT_ABORT_enabled) {
+ CHECK_LOG_STREAM_ENABLED(FATAL_WITHOUT_ABORT);
+}
+
+TEST(logging, LOG_STREAM_ERROR_disabled) {
+ CHECK_LOG_STREAM_DISABLED(ERROR);
+}
+
+TEST(logging, LOG_STREAM_ERROR_enabled) {
+ CHECK_LOG_STREAM_ENABLED(ERROR);
+}
+
+TEST(logging, LOG_STREAM_WARNING_disabled) {
+ CHECK_LOG_STREAM_DISABLED(WARNING);
+}
+
+TEST(logging, LOG_STREAM_WARNING_enabled) {
+ CHECK_LOG_STREAM_ENABLED(WARNING);
+}
+
+TEST(logging, LOG_STREAM_INFO_disabled) {
+ CHECK_LOG_STREAM_DISABLED(INFO);
+}
+
+TEST(logging, LOG_STREAM_INFO_enabled) {
+ CHECK_LOG_STREAM_ENABLED(INFO);
+}
+
+TEST(logging, LOG_STREAM_DEBUG_disabled) {
+ CHECK_LOG_STREAM_DISABLED(DEBUG);
+}
+
+TEST(logging, LOG_STREAM_DEBUG_enabled) {
+ CHECK_LOG_STREAM_ENABLED(DEBUG);
+}
+
+TEST(logging, LOG_STREAM_VERBOSE_disabled) {
+ CHECK_LOG_STREAM_DISABLED(VERBOSE);
+}
+
+TEST(logging, LOG_STREAM_VERBOSE_enabled) {
+ CHECK_LOG_STREAM_ENABLED(VERBOSE);
+}
+
+#undef CHECK_LOG_STREAM_DISABLED
+#undef CHECK_LOG_STREAM_ENABLED
+
+
+#define CHECK_LOG_DISABLED(severity) \
+ { \
+ android::base::ScopedLogSeverity sls1(android::base::FATAL); \
+ CapturedStderr cap1; \
+ LOG(severity) << "foo bar"; \
+ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \
+ } \
+ { \
+ android::base::ScopedLogSeverity sls1(android::base::FATAL); \
+ CapturedStderr cap1; \
+ LOG(::android::base::severity) << "foo bar"; \
+ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \
+ } \
+
+#define CHECK_LOG_ENABLED(severity) \
+ { \
+ android::base::ScopedLogSeverity sls2(android::base::severity); \
+ CapturedStderr cap2; \
+ LOG(severity) << "foobar"; \
+ CheckMessage(cap2, android::base::severity, "foobar"); \
+ } \
+ { \
+ android::base::ScopedLogSeverity sls2(android::base::severity); \
+ CapturedStderr cap2; \
+ LOG(::android::base::severity) << "foobar"; \
+ CheckMessage(cap2, android::base::severity, "foobar"); \
+ } \
+
TEST(logging, LOG_FATAL) {
ASSERT_DEATH({SuppressAbortUI(); LOG(FATAL) << "foobar";}, "foobar");
+ ASSERT_DEATH({SuppressAbortUI(); LOG(::android::base::FATAL) << "foobar";}, "foobar");
}
TEST(logging, LOG_FATAL_WITHOUT_ABORT_disabled) {
@@ -236,6 +420,36 @@
CHECK_LOG_ENABLED(VERBOSE);
}
+#undef CHECK_LOG_DISABLED
+#undef CHECK_LOG_ENABLED
+
+
+TEST(logging, LOG_complex_param) {
+#define CHECK_LOG_COMBINATION(use_scoped_log_severity_info, use_logging_severity_info) \
+ { \
+ android::base::ScopedLogSeverity sls( \
+ (use_scoped_log_severity_info) ? ::android::base::INFO : ::android::base::WARNING); \
+ CapturedStderr cap; \
+ LOG((use_logging_severity_info) ? ::android::base::INFO : ::android::base::WARNING) \
+ << "foobar"; \
+ if ((use_scoped_log_severity_info) || !(use_logging_severity_info)) { \
+ CheckMessage(cap, \
+ (use_logging_severity_info) ? ::android::base::INFO : ::android::base::WARNING, \
+ "foobar"); \
+ } else { \
+ ASSERT_EQ(0, lseek(cap.fd(), 0, SEEK_CUR)); \
+ } \
+ }
+
+ CHECK_LOG_COMBINATION(false,false);
+ CHECK_LOG_COMBINATION(false,true);
+ CHECK_LOG_COMBINATION(true,false);
+ CHECK_LOG_COMBINATION(true,true);
+
+#undef CHECK_LOG_COMBINATION
+}
+
+
TEST(logging, LOG_does_not_clobber_errno) {
CapturedStderr cap;
errno = 12345;
@@ -277,23 +491,39 @@
EXPECT_FALSE(flag) << "LOG macro probably has a dangling if with no else";
}
-#define CHECK_PLOG(severity) \
-
#define CHECK_PLOG_DISABLED(severity) \
- android::base::ScopedLogSeverity sls1(android::base::FATAL); \
- CapturedStderr cap1; \
- PLOG(severity) << "foo bar"; \
- ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \
+ { \
+ android::base::ScopedLogSeverity sls1(android::base::FATAL); \
+ CapturedStderr cap1; \
+ PLOG(severity) << "foo bar"; \
+ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \
+ } \
+ { \
+ android::base::ScopedLogSeverity sls1(android::base::FATAL); \
+ CapturedStderr cap1; \
+ PLOG(severity) << "foo bar"; \
+ ASSERT_EQ(0, lseek(cap1.fd(), 0, SEEK_CUR)); \
+ } \
#define CHECK_PLOG_ENABLED(severity) \
- android::base::ScopedLogSeverity sls2(android::base::severity); \
- CapturedStderr cap2; \
- errno = ENOENT; \
- PLOG(severity) << "foobar"; \
- CheckMessage(cap2, android::base::severity, "foobar: No such file or directory"); \
+ { \
+ android::base::ScopedLogSeverity sls2(android::base::severity); \
+ CapturedStderr cap2; \
+ errno = ENOENT; \
+ PLOG(severity) << "foobar"; \
+ CheckMessage(cap2, android::base::severity, "foobar: No such file or directory"); \
+ } \
+ { \
+ android::base::ScopedLogSeverity sls2(android::base::severity); \
+ CapturedStderr cap2; \
+ errno = ENOENT; \
+ PLOG(severity) << "foobar"; \
+ CheckMessage(cap2, android::base::severity, "foobar: No such file or directory"); \
+ } \
TEST(logging, PLOG_FATAL) {
ASSERT_DEATH({SuppressAbortUI(); PLOG(FATAL) << "foobar";}, "foobar");
+ ASSERT_DEATH({SuppressAbortUI(); PLOG(::android::base::FATAL) << "foobar";}, "foobar");
}
TEST(logging, PLOG_FATAL_WITHOUT_ABORT_disabled) {
@@ -344,6 +574,10 @@
CHECK_PLOG_ENABLED(VERBOSE);
}
+#undef CHECK_PLOG_DISABLED
+#undef CHECK_PLOG_ENABLED
+
+
TEST(logging, UNIMPLEMENTED) {
std::string expected = android::base::StringPrintf("%s unimplemented ", __PRETTY_FUNCTION__);
diff --git a/base/properties.cpp b/base/properties.cpp
new file mode 100644
index 0000000..fab3005
--- /dev/null
+++ b/base/properties.cpp
@@ -0,0 +1,82 @@
+/*
+ * 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/properties.h"
+
+#include <sys/system_properties.h>
+
+#include <string>
+
+#include <android-base/parseint.h>
+
+namespace android {
+namespace base {
+
+std::string GetProperty(const std::string& key, const std::string& default_value) {
+ const prop_info* pi = __system_property_find(key.c_str());
+ if (pi == nullptr) return default_value;
+
+ char buf[PROP_VALUE_MAX];
+ if (__system_property_read(pi, nullptr, buf) > 0) return buf;
+
+ // If the property exists but is empty, also return the default value.
+ // Since we can't remove system properties, "empty" is traditionally
+ // the same as "missing" (this was true for cutils' property_get).
+ return default_value;
+}
+
+bool GetBoolProperty(const std::string& key, bool default_value) {
+ std::string value = GetProperty(key, "");
+ if (value == "1" || value == "y" || value == "yes" || value == "on" || value == "true") {
+ return true;
+ } else if (value == "0" || value == "n" || value == "no" || value == "off" || value == "false") {
+ return false;
+ }
+ return default_value;
+}
+
+template <typename T>
+T GetIntProperty(const std::string& key, T default_value, T min, T max) {
+ T result;
+ std::string value = GetProperty(key, "");
+ if (!value.empty() && android::base::ParseInt(value.c_str(), &result, min, max)) return result;
+ return default_value;
+}
+
+template <typename T>
+T GetUintProperty(const std::string& key, T default_value, T max) {
+ T result;
+ std::string value = GetProperty(key, "");
+ if (!value.empty() && android::base::ParseUint(value.c_str(), &result, max)) return result;
+ return default_value;
+}
+
+template int8_t GetIntProperty(const std::string&, int8_t, int8_t, int8_t);
+template int16_t GetIntProperty(const std::string&, int16_t, int16_t, int16_t);
+template int32_t GetIntProperty(const std::string&, int32_t, int32_t, int32_t);
+template int64_t GetIntProperty(const std::string&, int64_t, int64_t, int64_t);
+
+template uint8_t GetUintProperty(const std::string&, uint8_t, uint8_t);
+template uint16_t GetUintProperty(const std::string&, uint16_t, uint16_t);
+template uint32_t GetUintProperty(const std::string&, uint32_t, uint32_t);
+template uint64_t GetUintProperty(const std::string&, uint64_t, uint64_t);
+
+bool SetProperty(const std::string& key, const std::string& value) {
+ return (__system_property_set(key.c_str(), value.c_str()) == 0);
+}
+
+} // namespace base
+} // namespace android
diff --git a/base/properties_test.cpp b/base/properties_test.cpp
new file mode 100644
index 0000000..da89ec5
--- /dev/null
+++ b/base/properties_test.cpp
@@ -0,0 +1,121 @@
+/*
+ * 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/properties.h"
+
+#include <gtest/gtest.h>
+
+#include <string>
+
+TEST(properties, smoke) {
+ android::base::SetProperty("debug.libbase.property_test", "hello");
+
+ std::string s = android::base::GetProperty("debug.libbase.property_test", "");
+ ASSERT_EQ("hello", s);
+
+ android::base::SetProperty("debug.libbase.property_test", "world");
+ s = android::base::GetProperty("debug.libbase.property_test", "");
+ ASSERT_EQ("world", s);
+
+ s = android::base::GetProperty("this.property.does.not.exist", "");
+ ASSERT_EQ("", s);
+
+ s = android::base::GetProperty("this.property.does.not.exist", "default");
+ ASSERT_EQ("default", s);
+}
+
+TEST(properties, empty) {
+ // Because you can't delete a property, people "delete" them by
+ // setting them to the empty string. In that case we'd want to
+ // keep the default value (like cutils' property_get did).
+ android::base::SetProperty("debug.libbase.property_test", "");
+ std::string s = android::base::GetProperty("debug.libbase.property_test", "default");
+ ASSERT_EQ("default", s);
+}
+
+static void CheckGetBoolProperty(bool expected, const std::string& value, bool default_value) {
+ android::base::SetProperty("debug.libbase.property_test", value.c_str());
+ ASSERT_EQ(expected, android::base::GetBoolProperty("debug.libbase.property_test", default_value));
+}
+
+TEST(properties, GetBoolProperty_true) {
+ CheckGetBoolProperty(true, "1", false);
+ CheckGetBoolProperty(true, "y", false);
+ CheckGetBoolProperty(true, "yes", false);
+ CheckGetBoolProperty(true, "on", false);
+ CheckGetBoolProperty(true, "true", false);
+}
+
+TEST(properties, GetBoolProperty_false) {
+ CheckGetBoolProperty(false, "0", true);
+ CheckGetBoolProperty(false, "n", true);
+ CheckGetBoolProperty(false, "no", true);
+ CheckGetBoolProperty(false, "off", true);
+ CheckGetBoolProperty(false, "false", true);
+}
+
+TEST(properties, GetBoolProperty_default) {
+ CheckGetBoolProperty(true, "burp", true);
+ CheckGetBoolProperty(false, "burp", false);
+}
+
+template <typename T> void CheckGetIntProperty() {
+ // Positive and negative.
+ android::base::SetProperty("debug.libbase.property_test", "-12");
+ EXPECT_EQ(T(-12), android::base::GetIntProperty<T>("debug.libbase.property_test", 45));
+ android::base::SetProperty("debug.libbase.property_test", "12");
+ EXPECT_EQ(T(12), android::base::GetIntProperty<T>("debug.libbase.property_test", 45));
+
+ // Default value.
+ android::base::SetProperty("debug.libbase.property_test", "");
+ EXPECT_EQ(T(45), android::base::GetIntProperty<T>("debug.libbase.property_test", 45));
+
+ // Bounds checks.
+ android::base::SetProperty("debug.libbase.property_test", "0");
+ EXPECT_EQ(T(45), android::base::GetIntProperty<T>("debug.libbase.property_test", 45, 1, 2));
+ android::base::SetProperty("debug.libbase.property_test", "1");
+ EXPECT_EQ(T(1), android::base::GetIntProperty<T>("debug.libbase.property_test", 45, 1, 2));
+ android::base::SetProperty("debug.libbase.property_test", "2");
+ EXPECT_EQ(T(2), android::base::GetIntProperty<T>("debug.libbase.property_test", 45, 1, 2));
+ android::base::SetProperty("debug.libbase.property_test", "3");
+ EXPECT_EQ(T(45), android::base::GetIntProperty<T>("debug.libbase.property_test", 45, 1, 2));
+}
+
+template <typename T> void CheckGetUintProperty() {
+ // Positive.
+ android::base::SetProperty("debug.libbase.property_test", "12");
+ EXPECT_EQ(T(12), android::base::GetUintProperty<T>("debug.libbase.property_test", 45));
+
+ // Default value.
+ android::base::SetProperty("debug.libbase.property_test", "");
+ EXPECT_EQ(T(45), android::base::GetUintProperty<T>("debug.libbase.property_test", 45));
+
+ // Bounds checks.
+ android::base::SetProperty("debug.libbase.property_test", "12");
+ EXPECT_EQ(T(12), android::base::GetUintProperty<T>("debug.libbase.property_test", 33, 22));
+ android::base::SetProperty("debug.libbase.property_test", "12");
+ EXPECT_EQ(T(5), android::base::GetUintProperty<T>("debug.libbase.property_test", 5, 10));
+}
+
+TEST(properties, GetIntProperty_int8_t) { CheckGetIntProperty<int8_t>(); }
+TEST(properties, GetIntProperty_int16_t) { CheckGetIntProperty<int16_t>(); }
+TEST(properties, GetIntProperty_int32_t) { CheckGetIntProperty<int32_t>(); }
+TEST(properties, GetIntProperty_int64_t) { CheckGetIntProperty<int64_t>(); }
+
+TEST(properties, GetUintProperty_uint8_t) { CheckGetUintProperty<uint8_t>(); }
+TEST(properties, GetUintProperty_uint16_t) { CheckGetUintProperty<uint16_t>(); }
+TEST(properties, GetUintProperty_uint32_t) { CheckGetUintProperty<uint32_t>(); }
+TEST(properties, GetUintProperty_uint64_t) { CheckGetUintProperty<uint64_t>(); }
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp
index 71a5a39..0ab4c98 100644
--- a/bootstat/bootstat.cpp
+++ b/bootstat/bootstat.cpp
@@ -20,6 +20,7 @@
#include <getopt.h>
#include <unistd.h>
+
#include <cmath>
#include <cstddef>
#include <cstdio>
@@ -27,12 +28,14 @@
#include <map>
#include <memory>
#include <string>
+
+#include <android/log.h>
#include <android-base/logging.h>
#include <android-base/parseint.h>
#include <cutils/properties.h>
-#include <log/log.h>
+
#include "boot_event_record_store.h"
-#include "event_log_list_builder.h"
+#include "event_log_list_builder.h" /* ToDo: switch to liblog implementation */
#include "histogram_logger.h"
#include "uptime_parser.h"
diff --git a/bootstat/event_log_list_builder.cpp b/bootstat/event_log_list_builder.cpp
index 241e3d5..a6af13e 100644
--- a/bootstat/event_log_list_builder.cpp
+++ b/bootstat/event_log_list_builder.cpp
@@ -19,8 +19,9 @@
#include <cinttypes>
#include <memory>
#include <string>
+
+#include <android/log.h>
#include <android-base/logging.h>
-#include <log/log.h>
namespace {
diff --git a/bootstat/event_log_list_builder_test.cpp b/bootstat/event_log_list_builder_test.cpp
index affb4bf..8f7f323 100644
--- a/bootstat/event_log_list_builder_test.cpp
+++ b/bootstat/event_log_list_builder_test.cpp
@@ -17,9 +17,10 @@
#include "event_log_list_builder.h"
#include <inttypes.h>
-#include <gtest/gtest.h>
+
+#include <android/log.h>
#include <gmock/gmock.h>
-#include <log/log.h>
+#include <gtest/gtest.h>
using testing::ElementsAreArray;
diff --git a/bootstat/histogram_logger.cpp b/bootstat/histogram_logger.cpp
index e3aad28..3144d8b 100644
--- a/bootstat/histogram_logger.cpp
+++ b/bootstat/histogram_logger.cpp
@@ -18,8 +18,10 @@
#include <cstdlib>
#include <memory>
+
+#include <android/log.h>
#include <android-base/logging.h>
-#include <log/log.h>
+
#include "event_log_list_builder.h"
namespace bootstat {
@@ -38,4 +40,4 @@
android_bWriteLog(HISTOGRAM_LOG_TAG, log.get(), size);
}
-} // namespace bootstat
\ No newline at end of file
+} // namespace bootstat
diff --git a/debuggerd/arm/machine.cpp b/debuggerd/arm/machine.cpp
index 78c2306..292edcb 100644
--- a/debuggerd/arm/machine.cpp
+++ b/debuggerd/arm/machine.cpp
@@ -22,8 +22,8 @@
#include <string.h>
#include <sys/ptrace.h>
+#include <android/log.h>
#include <backtrace/Backtrace.h>
-#include <log/log.h>
#include "machine.h"
#include "utility.h"
diff --git a/debuggerd/arm64/machine.cpp b/debuggerd/arm64/machine.cpp
index e7bf79a..cd1bd52 100644
--- a/debuggerd/arm64/machine.cpp
+++ b/debuggerd/arm64/machine.cpp
@@ -24,8 +24,8 @@
#include <sys/ptrace.h>
#include <sys/uio.h>
+#include <android/log.h>
#include <backtrace/Backtrace.h>
-#include <log/log.h>
#include "machine.h"
#include "utility.h"
diff --git a/debuggerd/backtrace.cpp b/debuggerd/backtrace.cpp
index 8f4a53f..06c1efe 100644
--- a/debuggerd/backtrace.cpp
+++ b/debuggerd/backtrace.cpp
@@ -16,25 +16,24 @@
#define LOG_TAG "DEBUG"
+#include <errno.h>
+#include <dirent.h>
+#include <limits.h>
#include <stddef.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <stdio.h>
-#include <time.h>
-#include <errno.h>
-#include <limits.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <sys/types.h>
#include <sys/ptrace.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
#include <memory>
#include <string>
+#include <android/log.h>
#include <backtrace/Backtrace.h>
-#include <log/log.h>
-
#include "backtrace.h"
#include "utility.h"
diff --git a/debuggerd/crasher.cpp b/debuggerd/crasher.cpp
index a37df33..7d3509c 100644
--- a/debuggerd/crasher.cpp
+++ b/debuggerd/crasher.cpp
@@ -13,8 +13,8 @@
#include <sys/wait.h>
#include <unistd.h>
+#include <android/log.h>
#include <cutils/sockets.h>
-#include <log/log.h>
#if defined(STATIC_CRASHER)
#include "debuggerd/client.h"
diff --git a/debuggerd/elf_utils.cpp b/debuggerd/elf_utils.cpp
index 3d99cab..d760a37 100644
--- a/debuggerd/elf_utils.cpp
+++ b/debuggerd/elf_utils.cpp
@@ -23,9 +23,9 @@
#include <string>
-#include <backtrace/Backtrace.h>
+#include <android/log.h>
#include <android-base/stringprintf.h>
-#include <log/log.h>
+#include <backtrace/Backtrace.h>
#include "elf_utils.h"
diff --git a/debuggerd/getevent.cpp b/debuggerd/getevent.cpp
index e5acd17..dfa7bec 100644
--- a/debuggerd/getevent.cpp
+++ b/debuggerd/getevent.cpp
@@ -14,20 +14,22 @@
* limitations under the License.
*/
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/input.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <stdint.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
#include <sys/inotify.h>
+#include <sys/ioctl.h>
#include <sys/limits.h>
#include <sys/poll.h>
-#include <linux/input.h>
-#include <errno.h>
+
#include <memory>
-#include <cutils/log.h>
+
+#include <android/log.h>
static struct pollfd* ufds;
static char** device_names;
diff --git a/debuggerd/mips/machine.cpp b/debuggerd/mips/machine.cpp
index cbf272a..99a9d65 100644
--- a/debuggerd/mips/machine.cpp
+++ b/debuggerd/mips/machine.cpp
@@ -22,8 +22,8 @@
#include <string.h>
#include <sys/ptrace.h>
+#include <android/log.h>
#include <backtrace/Backtrace.h>
-#include <log/log.h>
#include "machine.h"
#include "utility.h"
diff --git a/debuggerd/mips64/machine.cpp b/debuggerd/mips64/machine.cpp
index 0a8d532..ecd1ca2 100644
--- a/debuggerd/mips64/machine.cpp
+++ b/debuggerd/mips64/machine.cpp
@@ -22,8 +22,8 @@
#include <string.h>
#include <sys/ptrace.h>
+#include <android/log.h>
#include <backtrace/Backtrace.h>
-#include <log/log.h>
#include "machine.h"
#include "utility.h"
diff --git a/debuggerd/test/log_fake.cpp b/debuggerd/test/log_fake.cpp
index e27e9f6..ebf966f 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>
#include <log/logger.h>
// Forward declarations.
diff --git a/debuggerd/tombstone.cpp b/debuggerd/tombstone.cpp
index e663920..5c7f024 100644
--- a/debuggerd/tombstone.cpp
+++ b/debuggerd/tombstone.cpp
@@ -25,23 +25,21 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <time.h>
#include <sys/ptrace.h>
#include <sys/stat.h>
+#include <time.h>
#include <memory>
#include <string>
-#include <private/android_filesystem_config.h>
-
+#include <android/log.h>
#include <android-base/stringprintf.h>
-#include <cutils/properties.h>
-#include <log/log.h>
-#include <log/logger.h>
-#include <log/logprint.h>
-
#include <backtrace/Backtrace.h>
#include <backtrace/BacktraceMap.h>
+#include <cutils/properties.h>
+#include <log/logger.h>
+#include <log/logprint.h>
+#include <private/android_filesystem_config.h>
#include <selinux/android.h>
diff --git a/debuggerd/utility.cpp b/debuggerd/utility.cpp
index 7fabf69..e334e71 100644
--- a/debuggerd/utility.cpp
+++ b/debuggerd/utility.cpp
@@ -21,15 +21,15 @@
#include <errno.h>
#include <signal.h>
#include <string.h>
-#include <unistd.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
+#include <unistd.h>
#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/debuggerd/x86/machine.cpp b/debuggerd/x86/machine.cpp
index af10817..a6f21e1 100644
--- a/debuggerd/x86/machine.cpp
+++ b/debuggerd/x86/machine.cpp
@@ -21,8 +21,8 @@
#include <string.h>
#include <sys/ptrace.h>
+#include <android/log.h>
#include <backtrace/Backtrace.h>
-#include <log/log.h>
#include "machine.h"
#include "utility.h"
diff --git a/debuggerd/x86_64/machine.cpp b/debuggerd/x86_64/machine.cpp
index fc86bc2..705e12d 100644
--- a/debuggerd/x86_64/machine.cpp
+++ b/debuggerd/x86_64/machine.cpp
@@ -22,8 +22,8 @@
#include <string.h>
#include <sys/user.h>
+#include <android/log.h>
#include <backtrace/Backtrace.h>
-#include <log/log.h>
#include "machine.h"
#include "utility.h"
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 987ba83..d6b631f 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -402,6 +402,9 @@
" --skip-secondary Will not flash secondary slots when\n"
" performing a flashall or update. This\n"
" will preserve data on other slots.\n"
+ " --skip-reboot Will not reboot the device when\n"
+ " performing commands that normally\n"
+ " trigger a reboot.\n"
#if !defined(_WIN32)
" --wipe-and-use-fbe On devices which support it,\n"
" erase userdata and cache, and\n"
@@ -1392,6 +1395,7 @@
bool wants_wipe = false;
bool wants_reboot = false;
bool wants_reboot_bootloader = false;
+ bool skip_reboot = false;
bool wants_set_active = false;
bool skip_secondary = false;
bool erase_first = true;
@@ -1419,6 +1423,7 @@
{"set_active", optional_argument, 0, 'a'},
{"set-active", optional_argument, 0, 'a'},
{"skip-secondary", no_argument, 0, 0},
+ {"skip-reboot", no_argument, 0, 0},
#if !defined(_WIN32)
{"wipe-and-use-fbe", no_argument, 0, 0},
#endif
@@ -1505,6 +1510,8 @@
slot_override = std::string(optarg);
} else if (strcmp("skip-secondary", longopts[longindex].name) == 0 ) {
skip_secondary = true;
+ } else if (strcmp("skip-reboot", longopts[longindex].name) == 0 ) {
+ skip_reboot = true;
#if !defined(_WIN32)
} else if (strcmp("wipe-and-use-fbe", longopts[longindex].name) == 0) {
wants_wipe = true;
@@ -1729,7 +1736,7 @@
do_update(transport, "update.zip", slot_override, erase_first, skip_secondary || slot_all);
skip(1);
}
- wants_reboot = 1;
+ wants_reboot = true;
} else if(!strcmp(*argv, "set_active")) {
require(2);
std::string slot = verify_slot(transport, std::string(argv[1]), false);
@@ -1784,7 +1791,7 @@
if (wants_set_active) {
fb_set_active(next_active.c_str());
}
- if (wants_reboot) {
+ if (wants_reboot && !skip_reboot) {
fb_queue_reboot();
fb_queue_wait_for_disconnect();
} else if (wants_reboot_bootloader) {
diff --git a/fingerprintd/fingerprintd.cpp b/fingerprintd/fingerprintd.cpp
index 8fa7ed1..05109b7 100644
--- a/fingerprintd/fingerprintd.cpp
+++ b/fingerprintd/fingerprintd.cpp
@@ -16,20 +16,17 @@
#define LOG_TAG "fingerprintd"
-#include <cutils/log.h>
-#include <utils/Log.h>
-
+#include <android/log.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/PermissionCache.h>
-#include <utils/String16.h>
-
-#include <keystore/IKeystoreService.h>
-#include <keystore/keystore.h> // for error codes
-
#include <hardware/hardware.h>
#include <hardware/fingerprint.h>
#include <hardware/hw_auth_token.h>
+#include <keystore/IKeystoreService.h>
+#include <keystore/keystore.h> // for error codes
+#include <utils/Log.h>
+#include <utils/String16.h>
#include "FingerprintDaemonProxy.h"
diff --git a/gatekeeperd/gatekeeperd.cpp b/gatekeeperd/gatekeeperd.cpp
index 7254cf2..4107f55 100644
--- a/gatekeeperd/gatekeeperd.cpp
+++ b/gatekeeperd/gatekeeperd.cpp
@@ -19,25 +19,22 @@
#include "IGateKeeperService.h"
#include <errno.h>
-#include <stdint.h>
-#include <inttypes.h>
#include <fcntl.h>
+#include <inttypes.h>
+#include <stdint.h>
#include <unistd.h>
-#include <cutils/log.h>
-#include <utils/Log.h>
-
+#include <android/log.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/PermissionCache.h>
-#include <utils/String16.h>
-#include <utils/Log.h>
-
-#include <keystore/IKeystoreService.h>
-#include <keystore/keystore.h> // For error code
#include <gatekeeper/password_handle.h> // for password_handle_t
#include <hardware/gatekeeper.h>
#include <hardware/hw_auth_token.h>
+#include <keystore/IKeystoreService.h>
+#include <keystore/keystore.h> // For error code
+#include <utils/Log.h>
+#include <utils/String16.h>
#include "SoftGateKeeperDevice.h"
#include "IUserManager.h"
diff --git a/include/android/log.h b/include/android/log.h
index a4973b2..5f20f8c 100644
--- a/include/android/log.h
+++ b/include/android/log.h
@@ -67,7 +67,17 @@
* NOTE: These functions MUST be implemented by /system/lib/liblog.so
*/
+#if !defined(_WIN32)
+#include <pthread.h>
+#endif
#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <log/uio.h>
#ifdef __cplusplus
extern "C" {
@@ -142,6 +152,693 @@
#endif
;
+//
+// C/C++ logging functions. See the logging documentation for API details.
+//
+// We'd like these to be available from C code (in case we import some from
+// somewhere), so this has a C interface.
+//
+// The output will be correct when the log file is shared between multiple
+// threads and/or multiple processes so long as the operating system
+// supports O_APPEND. These calls have mutex-protected data structures
+// and so are NOT reentrant. Do not use LOG in a signal handler.
+//
+
+// This file uses ", ## __VA_ARGS__" zero-argument token pasting to
+// work around issues with debug-only syntax errors in assertions
+// that are missing format strings. See commit
+// 19299904343daf191267564fe32e6cd5c165cd42
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
+#endif
+
+int __android_log_bwrite(int32_t tag, const void *payload, size_t len);
+int __android_log_btwrite(int32_t tag, char type, const void *payload,
+ size_t len);
+int __android_log_bswrite(int32_t tag, const char *payload);
+
+int __android_log_security_bwrite(int32_t tag, const void *payload, size_t len);
+int __android_log_security_bswrite(int32_t tag, const char *payload);
+
+// ---------------------------------------------------------------------
+
+/*
+ * Normally we strip ALOGV (VERBOSE messages) from release builds.
+ * You can modify this (for example with "#define LOG_NDEBUG 0"
+ * at the top of your source file) to change that behavior.
+ */
+#ifndef LOG_NDEBUG
+#ifdef NDEBUG
+#define LOG_NDEBUG 1
+#else
+#define LOG_NDEBUG 0
+#endif
+#endif
+
+/*
+ * This is the local tag used for the following simplified
+ * logging macros. You can change this preprocessor definition
+ * before using the other macros to change the tag.
+ */
+#ifndef LOG_TAG
+#define LOG_TAG NULL
+#endif
+
+// ---------------------------------------------------------------------
+
+#ifndef __predict_false
+#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
+#endif
+
+/*
+ * -DLINT_RLOG in sources that you want to enforce that all logging
+ * goes to the radio log buffer. If any logging goes to any of the other
+ * log buffers, there will be a compile or link error to highlight the
+ * problem. This is not a replacement for a full audit of the code since
+ * this only catches compiled code, not ifdef'd debug code. Options to
+ * defining this, either temporarily to do a spot check, or permanently
+ * to enforce, in all the communications trees; We have hopes to ensure
+ * that by supplying just the radio log buffer that the communications
+ * teams will have their one-stop shop for triaging issues.
+ */
+#ifndef LINT_RLOG
+
+/*
+ * Simplified macro to send a verbose log message using the current LOG_TAG.
+ */
+#ifndef ALOGV
+#define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
+#if LOG_NDEBUG
+#define ALOGV(...) do { if (0) { __ALOGV(__VA_ARGS__); } } while (0)
+#else
+#define ALOGV(...) __ALOGV(__VA_ARGS__)
+#endif
+#endif
+
+#ifndef ALOGV_IF
+#if LOG_NDEBUG
+#define ALOGV_IF(cond, ...) ((void)0)
+#else
+#define ALOGV_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+#endif
+
+/*
+ * Simplified macro to send a debug log message using the current LOG_TAG.
+ */
+#ifndef ALOGD
+#define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef ALOGD_IF
+#define ALOGD_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send an info log message using the current LOG_TAG.
+ */
+#ifndef ALOGI
+#define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef ALOGI_IF
+#define ALOGI_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send a warning log message using the current LOG_TAG.
+ */
+#ifndef ALOGW
+#define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef ALOGW_IF
+#define ALOGW_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send an error log message using the current LOG_TAG.
+ */
+#ifndef ALOGE
+#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef ALOGE_IF
+#define ALOGE_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+// ---------------------------------------------------------------------
+
+/*
+ * Conditional based on whether the current LOG_TAG is enabled at
+ * verbose priority.
+ */
+#ifndef IF_ALOGV
+#if LOG_NDEBUG
+#define IF_ALOGV() if (false)
+#else
+#define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
+#endif
+#endif
+
+/*
+ * Conditional based on whether the current LOG_TAG is enabled at
+ * debug priority.
+ */
+#ifndef IF_ALOGD
+#define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
+#endif
+
+/*
+ * Conditional based on whether the current LOG_TAG is enabled at
+ * info priority.
+ */
+#ifndef IF_ALOGI
+#define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG)
+#endif
+
+/*
+ * Conditional based on whether the current LOG_TAG is enabled at
+ * warn priority.
+ */
+#ifndef IF_ALOGW
+#define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG)
+#endif
+
+/*
+ * Conditional based on whether the current LOG_TAG is enabled at
+ * error priority.
+ */
+#ifndef IF_ALOGE
+#define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
+#endif
+
+
+// ---------------------------------------------------------------------
+
+/*
+ * Simplified macro to send a verbose system log message using the current LOG_TAG.
+ */
+#ifndef SLOGV
+#define __SLOGV(...) \
+ ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
+#if LOG_NDEBUG
+#define SLOGV(...) do { if (0) { __SLOGV(__VA_ARGS__); } } while (0)
+#else
+#define SLOGV(...) __SLOGV(__VA_ARGS__)
+#endif
+#endif
+
+#ifndef SLOGV_IF
+#if LOG_NDEBUG
+#define SLOGV_IF(cond, ...) ((void)0)
+#else
+#define SLOGV_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+#endif
+
+/*
+ * Simplified macro to send a debug system log message using the current LOG_TAG.
+ */
+#ifndef SLOGD
+#define SLOGD(...) \
+ ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef SLOGD_IF
+#define SLOGD_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send an info system log message using the current LOG_TAG.
+ */
+#ifndef SLOGI
+#define SLOGI(...) \
+ ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef SLOGI_IF
+#define SLOGI_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send a warning system log message using the current LOG_TAG.
+ */
+#ifndef SLOGW
+#define SLOGW(...) \
+ ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef SLOGW_IF
+#define SLOGW_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send an error system log message using the current LOG_TAG.
+ */
+#ifndef SLOGE
+#define SLOGE(...) \
+ ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef SLOGE_IF
+#define SLOGE_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+#endif /* !LINT_RLOG */
+
+// ---------------------------------------------------------------------
+
+/*
+ * Simplified macro to send a verbose radio log message using the current LOG_TAG.
+ */
+#ifndef RLOGV
+#define __RLOGV(...) \
+ ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
+#if LOG_NDEBUG
+#define RLOGV(...) do { if (0) { __RLOGV(__VA_ARGS__); } } while (0)
+#else
+#define RLOGV(...) __RLOGV(__VA_ARGS__)
+#endif
+#endif
+
+#ifndef RLOGV_IF
+#if LOG_NDEBUG
+#define RLOGV_IF(cond, ...) ((void)0)
+#else
+#define RLOGV_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+#endif
+
+/*
+ * Simplified macro to send a debug radio log message using the current LOG_TAG.
+ */
+#ifndef RLOGD
+#define RLOGD(...) \
+ ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef RLOGD_IF
+#define RLOGD_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send an info radio log message using the current LOG_TAG.
+ */
+#ifndef RLOGI
+#define RLOGI(...) \
+ ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef RLOGI_IF
+#define RLOGI_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send a warning radio log message using the current LOG_TAG.
+ */
+#ifndef RLOGW
+#define RLOGW(...) \
+ ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef RLOGW_IF
+#define RLOGW_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send an error radio log message using the current LOG_TAG.
+ */
+#ifndef RLOGE
+#define RLOGE(...) \
+ ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef RLOGE_IF
+#define RLOGE_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+
+// ---------------------------------------------------------------------
+
+/*
+ * Log a fatal error. If the given condition fails, this stops program
+ * execution like a normal assertion, but also generating the given message.
+ * It is NOT stripped from release builds. Note that the condition test
+ * is -inverted- from the normal assert() semantics.
+ */
+#ifndef LOG_ALWAYS_FATAL_IF
+#define LOG_ALWAYS_FATAL_IF(cond, ...) \
+ ( (__predict_false(cond)) \
+ ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+#ifndef LOG_ALWAYS_FATAL
+#define LOG_ALWAYS_FATAL(...) \
+ ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
+#endif
+
+/*
+ * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
+ * are stripped out of release builds.
+ */
+#if LOG_NDEBUG
+
+#ifndef LOG_FATAL_IF
+#define LOG_FATAL_IF(cond, ...) ((void)0)
+#endif
+#ifndef LOG_FATAL
+#define LOG_FATAL(...) ((void)0)
+#endif
+
+#else
+
+#ifndef LOG_FATAL_IF
+#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
+#endif
+#ifndef LOG_FATAL
+#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
+#endif
+
+#endif
+
+/*
+ * Assertion that generates a log message when the assertion fails.
+ * Stripped out of release builds. Uses the current LOG_TAG.
+ */
+#ifndef ALOG_ASSERT
+#define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
+//#define ALOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
+#endif
+
+// ---------------------------------------------------------------------
+
+/*
+ * Basic log message macro.
+ *
+ * Example:
+ * ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
+ *
+ * The second argument may be NULL or "" to indicate the "global" tag.
+ */
+#ifndef ALOG
+#define ALOG(priority, tag, ...) \
+ LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
+#endif
+
+/*
+ * Log macro that allows you to specify a number for the priority.
+ */
+#ifndef LOG_PRI
+#define LOG_PRI(priority, tag, ...) \
+ android_printLog(priority, tag, __VA_ARGS__)
+#endif
+
+/*
+ * Log macro that allows you to pass in a varargs ("args" is a va_list).
+ */
+#ifndef LOG_PRI_VA
+#define LOG_PRI_VA(priority, tag, fmt, args) \
+ android_vprintLog(priority, NULL, tag, fmt, args)
+#endif
+
+/*
+ * Conditional given a desired logging priority and tag.
+ */
+#ifndef IF_ALOG
+#define IF_ALOG(priority, tag) \
+ if (android_testLog(ANDROID_##priority, tag))
+#endif
+
+// ---------------------------------------------------------------------
+
+/*
+ * Event logging.
+ */
+
+/*
+ * Event log entry types.
+ */
+typedef enum {
+ /* Special markers for android_log_list_element type */
+ EVENT_TYPE_LIST_STOP = '\n', /* declare end of list */
+ EVENT_TYPE_UNKNOWN = '?', /* protocol error */
+
+ /* must match with declaration in java/android/android/util/EventLog.java */
+ EVENT_TYPE_INT = 0, /* uint32_t */
+ EVENT_TYPE_LONG = 1, /* uint64_t */
+ EVENT_TYPE_STRING = 2,
+ EVENT_TYPE_LIST = 3,
+ EVENT_TYPE_FLOAT = 4,
+} AndroidEventLogType;
+#define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType)
+#define typeof_AndroidEventLogType unsigned char
+
+#ifndef LOG_EVENT_INT
+#define LOG_EVENT_INT(_tag, _value) { \
+ int intBuf = _value; \
+ (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
+ sizeof(intBuf)); \
+ }
+#endif
+#ifndef LOG_EVENT_LONG
+#define LOG_EVENT_LONG(_tag, _value) { \
+ long long longBuf = _value; \
+ (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
+ sizeof(longBuf)); \
+ }
+#endif
+#ifndef LOG_EVENT_FLOAT
+#define LOG_EVENT_FLOAT(_tag, _value) { \
+ float floatBuf = _value; \
+ (void) android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf, \
+ sizeof(floatBuf)); \
+ }
+#endif
+#ifndef LOG_EVENT_STRING
+#define LOG_EVENT_STRING(_tag, _value) \
+ (void) __android_log_bswrite(_tag, _value);
+#endif
+
+typedef enum log_id {
+ LOG_ID_MIN = 0,
+
+#ifndef LINT_RLOG
+ LOG_ID_MAIN = 0,
+#endif
+ LOG_ID_RADIO = 1,
+#ifndef LINT_RLOG
+ LOG_ID_EVENTS = 2,
+ LOG_ID_SYSTEM = 3,
+ LOG_ID_CRASH = 4,
+ LOG_ID_SECURITY = 5,
+ LOG_ID_KERNEL = 6, /* place last, third-parties can not use it */
+#endif
+
+ LOG_ID_MAX
+} log_id_t;
+#define sizeof_log_id_t sizeof(typeof_log_id_t)
+#define typeof_log_id_t unsigned char
+
+/* For manipulating lists of events. */
+
+#define ANDROID_MAX_LIST_NEST_DEPTH 8
+
+/*
+ * The opaque context used to manipulate lists of events.
+ */
+typedef struct android_log_context_internal *android_log_context;
+
+/*
+ * Elements returned when reading a list of events.
+ */
+typedef struct {
+ AndroidEventLogType type;
+ uint16_t complete;
+ uint16_t len;
+ union {
+ int32_t int32;
+ int64_t int64;
+ char *string;
+ float float32;
+ } data;
+} android_log_list_element;
+
+/*
+ * Creates a context associated with an event tag to write elements to
+ * the list of events.
+ */
+android_log_context create_android_logger(uint32_t tag);
+
+/* All lists must be braced by a begin and end call */
+/*
+ * NB: If the first level braces are missing when specifying multiple
+ * elements, we will manufacturer a list to embrace it for your API
+ * convenience. For a single element, it will remain solitary.
+ */
+int android_log_write_list_begin(android_log_context ctx);
+int android_log_write_list_end(android_log_context ctx);
+
+int android_log_write_int32(android_log_context ctx, int32_t value);
+int android_log_write_int64(android_log_context ctx, int64_t value);
+int android_log_write_string8(android_log_context ctx, const char *value);
+int android_log_write_string8_len(android_log_context ctx,
+ const char *value, size_t maxlen);
+int android_log_write_float32(android_log_context ctx, float value);
+
+/* Submit the composed list context to the specified logger id */
+/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */
+int android_log_write_list(android_log_context ctx, log_id_t id);
+
+/*
+ * Creates a context from a raw buffer representing a list of events to be read.
+ */
+android_log_context create_android_log_parser(const char *msg, size_t len);
+
+android_log_list_element android_log_read_next(android_log_context ctx);
+android_log_list_element android_log_peek_next(android_log_context ctx);
+
+/* Finished with reader or writer context */
+int android_log_destroy(android_log_context *ctx);
+
+/*
+ * ===========================================================================
+ *
+ * The stuff in the rest of this file should not be used directly.
+ */
+
+#define android_printLog(prio, tag, ...) \
+ __android_log_print(prio, tag, __VA_ARGS__)
+
+#define android_vprintLog(prio, cond, tag, ...) \
+ __android_log_vprint(prio, tag, __VA_ARGS__)
+
+/* XXX Macros to work around syntax errors in places where format string
+ * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
+ * (happens only in debug builds).
+ */
+
+/* Returns 2nd arg. Used to substitute default value if caller's vararg list
+ * is empty.
+ */
+#define __android_second(dummy, second, ...) second
+
+/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
+ * returns nothing.
+ */
+#define __android_rest(first, ...) , ## __VA_ARGS__
+
+#define android_printAssert(cond, tag, ...) \
+ __android_log_assert(cond, tag, \
+ __android_second(0, ## __VA_ARGS__, NULL) __android_rest(__VA_ARGS__))
+
+#define android_writeLog(prio, tag, text) \
+ __android_log_write(prio, tag, text)
+
+#define android_bWriteLog(tag, payload, len) \
+ __android_log_bwrite(tag, payload, len)
+#define android_btWriteLog(tag, type, payload, len) \
+ __android_log_btwrite(tag, type, payload, len)
+
+#define android_errorWriteLog(tag, subTag) \
+ __android_log_error_write(tag, subTag, -1, NULL, 0)
+
+#define android_errorWriteWithInfoLog(tag, subTag, uid, data, dataLen) \
+ __android_log_error_write(tag, subTag, uid, data, dataLen)
+
+/*
+ * IF_ALOG uses android_testLog, but IF_ALOG can be overridden.
+ * android_testLog will remain constant in its purpose as a wrapper
+ * for Android logging filter policy, and can be subject to
+ * change. It can be reused by the developers that override
+ * IF_ALOG as a convenient means to reimplement their policy
+ * over Android.
+ */
+#if LOG_NDEBUG /* Production */
+#define android_testLog(prio, tag) \
+ (__android_log_is_loggable_len(prio, tag, (tag && *tag) ? strlen(tag) : 0, \
+ ANDROID_LOG_DEBUG) != 0)
+#else
+#define android_testLog(prio, tag) \
+ (__android_log_is_loggable_len(prio, tag, (tag && *tag) ? strlen(tag) : 0, \
+ ANDROID_LOG_VERBOSE) != 0)
+#endif
+
+/*
+ * Use the per-tag properties "log.tag.<tagname>" to generate a runtime
+ * result of non-zero to expose a log. prio is ANDROID_LOG_VERBOSE to
+ * ANDROID_LOG_FATAL. default_prio if no property. Undefined behavior if
+ * any other value.
+ */
+int __android_log_is_loggable(int prio, const char *tag, int default_prio);
+int __android_log_is_loggable_len(int prio, const char *tag, size_t len, int default_prio);
+
+int __android_log_security(); /* Device Owner is present */
+
+int __android_log_error_write(int tag, const char *subTag, int32_t uid, const char *data,
+ uint32_t dataLen);
+
+/*
+ * Send a simple string to the log.
+ */
+int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
+int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
+#if defined(__GNUC__)
+ __attribute__((__format__(printf, 4, 5)))
+#endif
+ ;
+
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/include/cutils/log.h b/include/cutils/log.h
index 0e0248e..ffb8268 100644
--- a/include/cutils/log.h
+++ b/include/cutils/log.h
@@ -1 +1 @@
-#include <log/log.h>
+#include <android/log.h>
diff --git a/include/cutils/native_handle.h b/include/cutils/native_handle.h
index 268c5d3..31695cb 100644
--- a/include/cutils/native_handle.h
+++ b/include/cutils/native_handle.h
@@ -26,7 +26,14 @@
int version; /* sizeof(native_handle_t) */
int numFds; /* number of file-descriptors at &data[0] */
int numInts; /* number of ints at &data[numFds] */
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wzero-length-array"
+#endif
int data[0]; /* numFds + numInts ints */
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
} native_handle_t;
/*
diff --git a/include/cutils/sockets.h b/include/cutils/sockets.h
index 783bd0b..a93c8ea 100644
--- a/include/cutils/sockets.h
+++ b/include/cutils/sockets.h
@@ -18,6 +18,7 @@
#define __CUTILS_SOCKETS_H
#include <errno.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -51,28 +52,8 @@
* android_get_control_socket - simple helper function to get the file
* descriptor of our init-managed Unix domain socket. `name' is the name of the
* socket, as given in init.rc. Returns -1 on error.
- *
- * This is inline and not in libcutils proper because we want to use this in
- * third-party daemons with minimal modification.
*/
-static inline int android_get_control_socket(const char* name)
-{
- char key[64];
- snprintf(key, sizeof(key), ANDROID_SOCKET_ENV_PREFIX "%s", name);
-
- const char* val = getenv(key);
- if (!val) {
- return -1;
- }
-
- errno = 0;
- int fd = strtol(val, NULL, 10);
- if (errno) {
- return -1;
- }
-
- return fd;
-}
+int android_get_control_socket(const char* name);
/*
* See also android.os.LocalSocketAddress.Namespace
diff --git a/include/cutils/trace.h b/include/cutils/trace.h
index 19313af..0f00417 100644
--- a/include/cutils/trace.h
+++ b/include/cutils/trace.h
@@ -189,8 +189,8 @@
static inline void atrace_end(uint64_t tag)
{
if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
- char c = 'E';
- write(atrace_marker_fd, &c, 1);
+ void atrace_end_body();
+ atrace_end_body();
}
}
diff --git a/include/log/event_tag_map.h b/include/log/event_tag_map.h
index 1653c61..69774ba 100644
--- a/include/log/event_tag_map.h
+++ b/include/log/event_tag_map.h
@@ -41,7 +41,14 @@
/*
* Look up a tag by index. Returns the tag string, or NULL if not found.
*/
-const char* android_lookupEventTag(const EventTagMap* map, int tag);
+const char* android_lookupEventTag(const EventTagMap* map, unsigned int tag)
+ __attribute__((deprecated("use android_lookupEventTag_len() instead to minimize MAP_PRIVATE copy-on-write memory impact")));
+
+/*
+ * Look up a tag by index. Returns the tag string & string length, or NULL if
+ * not found. Returned string is not guaranteed to be nul terminated.
+ */
+const char* android_lookupEventTag_len(const EventTagMap* map, size_t* len, unsigned int tag);
#ifdef __cplusplus
}
diff --git a/include/log/log.h b/include/log/log.h
index 045feca..ffb8268 100644
--- a/include/log/log.h
+++ b/include/log/log.h
@@ -1,699 +1 @@
-/*
- * Copyright (C) 2005-2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//
-// C/C++ logging functions. See the logging documentation for API details.
-//
-// We'd like these to be available from C code (in case we import some from
-// somewhere), so this has a C interface.
-//
-// The output will be correct when the log file is shared between multiple
-// threads and/or multiple processes so long as the operating system
-// supports O_APPEND. These calls have mutex-protected data structures
-// and so are NOT reentrant. Do not use LOG in a signal handler.
-//
-#ifndef _LIBS_LOG_LOG_H
-#define _LIBS_LOG_LOG_H
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <log/logd.h>
-#include <log/uio.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// ---------------------------------------------------------------------
-
-/*
- * Normally we strip ALOGV (VERBOSE messages) from release builds.
- * You can modify this (for example with "#define LOG_NDEBUG 0"
- * at the top of your source file) to change that behavior.
- */
-#ifndef LOG_NDEBUG
-#ifdef NDEBUG
-#define LOG_NDEBUG 1
-#else
-#define LOG_NDEBUG 0
-#endif
-#endif
-
-/*
- * This is the local tag used for the following simplified
- * logging macros. You can change this preprocessor definition
- * before using the other macros to change the tag.
- */
-#ifndef LOG_TAG
-#define LOG_TAG NULL
-#endif
-
-// ---------------------------------------------------------------------
-
-#ifndef __predict_false
-#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
-#endif
-
-/*
- * -DLINT_RLOG in sources that you want to enforce that all logging
- * goes to the radio log buffer. If any logging goes to any of the other
- * log buffers, there will be a compile or link error to highlight the
- * problem. This is not a replacement for a full audit of the code since
- * this only catches compiled code, not ifdef'd debug code. Options to
- * defining this, either temporarily to do a spot check, or permanently
- * to enforce, in all the communications trees; We have hopes to ensure
- * that by supplying just the radio log buffer that the communications
- * teams will have their one-stop shop for triaging issues.
- */
-#ifndef LINT_RLOG
-
-/*
- * Simplified macro to send a verbose log message using the current LOG_TAG.
- */
-#ifndef ALOGV
-#define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
-#if LOG_NDEBUG
-#define ALOGV(...) do { if (0) { __ALOGV(__VA_ARGS__); } } while (0)
-#else
-#define ALOGV(...) __ALOGV(__VA_ARGS__)
-#endif
-#endif
-
-#ifndef ALOGV_IF
-#if LOG_NDEBUG
-#define ALOGV_IF(cond, ...) ((void)0)
-#else
-#define ALOGV_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-#endif
-
-/*
- * Simplified macro to send a debug log message using the current LOG_TAG.
- */
-#ifndef ALOGD
-#define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef ALOGD_IF
-#define ALOGD_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send an info log message using the current LOG_TAG.
- */
-#ifndef ALOGI
-#define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef ALOGI_IF
-#define ALOGI_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send a warning log message using the current LOG_TAG.
- */
-#ifndef ALOGW
-#define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef ALOGW_IF
-#define ALOGW_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send an error log message using the current LOG_TAG.
- */
-#ifndef ALOGE
-#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef ALOGE_IF
-#define ALOGE_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-// ---------------------------------------------------------------------
-
-/*
- * Conditional based on whether the current LOG_TAG is enabled at
- * verbose priority.
- */
-#ifndef IF_ALOGV
-#if LOG_NDEBUG
-#define IF_ALOGV() if (false)
-#else
-#define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
-#endif
-#endif
-
-/*
- * Conditional based on whether the current LOG_TAG is enabled at
- * debug priority.
- */
-#ifndef IF_ALOGD
-#define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
-#endif
-
-/*
- * Conditional based on whether the current LOG_TAG is enabled at
- * info priority.
- */
-#ifndef IF_ALOGI
-#define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG)
-#endif
-
-/*
- * Conditional based on whether the current LOG_TAG is enabled at
- * warn priority.
- */
-#ifndef IF_ALOGW
-#define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG)
-#endif
-
-/*
- * Conditional based on whether the current LOG_TAG is enabled at
- * error priority.
- */
-#ifndef IF_ALOGE
-#define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
-#endif
-
-
-// ---------------------------------------------------------------------
-
-/*
- * Simplified macro to send a verbose system log message using the current LOG_TAG.
- */
-#ifndef SLOGV
-#define __SLOGV(...) \
- ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
-#if LOG_NDEBUG
-#define SLOGV(...) do { if (0) { __SLOGV(__VA_ARGS__); } } while (0)
-#else
-#define SLOGV(...) __SLOGV(__VA_ARGS__)
-#endif
-#endif
-
-#ifndef SLOGV_IF
-#if LOG_NDEBUG
-#define SLOGV_IF(cond, ...) ((void)0)
-#else
-#define SLOGV_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-#endif
-
-/*
- * Simplified macro to send a debug system log message using the current LOG_TAG.
- */
-#ifndef SLOGD
-#define SLOGD(...) \
- ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef SLOGD_IF
-#define SLOGD_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send an info system log message using the current LOG_TAG.
- */
-#ifndef SLOGI
-#define SLOGI(...) \
- ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef SLOGI_IF
-#define SLOGI_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send a warning system log message using the current LOG_TAG.
- */
-#ifndef SLOGW
-#define SLOGW(...) \
- ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef SLOGW_IF
-#define SLOGW_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send an error system log message using the current LOG_TAG.
- */
-#ifndef SLOGE
-#define SLOGE(...) \
- ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef SLOGE_IF
-#define SLOGE_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-#endif /* !LINT_RLOG */
-
-// ---------------------------------------------------------------------
-
-/*
- * Simplified macro to send a verbose radio log message using the current LOG_TAG.
- */
-#ifndef RLOGV
-#define __RLOGV(...) \
- ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
-#if LOG_NDEBUG
-#define RLOGV(...) do { if (0) { __RLOGV(__VA_ARGS__); } } while (0)
-#else
-#define RLOGV(...) __RLOGV(__VA_ARGS__)
-#endif
-#endif
-
-#ifndef RLOGV_IF
-#if LOG_NDEBUG
-#define RLOGV_IF(cond, ...) ((void)0)
-#else
-#define RLOGV_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-#endif
-
-/*
- * Simplified macro to send a debug radio log message using the current LOG_TAG.
- */
-#ifndef RLOGD
-#define RLOGD(...) \
- ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef RLOGD_IF
-#define RLOGD_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send an info radio log message using the current LOG_TAG.
- */
-#ifndef RLOGI
-#define RLOGI(...) \
- ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef RLOGI_IF
-#define RLOGI_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send a warning radio log message using the current LOG_TAG.
- */
-#ifndef RLOGW
-#define RLOGW(...) \
- ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef RLOGW_IF
-#define RLOGW_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send an error radio log message using the current LOG_TAG.
- */
-#ifndef RLOGE
-#define RLOGE(...) \
- ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef RLOGE_IF
-#define RLOGE_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-
-// ---------------------------------------------------------------------
-
-/*
- * Log a fatal error. If the given condition fails, this stops program
- * execution like a normal assertion, but also generating the given message.
- * It is NOT stripped from release builds. Note that the condition test
- * is -inverted- from the normal assert() semantics.
- */
-#ifndef LOG_ALWAYS_FATAL_IF
-#define LOG_ALWAYS_FATAL_IF(cond, ...) \
- ( (__predict_false(cond)) \
- ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-#ifndef LOG_ALWAYS_FATAL
-#define LOG_ALWAYS_FATAL(...) \
- ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
-#endif
-
-/*
- * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
- * are stripped out of release builds.
- */
-#if LOG_NDEBUG
-
-#ifndef LOG_FATAL_IF
-#define LOG_FATAL_IF(cond, ...) ((void)0)
-#endif
-#ifndef LOG_FATAL
-#define LOG_FATAL(...) ((void)0)
-#endif
-
-#else
-
-#ifndef LOG_FATAL_IF
-#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
-#endif
-#ifndef LOG_FATAL
-#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
-#endif
-
-#endif
-
-/*
- * Assertion that generates a log message when the assertion fails.
- * Stripped out of release builds. Uses the current LOG_TAG.
- */
-#ifndef ALOG_ASSERT
-#define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
-//#define ALOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
-#endif
-
-// ---------------------------------------------------------------------
-
-/*
- * Basic log message macro.
- *
- * Example:
- * ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
- *
- * The second argument may be NULL or "" to indicate the "global" tag.
- */
-#ifndef ALOG
-#define ALOG(priority, tag, ...) \
- LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
-#endif
-
-/*
- * Log macro that allows you to specify a number for the priority.
- */
-#ifndef LOG_PRI
-#define LOG_PRI(priority, tag, ...) \
- android_printLog(priority, tag, __VA_ARGS__)
-#endif
-
-/*
- * Log macro that allows you to pass in a varargs ("args" is a va_list).
- */
-#ifndef LOG_PRI_VA
-#define LOG_PRI_VA(priority, tag, fmt, args) \
- android_vprintLog(priority, NULL, tag, fmt, args)
-#endif
-
-/*
- * Conditional given a desired logging priority and tag.
- */
-#ifndef IF_ALOG
-#define IF_ALOG(priority, tag) \
- if (android_testLog(ANDROID_##priority, tag))
-#endif
-
-// ---------------------------------------------------------------------
-
-/*
- * Event logging.
- */
-
-/*
- * Event log entry types.
- */
-typedef enum {
- /* Special markers for android_log_list_element type */
- EVENT_TYPE_LIST_STOP = '\n', /* declare end of list */
- EVENT_TYPE_UNKNOWN = '?', /* protocol error */
-
- /* must match with declaration in java/android/android/util/EventLog.java */
- EVENT_TYPE_INT = 0, /* uint32_t */
- EVENT_TYPE_LONG = 1, /* uint64_t */
- EVENT_TYPE_STRING = 2,
- EVENT_TYPE_LIST = 3,
- EVENT_TYPE_FLOAT = 4,
-} AndroidEventLogType;
-#define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType)
-#define typeof_AndroidEventLogType unsigned char
-
-#ifndef LOG_EVENT_INT
-#define LOG_EVENT_INT(_tag, _value) { \
- int intBuf = _value; \
- (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
- sizeof(intBuf)); \
- }
-#endif
-#ifndef LOG_EVENT_LONG
-#define LOG_EVENT_LONG(_tag, _value) { \
- long long longBuf = _value; \
- (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
- sizeof(longBuf)); \
- }
-#endif
-#ifndef LOG_EVENT_FLOAT
-#define LOG_EVENT_FLOAT(_tag, _value) { \
- float floatBuf = _value; \
- (void) android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf, \
- sizeof(floatBuf)); \
- }
-#endif
-#ifndef LOG_EVENT_STRING
-#define LOG_EVENT_STRING(_tag, _value) \
- (void) __android_log_bswrite(_tag, _value);
-#endif
-
-typedef enum log_id {
- LOG_ID_MIN = 0,
-
-#ifndef LINT_RLOG
- LOG_ID_MAIN = 0,
-#endif
- LOG_ID_RADIO = 1,
-#ifndef LINT_RLOG
- LOG_ID_EVENTS = 2,
- LOG_ID_SYSTEM = 3,
- LOG_ID_CRASH = 4,
- LOG_ID_SECURITY = 5,
- LOG_ID_KERNEL = 6, /* place last, third-parties can not use it */
-#endif
-
- LOG_ID_MAX
-} log_id_t;
-#define sizeof_log_id_t sizeof(typeof_log_id_t)
-#define typeof_log_id_t unsigned char
-
-/* For manipulating lists of events. */
-
-#define ANDROID_MAX_LIST_NEST_DEPTH 8
-
-/*
- * The opaque context used to manipulate lists of events.
- */
-typedef struct android_log_context_internal *android_log_context;
-
-/*
- * Elements returned when reading a list of events.
- */
-typedef struct {
- AndroidEventLogType type;
- uint16_t complete;
- uint16_t len;
- union {
- int32_t int32;
- int64_t int64;
- char *string;
- float float32;
- } data;
-} android_log_list_element;
-
-/*
- * Creates a context associated with an event tag to write elements to
- * the list of events.
- */
-android_log_context create_android_logger(uint32_t tag);
-
-/* All lists must be braced by a begin and end call */
-/*
- * NB: If the first level braces are missing when specifying multiple
- * elements, we will manufacturer a list to embrace it for your API
- * convenience. For a single element, it will remain solitary.
- */
-int android_log_write_list_begin(android_log_context ctx);
-int android_log_write_list_end(android_log_context ctx);
-
-int android_log_write_int32(android_log_context ctx, int32_t value);
-int android_log_write_int64(android_log_context ctx, int64_t value);
-int android_log_write_string8(android_log_context ctx, const char *value);
-int android_log_write_string8_len(android_log_context ctx,
- const char *value, size_t maxlen);
-int android_log_write_float32(android_log_context ctx, float value);
-
-/* Submit the composed list context to the specified logger id */
-/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */
-int android_log_write_list(android_log_context ctx, log_id_t id);
-
-/*
- * Creates a context from a raw buffer representing a list of events to be read.
- */
-android_log_context create_android_log_parser(const char *msg, size_t len);
-
-android_log_list_element android_log_read_next(android_log_context ctx);
-android_log_list_element android_log_peek_next(android_log_context ctx);
-
-/* Finished with reader or writer context */
-int android_log_destroy(android_log_context *ctx);
-
-/*
- * ===========================================================================
- *
- * The stuff in the rest of this file should not be used directly.
- */
-
-#define android_printLog(prio, tag, ...) \
- __android_log_print(prio, tag, __VA_ARGS__)
-
-#define android_vprintLog(prio, cond, tag, ...) \
- __android_log_vprint(prio, tag, __VA_ARGS__)
-
-/* XXX Macros to work around syntax errors in places where format string
- * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
- * (happens only in debug builds).
- */
-
-/* Returns 2nd arg. Used to substitute default value if caller's vararg list
- * is empty.
- */
-#define __android_second(dummy, second, ...) second
-
-/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
- * returns nothing.
- */
-#define __android_rest(first, ...) , ## __VA_ARGS__
-
-#define android_printAssert(cond, tag, ...) \
- __android_log_assert(cond, tag, \
- __android_second(0, ## __VA_ARGS__, NULL) __android_rest(__VA_ARGS__))
-
-#define android_writeLog(prio, tag, text) \
- __android_log_write(prio, tag, text)
-
-#define android_bWriteLog(tag, payload, len) \
- __android_log_bwrite(tag, payload, len)
-#define android_btWriteLog(tag, type, payload, len) \
- __android_log_btwrite(tag, type, payload, len)
-
-#define android_errorWriteLog(tag, subTag) \
- __android_log_error_write(tag, subTag, -1, NULL, 0)
-
-#define android_errorWriteWithInfoLog(tag, subTag, uid, data, dataLen) \
- __android_log_error_write(tag, subTag, uid, data, dataLen)
-
-/*
- * IF_ALOG uses android_testLog, but IF_ALOG can be overridden.
- * android_testLog will remain constant in its purpose as a wrapper
- * for Android logging filter policy, and can be subject to
- * change. It can be reused by the developers that override
- * IF_ALOG as a convenient means to reimplement their policy
- * over Android.
- */
-#if LOG_NDEBUG /* Production */
-#define android_testLog(prio, tag) \
- (__android_log_is_loggable(prio, tag, ANDROID_LOG_DEBUG) != 0)
-#else
-#define android_testLog(prio, tag) \
- (__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE) != 0)
-#endif
-
-/*
- * Use the per-tag properties "log.tag.<tagname>" to generate a runtime
- * result of non-zero to expose a log. prio is ANDROID_LOG_VERBOSE to
- * ANDROID_LOG_FATAL. default_prio if no property. Undefined behavior if
- * any other value.
- */
-int __android_log_is_loggable(int prio, const char *tag, int default_prio);
-
-int __android_log_security(); /* Device Owner is present */
-
-int __android_log_error_write(int tag, const char *subTag, int32_t uid, const char *data,
- uint32_t dataLen);
-
-/*
- * Send a simple string to the log.
- */
-int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
-int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
-#if defined(__GNUC__)
- __attribute__((__format__(printf, 4, 5)))
-#endif
- ;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _LIBS_LOG_LOG_H */
+#include <android/log.h>
diff --git a/include/log/log_read.h b/include/log/log_read.h
deleted file mode 100644
index 1b70aff..0000000
--- a/include/log/log_read.h
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright (C) 2013-2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _LIBS_LOG_LOG_READ_H
-#define _LIBS_LOG_LOG_READ_H
-
-#include <stdint.h>
-#include <time.h>
-
-/* struct log_time is a wire-format variant of struct timespec */
-#define NS_PER_SEC 1000000000ULL
-
-#ifdef __cplusplus
-
-// NB: do NOT define a copy constructor. This will result in structure
-// no longer being compatible with pass-by-value which is desired
-// efficient behavior. Also, pass-by-reference breaks C/C++ ABI.
-struct log_time {
-public:
- uint32_t tv_sec; // good to Feb 5 2106
- uint32_t tv_nsec;
-
- static const uint32_t tv_sec_max = 0xFFFFFFFFUL;
- static const uint32_t tv_nsec_max = 999999999UL;
-
- log_time(const timespec &T)
- {
- tv_sec = T.tv_sec;
- tv_nsec = T.tv_nsec;
- }
- log_time(uint32_t sec, uint32_t nsec)
- {
- tv_sec = sec;
- tv_nsec = nsec;
- }
- static const timespec EPOCH;
- log_time()
- {
- }
- log_time(clockid_t id)
- {
- timespec T;
- clock_gettime(id, &T);
- tv_sec = T.tv_sec;
- tv_nsec = T.tv_nsec;
- }
- log_time(const char *T)
- {
- const uint8_t *c = (const uint8_t *) T;
- tv_sec = c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24);
- tv_nsec = c[4] | (c[5] << 8) | (c[6] << 16) | (c[7] << 24);
- }
-
- // timespec
- bool operator== (const timespec &T) const
- {
- return (tv_sec == static_cast<uint32_t>(T.tv_sec))
- && (tv_nsec == static_cast<uint32_t>(T.tv_nsec));
- }
- bool operator!= (const timespec &T) const
- {
- return !(*this == T);
- }
- bool operator< (const timespec &T) const
- {
- return (tv_sec < static_cast<uint32_t>(T.tv_sec))
- || ((tv_sec == static_cast<uint32_t>(T.tv_sec))
- && (tv_nsec < static_cast<uint32_t>(T.tv_nsec)));
- }
- bool operator>= (const timespec &T) const
- {
- return !(*this < T);
- }
- bool operator> (const timespec &T) const
- {
- return (tv_sec > static_cast<uint32_t>(T.tv_sec))
- || ((tv_sec == static_cast<uint32_t>(T.tv_sec))
- && (tv_nsec > static_cast<uint32_t>(T.tv_nsec)));
- }
- bool operator<= (const timespec &T) const
- {
- return !(*this > T);
- }
- log_time operator-= (const timespec &T);
- log_time operator- (const timespec &T) const
- {
- log_time local(*this);
- return local -= T;
- }
- log_time operator+= (const timespec &T);
- log_time operator+ (const timespec &T) const
- {
- log_time local(*this);
- return local += T;
- }
-
- // log_time
- bool operator== (const log_time &T) const
- {
- return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec);
- }
- bool operator!= (const log_time &T) const
- {
- return !(*this == T);
- }
- bool operator< (const log_time &T) const
- {
- return (tv_sec < T.tv_sec)
- || ((tv_sec == T.tv_sec) && (tv_nsec < T.tv_nsec));
- }
- bool operator>= (const log_time &T) const
- {
- return !(*this < T);
- }
- bool operator> (const log_time &T) const
- {
- return (tv_sec > T.tv_sec)
- || ((tv_sec == T.tv_sec) && (tv_nsec > T.tv_nsec));
- }
- bool operator<= (const log_time &T) const
- {
- return !(*this > T);
- }
- log_time operator-= (const log_time &T);
- log_time operator- (const log_time &T) const
- {
- log_time local(*this);
- return local -= T;
- }
- log_time operator+= (const log_time &T);
- log_time operator+ (const log_time &T) const
- {
- log_time local(*this);
- return local += T;
- }
-
- uint64_t nsec() const
- {
- return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec;
- }
-
- static const char default_format[];
-
- // Add %#q for the fraction of a second to the standard library functions
- char *strptime(const char *s, const char *format = default_format);
-} __attribute__((__packed__));
-
-#else
-
-typedef struct log_time {
- uint32_t tv_sec;
- uint32_t tv_nsec;
-} __attribute__((__packed__)) log_time;
-
-#endif
-
-#endif /* define _LIBS_LOG_LOG_READ_H */
diff --git a/include/log/logd.h b/include/log/logd.h
index b271602..ffb8268 100644
--- a/include/log/logd.h
+++ b/include/log/logd.h
@@ -1,54 +1 @@
-/*
- * Copyright (C) 2009 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_CUTILS_LOGD_H
-#define _ANDROID_CUTILS_LOGD_H
-
-/* the stable/frozen log-related definitions have been
- * moved to this header, which is exposed by the NDK
- */
#include <android/log.h>
-
-/* the rest is only used internally by the system */
-#if !defined(_WIN32)
-#include <pthread.h>
-#endif
-#include <stdarg.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <log/uio.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int __android_log_bwrite(int32_t tag, const void *payload, size_t len);
-int __android_log_btwrite(int32_t tag, char type, const void *payload,
- size_t len);
-int __android_log_bswrite(int32_t tag, const char *payload);
-
-int __android_log_security_bwrite(int32_t tag, const void *payload, size_t len);
-int __android_log_security_bswrite(int32_t tag, const char *payload);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _LOGD_H */
diff --git a/include/log/logger.h b/include/log/logger.h
index 256fdd1..46587fb 100644
--- a/include/log/logger.h
+++ b/include/log/logger.h
@@ -11,12 +11,13 @@
#define _LIBS_LOG_LOGGER_H
#include <stdint.h>
-#ifdef __linux__
-#include <time.h> /* clockid_t definition */
+#include <time.h>
+
+#ifdef __cplusplus
+#include <string>
#endif
-#include <log/log.h>
-#include <log/log_read.h>
+#include <android/log.h>
#ifdef __cplusplus
extern "C" {
@@ -76,21 +77,168 @@
char msg[0]; /* the entry's payload */
} __attribute__((__packed__));
+/* struct log_time is a wire-format variant of struct timespec */
+#define NS_PER_SEC 1000000000ULL
+
+#ifdef __cplusplus
+
+// NB: do NOT define a copy constructor. This will result in structure
+// no longer being compatible with pass-by-value which is desired
+// efficient behavior. Also, pass-by-reference breaks C/C++ ABI.
+struct log_time {
+public:
+ uint32_t tv_sec; // good to Feb 5 2106
+ uint32_t tv_nsec;
+
+ static const uint32_t tv_sec_max = 0xFFFFFFFFUL;
+ static const uint32_t tv_nsec_max = 999999999UL;
+
+ log_time(const timespec &T)
+ {
+ tv_sec = T.tv_sec;
+ tv_nsec = T.tv_nsec;
+ }
+ log_time(uint32_t sec, uint32_t nsec)
+ {
+ tv_sec = sec;
+ tv_nsec = nsec;
+ }
+ static const timespec EPOCH;
+ log_time()
+ {
+ }
+#ifdef __linux__
+ log_time(clockid_t id)
+ {
+ timespec T;
+ clock_gettime(id, &T);
+ tv_sec = T.tv_sec;
+ tv_nsec = T.tv_nsec;
+ }
+#endif
+ log_time(const char *T)
+ {
+ const uint8_t *c = (const uint8_t *) T;
+ tv_sec = c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24);
+ tv_nsec = c[4] | (c[5] << 8) | (c[6] << 16) | (c[7] << 24);
+ }
+
+ // timespec
+ bool operator== (const timespec &T) const
+ {
+ return (tv_sec == static_cast<uint32_t>(T.tv_sec))
+ && (tv_nsec == static_cast<uint32_t>(T.tv_nsec));
+ }
+ bool operator!= (const timespec &T) const
+ {
+ return !(*this == T);
+ }
+ bool operator< (const timespec &T) const
+ {
+ return (tv_sec < static_cast<uint32_t>(T.tv_sec))
+ || ((tv_sec == static_cast<uint32_t>(T.tv_sec))
+ && (tv_nsec < static_cast<uint32_t>(T.tv_nsec)));
+ }
+ bool operator>= (const timespec &T) const
+ {
+ return !(*this < T);
+ }
+ bool operator> (const timespec &T) const
+ {
+ return (tv_sec > static_cast<uint32_t>(T.tv_sec))
+ || ((tv_sec == static_cast<uint32_t>(T.tv_sec))
+ && (tv_nsec > static_cast<uint32_t>(T.tv_nsec)));
+ }
+ bool operator<= (const timespec &T) const
+ {
+ return !(*this > T);
+ }
+ log_time operator-= (const timespec &T);
+ log_time operator- (const timespec &T) const
+ {
+ log_time local(*this);
+ return local -= T;
+ }
+ log_time operator+= (const timespec &T);
+ log_time operator+ (const timespec &T) const
+ {
+ log_time local(*this);
+ return local += T;
+ }
+
+ // log_time
+ bool operator== (const log_time &T) const
+ {
+ return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec);
+ }
+ bool operator!= (const log_time &T) const
+ {
+ return !(*this == T);
+ }
+ bool operator< (const log_time &T) const
+ {
+ return (tv_sec < T.tv_sec)
+ || ((tv_sec == T.tv_sec) && (tv_nsec < T.tv_nsec));
+ }
+ bool operator>= (const log_time &T) const
+ {
+ return !(*this < T);
+ }
+ bool operator> (const log_time &T) const
+ {
+ return (tv_sec > T.tv_sec)
+ || ((tv_sec == T.tv_sec) && (tv_nsec > T.tv_nsec));
+ }
+ bool operator<= (const log_time &T) const
+ {
+ return !(*this > T);
+ }
+ log_time operator-= (const log_time &T);
+ log_time operator- (const log_time &T) const
+ {
+ log_time local(*this);
+ return local -= T;
+ }
+ log_time operator+= (const log_time &T);
+ log_time operator+ (const log_time &T) const
+ {
+ log_time local(*this);
+ return local += T;
+ }
+
+ uint64_t nsec() const
+ {
+ return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec;
+ }
+
+ static const char default_format[];
+
+ // Add %#q for the fraction of a second to the standard library functions
+ char *strptime(const char *s, const char *format = default_format);
+} __attribute__((__packed__));
+
+#else
+
+typedef struct log_time {
+ uint32_t tv_sec;
+ uint32_t tv_nsec;
+} __attribute__((__packed__)) log_time;
+
+#endif
+
/*
* The maximum size of the log entry payload that can be
* written to the logger. An attempt to write more than
* this amount will result in a truncated log entry.
*/
-#define LOGGER_ENTRY_MAX_PAYLOAD 4068
+#define LOGGER_ENTRY_MAX_PAYLOAD 4068
/*
* The maximum size of a log entry which can be read from the
* kernel logger driver. An attempt to read less than this amount
* may result in read() returning EINVAL.
*/
-#define LOGGER_ENTRY_MAX_LEN (5*1024)
-
-#define NS_PER_SEC 1000000000ULL
+#define LOGGER_ENTRY_MAX_LEN (5*1024)
struct log_msg {
union {
@@ -220,6 +368,94 @@
const char *android_log_id_to_name(log_id_t log_id);
#ifdef __cplusplus
+// android_log_context C++ helpers
+class android_log_event_context {
+ android_log_context ctx;
+ int ret;
+
+public:
+ explicit android_log_event_context(int tag) : ret(0) {
+ ctx = create_android_logger(tag);
+ }
+ explicit android_log_event_context(log_msg& log_msg) : ret(0) {
+ ctx = create_android_log_parser(log_msg.msg() + sizeof(uint32_t),
+ log_msg.entry.len - sizeof(uint32_t));
+ }
+ ~android_log_event_context() { android_log_destroy(&ctx); }
+
+ int close() {
+ int retval = android_log_destroy(&ctx);
+ if (retval < 0) ret = retval;
+ return retval;
+ }
+
+ // To allow above C calls to use this class as parameter
+ operator android_log_context() const { return ctx; };
+
+ int error() const { return ret; }
+
+ int begin() {
+ int retval = android_log_write_list_begin(ctx);
+ if (retval < 0) ret = retval;
+ return ret;
+ }
+ int end() {
+ int retval = android_log_write_list_end(ctx);
+ if (retval < 0) ret = retval;
+ return ret;
+ }
+
+ android_log_event_context& operator <<(int32_t value) {
+ int retval = android_log_write_int32(ctx, value);
+ if (retval < 0) ret = retval;
+ return *this;
+ }
+ android_log_event_context& operator <<(uint32_t value) {
+ int retval = android_log_write_int32(ctx, value);
+ if (retval < 0) ret = retval;
+ return *this;
+ }
+ android_log_event_context& operator <<(int64_t value) {
+ int retval = android_log_write_int64(ctx, value);
+ if (retval < 0) ret = retval;
+ return *this;
+ }
+ android_log_event_context& operator <<(uint64_t value) {
+ int retval = android_log_write_int64(ctx, value);
+ if (retval < 0) ret = retval;
+ return *this;
+ }
+ android_log_event_context& operator <<(const char* value) {
+ int retval = android_log_write_string8(ctx, value);
+ if (retval < 0) ret = retval;
+ return *this;
+ }
+ android_log_event_context& operator <<(std::string& value) {
+ int retval = android_log_write_string8_len(ctx,
+ value.data(),
+ value.length());
+ if (retval < 0) ret = retval;
+ return *this;
+ }
+ android_log_event_context& operator <<(float value) {
+ int retval = android_log_write_float32(ctx, value);
+ if (retval < 0) ret = retval;
+ return *this;
+ }
+
+ int write(log_id_t id) {
+ int retval = android_log_write_list(ctx, id);
+ if (retval < 0) ret = retval;
+ return ret;
+ }
+
+ android_log_list_element read() { return android_log_read_next(ctx); }
+ android_log_list_element peak() { return android_log_peek_next(ctx); }
+
+};
+#endif
+
+#ifdef __cplusplus
}
#endif
diff --git a/include/log/logprint.h b/include/log/logprint.h
index 1bc1f72..f70633d 100644
--- a/include/log/logprint.h
+++ b/include/log/logprint.h
@@ -17,11 +17,12 @@
#ifndef _LOGPRINT_H
#define _LOGPRINT_H
-#include <log/log.h>
-#include <log/logger.h>
-#include <log/event_tag_map.h>
#include <pthread.h>
+#include <android/log.h>
+#include <log/event_tag_map.h>
+#include <log/logger.h>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -58,6 +59,7 @@
int32_t pid;
int32_t tid;
const char * tag;
+ size_t tagLen;
size_t messageLen;
const char * message;
} AndroidLogEntry;
diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h
index bc1c0ca..167a6d9 100644
--- a/include/private/android_filesystem_config.h
+++ b/include/private/android_filesystem_config.h
@@ -115,7 +115,6 @@
#define AID_NET_ADMIN 3005 /* can configure interfaces and routing tables. */
#define AID_NET_BW_STATS 3006 /* read bandwidth statistics */
#define AID_NET_BW_ACCT 3007 /* change bandwidth statistics accounting */
-#define AID_NET_BT_STACK 3008 /* bluetooth: access config files */
#define AID_READPROC 3009 /* Allow /proc read access */
#define AID_WAKELOCK 3010 /* Allow system wakelock read/write access */
@@ -221,7 +220,6 @@
{ "net_admin", AID_NET_ADMIN, },
{ "net_bw_stats", AID_NET_BW_STATS, },
{ "net_bw_acct", AID_NET_BW_ACCT, },
- { "net_bt_stack", AID_NET_BT_STACK, },
{ "readproc", AID_READPROC, },
{ "wakelock", AID_WAKELOCK, },
diff --git a/include/private/android_logger.h b/include/private/android_logger.h
index c3ea1ed..b6a20c3 100644
--- a/include/private/android_logger.h
+++ b/include/private/android_logger.h
@@ -24,11 +24,15 @@
#include <stdint.h>
#include <sys/types.h>
-#include <log/log.h>
-#include <log/log_read.h>
+#include <android/log.h>
+#include <log/logger.h>
#define LOGGER_MAGIC 'l'
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
/* Header Structure to pstore */
typedef struct __attribute__((__packed__)) {
uint8_t magic;
@@ -84,6 +88,7 @@
* in C++.
* http://stackoverflow.com/questions/4412749/are-flexible-array-members-valid-in-c
*/
+
typedef struct __attribute__((__packed__)) {
int8_t type; // EVENT_TYPE_STRING;
int32_t length; // Little Endian Order
@@ -98,10 +103,6 @@
char data[];
} android_log_event_string_t;
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
#define ANDROID_LOG_PMSG_FILE_MAX_SEQUENCE 256 /* 1MB file */
#define ANDROID_LOG_PMSG_FILE_SEQUENCE 1000
diff --git a/include/system/graphics.h b/include/system/graphics.h
index 529a562..ae10fa0 100644
--- a/include/system/graphics.h
+++ b/include/system/graphics.h
@@ -452,15 +452,15 @@
*
* Buffers must have a 8 bit depth.
*
- * @y, @cb, and @cr point to the first byte of their respective planes.
+ * y, cb, and cr point to the first byte of their respective planes.
*
* Stride describes the distance in bytes from the first value of one row of
* the image to the first value of the next row. It includes the width of the
* image plus padding.
- * @ystride is the stride of the luma plane.
- * @cstride is the stride of the chroma planes.
+ * ystride is the stride of the luma plane.
+ * cstride is the stride of the chroma planes.
*
- * @chroma_step is the distance in bytes from one chroma pixel value to the
+ * chroma_step is the distance in bytes from one chroma pixel value to the
* next. This is 2 bytes for semiplanar (because chroma values are interleaved
* and each chroma value is one byte) and 1 for planar.
*/
@@ -585,9 +585,9 @@
* measurement is correct. It is between 0.f and 1.f, inclusive, with 1.f ==
* 100% confidence.
*
- * @num_points is the number of points in the list
+ * num_points is the number of points in the list
*
- * @xyz_points is the flexible array of floating-point values.
+ * xyz_points is the flexible array of floating-point values.
* It contains (num_points) * 4 floats.
*
* For example:
@@ -612,7 +612,14 @@
/** reserved for future use, set to 0 by gralloc's (*lock)() */
uint32_t reserved[8];
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wc99-extensions"
+#endif
float xyzc_points[];
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
};
/**
diff --git a/include/system/qemu_pipe.h b/include/system/qemu_pipe.h
index d403f8d..af25079 100644
--- a/include/system/qemu_pipe.h
+++ b/include/system/qemu_pipe.h
@@ -85,7 +85,7 @@
const void* buff,
size_t len) {
char header[5];
- snprintf(header, sizeof(header), "%04x", len);
+ snprintf(header, sizeof(header), "%04zx", len);
ssize_t ret = TEMP_FAILURE_RETRY(write(fd, header, 4));
if (ret != 4) {
QEMU_PIPE_DEBUG("Can't write qemud frame header: %s", strerror(errno));
@@ -123,7 +123,7 @@
return -1;
}
ret = TEMP_FAILURE_RETRY(read(fd, buff, size));
- if (ret != size) {
+ if (ret != (ssize_t)size) {
QEMU_PIPE_DEBUG("Could not read qemud frame payload: %s",
strerror(errno));
return -1;
diff --git a/include/system/radio.h b/include/system/radio.h
index 9e291c8..d73d3ae 100644
--- a/include/system/radio.h
+++ b/include/system/radio.h
@@ -218,7 +218,8 @@
} radio_event_t;
-static radio_rds_t radio_rds_for_region(bool rds, radio_region_t region) {
+static inline
+radio_rds_t radio_rds_for_region(bool rds, radio_region_t region) {
if (!rds)
return RADIO_RDS_NONE;
switch(region) {
@@ -234,7 +235,8 @@
}
}
-static radio_deemphasis_t radio_demephasis_for_region(radio_region_t region) {
+static inline
+radio_deemphasis_t radio_demephasis_for_region(radio_region_t region) {
switch(region) {
case RADIO_REGION_KOREA:
case RADIO_REGION_ITU_2:
diff --git a/include/system/window.h b/include/system/window.h
index 33b7c3d..f439705 100644
--- a/include/system/window.h
+++ b/include/system/window.h
@@ -38,8 +38,17 @@
/*****************************************************************************/
+#ifdef __cplusplus
+#define ANDROID_NATIVE_UNSIGNED_CAST(x) static_cast<unsigned int>(x)
+#else
+#define ANDROID_NATIVE_UNSIGNED_CAST(x) ((unsigned int)(x))
+#endif
+
#define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \
- (((unsigned)(a)<<24)|((unsigned)(b)<<16)|((unsigned)(c)<<8)|(unsigned)(d))
+ ((ANDROID_NATIVE_UNSIGNED_CAST(a) << 24) | \
+ (ANDROID_NATIVE_UNSIGNED_CAST(b) << 16) | \
+ (ANDROID_NATIVE_UNSIGNED_CAST(c) << 8) | \
+ (ANDROID_NATIVE_UNSIGNED_CAST(d)))
#define ANDROID_NATIVE_WINDOW_MAGIC \
ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d')
diff --git a/include/utils/Compat.h b/include/utils/Compat.h
index b2ba55e..2709e3b 100644
--- a/include/utils/Compat.h
+++ b/include/utils/Compat.h
@@ -45,13 +45,8 @@
#define DEFFILEMODE 0666
#endif /* _WIN32 */
-#if defined(_WIN32)
-#define ZD "%ld"
-#define ZD_TYPE long
-#else
#define ZD "%zd"
#define ZD_TYPE ssize_t
-#endif
/*
* Needed for cases where something should be constexpr if possible, but not
diff --git a/include/utils/Condition.h b/include/utils/Condition.h
index 5650598..25a53aa 100644
--- a/include/utils/Condition.h
+++ b/include/utils/Condition.h
@@ -17,6 +17,7 @@
#ifndef _LIBS_UTILS_CONDITION_H
#define _LIBS_UTILS_CONDITION_H
+#include <limits.h>
#include <stdint.h>
#include <sys/types.h>
#include <time.h>
@@ -120,7 +121,7 @@
// On 32-bit devices, tv_sec is 32-bit, but `reltime` is 64-bit.
int64_t reltime_sec = reltime/1000000000;
- ts.tv_nsec += reltime%1000000000;
+ ts.tv_nsec += static_cast<long>(reltime%1000000000);
if (reltime_sec < INT64_MAX && ts.tv_nsec >= 1000000000) {
ts.tv_nsec -= 1000000000;
++reltime_sec;
@@ -133,11 +134,7 @@
time_sec += reltime_sec;
}
-#if defined(__LP64__)
- ts.tv_sec = time_sec;
-#else
- ts.tv_sec = (time_sec > INT32_MAX) ? INT32_MAX : time_sec;
-#endif
+ ts.tv_sec = (time_sec > LONG_MAX) ? LONG_MAX : static_cast<long>(time_sec);
return -pthread_cond_timedwait(&mCond, &mutex.mMutex, &ts);
}
diff --git a/include/utils/Flattenable.h b/include/utils/Flattenable.h
index 882a8b2..22b811a 100644
--- a/include/utils/Flattenable.h
+++ b/include/utils/Flattenable.h
@@ -19,55 +19,62 @@
#include <stdint.h>
+#include <string.h>
#include <sys/types.h>
#include <utils/Errors.h>
#include <utils/Debug.h>
+#include <type_traits>
+
namespace android {
class FlattenableUtils {
public:
- template<int N>
+ template<size_t N>
static size_t align(size_t size) {
COMPILE_TIME_ASSERT_FUNCTION_SCOPE( !(N & (N-1)) );
return (size + (N-1)) & ~(N-1);
}
- template<int N>
+ template<size_t N>
static size_t align(void const*& buffer) {
COMPILE_TIME_ASSERT_FUNCTION_SCOPE( !(N & (N-1)) );
- intptr_t b = intptr_t(buffer);
- buffer = (void*)((intptr_t(buffer) + (N-1)) & ~(N-1));
- return size_t(intptr_t(buffer) - b);
+ uintptr_t b = uintptr_t(buffer);
+ buffer = reinterpret_cast<void*>((uintptr_t(buffer) + (N-1)) & ~(N-1));
+ return size_t(uintptr_t(buffer) - b);
}
- template<int N>
+ template<size_t N>
static size_t align(void*& buffer) {
return align<N>( const_cast<void const*&>(buffer) );
}
static void advance(void*& buffer, size_t& size, size_t offset) {
- buffer = reinterpret_cast<void*>( intptr_t(buffer) + offset );
+ buffer = reinterpret_cast<void*>( uintptr_t(buffer) + offset );
size -= offset;
}
static void advance(void const*& buffer, size_t& size, size_t offset) {
- buffer = reinterpret_cast<void const*>( intptr_t(buffer) + offset );
+ buffer = reinterpret_cast<void const*>( uintptr_t(buffer) + offset );
size -= offset;
}
// write a POD structure
template<typename T>
static void write(void*& buffer, size_t& size, const T& value) {
- *static_cast<T*>(buffer) = value;
+ static_assert(std::is_trivially_copyable<T>::value,
+ "Cannot flatten a non-trivially-copyable type");
+ memcpy(buffer, &value, sizeof(T));
advance(buffer, size, sizeof(T));
}
// read a POD structure
template<typename T>
static void read(void const*& buffer, size_t& size, T& value) {
- value = *static_cast<T const*>(buffer);
+ static_assert(std::is_trivially_copyable<T>::value,
+ "Cannot unflatten a non-trivially-copyable type");
+ memcpy(&value, buffer, sizeof(T));
advance(buffer, size, sizeof(T));
}
};
diff --git a/include/utils/KeyedVector.h b/include/utils/KeyedVector.h
index c4faae0..42de401 100644
--- a/include/utils/KeyedVector.h
+++ b/include/utils/KeyedVector.h
@@ -21,11 +21,10 @@
#include <stdint.h>
#include <sys/types.h>
-#include <cutils/log.h>
-
+#include <android/log.h>
+#include <utils/Errors.h>
#include <utils/SortedVector.h>
#include <utils/TypeHelpers.h>
-#include <utils/Errors.h>
// ---------------------------------------------------------------------------
@@ -97,13 +96,6 @@
SortedVector< key_value_pair_t<KEY, VALUE> > mVector;
};
-// KeyedVector<KEY, VALUE> can be trivially moved using memcpy() because its
-// underlying SortedVector can be trivially moved.
-template<typename KEY, typename VALUE> struct trait_trivial_move<KeyedVector<KEY, VALUE> > {
- enum { value = trait_trivial_move<SortedVector< key_value_pair_t<KEY, VALUE> > >::value };
-};
-
-
// ---------------------------------------------------------------------------
/**
@@ -164,7 +156,7 @@
VALUE& KeyedVector<KEY,VALUE>::editValueFor(const KEY& key) {
ssize_t i = this->indexOfKey(key);
LOG_ALWAYS_FATAL_IF(i<0, "%s: key not found", __PRETTY_FUNCTION__);
- return mVector.editItemAt(i).value;
+ return mVector.editItemAt(static_cast<size_t>(i)).value;
}
template<typename KEY, typename VALUE> inline
@@ -188,7 +180,7 @@
ssize_t KeyedVector<KEY,VALUE>::replaceValueAt(size_t index, const VALUE& item) {
if (index<size()) {
mVector.editItemAt(index).value = item;
- return index;
+ return static_cast<ssize_t>(index);
}
return BAD_INDEX;
}
diff --git a/include/utils/Log.h b/include/utils/Log.h
index 4259c86..6ef3fa3 100644
--- a/include/utils/Log.h
+++ b/include/utils/Log.h
@@ -28,9 +28,10 @@
#ifndef _LIBS_UTILS_LOG_H
#define _LIBS_UTILS_LOG_H
-#include <cutils/log.h>
#include <sys/types.h>
+#include <android/log.h>
+
#ifdef __cplusplus
namespace android {
diff --git a/include/utils/Looper.h b/include/utils/Looper.h
index da2d5f2..a62e67f 100644
--- a/include/utils/Looper.h
+++ b/include/utils/Looper.h
@@ -49,7 +49,7 @@
*/
struct Message {
Message() : what(0) { }
- Message(int what) : what(what) { }
+ Message(int w) : what(w) { }
/* The message type. (interpretation is left up to the handler) */
int what;
@@ -66,7 +66,7 @@
*/
class MessageHandler : public virtual RefBase {
protected:
- virtual ~MessageHandler() { }
+ virtual ~MessageHandler();
public:
/**
@@ -97,7 +97,7 @@
*/
class LooperCallback : public virtual RefBase {
protected:
- virtual ~LooperCallback() { }
+ virtual ~LooperCallback();
public:
/**
@@ -436,8 +436,8 @@
struct MessageEnvelope {
MessageEnvelope() : uptime(0) { }
- MessageEnvelope(nsecs_t uptime, const sp<MessageHandler> handler,
- const Message& message) : uptime(uptime), handler(handler), message(message) {
+ MessageEnvelope(nsecs_t u, const sp<MessageHandler> h,
+ const Message& m) : uptime(u), handler(h), message(m) {
}
nsecs_t uptime;
diff --git a/include/utils/LruCache.h b/include/utils/LruCache.h
index f4e225a..89dccd6 100644
--- a/include/utils/LruCache.h
+++ b/include/utils/LruCache.h
@@ -166,7 +166,7 @@
, mOldest(NULL)
, mYoungest(NULL)
, mMaxCapacity(maxCapacity)
- , mNullValue(NULL) {
+ , mNullValue(0) {
mSet->max_load_factor(1.0);
};
diff --git a/include/utils/RefBase.h b/include/utils/RefBase.h
index 3c318c4..36016cd 100644
--- a/include/utils/RefBase.h
+++ b/include/utils/RefBase.h
@@ -206,6 +206,14 @@
// ---------------------------------------------------------------------------
+// RefererenceRenamer is pure abstract, there is no virtual method
+// implementation to put in a translation unit in order to silence the
+// weak vtables warning.
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wweak-vtables"
+#endif
+
class ReferenceRenamer {
protected:
// destructor is purposedly not virtual so we avoid code overhead from
@@ -217,6 +225,10 @@
virtual void operator()(size_t i) const = 0;
};
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
+
// ---------------------------------------------------------------------------
class RefBase
@@ -372,7 +384,7 @@
// destructor to eliminate the template requirement of LightRefBase
class VirtualLightRefBase : public LightRefBase<VirtualLightRefBase> {
public:
- virtual ~VirtualLightRefBase() {}
+ virtual ~VirtualLightRefBase();
};
// ---------------------------------------------------------------------------
@@ -646,42 +658,42 @@
// a template<typename TYPE inherits RefBase> template...
template<typename TYPE> static inline
- void move_references(sp<TYPE>* d, sp<TYPE> const* s, size_t n) {
+ void move_references(sp<TYPE>* dest, sp<TYPE> const* src, size_t n) {
class Renamer : public ReferenceRenamer {
- sp<TYPE>* d;
- sp<TYPE> const* s;
+ sp<TYPE>* d_;
+ sp<TYPE> const* s_;
virtual void operator()(size_t i) const {
// The id are known to be the sp<>'s this pointer
- TYPE::renameRefId(d[i].get(), &s[i], &d[i]);
+ TYPE::renameRefId(d_[i].get(), &s_[i], &d_[i]);
}
public:
- Renamer(sp<TYPE>* d, sp<TYPE> const* s) : d(d), s(s) { }
+ Renamer(sp<TYPE>* d, sp<TYPE> const* s) : d_(d), s_(s) { }
virtual ~Renamer() { }
};
- memmove(d, s, n*sizeof(sp<TYPE>));
- TYPE::renameRefs(n, Renamer(d, s));
+ memmove(dest, src, n*sizeof(sp<TYPE>));
+ TYPE::renameRefs(n, Renamer(dest, src));
}
template<typename TYPE> static inline
- void move_references(wp<TYPE>* d, wp<TYPE> const* s, size_t n) {
+ void move_references(wp<TYPE>* dest, wp<TYPE> const* src, size_t n) {
class Renamer : public ReferenceRenamer {
- wp<TYPE>* d;
- wp<TYPE> const* s;
+ wp<TYPE>* d_;
+ wp<TYPE> const* s_;
virtual void operator()(size_t i) const {
// The id are known to be the wp<>'s this pointer
- TYPE::renameRefId(d[i].get_refs(), &s[i], &d[i]);
+ TYPE::renameRefId(d_[i].get_refs(), &s_[i], &d_[i]);
}
public:
- Renamer(wp<TYPE>* d, wp<TYPE> const* s) : d(d), s(s) { }
+ Renamer(wp<TYPE>* rd, wp<TYPE> const* rs) : d_(rd), s_(rs) { }
virtual ~Renamer() { }
};
- memmove(d, s, n*sizeof(wp<TYPE>));
- TYPE::renameRefs(n, Renamer(d, s));
+ memmove(dest, src, n*sizeof(wp<TYPE>));
+ TYPE::renameRefs(n, Renamer(dest, src));
}
};
@@ -712,7 +724,6 @@
ReferenceMover::move_references(d, s, n);
}
-
}; // namespace android
// ---------------------------------------------------------------------------
diff --git a/include/utils/Singleton.h b/include/utils/Singleton.h
index ffc03cb..7cc4c18 100644
--- a/include/utils/Singleton.h
+++ b/include/utils/Singleton.h
@@ -19,6 +19,7 @@
#include <stdint.h>
#include <sys/types.h>
+#include <utils/Mutex.h>
#include <utils/threads.h>
#include <cutils/compiler.h>
@@ -45,8 +46,8 @@
}
protected:
- ~Singleton() { };
- Singleton() { };
+ ~Singleton() { }
+ Singleton() { }
private:
Singleton(const Singleton&);
@@ -55,6 +56,12 @@
static TYPE* sInstance;
};
+template <typename TYPE>
+Mutex Singleton<TYPE>::sLock;
+
+template <typename TYPE>
+TYPE* Singleton<TYPE>::sInstance;
+
/*
* use ANDROID_SINGLETON_STATIC_INSTANCE(TYPE) in your implementation file
* (eg: <TYPE>.cpp) to create the static instance of Singleton<>'s attributes,
diff --git a/include/utils/SortedVector.h b/include/utils/SortedVector.h
index 85bd263..96dfcca 100644
--- a/include/utils/SortedVector.h
+++ b/include/utils/SortedVector.h
@@ -21,11 +21,10 @@
#include <stdint.h>
#include <sys/types.h>
-#include <cutils/log.h>
-
+#include <android/log.h>
+#include <utils/TypeHelpers.h>
#include <utils/Vector.h>
#include <utils/VectorImpl.h>
-#include <utils/TypeHelpers.h>
// ---------------------------------------------------------------------------
@@ -150,10 +149,6 @@
virtual int do_compare(const void* lhs, const void* rhs) const;
};
-// SortedVector<T> can be trivially moved using memcpy() because moving does not
-// require any change to the underlying SharedBuffer contents or reference count.
-template<typename T> struct trait_trivial_move<SortedVector<T> > { enum { value = true }; };
-
// ---------------------------------------------------------------------------
// No user serviceable parts from here...
// ---------------------------------------------------------------------------
diff --git a/include/utils/StrongPointer.h b/include/utils/StrongPointer.h
index d90b788..294e6b6 100644
--- a/include/utils/StrongPointer.h
+++ b/include/utils/StrongPointer.h
@@ -137,7 +137,7 @@
sp<T>::sp(U* other)
: m_ptr(other) {
if (other)
- ((T*) other)->incStrong(this);
+ (static_cast<T*>(other))->incStrong(this);
}
template<typename T> template<typename U>
@@ -212,7 +212,7 @@
template<typename T> template<typename U>
sp<T>& sp<T>::operator =(U* other) {
if (other)
- ((T*) other)->incStrong(this);
+ (static_cast<T*>(other))->incStrong(this);
if (m_ptr)
m_ptr->decStrong(this);
m_ptr = other;
diff --git a/include/utils/TypeHelpers.h b/include/utils/TypeHelpers.h
index 64d25c5..2a25227 100644
--- a/include/utils/TypeHelpers.h
+++ b/include/utils/TypeHelpers.h
@@ -18,6 +18,8 @@
#define ANDROID_TYPE_HELPERS_H
#include <new>
+#include <type_traits>
+
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
@@ -149,16 +151,21 @@
}
}
-template<typename TYPE> inline
-void copy_type(TYPE* d, const TYPE* s, size_t n) {
- if (!traits<TYPE>::has_trivial_copy) {
- while (n > 0) {
- n--;
- new(d) TYPE(*s);
- d++, s++;
- }
- } else {
- memcpy(d,s,n*sizeof(TYPE));
+template<typename TYPE>
+typename std::enable_if<traits<TYPE>::has_trivial_copy>::type
+inline
+copy_type(TYPE* d, const TYPE* s, size_t n) {
+ memcpy(d,s,n*sizeof(TYPE));
+}
+
+template<typename TYPE>
+typename std::enable_if<!traits<TYPE>::has_trivial_copy>::type
+inline
+copy_type(TYPE* d, const TYPE* s, size_t n) {
+ while (n > 0) {
+ n--;
+ new(d) TYPE(*s);
+ d++, s++;
}
}
@@ -178,49 +185,61 @@
}
}
-template<typename TYPE> inline
-void move_forward_type(TYPE* d, const TYPE* s, size_t n = 1) {
- if ((traits<TYPE>::has_trivial_dtor && traits<TYPE>::has_trivial_copy)
- || traits<TYPE>::has_trivial_move)
- {
- memmove(d,s,n*sizeof(TYPE));
- } else {
- d += n;
- s += n;
- while (n > 0) {
- n--;
- --d, --s;
- if (!traits<TYPE>::has_trivial_copy) {
- new(d) TYPE(*s);
- } else {
- *d = *s;
- }
- if (!traits<TYPE>::has_trivial_dtor) {
- s->~TYPE();
- }
+template<typename TYPE>
+struct use_trivial_move : public std::integral_constant<bool,
+ (traits<TYPE>::has_trivial_dtor && traits<TYPE>::has_trivial_copy)
+ || traits<TYPE>::has_trivial_move
+> {};
+
+template<typename TYPE>
+typename std::enable_if<use_trivial_move<TYPE>::value>::type
+inline
+move_forward_type(TYPE* d, const TYPE* s, size_t n = 1) {
+ memmove(d, s, n*sizeof(TYPE));
+}
+
+template<typename TYPE>
+typename std::enable_if<!use_trivial_move<TYPE>::value>::type
+inline
+move_forward_type(TYPE* d, const TYPE* s, size_t n = 1) {
+ d += n;
+ s += n;
+ while (n > 0) {
+ n--;
+ --d, --s;
+ if (!traits<TYPE>::has_trivial_copy) {
+ new(d) TYPE(*s);
+ } else {
+ *d = *s;
+ }
+ if (!traits<TYPE>::has_trivial_dtor) {
+ s->~TYPE();
}
}
}
-template<typename TYPE> inline
-void move_backward_type(TYPE* d, const TYPE* s, size_t n = 1) {
- if ((traits<TYPE>::has_trivial_dtor && traits<TYPE>::has_trivial_copy)
- || traits<TYPE>::has_trivial_move)
- {
- memmove(d,s,n*sizeof(TYPE));
- } else {
- while (n > 0) {
- n--;
- if (!traits<TYPE>::has_trivial_copy) {
- new(d) TYPE(*s);
- } else {
- *d = *s;
- }
- if (!traits<TYPE>::has_trivial_dtor) {
- s->~TYPE();
- }
- d++, s++;
+template<typename TYPE>
+typename std::enable_if<use_trivial_move<TYPE>::value>::type
+inline
+move_backward_type(TYPE* d, const TYPE* s, size_t n = 1) {
+ memmove(d, s, n*sizeof(TYPE));
+}
+
+template<typename TYPE>
+typename std::enable_if<!use_trivial_move<TYPE>::value>::type
+inline
+move_backward_type(TYPE* d, const TYPE* s, size_t n = 1) {
+ while (n > 0) {
+ n--;
+ if (!traits<TYPE>::has_trivial_copy) {
+ new(d) TYPE(*s);
+ } else {
+ *d = *s;
}
+ if (!traits<TYPE>::has_trivial_dtor) {
+ s->~TYPE();
+ }
+ d++, s++;
}
}
@@ -239,6 +258,11 @@
VALUE value;
key_value_pair_t() { }
key_value_pair_t(const key_value_pair_t& o) : key(o.key), value(o.value) { }
+ key_value_pair_t& operator=(const key_value_pair_t& o) {
+ key = o.key;
+ value = o.value;
+ return *this;
+ }
key_value_pair_t(const KEY& k, const VALUE& v) : key(k), value(v) { }
explicit key_value_pair_t(const KEY& k) : key(k) { }
inline bool operator < (const key_value_pair_t& o) const {
@@ -275,8 +299,7 @@
template <typename TKey>
hash_t hash_type(const TKey& key);
-/* Built-in hash code specializations.
- * Assumes pointers are 32bit. */
+/* Built-in hash code specializations */
#define ANDROID_INT32_HASH(T) \
template <> inline hash_t hash_type(const T& value) { return hash_t(value); }
#define ANDROID_INT64_HASH(T) \
@@ -284,7 +307,11 @@
return hash_t((value >> 32) ^ value); }
#define ANDROID_REINTERPRET_HASH(T, R) \
template <> inline hash_t hash_type(const T& value) { \
- return hash_type(*reinterpret_cast<const R*>(&value)); }
+ R newValue; \
+ static_assert(sizeof(newValue) == sizeof(value), "size mismatch"); \
+ memcpy(&newValue, &value, sizeof(newValue)); \
+ return hash_type(newValue); \
+ }
ANDROID_INT32_HASH(bool)
ANDROID_INT32_HASH(int8_t)
diff --git a/include/utils/Unicode.h b/include/utils/Unicode.h
index a13f347..666b70f 100644
--- a/include/utils/Unicode.h
+++ b/include/utils/Unicode.h
@@ -60,6 +60,7 @@
* Returns the size actually used for storing the string.
* dst" is not nul-terminated when dst_len is fully used (like strncpy).
*
+ * \code
* Example 1
* "src" == \u3042\u3044 (\xE3\x81\x82\xE3\x81\x84)
* "src_len" == 2
@@ -87,6 +88,7 @@
* Returned value == 6
* "dst" becomes \xE3\x81\x82\xE3\x81\x84
* (note that "dst" is NOT nul-terminated, like strncpy)
+ * \endcode
*/
void utf32_to_utf8(const char32_t* src, size_t src_len, char* dst, size_t dst_len);
diff --git a/include/utils/Vector.h b/include/utils/Vector.h
index ed7b725..6c1931e 100644
--- a/include/utils/Vector.h
+++ b/include/utils/Vector.h
@@ -17,14 +17,14 @@
#ifndef ANDROID_VECTOR_H
#define ANDROID_VECTOR_H
-#include <new>
#include <stdint.h>
#include <sys/types.h>
-#include <cutils/log.h>
+#include <new>
-#include <utils/VectorImpl.h>
+#include <android/log.h>
#include <utils/TypeHelpers.h>
+#include <utils/VectorImpl.h>
// ---------------------------------------------------------------------------
@@ -194,7 +194,7 @@
inline void push_back(const TYPE& item) { insertAt(item, size(), 1); }
inline void push_front(const TYPE& item) { insertAt(item, 0, 1); }
inline iterator erase(iterator pos) {
- ssize_t index = removeItemsAt(pos-array());
+ ssize_t index = removeItemsAt(static_cast<size_t>(pos-array()));
return begin() + index;
}
@@ -207,10 +207,6 @@
virtual void do_move_backward(void* dest, const void* from, size_t num) const;
};
-// Vector<T> can be trivially moved using memcpy() because moving does not
-// require any change to the underlying SharedBuffer contents or reference count.
-template<typename T> struct trait_trivial_move<Vector<T> > { enum { value = true }; };
-
// ---------------------------------------------------------------------------
// No user serviceable parts from here...
// ---------------------------------------------------------------------------
@@ -375,12 +371,12 @@
template<class TYPE> inline
status_t Vector<TYPE>::sort(Vector<TYPE>::compar_t cmp) {
- return VectorImpl::sort((VectorImpl::compar_t)cmp);
+ return VectorImpl::sort(reinterpret_cast<VectorImpl::compar_t>(cmp));
}
template<class TYPE> inline
status_t Vector<TYPE>::sort(Vector<TYPE>::compar_r_t cmp, void* state) {
- return VectorImpl::sort((VectorImpl::compar_r_t)cmp, state);
+ return VectorImpl::sort(reinterpret_cast<VectorImpl::compar_r_t>(cmp), state);
}
// ---------------------------------------------------------------------------
diff --git a/include/ziparchive/zip_archive.h b/include/ziparchive/zip_archive.h
index 7dc60ae..4f68c3b 100644
--- a/include/ziparchive/zip_archive.h
+++ b/include/ziparchive/zip_archive.h
@@ -43,8 +43,7 @@
/*
* entry_name has to be an c-style string with only ASCII characters.
*/
- explicit ZipString(const char* entry_name)
- : name(reinterpret_cast<const uint8_t*>(entry_name)), name_length(strlen(entry_name)) {}
+ explicit ZipString(const char* entry_name);
bool operator==(const ZipString& rhs) const {
return name && (name_length == rhs.name_length) &&
diff --git a/init/property_service.cpp b/init/property_service.cpp
index 9e13733..1e569af 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -376,17 +376,17 @@
}
}
-/*
- * Filter is used to decide which properties to load: NULL loads all keys,
- * "ro.foo.*" is a prefix match, and "ro.foo.bar" is an exact match.
- */
+// Filter is used to decide which properties to load: NULL loads all keys,
+// "ro.foo.*" is a prefix match, and "ro.foo.bar" is an exact match.
static void load_properties_from_file(const char* filename, const char* filter) {
Timer t;
std::string data;
- if (read_file(filename, &data)) {
- data.push_back('\n');
- load_properties(&data[0], filter);
+ if (!read_file(filename, &data)) {
+ PLOG(WARNING) << "Couldn't load properties from " << filename;
+ return;
}
+ data.push_back('\n');
+ load_properties(&data[0], filter);
LOG(VERBOSE) << "(Loading properties from " << filename << " took " << t.duration() << "s.)";
}
diff --git a/libbacktrace/BacktraceLog.h b/libbacktrace/BacktraceLog.h
index 5c39f1c..0a27982 100644
--- a/libbacktrace/BacktraceLog.h
+++ b/libbacktrace/BacktraceLog.h
@@ -19,7 +19,7 @@
#define LOG_TAG "libbacktrace"
-#include <log/log.h>
+#include <android/log.h>
// Macro to log the function name along with the warning message.
#define BACK_LOGW(format, ...) \
diff --git a/libbacktrace/BacktraceMap.cpp b/libbacktrace/BacktraceMap.cpp
index 00c35b1..19ea1e3 100644
--- a/libbacktrace/BacktraceMap.cpp
+++ b/libbacktrace/BacktraceMap.cpp
@@ -20,9 +20,9 @@
#include <sys/types.h>
#include <unistd.h>
+#include <android/log.h>
#include <backtrace/backtrace_constants.h>
#include <backtrace/BacktraceMap.h>
-#include <log/log.h>
#include "thread_utils.h"
diff --git a/libcutils/ashmem-dev.c b/libcutils/ashmem-dev.c
index 09fa09a..db4ed11 100644
--- a/libcutils/ashmem-dev.c
+++ b/libcutils/ashmem-dev.c
@@ -23,6 +23,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <linux/ashmem.h>
#include <pthread.h>
#include <string.h>
#include <sys/ioctl.h>
@@ -30,10 +31,8 @@
#include <sys/types.h>
#include <unistd.h>
-#include <linux/ashmem.h>
-
+#include <android/log.h>
#include <cutils/ashmem.h>
-#include <log/log.h>
#define ASHMEM_DEVICE "/dev/ashmem"
diff --git a/libcutils/debugger.c b/libcutils/debugger.c
index 3407ec3..c6bdd1a 100644
--- a/libcutils/debugger.c
+++ b/libcutils/debugger.c
@@ -14,21 +14,21 @@
* limitations under the License.
*/
-#include <stdbool.h>
+#define LOG_TAG "DEBUG"
+
#include <fcntl.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/types.h>
#include <unistd.h>
+#include <android/log.h>
#include <cutils/debugger.h>
#include <cutils/sockets.h>
-#define LOG_TAG "DEBUG"
-#include <log/log.h>
-
static int send_request(int sock_fd, void* msg_ptr, size_t msg_len) {
int result = 0;
if (TEMP_FAILURE_RETRY(write(sock_fd, msg_ptr, msg_len)) != (ssize_t) msg_len) {
diff --git a/libcutils/dlmalloc_stubs.c b/libcutils/dlmalloc_stubs.c
index 2db473d..86fc880 100644
--- a/libcutils/dlmalloc_stubs.c
+++ b/libcutils/dlmalloc_stubs.c
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "log/log.h"
+#include "android/log.h"
#define UNUSED __attribute__((__unused__))
diff --git a/libcutils/fs.c b/libcutils/fs.c
index 3f14de7..1622ed9 100644
--- a/libcutils/fs.c
+++ b/libcutils/fs.c
@@ -21,18 +21,18 @@
#define _ATFILE_SOURCE 1
#define _GNU_SOURCE 1
-#include <cutils/fs.h>
-#include <cutils/log.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
+#include <dirent.h>
#include <errno.h>
-#include <string.h>
+#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
-#include <dirent.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <android/log.h>
+#include <cutils/fs.h>
#define ALL_PERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
#define BUF_SIZE 64
diff --git a/libcutils/fs_config.c b/libcutils/fs_config.c
index a6eaf11..4e62d74 100644
--- a/libcutils/fs_config.c
+++ b/libcutils/fs_config.c
@@ -33,7 +33,7 @@
#include <sys/stat.h>
#include <sys/types.h>
-#include <log/log.h>
+#include <android/log.h>
#include <private/android_filesystem_config.h>
#include <utils/Compat.h>
@@ -150,6 +150,9 @@
{ 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) |
CAP_MASK_LONG(CAP_NET_RAW), "system/bin/hostapd" },
+ /* 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/bin/hw/wifi_hal_legacy" },
+
{ 00750, AID_ROOT, AID_ROOT, 0, "system/bin/uncrypt" },
{ 00750, AID_ROOT, AID_ROOT, 0, "system/bin/install-recovery.sh" },
{ 00755, AID_ROOT, AID_SHELL, 0, "system/bin/*" },
diff --git a/libcutils/native_handle.c b/libcutils/native_handle.c
index 61fa38e..7f3479d 100644
--- a/libcutils/native_handle.c
+++ b/libcutils/native_handle.c
@@ -16,13 +16,13 @@
#define LOG_TAG "NativeHandle"
-#include <stdint.h>
#include <errno.h>
-#include <string.h>
+#include <stdint.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
-#include <cutils/log.h>
+#include <android/log.h>
#include <cutils/native_handle.h>
static const int kMaxNativeFds = 1024;
diff --git a/libcutils/properties.c b/libcutils/properties.c
index 4e46e02..5aa6371 100644
--- a/libcutils/properties.c
+++ b/libcutils/properties.c
@@ -17,18 +17,18 @@
#define LOG_TAG "properties"
// #define LOG_NDEBUG 0
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
#include <unistd.h>
-#include <cutils/sockets.h>
-#include <errno.h>
-#include <assert.h>
+#include <android/log.h>
#include <cutils/properties.h>
-#include <stdbool.h>
-#include <inttypes.h>
-#include <log/log.h>
+#include <cutils/sockets.h>
int8_t property_get_bool(const char *key, int8_t default_value) {
if (!key) {
diff --git a/libcutils/qtaguid.c b/libcutils/qtaguid.c
index dcd16ef..ae5a503 100644
--- a/libcutils/qtaguid.c
+++ b/libcutils/qtaguid.c
@@ -26,8 +26,8 @@
#include <string.h>
#include <unistd.h>
+#include <android/log.h>
#include <cutils/qtaguid.h>
-#include <log/log.h>
static const char* CTRL_PROCPATH = "/proc/net/xt_qtaguid/ctrl";
static const int CTRL_MAX_INPUT_LEN = 128;
diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c
index cba800f..d436b45 100644
--- a/libcutils/sched_policy.c
+++ b/libcutils/sched_policy.c
@@ -23,8 +23,8 @@
#include <string.h>
#include <unistd.h>
+#include <android/log.h>
#include <cutils/sched_policy.h>
-#include <log/log.h>
#define UNUSED __attribute__((__unused__))
diff --git a/libcutils/socket_network_client_unix.c b/libcutils/socket_network_client_unix.c
index 46818d6..37851b1 100644
--- a/libcutils/socket_network_client_unix.c
+++ b/libcutils/socket_network_client_unix.c
@@ -112,6 +112,7 @@
}
result = toggle_O_NONBLOCK(s);
+ break;
}
freeaddrinfo(addrs);
diff --git a/libcutils/sockets.cpp b/libcutils/sockets.cpp
index d9ab146..bba63ac 100644
--- a/libcutils/sockets.cpp
+++ b/libcutils/sockets.cpp
@@ -45,3 +45,24 @@
}
return -1;
}
+
+int android_get_control_socket(const char* name) {
+ char key[64];
+ snprintf(key, sizeof(key), ANDROID_SOCKET_ENV_PREFIX "%s", name);
+
+ const char* val = getenv(key);
+ if (!val) {
+ return -1;
+ }
+
+ errno = 0;
+ long ret = strtol(val, NULL, 10);
+ if (errno) {
+ return -1;
+ }
+ if (ret < 0 || ret > INT_MAX) {
+ return -1;
+ }
+
+ return static_cast<int>(ret);
+}
diff --git a/libcutils/sockets_unix.cpp b/libcutils/sockets_unix.cpp
index 8747d69..e51a1c7 100644
--- a/libcutils/sockets_unix.cpp
+++ b/libcutils/sockets_unix.cpp
@@ -14,11 +14,10 @@
* limitations under the License.
*/
-#include <cutils/sockets.h>
-
#include <sys/uio.h>
-#include <log/log.h>
+#include <android/log.h>
+#include <cutils/sockets.h>
#if defined(__ANDROID__)
/* For the socket trust (credentials) check */
diff --git a/libcutils/str_parms.c b/libcutils/str_parms.c
index 8dafded..6bb7e58 100644
--- a/libcutils/str_parms.c
+++ b/libcutils/str_parms.c
@@ -24,10 +24,10 @@
#include <stdlib.h>
#include <string.h>
+#include <android/log.h>
#include <cutils/hashmap.h>
#include <cutils/memory.h>
#include <cutils/str_parms.h>
-#include <log/log.h>
#define UNUSED __attribute__((unused))
diff --git a/libcutils/tests/Android.bp b/libcutils/tests/Android.bp
index ada7d5f..06d0e28 100644
--- a/libcutils/tests/Android.bp
+++ b/libcutils/tests/Android.bp
@@ -19,6 +19,7 @@
target: {
android: {
srcs: [
+ "AshmemTest.cpp",
"MemsetTest.cpp",
"PropertiesTest.cpp",
"sched_policy_test.cpp",
diff --git a/libcutils/tests/AshmemTest.cpp b/libcutils/tests/AshmemTest.cpp
new file mode 100644
index 0000000..51c679f
--- /dev/null
+++ b/libcutils/tests/AshmemTest.cpp
@@ -0,0 +1,177 @@
+/*
+ * 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 <sys/mman.h>
+#include <cutils/ashmem.h>
+#include <gtest/gtest.h>
+#include <android-base/unique_fd.h>
+
+using android::base::unique_fd;
+
+void TestCreateRegion(size_t size, unique_fd &fd, int prot) {
+ fd = unique_fd(ashmem_create_region(nullptr, size));
+ ASSERT_TRUE(fd >= 0);
+ ASSERT_TRUE(ashmem_valid(fd));
+ ASSERT_EQ(size, static_cast<size_t>(ashmem_get_size_region(fd)));
+ ASSERT_EQ(0, ashmem_set_prot_region(fd, prot));
+}
+
+void TestMmap(const unique_fd &fd, size_t size, int prot, void **region) {
+ *region = mmap(nullptr, size, prot, MAP_SHARED, fd, 0);
+ ASSERT_NE(MAP_FAILED, *region);
+}
+
+void TestProtDenied(const unique_fd &fd, size_t size, int prot) {
+ EXPECT_EQ(MAP_FAILED, mmap(nullptr, size, prot, MAP_SHARED, fd, 0));
+}
+
+void FillData(uint8_t* data, size_t dataLen) {
+ for (size_t i = 0; i < dataLen; i++) {
+ data[i] = i & 0xFF;
+ }
+}
+
+TEST(AshmemTest, BasicTest) {
+ constexpr size_t size = PAGE_SIZE;
+ uint8_t data[size];
+ FillData(data, size);
+
+ unique_fd fd;
+ ASSERT_NO_FATAL_FAILURE(TestCreateRegion(size, fd, PROT_READ | PROT_WRITE));
+
+ void *region1;
+ ASSERT_NO_FATAL_FAILURE(TestMmap(fd, size, PROT_READ | PROT_WRITE, ®ion1));
+
+ memcpy(region1, &data, size);
+ ASSERT_EQ(0, memcmp(region1, &data, size));
+
+ EXPECT_EQ(0, munmap(region1, size));
+
+ void *region2;
+ ASSERT_NO_FATAL_FAILURE(TestMmap(fd, size, PROT_READ, ®ion2));
+ ASSERT_EQ(0, memcmp(region2, &data, size));
+ EXPECT_EQ(0, munmap(region2, size));
+}
+
+TEST(AshmemTest, ForkTest) {
+ constexpr size_t size = PAGE_SIZE;
+ uint8_t data[size];
+ FillData(data, size);
+
+ unique_fd fd;
+ ASSERT_NO_FATAL_FAILURE(TestCreateRegion(size, fd, PROT_READ | PROT_WRITE));
+
+ void *region1;
+ ASSERT_NO_FATAL_FAILURE(TestMmap(fd, size, PROT_READ | PROT_WRITE, ®ion1));
+
+ memcpy(region1, &data, size);
+ ASSERT_EQ(0, memcmp(region1, &data, size));
+ EXPECT_EQ(0, munmap(region1, size));
+
+ ASSERT_EXIT({
+ void *region2 = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (region2 == MAP_FAILED) {
+ _exit(1);
+ }
+ if (memcmp(region2, &data, size) != 0) {
+ _exit(2);
+ }
+ memset(region2, 0, size);
+ munmap(region2, size);
+ _exit(0);
+ }, ::testing::ExitedWithCode(0),"");
+
+ memset(&data, 0, size);
+ void *region2;
+ ASSERT_NO_FATAL_FAILURE(TestMmap(fd, size, PROT_READ | PROT_WRITE, ®ion2));
+ ASSERT_EQ(0, memcmp(region2, &data, size));
+ EXPECT_EQ(0, munmap(region2, size));
+}
+
+TEST(AshmemTest, ProtTest) {
+ unique_fd fd;
+ constexpr size_t size = PAGE_SIZE;
+ void *region;
+
+ ASSERT_NO_FATAL_FAILURE(TestCreateRegion(size, fd, PROT_READ));
+ TestProtDenied(fd, size, PROT_WRITE);
+ ASSERT_NO_FATAL_FAILURE(TestMmap(fd, size, PROT_READ, ®ion));
+ EXPECT_EQ(0, munmap(region, size));
+
+ ASSERT_NO_FATAL_FAILURE(TestCreateRegion(size, fd, PROT_WRITE));
+ TestProtDenied(fd, size, PROT_READ);
+ ASSERT_NO_FATAL_FAILURE(TestMmap(fd, size, PROT_WRITE, ®ion));
+ EXPECT_EQ(0, munmap(region, size));
+}
+
+TEST(AshmemTest, ForkProtTest) {
+ unique_fd fd;
+ constexpr size_t size = PAGE_SIZE;
+
+ int protFlags[] = { PROT_READ, PROT_WRITE };
+ for (int i = 0; i < 2; i++) {
+ ASSERT_NO_FATAL_FAILURE(TestCreateRegion(size, fd, PROT_READ | PROT_WRITE));
+ ASSERT_EXIT({
+ if (ashmem_set_prot_region(fd, protFlags[i]) >= 0) {
+ _exit(0);
+ } else {
+ _exit(1);
+ }
+ }, ::testing::ExitedWithCode(0), "");
+ ASSERT_NO_FATAL_FAILURE(TestProtDenied(fd, size, protFlags[1-i]));
+ }
+}
+
+TEST(AshmemTest, ForkMultiRegionTest) {
+ constexpr size_t size = PAGE_SIZE;
+ uint8_t data[size];
+ FillData(data, size);
+
+ constexpr int nRegions = 16;
+ unique_fd fd[nRegions];
+ for (int i = 0; i < nRegions; i++) {
+ ASSERT_NO_FATAL_FAILURE(TestCreateRegion(size, fd[i], PROT_READ | PROT_WRITE));
+ void *region;
+ ASSERT_NO_FATAL_FAILURE(TestMmap(fd[i], size, PROT_READ | PROT_WRITE, ®ion));
+ memcpy(region, &data, size);
+ ASSERT_EQ(0, memcmp(region, &data, size));
+ EXPECT_EQ(0, munmap(region, size));
+ }
+
+ ASSERT_EXIT({
+ for (int i = 0; i < nRegions; i++) {
+ void *region = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd[i], 0);
+ if (region == MAP_FAILED) {
+ _exit(1);
+ }
+ if (memcmp(region, &data, size) != 0) {
+ munmap(region, size);
+ _exit(2);
+ }
+ memset(region, 0, size);
+ munmap(region, size);
+ }
+ _exit(0);
+ }, ::testing::ExitedWithCode(0), "");
+
+ memset(&data, 0, size);
+ for (int i = 0; i < nRegions; i++) {
+ void *region;
+ ASSERT_NO_FATAL_FAILURE(TestMmap(fd[i], size, PROT_READ | PROT_WRITE, ®ion));
+ ASSERT_EQ(0, memcmp(region, &data, size));
+ EXPECT_EQ(0, munmap(region, size));
+ }
+}
diff --git a/libcutils/tests/PropertiesTest.cpp b/libcutils/tests/PropertiesTest.cpp
index f66590b..f0cdffd 100644
--- a/libcutils/tests/PropertiesTest.cpp
+++ b/libcutils/tests/PropertiesTest.cpp
@@ -15,16 +15,17 @@
*/
#define LOG_TAG "Properties_test"
-#include <cutils/log.h>
-#include <gtest/gtest.h>
-#include <cutils/properties.h>
#include <limits.h>
-#include <string>
-#include <sstream>
-#include <iostream>
+#include <iostream>
+#include <sstream>
+#include <string>
+
+#include <android/log.h>
#include <android-base/macros.h>
+#include <cutils/properties.h>
+#include <gtest/gtest.h>
namespace android {
diff --git a/libcutils/trace-dev.c b/libcutils/trace-dev.c
index 778e4f0..dcd9582 100644
--- a/libcutils/trace-dev.c
+++ b/libcutils/trace-dev.c
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "cutils-trace"
+
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@@ -23,13 +25,12 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
+
+#include <android/log.h>
#include <cutils/compiler.h>
#include <cutils/properties.h>
#include <cutils/trace.h>
-#define LOG_TAG "cutils-trace"
-#include <log/log.h>
-
/**
* Maximum size of a message that can be logged to the trace buffer.
* Note this message includes a tag, the pid, and the string given as the name.
@@ -196,6 +197,12 @@
write(atrace_marker_fd, buf, len);
}
+void atrace_end_body()
+{
+ char c = 'E';
+ write(atrace_marker_fd, &c, 1);
+}
+
#define WRITE_MSG(format_begin, format_end, pid, name, value) { \
char buf[ATRACE_MESSAGE_LENGTH]; \
int len = snprintf(buf, sizeof(buf), format_begin "%s" format_end, pid, \
diff --git a/libcutils/trace-host.c b/libcutils/trace-host.c
index 6478e3e..05842cd 100644
--- a/libcutils/trace-host.c
+++ b/libcutils/trace-host.c
@@ -29,6 +29,7 @@
void atrace_update_tags() { }
void atrace_setup() { }
void atrace_begin_body(const char* name __unused) { }
+void atrace_end_body() { }
void atrace_async_begin_body(const char* name __unused, int32_t cookie __unused) { }
void atrace_async_end_body(const char* name __unused, int32_t cookie __unused) { }
void atrace_int_body(const char* name __unused, int32_t value __unused) { }
diff --git a/libdiskconfig/config_mbr.c b/libdiskconfig/config_mbr.c
index 7b6ca1c..1d3cd20 100644
--- a/libdiskconfig/config_mbr.c
+++ b/libdiskconfig/config_mbr.c
@@ -16,16 +16,15 @@
*/
#define LOG_TAG "config_mbr"
+
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <stdio.h>
-#include <cutils/log.h>
-
+#include <android/log.h>
#include <diskconfig/diskconfig.h>
-
/* start and len are in LBA units */
static void
cfg_pentry(struct pc_partition *pentry, uint8_t status, uint8_t type,
diff --git a/libdiskconfig/diskconfig.c b/libdiskconfig/diskconfig.c
index 1167d4b..2d59ad9 100644
--- a/libdiskconfig/diskconfig.c
+++ b/libdiskconfig/diskconfig.c
@@ -20,21 +20,19 @@
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
+#include <linux/fs.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
+#include <unistd.h>
-#include <linux/fs.h>
-
+#include <android/log.h>
#include <cutils/config_utils.h>
-#include <log/log.h>
#include <diskconfig/diskconfig.h>
-
static int
parse_len(const char *str, uint64_t *plen)
{
diff --git a/libdiskconfig/diskutils.c b/libdiskconfig/diskutils.c
index 5d0ee62..3a27601 100644
--- a/libdiskconfig/diskutils.c
+++ b/libdiskconfig/diskutils.c
@@ -23,10 +23,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <sys/stat.h>
+#include <unistd.h>
-#include <log/log.h>
+#include <android/log.h>
#include <diskconfig/diskconfig.h>
diff --git a/libdiskconfig/dump_diskconfig.c b/libdiskconfig/dump_diskconfig.c
index 75256f6..c94e7f4 100644
--- a/libdiskconfig/dump_diskconfig.c
+++ b/libdiskconfig/dump_diskconfig.c
@@ -16,9 +16,10 @@
*/
#define LOG_TAG "dump_diskconfig"
+
#include <stdio.h>
-#include <cutils/log.h>
+#include <android/log.h>
#include "diskconfig.h"
diff --git a/libdiskconfig/write_lst.c b/libdiskconfig/write_lst.c
index 90b1c82..21d4a31 100644
--- a/libdiskconfig/write_lst.c
+++ b/libdiskconfig/write_lst.c
@@ -16,14 +16,14 @@
*/
#define LOG_TAG "write_lst"
-#include <sys/types.h>
+
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/types.h>
#include <unistd.h>
-#include <cutils/log.h>
-
+#include <android/log.h>
#include <diskconfig/diskconfig.h>
struct write_list *
diff --git a/libion/ion.c b/libion/ion.c
index d1984bd..424776a 100644
--- a/libion/ion.c
+++ b/libion/ion.c
@@ -19,16 +19,16 @@
*/
#define LOG_TAG "ion"
-#include <cutils/log.h>
#include <errno.h>
#include <fcntl.h>
+#include <linux/ion.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/types.h>
-#include <linux/ion.h>
+#include <android/log.h>
#include <ion/ion.h>
int ion_open()
diff --git a/liblog/Android.bp b/liblog/Android.bp
index e32f73c..c59dde9 100644
--- a/liblog/Android.bp
+++ b/liblog/Android.bp
@@ -84,10 +84,15 @@
// 's/^\([0-9]*\)[ \t]*liblog[ \t].*/-DLIBLOG_LOG_TAG=\1/p' \
// $(LOCAL_PATH)/event.logtags)
// so make sure we do not regret hard-coding it as follows:
- "-DLIBLOG_LOG_TAG=1005",
+ "-DLIBLOG_LOG_TAG=1006",
"-DSNET_EVENT_LOG_TAG=1397638484",
],
logtags: ["event.logtags"],
compile_multilib: "both",
- stl: "none",
+}
+
+ndk_library {
+ name: "liblog.ndk",
+ symbol_file: "liblog.map.txt",
+ first_version: "9",
}
diff --git a/liblog/README b/liblog/README
index df1e68c..eefa80f 100644
--- a/liblog/README
+++ b/liblog/README
@@ -6,7 +6,7 @@
liblog - Android NDK logger interfaces
SYNOPSIS
- #include <log/log.h>
+ #include <android/log.h>
ALOG(android_priority, tag, format, ...)
IF_ALOG(android_priority, tag)
diff --git a/liblog/event.logtags b/liblog/event.logtags
index 72ecab1..301e885 100644
--- a/liblog/event.logtags
+++ b/liblog/event.logtags
@@ -33,4 +33,4 @@
#
# TODO: generate ".java" and ".h" files with integer constants from this file.
-1005 liblog (dropped|1)
+1006 liblog (dropped|1)
diff --git a/liblog/event_tag_map.c b/liblog/event_tag_map.c
index 345f0d3..6705fb2 100644
--- a/liblog/event_tag_map.c
+++ b/liblog/event_tag_map.c
@@ -15,14 +15,16 @@
*/
#include <assert.h>
+#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
+#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
+#include <android/log.h>
#include <log/event_tag_map.h>
-#include <log/log.h>
#include "log_portability.h"
@@ -32,8 +34,9 @@
* Single entry.
*/
typedef struct EventTag {
- unsigned int tagIndex;
- const char* tagStr;
+ uint32_t tagIndex;
+ char* tagStr;
+ size_t tagLen;
} EventTag;
/*
@@ -56,7 +59,6 @@
static int scanTagLine(char** pData, EventTag* tag, int lineNum);
static int sortTags(EventTagMap* map);
-
/*
* Open the map file and allocate a structure to manage it.
*
@@ -67,47 +69,57 @@
{
EventTagMap* newTagMap;
off_t end;
- int fd = -1;
+ int save_errno;
- newTagMap = calloc(1, sizeof(EventTagMap));
- if (newTagMap == NULL)
- return NULL;
-
- fd = open(fileName, O_RDONLY | O_CLOEXEC);
+ int fd = open(fileName, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
+ save_errno = errno;
fprintf(stderr, "%s: unable to open map '%s': %s\n",
- OUT_TAG, fileName, strerror(errno));
- goto fail;
+ OUT_TAG, fileName, strerror(save_errno));
+ goto fail_errno;
}
end = lseek(fd, 0L, SEEK_END);
+ save_errno = errno;
(void) lseek(fd, 0L, SEEK_SET);
if (end < 0) {
- fprintf(stderr, "%s: unable to seek map '%s'\n", OUT_TAG, fileName);
- goto fail;
+ fprintf(stderr, "%s: unable to seek map '%s' %s\n",
+ OUT_TAG, fileName, strerror(save_errno));
+ goto fail_close;
}
- newTagMap->mapAddr = mmap(NULL, end, PROT_READ | PROT_WRITE, MAP_PRIVATE,
- fd, 0);
- if (newTagMap->mapAddr == MAP_FAILED) {
- fprintf(stderr, "%s: mmap(%s) failed: %s\n",
- OUT_TAG, fileName, strerror(errno));
- goto fail;
+ newTagMap = (EventTagMap*)calloc(1, sizeof(EventTagMap));
+ if (newTagMap == NULL) {
+ save_errno = errno;
+ goto fail_close;
}
+
+ newTagMap->mapAddr = mmap(NULL, end, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
+ save_errno = errno;
+ close(fd);
+ fd = -1;
+ if ((newTagMap->mapAddr == MAP_FAILED) || (newTagMap->mapAddr == NULL)) {
+ fprintf(stderr, "%s: mmap(%s) failed: %s\n",
+ OUT_TAG, fileName, strerror(save_errno));
+ goto fail_free;
+ }
+
newTagMap->mapLen = end;
- if (processFile(newTagMap) != 0)
- goto fail;
-
- if (fd >= 0)
- close(fd);
+ if (processFile(newTagMap) != 0) goto fail_unmap;
return newTagMap;
+fail_unmap:
+ munmap(newTagMap->mapAddr, newTagMap->mapLen);
+ save_errno = EINVAL;
+fail_free:
+ free(newTagMap);
+fail_close:
+ close(fd);
+fail_errno:
+ errno = save_errno;
fail:
- android_closeEventTagMap(newTagMap);
- if (fd >= 0)
- close(fd);
return NULL;
}
@@ -116,10 +128,10 @@
*/
LIBLOG_ABI_PUBLIC void android_closeEventTagMap(EventTagMap* map)
{
- if (map == NULL)
- return;
+ if (map == NULL) return;
munmap(map->mapAddr, map->mapLen);
+ free(map->tagArray);
free(map);
}
@@ -128,19 +140,17 @@
*
* The entries are sorted by tag number, so we can do a binary search.
*/
-LIBLOG_ABI_PUBLIC const char* android_lookupEventTag(const EventTagMap* map,
- int tag)
+LIBLOG_ABI_PUBLIC const char* android_lookupEventTag_len(const EventTagMap* map,
+ size_t *len,
+ unsigned int tag)
{
- int hi, lo, mid;
-
- lo = 0;
- hi = map->numTags-1;
+ int lo = 0;
+ int hi = map->numTags - 1;
while (lo <= hi) {
- int cmp;
+ int mid = (lo + hi) / 2;
+ int cmp = map->tagArray[mid].tagIndex - tag;
- mid = (lo+hi)/2;
- cmp = map->tagArray[mid].tagIndex - tag;
if (cmp < 0) {
/* tag is bigger */
lo = mid + 1;
@@ -149,69 +159,57 @@
hi = mid - 1;
} else {
/* found */
+ if (len) *len = map->tagArray[mid].tagLen;
+ /*
+ * b/31456426 to check if gTest can detect copy-on-write issue
+ * add the following line to break us:
+ * map->tagArray[mid].tagStr[map->tagArray[mid].tagLen] = '\0';
+ * or explicitly use deprecated android_lookupEventTag().
+ */
return map->tagArray[mid].tagStr;
}
}
+ errno = ENOENT;
+ if (len) *len = 0;
return NULL;
}
-
-
-/*
- * Determine whether "c" is a whitespace char.
- */
-static inline int isCharWhitespace(char c)
+LIBLOG_ABI_PUBLIC const char* android_lookupEventTag(const EventTagMap* map,
+ unsigned int tag)
{
- return (c == ' ' || c == '\n' || c == '\r' || c == '\t');
-}
+ size_t len;
+ const char* tagStr = android_lookupEventTag_len(map, &len, tag);
+ char* cp;
-/*
- * Determine whether "c" is a valid tag char.
- */
-static inline int isCharValidTag(char c)
-{
- return ((c >= 'A' && c <= 'Z') ||
- (c >= 'a' && c <= 'z') ||
- (c >= '0' && c <= '9') ||
- (c == '_'));
+ if (!tagStr) return tagStr;
+ cp = (char*)tagStr;
+ cp += len;
+ if (*cp) *cp = '\0'; /* Trigger copy on write :-( */
+ return tagStr;
}
/*
- * Determine whether "c" is a valid decimal digit.
- */
-static inline int isCharDigit(char c)
-{
- return (c >= '0' && c <= '9');
-}
-
-
-/*
* Crunch through the file, parsing the contents and creating a tag index.
*/
static int processFile(EventTagMap* map)
{
/* get a tag count */
map->numTags = countMapLines(map);
- if (map->numTags < 0)
- return -1;
-
- //printf("+++ found %d tags\n", map->numTags);
-
- /* allocate storage for the tag index array */
- map->tagArray = calloc(1, sizeof(EventTag) * map->numTags);
- if (map->tagArray == NULL)
- return -1;
-
- /* parse the file, null-terminating tag strings */
- if (parseMapLines(map) != 0) {
- fprintf(stderr, "%s: file parse failed\n", OUT_TAG);
+ if (map->numTags < 0) {
+ errno = ENOENT;
return -1;
}
+ /* allocate storage for the tag index array */
+ map->tagArray = (EventTag*)calloc(1, sizeof(EventTag) * map->numTags);
+ if (map->tagArray == NULL) return -1;
+
+ /* parse the file, null-terminating tag strings */
+ if (parseMapLines(map) != 0) return -1;
+
/* sort the tags and check for duplicates */
- if (sortTags(map) != 0)
- return -1;
+ if (sortTags(map) != 0) return -1;
return 0;
}
@@ -228,24 +226,20 @@
*/
static int countMapLines(const EventTagMap* map)
{
- int numTags, unknown;
- const char* cp;
- const char* endp;
+ const char* cp = (const char*) map->mapAddr;
+ const char* endp = cp + map->mapLen;
+ int numTags = 0;
+ int unknown = 1;
- cp = (const char*) map->mapAddr;
- endp = cp + map->mapLen;
-
- numTags = 0;
- unknown = 1;
while (cp < endp) {
if (*cp == '\n') {
unknown = 1;
} else if (unknown) {
- if (isCharDigit(*cp)) {
+ if (isdigit(*cp)) {
/* looks like a tag to me */
numTags++;
unknown = 0;
- } else if (isCharWhitespace(*cp)) {
+ } else if (isspace(*cp)) {
/* might be leading whitespace before tag num, keep going */
} else {
/* assume comment; second pass can complain in detail */
@@ -266,15 +260,13 @@
static int parseMapLines(EventTagMap* map)
{
int tagNum, lineStart, lineNum;
- char* cp;
- char* endp;
-
- cp = (char*) map->mapAddr;
- endp = cp + map->mapLen;
+ char* cp = (char*) map->mapAddr;
+ char* endp = cp + map->mapLen;
/* insist on EOL at EOF; simplifies parsing and null-termination */
- if (*(endp-1) != '\n') {
+ if (*(endp - 1) != '\n') {
fprintf(stderr, "%s: map file missing EOL on last line\n", OUT_TAG);
+ errno = EINVAL;
return -1;
}
@@ -282,7 +274,6 @@
lineStart = 1;
lineNum = 1;
while (cp < endp) {
- //printf("{%02x}", *cp); fflush(stdout);
if (*cp == '\n') {
lineStart = 1;
lineNum++;
@@ -290,24 +281,27 @@
if (*cp == '#') {
/* comment; just scan to end */
lineStart = 0;
- } else if (isCharDigit(*cp)) {
+ } else if (isdigit(*cp)) {
/* looks like a tag; scan it out */
if (tagNum >= map->numTags) {
fprintf(stderr,
"%s: more tags than expected (%d)\n", OUT_TAG, tagNum);
+ errno = EMFILE;
return -1;
}
- if (scanTagLine(&cp, &map->tagArray[tagNum], lineNum) != 0)
+ if (scanTagLine(&cp, &map->tagArray[tagNum], lineNum) != 0) {
return -1;
+ }
tagNum++;
lineNum++; // we eat the '\n'
/* leave lineStart==1 */
- } else if (isCharWhitespace(*cp)) {
+ } else if (isspace(*cp)) {
/* looks like leading whitespace; keep scanning */
} else {
fprintf(stderr,
"%s: unexpected chars (0x%02x) in tag number on line %d\n",
OUT_TAG, *cp, lineNum);
+ errno = EINVAL;
return -1;
}
} else {
@@ -319,6 +313,7 @@
if (tagNum != map->numTags) {
fprintf(stderr, "%s: parsed %d tags, expected %d\n",
OUT_TAG, tagNum, map->numTags);
+ errno = EINVAL;
return -1;
}
@@ -336,58 +331,51 @@
*/
static int scanTagLine(char** pData, EventTag* tag, int lineNum)
{
- char* cp = *pData;
- char* startp;
- char* endp;
- unsigned long val;
+ char* cp;
- startp = cp;
- while (isCharDigit(*++cp))
- ;
- *cp = '\0';
-
- val = strtoul(startp, &endp, 10);
- assert(endp == cp);
- if (endp != cp)
- fprintf(stderr, "ARRRRGH\n");
+ unsigned long val = strtoul(*pData, &cp, 10);
+ if (cp == *pData) {
+ fprintf(stderr, "%s: malformed tag number on line %d\n", OUT_TAG, lineNum);
+ errno = EINVAL;
+ return -1;
+ }
tag->tagIndex = val;
+ if (tag->tagIndex != val) {
+ fprintf(stderr, "%s: tag number too large on line %d\n", OUT_TAG, lineNum);
+ errno = ERANGE;
+ return -1;
+ }
- while (*++cp != '\n' && isCharWhitespace(*cp))
- ;
+ while ((*++cp != '\n') && isspace(*cp)) {
+ }
if (*cp == '\n') {
- fprintf(stderr,
- "%s: missing tag string on line %d\n", OUT_TAG, lineNum);
+ fprintf(stderr, "%s: missing tag string on line %d\n", OUT_TAG, lineNum);
+ errno = EINVAL;
return -1;
}
tag->tagStr = cp;
- while (isCharValidTag(*++cp))
- ;
+ /* Determine whether "c" is a valid tag char. */
+ while (isalnum(*++cp) || (*cp == '_')) {
+ }
+ tag->tagLen = cp - tag->tagStr;
- if (*cp == '\n') {
- /* null terminate and return */
- *cp = '\0';
- } else if (isCharWhitespace(*cp)) {
- /* CRLF or trailin spaces; zap this char, then scan for the '\n' */
- *cp = '\0';
-
+ if (isspace(*cp)) {
/* just ignore the rest of the line till \n
TODO: read the tag description that follows the tag name
*/
- while (*++cp != '\n') {
- }
+ while (*cp != '\n') ++cp;
} else {
- fprintf(stderr,
- "%s: invalid tag chars on line %d\n", OUT_TAG, lineNum);
+ fprintf(stderr, "%s: invalid tag chars on line %d\n", OUT_TAG, lineNum);
+ errno = EINVAL;
return -1;
}
*pData = cp;
- //printf("+++ Line %d: got %d '%s'\n", lineNum, tag->tagIndex, tag->tagStr);
return 0;
}
@@ -415,11 +403,15 @@
qsort(map->tagArray, map->numTags, sizeof(EventTag), compareEventTags);
for (i = 1; i < map->numTags; i++) {
- if (map->tagArray[i].tagIndex == map->tagArray[i-1].tagIndex) {
- fprintf(stderr, "%s: duplicate tag entries (%d:%s and %d:%s)\n",
+ if (map->tagArray[i].tagIndex == map->tagArray[i - 1].tagIndex) {
+ fprintf(stderr,
+ "%s: duplicate tag entries (%" PRIu32 ":%.*s and %" PRIu32 ":%.*s)\n",
OUT_TAG,
- map->tagArray[i].tagIndex, map->tagArray[i].tagStr,
- map->tagArray[i-1].tagIndex, map->tagArray[i-1].tagStr);
+ map->tagArray[i].tagIndex, (int)map->tagArray[i].tagLen,
+ map->tagArray[i].tagStr,
+ map->tagArray[i - 1].tagIndex, (int)map->tagArray[i - 1].tagLen,
+ map->tagArray[i - 1].tagStr);
+ errno = EMLINK;
return -1;
}
}
diff --git a/liblog/fake_log_device.c b/liblog/fake_log_device.c
index cc67f3e..7bd1f83 100644
--- a/liblog/fake_log_device.c
+++ b/liblog/fake_log_device.c
@@ -28,7 +28,7 @@
#include <stdlib.h>
#include <string.h>
-#include <log/logd.h>
+#include <android/log.h>
#include "fake_log_device.h"
#include "log_portability.h"
@@ -718,3 +718,12 @@
int logLevel = def;
return logLevel >= 0 && prio >= logLevel;
}
+
+LIBLOG_ABI_PUBLIC int __android_log_is_loggable_len(int prio,
+ const char *tag __unused,
+ size_t len __unused,
+ int def)
+{
+ int logLevel = def;
+ return logLevel >= 0 && prio >= logLevel;
+}
diff --git a/liblog/fake_writer.c b/liblog/fake_writer.c
index dab8bc5..47935e3 100644
--- a/liblog/fake_writer.c
+++ b/liblog/fake_writer.c
@@ -18,7 +18,7 @@
#include <fcntl.h>
#include <unistd.h>
-#include <log/log.h>
+#include <android/log.h>
#include "config_write.h"
#include "fake_log_device.h"
diff --git a/liblog/liblog.map.txt b/liblog/liblog.map.txt
new file mode 100644
index 0000000..5f19cc1
--- /dev/null
+++ b/liblog/liblog.map.txt
@@ -0,0 +1,14 @@
+LIBLOG {
+ global:
+ __android_log_assert;
+ __android_log_btwrite;
+ __android_log_buf_print; # introduced-arm=21 introduced-arm64=21 introduced-mips=9 introduced-mips64=21 introduced-x86=9 introduced-x86_64=21
+ __android_log_buf_write; # introduced-arm=21 introduced-arm64=21 introduced-mips=9 introduced-mips64=21 introduced-x86=9 introduced-x86_64=21
+ __android_log_bwrite;
+ __android_log_dev_available;
+ __android_log_print;
+ __android_log_vprint;
+ __android_log_write;
+ local:
+ *;
+};
diff --git a/liblog/log_event_list.c b/liblog/log_event_list.c
index 64d9024..a4244cd 100644
--- a/liblog/log_event_list.c
+++ b/liblog/log_event_list.c
@@ -22,7 +22,7 @@
#include <stdlib.h>
#include <string.h>
-#include <log/log.h>
+#include <android/log.h>
#include <log/logger.h>
#include "log_portability.h"
diff --git a/liblog/log_event_write.c b/liblog/log_event_write.c
index b9827a1..8c8a9a1 100644
--- a/liblog/log_event_write.c
+++ b/liblog/log_event_write.c
@@ -16,7 +16,7 @@
#include <errno.h>
-#include <log/log.h>
+#include <android/log.h>
#include "log_portability.h"
diff --git a/liblog/log_is_loggable.c b/liblog/log_is_loggable.c
index bd8d5af..4af8507 100644
--- a/liblog/log_is_loggable.c
+++ b/liblog/log_is_loggable.c
@@ -85,13 +85,13 @@
}
}
-static int __android_log_level(const char *tag, 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.";
static const size_t base_offset = 8; /* skip "persist." */
/* calculate the size of our key temporary buffer */
- const size_t taglen = (tag && *tag) ? strlen(tag) : 0;
+ 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;
@@ -147,7 +147,11 @@
if (!not_locked) {
if (!last_tag[0]
|| (last_tag[0] != tag[0])
- || strncmp(last_tag + 1, tag + 1, sizeof(last_tag) - 1)) {
+ || strncmp(last_tag + 1, tag + 1,
+ (len < sizeof(last_tag)) ?
+ (len - 1) :
+ (sizeof(last_tag) - 1))
+ || ((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;
@@ -157,10 +161,16 @@
local_change_detected = 1;
}
if (!last_tag[0]) {
- strncpy(last_tag, tag, sizeof(last_tag));
+ if (len < sizeof(last_tag)) {
+ strncpy(last_tag, tag, len);
+ last_tag[len] = '\0';
+ } else {
+ strncpy(last_tag, tag, sizeof(last_tag));
+ }
}
}
- strcpy(key + sizeof(log_namespace) - 1, tag);
+ strncpy(key + sizeof(log_namespace) - 1, tag, len);
+ key[sizeof(log_namespace) - 1 + len] = '\0';
kp = key;
for (i = 0; i < (sizeof(tag_cache) / sizeof(tag_cache[0])); ++i) {
@@ -246,10 +256,21 @@
return default_prio;
}
-LIBLOG_ABI_PUBLIC int __android_log_is_loggable(int prio, const char *tag,
+LIBLOG_ABI_PUBLIC int __android_log_is_loggable_len(int prio,
+ const char *tag, size_t len,
+ int default_prio)
+{
+ int logLevel = __android_log_level(tag, len, default_prio);
+ return logLevel >= 0 && prio >= logLevel;
+}
+
+LIBLOG_ABI_PUBLIC int __android_log_is_loggable(int prio,
+ const char *tag,
int default_prio)
{
- int logLevel = __android_log_level(tag, default_prio);
+ int logLevel = __android_log_level(tag,
+ (tag && *tag) ? strlen(tag) : 0,
+ default_prio);
return logLevel >= 0 && prio >= logLevel;
}
diff --git a/liblog/log_time.cpp b/liblog/log_time.cpp
index d2bf181..c8bd27d 100644
--- a/liblog/log_time.cpp
+++ b/liblog/log_time.cpp
@@ -19,7 +19,7 @@
#include <stdio.h>
#include <string.h>
-#include <log/log_read.h>
+#include <log/logger.h>
#include "log_portability.h"
diff --git a/liblog/logd_reader.c b/liblog/logd_reader.c
index b894349..563b5c7 100644
--- a/liblog/logd_reader.c
+++ b/liblog/logd_reader.c
@@ -31,10 +31,9 @@
#include <time.h>
#include <unistd.h>
+#include <android/log.h>
#include <cutils/sockets.h>
-#include <log/logd.h>
#include <log/logger.h>
-#include <log/log_read.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 ed82902..e8e392d 100644
--- a/liblog/logd_writer.c
+++ b/liblog/logd_writer.c
@@ -31,10 +31,9 @@
#include <time.h>
#include <unistd.h>
+#include <android/log.h>
#include <cutils/sockets.h>
-#include <log/logd.h>
#include <log/logger.h>
-#include <log/log_read.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
@@ -182,9 +181,9 @@
}
}
snapshot = atomic_exchange_explicit(&dropped, 0, memory_order_relaxed);
- if (snapshot && __android_log_is_loggable(ANDROID_LOG_INFO,
- "liblog",
- ANDROID_LOG_VERBOSE)) {
+ if (snapshot && __android_log_is_loggable_len(ANDROID_LOG_INFO,
+ "liblog", strlen("liblog"),
+ ANDROID_LOG_VERBOSE)) {
android_log_event_int_t buffer;
header.id = LOG_ID_EVENTS;
diff --git a/liblog/logger.h b/liblog/logger.h
index 2a4cfcb..8fb2b4d 100644
--- a/liblog/logger.h
+++ b/liblog/logger.h
@@ -20,9 +20,8 @@
#include <stdbool.h>
#include <log/uio.h>
+#include <android/log.h>
#include <cutils/list.h>
-#include <log/log.h>
-#include <log/log_read.h>
#include <log/logger.h>
#include "log_portability.h"
diff --git a/liblog/logger_name.c b/liblog/logger_name.c
index b7ccac5..12e263a 100644
--- a/liblog/logger_name.c
+++ b/liblog/logger_name.c
@@ -16,7 +16,7 @@
#include <string.h>
-#include <log/log.h>
+#include <android/log.h>
#include <log/logger.h>
#include "log_portability.h"
diff --git a/liblog/logger_read.c b/liblog/logger_read.c
index 0d55453..d979e22 100644
--- a/liblog/logger_read.c
+++ b/liblog/logger_read.c
@@ -23,8 +23,8 @@
#include <string.h>
#include <unistd.h>
+#include <android/log.h>
#include <cutils/list.h>
-#include <log/log.h>
#include <log/logger.h>
#include <private/android_filesystem_config.h>
diff --git a/liblog/logger_write.c b/liblog/logger_write.c
index c7b5a84..1e56b27 100644
--- a/liblog/logger_write.c
+++ b/liblog/logger_write.c
@@ -24,10 +24,9 @@
#include <android/set_abort_message.h>
#endif
+#include <android/log.h>
#include <log/event_tag_map.h>
-#include <log/logd.h>
#include <log/logger.h>
-#include <log/log_read.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
@@ -132,12 +131,20 @@
}
return kLogNotAvailable;
}
+
+#if defined(__BIONIC__)
+static atomic_uintptr_t tagMap;
+#endif
+
/*
* Release any logger resources. A new log write will immediately re-acquire.
*/
LIBLOG_ABI_PUBLIC void __android_log_close()
{
struct android_log_transport_write *transport;
+#if defined(__BIONIC__)
+ EventTagMap *m;
+#endif
__android_log_lock();
@@ -165,7 +172,28 @@
}
}
+#if defined(__BIONIC__)
+ /*
+ * Additional risk here somewhat mitigated by immediately unlock flushing
+ * the processor cache. The multi-threaded race that we choose to accept,
+ * to minimize locking, is an atomic_load in a writer picking up a value
+ * just prior to entering this routine. There will be an use after free.
+ *
+ * Again, anyone calling this is doing so to release the logging resources
+ * is most probably going to quiesce then shut down; or to restart after
+ * a fork so the risk should be non-existent. For this reason we
+ * choose a mitigation stance for efficiency instead of incuring the cost
+ * of a lock for every log write.
+ */
+ m = (EventTagMap *)atomic_exchange(&tagMap, (uintptr_t)0);
+#endif
+
__android_log_unlock();
+
+#if defined(__BIONIC__)
+ android_closeEventTagMap(m);
+#endif
+
}
/* log_init_lock assumed */
@@ -250,8 +278,8 @@
return -EPERM;
}
} else if (log_id == LOG_ID_EVENTS) {
- static atomic_uintptr_t map;
const char *tag;
+ size_t len;
EventTagMap *m, *f;
if (vec[0].iov_len < 4) {
@@ -259,12 +287,13 @@
}
tag = NULL;
+ len = 0;
f = NULL;
- m = (EventTagMap *)atomic_load(&map);
+ m = (EventTagMap *)atomic_load(&tagMap);
if (!m) {
ret = __android_log_trylock();
- m = (EventTagMap *)atomic_load(&map); /* trylock flush cache */
+ m = (EventTagMap *)atomic_load(&tagMap); /* trylock flush cache */
if (!m) {
m = android_openEventTagMap(EVENT_TAG_MAP_FILE);
if (ret) { /* trylock failed, use local copy, mark for close */
@@ -273,7 +302,7 @@
if (!m) { /* One chance to open map file */
m = (EventTagMap *)(uintptr_t)-1LL;
}
- atomic_store(&map, (uintptr_t)m);
+ atomic_store(&tagMap, (uintptr_t)m);
}
}
if (!ret) { /* trylock succeeded, unlock */
@@ -281,11 +310,11 @@
}
}
if (m && (m != (EventTagMap *)(uintptr_t)-1LL)) {
- tag = android_lookupEventTag(m, get4LE(vec[0].iov_base));
+ tag = android_lookupEventTag_len(m, &len, get4LE(vec[0].iov_base));
}
- ret = __android_log_is_loggable(ANDROID_LOG_INFO,
- tag,
- ANDROID_LOG_VERBOSE);
+ ret = __android_log_is_loggable_len(ANDROID_LOG_INFO,
+ tag, len,
+ ANDROID_LOG_VERBOSE);
if (f) { /* local copy marked for close */
android_closeEventTagMap(f);
}
@@ -318,7 +347,9 @@
tag = NULL;
}
- if (!__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE)) {
+ if (!__android_log_is_loggable_len(prio,
+ tag, len - 1,
+ ANDROID_LOG_VERBOSE)) {
return -EPERM;
}
}
diff --git a/liblog/logprint.c b/liblog/logprint.c
index e21a9c4..2c4e619 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -31,8 +31,8 @@
#include <sys/param.h>
#include <sys/types.h>
+#include <android/log.h>
#include <cutils/list.h>
-#include <log/logd.h>
#include <log/logprint.h>
#include "log_portability.h"
@@ -539,6 +539,7 @@
entry->priority = msg[0];
entry->tag = msg + 1;
+ entry->tagLen = msgStart - 1;
entry->message = msg + msgStart;
entry->messageLen = (msgEnd < msgStart) ? 0 : (msgEnd - msgStart);
@@ -801,8 +802,9 @@
eventData += 4;
inCount -= 4;
+ entry->tagLen = 0;
if (map != NULL) {
- entry->tag = android_lookupEventTag(map, tagIndex);
+ entry->tag = android_lookupEventTag_len(map, &entry->tagLen, tagIndex);
} else {
entry->tag = NULL;
}
@@ -813,12 +815,16 @@
* shift the buffer pointers down.
*/
if (entry->tag == NULL) {
- int tagLen;
+ size_t tagLen;
tagLen = snprintf(messageBuf, messageBufLen, "[%d]", tagIndex);
+ if (tagLen >= (size_t)messageBufLen) {
+ tagLen = messageBufLen - 1;
+ }
entry->tag = messageBuf;
- messageBuf += tagLen+1;
- messageBufLen -= tagLen+1;
+ entry->tagLen = tagLen;
+ messageBuf += tagLen + 1;
+ messageBufLen -= tagLen + 1;
}
/*
@@ -1386,13 +1392,13 @@
switch (p_format->format) {
case FORMAT_TAG:
len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
- "%c/%-8s: ", priChar, entry->tag);
+ "%c/%-8.*s: ", priChar, (int)entry->tagLen, entry->tag);
strcpy(suffixBuf + suffixLen, "\n");
++suffixLen;
break;
case FORMAT_PROCESS:
len = snprintf(suffixBuf + suffixLen, sizeof(suffixBuf) - suffixLen,
- " (%s)\n", entry->tag);
+ " (%.*s)\n", (int)entry->tagLen, entry->tag);
suffixLen += MIN(len, sizeof(suffixBuf) - suffixLen);
len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
"%c(%s%5d) ", priChar, uid, entry->pid);
@@ -1411,8 +1417,8 @@
break;
case FORMAT_TIME:
len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
- "%s %c/%-8s(%s%5d): ", timeBuf, priChar, entry->tag,
- uid, entry->pid);
+ "%s %c/%-8.*s(%s%5d): ", timeBuf, priChar,
+ (int)entry->tagLen, entry->tag, uid, entry->pid);
strcpy(suffixBuf + suffixLen, "\n");
++suffixLen;
break;
@@ -1422,15 +1428,16 @@
*ret = ' ';
}
len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
- "%s %s%5d %5d %c %-8s: ", timeBuf,
- uid, entry->pid, entry->tid, priChar, entry->tag);
+ "%s %s%5d %5d %c %-8.*s: ", timeBuf, uid, entry->pid,
+ entry->tid, priChar, (int)entry->tagLen, entry->tag);
strcpy(suffixBuf + suffixLen, "\n");
++suffixLen;
break;
case FORMAT_LONG:
len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
- "[ %s %s%5d:%5d %c/%-8s ]\n",
- timeBuf, uid, entry->pid, entry->tid, priChar, entry->tag);
+ "[ %s %s%5d:%5d %c/%-8.*s ]\n",
+ timeBuf, uid, entry->pid, entry->tid, priChar,
+ (int)entry->tagLen, entry->tag);
strcpy(suffixBuf + suffixLen, "\n\n");
suffixLen += 2;
prefixSuffixIsHeaderFooter = 1;
@@ -1438,7 +1445,8 @@
case FORMAT_BRIEF:
default:
len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
- "%c/%-8s(%s%5d): ", priChar, entry->tag, uid, entry->pid);
+ "%c/%-8.*s(%s%5d): ", priChar, (int)entry->tagLen, entry->tag,
+ uid, entry->pid);
strcpy(suffixBuf + suffixLen, "\n");
++suffixLen;
break;
diff --git a/liblog/pmsg_writer.c b/liblog/pmsg_writer.c
index b338dca..06652f3 100644
--- a/liblog/pmsg_writer.c
+++ b/liblog/pmsg_writer.c
@@ -25,14 +25,12 @@
#include <sys/types.h>
#include <time.h>
-#include <log/log.h>
+#include <android/log.h>
#include <log/logger.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
-#include <sys/system_properties.h>
-
#include "config_write.h"
#include "log_portability.h"
#include "logger.h"
@@ -53,25 +51,8 @@
.write = pmsgWrite,
};
-static bool pmsgShouldUse = false;
-
-// Only use pmsg on eng builds
-static bool pmsgIsEng() {
- char buf[PROP_VALUE_MAX];
-
- if (__system_property_get("ro.build.type", buf) == 0) {
- return false;
- }
-
- if (!strncmp(buf, "eng", sizeof("eng"))) {
- return true;
- }
- return false;
-}
-
static int pmsgOpen()
{
- pmsgShouldUse = pmsgIsEng();
if (pmsgLoggerWrite.context.fd < 0) {
pmsgLoggerWrite.context.fd = TEMP_FAILURE_RETRY(open("/dev/pmsg0", O_WRONLY | O_CLOEXEC));
}
@@ -94,7 +75,7 @@
}
if ((logId != LOG_ID_SECURITY) &&
(logId != LOG_ID_EVENTS) &&
- (!pmsgShouldUse || !__android_log_is_debuggable())) {
+ !__android_log_is_debuggable()) {
return -EINVAL;
}
if (pmsgLoggerWrite.context.fd < 0) {
@@ -124,7 +105,7 @@
size_t i, payloadSize;
ssize_t ret;
- if ((logId == LOG_ID_EVENTS) && (!pmsgShouldUse || !__android_log_is_debuggable())) {
+ if ((logId == LOG_ID_EVENTS) && !__android_log_is_debuggable()) {
if (vec[0].iov_len < 4) {
return -EINVAL;
}
diff --git a/liblog/tests/Android.mk b/liblog/tests/Android.mk
index 8229859..a755b98 100644
--- a/liblog/tests/Android.mk
+++ b/liblog/tests/Android.mk
@@ -40,7 +40,7 @@
LOCAL_MODULE := $(test_module_prefix)benchmarks
LOCAL_MODULE_TAGS := $(test_tags)
LOCAL_CFLAGS += $(benchmark_c_flags)
-LOCAL_SHARED_LIBRARIES += liblog libm
+LOCAL_SHARED_LIBRARIES += liblog libm libbase
LOCAL_SRC_FILES := $(benchmark_src_files)
include $(BUILD_NATIVE_TEST)
@@ -73,6 +73,6 @@
LOCAL_MODULE := $(test_module_prefix)unit-tests
LOCAL_MODULE_TAGS := $(test_tags)
LOCAL_CFLAGS += $(test_c_flags)
-LOCAL_SHARED_LIBRARIES := liblog libcutils
+LOCAL_SHARED_LIBRARIES := liblog libcutils libbase
LOCAL_SRC_FILES := $(test_src_files)
include $(BUILD_NATIVE_TEST)
diff --git a/liblog/tests/liblog_benchmark.cpp b/liblog/tests/liblog_benchmark.cpp
index f4e3089..cd012ce 100644
--- a/liblog/tests/liblog_benchmark.cpp
+++ b/liblog/tests/liblog_benchmark.cpp
@@ -20,10 +20,9 @@
#include <sys/types.h>
#include <unistd.h>
+#include <android/log.h>
#include <cutils/sockets.h>
-#include <log/log.h>
#include <log/logger.h>
-#include <log/log_read.h>
#include <private/android_logger.h>
#include "benchmark.h"
@@ -651,10 +650,14 @@
* Measure the time it takes for __android_log_is_loggable.
*/
static void BM_is_loggable(int iters) {
+ static const char logd[] = "logd";
+
StartBenchmarkTiming();
for (int i = 0; i < iters; ++i) {
- __android_log_is_loggable(ANDROID_LOG_WARN, "logd", ANDROID_LOG_VERBOSE);
+ __android_log_is_loggable_len(ANDROID_LOG_WARN,
+ logd, strlen(logd),
+ ANDROID_LOG_VERBOSE);
}
StopBenchmarkTiming();
diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp
index b3b44e3..b1dae9e 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include <ctype.h>
+#include <dirent.h>
#include <fcntl.h>
#include <inttypes.h>
#include <semaphore.h>
@@ -22,11 +24,14 @@
#include <sys/types.h>
#include <unistd.h>
+#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/log.h>
#include <log/logger.h>
-#include <log/log_read.h>
#include <log/logprint.h>
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
@@ -1338,8 +1343,8 @@
continue;
}
fprintf(stderr, "i=%zu j=%zu\r", i, j);
- bool android_log_is_loggable = __android_log_is_loggable(
- levels[i].level, tag, levels[j].level);
+ bool android_log_is_loggable = __android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), levels[j].level);
if ((levels[i].level < levels[j].level)
|| (levels[j].level == -1)) {
if (android_log_is_loggable) {
@@ -1347,8 +1352,8 @@
}
EXPECT_FALSE(android_log_is_loggable);
for(size_t k = 10; k; --k) {
- EXPECT_FALSE(__android_log_is_loggable(
- levels[i].level, tag, levels[j].level));
+ EXPECT_FALSE(__android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), levels[j].level));
}
} else {
if (!android_log_is_loggable) {
@@ -1356,8 +1361,8 @@
}
EXPECT_TRUE(android_log_is_loggable);
for(size_t k = 10; k; --k) {
- EXPECT_TRUE(__android_log_is_loggable(
- levels[i].level, tag, levels[j].level));
+ EXPECT_TRUE(__android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), levels[j].level));
}
}
}
@@ -1378,8 +1383,8 @@
i, j, key, buf);
usleep(20000);
property_set(key, buf);
- bool android_log_is_loggable = __android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG);
+ bool android_log_is_loggable = __android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG);
if ((levels[i].level < levels[j].level)
|| (levels[j].level == -1)
|| ((levels[i].level < ANDROID_LOG_DEBUG)
@@ -1389,8 +1394,8 @@
}
EXPECT_FALSE(android_log_is_loggable);
for(size_t k = 10; k; --k) {
- EXPECT_FALSE(__android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG));
+ EXPECT_FALSE(__android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG));
}
} else {
if (!android_log_is_loggable) {
@@ -1398,8 +1403,8 @@
}
EXPECT_TRUE(android_log_is_loggable);
for(size_t k = 10; k; --k) {
- EXPECT_TRUE(__android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG));
+ EXPECT_TRUE(__android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG));
}
}
usleep(20000);
@@ -1408,8 +1413,8 @@
fprintf(stderr, "i=%zu j=%zu property_set(\"%s\",\"%s\")\r",
i, j, key + base_offset, buf);
property_set(key + base_offset, buf);
- android_log_is_loggable = __android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG);
+ android_log_is_loggable = __android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG);
if ((levels[i].level < levels[j].level)
|| (levels[j].level == -1)
|| ((levels[i].level < ANDROID_LOG_DEBUG)
@@ -1419,8 +1424,8 @@
}
EXPECT_FALSE(android_log_is_loggable);
for(size_t k = 10; k; --k) {
- EXPECT_FALSE(__android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG));
+ EXPECT_FALSE(__android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG));
}
} else {
if (!android_log_is_loggable) {
@@ -1428,8 +1433,8 @@
}
EXPECT_TRUE(android_log_is_loggable);
for(size_t k = 10; k; --k) {
- EXPECT_TRUE(__android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG));
+ EXPECT_TRUE(__android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG));
}
}
usleep(20000);
@@ -1440,8 +1445,8 @@
fprintf(stderr, "i=%zu j=%zu property_set(\"%s\",\"%s\")\r",
i, j, key, buf);
property_set(key, buf);
- android_log_is_loggable = __android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG);
+ android_log_is_loggable = __android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG);
if ((levels[i].level < levels[j].level)
|| (levels[j].level == -1)
|| ((levels[i].level < ANDROID_LOG_DEBUG)
@@ -1451,8 +1456,8 @@
}
EXPECT_FALSE(android_log_is_loggable);
for(size_t k = 10; k; --k) {
- EXPECT_FALSE(__android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG));
+ EXPECT_FALSE(__android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG));
}
} else {
if (!android_log_is_loggable) {
@@ -1460,8 +1465,8 @@
}
EXPECT_TRUE(android_log_is_loggable);
for(size_t k = 10; k; --k) {
- EXPECT_TRUE(__android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG));
+ EXPECT_TRUE(__android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG));
}
}
usleep(20000);
@@ -1470,8 +1475,8 @@
fprintf(stderr, "i=%zu j=%zu property_set(\"%s\",\"%s\")\r",
i, j, key + base_offset, buf);
property_set(key + base_offset, buf);
- android_log_is_loggable = __android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG);
+ android_log_is_loggable = __android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG);
if ((levels[i].level < levels[j].level)
|| (levels[j].level == -1)
|| ((levels[i].level < ANDROID_LOG_DEBUG)
@@ -1481,8 +1486,8 @@
}
EXPECT_FALSE(android_log_is_loggable);
for(size_t k = 10; k; --k) {
- EXPECT_FALSE(__android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG));
+ EXPECT_FALSE(__android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG));
}
} else {
if (!android_log_is_loggable) {
@@ -1490,8 +1495,8 @@
}
EXPECT_TRUE(android_log_is_loggable);
for(size_t k = 10; k; --k) {
- EXPECT_TRUE(__android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG));
+ EXPECT_TRUE(__android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG));
}
}
usleep(20000);
@@ -1518,8 +1523,8 @@
i, j, key, buf);
usleep(20000);
property_set(key, buf);
- bool android_log_is_loggable = __android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG);
+ bool android_log_is_loggable = __android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG);
if ((levels[i].level < levels[j].level)
|| (levels[j].level == -1)
|| ((levels[i].level < ANDROID_LOG_INFO) // Yes INFO
@@ -1529,8 +1534,8 @@
}
EXPECT_FALSE(android_log_is_loggable);
for(size_t k = 10; k; --k) {
- EXPECT_FALSE(__android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG));
+ EXPECT_FALSE(__android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG));
}
} else {
if (!android_log_is_loggable) {
@@ -1538,8 +1543,8 @@
}
EXPECT_TRUE(android_log_is_loggable);
for(size_t k = 10; k; --k) {
- EXPECT_TRUE(__android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG));
+ EXPECT_TRUE(__android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG));
}
}
usleep(20000);
@@ -1548,8 +1553,8 @@
fprintf(stderr, "i=%zu j=%zu property_set(\"%s\",\"%s\")\r",
i, j, key + base_offset, buf);
property_set(key + base_offset, buf);
- android_log_is_loggable = __android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG);
+ android_log_is_loggable = __android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG);
if ((levels[i].level < levels[j].level)
|| (levels[j].level == -1)
|| ((levels[i].level < ANDROID_LOG_INFO) // Yes INFO
@@ -1559,8 +1564,8 @@
}
EXPECT_FALSE(android_log_is_loggable);
for(size_t k = 10; k; --k) {
- EXPECT_FALSE(__android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG));
+ EXPECT_FALSE(__android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG));
}
} else {
if (!android_log_is_loggable) {
@@ -1568,8 +1573,8 @@
}
EXPECT_TRUE(android_log_is_loggable);
for(size_t k = 10; k; --k) {
- EXPECT_TRUE(__android_log_is_loggable(
- levels[i].level, tag, ANDROID_LOG_DEBUG));
+ EXPECT_TRUE(__android_log_is_loggable_len(
+ levels[i].level, tag, strlen(tag), ANDROID_LOG_DEBUG));
}
}
usleep(20000);
@@ -2618,3 +2623,83 @@
EXPECT_LT(0, ret);
EXPECT_EQ(1U, signaled);
}
+
+// meant to be handed to ASSERT_TRUE / EXPECT_TRUE only to expand the message
+static testing::AssertionResult IsOk(bool ok, std::string &message) {
+ return ok ?
+ testing::AssertionSuccess() :
+ (testing::AssertionFailure() << message);
+}
+
+static void event_log_tags_test_smap(pid_t pid) {
+ std::string filename = android::base::StringPrintf("/proc/%d/smaps", pid);
+
+ std::string content;
+ if (!android::base::ReadFileToString(filename, &content)) return;
+
+ bool shared_ok = false;
+ bool anonymous_ok = false;
+ bool pass_ok = false;
+
+ static const char event_log_tags[] = "event-log-tags";
+ std::string::size_type pos = 0;
+ while ((pos = content.find(event_log_tags, pos)) != std::string::npos) {
+ pos += strlen(event_log_tags);
+
+ // must not be: 'Shared_Clean: 0 kB'
+ static const char shared_clean[] = "Shared_Clean:";
+ std::string::size_type clean = content.find(shared_clean, pos);
+ bool ok = (clean != std::string::npos) &&
+ ((clean = content.find_first_not_of(" \t", clean +
+ strlen(shared_clean))) != std::string::npos) &&
+ (content.find_first_not_of("123456789", clean) != clean);
+ if (ok && !pass_ok) {
+ shared_ok = true;
+ } else if (!ok) {
+ shared_ok = false;
+ }
+
+ // must be: 'Anonymous: 0 kB'
+ static const char anonymous[] = "Anonymous:";
+ std::string::size_type anon = content.find(anonymous, pos);
+ ok = (anon != std::string::npos) &&
+ ((anon = content.find_first_not_of(" \t", anon +
+ strlen(anonymous))) != std::string::npos) &&
+ (content.find_first_not_of("0", anon) != anon);
+ if (ok && !pass_ok) {
+ anonymous_ok = true;
+ } else if (!ok) {
+ anonymous_ok = false;
+ }
+
+ pass_ok = true;
+ }
+ content = "";
+
+ if (!pass_ok) return;
+ if (shared_ok && anonymous_ok) return;
+
+ filename = android::base::StringPrintf("/proc/%d/comm", pid);
+ android::base::ReadFileToString(filename, &content);
+ content = android::base::StringPrintf("%d:%s",
+ pid, content.substr(0, content.find("\n")).c_str());
+
+ EXPECT_TRUE(IsOk(shared_ok, content));
+ EXPECT_TRUE(IsOk(anonymous_ok, content));
+}
+
+TEST(liblog, event_log_tags) {
+ std::unique_ptr<DIR, int(*)(DIR*)> proc_dir(opendir("/proc"), closedir);
+ ASSERT_FALSE(!proc_dir);
+
+ dirent* e;
+ while ((e = readdir(proc_dir.get()))) {
+ if (e->d_type != DT_DIR) continue;
+ if (!isdigit(e->d_name[0])) continue;
+ long long id = atoll(e->d_name);
+ if (id <= 0) continue;
+ pid_t pid = id;
+ if (id != pid) continue;
+ event_log_tags_test_smap(pid);
+ }
+}
diff --git a/libmemtrack/memtrack.c b/libmemtrack/memtrack.c
index b528214..29cc92c 100644
--- a/libmemtrack/memtrack.c
+++ b/libmemtrack/memtrack.c
@@ -14,16 +14,15 @@
* limitations under the License.
*/
-#include <memtrack/memtrack.h>
-
#define LOG_TAG "memtrack"
-#include <log/log.h>
+#include <memtrack/memtrack.h>
#include <errno.h>
#include <malloc.h>
#include <string.h>
+#include <android/log.h>
#include <hardware/memtrack.h>
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
diff --git a/libmemunreachable/Tarjan.h b/libmemunreachable/Tarjan.h
index dcd139a..2546341 100644
--- a/libmemunreachable/Tarjan.h
+++ b/libmemunreachable/Tarjan.h
@@ -19,6 +19,7 @@
#ifndef LIBMEMUNREACHABLE_TARJAN_H_
#define LIBMEMUNREACHABLE_TARJAN_H_
+#include <assert.h>
#include <algorithm>
#include "Allocator.h"
diff --git a/libmemunreachable/log.h b/libmemunreachable/log.h
index cdfbfd9..dd146b6 100644
--- a/libmemunreachable/log.h
+++ b/libmemunreachable/log.h
@@ -19,6 +19,6 @@
#define LOG_TAG "libmemunreachable"
-#include <log/log.h>
+#include <android/log.h>
#endif // LIBMEMUNREACHABLE_LOG_H_
diff --git a/libnativebridge/native_bridge.cc b/libnativebridge/native_bridge.cc
index ecfd719..9f9c83f 100644
--- a/libnativebridge/native_bridge.cc
+++ b/libnativebridge/native_bridge.cc
@@ -16,8 +16,6 @@
#include "nativebridge/native_bridge.h"
-#include <cstring>
-#include <cutils/log.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
@@ -25,6 +23,9 @@
#include <sys/mount.h>
#include <sys/stat.h>
+#include <cstring>
+
+#include <android/log.h>
namespace android {
diff --git a/libnativebridge/tests/PreInitializeNativeBridgeFail1_test.cpp b/libnativebridge/tests/PreInitializeNativeBridgeFail1_test.cpp
index 69c30a1..5a2b0a1 100644
--- a/libnativebridge/tests/PreInitializeNativeBridgeFail1_test.cpp
+++ b/libnativebridge/tests/PreInitializeNativeBridgeFail1_test.cpp
@@ -16,9 +16,6 @@
#include "NativeBridgeTest.h"
-#include <cstdio>
-#include <cstring>
-#include <cutils/log.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
@@ -26,6 +23,11 @@
#include <sys/mount.h>
#include <sys/stat.h>
+#include <cstdio>
+#include <cstring>
+
+#include <android/log.h>
+
namespace android {
TEST_F(NativeBridgeTest, PreInitializeNativeBridgeFail1) {
diff --git a/libnativebridge/tests/PreInitializeNativeBridgeFail2_test.cpp b/libnativebridge/tests/PreInitializeNativeBridgeFail2_test.cpp
index 74e96e0..af976b1 100644
--- a/libnativebridge/tests/PreInitializeNativeBridgeFail2_test.cpp
+++ b/libnativebridge/tests/PreInitializeNativeBridgeFail2_test.cpp
@@ -14,11 +14,6 @@
* limitations under the License.
*/
-#include "NativeBridgeTest.h"
-
-#include <cstdio>
-#include <cstring>
-#include <cutils/log.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
@@ -26,6 +21,13 @@
#include <sys/mount.h>
#include <sys/stat.h>
+#include <cstdio>
+#include <cstring>
+
+#include <android/log.h>
+
+#include "NativeBridgeTest.h"
+
namespace android {
TEST_F(NativeBridgeTest, PreInitializeNativeBridgeFail2) {
diff --git a/libnativebridge/tests/PreInitializeNativeBridge_test.cpp b/libnativebridge/tests/PreInitializeNativeBridge_test.cpp
index d3bbebe..f3e5f38 100644
--- a/libnativebridge/tests/PreInitializeNativeBridge_test.cpp
+++ b/libnativebridge/tests/PreInitializeNativeBridge_test.cpp
@@ -14,11 +14,6 @@
* limitations under the License.
*/
-#include "NativeBridgeTest.h"
-
-#include <cstdio>
-#include <cstring>
-#include <cutils/log.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
@@ -26,6 +21,13 @@
#include <sys/mount.h>
#include <sys/stat.h>
+#include <cstdio>
+#include <cstring>
+
+#include <android/log.h>
+
+#include "NativeBridgeTest.h"
+
namespace android {
static constexpr const char* kTestData = "PreInitializeNativeBridge test.";
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp
index e89c50f..3a6e54d 100644
--- a/libnativeloader/native_loader.cpp
+++ b/libnativeloader/native_loader.cpp
@@ -20,9 +20,9 @@
#include <dlfcn.h>
#ifdef __ANDROID__
#include "dlext_namespaces.h"
-#include "cutils/properties.h"
#define LOG_TAG "libnativeloader"
-#include "log/log.h"
+#include "android/log.h"
+#include "cutils/properties.h"
#endif
#include <algorithm>
@@ -30,9 +30,9 @@
#include <string>
#include <mutex>
-#include "android-base/file.h"
-#include "android-base/macros.h"
-#include "android-base/strings.h"
+#include <android-base/file.h>
+#include <android-base/macros.h>
+#include <android-base/strings.h>
namespace android {
diff --git a/libnetutils/dhcpclient.c b/libnetutils/dhcpclient.c
index 240a789..d17bdd3 100644
--- a/libnetutils/dhcpclient.c
+++ b/libnetutils/dhcpclient.c
@@ -14,27 +14,25 @@
* limitations under the License.
*/
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-
-#include <time.h>
-#include <sys/time.h>
-#include <poll.h>
-
-#include <sys/socket.h>
-#include <sys/select.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-
-#include <cutils/properties.h>
#define LOG_TAG "DHCP"
-#include <cutils/log.h>
#include <dirent.h>
+#include <errno.h>
+#include <poll.h>
+#include <netinet/in.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/select.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <android/log.h>
+#include <cutils/properties.h>
#include <netutils/ifc.h>
#include "dhcpmsg.h"
diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c
index eae32ce..275327a 100644
--- a/libnetutils/ifc_utils.c
+++ b/libnetutils/ifc_utils.c
@@ -1,34 +1,21 @@
/*
* Copyright 2008, 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
+ * 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
+ * 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
+ * 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 <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <pthread.h>
-
-#include <sys/socket.h>
-#include <sys/select.h>
-#include <sys/types.h>
-#include <netinet/in.h>
#include <arpa/inet.h>
-#include <net/if.h>
-#include <netdb.h>
-
+#include <errno.h>
#include <linux/if.h>
#include <linux/if_ether.h>
#include <linux/if_arp.h>
@@ -37,20 +24,29 @@
#include <linux/ipv6_route.h>
#include <linux/rtnetlink.h>
#include <linux/sockios.h>
-
-#include "netutils/ifc.h"
+#include <net/if.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/select.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <unistd.h>
#ifdef ANDROID
#define LOG_TAG "NetUtils"
-#include <cutils/log.h>
+#include <android/log.h>
#include <cutils/properties.h>
#else
-#include <stdio.h>
-#include <string.h>
#define ALOGD printf
#define ALOGW printf
#endif
+#include "netutils/ifc.h"
+
#if defined(__ANDROID__)
/* SIOCKILLADDR is an Android extension. */
#define SIOCKILLADDR 0x8939
diff --git a/libnetutils/packet.c b/libnetutils/packet.c
index cd26d05..56168e8 100644
--- a/libnetutils/packet.c
+++ b/libnetutils/packet.c
@@ -1,37 +1,36 @@
/*
* Copyright 2008, 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
+ * 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
+ * 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
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <errno.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-#include <sys/uio.h>
#include <sys/socket.h>
+#include <sys/uio.h>
+#include <linux/if_ether.h>
+#include <linux/if_packet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
-#include <linux/if_packet.h>
-#include <linux/if_ether.h>
-#include <errno.h>
+#include <unistd.h>
#ifdef ANDROID
#define LOG_TAG "DHCP"
-#include <cutils/log.h>
+#include <android/log.h>
#else
#include <stdio.h>
-#include <string.h>
#define ALOGD printf
#define ALOGW printf
#endif
diff --git a/libpackagelistparser/packagelistparser.c b/libpackagelistparser/packagelistparser.c
index e309027..f74b8b4 100644
--- a/libpackagelistparser/packagelistparser.c
+++ b/libpackagelistparser/packagelistparser.c
@@ -18,17 +18,16 @@
*
*/
+#define LOG_TAG "packagelistparser"
+
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
#include <sys/limits.h>
-#define LOG_TAG "packagelistparser"
-#include <cutils/log.h>
-
+#include <android/log.h>
#include <packagelistparser/packagelistparser.h>
#define CLOGE(fmt, ...) \
diff --git a/libpixelflinger/codeflinger/ARMAssembler.cpp b/libpixelflinger/codeflinger/ARMAssembler.cpp
index 849512a..36c1326 100644
--- a/libpixelflinger/codeflinger/ARMAssembler.cpp
+++ b/libpixelflinger/codeflinger/ARMAssembler.cpp
@@ -2,16 +2,16 @@
**
** 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
+** 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
+** 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
+** 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.
*/
@@ -19,9 +19,9 @@
#include <stdio.h>
#include <stdlib.h>
-#include <cutils/log.h>
-#include <cutils/properties.h>
+#include <android/log.h>
+#include <cutils/properties.h>
#include <private/pixelflinger/ggl_context.h>
#include "ARMAssembler.h"
diff --git a/libpixelflinger/codeflinger/ARMAssemblerInterface.cpp b/libpixelflinger/codeflinger/ARMAssemblerInterface.cpp
index 5041999..67eba80 100644
--- a/libpixelflinger/codeflinger/ARMAssemblerInterface.cpp
+++ b/libpixelflinger/codeflinger/ARMAssemblerInterface.cpp
@@ -2,26 +2,26 @@
**
** 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
+** 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
+** 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
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
** limitations under the License.
*/
-
#include <errno.h>
-#include <stdlib.h>
#include <stdint.h>
+#include <stdlib.h>
#include <sys/types.h>
-#include <cutils/log.h>
+#include <android/log.h>
+
#include "ARMAssemblerInterface.h"
namespace android {
diff --git a/libpixelflinger/codeflinger/Arm64Assembler.cpp b/libpixelflinger/codeflinger/Arm64Assembler.cpp
index bd11818..fb297ec 100644
--- a/libpixelflinger/codeflinger/Arm64Assembler.cpp
+++ b/libpixelflinger/codeflinger/Arm64Assembler.cpp
@@ -32,14 +32,13 @@
#include <stdlib.h>
#include <string.h>
-#include <cutils/log.h>
+#include <android/log.h>
#include <cutils/properties.h>
#include <private/pixelflinger/ggl_context.h>
#include "codeflinger/Arm64Assembler.h"
-#include "codeflinger/CodeCache.h"
#include "codeflinger/Arm64Disassembler.h"
-
+#include "codeflinger/CodeCache.h"
/*
** --------------------------------------------
diff --git a/libpixelflinger/codeflinger/CodeCache.cpp b/libpixelflinger/codeflinger/CodeCache.cpp
index ae38519..37bd074 100644
--- a/libpixelflinger/codeflinger/CodeCache.cpp
+++ b/libpixelflinger/codeflinger/CodeCache.cpp
@@ -15,17 +15,16 @@
** limitations under the License.
*/
+#define LOG_TAG "CodeCache"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
#include <sys/mman.h>
+#include <unistd.h>
+#include <android/log.h>
#include <cutils/ashmem.h>
-#define LOG_TAG "CodeCache"
-#include <cutils/log.h>
-
#include "CodeCache.h"
diff --git a/libpixelflinger/codeflinger/GGLAssembler.cpp b/libpixelflinger/codeflinger/GGLAssembler.cpp
index 346779f..0b9b5a4 100644
--- a/libpixelflinger/codeflinger/GGLAssembler.cpp
+++ b/libpixelflinger/codeflinger/GGLAssembler.cpp
@@ -2,16 +2,16 @@
**
** 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
+** 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
+** 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
+** 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.
*/
@@ -19,10 +19,11 @@
#include <assert.h>
#include <stdint.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
#include <sys/types.h>
-#include <cutils/log.h>
+
+#include <android/log.h>
#include "GGLAssembler.h"
diff --git a/libpixelflinger/codeflinger/MIPS64Assembler.cpp b/libpixelflinger/codeflinger/MIPS64Assembler.cpp
index b9f31ff..a7bbaf7 100644
--- a/libpixelflinger/codeflinger/MIPS64Assembler.cpp
+++ b/libpixelflinger/codeflinger/MIPS64Assembler.cpp
@@ -25,24 +25,21 @@
**
*/
-
#define LOG_TAG "MIPS64Assembler"
#include <stdio.h>
#include <stdlib.h>
-#include <cutils/log.h>
-#include <cutils/properties.h>
+#include <android/log.h>
+#include <cutils/properties.h>
#include <private/pixelflinger/ggl_context.h>
#include "MIPS64Assembler.h"
#include "CodeCache.h"
#include "mips64_disassem.h"
-
#define NOT_IMPLEMENTED() LOG_ALWAYS_FATAL("Arm instruction %s not yet implemented\n", __func__)
-
// ----------------------------------------------------------------------------
namespace android {
diff --git a/libpixelflinger/codeflinger/MIPSAssembler.cpp b/libpixelflinger/codeflinger/MIPSAssembler.cpp
index ae06a13..4cddcc8 100644
--- a/libpixelflinger/codeflinger/MIPSAssembler.cpp
+++ b/libpixelflinger/codeflinger/MIPSAssembler.cpp
@@ -52,13 +52,13 @@
#include <stdio.h>
#include <stdlib.h>
-#include <cutils/log.h>
-#include <cutils/properties.h>
+#include <android/log.h>
+#include <cutils/properties.h>
#include <private/pixelflinger/ggl_context.h>
-#include "MIPSAssembler.h"
#include "CodeCache.h"
+#include "MIPSAssembler.h"
#include "mips_disassem.h"
// Choose MIPS arch variant following gcc flags
diff --git a/libpixelflinger/codeflinger/blending.cpp b/libpixelflinger/codeflinger/blending.cpp
index b20219c..d4aa475 100644
--- a/libpixelflinger/codeflinger/blending.cpp
+++ b/libpixelflinger/codeflinger/blending.cpp
@@ -2,30 +2,29 @@
**
** 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
+** 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
+** 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
+** 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 <assert.h>
#include <stdint.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
#include <sys/types.h>
-#include <cutils/log.h>
+#include <android/log.h>
#include "GGLAssembler.h"
-
namespace android {
void GGLAssembler::build_fog(
diff --git a/libpixelflinger/codeflinger/load_store.cpp b/libpixelflinger/codeflinger/load_store.cpp
index e5a1ae0..d68f6dc 100644
--- a/libpixelflinger/codeflinger/load_store.cpp
+++ b/libpixelflinger/codeflinger/load_store.cpp
@@ -2,22 +2,24 @@
**
** 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
+** 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
+** 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
+** 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 <assert.h>
#include <stdio.h>
-#include <cutils/log.h>
+
+#include <android/log.h>
+
#include "GGLAssembler.h"
namespace android {
@@ -25,7 +27,7 @@
// ----------------------------------------------------------------------------
void GGLAssembler::store(const pointer_t& addr, const pixel_t& s, uint32_t flags)
-{
+{
const int bits = addr.size;
const int inc = (flags & WRITE_BACK)?1:0;
switch (bits) {
@@ -59,8 +61,8 @@
}
void GGLAssembler::load(const pointer_t& addr, const pixel_t& s, uint32_t flags)
-{
- Scratch scratches(registerFile());
+{
+ Scratch scratches(registerFile());
int s0;
const int bits = addr.size;
@@ -72,7 +74,7 @@
break;
case 24:
// 24 bits formats are a little special and used only for RGB
- // R,G,B is packed as 0x00BBGGRR
+ // R,G,B is packed as 0x00BBGGRR
s0 = scratches.obtain();
if (s.reg != addr.reg) {
LDRB(AL, s.reg, addr.reg, immed12_pre(0)); // R
@@ -90,7 +92,7 @@
}
if (inc)
ADD(AL, 0, addr.reg, addr.reg, imm(3));
- break;
+ break;
case 16:
if (inc) LDRH(AL, s.reg, addr.reg, immed8_post(2));
else LDRH(AL, s.reg, addr.reg);
@@ -112,7 +114,7 @@
assert(maskLen<=8);
#endif
assert(h);
-
+
if (h != bits) {
const int mask = ((1<<maskLen)-1) << l;
if (isValidImmediate(mask)) {
@@ -126,12 +128,12 @@
}
s = d.reg;
}
-
+
if (l) {
MOV(AL, 0, d.reg, reg_imm(s, LSR, l)); // component = packed >> l;
s = d.reg;
}
-
+
if (s != d.reg) {
MOV(AL, 0, d.reg, s);
}
@@ -212,12 +214,12 @@
} while(dbits>0);
return;
}
-
+
dbits -= sbits;
do {
ORR(AL, 0, d, s, reg_imm(s, LSL, sbits));
// d |= d<<sbits;
- s = d;
+ s = d;
dbits -= sbits;
if (sbits*2 < dbits) {
sbits *= 2;
@@ -241,14 +243,14 @@
int dl = d.format.c[component].l;
int dbits = dh - dl;
int dithering = 0;
-
+
ALOGE_IF(sbits<dbits, "sbits (%d) < dbits (%d) in downshift", sbits, dbits);
if (sbits>dbits) {
// see if we need to dither
dithering = mDithering;
}
-
+
int ireg = d.reg;
if (!(d.flags & FIRST)) {
if (s.flags & CORRUPTIBLE) {
@@ -271,7 +273,7 @@
if (isValidImmediate(mask) || isValidImmediate(~mask)) {
build_and_immediate(ireg, s.reg, mask, 32);
sl = offset;
- s.reg = ireg;
+ s.reg = ireg;
sbits = dbits;
maskLoBits = maskHiBits = 0;
}
@@ -281,7 +283,7 @@
const uint32_t mask = ((1<<sbits)-1) << sl;
if (isValidImmediate(mask) || isValidImmediate(~mask)) {
build_and_immediate(ireg, s.reg, mask, 32);
- s.reg = ireg;
+ s.reg = ireg;
maskLoBits = maskHiBits = 0;
}
}
@@ -325,7 +327,7 @@
MOV(AL, 0, ireg, reg_imm(s.reg, LSR, sl));
sh -= sl;
sl = 0;
- s.reg = ireg;
+ s.reg = ireg;
}
// scaling (V-V>>dbits)
SUB(AL, 0, ireg, s.reg, reg_imm(s.reg, LSR, dbits));
@@ -333,7 +335,7 @@
if (shift>0) ADD(AL, 0, ireg, ireg, reg_imm(dither.reg, LSR, shift));
else if (shift<0) ADD(AL, 0, ireg, ireg, reg_imm(dither.reg, LSL,-shift));
else ADD(AL, 0, ireg, ireg, dither.reg);
- s.reg = ireg;
+ s.reg = ireg;
}
if ((maskLoBits|dithering) && (sh > dbits)) {
diff --git a/libpixelflinger/codeflinger/mips64_disassem.c b/libpixelflinger/codeflinger/mips64_disassem.c
index 44b7fe7..f28d726 100644
--- a/libpixelflinger/codeflinger/mips64_disassem.c
+++ b/libpixelflinger/codeflinger/mips64_disassem.c
@@ -34,21 +34,20 @@
* from: @(#)kadb.c 8.1 (Berkeley) 6/10/93
*/
-#include <stdio.h>
-#include <stdint.h>
#include <stdarg.h>
#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
#include <sys/cdefs.h>
-
#include <sys/types.h>
-#include "mips_opcode.h"
-#include <cutils/log.h>
+#include <android/log.h>
+
+#include "mips_opcode.h"
static char *sprintf_buffer;
static int sprintf_buf_len;
-
typedef uint64_t db_addr_t;
static void db_printf(const char* fmt, ...);
diff --git a/libpixelflinger/codeflinger/texturing.cpp b/libpixelflinger/codeflinger/texturing.cpp
index 29a3742..d66981d 100644
--- a/libpixelflinger/codeflinger/texturing.cpp
+++ b/libpixelflinger/codeflinger/texturing.cpp
@@ -2,26 +2,26 @@
**
** 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
+** 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
+** 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
+** 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 <assert.h>
#include <stdint.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
#include <sys/types.h>
-#include <cutils/log.h>
+#include <android/log.h>
#include "GGLAssembler.h"
diff --git a/libpixelflinger/scanline.cpp b/libpixelflinger/scanline.cpp
index aa18360..1a2f6fb 100644
--- a/libpixelflinger/scanline.cpp
+++ b/libpixelflinger/scanline.cpp
@@ -2,29 +2,28 @@
**
** Copyright 2006-2011, 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
+** 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
+** 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
+** 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 "pixelflinger"
#include <assert.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include <android/log.h>
#include <cutils/memory.h>
-#include <cutils/log.h>
#include "buffer.h"
#include "scanline.h"
diff --git a/libpixelflinger/tests/arch-mips64/assembler/mips64_assembler_test.cpp b/libpixelflinger/tests/arch-mips64/assembler/mips64_assembler_test.cpp
index e8c4626..9fb0a28 100644
--- a/libpixelflinger/tests/arch-mips64/assembler/mips64_assembler_test.cpp
+++ b/libpixelflinger/tests/arch-mips64/assembler/mips64_assembler_test.cpp
@@ -26,21 +26,21 @@
* SUCH DAMAGE.
*/
+#include <errno.h>
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
#include <sys/mman.h>
-#include <cutils/ashmem.h>
-#include <cutils/log.h>
+#include <unistd.h>
-#define __STDC_FORMAT_MACROS
-#include <inttypes.h>
+#include <android/log.h>
+#include <cutils/ashmem.h>
#include "codeflinger/ARMAssemblerInterface.h"
#include "codeflinger/MIPS64Assembler.h"
+
using namespace android;
#define TESTS_DATAOP_ENABLE 1
diff --git a/libpixelflinger/trap.cpp b/libpixelflinger/trap.cpp
index ea53625..f00e50a 100644
--- a/libpixelflinger/trap.cpp
+++ b/libpixelflinger/trap.cpp
@@ -2,16 +2,16 @@
**
** 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
+** 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
+** 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
+** 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.
*/
@@ -19,12 +19,12 @@
#include <stdio.h>
#include <stdlib.h>
+#include <android/log.h>
+#include <cutils/memory.h>
+
#include "trap.h"
#include "picker.h"
-#include <cutils/log.h>
-#include <cutils/memory.h>
-
namespace android {
// ----------------------------------------------------------------------------
diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp
index 65bbc1e..7c15429 100644
--- a/libprocessgroup/processgroup.cpp
+++ b/libprocessgroup/processgroup.cpp
@@ -203,9 +203,8 @@
{
std::unique_ptr<DIR, decltype(&closedir)> uid(opendir(uid_path), closedir);
if (uid != NULL) {
- struct dirent cur;
- struct dirent *dir;
- while ((readdir_r(uid.get(), &cur, &dir) == 0) && dir) {
+ dirent* dir;
+ while ((dir = readdir(uid.get())) != nullptr) {
char path[PROCESSGROUP_MAX_PATH_LEN];
if (dir->d_type != DT_DIR) {
@@ -231,9 +230,8 @@
if (root == NULL) {
PLOG(ERROR) << "failed to open " << cgroup_root_path;
} else {
- struct dirent cur;
- struct dirent *dir;
- while ((readdir_r(root.get(), &cur, &dir) == 0) && dir) {
+ dirent* dir;
+ while ((dir = readdir(root.get())) != nullptr) {
char path[PROCESSGROUP_MAX_PATH_LEN];
if (dir->d_type != DT_DIR) {
diff --git a/libsuspend/autosuspend.c b/libsuspend/autosuspend.c
index edd1007..64d1bfc 100644
--- a/libsuspend/autosuspend.c
+++ b/libsuspend/autosuspend.c
@@ -14,10 +14,11 @@
* limitations under the License.
*/
+#define LOG_TAG "libsuspend"
+
#include <stdbool.h>
-#define LOG_TAG "libsuspend"
-#include <cutils/log.h>
+#include <android/log.h>
#include <suspend/autosuspend.h>
diff --git a/libsuspend/autosuspend_autosleep.c b/libsuspend/autosuspend_autosleep.c
index 7262cc7..97109ac 100644
--- a/libsuspend/autosuspend_autosleep.c
+++ b/libsuspend/autosuspend_autosleep.c
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "libsuspend"
+
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
@@ -22,8 +24,7 @@
#include <sys/types.h>
#include <unistd.h>
-#define LOG_TAG "libsuspend"
-#include <cutils/log.h>
+#include <android/log.h>
#include "autosuspend_ops.h"
diff --git a/libsuspend/autosuspend_earlysuspend.c b/libsuspend/autosuspend_earlysuspend.c
index 3793a69..9519e51 100644
--- a/libsuspend/autosuspend_earlysuspend.c
+++ b/libsuspend/autosuspend_earlysuspend.c
@@ -14,18 +14,19 @@
* limitations under the License.
*/
+#define LOG_TAG "libsuspend"
+
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
-#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
-#define LOG_TAG "libsuspend"
-#include <cutils/log.h>
+#include <android/log.h>
#include "autosuspend_ops.h"
diff --git a/libsuspend/autosuspend_wakeup_count.c b/libsuspend/autosuspend_wakeup_count.c
index 23a0290..d3fb45f 100644
--- a/libsuspend/autosuspend_wakeup_count.c
+++ b/libsuspend/autosuspend_wakeup_count.c
@@ -14,6 +14,9 @@
* limitations under the License.
*/
+#define LOG_TAG "libsuspend"
+//#define LOG_NDEBUG 0
+
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
@@ -25,9 +28,7 @@
#include <sys/types.h>
#include <unistd.h>
-#define LOG_TAG "libsuspend"
-//#define LOG_NDEBUG 0
-#include <cutils/log.h>
+#include <android/log.h>
#include "autosuspend_ops.h"
diff --git a/libsysutils/src/FrameworkClient.cpp b/libsysutils/src/FrameworkClient.cpp
index 2f37055..72b3d0a 100644
--- a/libsysutils/src/FrameworkClient.cpp
+++ b/libsysutils/src/FrameworkClient.cpp
@@ -1,11 +1,27 @@
-#include <alloca.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <pthread.h>
+/*
+ * Copyright (C) 2009-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.
+ */
#define LOG_TAG "FrameworkClient"
-#include <cutils/log.h>
+#include <alloca.h>
+#include <errno.h>
+#include <pthread.h>
+#include <sys/types.h>
+
+#include <android/log.h>
#include <sysutils/FrameworkClient.h>
FrameworkClient::FrameworkClient(int socket) {
diff --git a/libsysutils/src/FrameworkCommand.cpp b/libsysutils/src/FrameworkCommand.cpp
index 0b95a81..dccacda 100644
--- a/libsysutils/src/FrameworkCommand.cpp
+++ b/libsysutils/src/FrameworkCommand.cpp
@@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <errno.h>
#define LOG_TAG "FrameworkCommand"
-#include <cutils/log.h>
+#include <errno.h>
+#include <android/log.h>
#include <sysutils/FrameworkCommand.h>
#define UNUSED __attribute__((unused))
diff --git a/libsysutils/src/FrameworkListener.cpp b/libsysutils/src/FrameworkListener.cpp
index 579ead9..b1fb849 100644
--- a/libsysutils/src/FrameworkListener.cpp
+++ b/libsysutils/src/FrameworkListener.cpp
@@ -13,16 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
#define LOG_TAG "FrameworkListener"
-#include <cutils/log.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
-#include <sysutils/FrameworkListener.h>
+#include <android/log.h>
#include <sysutils/FrameworkCommand.h>
+#include <sysutils/FrameworkListener.h>
#include <sysutils/SocketClient.h>
static const int CMD_BUF_SIZE = 1024;
diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp
index 739fad7..b787692 100644
--- a/libsysutils/src/NetlinkEvent.cpp
+++ b/libsysutils/src/NetlinkEvent.cpp
@@ -13,39 +13,36 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <stdlib.h>
-#include <string.h>
#define LOG_TAG "NetlinkEvent"
-#include <cutils/log.h>
-#include <sysutils/NetlinkEvent.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/icmp6.h>
#include <arpa/inet.h>
-#include <net/if.h>
-
#include <linux/if.h>
#include <linux/if_addr.h>
#include <linux/if_link.h>
#include <linux/netfilter/nfnetlink.h>
#include <linux/netfilter/nfnetlink_log.h>
#include <linux/netfilter_ipv4/ipt_ULOG.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <netinet/icmp6.h>
+#include <netlink/attr.h>
+#include <netlink/genl/genl.h>
+#include <netlink/handlers.h>
+#include <netlink/msg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/types.h>
/* From kernel's net/netfilter/xt_quota2.c */
const int LOCAL_QLOG_NL_EVENT = 112;
const int LOCAL_NFLOG_PACKET = NFNL_SUBSYS_ULOG << 8 | NFULNL_MSG_PACKET;
-#include <linux/netlink.h>
-#include <linux/rtnetlink.h>
-
-#include <netlink/attr.h>
-#include <netlink/genl/genl.h>
-#include <netlink/handlers.h>
-#include <netlink/msg.h>
+#include <android/log.h>
+#include <sysutils/NetlinkEvent.h>
NetlinkEvent::NetlinkEvent() {
mAction = Action::kUnknown;
diff --git a/libsysutils/src/NetlinkListener.cpp b/libsysutils/src/NetlinkListener.cpp
index 637aa1e..1c4c7df 100644
--- a/libsysutils/src/NetlinkListener.cpp
+++ b/libsysutils/src/NetlinkListener.cpp
@@ -13,17 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <errno.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <linux/netlink.h>
-#include <string.h>
#define LOG_TAG "NetlinkListener"
-#include <cutils/log.h>
-#include <cutils/uevent.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+
+#include <linux/netlink.h> /* out of order because must follow sys/socket.h */
+
+#include <android/log.h>
+#include <cutils/uevent.h>
#include <sysutils/NetlinkEvent.h>
#if 1
diff --git a/libsysutils/src/ServiceManager.cpp b/libsysutils/src/ServiceManager.cpp
index 41ac1dd..1abe988 100644
--- a/libsysutils/src/ServiceManager.cpp
+++ b/libsysutils/src/ServiceManager.cpp
@@ -1,11 +1,27 @@
+/*
+ * Copyright (C) 2009-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.
+ */
+
+#define LOG_TAG "Service"
+
#include <errno.h>
#include <string.h>
-#include <sysutils/ServiceManager.h>
-
-#define LOG_TAG "Service"
-#include <cutils/log.h>
+#include <android/log.h>
#include <cutils/properties.h>
+#include <sysutils/ServiceManager.h>
ServiceManager::ServiceManager() {
}
diff --git a/libsysutils/src/SocketClient.cpp b/libsysutils/src/SocketClient.cpp
index bb9b6a1..02505d3 100644
--- a/libsysutils/src/SocketClient.cpp
+++ b/libsysutils/src/SocketClient.cpp
@@ -1,16 +1,32 @@
+/*
+ * Copyright (C) 2009-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.
+ */
+
+#define LOG_TAG "SocketClient"
+
#include <alloca.h>
+#include <arpa/inet.h>
#include <errno.h>
#include <malloc.h>
#include <pthread.h>
#include <signal.h>
#include <string.h>
-#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/types.h>
-#define LOG_TAG "SocketClient"
-#include <cutils/log.h>
-
+#include <android/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 608abae..6a676a9 100644
--- a/libsysutils/src/SocketListener.cpp
+++ b/libsysutils/src/SocketListener.cpp
@@ -13,19 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <stdio.h>
+
+#define LOG_TAG "SocketListener"
+
#include <errno.h>
+#include <stdio.h>
#include <stdlib.h>
-#include <sys/socket.h>
#include <sys/select.h>
+#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/un.h>
-#define LOG_TAG "SocketListener"
-#include <cutils/log.h>
+#include <android/log.h>
#include <cutils/sockets.h>
-
#include <sysutils/SocketListener.h>
#include <sysutils/SocketClient.h>
diff --git a/libusbhost/include/usbhost/usbhost.h b/libusbhost/include/usbhost/usbhost.h
index 88b5b44..84594c8 100644
--- a/libusbhost/include/usbhost/usbhost.h
+++ b/libusbhost/include/usbhost/usbhost.h
@@ -216,7 +216,7 @@
int usb_device_bulk_transfer(struct usb_device *device,
int endpoint,
void* buffer,
- int length,
+ unsigned int length,
unsigned int timeout);
/** Reset USB bus for the device */
diff --git a/libusbhost/usbhost.c b/libusbhost/usbhost.c
index 299fdc4..68aca17 100644
--- a/libusbhost/usbhost.c
+++ b/libusbhost/usbhost.c
@@ -600,7 +600,7 @@
int usb_device_bulk_transfer(struct usb_device *device,
int endpoint,
void* buffer,
- int length,
+ unsigned int length,
unsigned int timeout)
{
struct usbdevfs_bulktransfer ctrl;
diff --git a/libutils/FileMap.cpp b/libutils/FileMap.cpp
index 4f4b889..1afa1ec 100644
--- a/libutils/FileMap.cpp
+++ b/libutils/FileMap.cpp
@@ -98,7 +98,7 @@
}
#if defined(__MINGW32__)
if (mBasePtr && UnmapViewOfFile(mBasePtr) == 0) {
- ALOGD("UnmapViewOfFile(%p) failed, error = %" PRId32 "\n", mBasePtr,
+ ALOGD("UnmapViewOfFile(%p) failed, error = %lu\n", mBasePtr,
GetLastError() );
}
if (mFileMapping != INVALID_HANDLE_VALUE) {
@@ -138,7 +138,7 @@
mFileHandle = (HANDLE) _get_osfhandle(fd);
mFileMapping = CreateFileMapping( mFileHandle, NULL, protect, 0, 0, NULL);
if (mFileMapping == NULL) {
- ALOGE("CreateFileMapping(%p, %" PRIx32 ") failed with error %" PRId32 "\n",
+ ALOGE("CreateFileMapping(%p, %lx) failed with error %lu\n",
mFileHandle, protect, GetLastError() );
return false;
}
@@ -153,7 +153,7 @@
(DWORD)(adjOffset),
adjLength );
if (mBasePtr == NULL) {
- ALOGE("MapViewOfFile(%" PRId64 ", %zu) failed with error %" PRId32 "\n",
+ ALOGE("MapViewOfFile(%" PRId64 ", %zu) failed with error %lu\n",
adjOffset, adjLength, GetLastError() );
CloseHandle(mFileMapping);
mFileMapping = INVALID_HANDLE_VALUE;
diff --git a/libutils/Looper.cpp b/libutils/Looper.cpp
index 254cd8d..3edc536 100644
--- a/libutils/Looper.cpp
+++ b/libutils/Looper.cpp
@@ -13,18 +13,17 @@
// Debugs callback registration and invocation.
#define DEBUG_CALLBACKS 0
-#include <cutils/log.h>
-#include <utils/Looper.h>
-#include <utils/Timers.h>
-
#include <errno.h>
#include <fcntl.h>
-#include <limits.h>
#include <inttypes.h>
+#include <limits.h>
#include <string.h>
#include <sys/eventfd.h>
#include <unistd.h>
+#include <android/log.h>
+#include <utils/Looper.h>
+#include <utils/Timers.h>
namespace android {
@@ -679,4 +678,8 @@
eventItem->data.fd = fd;
}
+MessageHandler::~MessageHandler() { }
+
+LooperCallback::~LooperCallback() { }
+
} // namespace android
diff --git a/libutils/ProcessCallStack.cpp b/libutils/ProcessCallStack.cpp
index 4e87a98..73ed4eb 100644
--- a/libutils/ProcessCallStack.cpp
+++ b/libutils/ProcessCallStack.cpp
@@ -131,9 +131,6 @@
}
void ProcessCallStack::update() {
- struct dirent *ep;
- struct dirent entry;
-
std::unique_ptr<DIR, decltype(&closedir)> dp(opendir(PATH_SELF_TASK), closedir);
if (dp == NULL) {
ALOGE("%s: Failed to update the process's call stacks: %s",
@@ -158,8 +155,8 @@
* Each tid is a directory inside of /proc/self/task
* - Read every file in directory => get every tid
*/
- int code;
- while ((code = readdir_r(dp.get(), &entry, &ep)) == 0 && ep != NULL) {
+ dirent* ep;
+ while ((ep = readdir(dp.get())) != NULL) {
pid_t tid = -1;
sscanf(ep->d_name, "%d", &tid);
@@ -194,10 +191,6 @@
ALOGV("%s: Got call stack for tid %d (size %zu)",
__FUNCTION__, tid, threadInfo.callStack.size());
}
- if (code != 0) { // returns positive error value on error
- ALOGE("%s: Failed to readdir from %s: %s",
- __FUNCTION__, PATH_SELF_TASK, strerror(code));
- }
}
void ProcessCallStack::log(const char* logtag, android_LogPriority priority,
diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp
index fee9984..1f8395b 100644
--- a/libutils/RefBase.cpp
+++ b/libutils/RefBase.cpp
@@ -770,4 +770,6 @@
ref->mRefs->renameWeakRefId(old_id, new_id);
}
+VirtualLightRefBase::~VirtualLightRefBase() {}
+
}; // namespace android
diff --git a/libutils/SharedBuffer.cpp b/libutils/SharedBuffer.cpp
index d4fb3f9..1aa761a 100644
--- a/libutils/SharedBuffer.cpp
+++ b/libutils/SharedBuffer.cpp
@@ -17,7 +17,7 @@
#include <stdlib.h>
#include <string.h>
-#include <log/log.h>
+#include <android/log.h>
#include "SharedBuffer.h"
diff --git a/libutils/Unicode.cpp b/libutils/Unicode.cpp
index 5f96efa..0652101 100644
--- a/libutils/Unicode.cpp
+++ b/libutils/Unicode.cpp
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-#include <log/log.h>
-#include <utils/Unicode.h>
-
#include <limits.h>
#include <stddef.h>
+#include <android/log.h>
+#include <utils/Unicode.h>
+
#if defined(_WIN32)
# undef nhtol
# undef htonl
diff --git a/libutils/VectorImpl.cpp b/libutils/VectorImpl.cpp
index e8d40ed..893e4f2 100644
--- a/libutils/VectorImpl.cpp
+++ b/libutils/VectorImpl.cpp
@@ -16,16 +16,16 @@
#define LOG_TAG "Vector"
-#include <string.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
-#include <cutils/log.h>
-#include <safe_iop.h>
-
+#include <android/log.h>
#include <utils/Errors.h>
#include <utils/VectorImpl.h>
+#include <safe_iop.h>
+
#include "SharedBuffer.h"
/*****************************************************************************/
diff --git a/libutils/tests/BitSet_test.cpp b/libutils/tests/BitSet_test.cpp
index 59d913e..fbcf025 100644
--- a/libutils/tests/BitSet_test.cpp
+++ b/libutils/tests/BitSet_test.cpp
@@ -16,11 +16,12 @@
#define LOG_TAG "BitSet_test"
-#include <utils/BitSet.h>
-#include <cutils/log.h>
-#include <gtest/gtest.h>
#include <unistd.h>
+#include <android/log.h>
+#include <gtest/gtest.h>
+#include <utils/BitSet.h>
+
namespace android {
class BitSet32Test : public testing::Test {
diff --git a/libutils/tests/LruCache_test.cpp b/libutils/tests/LruCache_test.cpp
index de440fd..4e885bb 100644
--- a/libutils/tests/LruCache_test.cpp
+++ b/libutils/tests/LruCache_test.cpp
@@ -15,10 +15,11 @@
*/
#include <stdlib.h>
+
+#include <android/log.h>
+#include <gtest/gtest.h>
#include <utils/JenkinsHash.h>
#include <utils/LruCache.h>
-#include <cutils/log.h>
-#include <gtest/gtest.h>
namespace {
diff --git a/libutils/tests/Vector_test.cpp b/libutils/tests/Vector_test.cpp
index 24ecf86..671200f 100644
--- a/libutils/tests/Vector_test.cpp
+++ b/libutils/tests/Vector_test.cpp
@@ -18,11 +18,12 @@
#define __STDC_LIMIT_MACROS
#include <stdint.h>
-#include <utils/Vector.h>
-#include <cutils/log.h>
-#include <gtest/gtest.h>
#include <unistd.h>
+#include <android/log.h>
+#include <gtest/gtest.h>
+#include <utils/Vector.h>
+
namespace android {
class VectorTest : public testing::Test {
diff --git a/libziparchive/testdata/crash.apk b/libziparchive/testdata/crash.apk
new file mode 100644
index 0000000..d6dd52d
--- /dev/null
+++ b/libziparchive/testdata/crash.apk
Binary files differ
diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc
index 350be31..a1455b0 100644
--- a/libziparchive/zip_archive.cc
+++ b/libziparchive/zip_archive.cc
@@ -30,12 +30,13 @@
#include <memory>
#include <vector>
-#include "android-base/file.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 <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 <utils/Compat.h>
+#include <utils/FileMap.h>
#include "ziparchive/zip_archive.h"
#include "zlib.h"
@@ -269,9 +270,14 @@
* Grab the CD offset and size, and the number of entries in the
* archive and verify that they look reasonable.
*/
- if (eocd->cd_start_offset + eocd->cd_size > eocd_offset) {
+ if (static_cast<off64_t>(eocd->cd_start_offset) + eocd->cd_size > eocd_offset) {
ALOGW("Zip: bad offsets (dir %" PRIu32 ", size %" PRIu32 ", eocd %" PRId64 ")",
eocd->cd_start_offset, eocd->cd_size, static_cast<int64_t>(eocd_offset));
+#if defined(__ANDROID__)
+ if (eocd->cd_start_offset + eocd->cd_size <= eocd_offset) {
+ android_errorWriteLog(0x534e4554, "31251826");
+ }
+#endif
return kInvalidOffset;
}
if (eocd->num_records == 0) {
@@ -1073,3 +1079,10 @@
int GetFileDescriptor(const ZipArchiveHandle handle) {
return reinterpret_cast<ZipArchive*>(handle)->fd;
}
+
+ZipString::ZipString(const char* entry_name)
+ : name(reinterpret_cast<const uint8_t*>(entry_name)) {
+ size_t len = strlen(entry_name);
+ CHECK_LE(len, static_cast<size_t>(UINT16_MAX));
+ name_length = static_cast<uint16_t>(len);
+}
diff --git a/libziparchive/zip_archive_stream_entry.cc b/libziparchive/zip_archive_stream_entry.cc
index 4b205a7..41988bc 100644
--- a/libziparchive/zip_archive_stream_entry.cc
+++ b/libziparchive/zip_archive_stream_entry.cc
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "ZIPARCHIVE"
+
// Read-only stream access to Zip Archive entries.
#include <errno.h>
#include <inttypes.h>
@@ -24,9 +26,8 @@
#include <memory>
#include <vector>
-#define LOG_TAG "ZIPARCHIVE"
+#include <android/log.h>
#include <android-base/file.h>
-#include <log/log.h>
#include <ziparchive/zip_archive.h>
#include <ziparchive/zip_archive_stream_entry.h>
#include <zlib.h>
diff --git a/libziparchive/zip_archive_test.cc b/libziparchive/zip_archive_test.cc
index 6aee1bb..42eb5ee 100644
--- a/libziparchive/zip_archive_test.cc
+++ b/libziparchive/zip_archive_test.cc
@@ -36,6 +36,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 kCrashApk = "crash.apk";
static const std::vector<uint8_t> kATxtContents {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
@@ -84,6 +85,12 @@
CloseArchive(handle);
}
+TEST(ziparchive, OutOfBound) {
+ ZipArchiveHandle handle;
+ ASSERT_EQ(-8, OpenArchiveWrapper(kCrashApk, &handle));
+ CloseArchive(handle);
+}
+
TEST(ziparchive, OpenMissing) {
ZipArchiveHandle handle;
ASSERT_NE(0, OpenArchiveWrapper(kMissingZip, &handle));
diff --git a/libziparchive/zip_writer.cc b/libziparchive/zip_writer.cc
index 1ebed30..b72ed7f 100644
--- a/libziparchive/zip_writer.cc
+++ b/libziparchive/zip_writer.cc
@@ -243,8 +243,12 @@
// Initialize the z_stream for compression.
z_stream_ = std::unique_ptr<z_stream, void(*)(z_stream*)>(new z_stream(), DeleteZStream);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
int zerr = deflateInit2(z_stream_.get(), Z_BEST_COMPRESSION, Z_DEFLATED, -MAX_WBITS,
DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
+#pragma GCC diagnostic pop
+
if (zerr != Z_OK) {
if (zerr == Z_VERSION_ERROR) {
ALOGE("Installed zlib is not compatible with linked version (%s)", ZLIB_VERSION);
diff --git a/lmkd/Android.mk b/lmkd/Android.mk
index 8c88661..8980d1c 100644
--- a/lmkd/Android.mk
+++ b/lmkd/Android.mk
@@ -2,7 +2,7 @@
include $(CLEAR_VARS)
LOCAL_SRC_FILES := lmkd.c
-LOCAL_SHARED_LIBRARIES := liblog libm libc libprocessgroup
+LOCAL_SHARED_LIBRARIES := liblog libm libc libprocessgroup libcutils
LOCAL_CFLAGS := -Werror
LOCAL_MODULE := lmkd
diff --git a/lmkd/lmkd.c b/lmkd/lmkd.c
index df1b9af..107aa3e 100644
--- a/lmkd/lmkd.c
+++ b/lmkd/lmkd.c
@@ -30,8 +30,8 @@
#include <sys/types.h>
#include <unistd.h>
+#include <android/log.h>
#include <cutils/sockets.h>
-#include <log/log.h>
#include <processgroup/processgroup.h>
#ifndef __unused
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index 7e2bac7..d1a23ae 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -25,15 +25,13 @@
#include <memory>
#include <string>
+#include <android/log.h>
#include <android-base/file.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <cutils/sched_policy.h>
#include <cutils/sockets.h>
#include <log/event_tag_map.h>
-#include <log/log.h>
-#include <log/log_read.h>
-#include <log/logd.h>
#include <log/logger.h>
#include <log/logprint.h>
#include <system/thread_defs.h>
diff --git a/logcat/tests/logcat_test.cpp b/logcat/tests/logcat_test.cpp
index 3daee13..9c9043e 100644
--- a/logcat/tests/logcat_test.cpp
+++ b/logcat/tests/logcat_test.cpp
@@ -26,10 +26,9 @@
#include <memory>
+#include <android/log.h>
#include <gtest/gtest.h>
-#include <log/log.h>
#include <log/logger.h>
-#include <log/log_read.h>
#define BIG_BUFFER (5 * 1024)
diff --git a/logd/FlushCommand.h b/logd/FlushCommand.h
index 7172d5f..a6cdf9d 100644
--- a/logd/FlushCommand.h
+++ b/logd/FlushCommand.h
@@ -16,7 +16,7 @@
#ifndef _FLUSH_COMMAND_H
#define _FLUSH_COMMAND_H
-#include <log/log_read.h>
+#include <log/logger.h>
#include <sysutils/SocketClientCommand.h>
class LogBufferElement;
diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp
index 1ecf99c..7f5fe4f 100644
--- a/logd/LogBuffer.cpp
+++ b/logd/LogBuffer.cpp
@@ -211,13 +211,15 @@
if (log_id != LOG_ID_SECURITY) {
int prio = ANDROID_LOG_INFO;
const char *tag = NULL;
+ size_t len = 0;
if (log_id == LOG_ID_EVENTS) {
- tag = android::tagToName(elem->getTag());
+ tag = android::tagToName(&len, elem->getTag());
} else {
prio = *msg;
tag = msg + 1;
+ len = strlen(tag);
}
- if (!__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE)) {
+ if (!__android_log_is_loggable_len(prio, tag, len, ANDROID_LOG_VERBOSE)) {
// Log traffic received to total
pthread_mutex_lock(&mLogElementsLock);
stats.add(elem);
diff --git a/logd/LogBuffer.h b/logd/LogBuffer.h
index 162c189..ff9692e 100644
--- a/logd/LogBuffer.h
+++ b/logd/LogBuffer.h
@@ -22,10 +22,9 @@
#include <list>
#include <string>
-#include <log/log.h>
-#include <sysutils/SocketClient.h>
-
+#include <android/log.h>
#include <private/android_filesystem_config.h>
+#include <sysutils/SocketClient.h>
#include "LogBufferElement.h"
#include "LogTimes.h"
@@ -119,7 +118,7 @@
unsigned long getSize(log_id_t id);
int setSize(log_id_t id, unsigned long size);
unsigned long getSizeUsed(log_id_t id);
- // *strp uses malloc, use free to release.
+
std::string formatStatistics(uid_t uid, pid_t pid, unsigned int logMask);
void enableStatistics() {
diff --git a/logd/LogBufferElement.cpp b/logd/LogBufferElement.cpp
index 3e6e586..e5de11d 100644
--- a/logd/LogBufferElement.cpp
+++ b/logd/LogBufferElement.cpp
@@ -110,7 +110,9 @@
LogBuffer *parent) {
static const char tag[] = "chatty";
- if (!__android_log_is_loggable(ANDROID_LOG_INFO, tag, ANDROID_LOG_VERBOSE)) {
+ if (!__android_log_is_loggable_len(ANDROID_LOG_INFO,
+ tag, strlen(tag),
+ ANDROID_LOG_VERBOSE)) {
return 0;
}
diff --git a/logd/LogBufferElement.h b/logd/LogBufferElement.h
index e7f88b9..f089550 100644
--- a/logd/LogBufferElement.h
+++ b/logd/LogBufferElement.h
@@ -21,9 +21,9 @@
#include <stdlib.h>
#include <sys/types.h>
+#include <android/log.h>
#include <sysutils/SocketClient.h>
-#include <log/log.h>
-#include <log/log_read.h>
+#include <log/logger.h>
class LogBuffer;
diff --git a/logd/LogKlog.h b/logd/LogKlog.h
index a4f871e..c0c1223 100644
--- a/logd/LogKlog.h
+++ b/logd/LogKlog.h
@@ -17,8 +17,8 @@
#ifndef _LOGD_LOG_KLOG_H__
#define _LOGD_LOG_KLOG_H__
+#include <log/logger.h>
#include <sysutils/SocketListener.h>
-#include <log/log_read.h>
char *log_strntok_r(char *s, size_t *len, char **saveptr, size_t *sublen);
diff --git a/logd/LogStatistics.cpp b/logd/LogStatistics.cpp
index 86d33b2..c6ebd52 100644
--- a/logd/LogStatistics.cpp
+++ b/logd/LogStatistics.cpp
@@ -436,11 +436,12 @@
name = android::base::StringPrintf("%7u/%u",
getKey(), uid);
}
- const char *nameTmp = getName();
+ size_t len = 0;
+ const char *nameTmp = getName(len);
if (nameTmp) {
name += android::base::StringPrintf(
- "%*s%s", (int)std::max(14 - name.length(), (size_t)1),
- "", nameTmp);
+ "%*s%.*s", (int)std::max(14 - name.length(), (size_t)1),
+ "", (int)len, nameTmp);
}
std::string size = android::base::StringPrintf("%zu",
diff --git a/logd/LogStatistics.h b/logd/LogStatistics.h
index 878c333..bfaafa4 100644
--- a/logd/LogStatistics.h
+++ b/logd/LogStatistics.h
@@ -25,8 +25,8 @@
#include <string> // std::string
#include <unordered_map>
+#include <android/log.h>
#include <android-base/stringprintf.h>
-#include <log/log.h>
#include <private/android_filesystem_config.h>
#include "LogBufferElement.h"
@@ -385,7 +385,7 @@
const uint32_t&getKey() const { return tag; }
const pid_t&getPid() const { return pid; }
const uid_t&getUid() const { return uid; }
- const char*getName() const { return android::tagToName(tag); }
+ const char*getName(size_t &len) const { return android::tagToName(&len, tag); }
inline void add(LogBufferElement *element) {
if (uid != element->getUid()) {
diff --git a/logd/LogTimes.h b/logd/LogTimes.h
index b66ff9e..8401953 100644
--- a/logd/LogTimes.h
+++ b/logd/LogTimes.h
@@ -23,8 +23,8 @@
#include <list>
+#include <android/log.h>
#include <sysutils/SocketClient.h>
-#include <log/log.h>
class LogReader;
class LogBufferElement;
diff --git a/logd/LogUtils.h b/logd/LogUtils.h
index fc66330..6db4c51 100644
--- a/logd/LogUtils.h
+++ b/logd/LogUtils.h
@@ -20,7 +20,7 @@
#include <sys/cdefs.h>
#include <sys/types.h>
-#include <log/log.h>
+#include <android/log.h>
#include <sysutils/SocketClient.h>
// Hijack this header as a common include file used by most all sources
@@ -37,7 +37,7 @@
char *tidToName(pid_t tid);
// Furnished in main.cpp. Thread safe.
-const char *tagToName(uint32_t tag);
+const char *tagToName(size_t *len, uint32_t tag);
}
diff --git a/logd/libaudit.c b/logd/libaudit.c
index d00d579..288a052 100644
--- a/logd/libaudit.c
+++ b/logd/libaudit.c
@@ -18,12 +18,13 @@
*
*/
+#define LOG_TAG "libaudit"
+
#include <errno.h>
#include <string.h>
#include <unistd.h>
-#define LOG_TAG "libaudit"
-#include <log/log.h>
+#include <android/log.h>
#include "libaudit.h"
diff --git a/logd/main.cpp b/logd/main.cpp
index 77a6973..a0cea25 100644
--- a/logd/main.cpp
+++ b/logd/main.cpp
@@ -302,7 +302,7 @@
}
// tagToName converts an events tag into a name
-const char *android::tagToName(uint32_t tag) {
+const char *android::tagToName(size_t *len, uint32_t tag) {
static const EventTagMap *map;
if (!map) {
@@ -312,10 +312,11 @@
}
sem_post(&sem_name);
if (!map) {
+ if (len) len = 0;
return NULL;
}
}
- return android_lookupEventTag(map, tag);
+ return android_lookupEventTag_len(map, len, tag);
}
static void readDmesg(LogAudit *al, LogKlog *kl) {
diff --git a/logd/tests/logd_test.cpp b/logd/tests/logd_test.cpp
index 301ede9..cac8bce 100644
--- a/logd/tests/logd_test.cpp
+++ b/logd/tests/logd_test.cpp
@@ -23,11 +23,10 @@
#include <string>
-#include <gtest/gtest.h>
-
+#include <android/log.h>
#include <android-base/stringprintf.h>
#include <cutils/sockets.h>
-#include <log/log.h>
+#include <gtest/gtest.h>
#include <log/logger.h>
#include "../LogReader.h" // pickup LOGD_SNDTIMEO
diff --git a/logwrapper/logwrap.c b/logwrapper/logwrap.c
index ccbe0bf..1bfecd6 100644
--- a/logwrapper/logwrap.c
+++ b/logwrapper/logwrap.c
@@ -14,24 +14,24 @@
* limitations under the License.
*/
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <poll.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
-#include <stdbool.h>
+#include <poll.h>
#include <pthread.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
-#include <logwrap/logwrap.h>
-#include "private/android_filesystem_config.h"
-#include "cutils/log.h"
+#include <android/log.h>
#include <cutils/klog.h>
+#include <logwrap/logwrap.h>
+#include <private/android_filesystem_config.h>
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
#define MIN(a,b) (((a)<(b))?(a):(b))
diff --git a/logwrapper/logwrapper.c b/logwrapper/logwrapper.c
index 55b71c7..28fe530 100644
--- a/logwrapper/logwrapper.c
+++ b/logwrapper/logwrapper.c
@@ -20,10 +20,9 @@
#include <sys/wait.h>
#include <unistd.h>
-#include <logwrap/logwrap.h>
+#include <android/log.h>
#include <cutils/klog.h>
-
-#include "cutils/log.h"
+#include <logwrap/logwrap.h>
void fatal(const char *msg) {
fprintf(stderr, "%s", msg);
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 90ae4a7..31b1821 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -368,12 +368,12 @@
# create basic filesystem structure
mkdir /data/misc 01771 system misc
- mkdir /data/misc/bluedroid 02770 bluetooth net_bt_stack
+ mkdir /data/misc/bluedroid 02770 bluetooth bluetooth
# Fix the access permissions and group ownership for 'bt_config.conf'
chmod 0660 /data/misc/bluedroid/bt_config.conf
- chown bluetooth net_bt_stack /data/misc/bluedroid/bt_config.conf
- mkdir /data/misc/bluetooth 0770 bluetooth net_bt_stack
- mkdir /data/misc/bluetooth/logs 0770 bluetooth net_bt_stack
+ chown bluetooth bluetooth /data/misc/bluedroid/bt_config.conf
+ mkdir /data/misc/bluetooth 0770 bluetooth bluetooth
+ mkdir /data/misc/bluetooth/logs 0770 bluetooth bluetooth
mkdir /data/misc/keystore 0700 keystore keystore
mkdir /data/misc/gatekeeper 0700 system system
mkdir /data/misc/keychain 0771 system system
@@ -578,6 +578,8 @@
# Define default initial receive window size in segments.
setprop net.tcp.default_init_rwnd 60
+ # Start all binderized HAL daemons
+ start hwservicemanager
class_start core
on nonencrypted
@@ -667,3 +669,13 @@
service flash_recovery /system/bin/install-recovery.sh
class main
oneshot
+
+service hwservicemanager /system/bin/hwservicemanager
+ user system
+ disabled
+ group system readproc
+ critical
+ writepid /dev/cpuset/system-background/tasks
+
+on property:hwservicemanager.ready=true
+ class_start hal
diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc
index bf87b43..8725113 100644
--- a/rootdir/ueventd.rc
+++ b/rootdir/ueventd.rc
@@ -41,8 +41,8 @@
/dev/android_adb 0660 adb adb
/dev/android_adb_enable 0660 adb adb
/dev/ttyMSM0 0600 bluetooth bluetooth
-/dev/uhid 0660 system net_bt_stack
-/dev/uinput 0660 system net_bt_stack
+/dev/uhid 0660 system bluetooth
+/dev/uinput 0660 system bluetooth
/dev/alarm 0664 system radio
/dev/rtc0 0640 system system
/dev/tty0 0660 root system
diff --git a/sdcard/fuse.cpp b/sdcard/fuse.cpp
index f549606..f6dad8a 100644
--- a/sdcard/fuse.cpp
+++ b/sdcard/fuse.cpp
@@ -982,7 +982,7 @@
{
struct node* node;
char path[PATH_MAX];
- struct fuse_open_out out;
+ struct fuse_open_out out = {};
struct handle *h;
pthread_mutex_lock(&fuse->global->lock);
@@ -1011,7 +1011,6 @@
}
out.fh = ptr_to_id(h);
out.open_flags = 0;
- out.padding = 0;
fuse_reply(fuse, hdr->unique, &out, sizeof(out));
return NO_STATUS;
}
@@ -1148,7 +1147,7 @@
{
struct node* node;
char path[PATH_MAX];
- struct fuse_open_out out;
+ struct fuse_open_out out = {};
struct dirhandle *h;
pthread_mutex_lock(&fuse->global->lock);
@@ -1175,7 +1174,6 @@
}
out.fh = ptr_to_id(h);
out.open_flags = 0;
- out.padding = 0;
fuse_reply(fuse, hdr->unique, &out, sizeof(out));
return NO_STATUS;
}
diff --git a/trusty/gatekeeper/trusty_gatekeeper.cpp b/trusty/gatekeeper/trusty_gatekeeper.cpp
index d24f44f..7e55fb1 100644
--- a/trusty/gatekeeper/trusty_gatekeeper.cpp
+++ b/trusty/gatekeeper/trusty_gatekeeper.cpp
@@ -14,18 +14,19 @@
* limitations under the License.
*/
+#define LOG_TAG "TrustyGateKeeper"
+
+#include <assert.h>
#include <errno.h>
#include <stdio.h>
-#include <assert.h>
#include <type_traits>
+#include <android/log.h>
+
#include "trusty_gatekeeper.h"
#include "trusty_gatekeeper_ipc.h"
#include "gatekeeper_ipc.h"
-#define LOG_TAG "TrustyGateKeeper"
-#include <cutils/log.h>
-
namespace gatekeeper {
const uint32_t SEND_BUF_SIZE = 8192;
diff --git a/trusty/gatekeeper/trusty_gatekeeper_ipc.c b/trusty/gatekeeper/trusty_gatekeeper_ipc.c
index a1c319e..ae536c5 100644
--- a/trusty/gatekeeper/trusty_gatekeeper_ipc.c
+++ b/trusty/gatekeeper/trusty_gatekeeper_ipc.c
@@ -14,12 +14,13 @@
* limitations under the License.
*/
+#define LOG_TAG "TrustyGateKeeper"
+
#include <errno.h>
#include <stdlib.h>
#include <string.h>
-#define LOG_TAG "TrustyGateKeeper"
-#include <cutils/log.h>
+#include <android/log.h>
#include <trusty/tipc.h>
#include "trusty_gatekeeper_ipc.h"
diff --git a/trusty/keymaster/trusty_keymaster_device.cpp b/trusty/keymaster/trusty_keymaster_device.cpp
index 069b4fe..de5e463 100644
--- a/trusty/keymaster/trusty_keymaster_device.cpp
+++ b/trusty/keymaster/trusty_keymaster_device.cpp
@@ -14,26 +14,24 @@
* limitations under the License.
*/
-#include "trusty_keymaster_device.h"
+#define LOG_TAG "TrustyKeymaster"
#include <assert.h>
+#include <openssl/evp.h>
+#include <openssl/x509.h>
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
-#include <stddef.h>
#include <type_traits>
-#include <openssl/evp.h>
-#include <openssl/x509.h>
-
-#define LOG_TAG "TrustyKeymaster"
-#include <cutils/log.h>
+#include <android/log.h>
#include <hardware/keymaster0.h>
-
#include <keymaster/authorization_set.h>
+#include "trusty_keymaster_device.h"
#include "trusty_keymaster_ipc.h"
#include "keymaster_ipc.h"
diff --git a/trusty/keymaster/trusty_keymaster_ipc.c b/trusty/keymaster/trusty_keymaster_ipc.c
index b68209e..0159bce 100644
--- a/trusty/keymaster/trusty_keymaster_ipc.c
+++ b/trusty/keymaster/trusty_keymaster_ipc.c
@@ -14,15 +14,15 @@
* limitations under the License.
*/
+#define LOG_TAG "TrustyKeymaster"
+
// TODO: make this generic in libtrusty
#include <errno.h>
#include <stdlib.h>
#include <string.h>
-#define LOG_TAG "TrustyKeymaster"
-#include <cutils/log.h>
-
+#include <android/log.h>
#include <trusty/tipc.h>
#include "trusty_keymaster_ipc.h"
diff --git a/trusty/libtrusty/trusty.c b/trusty/libtrusty/trusty.c
index b6897ce..ba16bee 100644
--- a/trusty/libtrusty/trusty.c
+++ b/trusty/libtrusty/trusty.c
@@ -23,7 +23,7 @@
#include <stdlib.h>
#include <string.h>
-#include <cutils/log.h>
+#include <android/log.h>
#include "tipc_ioctl.h"
diff --git a/trusty/nvram/trusty_nvram_implementation.cpp b/trusty/nvram/trusty_nvram_implementation.cpp
index 041c1bd..caa25ab 100644
--- a/trusty/nvram/trusty_nvram_implementation.cpp
+++ b/trusty/nvram/trusty_nvram_implementation.cpp
@@ -14,17 +14,17 @@
* limitations under the License.
*/
+#define LOG_TAG "TrustyNVRAM"
+
#include "trusty_nvram_implementation.h"
#include <errno.h>
#include <string.h>
+#include <android/log.h>
#include <hardware/nvram.h>
#include <trusty/tipc.h>
-#define LOG_TAG "TrustyNVRAM"
-#include <log/log.h>
-
#include <nvram/messages/blob.h>
namespace nvram {
diff --git a/trusty/storage/lib/storage.c b/trusty/storage/lib/storage.c
index 8130f76..3002c0b 100644
--- a/trusty/storage/lib/storage.c
+++ b/trusty/storage/lib/storage.c
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "trusty_storage_client"
+
#include <errno.h>
#include <stdarg.h>
#include <stdbool.h>
@@ -21,12 +23,10 @@
#include <string.h>
#include <sys/uio.h>
+#include <android/log.h>
#include <trusty/tipc.h>
#include <trusty/lib/storage.h>
-#define LOG_TAG "trusty_storage_client"
-#include <cutils/log.h>
-
#define MAX_CHUNK_SIZE 4040
static inline file_handle_t make_file_handle(storage_session_t s, uint32_t fid)
diff --git a/trusty/storage/proxy/log.h b/trusty/storage/proxy/log.h
index 471cb50..3d2e654 100644
--- a/trusty/storage/proxy/log.h
+++ b/trusty/storage/proxy/log.h
@@ -15,5 +15,6 @@
*/
#define LOG_TAG "storageproxyd"
-#include <cutils/log.h>
+
+#include <android/log.h>