Merge "Set HAVE_LOCALTIME_R to 1 when defined."
diff --git a/adb/Android.mk b/adb/Android.mk
index 7744d2b..248208a 100644
--- a/adb/Android.mk
+++ b/adb/Android.mk
@@ -133,6 +133,10 @@
LOCAL_CFLAGS += -DANDROID_GADGET=1
endif
+ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
+LOCAL_CFLAGS += -DALLOW_ADBD_ROOT=1
+endif
+
LOCAL_MODULE := adbd
LOCAL_FORCE_STATIC_EXECUTABLE := true
diff --git a/adb/adb.c b/adb/adb.c
index 6dbd562..4434524 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -842,10 +842,43 @@
snprintf(target_str, target_size, "tcp:%d", server_port);
}
+#if !ADB_HOST
+static int should_drop_privileges() {
+#ifndef ALLOW_ADBD_ROOT
+ return 1;
+#else /* ALLOW_ADBD_ROOT */
+ int secure = 0;
+ char value[PROPERTY_VALUE_MAX];
+
+ /* run adbd in secure mode if ro.secure is set and
+ ** we are not in the emulator
+ */
+ property_get("ro.kernel.qemu", value, "");
+ if (strcmp(value, "1") != 0) {
+ property_get("ro.secure", value, "1");
+ if (strcmp(value, "1") == 0) {
+ // don't run as root if ro.secure is set...
+ secure = 1;
+
+ // ... except we allow running as root in userdebug builds if the
+ // service.adb.root property has been set by the "adb root" command
+ property_get("ro.debuggable", value, "");
+ if (strcmp(value, "1") == 0) {
+ property_get("service.adb.root", value, "");
+ if (strcmp(value, "1") == 0) {
+ secure = 0;
+ }
+ }
+ }
+ }
+ return secure;
+#endif /* ALLOW_ADBD_ROOT */
+}
+#endif /* !ADB_HOST */
+
int adb_main(int is_daemon, int server_port)
{
#if !ADB_HOST
- int secure = 0;
int port;
char value[PROPERTY_VALUE_MAX];
#endif
@@ -873,31 +906,10 @@
exit(1);
}
#else
- /* run adbd in secure mode if ro.secure is set and
- ** we are not in the emulator
- */
- property_get("ro.kernel.qemu", value, "");
- if (strcmp(value, "1") != 0) {
- property_get("ro.secure", value, "1");
- if (strcmp(value, "1") == 0) {
- // don't run as root if ro.secure is set...
- secure = 1;
-
- // ... except we allow running as root in userdebug builds if the
- // service.adb.root property has been set by the "adb root" command
- property_get("ro.debuggable", value, "");
- if (strcmp(value, "1") == 0) {
- property_get("service.adb.root", value, "");
- if (strcmp(value, "1") == 0) {
- secure = 0;
- }
- }
- }
- }
/* don't listen on a port (default 5037) if running in secure mode */
/* don't run as root if we are running in secure mode */
- if (secure) {
+ if (should_drop_privileges()) {
struct __user_cap_header_struct header;
struct __user_cap_data_struct cap;