Merge "Fix google-explicit-constructor warnings in system/core."
diff --git a/bootstat/boot_event_record_store.cpp b/bootstat/boot_event_record_store.cpp
index ef4f68e..346eada 100644
--- a/bootstat/boot_event_record_store.cpp
+++ b/bootstat/boot_event_record_store.cpp
@@ -25,6 +25,7 @@
#include <utility>
#include <android-base/file.h>
#include <android-base/logging.h>
+#include <android-base/parseint.h>
#include "histogram_logger.h"
#include "uptime_parser.h"
@@ -57,8 +58,10 @@
// Ignore existing bootstat records (which do not contain file content).
if (!content.empty()) {
- int32_t value = std::stoi(content);
- bootstat::LogHistogram("bootstat_mtime_matches_content", value == *uptime);
+ int32_t value;
+ if (android::base::ParseInt(content.c_str(), &value)) {
+ bootstat::LogHistogram("bootstat_mtime_matches_content", value == *uptime);
+ }
}
return true;
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp
index 7c1b7f3..71a5a39 100644
--- a/bootstat/bootstat.cpp
+++ b/bootstat/bootstat.cpp
@@ -28,6 +28,7 @@
#include <memory>
#include <string>
#include <android-base/logging.h>
+#include <android-base/parseint.h>
#include <cutils/properties.h>
#include <log/log.h>
#include "boot_event_record_store.h"
@@ -56,8 +57,9 @@
BootEventRecordStore boot_event_store;
if (!value_str.empty()) {
int32_t value = 0;
- value = std::stoi(value_str);
- boot_event_store.AddBootEventWithValue(event, value);
+ if (android::base::ParseInt(value_str.c_str(), &value)) {
+ boot_event_store.AddBootEventWithValue(event, value);
+ }
} else {
boot_event_store.AddBootEvent(event);
}
@@ -187,7 +189,10 @@
std::string boot_complete_prefix = "boot_complete";
std::string build_date_str = GetProperty("ro.build.date.utc");
- int32_t build_date = std::stoi(build_date_str);
+ int32_t build_date;
+ if (!android::base::ParseInt(build_date_str.c_str(), &build_date)) {
+ return std::string();
+ }
BootEventRecordStore boot_event_store;
BootEventRecordStore::BootEventRecord record;
@@ -223,6 +228,10 @@
// ota_boot_complete. The latter signifies that the device is booting after
// a system update.
std::string boot_complete_prefix = CalculateBootCompletePrefix();
+ if (boot_complete_prefix.empty()) {
+ // The system is hosed because the build date property could not be read.
+ return;
+ }
// post_decrypt_time_elapsed is only logged on encrypted devices.
if (boot_event_store.GetBootEvent("post_decrypt_time_elapsed", &record)) {
diff --git a/crash_reporter/crash_collector.cc b/crash_reporter/crash_collector.cc
index d993576..6e81c51 100644
--- a/crash_reporter/crash_collector.cc
+++ b/crash_reporter/crash_collector.cc
@@ -317,7 +317,7 @@
continue;
std::string filename(ent->d_name);
- size_t last_dot = filename.rfind(".");
+ size_t last_dot = filename.rfind('.');
std::string basename;
// If there is a valid looking extension, use the base part of the
// name. If the only dot is the first byte (aka a dot file), treat
diff --git a/crash_reporter/kernel_collector_test.cc b/crash_reporter/kernel_collector_test.cc
index 60fd832..0f6b930 100644
--- a/crash_reporter/kernel_collector_test.cc
+++ b/crash_reporter/kernel_collector_test.cc
@@ -283,7 +283,7 @@
pos += strlen(kNamePrefix);
std::string filename = log.substr(pos, std::string::npos);
// Take the name up until \n
- size_t end_pos = filename.find_first_of("\n");
+ size_t end_pos = filename.find_first_of('\n');
ASSERT_NE(std::string::npos, end_pos);
filename = filename.substr(0, end_pos);
ASSERT_EQ(0U, filename.find(test_crash_directory().value()));
diff --git a/fs_mgr/fs_mgr_verity.cpp b/fs_mgr/fs_mgr_verity.cpp
index 25b023e..67104cc 100644
--- a/fs_mgr/fs_mgr_verity.cpp
+++ b/fs_mgr/fs_mgr_verity.cpp
@@ -858,7 +858,7 @@
std::string result, word;
auto tokens = android::base::Split(*table, " ");
- for (const auto token : tokens) {
+ for (const auto& token : tokens) {
if (android::base::StartsWith(token, "/dev/block/") &&
android::base::StartsWith(blk_device, token.c_str())) {
word = blk_device;
diff --git a/healthd/BatteryPropertiesRegistrar.cpp b/healthd/BatteryPropertiesRegistrar.cpp
index 5d1fa52..d28ba41 100644
--- a/healthd/BatteryPropertiesRegistrar.cpp
+++ b/healthd/BatteryPropertiesRegistrar.cpp
@@ -35,7 +35,7 @@
defaultServiceManager()->addService(String16("batteryproperties"), service);
}
-void BatteryPropertiesRegistrar::notifyListeners(struct BatteryProperties props) {
+void BatteryPropertiesRegistrar::notifyListeners(const struct BatteryProperties& props) {
Mutex::Autolock _l(mRegistrationLock);
for (size_t i = 0; i < mListeners.size(); i++) {
mListeners[i]->batteryPropertiesChanged(props);
diff --git a/healthd/BatteryPropertiesRegistrar.h b/healthd/BatteryPropertiesRegistrar.h
index d17e4a3..095f3d3 100644
--- a/healthd/BatteryPropertiesRegistrar.h
+++ b/healthd/BatteryPropertiesRegistrar.h
@@ -31,7 +31,7 @@
public IBinder::DeathRecipient {
public:
void publish(const sp<BatteryPropertiesRegistrar>& service);
- void notifyListeners(struct BatteryProperties props);
+ void notifyListeners(const struct BatteryProperties& props);
private:
Mutex mRegistrationLock;
diff --git a/init/action.cpp b/init/action.cpp
index eeed744..f3e362e 100644
--- a/init/action.cpp
+++ b/init/action.cpp
@@ -118,7 +118,7 @@
Timer t;
int result = command.InvokeFunc();
- if (klog_get_level() >= KLOG_INFO_LEVEL) {
+ if (klog_get_level() >= KLOG_DEBUG_LEVEL) {
std::string trigger_name = BuildTriggersString();
std::string cmd_str = command.BuildCommandString();
std::string source = command.BuildSourceString();
diff --git a/init/devices.cpp b/init/devices.cpp
index 5e12f25..373177e 100644
--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -181,7 +181,7 @@
}
if (access(path.c_str(), F_OK) == 0) {
- LOG(INFO) << "restorecon_recursive: " << path;
+ LOG(VERBOSE) << "restorecon_recursive: " << path;
restorecon_recursive(path.c_str());
}
}
diff --git a/init/init.cpp b/init/init.cpp
index fc3e80f..78d71a8 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -29,6 +29,7 @@
#include <sys/mount.h>
#include <sys/socket.h>
#include <sys/stat.h>
+#include <sys/sysmacros.h>
#include <sys/types.h>
#include <sys/un.h>
#include <sys/wait.h>
@@ -487,12 +488,11 @@
mount("proc", "/proc", "proc", 0, "hidepid=2,gid=" MAKE_STR(AID_READPROC));
mount("sysfs", "/sys", "sysfs", 0, NULL);
mount("selinuxfs", "/sys/fs/selinux", "selinuxfs", 0, NULL);
+ mknod("/dev/kmsg", S_IFCHR | 0600, makedev(1, 11));
}
- // We must have some place other than / to create the device nodes for
- // kmsg and null, otherwise we won't be able to remount / read-only
- // later on. Now that tmpfs is mounted on /dev, we can actually talk
- // to the outside world.
+ // Now that tmpfs is mounted on /dev and we have /dev/kmsg, we can actually
+ // talk to the outside world...
InitKernelLogging(argv);
LOG(INFO) << "init " << (is_first_stage ? "first stage" : "second stage") << " started!";
@@ -536,6 +536,7 @@
// This must happen before /dev is populated by ueventd.
LOG(INFO) << "Running restorecon...";
restorecon("/dev");
+ restorecon("/dev/kmsg");
restorecon("/dev/socket");
restorecon("/dev/__properties__");
restorecon("/property_contexts");
diff --git a/init/log.cpp b/init/log.cpp
index 3934ca0..379141a 100644
--- a/init/log.cpp
+++ b/init/log.cpp
@@ -26,8 +26,12 @@
#include <selinux/selinux.h>
static const int kLogSeverityToKLogLevel[] = {
- KLOG_NOTICE_LEVEL, KLOG_DEBUG_LEVEL, KLOG_INFO_LEVEL,
- KLOG_WARNING_LEVEL, KLOG_ERROR_LEVEL, KLOG_ERROR_LEVEL,
+ [android::base::VERBOSE] = KLOG_DEBUG_LEVEL,
+ [android::base::DEBUG] = KLOG_DEBUG_LEVEL,
+ [android::base::INFO] = KLOG_INFO_LEVEL,
+ [android::base::WARNING] = KLOG_WARNING_LEVEL,
+ [android::base::ERROR] = KLOG_ERROR_LEVEL,
+ [android::base::FATAL] = KLOG_ERROR_LEVEL,
};
static_assert(arraysize(kLogSeverityToKLogLevel) == android::base::FATAL + 1,
"Mismatch in size of kLogSeverityToKLogLevel and values in LogSeverity");
@@ -68,7 +72,7 @@
if (fd > 2) close(fd);
android::base::InitLogging(argv, &KernelLogger);
- klog_set_level(KLOG_NOTICE_LEVEL);
+ klog_set_level(KLOG_INFO_LEVEL);
}
int selinux_klog_callback(int type, const char *fmt, ...) {
diff --git a/init/service.cpp b/init/service.cpp
index c636677..f67af2d 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -95,16 +95,16 @@
// It's OK to LOG(FATAL) in this function since it's running in the first
// child process.
if (mount("", "/proc", "proc", kSafeFlags | MS_REMOUNT, "") == -1) {
- PLOG(FATAL) << "couldn't remount(/proc)";
+ PLOG(FATAL) << "couldn't remount(/proc) for " << service_name;
}
if (prctl(PR_SET_NAME, service_name.c_str()) == -1) {
- PLOG(FATAL) << "couldn't set name";
+ PLOG(FATAL) << "couldn't set name for " << service_name;
}
pid_t child_pid = fork();
if (child_pid == -1) {
- PLOG(FATAL) << "couldn't fork init inside the PID namespace";
+ PLOG(FATAL) << "couldn't fork init inside the PID namespace for " << service_name;
}
if (child_pid > 0) {
@@ -219,31 +219,32 @@
}
void Service::SetProcessAttributes() {
- setpgid(0, getpid());
+ // TODO: work out why this fails for `console` then upgrade to FATAL.
+ if (setpgid(0, getpid()) == -1) PLOG(ERROR) << "setpgid failed for " << name_;
if (gid_) {
if (setgid(gid_) != 0) {
- PLOG(FATAL) << "setgid failed";
+ PLOG(FATAL) << "setgid failed for " << name_;
}
}
if (!supp_gids_.empty()) {
if (setgroups(supp_gids_.size(), &supp_gids_[0]) != 0) {
- PLOG(FATAL) << "setgroups failed";
+ PLOG(FATAL) << "setgroups failed for " << name_;
}
}
if (uid_) {
if (setuid(uid_) != 0) {
- PLOG(FATAL) << "setuid failed";
+ PLOG(FATAL) << "setuid failed for " << name_;
}
}
if (!seclabel_.empty()) {
if (setexeccon(seclabel_.c_str()) < 0) {
- PLOG(FATAL) << "cannot setexeccon('" << seclabel_ << "')";
+ PLOG(FATAL) << "cannot setexeccon('" << seclabel_ << "') for " << name_;
}
}
if (priority_ != 0) {
if (setpriority(PRIO_PROCESS, 0, priority_) != 0) {
- PLOG(FATAL) << "setpriority failed";
+ PLOG(FATAL) << "setpriority failed for " << name_;
}
}
}
diff --git a/libcrypto_utils/Android.mk b/libcrypto_utils/Android.mk
index 5e9763f..b6d2204 100644
--- a/libcrypto_utils/Android.mk
+++ b/libcrypto_utils/Android.mk
@@ -31,7 +31,7 @@
LOCAL_CFLAGS := -Wall -Werror -Wextra -std=c99
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
-LOCAL_SHARED_LIBRARIES := libcrypto-host
+LOCAL_SHARED_LIBRARIES := libcrypto
include $(BUILD_HOST_SHARED_LIBRARY)
include $(CLEAR_VARS)
@@ -40,7 +40,7 @@
LOCAL_CFLAGS := -Wall -Werror -Wextra -std=c99
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
-LOCAL_STATIC_LIBRARIES := libcrypto_static
+LOCAL_STATIC_LIBRARIES := libcrypto
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
diff --git a/libcrypto_utils/tests/Android.mk b/libcrypto_utils/tests/Android.mk
index dad82f7..bdaef71 100644
--- a/libcrypto_utils/tests/Android.mk
+++ b/libcrypto_utils/tests/Android.mk
@@ -20,5 +20,5 @@
LOCAL_MODULE := libcrypto_utils_test
LOCAL_SRC_FILES := android_pubkey_test.cpp
LOCAL_CFLAGS := -Wall -Werror -Wextra -std=c++11
-LOCAL_SHARED_LIBRARIES := libcrypto_utils libcrypto-host
+LOCAL_SHARED_LIBRARIES := libcrypto_utils libcrypto
include $(BUILD_HOST_NATIVE_TEST)
diff --git a/libcutils/klog.cpp b/libcutils/klog.cpp
index abf643f..061af1b 100644
--- a/libcutils/klog.cpp
+++ b/libcutils/klog.cpp
@@ -37,15 +37,7 @@
}
static int __open_klog(void) {
- int fd = open("/dev/kmsg", O_WRONLY | O_CLOEXEC);
- if (fd == -1) {
- static const char* name = "/dev/__kmsg__";
- if (mknod(name, S_IFCHR | 0600, (1 << 8) | 11) == 0) {
- fd = open(name, O_WRONLY | O_CLOEXEC);
- unlink(name);
- }
- }
- return fd;
+ return TEMP_FAILURE_RETRY(open("/dev/kmsg", O_WRONLY | O_CLOEXEC));
}
#define LOG_BUF_MAX 512
diff --git a/libmemunreachable/tests/Allocator_test.cpp b/libmemunreachable/tests/Allocator_test.cpp
index fa76ae0..21c8218 100644
--- a/libmemunreachable/tests/Allocator_test.cpp
+++ b/libmemunreachable/tests/Allocator_test.cpp
@@ -160,7 +160,7 @@
Allocator<int>::shared_ptr ptr = allocator.make_shared(0);
{
- auto ptr2 = ptr;
+ auto ptr2 = ptr; // NOLINT, test copy of ptr
}
ASSERT_NE(ptr, nullptr);
}
diff --git a/libnativeloader/Android.bp b/libnativeloader/Android.bp
new file mode 100644
index 0000000..b4a69bc
--- /dev/null
+++ b/libnativeloader/Android.bp
@@ -0,0 +1,32 @@
+// Shared library for target
+// ========================================================
+cc_library {
+ name: "libnativeloader",
+ host_supported: true,
+ srcs: ["native_loader.cpp"],
+ shared_libs: [
+ "libnativehelper",
+ "liblog",
+ "libcutils",
+ ],
+ static_libs: ["libbase"],
+ target: {
+ android: {
+ shared_libs: ["libdl"],
+ },
+ host: {
+ host_ldlibs: ["-ldl"],
+ },
+ },
+ clang: true,
+ cflags: [
+ "-Werror",
+ "-Wall",
+ ],
+ cppflags: [
+ "-std=gnu++14",
+ "-fvisibility=hidden",
+ ],
+ export_include_dirs: ["include"],
+ local_include_dirs: ["include"],
+}
diff --git a/libnativeloader/Android.mk b/libnativeloader/Android.mk
deleted file mode 100644
index c81c671..0000000
--- a/libnativeloader/Android.mk
+++ /dev/null
@@ -1,58 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-native_loader_common_src_files := \
- native_loader.cpp
-
-native_loader_common_cflags := -Werror -Wall
-
-# Shared library for target
-# ========================================================
-include $(CLEAR_VARS)
-
-LOCAL_MODULE:= libnativeloader
-
-LOCAL_SRC_FILES:= $(native_loader_common_src_files)
-LOCAL_SHARED_LIBRARIES := libnativehelper liblog libcutils libdl
-LOCAL_STATIC_LIBRARIES := libbase
-LOCAL_CLANG := true
-LOCAL_CFLAGS := $(native_loader_common_cflags)
-LOCAL_CPPFLAGS := -std=gnu++14 -fvisibility=hidden
-LOCAL_MULTILIB := both
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
-include $(BUILD_SHARED_LIBRARY)
-
-# Shared library for host
-# ========================================================
-include $(CLEAR_VARS)
-
-LOCAL_MODULE:= libnativeloader
-
-LOCAL_SRC_FILES:= $(native_loader_common_src_files)
-LOCAL_SHARED_LIBRARIES := libnativehelper liblog libcutils
-LOCAL_STATIC_LIBRARIES := libbase
-LOCAL_CLANG := true
-LOCAL_CFLAGS := $(native_loader_common_cflags)
-LOCAL_CPPFLAGS := -std=gnu++14 -fvisibility=hidden
-LOCAL_LDFLAGS := -ldl
-LOCAL_MULTILIB := both
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
-include $(BUILD_HOST_SHARED_LIBRARY)
-
-# Static library for host
-# ========================================================
-include $(CLEAR_VARS)
-
-LOCAL_MODULE:= libnativeloader
-
-LOCAL_SRC_FILES:= $(native_loader_common_src_files)
-LOCAL_STATIC_LIBRARIES := libnativehelper libcutils liblog libbase
-LOCAL_CLANG := true
-LOCAL_CFLAGS := $(native_loader_common_cflags)
-LOCAL_CPPFLAGS := -std=gnu++14 -fvisibility=hidden
-LOCAL_LDFLAGS := -ldl
-LOCAL_MULTILIB := both
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
-include $(BUILD_HOST_STATIC_LIBRARY)
diff --git a/logcat/logpersist b/logcat/logpersist
index e9982e2..f0e7d42 100755
--- a/logcat/logpersist
+++ b/logcat/logpersist
@@ -17,6 +17,7 @@
;;
esac
+log_tag_property=persist.log.tag
data=/data/misc/logd
service=logcatd
size_default=256
@@ -65,6 +66,9 @@
exit 1
fi
+log_tag="`getprop ${log_tag_property}`"
+logd_logpersistd="`getprop ${property}`"
+
case ${progname} in
*.cat)
if [ -n "${size}${buffer}" -o "true" = "${clear}" ]; then
@@ -123,6 +127,12 @@
while [ "clear" = "`getprop ${property#persist.}`" ]; do
continue
done
+ # Tell Settings that we are back on again if we turned logging off
+ tag="${log_tag#Settings}"
+ if [ X"${log_tag}" != X"${tag}" ]; then
+ echo "WARNING: enabling logd service" >&2
+ setprop ${log_tag_property} "${tag#,}"
+ fi
# ${service}.rc does the heavy lifting with the following trigger
setprop ${property} ${service}
# 20ms done, to permit process feedback check
@@ -158,3 +168,9 @@
echo "ERROR: Unexpected command ${0##*/} ${args}" >&2
exit 1
esac
+
+if [ X"${log_tag}" != X"`getprop ${log_tag_property}`" ] ||
+ [ X"${logd_logpersistd}" != X"`getprop ${property}`" ]; then
+ echo "WARNING: killing Settings" >&2
+ am force-stop com.android.settings
+fi
diff --git a/metricsd/uploader/sender_http.cc b/metricsd/uploader/sender_http.cc
index 4b572a6..1f775df 100644
--- a/metricsd/uploader/sender_http.cc
+++ b/metricsd/uploader/sender_http.cc
@@ -23,7 +23,7 @@
#include <brillo/http/http_utils.h>
#include <brillo/mime_utils.h>
-HttpSender::HttpSender(const std::string server_url)
+HttpSender::HttpSender(const std::string& server_url)
: server_url_(server_url) {}
bool HttpSender::Send(const std::string& content,
diff --git a/metricsd/uploader/sender_http.h b/metricsd/uploader/sender_http.h
index 4f1c08f..0d64c74 100644
--- a/metricsd/uploader/sender_http.h
+++ b/metricsd/uploader/sender_http.h
@@ -26,7 +26,7 @@
// Sender implemented using http_utils from libbrillo
class HttpSender : public Sender {
public:
- explicit HttpSender(std::string server_url);
+ explicit HttpSender(const std::string& server_url);
~HttpSender() override = default;
// Sends |content| whose SHA1 hash is |hash| to server_url with a synchronous
// POST request to server_url.
diff --git a/rootdir/init.usb.configfs.rc b/rootdir/init.usb.configfs.rc
index e19b058..dc875b4 100644
--- a/rootdir/init.usb.configfs.rc
+++ b/rootdir/init.usb.configfs.rc
@@ -5,6 +5,10 @@
write /config/usb_gadget/g1/bDeviceClass 0
write /config/usb_gadget/g1/bDeviceSubClass 0
write /config/usb_gadget/g1/bDeviceProtocol 0
+ rm /config/usb_gadget/g1/configs/b.1/f1
+ rm /config/usb_gadget/g1/configs/b.1/f2
+ rm /config/usb_gadget/g1/configs/b.1/f3
+ rmdir /config/usb_gadget/g1/functions/rndis.gs4
setprop sys.usb.state ${sys.usb.config}
on property:sys.usb.config=adb && property:sys.usb.configfs=1
@@ -12,18 +16,12 @@
on property:sys.usb.ffs.ready=1 && property:sys.usb.config=adb && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "adb"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}
on property:sys.usb.config=mtp && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "mtp"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/mtp.gs0 /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}
@@ -33,9 +31,6 @@
on property:sys.usb.ffs.ready=1 && property:sys.usb.config=mtp,adb && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "mtp_adb"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/mtp.gs0 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
@@ -43,9 +38,6 @@
on property:sys.usb.config=ptp && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "ptp"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/ptp.gs1 /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}
@@ -55,9 +47,6 @@
on property:sys.usb.ffs.ready=1 && property:sys.usb.config=ptp,adb && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "ptp_adb"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/ptp.gs1 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
@@ -65,9 +54,6 @@
on property:sys.usb.config=accessory && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "accessory"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/accessory.gs2 /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}
@@ -77,9 +63,6 @@
on property:sys.usb.ffs.ready=1 && property:sys.usb.config=accessory,adb && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "accessory_adb"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/accessory.gs2 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
@@ -87,9 +70,6 @@
on property:sys.usb.config=audio_source && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "audiosource"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/audio_source.gs2 /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}
@@ -99,9 +79,6 @@
on property:sys.usb.ffs.ready=1 && property:sys.usb.config=audio_source,adb && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "audiosource_adb"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/audio_source.gs2 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
@@ -109,9 +86,6 @@
on property:sys.usb.config=accessory,audio_source && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "accessory_audiosource"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/accessory.gs2 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/audio_source.gs3 /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
@@ -122,9 +96,6 @@
on property:sys.usb.ffs.ready=1 && property:sys.usb.config=accessory,audio_source,adb && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "accessory_audiosource_adb"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/accessory.gs2 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/audio_source.gs3 /config/usb_gadget/g1/configs/b.1/f2
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f3
@@ -133,9 +104,6 @@
on property:sys.usb.config=midi && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "midi"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/midi.gs5 /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}
@@ -145,19 +113,14 @@
on property:sys.usb.ffs.ready=1 && property:sys.usb.config=midi,adb && property:sys.usb.configfs=1
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "midi_adb"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/midi.gs5 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}
on property:sys.usb.config=rndis && property:sys.usb.configfs=1
+ mkdir /config/usb_gadget/g1/functions/rndis.gs4
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "rndis"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/rndis.gs4 /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
setprop sys.usb.state ${sys.usb.config}
@@ -166,10 +129,8 @@
start adbd
on property:sys.usb.ffs.ready=1 && property:sys.usb.config=rndis,adb && property:sys.usb.configfs=1
+ mkdir /config/usb_gadget/g1/functions/rndis.gs4
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "rndis_adb"
- rm /config/usb_gadget/g1/configs/b.1/f1
- rm /config/usb_gadget/g1/configs/b.1/f2
- rm /config/usb_gadget/g1/configs/b.1/f3
symlink /config/usb_gadget/g1/functions/rndis.gs4 /config/usb_gadget/g1/configs/b.1/f1
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
write /config/usb_gadget/g1/UDC ${sys.usb.controller}
diff --git a/sdcard/Android.mk b/sdcard/Android.mk
index 992b51c..0c58574 100644
--- a/sdcard/Android.mk
+++ b/sdcard/Android.mk
@@ -5,7 +5,7 @@
LOCAL_SRC_FILES := sdcard.cpp fuse.cpp
LOCAL_MODULE := sdcard
LOCAL_CFLAGS := -Wall -Wno-unused-parameter -Werror
-LOCAL_SHARED_LIBRARIES := libbase liblog libcutils libminijail libpackagelistparser
+LOCAL_SHARED_LIBRARIES := libbase libcutils libminijail libpackagelistparser
LOCAL_SANITIZE := integer
LOCAL_CLANG := true
diff --git a/sdcard/fuse.cpp b/sdcard/fuse.cpp
index 9b1b190..47e4257 100644
--- a/sdcard/fuse.cpp
+++ b/sdcard/fuse.cpp
@@ -18,6 +18,8 @@
#include "fuse.h"
+#include <android-base/logging.h>
+
#define FUSE_UNKNOWN_INO 0xffffffff
/* Pseudo-error constant used to indicate that no fuse status is needed
@@ -37,18 +39,20 @@
static void acquire_node_locked(struct node* node)
{
node->refcount++;
- TRACE("ACQUIRE %p (%s) rc=%d\n", node, node->name, node->refcount);
+ DLOG(INFO) << "ACQUIRE " << std::hex << node << std::dec
+ << " (" << node->name << ") rc=" << node->refcount;
}
static void remove_node_from_parent_locked(struct node* node);
static void release_node_locked(struct node* node)
{
- TRACE("RELEASE %p (%s) rc=%d\n", node, node->name, node->refcount);
+ DLOG(INFO) << "RELEASE " << std::hex << node << std::dec
+ << " (" << node->name << ") rc=" << node->refcount;
if (node->refcount > 0) {
node->refcount--;
if (!node->refcount) {
- TRACE("DESTROY %p (%s)\n", node, node->name);
+ DLOG(INFO) << "DESTROY " << std::hex << node << std::dec << " (" << node->name << ")";
remove_node_from_parent_locked(node);
/* TODO: remove debugging - poison memory */
@@ -59,7 +63,7 @@
free(node);
}
} else {
- ERROR("Zero refcnt %p\n", node);
+ LOG(ERROR) << std::hex << node << std::dec << " refcount=0";
}
}
@@ -153,7 +157,7 @@
struct dirent* entry;
DIR* dir = opendir(path);
if (!dir) {
- ERROR("opendir %s failed: %s\n", path, strerror(errno));
+ PLOG(ERROR) << "opendir(" << path << ") failed";
return actual;
}
while ((entry = readdir(dir))) {
@@ -221,7 +225,7 @@
if (errno == EEXIST) {
return 0;
} else {
- ERROR("Failed to open(%s): %s\n", path, strerror(errno));
+ PLOG(ERROR) << "open(" << path << ") failed";
return -1;
}
}
@@ -333,7 +337,7 @@
// Detect overflows in the inode counter. "4 billion nodes should be enough
// for everybody".
if (fuse->global->inode_ctr == 0) {
- ERROR("No more inode numbers available");
+ LOG(ERROR) << "No more inode numbers available";
return NULL;
}
@@ -482,7 +486,7 @@
res = writev(fuse->fd, vec, 2);
if (res < 0) {
- ERROR("*** REPLY FAILED *** %d\n", errno);
+ PLOG(ERROR) << "*** REPLY FAILED ***";
}
}
@@ -558,7 +562,7 @@
res = writev(fuse->fd, vec, 3);
/* Ignore ENOENT, since other views may not have seen the entry */
if (res < 0 && errno != ENOENT) {
- ERROR("*** NOTIFY FAILED *** %d\n", errno);
+ PLOG(ERROR) << "*** NOTIFY FAILED ***";
}
}
@@ -573,8 +577,8 @@
pthread_mutex_lock(&fuse->global->lock);
parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
parent_path, sizeof(parent_path));
- TRACE("[%d] LOOKUP %s @ %" PRIx64 " (%s)\n", handler->token, name, hdr->nodeid,
- parent_node ? parent_node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] LOOKUP " << name << " @ " << hdr->nodeid
+ << " (" << (parent_node ? parent_node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!parent_node || !(actual_name = find_file_within(parent_path, name,
@@ -595,8 +599,9 @@
pthread_mutex_lock(&fuse->global->lock);
node = lookup_node_by_id_locked(fuse, hdr->nodeid);
- TRACE("[%d] FORGET #%" PRIu64 " @ %" PRIx64 " (%s)\n", handler->token, req->nlookup,
- hdr->nodeid, node ? node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] FORGET #" << req->nlookup
+ << " @ " << std::hex << hdr->nodeid
+ << " (" << (node ? node->name : "?") << ")";
if (node) {
__u64 n = req->nlookup;
while (n) {
@@ -616,8 +621,9 @@
pthread_mutex_lock(&fuse->global->lock);
node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
- TRACE("[%d] GETATTR flags=%x fh=%" PRIx64 " @ %" PRIx64 " (%s)\n", handler->token,
- req->getattr_flags, req->fh, hdr->nodeid, node ? node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] GETATTR flags=" << req->getattr_flags
+ << " fh=" << std::hex << req->fh << " @ " << hdr->nodeid << std::dec
+ << " (" << (node ? node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!node) {
@@ -639,8 +645,9 @@
pthread_mutex_lock(&fuse->global->lock);
node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
- TRACE("[%d] SETATTR fh=%" PRIx64 " valid=%x @ %" PRIx64 " (%s)\n", handler->token,
- req->fh, req->valid, hdr->nodeid, node ? node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] SETATTR fh=" << std::hex << req->fh
+ << " valid=" << std::hex << req->valid << " @ " << hdr->nodeid << std::dec
+ << " (" << (node ? node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!node) {
@@ -684,8 +691,8 @@
times[1].tv_nsec = req->mtimensec;
}
}
- TRACE("[%d] Calling utimensat on %s with atime %ld, mtime=%ld\n",
- handler->token, path, times[0].tv_sec, times[1].tv_sec);
+ DLOG(INFO) << "[" << handler->token << "] Calling utimensat on " << path
+ << " with atime " << times[0].tv_sec << ", mtime=" << times[1].tv_sec;
if (utimensat(-1, path, times, 0) < 0) {
return -errno;
}
@@ -704,8 +711,9 @@
pthread_mutex_lock(&fuse->global->lock);
parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
parent_path, sizeof(parent_path));
- TRACE("[%d] MKNOD %s 0%o @ %" PRIx64 " (%s)\n", handler->token,
- name, req->mode, hdr->nodeid, parent_node ? parent_node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] MKNOD " << name << " 0" << std::oct << req->mode
+ << " @ " << std::hex << hdr->nodeid
+ << " (" << (parent_node ? parent_node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!parent_node || !(actual_name = find_file_within(parent_path, name,
@@ -733,8 +741,9 @@
pthread_mutex_lock(&fuse->global->lock);
parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
parent_path, sizeof(parent_path));
- TRACE("[%d] MKDIR %s 0%o @ %" PRIx64 " (%s)\n", handler->token,
- name, req->mode, hdr->nodeid, parent_node ? parent_node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] MKDIR " << name << " 0" << std::oct << req->mode
+ << " @ " << std::hex << hdr->nodeid
+ << " (" << (parent_node ? parent_node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!parent_node || !(actual_name = find_file_within(parent_path, name,
@@ -754,7 +763,7 @@
char nomedia[PATH_MAX];
snprintf(nomedia, PATH_MAX, "%s/.nomedia", child_path);
if (touch(nomedia, 0664) != 0) {
- ERROR("Failed to touch(%s): %s\n", nomedia, strerror(errno));
+ PLOG(ERROR) << "touch(" << nomedia << ") failed";
return -ENOENT;
}
}
@@ -762,7 +771,7 @@
char nomedia[PATH_MAX];
snprintf(nomedia, PATH_MAX, "%s/.nomedia", fuse->global->obb_path);
if (touch(nomedia, 0664) != 0) {
- ERROR("Failed to touch(%s): %s\n", nomedia, strerror(errno));
+ PLOG(ERROR) << "touch(" << nomedia << ") failed";
return -ENOENT;
}
}
@@ -781,8 +790,8 @@
pthread_mutex_lock(&fuse->global->lock);
parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
parent_path, sizeof(parent_path));
- TRACE("[%d] UNLINK %s @ %" PRIx64 " (%s)\n", handler->token,
- name, hdr->nodeid, parent_node ? parent_node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] UNLINK " << name << " @ " << std::hex << hdr->nodeid
+ << " (" << (parent_node ? parent_node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!parent_node || !find_file_within(parent_path, name,
@@ -803,8 +812,10 @@
pthread_mutex_unlock(&fuse->global->lock);
if (parent_node && child_node) {
/* Tell all other views that node is gone */
- TRACE("[%d] fuse_notify_delete parent=%" PRIx64 ", child=%" PRIx64 ", name=%s\n",
- handler->token, (uint64_t) parent_node->nid, (uint64_t) child_node->nid, name);
+ DLOG(INFO) << "[" << handler->token << "] fuse_notify_delete"
+ << " parent=" << std::hex << parent_node->nid
+ << ", child=" << std::hex << child_node->nid << std::dec
+ << ", name=" << name;
if (fuse != fuse->global->fuse_default) {
fuse_notify_delete(fuse->global->fuse_default, parent_node->nid, child_node->nid, name);
}
@@ -829,8 +840,8 @@
pthread_mutex_lock(&fuse->global->lock);
parent_node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid,
parent_path, sizeof(parent_path));
- TRACE("[%d] RMDIR %s @ %" PRIx64 " (%s)\n", handler->token,
- name, hdr->nodeid, parent_node ? parent_node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] UNLINK " << name << " @ " << std::hex << hdr->nodeid
+ << " (" << (parent_node ? parent_node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!parent_node || !find_file_within(parent_path, name,
@@ -851,8 +862,10 @@
pthread_mutex_unlock(&fuse->global->lock);
if (parent_node && child_node) {
/* Tell all other views that node is gone */
- TRACE("[%d] fuse_notify_delete parent=%" PRIx64 ", child=%" PRIx64 ", name=%s\n",
- handler->token, (uint64_t) parent_node->nid, (uint64_t) child_node->nid, name);
+ DLOG(INFO) << "[" << handler->token << "] fuse_notify_delete"
+ << " parent=" << std::hex << parent_node->nid
+ << ", child=" << std::hex << child_node->nid << std::dec
+ << ", name=" << name;
if (fuse != fuse->global->fuse_default) {
fuse_notify_delete(fuse->global->fuse_default, parent_node->nid, child_node->nid, name);
}
@@ -886,10 +899,11 @@
old_parent_path, sizeof(old_parent_path));
new_parent_node = lookup_node_and_path_by_id_locked(fuse, req->newdir,
new_parent_path, sizeof(new_parent_path));
- TRACE("[%d] RENAME %s->%s @ %" PRIx64 " (%s) -> %" PRIx64 " (%s)\n", handler->token,
- old_name, new_name,
- hdr->nodeid, old_parent_node ? old_parent_node->name : "?",
- req->newdir, new_parent_node ? new_parent_node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] RENAME " << old_name << "->" << new_name
+ << " @ " << std::hex << hdr->nodeid
+ << " (" << (old_parent_node ? old_parent_node->name : "?") << ") -> "
+ << std::hex << req->newdir
+ << " (" << (new_parent_node ? new_parent_node->name : "?") << ")";
if (!old_parent_node || !new_parent_node) {
res = -ENOENT;
goto lookup_error;
@@ -923,7 +937,7 @@
goto io_error;
}
- TRACE("[%d] RENAME %s->%s\n", handler->token, old_child_path, new_child_path);
+ DLOG(INFO) << "[" << handler->token << "] RENAME " << old_child_path << "->" << new_child_path;
res = rename(old_child_path, new_child_path);
if (res < 0) {
res = -errno;
@@ -970,8 +984,9 @@
pthread_mutex_lock(&fuse->global->lock);
node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
- TRACE("[%d] OPEN 0%o @ %" PRIx64 " (%s)\n", handler->token,
- req->flags, hdr->nodeid, node ? node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] OPEN 0" << std::oct << req->flags
+ << " @ " << std::hex << hdr->nodeid << std::dec
+ << " (" << (node ? node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!node) {
@@ -985,7 +1000,7 @@
if (!h) {
return -ENOMEM;
}
- TRACE("[%d] OPEN %s\n", handler->token, path);
+ DLOG(INFO) << "[" << handler->token << "] OPEN " << path;
h->fd = open(path, req->flags);
if (h->fd < 0) {
free(h);
@@ -1018,8 +1033,8 @@
* overlaps the request buffer and will clobber data in the request. This
* saves us 128KB per request handler thread at the cost of this scary comment. */
- TRACE("[%d] READ %p(%d) %u@%" PRIu64 "\n", handler->token,
- h, h->fd, size, (uint64_t) offset);
+ DLOG(INFO) << "[" << handler->token << "] READ " << std::hex << h << std::dec
+ << "(" << h->fd << ") " << size << "@" << offset;
if (size > MAX_READ) {
return -EINVAL;
}
@@ -1045,8 +1060,8 @@
buffer = (const __u8*) aligned_buffer;
}
- TRACE("[%d] WRITE %p(%d) %u@%" PRIu64 "\n", handler->token,
- h, h->fd, req->size, req->offset);
+ DLOG(INFO) << "[" << handler->token << "] WRITE " << std::hex << h << std::dec
+ << "(" << h->fd << ") " << req->size << "@" << req->offset;
res = pwrite64(h->fd, buffer, req->size, req->offset);
if (res < 0) {
return -errno;
@@ -1066,7 +1081,7 @@
int res;
pthread_mutex_lock(&fuse->global->lock);
- TRACE("[%d] STATFS\n", handler->token);
+ DLOG(INFO) << "[" << handler->token << "] STATFS";
res = get_node_path_locked(&fuse->global->root, path, sizeof(path));
pthread_mutex_unlock(&fuse->global->lock);
if (res < 0) {
@@ -1093,7 +1108,8 @@
{
struct handle *h = static_cast<struct handle*>(id_to_ptr(req->fh));
- TRACE("[%d] RELEASE %p(%d)\n", handler->token, h, h->fd);
+ DLOG(INFO) << "[" << handler->token << "] RELEASE " << std::hex << h << std::dec
+ << "(" << h->fd << ")";
close(h->fd);
free(h);
return 0;
@@ -1114,9 +1130,8 @@
fd = h->fd;
}
- TRACE("[%d] %s %p(%d) is_data_sync=%d\n", handler->token,
- is_dir ? "FSYNCDIR" : "FSYNC",
- static_cast<struct node*>(id_to_ptr(req->fh)), fd, is_data_sync);
+ DLOG(INFO) << "[" << handler->token << "] " << (is_dir ? "FSYNCDIR" : "FSYNC") << " "
+ << std::hex << req->fh << std::dec << "(" << fd << ") is_data_sync=" << is_data_sync;
int res = is_data_sync ? fdatasync(fd) : fsync(fd);
if (res == -1) {
return -errno;
@@ -1127,7 +1142,7 @@
static int handle_flush(struct fuse* fuse, struct fuse_handler* handler,
const struct fuse_in_header* hdr)
{
- TRACE("[%d] FLUSH\n", handler->token);
+ DLOG(INFO) << "[" << handler->token << "] FLUSH";
return 0;
}
@@ -1141,8 +1156,8 @@
pthread_mutex_lock(&fuse->global->lock);
node = lookup_node_and_path_by_id_locked(fuse, hdr->nodeid, path, sizeof(path));
- TRACE("[%d] OPENDIR @ %" PRIx64 " (%s)\n", handler->token,
- hdr->nodeid, node ? node->name : "?");
+ DLOG(INFO) << "[" << handler->token << "] OPENDIR @ " << std::hex << hdr->nodeid
+ << " (" << (node ? node->name : "?") << ")";
pthread_mutex_unlock(&fuse->global->lock);
if (!node) {
@@ -1155,7 +1170,7 @@
if (!h) {
return -ENOMEM;
}
- TRACE("[%d] OPENDIR %s\n", handler->token, path);
+ DLOG(INFO) << "[" << handler->token << "] OPENDIR " << path;
h->d = opendir(path);
if (!h->d) {
free(h);
@@ -1182,10 +1197,10 @@
struct dirent *de;
struct dirhandle *h = static_cast<struct dirhandle*>(id_to_ptr(req->fh));
- TRACE("[%d] READDIR %p\n", handler->token, h);
+ DLOG(INFO) << "[" << handler->token << "] READDIR " << h;
if (req->offset == 0) {
/* rewinddir() might have been called above us, so rewind here too */
- TRACE("[%d] calling rewinddir()\n", handler->token);
+ DLOG(INFO) << "[" << handler->token << "] calling rewinddir()";
rewinddir(h->d);
}
de = readdir(h->d);
@@ -1208,7 +1223,7 @@
{
struct dirhandle *h = static_cast<struct dirhandle*>(id_to_ptr(req->fh));
- TRACE("[%d] RELEASEDIR %p\n", handler->token, h);
+ DLOG(INFO) << "[" << handler->token << "] RELEASEDIR " << h;
closedir(h->d);
free(h);
return 0;
@@ -1220,8 +1235,8 @@
struct fuse_init_out out;
size_t fuse_struct_size;
- TRACE("[%d] INIT ver=%d.%d maxread=%d flags=%x\n",
- handler->token, req->major, req->minor, req->max_readahead, req->flags);
+ DLOG(INFO) << "[" << handler->token << "] INIT ver=" << req->major << "." << req->minor
+ << " maxread=" << req->max_readahead << " flags=" << std::hex << req->flags;
/* Kernel 2.6.16 is the first stable kernel with struct fuse_init_out
* defined (fuse version 7.6). The structure is the same from 7.6 through
@@ -1229,8 +1244,9 @@
* new parameters.
*/
if (req->major != FUSE_KERNEL_VERSION || req->minor < 6) {
- ERROR("Fuse kernel version mismatch: Kernel version %d.%d, Expected at least %d.6",
- req->major, req->minor, FUSE_KERNEL_VERSION);
+ LOG(ERROR) << "Fuse kernel version mismatch: Kernel version "
+ << req->major << "." << req->minor
+ << ", Expected at least " << FUSE_KERNEL_VERSION << ".6";
return -1;
}
@@ -1379,8 +1395,8 @@
}
default: {
- TRACE("[%d] NOTIMPL op=%d uniq=%" PRIx64 " nid=%" PRIx64 "\n",
- handler->token, hdr->opcode, hdr->unique, hdr->nodeid);
+ DLOG(INFO) << "[" << handler->token << "] NOTIMPL op=" << hdr->opcode
+ << "uniq=" << std::hex << hdr->unique << "nid=" << hdr->nodeid << std::dec;
return -ENOSYS;
}
}
@@ -1394,23 +1410,23 @@
handler->request_buffer, sizeof(handler->request_buffer)));
if (len < 0) {
if (errno == ENODEV) {
- ERROR("[%d] someone stole our marbles!\n", handler->token);
+ LOG(ERROR) << "[" << handler->token << "] someone stole our marbles!";
exit(2);
}
- ERROR("[%d] handle_fuse_requests: errno=%d\n", handler->token, errno);
+ PLOG(ERROR) << "[" << handler->token << "] handle_fuse_requests";
continue;
}
if ((size_t)len < sizeof(struct fuse_in_header)) {
- ERROR("[%d] request too short: len=%zu\n", handler->token, (size_t)len);
+ LOG(ERROR) << "[" << handler->token << "] request too short: len=" << len;
continue;
}
const struct fuse_in_header* hdr =
reinterpret_cast<const struct fuse_in_header*>(handler->request_buffer);
if (hdr->len != (size_t)len) {
- ERROR("[%d] malformed header: len=%zu, hdr->len=%u\n",
- handler->token, (size_t)len, hdr->len);
+ LOG(ERROR) << "[" << handler->token << "] malformed header: len=" << len
+ << ", hdr->len=" << hdr->len;
continue;
}
@@ -1424,7 +1440,7 @@
if (res != NO_STATUS) {
if (res) {
- TRACE("[%d] ERROR %d\n", handler->token, res);
+ DLOG(INFO) << "[" << handler->token << "] ERROR " << res;
}
fuse_status(fuse, unique, res);
}
diff --git a/sdcard/fuse.h b/sdcard/fuse.h
index 634fbf1..9ccd21d 100644
--- a/sdcard/fuse.h
+++ b/sdcard/fuse.h
@@ -33,23 +33,24 @@
#include <map>
#include <string>
+#include <android-base/logging.h>
#include <cutils/fs.h>
-#include <cutils/log.h>
#include <cutils/multiuser.h>
#include <packagelistparser/packagelistparser.h>
#include <private/android_filesystem_config.h>
-// TODO(b/30222003): Fix compilation with FUSE_TRACE == 1.
#define FUSE_TRACE 0
#if FUSE_TRACE
-#define TRACE(x...) ALOGD(x)
-#else
-#define TRACE(x...) do {} while (0)
+static constexpr bool kEnableDLog = true;
+#else // FUSE_TRACE == 0
+static constexpr bool kEnableDLog = false;
#endif
-#define ERROR(x...) ALOGE(x)
+// Use same strategy as DCHECK().
+#define DLOG(x) \
+ if (kEnableDLog) LOG(x)
/* Maximum number of bytes to write in one request. */
#define MAX_WRITE (256 * 1024)
diff --git a/sdcard/sdcard.cpp b/sdcard/sdcard.cpp
index 3d7bdc9..3481ec3 100644
--- a/sdcard/sdcard.cpp
+++ b/sdcard/sdcard.cpp
@@ -32,7 +32,6 @@
#include <android-base/macros.h>
#include <cutils/fs.h>
-#include <cutils/log.h>
#include <cutils/multiuser.h>
#include <packagelistparser/packagelistparser.h>
@@ -89,8 +88,7 @@
global->package_to_appid->clear();
bool rc = packagelist_parse(package_parse_callback, global);
- TRACE("read_package_list: found %zu packages\n",
- global->package_to_appid->size());
+ DLOG(INFO) << "read_package_list: found " << global->package_to_appid->size() << " packages";
// Regenerate ownership details using newly loaded mapping.
derive_permissions_recursive_locked(global->fuse_default, &global->root);
@@ -148,7 +146,7 @@
int event_size;
event = (struct inotify_event *) (event_buf + event_pos);
- TRACE("inotify event: %08x\n", event->mask);
+ DLOG(INFO) << "inotify event: " << std::hex << event->mask << std::dec;
if ((event->mask & IN_IGNORED) == IN_IGNORED) {
/* Previously watched file was deleted, probably due to move
* that swapped in new data; re-arm the watch and read. */
diff --git a/trusty/nvram/Android.mk b/trusty/nvram/Android.mk
index 18c54d5..44e2212 100644
--- a/trusty/nvram/Android.mk
+++ b/trusty/nvram/Android.mk
@@ -22,9 +22,22 @@
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := \
module.c \
+ trusty_nvram_device.cpp \
trusty_nvram_implementation.cpp
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS := -Wall -Werror -Wextra -fvisibility=hidden
LOCAL_STATIC_LIBRARIES := libnvram-hal
LOCAL_SHARED_LIBRARIES := libtrusty libnvram-messages liblog
include $(BUILD_SHARED_LIBRARY)
+
+# nvram-wipe is a helper tool for clearing NVRAM state.
+include $(CLEAR_VARS)
+LOCAL_MODULE := nvram-wipe
+LOCAL_SRC_FILES := \
+ nvram_wipe.cpp \
+ trusty_nvram_implementation.cpp
+LOCAL_MODULE_TAGS := optional
+LOCAL_CFLAGS := -Wall -Werror -Wextra -fvisibility=hidden
+LOCAL_STATIC_LIBRARIES := libnvram-hal
+LOCAL_SHARED_LIBRARIES := libtrusty libnvram-messages liblog
+include $(BUILD_EXECUTABLE)
diff --git a/trusty/nvram/module.c b/trusty/nvram/module.c
index 06819c0..a2e64d3 100644
--- a/trusty/nvram/module.c
+++ b/trusty/nvram/module.c
@@ -16,7 +16,7 @@
#include <hardware/nvram.h>
-// This function is defined in trusty_nvram_implementation.cpp.
+// This function is defined in trusty_nvram_device.cpp.
int trusty_nvram_open(const hw_module_t* module,
const char* device_id,
hw_device_t** device_ptr);
diff --git a/trusty/nvram/nvram_wipe.cpp b/trusty/nvram/nvram_wipe.cpp
new file mode 100644
index 0000000..d0f4fad
--- /dev/null
+++ b/trusty/nvram/nvram_wipe.cpp
@@ -0,0 +1,66 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <nvram/messages/nvram_messages.h>
+
+#include "trusty_nvram_implementation.h"
+
+void usage(const char* program_name) {
+ fprintf(stderr, "Usage: %s [status|disable|wipe]\n", program_name);
+ exit(-1);
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 2) {
+ usage(argv[0]);
+ }
+
+ nvram::TrustyNvramImplementation nvram_proxy;
+ nvram::Request request;
+ nvram::Response response;
+
+ if (!strcmp(argv[1], "status")) {
+ request.payload.Activate<nvram::COMMAND_GET_INFO>();
+ nvram_proxy.Execute(request, &response);
+ const nvram::GetInfoResponse* get_info_response =
+ response.payload.get<nvram::COMMAND_GET_INFO>();
+ if (response.result == NV_RESULT_SUCCESS) {
+ int status = get_info_response && get_info_response->wipe_disabled;
+ printf("Wiping disabled: %d\n", status);
+ return status;
+ }
+ } else if (!strcmp(argv[1], "disable")) {
+ request.payload.Activate<nvram::COMMAND_DISABLE_WIPE>();
+ nvram_proxy.Execute(request, &response);
+ } else if (!strcmp(argv[1], "wipe")) {
+ request.payload.Activate<nvram::COMMAND_WIPE_STORAGE>();
+ nvram_proxy.Execute(request, &response);
+ } else {
+ usage(argv[0]);
+ }
+
+ if (response.result != NV_RESULT_SUCCESS) {
+ fprintf(stderr, "Command execution failure: %u\n", response.result);
+ return -1;
+ }
+
+ return 0;
+}
+
diff --git a/trusty/nvram/trusty_nvram_device.cpp b/trusty/nvram/trusty_nvram_device.cpp
new file mode 100644
index 0000000..2c50915
--- /dev/null
+++ b/trusty/nvram/trusty_nvram_device.cpp
@@ -0,0 +1,32 @@
+/*
+ * 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 <nvram/hal/nvram_device_adapter.h>
+
+#include "trusty_nvram_implementation.h"
+
+extern "C" int trusty_nvram_open(const hw_module_t* module,
+ const char* device_id,
+ hw_device_t** device_ptr) {
+ if (strcmp(NVRAM_HARDWARE_DEVICE_ID, device_id) != 0) {
+ return -EINVAL;
+ }
+
+ nvram::NvramDeviceAdapter* adapter = new nvram::NvramDeviceAdapter(
+ module, new nvram::TrustyNvramImplementation);
+ *device_ptr = adapter->as_device();
+ return 0;
+}
diff --git a/trusty/nvram/trusty_nvram_implementation.cpp b/trusty/nvram/trusty_nvram_implementation.cpp
index 39496b4..041c1bd 100644
--- a/trusty/nvram/trusty_nvram_implementation.cpp
+++ b/trusty/nvram/trusty_nvram_implementation.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include "trusty_nvram_implementation.h"
+
#include <errno.h>
#include <string.h>
@@ -23,10 +25,9 @@
#define LOG_TAG "TrustyNVRAM"
#include <log/log.h>
-#include <nvram/hal/nvram_device_adapter.h>
#include <nvram/messages/blob.h>
-#include <nvram/messages/nvram_messages.h>
+namespace nvram {
namespace {
// Character device to open for Trusty IPC connections.
@@ -35,35 +36,7 @@
// App identifier of the NVRAM app.
const char kTrustyNvramAppId[] = "com.android.trusty.nvram";
-// |TrustyNvramImplementation| proxies requests to the Trusty NVRAM app. It
-// serializes the request objects, sends it to the Trusty app and finally reads
-// back the result and decodes it.
-class TrustyNvramImplementation : public nvram::NvramImplementation {
- public:
- ~TrustyNvramImplementation() override;
-
- void Execute(const nvram::Request& request,
- nvram::Response* response) override;
-
- private:
- // Connects the IPC channel to the Trusty app if it is not already open.
- // Returns true if the channel is open, false on errors.
- bool Connect();
-
- // Dispatches a command to the trust app. Returns true if successful (note
- // that the response may still indicate an error on the Trusty side), false if
- // there are any I/O or encoding/decoding errors.
- bool SendRequest(const nvram::Request& request,
- nvram::Response* response);
-
- // The file descriptor for the IPC connection to the Trusty app.
- int tipc_nvram_fd_ = -1;
-
- // Response buffer. This puts a hard size limit on the responses from the
- // Trusty app. 4096 matches the maximum IPC message size currently supported
- // by Trusty.
- uint8_t response_buffer_[4096];
-};
+} // namespace
TrustyNvramImplementation::~TrustyNvramImplementation() {
if (tipc_nvram_fd_ != -1) {
@@ -136,17 +109,4 @@
return true;
}
-} // namespace
-
-extern "C" int trusty_nvram_open(const hw_module_t* module,
- const char* device_id,
- hw_device_t** device_ptr) {
- if (strcmp(NVRAM_HARDWARE_DEVICE_ID, device_id) != 0) {
- return -EINVAL;
- }
-
- nvram::NvramDeviceAdapter* adapter =
- new nvram::NvramDeviceAdapter(module, new TrustyNvramImplementation);
- *device_ptr = adapter->as_device();
- return 0;
-}
+} // namespace nvram
diff --git a/trusty/nvram/trusty_nvram_implementation.h b/trusty/nvram/trusty_nvram_implementation.h
new file mode 100644
index 0000000..60758f7
--- /dev/null
+++ b/trusty/nvram/trusty_nvram_implementation.h
@@ -0,0 +1,59 @@
+/*
+ * 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 TRUSTY_NVRAM_TRUSTY_NVRAM_IMPLEMENTATION_H_
+#define TRUSTY_NVRAM_TRUSTY_NVRAM_IMPLEMENTATION_H_
+
+#include <stdint.h>
+
+#include <nvram/hal/nvram_device_adapter.h>
+#include <nvram/messages/nvram_messages.h>
+
+namespace nvram {
+
+// |TrustyNvramImplementation| proxies requests to the Trusty NVRAM app. It
+// serializes the request objects, sends it to the Trusty app and finally reads
+// back the result and decodes it.
+class TrustyNvramImplementation : public nvram::NvramImplementation {
+ public:
+ ~TrustyNvramImplementation() override;
+
+ void Execute(const nvram::Request& request,
+ nvram::Response* response) override;
+
+ private:
+ // Connects the IPC channel to the Trusty app if it is not already open.
+ // Returns true if the channel is open, false on errors.
+ bool Connect();
+
+ // Dispatches a command to the trust app. Returns true if successful (note
+ // that the response may still indicate an error on the Trusty side), false if
+ // there are any I/O or encoding/decoding errors.
+ bool SendRequest(const nvram::Request& request,
+ nvram::Response* response);
+
+ // The file descriptor for the IPC connection to the Trusty app.
+ int tipc_nvram_fd_ = -1;
+
+ // Response buffer. This puts a hard size limit on the responses from the
+ // Trusty app. 4096 matches the maximum IPC message size currently supported
+ // by Trusty.
+ uint8_t response_buffer_[4096];
+};
+
+} // namespace nvram
+
+#endif // TRUSTY_NVRAM_TRUSTY_NVRAM_IMPLEMENTATION_H_