diff options
Diffstat (limited to 'minadbd')
-rw-r--r-- | minadbd/Android.bp | 5 | ||||
-rw-r--r-- | minadbd/fuse_adb_provider.h | 4 | ||||
-rw-r--r-- | minadbd/minadbd_services.cpp | 54 | ||||
-rw-r--r-- | minadbd/minadbd_types.h | 1 |
4 files changed, 49 insertions, 15 deletions
diff --git a/minadbd/Android.bp b/minadbd/Android.bp index 007e5057b..afd57ad2d 100644 --- a/minadbd/Android.bp +++ b/minadbd/Android.bp @@ -43,6 +43,10 @@ cc_library { "minadbd_services.cpp", ], + static_libs: [ + "libotautil", + ], + shared_libs: [ "libadbd", "libbase", @@ -96,6 +100,7 @@ cc_test { static_libs: [ "libminadbd_services", "libfusesideload", + "libotautil", "libadbd", "libcrypto", ], diff --git a/minadbd/fuse_adb_provider.h b/minadbd/fuse_adb_provider.h index c5561e57d..43c07d28e 100644 --- a/minadbd/fuse_adb_provider.h +++ b/minadbd/fuse_adb_provider.h @@ -29,6 +29,10 @@ class FuseAdbDataProvider : public FuseDataProvider { bool ReadBlockAlignedData(uint8_t* buffer, uint32_t fetch_size, uint32_t start_block) const override; + bool Valid() const override { + return fd_ != -1; + } + private: // The underlying source to read data from (i.e. the one that talks to the host). int fd_; diff --git a/minadbd/minadbd_services.cpp b/minadbd/minadbd_services.cpp index 1c4c0f494..c31afbe06 100644 --- a/minadbd/minadbd_services.cpp +++ b/minadbd/minadbd_services.cpp @@ -25,10 +25,10 @@ #include <functional> #include <memory> +#include <set> #include <string> #include <string_view> #include <thread> -#include <unordered_set> #include <android-base/file.h> #include <android-base/logging.h> @@ -41,7 +41,6 @@ #include "adb.h" #include "adb_unique_fd.h" #include "adb_utils.h" -#include "fdevent.h" #include "fuse_adb_provider.h" #include "fuse_sideload.h" #include "minadbd_types.h" @@ -156,23 +155,48 @@ static void RescueInstallHostService(unique_fd sfd, const std::string& args) { } } +// Answers the query on a given property |prop|, by writing the result to the given |sfd|. The +// result will be newline-terminated, so nonexistent or nonallowed query will be answered with "\n". +// If given an empty string, dumps all the supported properties (analogous to `adb shell getprop`) +// in lines, e.g. "[prop]: [value]". static void RescueGetpropHostService(unique_fd sfd, const std::string& prop) { - static const std::unordered_set<std::string> kGetpropAllowedProps = { - "ro.build.fingerprint", + static const std::set<std::string> kGetpropAllowedProps = { "ro.build.date.utc", + "ro.build.fingerprint", + "ro.build.flavor", + "ro.build.id", + "ro.build.product", + "ro.build.tags", + "ro.build.version.incremental", + "ro.product.device", + "ro.product.vendor.device", }; - auto allowed = kGetpropAllowedProps.find(prop) != kGetpropAllowedProps.end(); - if (!allowed) { - return; + std::string result; + if (prop.empty()) { + for (const auto& key : kGetpropAllowedProps) { + auto value = android::base::GetProperty(key, ""); + if (value.empty()) { + continue; + } + result += "[" + key + "]: [" + value + "]\n"; + } + } else if (kGetpropAllowedProps.find(prop) != kGetpropAllowedProps.end()) { + result = android::base::GetProperty(prop, "") + "\n"; } - - auto result = android::base::GetProperty(prop, ""); if (result.empty()) { - return; + result = "\n"; } if (!android::base::WriteFully(sfd, result.data(), result.size())) { exit(kMinadbdHostSocketIOError); } + + // Send heartbeat signal to keep the rescue service alive. + if (!WriteCommandToFd(MinadbdCommand::kNoOp, minadbd_socket)) { + exit(kMinadbdSocketIOError); + } + if (MinadbdCommandStatus status; !WaitForCommandStatus(minadbd_socket, &status)) { + exit(kMinadbdMessageFormatError); + } } // Reboots into the given target. We don't reboot directly from minadbd, but going through recovery @@ -230,7 +254,7 @@ static void WipeDeviceService(unique_fd fd, const std::string& args) { unique_fd daemon_service_to_fd(std::string_view name, atransport* /* transport */) { // Common services that are supported both in sideload and rescue modes. - if (ConsumePrefix(&name, "reboot:")) { + if (android::base::ConsumePrefix(&name, "reboot:")) { // "reboot:<target>", where target must be one of the following. std::string args(name); if (args.empty() || args == "bootloader" || args == "rescue" || args == "recovery" || @@ -243,17 +267,17 @@ unique_fd daemon_service_to_fd(std::string_view name, atransport* /* transport * // Rescue-specific services. if (rescue_mode) { - if (ConsumePrefix(&name, "rescue-install:")) { + if (android::base::ConsumePrefix(&name, "rescue-install:")) { // rescue-install:<file-size>:<block-size> std::string args(name); return create_service_thread( "rescue-install", std::bind(RescueInstallHostService, std::placeholders::_1, args)); - } else if (ConsumePrefix(&name, "rescue-getprop:")) { + } else if (android::base::ConsumePrefix(&name, "rescue-getprop:")) { // rescue-getprop:<prop> std::string args(name); return create_service_thread( "rescue-getprop", std::bind(RescueGetpropHostService, std::placeholders::_1, args)); - } else if (ConsumePrefix(&name, "rescue-wipe:")) { + } else if (android::base::ConsumePrefix(&name, "rescue-wipe:")) { // rescue-wipe:target:<message-size> std::string args(name); return create_service_thread("rescue-wipe", @@ -268,7 +292,7 @@ unique_fd daemon_service_to_fd(std::string_view name, atransport* /* transport * // This exit status causes recovery to print a special error message saying to use a newer adb // (that supports sideload-host). exit(kMinadbdAdbVersionError); - } else if (ConsumePrefix(&name, "sideload-host:")) { + } else if (android::base::ConsumePrefix(&name, "sideload-host:")) { // sideload-host:<file-size>:<block-size> std::string args(name); return create_service_thread("sideload-host", diff --git a/minadbd/minadbd_types.h b/minadbd/minadbd_types.h index 99fd45e83..002523f1f 100644 --- a/minadbd/minadbd_types.h +++ b/minadbd/minadbd_types.h @@ -53,6 +53,7 @@ enum class MinadbdCommand : uint32_t { kRebootRescue = 6, kWipeCache = 7, kWipeData = 8, + kNoOp = 9, // Last but invalid command. kError, |