Merge "Add libhealthstoragedefault to make files"
diff --git a/adb/Android.mk b/adb/Android.mk
index d76d175..0eeafb6 100644
--- a/adb/Android.mk
+++ b/adb/Android.mk
@@ -237,7 +237,7 @@
 LOCAL_LDLIBS_linux := -lrt -ldl -lpthread
 LOCAL_LDLIBS_darwin := -framework CoreFoundation -framework IOKit -lobjc
 LOCAL_LDLIBS_windows := -lws2_32 -luserenv
-LOCAL_STATIC_LIBRARIES_windows := AdbWinApi
+LOCAL_SHARED_LIBRARIES_windows := AdbWinApi
 
 LOCAL_MULTILIB := first
 
@@ -254,8 +254,8 @@
 # Use wmain instead of main
 LOCAL_LDFLAGS_windows := -municode
 LOCAL_LDLIBS_windows := -lws2_32 -lgdi32
-LOCAL_STATIC_LIBRARIES_windows := AdbWinApi
-LOCAL_REQUIRED_MODULES_windows := AdbWinApi AdbWinUsbApi
+LOCAL_SHARED_LIBRARIES_windows := AdbWinApi
+LOCAL_REQUIRED_MODULES_windows := AdbWinUsbApi
 
 LOCAL_SRC_FILES := \
     adb_client.cpp \
diff --git a/base/include/android-base/stringprintf.h b/base/include/android-base/stringprintf.h
index cf666ab..1fd6297 100644
--- a/base/include/android-base/stringprintf.h
+++ b/base/include/android-base/stringprintf.h
@@ -28,27 +28,27 @@
 // if the mingw version of vsnprintf is used, use `gnu_printf' which allows z
 // in %zd and PRIu64 (and related) to be recognized by the compile-time
 // checking.
-#define FORMAT_ARCHETYPE __printf__
+#define ANDROID_BASE_FORMAT_ARCHETYPE __printf__
 #ifdef __USE_MINGW_ANSI_STDIO
 #if __USE_MINGW_ANSI_STDIO
-#undef FORMAT_ARCHETYPE
-#define FORMAT_ARCHETYPE gnu_printf
+#undef ANDROID_BASE_FORMAT_ARCHETYPE
+#define ANDROID_BASE_FORMAT_ARCHETYPE gnu_printf
 #endif
 #endif
 
 // Returns a string corresponding to printf-like formatting of the arguments.
 std::string StringPrintf(const char* fmt, ...)
-    __attribute__((__format__(FORMAT_ARCHETYPE, 1, 2)));
+    __attribute__((__format__(ANDROID_BASE_FORMAT_ARCHETYPE, 1, 2)));
 
 // Appends a printf-like formatting of the arguments to 'dst'.
 void StringAppendF(std::string* dst, const char* fmt, ...)
-    __attribute__((__format__(FORMAT_ARCHETYPE, 2, 3)));
+    __attribute__((__format__(ANDROID_BASE_FORMAT_ARCHETYPE, 2, 3)));
 
 // Appends a printf-like formatting of the arguments to 'dst'.
 void StringAppendV(std::string* dst, const char* format, va_list ap)
-    __attribute__((__format__(FORMAT_ARCHETYPE, 2, 0)));
+    __attribute__((__format__(ANDROID_BASE_FORMAT_ARCHETYPE, 2, 0)));
 
-#undef FORMAT_ARCHETYPE
+#undef ANDROID_BASE_FORMAT_ARCHETYPE
 
 }  // namespace base
 }  // namespace android
diff --git a/base/include/android-base/thread_annotations.h b/base/include/android-base/thread_annotations.h
index fbb5923..1307f0e 100644
--- a/base/include/android-base/thread_annotations.h
+++ b/base/include/android-base/thread_annotations.h
@@ -38,6 +38,12 @@
 #define PT_GUARDED_BY(x) \
       THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
 
+#define EXCLUSIVE_LOCKS_REQUIRED(...) \
+      THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(__VA_ARGS__))
+
+#define SHARED_LOCKS_REQUIRED(...) \
+      THREAD_ANNOTATION_ATTRIBUTE__(shared_locks_required(__VA_ARGS__))
+
 #define ACQUIRED_BEFORE(...) \
       THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__))
 
diff --git a/fastboot/Android.mk b/fastboot/Android.mk
index 10ef356..dfcf090 100644
--- a/fastboot/Android.mk
+++ b/fastboot/Android.mk
@@ -50,8 +50,8 @@
 LOCAL_CFLAGS_darwin := -Wno-unused-parameter
 
 LOCAL_SRC_FILES_windows := usb_windows.cpp
-LOCAL_STATIC_LIBRARIES_windows := AdbWinApi
-LOCAL_REQUIRED_MODULES_windows := AdbWinApi AdbWinUsbApi
+LOCAL_SHARED_LIBRARIES_windows := AdbWinApi
+LOCAL_REQUIRED_MODULES_windows := AdbWinUsbApi
 LOCAL_LDLIBS_windows := -lws2_32
 LOCAL_C_INCLUDES_windows := development/host/windows/usb/api
 
diff --git a/fastboot/engine.cpp b/fastboot/engine.cpp
index 7e10cc9..271b792 100644
--- a/fastboot/engine.cpp
+++ b/fastboot/engine.cpp
@@ -114,7 +114,7 @@
 
     if (cmdsize >= sizeof(a->cmd)) {
         free(a);
-        die("Command length (%d) exceeds maximum size (%d)", cmdsize, sizeof(a->cmd));
+        die("Command length (%zu) exceeds maximum size (%zu)", cmdsize, sizeof(a->cmd));
     }
 
     if (action_last) {
diff --git a/fastboot/fastboot.h b/fastboot/fastboot.h
index e3c60ae..f4faa21 100644
--- a/fastboot/fastboot.h
+++ b/fastboot/fastboot.h
@@ -75,7 +75,22 @@
 /* util stuff */
 double now();
 char *mkmsg(const char *fmt, ...);
-__attribute__((__noreturn__)) void die(const char *fmt, ...);
+
+// These printf-like functions are implemented in terms of vsnprintf, so they
+// use the same attribute for compile-time format string checking. On Windows,
+// if the mingw version of vsnprintf is used, use `gnu_printf' which allows z
+// in %zd and PRIu64 (and related) to be recognized by the compile-time
+// checking.
+#define FASTBOOT_FORMAT_ARCHETYPE __printf__
+#ifdef __USE_MINGW_ANSI_STDIO
+#if __USE_MINGW_ANSI_STDIO
+#undef FASTBOOT_FORMAT_ARCHETYPE
+#define FASTBOOT_FORMAT_ARCHETYPE gnu_printf
+#endif
+#endif
+void die(const char* fmt, ...) __attribute__((__noreturn__))
+__attribute__((__format__(FASTBOOT_FORMAT_ARCHETYPE, 1, 2)));
+#undef FASTBOOT_FORMAT_ARCHETYPE
 
 /* Current product */
 extern char cur_product[FB_RESPONSE_SZ + 1];
diff --git a/libcutils/include/private/android_filesystem_config.h b/libcutils/include/private/android_filesystem_config.h
index 2f2e262..5753e49 100644
--- a/libcutils/include/private/android_filesystem_config.h
+++ b/libcutils/include/private/android_filesystem_config.h
@@ -123,6 +123,8 @@
 #define AID_LOWPAN 1063          /* LoWPAN subsystem */
 #define AID_HSM 1064             /* hardware security module subsystem */
 #define AID_RESERVED_DISK 1065   /* GID that has access to reserved disk space */
+#define AID_STATSD 1066          /* statsd daemon */
+#define AID_INCIDENTD 1067       /* incidentd daemon */
 /* Changes to this file must be made in AOSP, *not* in internal branches. */
 
 #define AID_SHELL 2000 /* adb and debug shell user */
diff --git a/libcutils/uevent.cpp b/libcutils/uevent.cpp
index a84e5b0..2dfceed 100644
--- a/libcutils/uevent.cpp
+++ b/libcutils/uevent.cpp
@@ -27,54 +27,6 @@
 
 #include <linux/netlink.h>
 
-#include <fstream>
-
-#include <private/android_filesystem_config.h>
-
-namespace {
-
-// Returns the uid of root in the current user namespace.
-// Returns AID_OVERFLOWUID if the root user is not mapped in the current
-// namespace.
-// Returns 0 if the kernel is not user namespace-aware (for backwards
-// compatibility) or if AID_OVERFLOWUID could not be validated to match what the
-// kernel would return.
-uid_t GetRootUid() {
-    constexpr uid_t kParentRootUid = 0;
-
-    std::ifstream uid_map_file("/proc/self/uid_map");
-    if (!uid_map_file) {
-        // The kernel does not support user namespaces.
-        return kParentRootUid;
-    }
-
-    uid_t current_namespace_uid, parent_namespace_uid;
-    uint32_t length;
-    while (uid_map_file >> current_namespace_uid >> parent_namespace_uid >> length) {
-        // Since kParentRootUid is 0, it should be the first entry in the mapped
-        // range.
-        if (parent_namespace_uid != kParentRootUid || length < 1) continue;
-        return current_namespace_uid;
-    }
-
-    // Sanity check: verify that the overflow UID is the one to be returned by
-    // the kernel.
-    std::ifstream overflowuid_file("/proc/sys/kernel/overflowuid");
-    if (!overflowuid_file) {
-        // It's better to return 0 in case we cannot make sure that the overflow
-        // UID matches.
-        return kParentRootUid;
-    }
-    uid_t kernel_overflow_uid;
-    if (!(overflowuid_file >> kernel_overflow_uid) || kernel_overflow_uid != AID_OVERFLOWUID)
-        return kParentRootUid;
-
-    // root is unmapped, use the kernel "overflow" uid.
-    return AID_OVERFLOWUID;
-}
-
-}  // namespace
-
 extern "C" {
 
 /**
@@ -99,7 +51,6 @@
 }
 
 ssize_t uevent_kernel_recv(int socket, void* buffer, size_t length, bool require_group, uid_t* uid) {
-    static const uid_t root_uid = GetRootUid();
     struct iovec iov = {buffer, length};
     struct sockaddr_nl addr;
     char control[CMSG_SPACE(sizeof(struct ucred))];
@@ -122,10 +73,6 @@
 
     cred = (struct ucred*)CMSG_DATA(cmsg);
     *uid = cred->uid;
-    if (cred->uid != root_uid) {
-        /* ignoring netlink message from non-root user */
-        goto out;
-    }
 
     if (addr.nl_pid != 0) {
         /* ignore non-kernel */
diff --git a/liblog/Android.bp b/liblog/Android.bp
index 7d9e306..eae0b10 100644
--- a/liblog/Android.bp
+++ b/liblog/Android.bp
@@ -80,10 +80,6 @@
                 address: false,
             },
         },
-        android_arm: {
-            // TODO: This is to work around b/24465209. Remove after root cause is fixed
-            ldflags: ["-Wl,--hash-style=both"],
-        },
         windows: {
             srcs: ["uio.c"],
             enabled: true,
diff --git a/property_service/libpropertyinfoparser/Android.bp b/property_service/libpropertyinfoparser/Android.bp
index e0cd30c..ea9b968 100644
--- a/property_service/libpropertyinfoparser/Android.bp
+++ b/property_service/libpropertyinfoparser/Android.bp
@@ -5,13 +5,6 @@
     srcs: ["property_info_parser.cpp"],
 
     cpp_std: "experimental",
-    target: {
-        linux: {
-            sanitize: {
-                misc_undefined: ["signed-integer-overflow"],
-            },
-        },
-    },
     cppflags: [
         "-Wall",
         "-Wextra",
diff --git a/property_service/libpropertyinfoserializer/Android.bp b/property_service/libpropertyinfoserializer/Android.bp
index 5de7477..72ae19a 100644
--- a/property_service/libpropertyinfoserializer/Android.bp
+++ b/property_service/libpropertyinfoserializer/Android.bp
@@ -3,13 +3,6 @@
     host_supported: true,
     vendor_available: true,
     cpp_std: "experimental",
-    target: {
-        linux: {
-            sanitize: {
-                misc_undefined: ["signed-integer-overflow"],
-            },
-        },
-    },
     cppflags: [
         "-Wall",
         "-Wextra",
diff --git a/property_service/property_info_checker/Android.bp b/property_service/property_info_checker/Android.bp
index 6e9e7f1..6ee649a 100644
--- a/property_service/property_info_checker/Android.bp
+++ b/property_service/property_info_checker/Android.bp
@@ -3,13 +3,6 @@
     host_supported: true,
     static_executable: true,
     cpp_std: "experimental",
-    target: {
-        linux: {
-            sanitize: {
-                misc_undefined: ["signed-integer-overflow"],
-            },
-        },
-    },
     static_libs: [
         "libpropertyinfoserializer",
         "libpropertyinfoparser",
diff --git a/rootdir/Android.mk b/rootdir/Android.mk
index 19269d8..7804f6d 100644
--- a/rootdir/Android.mk
+++ b/rootdir/Android.mk
@@ -125,14 +125,12 @@
 bcp_md5 :=
 bcp_dep :=
 
-# If PLATFORM_VNDK_VERSION is defined and not "current", generate versioned
-# module names for ld.config.txt, llndk.libraries.txt and vndksp.libraries.txt
-# files.
-define versioned_module_name
+# If BOARD_VNDK_VERSION is defined, append PLATFORM_VNDK_VERSION to base name.
+define append_vndk_version
 $(strip \
-  $(if $(filter-out current,$(PLATFORM_VNDK_VERSION)), \
-    $(basename $(LOCAL_MODULE)).$(PLATFORM_VNDK_VERSION)$(suffix $(LOCAL_MODULE)), \
-    $(LOCAL_MODULE) \
+  $(if $(BOARD_VNDK_VERSION), \
+    $(basename $(1)).$(PLATFORM_VNDK_VERSION)$(suffix $(1)), \
+    $(1) \
   ) \
 )
 endef
@@ -153,7 +151,7 @@
 LOCAL_MODULE := ld.config.txt
 LOCAL_MODULE_CLASS := ETC
 LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)
-LOCAL_MODULE_STEM := $(call versioned_module_name)
+LOCAL_MODULE_STEM := $(call append_vndk_version,$(LOCAL_MODULE))
 include $(BUILD_SYSTEM)/base_rules.mk
 
 llndk_libraries := $(call normalize-path-list,$(addsuffix .so,\
@@ -200,7 +198,7 @@
 LOCAL_MODULE := ld.config.txt
 ifeq ($(PRODUCT_TREBLE_LINKER_NAMESPACES)|$(SANITIZE_TARGET),true|)
   LOCAL_SRC_FILES := etc/ld.config.txt
-  LOCAL_MODULE_STEM := $(call versioned_module_name)
+  LOCAL_MODULE_STEM := $(call append_vndk_version,$(LOCAL_MODULE))
 else
   LOCAL_SRC_FILES := etc/ld.config.legacy.txt
   LOCAL_MODULE_STEM := $(LOCAL_MODULE)
@@ -216,7 +214,7 @@
 LOCAL_MODULE := llndk.libraries.txt
 LOCAL_MODULE_CLASS := ETC
 LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)
-LOCAL_MODULE_STEM := $(call versioned_module_name)
+LOCAL_MODULE_STEM := $(call append_vndk_version,$(LOCAL_MODULE))
 include $(BUILD_SYSTEM)/base_rules.mk
 $(LOCAL_BUILT_MODULE): PRIVATE_LLNDK_LIBRARIES := $(LLNDK_LIBRARIES)
 $(LOCAL_BUILT_MODULE):
@@ -232,7 +230,7 @@
 LOCAL_MODULE := vndksp.libraries.txt
 LOCAL_MODULE_CLASS := ETC
 LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)
-LOCAL_MODULE_STEM := $(call versioned_module_name)
+LOCAL_MODULE_STEM := $(call append_vndk_version,$(LOCAL_MODULE))
 include $(BUILD_SYSTEM)/base_rules.mk
 $(LOCAL_BUILT_MODULE): PRIVATE_VNDK_SAMEPROCESS_LIBRARIES := $(VNDK_SAMEPROCESS_LIBRARIES)
 $(LOCAL_BUILT_MODULE):
diff --git a/rootdir/etc/ld.config.txt.in b/rootdir/etc/ld.config.txt.in
index 70363569..ffc4359 100644
--- a/rootdir/etc/ld.config.txt.in
+++ b/rootdir/etc/ld.config.txt.in
@@ -277,12 +277,6 @@
 namespace.vndk.search.paths  = /system/${LIB}/vndk-sp${VNDK_VER}
 namespace.vndk.search.paths += /system/${LIB}/vndk${VNDK_VER}
 
-# This is exceptionally required since android.hidl.memory@1.0-impl.so is here
-namespace.vndk.permitted.paths = /system/${LIB}/vndk-sp${VNDK_VER}/hw
-
-namespace.vndk.asan.permitted.paths += /data/asan/system/${LIB}/vndk-sp${VNDK_VER}/hw
-namespace.vndk.asan.permitted.paths +=           /system/${LIB}/vndk-sp${VNDK_VER}/hw
-
 namespace.vndk.asan.search.paths  = /data/asan/system/${LIB}/vndk-sp${VNDK_VER}
 namespace.vndk.asan.search.paths +=           /system/${LIB}/vndk-sp${VNDK_VER}
 namespace.vndk.asan.search.paths += /data/asan/system/${LIB}/vndk${VNDK_VER}
diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc
index eadf219..b03d83b 100644
--- a/rootdir/ueventd.rc
+++ b/rootdir/ueventd.rc
@@ -77,6 +77,7 @@
 /dev/graphics/*           0660   root       graphics
 /dev/msm_hw3dm            0660   system     graphics
 /dev/input/*              0660   root       input
+/dev/v4l-touch*           0660   root       input
 /dev/eac                  0660   root       audio
 /dev/cam                  0660   root       camera
 /dev/pmem                 0660   system     graphics
diff --git a/shell_and_utilities/Android.bp b/shell_and_utilities/Android.bp
index 4203db4..3ccb92f 100644
--- a/shell_and_utilities/Android.bp
+++ b/shell_and_utilities/Android.bp
@@ -12,6 +12,7 @@
         "sh",
         "sh_vendor",
         "toolbox",
+        "toolbox_vendor",
         "toybox",
         "toybox_vendor",
     ],
diff --git a/toolbox/Android.bp b/toolbox/Android.bp
index de8324a..9f7fc3b 100644
--- a/toolbox/Android.bp
+++ b/toolbox/Android.bp
@@ -13,6 +13,7 @@
 cc_library_static {
     name: "libtoolbox_dd",
     defaults: ["toolbox_defaults"],
+    vendor_available: true,
     srcs: [
         "upstream-netbsd/bin/dd/args.c",
         "upstream-netbsd/bin/dd/conv.c",
@@ -33,12 +34,6 @@
 }
 
 genrule {
-    name: "toolbox_tools",
-    cmd: "echo '/* file generated automatically */' >$(out) && for t in toolbox dd getevent newfs_msdos getprop; do echo \"TOOL($$t)\" >>$(out); done",
-    out: ["tools.h"],
-}
-
-genrule {
     name: "toolbox_input_labels",
     tool_files: ["generate-input.h-labels.py"],
     cmd: "$(location) $(in) >$(out)",
@@ -46,9 +41,10 @@
     out: ["input.h-labels.h"],
 }
 
-cc_binary {
-    name: "toolbox",
+cc_defaults {
+    name: "toolbox_binary_defaults",
     defaults: ["toolbox_defaults"],
+    cpp_std: "experimental",
     srcs: [
         "toolbox.c",
         "getevent.c",
@@ -56,7 +52,6 @@
         "newfs_msdos.c",
     ],
     generated_headers: [
-        "toolbox_tools",
         "toolbox_input_labels",
     ],
     whole_static_libs: ["libtoolbox_dd"],
@@ -64,10 +59,7 @@
         "libbase",
         "libcutils",
     ],
-    static_libs: [
-        "libpropertyinfoparser",
-    ],
-    cpp_std: "gnu++1z",
+    static_libs: ["libpropertyinfoparser"],
 
     symlinks: [
         "dd",
@@ -77,6 +69,18 @@
     ],
 }
 
+cc_binary {
+    name: "toolbox",
+    defaults: ["toolbox_binary_defaults"],
+}
+
+cc_binary {
+    name: "toolbox_vendor",
+    stem: "toolbox",
+    vendor: true,
+    defaults: ["toolbox_binary_defaults"],
+}
+
 // We only want 'r' on userdebug and eng builds.
 cc_binary {
     name: "r",
diff --git a/toolbox/getprop.cpp b/toolbox/getprop.cpp
index 7818ff2..611e244 100644
--- a/toolbox/getprop.cpp
+++ b/toolbox/getprop.cpp
@@ -30,97 +30,98 @@
 PropertyInfoAreaFile property_info_file;
 
 void PrintAllProperties(bool print_property_context) {
-  std::vector<std::pair<std::string, std::string>> properties;
-  __system_property_foreach(
-      [](const prop_info* pi, void* cookie) {
-        __system_property_read_callback(
-            pi,
-            [](void* cookie, const char* name, const char* value, unsigned) {
-              auto properties =
-                  reinterpret_cast<std::vector<std::pair<std::string, std::string>>*>(cookie);
-              properties->emplace_back(name, value);
-            },
-            cookie);
-      },
-      &properties);
+    std::vector<std::pair<std::string, std::string>> properties;
+    __system_property_foreach(
+        [](const prop_info* pi, void* cookie) {
+            __system_property_read_callback(
+                pi,
+                [](void* cookie, const char* name, const char* value, unsigned) {
+                    auto properties =
+                        reinterpret_cast<std::vector<std::pair<std::string, std::string>>*>(cookie);
+                    properties->emplace_back(name, value);
+                },
+                cookie);
+        },
+        &properties);
 
-  std::sort(properties.begin(), properties.end());
+    std::sort(properties.begin(), properties.end());
 
-  if (print_property_context) {
-    for (auto& [name, value] : properties) {
-      const char* context = nullptr;
-      property_info_file->GetPropertyInfo(name.c_str(), &context, nullptr);
-      value = context;
+    if (print_property_context) {
+        for (auto& [name, value] : properties) {
+            const char* context = nullptr;
+            property_info_file->GetPropertyInfo(name.c_str(), &context, nullptr);
+            value = context;
+        }
     }
-  }
 
-  for (const auto& [name, value] : properties) {
-    std::cout << "[" << name << "]: [" << value << "]" << std::endl;
-  }
+    for (const auto& [name, value] : properties) {
+        std::cout << "[" << name << "]: [" << value << "]" << std::endl;
+    }
 }
 
 void PrintProperty(const char* name, const char* default_value, bool print_property_context) {
-  if (print_property_context) {
-    const char* context = nullptr;
-    property_info_file->GetPropertyInfo(name, &context, nullptr);
-    std::cout << context << std::endl;
-  } else {
-    std::cout << GetProperty(name, default_value) << std::endl;
-  }
+    if (print_property_context) {
+        const char* context = nullptr;
+        property_info_file->GetPropertyInfo(name, &context, nullptr);
+        std::cout << context << std::endl;
+    } else {
+        std::cout << GetProperty(name, default_value) << std::endl;
+    }
 }
 
 extern "C" int getprop_main(int argc, char** argv) {
-  bool print_property_context = false;
+    bool print_property_context = false;
 
-  while (true) {
-    static const struct option long_options[] = {
-        {"help", no_argument, nullptr, 'h'},
-        {nullptr, 0, nullptr, 0},
-    };
+    while (true) {
+        static const struct option long_options[] = {
+            {"help", no_argument, nullptr, 'h'},
+            {nullptr, 0, nullptr, 0},
+        };
 
-    int arg = getopt_long(argc, argv, "Z", long_options, nullptr);
+        int arg = getopt_long(argc, argv, "Z", long_options, nullptr);
 
-    if (arg == -1) {
-      break;
+        if (arg == -1) {
+            break;
+        }
+
+        switch (arg) {
+            case 'h':
+                std::cout << "usage: getprop [-Z] [NAME [DEFAULT]]\n\n"
+                             "Gets an Android system property, or lists them all.\n"
+                             "Use -Z to return the property context instead of the property value\n"
+                          << std::endl;
+                return 0;
+            case 'Z':
+                print_property_context = true;
+                break;
+            case '?':
+                return -1;
+            default:
+                std::cerr << "getprop: getopt returned invalid result: " << arg << std::endl;
+                return -1;
+        }
     }
 
-    switch (arg) {
-      case 'h':
-        std::cout << "usage: getprop [-Z] [NAME [DEFAULT]]\n\n"
-                     "Gets an Android system property, or lists them all.\n"
-                     "Use -Z to return the property context instead of the property value\n"
-                  << std::endl;
+    if (print_property_context) {
+        property_info_file.LoadDefaultPath();
+        if (!property_info_file) {
+            std::cerr << "Unable to load property info file" << std::endl;
+            return -1;
+        }
+    }
+
+    if (optind >= argc) {
+        PrintAllProperties(print_property_context);
         return 0;
-      case 'Z':
-        print_property_context = true;
-        break;
-      case '?':
-        return -1;
-      default:
-        std::cerr << "getprop: getopt returned invalid result: " << arg << std::endl;
+    }
+
+    if (optind < argc - 2) {
+        std::cerr << "getprop: Max 2 arguments (see \"getprop --help\")" << std::endl;
         return -1;
     }
-  }
 
-  if (print_property_context) {
-    property_info_file.LoadDefaultPath();
-    if (!property_info_file) {
-      std::cerr << "Unable to load property info file" << std::endl;
-      return -1;
-    }
-  }
+    PrintProperty(argv[optind], (optind == argc - 1) ? "" : argv[optind + 1],
+                  print_property_context);
 
-  if (optind >= argc) {
-    PrintAllProperties(print_property_context);
     return 0;
-  }
-
-  if (optind < argc - 2) {
-    std::cerr << "getprop: Max 2 arguments (see \"getprop --help\")" << std::endl;
-    return -1;
-  }
-
-  PrintProperty(argv[optind], (optind == argc - 1) ? "" : argv[optind + 1], print_property_context);
-
-  return 0;
 }
diff --git a/toolbox/tools.h b/toolbox/tools.h
new file mode 100644
index 0000000..505f528
--- /dev/null
+++ b/toolbox/tools.h
@@ -0,0 +1,5 @@
+TOOL(dd)
+TOOL(getevent)
+TOOL(getprop)
+TOOL(newfs_msdos)
+TOOL(toolbox)