From 5359d777e624ddc6b50ae7221d61e83ff52bab80 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 4 Jun 2019 11:20:00 -0700 Subject: minadbd: Support `adb rescue getprop`. It dumps all the allowed properties, similar to `adb shell getprop`. Bug: 134027350 Test: Run the command under rescue mode. Change-Id: Ic0864ca0fb51505ec1e4f38af2464591aa576201 Merged-In: Ic0864ca0fb51505ec1e4f38af2464591aa576201 (cherry picked from commit d8db81a01464c53c9bd6dbff32194faed85b6ccc) --- minadbd/minadbd_services.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/minadbd/minadbd_services.cpp b/minadbd/minadbd_services.cpp index e271c36fe..7181fcf45 100644 --- a/minadbd/minadbd_services.cpp +++ b/minadbd/minadbd_services.cpp @@ -25,10 +25,10 @@ #include #include +#include #include #include #include -#include #include #include @@ -156,8 +156,11 @@ static void RescueInstallHostService(unique_fd sfd, const std::string& args) { } } +// Answers the query on a given property. The result will be written to the given sfd. If given an +// empty string, dumps all the supported properties (similar 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 kGetpropAllowedProps = { + static const std::set kGetpropAllowedProps = { "ro.build.date.utc", "ro.build.fingerprint", "ro.build.flavor", @@ -168,12 +171,22 @@ static void RescueGetpropHostService(unique_fd sfd, const std::string& prop) { "ro.product.device", "ro.product.vendor.device", }; - auto allowed = kGetpropAllowedProps.find(prop) != kGetpropAllowedProps.end(); - if (!allowed) { + if (!prop.empty() && kGetpropAllowedProps.find(prop) == kGetpropAllowedProps.end()) { return; } - auto result = android::base::GetProperty(prop, ""); + 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 { + result = android::base::GetProperty(prop, ""); + } if (result.empty()) { return; } -- cgit v1.2.3