summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adb/adb.cpp84
-rw-r--r--adb/adb.h5
-rw-r--r--adb/client/bugreport.cpp4
-rw-r--r--adb/client/commandline.cpp2
-rw-r--r--adb/daemon/remount_service.cpp9
-rw-r--r--adb/daemon/services.cpp2
-rw-r--r--adb/transport.cpp69
-rw-r--r--base/include/android-base/logging.h5
-rw-r--r--base/logging.cpp9
-rw-r--r--fastboot/fastboot.cpp10
-rw-r--r--fastboot/fastboot_driver.cpp4
-rw-r--r--fs_mgr/fs_mgr.cpp7
-rw-r--r--healthd/healthd_draw.cpp212
-rw-r--r--healthd/healthd_draw.h6
-rw-r--r--init/init.cpp4
-rw-r--r--init/selinux.cpp2
-rw-r--r--liblog/include/log/log_event_list.h7
-rw-r--r--liblog/include_vndk/log/log_event_list.h7
-rw-r--r--liblog/liblog.map.txt6
-rw-r--r--liblog/log_event_list.c64
-rw-r--r--rootdir/init.rc1
-rw-r--r--shell_and_utilities/Android.bp1
-rw-r--r--toolbox/Android.bp25
23 files changed, 355 insertions, 190 deletions
diff --git a/adb/adb.cpp b/adb/adb.cpp
index 19300f660..38c6f62c9 100644
--- a/adb/adb.cpp
+++ b/adb/adb.cpp
@@ -920,13 +920,45 @@ int launch_server(const std::string& socket_spec) {
920} 920}
921#endif /* ADB_HOST */ 921#endif /* ADB_HOST */
922 922
923bool handle_forward_request(const char* service, atransport* transport, int reply_fd) {
924 return handle_forward_request(service, [transport](std::string*) { return transport; },
925 reply_fd);
926}
927
923// Try to handle a network forwarding request. 928// Try to handle a network forwarding request.
924// This returns 1 on success, 0 on failure, and -1 to indicate this is not 929bool handle_forward_request(const char* service,
925// a forwarding-related request. 930 std::function<atransport*(std::string* error)> transport_acquirer,
926int handle_forward_request(const char* service, atransport* transport, int reply_fd) { 931 int reply_fd) {
932 if (!strcmp(service, "list-forward")) {
933 // Create the list of forward redirections.
934 std::string listeners = format_listeners();
935#if ADB_HOST
936 SendOkay(reply_fd);
937#endif
938 SendProtocolString(reply_fd, listeners);
939 return true;
940 }
941
942 if (!strcmp(service, "killforward-all")) {
943 remove_all_listeners();
944#if ADB_HOST
945 /* On the host: 1st OKAY is connect, 2nd OKAY is status */
946 SendOkay(reply_fd);
947#endif
948 SendOkay(reply_fd);
949 return true;
950 }
951
927 if (!strncmp(service, "forward:", 8) || !strncmp(service, "killforward:", 12)) { 952 if (!strncmp(service, "forward:", 8) || !strncmp(service, "killforward:", 12)) {
928 // killforward:local 953 // killforward:local
929 // forward:(norebind:)?local;remote 954 // forward:(norebind:)?local;remote
955 std::string error;
956 atransport* transport = transport_acquirer(&error);
957 if (!transport) {
958 SendFail(reply_fd, error);
959 return true;
960 }
961
930 bool kill_forward = false; 962 bool kill_forward = false;
931 bool no_rebind = false; 963 bool no_rebind = false;
932 if (android::base::StartsWith(service, "killforward:")) { 964 if (android::base::StartsWith(service, "killforward:")) {
@@ -946,17 +978,16 @@ int handle_forward_request(const char* service, atransport* transport, int reply
946 // Check killforward: parameter format: '<local>' 978 // Check killforward: parameter format: '<local>'
947 if (pieces.size() != 1 || pieces[0].empty()) { 979 if (pieces.size() != 1 || pieces[0].empty()) {
948 SendFail(reply_fd, android::base::StringPrintf("bad killforward: %s", service)); 980 SendFail(reply_fd, android::base::StringPrintf("bad killforward: %s", service));
949 return 1; 981 return true;
950 } 982 }
951 } else { 983 } else {
952 // Check forward: parameter format: '<local>;<remote>' 984 // Check forward: parameter format: '<local>;<remote>'
953 if (pieces.size() != 2 || pieces[0].empty() || pieces[1].empty() || pieces[1][0] == '*') { 985 if (pieces.size() != 2 || pieces[0].empty() || pieces[1].empty() || pieces[1][0] == '*') {
954 SendFail(reply_fd, android::base::StringPrintf("bad forward: %s", service)); 986 SendFail(reply_fd, android::base::StringPrintf("bad forward: %s", service));
955 return 1; 987 return true;
956 } 988 }
957 } 989 }
958 990
959 std::string error;
960 InstallStatus r; 991 InstallStatus r;
961 int resolved_tcp_port = 0; 992 int resolved_tcp_port = 0;
962 if (kill_forward) { 993 if (kill_forward) {
@@ -977,7 +1008,7 @@ int handle_forward_request(const char* service, atransport* transport, int reply
977 SendProtocolString(reply_fd, android::base::StringPrintf("%d", resolved_tcp_port)); 1008 SendProtocolString(reply_fd, android::base::StringPrintf("%d", resolved_tcp_port));
978 } 1009 }
979 1010
980 return 1; 1011 return true;
981 } 1012 }
982 1013
983 std::string message; 1014 std::string message;
@@ -996,9 +1027,10 @@ int handle_forward_request(const char* service, atransport* transport, int reply
996 break; 1027 break;
997 } 1028 }
998 SendFail(reply_fd, message); 1029 SendFail(reply_fd, message);
999 return 1; 1030 return true;
1000 } 1031 }
1001 return 0; 1032
1033 return false;
1002} 1034}
1003 1035
1004#if ADB_HOST 1036#if ADB_HOST
@@ -1186,35 +1218,15 @@ int handle_host_request(const char* service, TransportType type, const char* ser
1186 return SendOkay(reply_fd, response); 1218 return SendOkay(reply_fd, response);
1187 } 1219 }
1188 1220
1189 if (!strcmp(service, "list-forward")) { 1221 if (handle_forward_request(service,
1190 // Create the list of forward redirections. 1222 [=](std::string* error) {
1191 std::string listeners = format_listeners(); 1223 return acquire_one_transport(type, serial, transport_id, nullptr,
1192#if ADB_HOST 1224 error);
1193 SendOkay(reply_fd); 1225 },
1194#endif 1226 reply_fd)) {
1195 return SendProtocolString(reply_fd, listeners); 1227 return 0;
1196 }
1197
1198 if (!strcmp(service, "killforward-all")) {
1199 remove_all_listeners();
1200#if ADB_HOST
1201 /* On the host: 1st OKAY is connect, 2nd OKAY is status */
1202 SendOkay(reply_fd);
1203#endif
1204 SendOkay(reply_fd);
1205 return 1;
1206 }
1207
1208 std::string error;
1209 atransport* t = acquire_one_transport(type, serial, transport_id, nullptr, &error);
1210 if (!t) {
1211 SendFail(reply_fd, error);
1212 return 1;
1213 } 1228 }
1214 1229
1215 int ret = handle_forward_request(service, t, reply_fd);
1216 if (ret >= 0)
1217 return ret - 1;
1218 return -1; 1230 return -1;
1219} 1231}
1220 1232
diff --git a/adb/adb.h b/adb/adb.h
index 13ca4d7e0..e6af780c4 100644
--- a/adb/adb.h
+++ b/adb/adb.h
@@ -158,7 +158,10 @@ asocket* create_jdwp_tracker_service_socket();
158unique_fd create_jdwp_connection_fd(int jdwp_pid); 158unique_fd create_jdwp_connection_fd(int jdwp_pid);
159#endif 159#endif
160 160
161int handle_forward_request(const char* service, atransport* transport, int reply_fd); 161bool handle_forward_request(const char* service, atransport* transport, int reply_fd);
162bool handle_forward_request(const char* service,
163 std::function<atransport*(std::string* error)> transport_acquirer,
164 int reply_fd);
162 165
163/* packet allocator */ 166/* packet allocator */
164apacket* get_apacket(void); 167apacket* get_apacket(void);
diff --git a/adb/client/bugreport.cpp b/adb/client/bugreport.cpp
index 346bb4b2c..fe9873725 100644
--- a/adb/client/bugreport.cpp
+++ b/adb/client/bugreport.cpp
@@ -16,6 +16,8 @@
16 16
17#define TRACE_TAG ADB 17#define TRACE_TAG ADB
18 18
19#include "sysdeps.h"
20
19#include "bugreport.h" 21#include "bugreport.h"
20 22
21#include <string> 23#include <string>
@@ -24,8 +26,6 @@
24#include <android-base/file.h> 26#include <android-base/file.h>
25#include <android-base/strings.h> 27#include <android-base/strings.h>
26 28
27#include "sysdeps.h"
28
29#include "adb_utils.h" 29#include "adb_utils.h"
30#include "client/file_sync_client.h" 30#include "client/file_sync_client.h"
31 31
diff --git a/adb/client/commandline.cpp b/adb/client/commandline.cpp
index a7a94e775..3fb14f351 100644
--- a/adb/client/commandline.cpp
+++ b/adb/client/commandline.cpp
@@ -1614,9 +1614,9 @@ int adb_commandline(int argc, const char** argv) {
1614 return bugreport.DoIt(argc, argv); 1614 return bugreport.DoIt(argc, argv);
1615 } else if (!strcmp(argv[0], "forward") || !strcmp(argv[0], "reverse")) { 1615 } else if (!strcmp(argv[0], "forward") || !strcmp(argv[0], "reverse")) {
1616 bool reverse = !strcmp(argv[0], "reverse"); 1616 bool reverse = !strcmp(argv[0], "reverse");
1617 ++argv;
1618 --argc; 1617 --argc;
1619 if (argc < 1) return syntax_error("%s requires an argument", argv[0]); 1618 if (argc < 1) return syntax_error("%s requires an argument", argv[0]);
1619 ++argv;
1620 1620
1621 // Determine the <host-prefix> for this command. 1621 // Determine the <host-prefix> for this command.
1622 std::string host_prefix; 1622 std::string host_prefix;
diff --git a/adb/daemon/remount_service.cpp b/adb/daemon/remount_service.cpp
index 658858717..0e79d824e 100644
--- a/adb/daemon/remount_service.cpp
+++ b/adb/daemon/remount_service.cpp
@@ -92,12 +92,13 @@ bool make_block_device_writable(const std::string& dev) {
92 return result; 92 return result;
93} 93}
94 94
95static bool fs_has_shared_blocks(const char* dev) { 95static bool fs_has_shared_blocks(const std::string& mount_point, const std::string& device) {
96 std::string path = mount_point + "/lost+found";
96 struct statfs fs; 97 struct statfs fs;
97 if (statfs(dev, &fs) == -1 || fs.f_type == EXT4_SUPER_MAGIC) { 98 if (statfs(path.c_str(), &fs) == -1 || fs.f_type != EXT4_SUPER_MAGIC) {
98 return false; 99 return false;
99 } 100 }
100 unique_fd fd(unix_open(dev, O_RDONLY)); 101 unique_fd fd(unix_open(device.c_str(), O_RDONLY));
101 if (fd < 0) { 102 if (fd < 0) {
102 return false; 103 return false;
103 } 104 }
@@ -237,7 +238,7 @@ void remount_service(unique_fd fd, const std::string& cmd) {
237 std::set<std::string> dedup; 238 std::set<std::string> dedup;
238 for (const auto& partition : partitions) { 239 for (const auto& partition : partitions) {
239 std::string dev = find_mount(partition.c_str(), partition == "/"); 240 std::string dev = find_mount(partition.c_str(), partition == "/");
240 if (dev.empty() || !fs_has_shared_blocks(dev.c_str())) { 241 if (dev.empty() || !fs_has_shared_blocks(partition, dev)) {
241 continue; 242 continue;
242 } 243 }
243 if (can_unshare_blocks(fd.get(), dev.c_str())) { 244 if (can_unshare_blocks(fd.get(), dev.c_str())) {
diff --git a/adb/daemon/services.cpp b/adb/daemon/services.cpp
index 25024b05a..1f59d6446 100644
--- a/adb/daemon/services.cpp
+++ b/adb/daemon/services.cpp
@@ -157,7 +157,7 @@ unique_fd reverse_service(const char* command, atransport* transport) {
157 return unique_fd{}; 157 return unique_fd{};
158 } 158 }
159 VLOG(SERVICES) << "service socketpair: " << s[0] << ", " << s[1]; 159 VLOG(SERVICES) << "service socketpair: " << s[0] << ", " << s[1];
160 if (handle_forward_request(command, transport, s[1]) < 0) { 160 if (!handle_forward_request(command, transport, s[1])) {
161 SendFail(s[1], "not a reverse forwarding command"); 161 SendFail(s[1], "not a reverse forwarding command");
162 } 162 }
163 adb_close(s[1]); 163 adb_close(s[1]);
diff --git a/adb/transport.cpp b/adb/transport.cpp
index 793c283fc..922200826 100644
--- a/adb/transport.cpp
+++ b/adb/transport.cpp
@@ -50,6 +50,7 @@
50#include "adb_trace.h" 50#include "adb_trace.h"
51#include "adb_utils.h" 51#include "adb_utils.h"
52#include "fdevent.h" 52#include "fdevent.h"
53#include "sysdeps/chrono.h"
53 54
54static void register_transport(atransport* transport); 55static void register_transport(atransport* transport);
55static void remove_transport(atransport* transport); 56static void remove_transport(atransport* transport);
@@ -80,6 +81,7 @@ class SCOPED_CAPABILITY ScopedAssumeLocked {
80 ~ScopedAssumeLocked() RELEASE() {} 81 ~ScopedAssumeLocked() RELEASE() {}
81}; 82};
82 83
84#if ADB_HOST
83// Tracks and handles atransport*s that are attempting reconnection. 85// Tracks and handles atransport*s that are attempting reconnection.
84class ReconnectHandler { 86class ReconnectHandler {
85 public: 87 public:
@@ -102,12 +104,18 @@ class ReconnectHandler {
102 // Tracks a reconnection attempt. 104 // Tracks a reconnection attempt.
103 struct ReconnectAttempt { 105 struct ReconnectAttempt {
104 atransport* transport; 106 atransport* transport;
105 std::chrono::system_clock::time_point deadline; 107 std::chrono::steady_clock::time_point reconnect_time;
106 size_t attempts_left; 108 size_t attempts_left;
109
110 bool operator<(const ReconnectAttempt& rhs) const {
111 // std::priority_queue returns the largest element first, so we want attempts that have
112 // less time remaining (i.e. smaller time_points) to compare greater.
113 return reconnect_time > rhs.reconnect_time;
114 }
107 }; 115 };
108 116
109 // Only retry for up to one minute. 117 // Only retry for up to one minute.
110 static constexpr const std::chrono::seconds kDefaultTimeout = std::chrono::seconds(10); 118 static constexpr const std::chrono::seconds kDefaultTimeout = 10s;
111 static constexpr const size_t kMaxAttempts = 6; 119 static constexpr const size_t kMaxAttempts = 6;
112 120
113 // Protects all members. 121 // Protects all members.
@@ -115,7 +123,7 @@ class ReconnectHandler {
115 bool running_ GUARDED_BY(reconnect_mutex_) = true; 123 bool running_ GUARDED_BY(reconnect_mutex_) = true;
116 std::thread handler_thread_; 124 std::thread handler_thread_;
117 std::condition_variable reconnect_cv_; 125 std::condition_variable reconnect_cv_;
118 std::queue<ReconnectAttempt> reconnect_queue_ GUARDED_BY(reconnect_mutex_); 126 std::priority_queue<ReconnectAttempt> reconnect_queue_ GUARDED_BY(reconnect_mutex_);
119 127
120 DISALLOW_COPY_AND_ASSIGN(ReconnectHandler); 128 DISALLOW_COPY_AND_ASSIGN(ReconnectHandler);
121}; 129};
@@ -137,7 +145,7 @@ void ReconnectHandler::Stop() {
137 // Drain the queue to free all resources. 145 // Drain the queue to free all resources.
138 std::lock_guard<std::mutex> lock(reconnect_mutex_); 146 std::lock_guard<std::mutex> lock(reconnect_mutex_);
139 while (!reconnect_queue_.empty()) { 147 while (!reconnect_queue_.empty()) {
140 ReconnectAttempt attempt = reconnect_queue_.front(); 148 ReconnectAttempt attempt = reconnect_queue_.top();
141 reconnect_queue_.pop(); 149 reconnect_queue_.pop();
142 remove_transport(attempt.transport); 150 remove_transport(attempt.transport);
143 } 151 }
@@ -148,9 +156,10 @@ void ReconnectHandler::TrackTransport(atransport* transport) {
148 { 156 {
149 std::lock_guard<std::mutex> lock(reconnect_mutex_); 157 std::lock_guard<std::mutex> lock(reconnect_mutex_);
150 if (!running_) return; 158 if (!running_) return;
151 reconnect_queue_.emplace(ReconnectAttempt{ 159 // Arbitrary sleep to give adbd time to get ready, if we disconnected because it exited.
152 transport, std::chrono::system_clock::now() + ReconnectHandler::kDefaultTimeout, 160 auto reconnect_time = std::chrono::steady_clock::now() + 250ms;
153 ReconnectHandler::kMaxAttempts}); 161 reconnect_queue_.emplace(
162 ReconnectAttempt{transport, reconnect_time, ReconnectHandler::kMaxAttempts});
154 } 163 }
155 reconnect_cv_.notify_one(); 164 reconnect_cv_.notify_one();
156} 165}
@@ -162,15 +171,27 @@ void ReconnectHandler::Run() {
162 std::unique_lock<std::mutex> lock(reconnect_mutex_); 171 std::unique_lock<std::mutex> lock(reconnect_mutex_);
163 ScopedAssumeLocked assume_lock(reconnect_mutex_); 172 ScopedAssumeLocked assume_lock(reconnect_mutex_);
164 173
165 auto deadline = std::chrono::time_point<std::chrono::system_clock>::max(); 174 if (!reconnect_queue_.empty()) {
166 if (!reconnect_queue_.empty()) deadline = reconnect_queue_.front().deadline; 175 // FIXME: libstdc++ (used on Windows) implements condition_variable with
167 reconnect_cv_.wait_until(lock, deadline, [&]() REQUIRES(reconnect_mutex_) { 176 // system_clock as its clock, so we're probably hosed if the clock changes,
168 return !running_ || 177 // even if we use steady_clock throughout. This problem goes away once we
169 (!reconnect_queue_.empty() && reconnect_queue_.front().deadline < deadline); 178 // switch to libc++.
170 }); 179 reconnect_cv_.wait_until(lock, reconnect_queue_.top().reconnect_time);
180 } else {
181 reconnect_cv_.wait(lock);
182 }
171 183
172 if (!running_) return; 184 if (!running_) return;
173 attempt = reconnect_queue_.front(); 185 if (reconnect_queue_.empty()) continue;
186
187 // Go back to sleep in case |reconnect_cv_| woke up spuriously and we still
188 // have more time to wait for the current attempt.
189 auto now = std::chrono::steady_clock::now();
190 if (reconnect_queue_.top().reconnect_time > now) {
191 continue;
192 }
193
194 attempt = reconnect_queue_.top();
174 reconnect_queue_.pop(); 195 reconnect_queue_.pop();
175 if (attempt.transport->kicked()) { 196 if (attempt.transport->kicked()) {
176 D("transport %s was kicked. giving up on it.", attempt.transport->serial.c_str()); 197 D("transport %s was kicked. giving up on it.", attempt.transport->serial.c_str());
@@ -191,9 +212,9 @@ void ReconnectHandler::Run() {
191 212
192 std::lock_guard<std::mutex> lock(reconnect_mutex_); 213 std::lock_guard<std::mutex> lock(reconnect_mutex_);
193 reconnect_queue_.emplace(ReconnectAttempt{ 214 reconnect_queue_.emplace(ReconnectAttempt{
194 attempt.transport, 215 attempt.transport,
195 std::chrono::system_clock::now() + ReconnectHandler::kDefaultTimeout, 216 std::chrono::steady_clock::now() + ReconnectHandler::kDefaultTimeout,
196 attempt.attempts_left - 1}); 217 attempt.attempts_left - 1});
197 continue; 218 continue;
198 } 219 }
199 220
@@ -204,6 +225,8 @@ void ReconnectHandler::Run() {
204 225
205static auto& reconnect_handler = *new ReconnectHandler(); 226static auto& reconnect_handler = *new ReconnectHandler();
206 227
228#endif
229
207} // namespace 230} // namespace
208 231
209TransportId NextTransportId() { 232TransportId NextTransportId() {
@@ -677,9 +700,11 @@ static void transport_registration_func(int _fd, unsigned ev, void*) {
677 update_transports(); 700 update_transports();
678} 701}
679 702
703#if ADB_HOST
680void init_reconnect_handler(void) { 704void init_reconnect_handler(void) {
681 reconnect_handler.Start(); 705 reconnect_handler.Start();
682} 706}
707#endif
683 708
684void init_transport_registration(void) { 709void init_transport_registration(void) {
685 int s[2]; 710 int s[2];
@@ -698,7 +723,9 @@ void init_transport_registration(void) {
698} 723}
699 724
700void kick_all_transports() { 725void kick_all_transports() {
726#if ADB_HOST
701 reconnect_handler.Stop(); 727 reconnect_handler.Stop();
728#endif
702 // To avoid only writing part of a packet to a transport after exit, kick all transports. 729 // To avoid only writing part of a packet to a transport after exit, kick all transports.
703 std::lock_guard<std::recursive_mutex> lock(transport_lock); 730 std::lock_guard<std::recursive_mutex> lock(transport_lock);
704 for (auto t : transport_list) { 731 for (auto t : transport_list) {
@@ -736,13 +763,19 @@ static void transport_unref(atransport* t) {
736 t->ref_count--; 763 t->ref_count--;
737 if (t->ref_count == 0) { 764 if (t->ref_count == 0) {
738 t->connection()->Stop(); 765 t->connection()->Stop();
766#if ADB_HOST
739 if (t->IsTcpDevice() && !t->kicked()) { 767 if (t->IsTcpDevice() && !t->kicked()) {
740 D("transport: %s unref (attempting reconnection) %d", t->serial.c_str(), t->kicked()); 768 D("transport: %s unref (attempting reconnection)", t->serial.c_str());
741 reconnect_handler.TrackTransport(t); 769 reconnect_handler.TrackTransport(t);
742 } else { 770 } else {
743 D("transport: %s unref (kicking and closing)", t->serial.c_str()); 771 D("transport: %s unref (kicking and closing)", t->serial.c_str());
744 remove_transport(t); 772 remove_transport(t);
745 } 773 }
774#else
775 D("transport: %s unref (kicking and closing)", t->serial.c_str());
776 remove_transport(t);
777#endif
778
746 } else { 779 } else {
747 D("transport: %s unref (count=%zu)", t->serial.c_str(), t->ref_count); 780 D("transport: %s unref (count=%zu)", t->serial.c_str(), t->ref_count);
748 } 781 }
diff --git a/base/include/android-base/logging.h b/base/include/android-base/logging.h
index aea6ce601..f94cc258e 100644
--- a/base/include/android-base/logging.h
+++ b/base/include/android-base/logging.h
@@ -447,11 +447,6 @@ class LogMessage {
447 private: 447 private:
448 const std::unique_ptr<LogMessageData> data_; 448 const std::unique_ptr<LogMessageData> data_;
449 449
450 // TODO(b/35361699): remove these symbols once all prebuilds stop using it.
451 LogMessage(const char* file, unsigned int line, LogId id, LogSeverity severity, int error);
452 static void LogLine(const char* file, unsigned int line, LogId id, LogSeverity severity,
453 const char* msg);
454
455 DISALLOW_COPY_AND_ASSIGN(LogMessage); 450 DISALLOW_COPY_AND_ASSIGN(LogMessage);
456}; 451};
457 452
diff --git a/base/logging.cpp b/base/logging.cpp
index 35054ac82..d60d91d5d 100644
--- a/base/logging.cpp
+++ b/base/logging.cpp
@@ -410,10 +410,6 @@ LogMessage::LogMessage(const char* file, unsigned int line, LogId id, LogSeverit
410 const char* tag, int error) 410 const char* tag, int error)
411 : data_(new LogMessageData(file, line, id, severity, tag, error)) {} 411 : data_(new LogMessageData(file, line, id, severity, tag, error)) {}
412 412
413LogMessage::LogMessage(const char* file, unsigned int line, LogId id, LogSeverity severity,
414 int error)
415 : LogMessage(file, line, id, severity, nullptr, error) {}
416
417LogMessage::~LogMessage() { 413LogMessage::~LogMessage() {
418 // Check severity again. This is duplicate work wrt/ LOG macros, but not LOG_STREAM. 414 // Check severity again. This is duplicate work wrt/ LOG macros, but not LOG_STREAM.
419 if (!WOULD_LOG(data_->GetSeverity())) { 415 if (!WOULD_LOG(data_->GetSeverity())) {
@@ -470,11 +466,6 @@ void LogMessage::LogLine(const char* file, unsigned int line, LogId id, LogSever
470 } 466 }
471} 467}
472 468
473void LogMessage::LogLine(const char* file, unsigned int line, LogId id, LogSeverity severity,
474 const char* message) {
475 LogLine(file, line, id, severity, nullptr, message);
476}
477
478LogSeverity GetMinimumLogSeverity() { 469LogSeverity GetMinimumLogSeverity() {
479 return gMinimumLogSeverity; 470 return gMinimumLogSeverity;
480} 471}
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 263ea1780..321e6bad7 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -114,20 +114,26 @@ static struct {
114 bool is_optional; 114 bool is_optional;
115 bool is_secondary; 115 bool is_secondary;
116} images[] = { 116} images[] = {
117 // clang-format off 117 // clang-format off
118 { "boot", "boot.img", "boot.sig", "boot", false, false }, 118 { "boot", "boot.img", "boot.sig", "boot", false, false },
119 { nullptr, "boot_other.img", "boot.sig", "boot", true, true }, 119 { nullptr, "boot_other.img", "boot.sig", "boot", true, true },
120 { "dtbo", "dtbo.img", "dtbo.sig", "dtbo", true, false }, 120 { "dtbo", "dtbo.img", "dtbo.sig", "dtbo", true, false },
121 { "dts", "dt.img", "dt.sig", "dts", true, false }, 121 { "dts", "dt.img", "dt.sig", "dts", true, false },
122 { "odm", "odm.img", "odm.sig", "odm", true, false }, 122 { "odm", "odm.img", "odm.sig", "odm", true, false },
123 { "product", "product.img", "product.sig", "product", true, false }, 123 { "product", "product.img", "product.sig", "product", true, false },
124 { "product-services",
125 "product-services.img",
126 "product-services.sig",
127 "product-services",
128 true, false },
124 { "recovery", "recovery.img", "recovery.sig", "recovery", true, false }, 129 { "recovery", "recovery.img", "recovery.sig", "recovery", true, false },
130 { "super", "super.img", "super.sig", "super", true, false },
125 { "system", "system.img", "system.sig", "system", false, false }, 131 { "system", "system.img", "system.sig", "system", false, false },
126 { nullptr, "system_other.img", "system.sig", "system", true, true }, 132 { nullptr, "system_other.img", "system.sig", "system", true, true },
127 { "vbmeta", "vbmeta.img", "vbmeta.sig", "vbmeta", true, false }, 133 { "vbmeta", "vbmeta.img", "vbmeta.sig", "vbmeta", true, false },
128 { "vendor", "vendor.img", "vendor.sig", "vendor", true, false }, 134 { "vendor", "vendor.img", "vendor.sig", "vendor", true, false },
129 { nullptr, "vendor_other.img", "vendor.sig", "vendor", true, true }, 135 { nullptr, "vendor_other.img", "vendor.sig", "vendor", true, true },
130 // clang-format on 136 // clang-format on
131}; 137};
132 138
133static std::string find_item_given_name(const char* img_name) { 139static std::string find_item_given_name(const char* img_name) {
diff --git a/fastboot/fastboot_driver.cpp b/fastboot/fastboot_driver.cpp
index c30842055..aabc620d4 100644
--- a/fastboot/fastboot_driver.cpp
+++ b/fastboot/fastboot_driver.cpp
@@ -462,6 +462,10 @@ RetCode FastBootDriver::SendBuffer(const std::vector<char>& buf) {
462} 462}
463 463
464RetCode FastBootDriver::SendBuffer(const void* buf, size_t size) { 464RetCode FastBootDriver::SendBuffer(const void* buf, size_t size) {
465 if (!size) {
466 return SUCCESS;
467 }
468
465 // Write the buffer 469 // Write the buffer
466 ssize_t tmp = transport->Write(buf, size); 470 ssize_t tmp = transport->Write(buf, size);
467 471
diff --git a/fs_mgr/fs_mgr.cpp b/fs_mgr/fs_mgr.cpp
index b3df811e4..5f5718264 100644
--- a/fs_mgr/fs_mgr.cpp
+++ b/fs_mgr/fs_mgr.cpp
@@ -1052,6 +1052,9 @@ int fs_mgr_do_mount_one(struct fstab_rec *rec)
1052 return FS_MGR_DOMNT_FAILED; 1052 return FS_MGR_DOMNT_FAILED;
1053 } 1053 }
1054 1054
1055 // Run fsck if needed
1056 prepare_fs_for_mount(rec->blk_device, rec);
1057
1055 int ret = __mount(rec->blk_device, rec->mount_point, rec); 1058 int ret = __mount(rec->blk_device, rec->mount_point, rec);
1056 if (ret) { 1059 if (ret) {
1057 ret = (errno == EBUSY) ? FS_MGR_DOMNT_BUSY : FS_MGR_DOMNT_FAILED; 1060 ret = (errno == EBUSY) ? FS_MGR_DOMNT_BUSY : FS_MGR_DOMNT_FAILED;
@@ -1177,8 +1180,8 @@ int fs_mgr_do_tmpfs_mount(const char *n_name)
1177{ 1180{
1178 int ret; 1181 int ret;
1179 1182
1180 ret = mount("tmpfs", n_name, "tmpfs", 1183 ret = mount("tmpfs", n_name, "tmpfs", MS_NOATIME | MS_NOSUID | MS_NODEV | MS_NOEXEC,
1181 MS_NOATIME | MS_NOSUID | MS_NODEV, CRYPTO_TMPFS_OPTIONS); 1184 CRYPTO_TMPFS_OPTIONS);
1182 if (ret < 0) { 1185 if (ret < 0) {
1183 LERROR << "Cannot mount tmpfs filesystem at " << n_name; 1186 LERROR << "Cannot mount tmpfs filesystem at " << n_name;
1184 return -1; 1187 return -1;
diff --git a/healthd/healthd_draw.cpp b/healthd/healthd_draw.cpp
index ea3d991c0..30f2cf3be 100644
--- a/healthd/healthd_draw.cpp
+++ b/healthd/healthd_draw.cpp
@@ -21,77 +21,96 @@
21#include "healthd_draw.h" 21#include "healthd_draw.h"
22 22
23#define LOGE(x...) KLOG_ERROR("charger", x); 23#define LOGE(x...) KLOG_ERROR("charger", x);
24#define LOGW(x...) KLOG_WARNING("charger", x);
24#define LOGV(x...) KLOG_DEBUG("charger", x); 25#define LOGV(x...) KLOG_DEBUG("charger", x);
25 26
26HealthdDraw::HealthdDraw(animation* anim) 27HealthdDraw::HealthdDraw(animation* anim)
27 : kSplitScreen(HEALTHD_DRAW_SPLIT_SCREEN), 28 : kSplitScreen(HEALTHD_DRAW_SPLIT_SCREEN),
28 kSplitOffset(HEALTHD_DRAW_SPLIT_OFFSET) { 29 kSplitOffset(HEALTHD_DRAW_SPLIT_OFFSET) {
29 gr_init(); 30 int ret = gr_init();
30 gr_font_size(gr_sys_font(), &char_width_, &char_height_); 31
31 32 if (ret < 0) {
32 screen_width_ = gr_fb_width() / (kSplitScreen ? 2 : 1); 33 LOGE("gr_init failed\n");
33 screen_height_ = gr_fb_height(); 34 graphics_available = false;
34 35 return;
35 int res; 36 }
36 if (!anim->text_clock.font_file.empty() && 37
37 (res = gr_init_font(anim->text_clock.font_file.c_str(), 38 graphics_available = true;
38 &anim->text_clock.font)) < 0) { 39 sys_font = gr_sys_font();
39 LOGE("Could not load time font (%d)\n", res); 40 if (sys_font == nullptr) {
40 } 41 LOGW("No system font, screen fallback text not available\n");
41 if (!anim->text_percent.font_file.empty() && 42 } else {
42 (res = gr_init_font(anim->text_percent.font_file.c_str(), 43 gr_font_size(sys_font, &char_width_, &char_height_);
43 &anim->text_percent.font)) < 0) { 44 }
44 LOGE("Could not load percent font (%d)\n", res); 45
45 } 46 screen_width_ = gr_fb_width() / (kSplitScreen ? 2 : 1);
47 screen_height_ = gr_fb_height();
48
49 int res;
50 if (!anim->text_clock.font_file.empty() &&
51 (res = gr_init_font(anim->text_clock.font_file.c_str(), &anim->text_clock.font)) < 0) {
52 LOGE("Could not load time font (%d)\n", res);
53 }
54 if (!anim->text_percent.font_file.empty() &&
55 (res = gr_init_font(anim->text_percent.font_file.c_str(), &anim->text_percent.font)) < 0) {
56 LOGE("Could not load percent font (%d)\n", res);
57 }
46} 58}
47 59
48HealthdDraw::~HealthdDraw() {} 60HealthdDraw::~HealthdDraw() {}
49 61
50void HealthdDraw::redraw_screen(const animation* batt_anim, GRSurface* surf_unknown) { 62void HealthdDraw::redraw_screen(const animation* batt_anim, GRSurface* surf_unknown) {
51 clear_screen(); 63 if (!graphics_available) return;
52 64 clear_screen();
53 /* try to display *something* */ 65
54 if (batt_anim->cur_level < 0 || batt_anim->num_frames == 0) 66 /* try to display *something* */
55 draw_unknown(surf_unknown); 67 if (batt_anim->cur_level < 0 || batt_anim->num_frames == 0)
56 else 68 draw_unknown(surf_unknown);
57 draw_battery(batt_anim); 69 else
58 gr_flip(); 70 draw_battery(batt_anim);
71 gr_flip();
59} 72}
60 73
61void HealthdDraw::blank_screen(bool blank) { gr_fb_blank(blank); } 74void HealthdDraw::blank_screen(bool blank) {
75 if (!graphics_available) return;
76 gr_fb_blank(blank);
77}
62 78
63void HealthdDraw::clear_screen(void) { 79void HealthdDraw::clear_screen(void) {
64 gr_color(0, 0, 0, 255); 80 if (!graphics_available) return;
65 gr_clear(); 81 gr_color(0, 0, 0, 255);
82 gr_clear();
66} 83}
67 84
68int HealthdDraw::draw_surface_centered(GRSurface* surface) { 85int HealthdDraw::draw_surface_centered(GRSurface* surface) {
69 int w = gr_get_width(surface); 86 if (!graphics_available) return 0;
70 int h = gr_get_height(surface); 87
71 int x = (screen_width_ - w) / 2 + kSplitOffset; 88 int w = gr_get_width(surface);
72 int y = (screen_height_ - h) / 2; 89 int h = gr_get_height(surface);
73 90 int x = (screen_width_ - w) / 2 + kSplitOffset;
74 LOGV("drawing surface %dx%d+%d+%d\n", w, h, x, y); 91 int y = (screen_height_ - h) / 2;
75 gr_blit(surface, 0, 0, w, h, x, y); 92
76 if (kSplitScreen) {
77 x += screen_width_ - 2 * kSplitOffset;
78 LOGV("drawing surface %dx%d+%d+%d\n", w, h, x, y); 93 LOGV("drawing surface %dx%d+%d+%d\n", w, h, x, y);
79 gr_blit(surface, 0, 0, w, h, x, y); 94 gr_blit(surface, 0, 0, w, h, x, y);
80 } 95 if (kSplitScreen) {
96 x += screen_width_ - 2 * kSplitOffset;
97 LOGV("drawing surface %dx%d+%d+%d\n", w, h, x, y);
98 gr_blit(surface, 0, 0, w, h, x, y);
99 }
81 100
82 return y + h; 101 return y + h;
83} 102}
84 103
85int HealthdDraw::draw_text(const GRFont* font, int x, int y, const char* str) { 104int HealthdDraw::draw_text(const GRFont* font, int x, int y, const char* str) {
86 int str_len_px = gr_measure(font, str); 105 if (!graphics_available) return 0;
106 int str_len_px = gr_measure(font, str);
87 107
88 if (x < 0) x = (screen_width_ - str_len_px) / 2; 108 if (x < 0) x = (screen_width_ - str_len_px) / 2;
89 if (y < 0) y = (screen_height_ - char_height_) / 2; 109 if (y < 0) y = (screen_height_ - char_height_) / 2;
90 gr_text(font, x + kSplitOffset, y, str, false /* bold */); 110 gr_text(font, x + kSplitOffset, y, str, false /* bold */);
91 if (kSplitScreen) 111 if (kSplitScreen) gr_text(font, x - kSplitOffset + screen_width_, y, str, false /* bold */);
92 gr_text(font, x - kSplitOffset + screen_width_, y, str, false /* bold */);
93 112
94 return y + char_height_; 113 return y + char_height_;
95} 114}
96 115
97void HealthdDraw::determine_xy(const animation::text_field& field, 116void HealthdDraw::determine_xy(const animation::text_field& field,
@@ -119,77 +138,80 @@ void HealthdDraw::determine_xy(const animation::text_field& field,
119} 138}
120 139
121void HealthdDraw::draw_clock(const animation* anim) { 140void HealthdDraw::draw_clock(const animation* anim) {
122 static constexpr char CLOCK_FORMAT[] = "%H:%M"; 141 static constexpr char CLOCK_FORMAT[] = "%H:%M";
123 static constexpr int CLOCK_LENGTH = 6; 142 static constexpr int CLOCK_LENGTH = 6;
124 143
125 const animation::text_field& field = anim->text_clock; 144 const animation::text_field& field = anim->text_clock;
126 145
127 if (field.font == nullptr || field.font->char_width == 0 || 146 if (!graphics_available || field.font == nullptr || field.font->char_width == 0 ||
128 field.font->char_height == 0) 147 field.font->char_height == 0)
129 return; 148 return;
130 149
131 time_t rawtime; 150 time_t rawtime;
132 time(&rawtime); 151 time(&rawtime);
133 tm* time_info = localtime(&rawtime); 152 tm* time_info = localtime(&rawtime);
134 153
135 char clock_str[CLOCK_LENGTH]; 154 char clock_str[CLOCK_LENGTH];
136 size_t length = strftime(clock_str, CLOCK_LENGTH, CLOCK_FORMAT, time_info); 155 size_t length = strftime(clock_str, CLOCK_LENGTH, CLOCK_FORMAT, time_info);
137 if (length != CLOCK_LENGTH - 1) { 156 if (length != CLOCK_LENGTH - 1) {
138 LOGE("Could not format time\n"); 157 LOGE("Could not format time\n");
139 return; 158 return;
140 } 159 }
141 160
142 int x, y; 161 int x, y;
143 determine_xy(field, length, &x, &y); 162 determine_xy(field, length, &x, &y);
144 163
145 LOGV("drawing clock %s %d %d\n", clock_str, x, y); 164 LOGV("drawing clock %s %d %d\n", clock_str, x, y);
146 gr_color(field.color_r, field.color_g, field.color_b, field.color_a); 165 gr_color(field.color_r, field.color_g, field.color_b, field.color_a);
147 draw_text(field.font, x, y, clock_str); 166 draw_text(field.font, x, y, clock_str);
148} 167}
149 168
150void HealthdDraw::draw_percent(const animation* anim) { 169void HealthdDraw::draw_percent(const animation* anim) {
151 int cur_level = anim->cur_level; 170 if (!graphics_available) return;
152 if (anim->cur_status == BATTERY_STATUS_FULL) { 171 int cur_level = anim->cur_level;
153 cur_level = 100; 172 if (anim->cur_status == BATTERY_STATUS_FULL) {
154 } 173 cur_level = 100;
174 }
155 175
156 if (cur_level <= 0) return; 176 if (cur_level <= 0) return;
157 177
158 const animation::text_field& field = anim->text_percent; 178 const animation::text_field& field = anim->text_percent;
159 if (field.font == nullptr || field.font->char_width == 0 || 179 if (field.font == nullptr || field.font->char_width == 0 || field.font->char_height == 0) {
160 field.font->char_height == 0) { 180 return;
161 return; 181 }
162 }
163 182
164 std::string str = base::StringPrintf("%d%%", cur_level); 183 std::string str = base::StringPrintf("%d%%", cur_level);
165 184
166 int x, y; 185 int x, y;
167 determine_xy(field, str.size(), &x, &y); 186 determine_xy(field, str.size(), &x, &y);
168 187
169 LOGV("drawing percent %s %d %d\n", str.c_str(), x, y); 188 LOGV("drawing percent %s %d %d\n", str.c_str(), x, y);
170 gr_color(field.color_r, field.color_g, field.color_b, field.color_a); 189 gr_color(field.color_r, field.color_g, field.color_b, field.color_a);
171 draw_text(field.font, x, y, str.c_str()); 190 draw_text(field.font, x, y, str.c_str());
172} 191}
173 192
174void HealthdDraw::draw_battery(const animation* anim) { 193void HealthdDraw::draw_battery(const animation* anim) {
175 const animation::frame& frame = anim->frames[anim->cur_frame]; 194 if (!graphics_available) return;
176 195 const animation::frame& frame = anim->frames[anim->cur_frame];
177 if (anim->num_frames != 0) { 196
178 draw_surface_centered(frame.surface); 197 if (anim->num_frames != 0) {
179 LOGV("drawing frame #%d min_cap=%d time=%d\n", anim->cur_frame, 198 draw_surface_centered(frame.surface);
180 frame.min_level, frame.disp_time); 199 LOGV("drawing frame #%d min_cap=%d time=%d\n", anim->cur_frame, frame.min_level,
181 } 200 frame.disp_time);
182 draw_clock(anim); 201 }
183 draw_percent(anim); 202 draw_clock(anim);
203 draw_percent(anim);
184} 204}
185 205
186void HealthdDraw::draw_unknown(GRSurface* surf_unknown) { 206void HealthdDraw::draw_unknown(GRSurface* surf_unknown) {
187 int y; 207 int y;
188 if (surf_unknown) { 208 if (surf_unknown) {
189 draw_surface_centered(surf_unknown); 209 draw_surface_centered(surf_unknown);
210 } else if (sys_font) {
211 gr_color(0xa4, 0xc6, 0x39, 255);
212 y = draw_text(sys_font, -1, -1, "Charging!");
213 draw_text(sys_font, -1, y + 25, "?\?/100");
190 } else { 214 } else {
191 gr_color(0xa4, 0xc6, 0x39, 255); 215 LOGW("Charging, level unknown\n");
192 y = draw_text(gr_sys_font(), -1, -1, "Charging!");
193 draw_text(gr_sys_font(), -1, y + 25, "?\?/100");
194 } 216 }
195} 217}
diff --git a/healthd/healthd_draw.h b/healthd/healthd_draw.h
index 6a6ba7655..7c847bdbf 100644
--- a/healthd/healthd_draw.h
+++ b/healthd/healthd_draw.h
@@ -70,6 +70,12 @@ class HealthdDraw {
70 const bool kSplitScreen; 70 const bool kSplitScreen;
71 // Pixels to offset graphics towards center split. 71 // Pixels to offset graphics towards center split.
72 const int kSplitOffset; 72 const int kSplitOffset;
73
74 // system text font, may be nullptr
75 const GRFont* sys_font;
76
77 // true if minui init'ed OK, false if minui init failed
78 bool graphics_available;
73}; 79};
74 80
75#endif // HEALTHD_DRAW_H 81#endif // HEALTHD_DRAW_H
diff --git a/init/init.cpp b/init/init.cpp
index 73194bdd9..7ad9ec396 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -670,6 +670,10 @@ int main(int argc, char** argv) {
670 CHECKCALL(mknod("/dev/random", S_IFCHR | 0666, makedev(1, 8))); 670 CHECKCALL(mknod("/dev/random", S_IFCHR | 0666, makedev(1, 8)));
671 CHECKCALL(mknod("/dev/urandom", S_IFCHR | 0666, makedev(1, 9))); 671 CHECKCALL(mknod("/dev/urandom", S_IFCHR | 0666, makedev(1, 9)));
672 672
673 // This is needed for log wrapper, which gets called before ueventd runs.
674 CHECKCALL(mknod("/dev/ptmx", S_IFCHR | 0666, makedev(5, 2)));
675 CHECKCALL(mknod("/dev/null", S_IFCHR | 0666, makedev(1, 3)));
676
673 // Mount staging areas for devices managed by vold 677 // Mount staging areas for devices managed by vold
674 // See storage config details at http://source.android.com/devices/storage/ 678 // See storage config details at http://source.android.com/devices/storage/
675 CHECKCALL(mount("tmpfs", "/mnt", "tmpfs", MS_NOEXEC | MS_NOSUID | MS_NODEV, 679 CHECKCALL(mount("tmpfs", "/mnt", "tmpfs", MS_NOEXEC | MS_NOSUID | MS_NODEV,
diff --git a/init/selinux.cpp b/init/selinux.cpp
index 94f206ede..b788be9d6 100644
--- a/init/selinux.cpp
+++ b/init/selinux.cpp
@@ -414,6 +414,8 @@ void SelinuxRestoreContext() {
414 if constexpr (WORLD_WRITABLE_KMSG) { 414 if constexpr (WORLD_WRITABLE_KMSG) {
415 selinux_android_restorecon("/dev/kmsg_debug", 0); 415 selinux_android_restorecon("/dev/kmsg_debug", 0);
416 } 416 }
417 selinux_android_restorecon("/dev/null", 0);
418 selinux_android_restorecon("/dev/ptmx", 0);
417 selinux_android_restorecon("/dev/socket", 0); 419 selinux_android_restorecon("/dev/socket", 0);
418 selinux_android_restorecon("/dev/random", 0); 420 selinux_android_restorecon("/dev/random", 0);
419 selinux_android_restorecon("/dev/urandom", 0); 421 selinux_android_restorecon("/dev/urandom", 0);
diff --git a/liblog/include/log/log_event_list.h b/liblog/include/log/log_event_list.h
index bb1ce3485..1b7c37717 100644
--- a/liblog/include/log/log_event_list.h
+++ b/liblog/include/log/log_event_list.h
@@ -108,6 +108,13 @@ android_log_context create_android_log_parser(const char* msg, size_t len);
108android_log_list_element android_log_read_next(android_log_context ctx); 108android_log_list_element android_log_read_next(android_log_context ctx);
109android_log_list_element android_log_peek_next(android_log_context ctx); 109android_log_list_element android_log_peek_next(android_log_context ctx);
110 110
111/* Reset writer context */
112int android_log_reset(android_log_context ctx);
113
114/* Reset reader context */
115int android_log_parser_reset(android_log_context ctx,
116 const char* msg, size_t len);
117
111/* Finished with reader or writer context */ 118/* Finished with reader or writer context */
112int android_log_destroy(android_log_context* ctx); 119int android_log_destroy(android_log_context* ctx);
113 120
diff --git a/liblog/include_vndk/log/log_event_list.h b/liblog/include_vndk/log/log_event_list.h
index cbd309174..9f74534be 100644
--- a/liblog/include_vndk/log/log_event_list.h
+++ b/liblog/include_vndk/log/log_event_list.h
@@ -63,6 +63,13 @@ int android_log_write_float32(android_log_context ctx, float value);
63/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */ 63/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */
64int android_log_write_list(android_log_context ctx, log_id_t id); 64int android_log_write_list(android_log_context ctx, log_id_t id);
65 65
66/* Reset writer context */
67int android_log_reset(android_log_context ctx);
68
69/* Reset reader context */
70int android_log_parser_reset(android_log_context ctx,
71 const char* msg, size_t len);
72
66/* Finished with reader or writer context */ 73/* Finished with reader or writer context */
67int android_log_destroy(android_log_context* ctx); 74int android_log_destroy(android_log_context* ctx);
68 75
diff --git a/liblog/liblog.map.txt b/liblog/liblog.map.txt
index 66670fe28..015c9cbf9 100644
--- a/liblog/liblog.map.txt
+++ b/liblog/liblog.map.txt
@@ -53,3 +53,9 @@ LIBLOG_O {
53 __android_log_is_loggable_len; 53 __android_log_is_loggable_len;
54 __android_log_is_debuggable; # vndk 54 __android_log_is_debuggable; # vndk
55}; 55};
56
57LIBLOG_Q {
58 global:
59 android_log_reset; #vndk
60 android_log_parser_reset; #vndk
61};
diff --git a/liblog/log_event_list.c b/liblog/log_event_list.c
index a59cb8738..14002ceb5 100644
--- a/liblog/log_event_list.c
+++ b/liblog/log_event_list.c
@@ -45,14 +45,9 @@ typedef struct {
45 uint8_t storage[LOGGER_ENTRY_MAX_PAYLOAD]; 45 uint8_t storage[LOGGER_ENTRY_MAX_PAYLOAD];
46} android_log_context_internal; 46} android_log_context_internal;
47 47
48LIBLOG_ABI_PUBLIC android_log_context create_android_logger(uint32_t tag) { 48static void init_context(android_log_context_internal* context, uint32_t tag) {
49 size_t needed, i; 49 size_t needed;
50 android_log_context_internal* context;
51 50
52 context = calloc(1, sizeof(android_log_context_internal));
53 if (!context) {
54 return NULL;
55 }
56 context->tag = tag; 51 context->tag = tag;
57 context->read_write_flag = kAndroidLoggerWrite; 52 context->read_write_flag = kAndroidLoggerWrite;
58 needed = sizeof(uint8_t) + sizeof(uint8_t); 53 needed = sizeof(uint8_t) + sizeof(uint8_t);
@@ -63,6 +58,24 @@ LIBLOG_ABI_PUBLIC android_log_context create_android_logger(uint32_t tag) {
63 context->storage[context->pos + 0] = EVENT_TYPE_LIST; 58 context->storage[context->pos + 0] = EVENT_TYPE_LIST;
64 context->list[0] = context->pos + 1; 59 context->list[0] = context->pos + 1;
65 context->pos += needed; 60 context->pos += needed;
61}
62
63static void init_parser_context(android_log_context_internal* context,
64 const char* msg, size_t len) {
65 len = (len <= MAX_EVENT_PAYLOAD) ? len : MAX_EVENT_PAYLOAD;
66 context->len = len;
67 memcpy(context->storage, msg, len);
68 context->read_write_flag = kAndroidLoggerRead;
69}
70
71LIBLOG_ABI_PUBLIC android_log_context create_android_logger(uint32_t tag) {
72 android_log_context_internal* context;
73
74 context = calloc(1, sizeof(android_log_context_internal));
75 if (!context) {
76 return NULL;
77 }
78 init_context(context, tag);
66 79
67 return (android_log_context)context; 80 return (android_log_context)context;
68} 81}
@@ -76,10 +89,7 @@ LIBLOG_ABI_PUBLIC android_log_context create_android_log_parser(const char* msg,
76 if (!context) { 89 if (!context) {
77 return NULL; 90 return NULL;
78 } 91 }
79 len = (len <= MAX_EVENT_PAYLOAD) ? len : MAX_EVENT_PAYLOAD; 92 init_parser_context(context, msg, len);
80 context->len = len;
81 memcpy(context->storage, msg, len);
82 context->read_write_flag = kAndroidLoggerRead;
83 93
84 return (android_log_context)context; 94 return (android_log_context)context;
85} 95}
@@ -97,6 +107,38 @@ LIBLOG_ABI_PUBLIC int android_log_destroy(android_log_context* ctx) {
97 return 0; 107 return 0;
98} 108}
99 109
110LIBLOG_ABI_PUBLIC int android_log_reset(android_log_context ctx) {
111 android_log_context_internal* context;
112 uint32_t tag;
113
114 context = (android_log_context_internal*)ctx;
115 if (!context || (kAndroidLoggerWrite != context->read_write_flag)) {
116 return -EBADF;
117 }
118
119 tag = context->tag;
120 memset(context, 0, sizeof(*context));
121 init_context(context, tag);
122
123 return 0;
124}
125
126LIBLOG_ABI_PUBLIC int android_log_parser_reset(android_log_context ctx,
127 const char* msg, size_t len) {
128 android_log_context_internal* context;
129
130 context = (android_log_context_internal*)ctx;
131 if (!context || (kAndroidLoggerRead != context->read_write_flag)) {
132 return -EBADF;
133 }
134
135 memset(context, 0, sizeof(*context));
136 init_parser_context(context, msg, len);
137
138 return 0;
139}
140
141
100LIBLOG_ABI_PUBLIC int android_log_write_list_begin(android_log_context ctx) { 142LIBLOG_ABI_PUBLIC int android_log_write_list_begin(android_log_context ctx) {
101 size_t needed; 143 size_t needed;
102 android_log_context_internal* context; 144 android_log_context_internal* context;
diff --git a/rootdir/init.rc b/rootdir/init.rc
index d3f038ea5..486d096ab 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -26,6 +26,7 @@ on early-init
26 26
27 # Mount cgroup mount point for cpu accounting 27 # Mount cgroup mount point for cpu accounting
28 mount cgroup none /acct nodev noexec nosuid cpuacct 28 mount cgroup none /acct nodev noexec nosuid cpuacct
29 chmod 0555 /acct
29 mkdir /acct/uid 30 mkdir /acct/uid
30 31
31 # root memory control cgroup, used by lmkd 32 # root memory control cgroup, used by lmkd
diff --git a/shell_and_utilities/Android.bp b/shell_and_utilities/Android.bp
index 0586381e8..3d7521cf2 100644
--- a/shell_and_utilities/Android.bp
+++ b/shell_and_utilities/Android.bp
@@ -27,6 +27,7 @@ phony {
27phony { 27phony {
28 name: "shell_and_utilities_recovery", 28 name: "shell_and_utilities_recovery",
29 required: [ 29 required: [
30 "grep.recovery",
30 "sh.recovery", 31 "sh.recovery",
31 "toolbox.recovery", 32 "toolbox.recovery",
32 "toybox.recovery", 33 "toybox.recovery",
diff --git a/toolbox/Android.bp b/toolbox/Android.bp
index e75e4afcc..f08cf937b 100644
--- a/toolbox/Android.bp
+++ b/toolbox/Android.bp
@@ -62,8 +62,8 @@ cc_binary {
62} 62}
63 63
64// We build BSD grep separately (but see http://b/111849261). 64// We build BSD grep separately (but see http://b/111849261).
65cc_binary { 65cc_defaults {
66 name: "grep", 66 name: "grep_common",
67 defaults: ["toolbox_defaults"], 67 defaults: ["toolbox_defaults"],
68 srcs: [ 68 srcs: [
69 "upstream-netbsd/usr.bin/grep/fastgrep.c", 69 "upstream-netbsd/usr.bin/grep/fastgrep.c",
@@ -72,8 +72,27 @@ cc_binary {
72 "upstream-netbsd/usr.bin/grep/queue.c", 72 "upstream-netbsd/usr.bin/grep/queue.c",
73 "upstream-netbsd/usr.bin/grep/util.c", 73 "upstream-netbsd/usr.bin/grep/util.c",
74 ], 74 ],
75 75 symlinks: [
76 "egrep",
77 "fgrep",
78 ],
76 sanitize: { 79 sanitize: {
77 integer_overflow: false, 80 integer_overflow: false,
78 }, 81 },
79} 82}
83
84cc_binary {
85 name: "grep",
86 defaults: ["grep_common"],
87 recovery_available: true,
88}
89
90// Build vendor grep.
91// TODO: Add vendor_available to "grep" module and remove "grep_vendor" module
92// when vendor_available is fully supported.
93cc_binary {
94 name: "grep_vendor",
95 stem: "grep",
96 vendor: true,
97 defaults: ["grep_common"],
98}