Merge "Remove sys.usb.ffs.mtp.ready property" into pi-dev
diff --git a/adb/daemon/usb.cpp b/adb/daemon/usb.cpp
index c2e9337..7869324 100644
--- a/adb/daemon/usb.cpp
+++ b/adb/daemon/usb.cpp
@@ -437,23 +437,29 @@
num_bufs += 1;
}
- if (io_submit(aiob->ctx, num_bufs, aiob->iocbs.data()) < num_bufs) {
- D("[ aio: got error submitting %s (%d) ]", read ? "read" : "write", errno);
- return -1;
- }
- if (TEMP_FAILURE_RETRY(
- io_getevents(aiob->ctx, num_bufs, num_bufs, aiob->events.data(), nullptr)) < num_bufs) {
- D("[ aio: got error waiting %s (%d) ]", read ? "read" : "write", errno);
- return -1;
- }
- for (int i = 0; i < num_bufs; i++) {
- if (aiob->events[i].res < 0) {
- errno = aiob->events[i].res;
- D("[ aio: got error event on %s (%d) ]", read ? "read" : "write", errno);
+ while (true) {
+ if (TEMP_FAILURE_RETRY(io_submit(aiob->ctx, num_bufs, aiob->iocbs.data())) < num_bufs) {
+ PLOG(ERROR) << "aio: got error submitting " << (read ? "read" : "write");
return -1;
}
+ if (TEMP_FAILURE_RETRY(io_getevents(aiob->ctx, num_bufs, num_bufs, aiob->events.data(),
+ nullptr)) < num_bufs) {
+ PLOG(ERROR) << "aio: got error waiting " << (read ? "read" : "write");
+ return -1;
+ }
+ if (num_bufs == 1 && aiob->events[0].res == -EINTR) {
+ continue;
+ }
+ for (int i = 0; i < num_bufs; i++) {
+ if (aiob->events[i].res < 0) {
+ errno = -aiob->events[i].res;
+ PLOG(ERROR) << "aio: got error event on " << (read ? "read" : "write")
+ << " total bufs " << num_bufs;
+ return -1;
+ }
+ }
+ return 0;
}
- return 0;
}
static int usb_ffs_aio_read(usb_handle* h, void* data, int len) {
diff --git a/base/include/android-base/scopeguard.h b/base/include/android-base/scopeguard.h
index abcf4bc..c314e02 100644
--- a/base/include/android-base/scopeguard.h
+++ b/base/include/android-base/scopeguard.h
@@ -17,20 +17,27 @@
#ifndef ANDROID_BASE_SCOPEGUARD_H
#define ANDROID_BASE_SCOPEGUARD_H
-#include <utility> // for std::move
+#include <utility> // for std::move, std::forward
namespace android {
namespace base {
+// ScopeGuard ensures that the specified functor is executed no matter how the
+// current scope exits.
template <typename F>
class ScopeGuard {
public:
- ScopeGuard(F f) : f_(f), active_(true) {}
+ ScopeGuard(F&& f) : f_(std::forward<F>(f)), active_(true) {}
ScopeGuard(ScopeGuard&& that) : f_(std::move(that.f_)), active_(that.active_) {
that.active_ = false;
}
+ template <typename Functor>
+ ScopeGuard(ScopeGuard<Functor>&& that) : f_(std::move(that.f_)), active_(that.active_) {
+ that.active_ = false;
+ }
+
~ScopeGuard() {
if (active_) f_();
}
@@ -45,13 +52,16 @@
bool active() const { return active_; }
private:
+ template <typename Functor>
+ friend class ScopeGuard;
+
F f_;
bool active_;
};
-template <typename T>
-ScopeGuard<T> make_scope_guard(T f) {
- return ScopeGuard<T>(f);
+template <typename F>
+ScopeGuard<F> make_scope_guard(F&& f) {
+ return ScopeGuard<F>(std::forward<F>(f));
}
} // namespace base
diff --git a/base/scopeguard_test.cpp b/base/scopeguard_test.cpp
index e11154a..9236d7b 100644
--- a/base/scopeguard_test.cpp
+++ b/base/scopeguard_test.cpp
@@ -17,6 +17,7 @@
#include "android-base/scopeguard.h"
#include <utility>
+#include <vector>
#include <gtest/gtest.h>
@@ -44,3 +45,15 @@
EXPECT_FALSE(scopeguard.active());
ASSERT_FALSE(guarded_var);
}
+
+TEST(scopeguard, vector) {
+ int guarded_var = 0;
+ {
+ std::vector<android::base::ScopeGuard<std::function<void()>>> scopeguards;
+ scopeguards.emplace_back(android::base::make_scope_guard(
+ std::bind([](int& guarded_var) { guarded_var++; }, std::ref(guarded_var))));
+ scopeguards.emplace_back(android::base::make_scope_guard(
+ std::bind([](int& guarded_var) { guarded_var++; }, std::ref(guarded_var))));
+ }
+ ASSERT_EQ(guarded_var, 2);
+}
diff --git a/libcutils/include/cutils/trace.h b/libcutils/include/cutils/trace.h
index b2779b2..bbb150d 100644
--- a/libcutils/include/cutils/trace.h
+++ b/libcutils/include/cutils/trace.h
@@ -73,7 +73,8 @@
#define ATRACE_TAG_NETWORK (1<<21)
#define ATRACE_TAG_ADB (1<<22)
#define ATRACE_TAG_VIBRATOR (1<<23)
-#define ATRACE_TAG_LAST ATRACE_TAG_VIBRATOR
+#define ATRACE_TAG_AIDL (1<<24)
+#define ATRACE_TAG_LAST ATRACE_TAG_AIDL
// Reserved for initialization.
#define ATRACE_TAG_NOT_READY (1ULL<<63)
diff --git a/lmkd/Android.bp b/lmkd/Android.bp
index 8e65162..58647f2 100644
--- a/lmkd/Android.bp
+++ b/lmkd/Android.bp
@@ -12,6 +12,13 @@
local_include_dirs: ["include"],
cflags: ["-Werror", "-DLMKD_TRACE_KILLS"],
init_rc: ["lmkd.rc"],
+ product_variables: {
+ use_lmkd_stats_log: {
+ cflags: [
+ "-DLMKD_LOG_STATS"
+ ],
+ },
+ },
}
cc_library_static {
diff --git a/lmkd/lmkd.c b/lmkd/lmkd.c
index 1d8afb4..e2e5c4e 100644
--- a/lmkd/lmkd.c
+++ b/lmkd/lmkd.c
@@ -1201,7 +1201,7 @@
(unsigned long)property_get_int32("ro.lmk.kill_timeout_ms", 0);
#ifdef LMKD_LOG_STATS
- statlog_init();
+ statslog_init(&log_ctx, &enable_stats_log);
#endif
// MCL_ONFAULT pins pages as they fault instead of loading
@@ -1221,7 +1221,7 @@
mainloop();
#ifdef LMKD_LOG_STATS
- statslog_destroy();
+ statslog_destroy(&log_ctx);
#endif
ALOGI("exiting");
diff --git a/lmkd/statslog.h b/lmkd/statslog.h
index b567fbf..4cde840 100644
--- a/lmkd/statslog.h
+++ b/lmkd/statslog.h
@@ -17,6 +17,7 @@
#ifndef _STATSLOG_H_
#define _STATSLOG_H_
+#include <assert.h>
#include <stdbool.h>
#include <sys/cdefs.h>
@@ -34,17 +35,26 @@
#define LMK_STATE_CHANGE_START 1
#define LMK_STATE_CHANGE_STOP 2
-static inline void statslog_init() {
- enable_stats_log = property_get_bool("ro.lmk.log_stats", false);
+/*
+ * The single event tag id for all stats logs.
+ * Keep this in sync with system/core/logcat/event.logtags
+ */
+const static int kStatsEventTag = 1937006964;
- if (enable_stats_log) {
- log_ctx = create_android_logger(kStatsEventTag);
+static inline void statslog_init(android_log_context* log_ctx, bool* enable_stats_log) {
+ assert(log_ctx != NULL);
+ assert(enable_stats_log != NULL);
+ *enable_stats_log = property_get_bool("ro.lmk.log_stats", false);
+
+ if (*enable_stats_log) {
+ *log_ctx = create_android_logger(kStatsEventTag);
}
}
-static inline void statslog_destroy() {
- if (log_ctx) {
- android_log_destroy(&log_ctx);
+static inline void statslog_destroy(android_log_context* log_ctx) {
+ assert(log_ctx != NULL);
+ if (*log_ctx) {
+ android_log_destroy(log_ctx);
}
}
@@ -58,12 +68,6 @@
#define MEMCG_PROCESS_MEMORY_STAT_PATH "/dev/memcg/apps/uid_%u/pid_%u/memory.stat"
-/*
- * The single event tag id for all stats logs.
- * Keep this in sync with system/core/logcat/event.logtags
- */
-const static int kStatsEventTag = 1937006964;
-
/**
* Logs the change in LMKD state which is used as start/stop boundaries for logging
* LMK_KILL_OCCURRED event.