Merge "minadbd: Support adb rescue getprop." am: 533a12c71e

am: 0d00c1bf12

Change-Id: I124c643a9aff253e65c5ad81c5f941d6bc697e40
This commit is contained in:
Tao Bao
2019-06-05 14:13:00 -07:00
committed by android-build-merger

View File

@@ -25,10 +25,10 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <set>
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <thread> #include <thread>
#include <unordered_set>
#include <android-base/file.h> #include <android-base/file.h>
#include <android-base/logging.h> #include <android-base/logging.h>
@@ -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 void RescueGetpropHostService(unique_fd sfd, const std::string& prop) {
static const std::unordered_set<std::string> kGetpropAllowedProps = { static const std::set<std::string> kGetpropAllowedProps = {
"ro.build.date.utc", "ro.build.date.utc",
"ro.build.fingerprint", "ro.build.fingerprint",
"ro.build.flavor", "ro.build.flavor",
@@ -168,12 +171,22 @@ static void RescueGetpropHostService(unique_fd sfd, const std::string& prop) {
"ro.product.device", "ro.product.device",
"ro.product.vendor.device", "ro.product.vendor.device",
}; };
auto allowed = kGetpropAllowedProps.find(prop) != kGetpropAllowedProps.end(); if (!prop.empty() && kGetpropAllowedProps.find(prop) == kGetpropAllowedProps.end()) {
if (!allowed) {
return; 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()) { if (result.empty()) {
return; return;
} }