Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e3cc180d authored by Tao Bao's avatar Tao Bao
Browse files

minadbd: `adb rescue getprop` returns newline-terminated result.

This change addresses the comment in [1], which makes the results of
`adb shell getprop foo` and `adb rescue getprop foo` more consistent.
That is, both will return newline-terminated results now.

[1] https://r.android.com/c/platform/bootable/recovery/+/976340/3/minadbd/minadbd_services.cpp#188

Fixes: 134027350
Test: Run the following commands on taimen (under rescue mode):
    `adb rescue getprop ro.build.fingerprint`
    `adb rescue getprop ro.nonexistent`
    `adb rescue getprop`
Change-Id: I5af47f8ea4d569b8507e259daef87749c0945f47
Merged-In: I5af47f8ea4d569b8507e259daef87749c0945f47
(cherry picked from commit 57a27890)
parent 5359d777
Loading
Loading
Loading
Loading
+7 −10
Original line number Diff line number Diff line
@@ -156,9 +156,10 @@ 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]".
// 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::set<std::string> kGetpropAllowedProps = {
    "ro.build.date.utc",
@@ -171,10 +172,6 @@ static void RescueGetpropHostService(unique_fd sfd, const std::string& prop) {
    "ro.product.device",
    "ro.product.vendor.device",
  };
  if (!prop.empty() && kGetpropAllowedProps.find(prop) == kGetpropAllowedProps.end()) {
    return;
  }

  std::string result;
  if (prop.empty()) {
    for (const auto& key : kGetpropAllowedProps) {
@@ -184,11 +181,11 @@ static void RescueGetpropHostService(unique_fd sfd, const std::string& prop) {
      }
      result += "[" + key + "]: [" + value + "]\n";
    }
  } else {
    result = android::base::GetProperty(prop, "");
  } else if (kGetpropAllowedProps.find(prop) != kGetpropAllowedProps.end()) {
    result = android::base::GetProperty(prop, "") + "\n";
  }
  if (result.empty()) {
    return;
    result = "\n";
  }
  if (!android::base::WriteFully(sfd, result.data(), result.size())) {
    exit(kMinadbdHostSocketIOError);