Merge "minadbd: Return battery level via getprop."

am: e0e34a7f5c

Change-Id: Ib714d7add905ac1b2084f4144a2017a01a21fd2f
This commit is contained in:
Tao Bao
2019-10-07 08:37:00 -07:00
committed by android-build-merger
3 changed files with 21 additions and 2 deletions
+4
View File
@@ -40,6 +40,7 @@ cc_library {
defaults: [ defaults: [
"minadbd_defaults", "minadbd_defaults",
"librecovery_utils_defaults",
], ],
srcs: [ srcs: [
@@ -48,6 +49,7 @@ cc_library {
], ],
static_libs: [ static_libs: [
"librecovery_utils",
"libotautil", "libotautil",
], ],
@@ -97,6 +99,7 @@ cc_test {
defaults: [ defaults: [
"minadbd_defaults", "minadbd_defaults",
"librecovery_utils_defaults",
], ],
srcs: [ srcs: [
@@ -107,6 +110,7 @@ cc_test {
static_libs: [ static_libs: [
"libminadbd_services", "libminadbd_services",
"libfusesideload", "libfusesideload",
"librecovery_utils",
"libotautil", "libotautil",
"libadbd", "libadbd",
], ],
+16 -2
View File
@@ -44,6 +44,7 @@
#include "fuse_adb_provider.h" #include "fuse_adb_provider.h"
#include "fuse_sideload.h" #include "fuse_sideload.h"
#include "minadbd/types.h" #include "minadbd/types.h"
#include "recovery_utils/battery_utils.h"
#include "services.h" #include "services.h"
#include "sysdeps.h" #include "sysdeps.h"
@@ -160,7 +161,10 @@ static void RescueInstallHostService(unique_fd sfd, const std::string& args) {
// If given an empty string, dumps all the supported properties (analogous to `adb shell getprop`) // If given an empty string, dumps all the supported properties (analogous to `adb shell getprop`)
// in lines, e.g. "[prop]: [value]". // 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) {
constexpr const char* kRescueBatteryLevelProp = "rescue.battery_level";
static const std::set<std::string> kGetpropAllowedProps = { static const std::set<std::string> kGetpropAllowedProps = {
// clang-format off
kRescueBatteryLevelProp,
"ro.build.date.utc", "ro.build.date.utc",
"ro.build.fingerprint", "ro.build.fingerprint",
"ro.build.flavor", "ro.build.flavor",
@@ -170,18 +174,28 @@ static void RescueGetpropHostService(unique_fd sfd, const std::string& prop) {
"ro.build.version.incremental", "ro.build.version.incremental",
"ro.product.device", "ro.product.device",
"ro.product.vendor.device", "ro.product.vendor.device",
// clang-format on
}; };
auto query_prop = [](const std::string& key) {
if (key == kRescueBatteryLevelProp) {
auto battery_info = GetBatteryInfo();
return std::to_string(battery_info.capacity);
}
return android::base::GetProperty(key, "");
};
std::string result; std::string result;
if (prop.empty()) { if (prop.empty()) {
for (const auto& key : kGetpropAllowedProps) { for (const auto& key : kGetpropAllowedProps) {
auto value = android::base::GetProperty(key, ""); auto value = query_prop(key);
if (value.empty()) { if (value.empty()) {
continue; continue;
} }
result += "[" + key + "]: [" + value + "]\n"; result += "[" + key + "]: [" + value + "]\n";
} }
} else if (kGetpropAllowedProps.find(prop) != kGetpropAllowedProps.end()) { } else if (kGetpropAllowedProps.find(prop) != kGetpropAllowedProps.end()) {
result = android::base::GetProperty(prop, "") + "\n"; result = query_prop(prop) + "\n";
} }
if (result.empty()) { if (result.empty()) {
result = "\n"; result = "\n";
+1
View File
@@ -75,6 +75,7 @@ cc_library_static {
visibility: [ visibility: [
"//bootable/recovery", "//bootable/recovery",
"//bootable/recovery/install", "//bootable/recovery/install",
"//bootable/recovery/minadbd",
"//bootable/recovery/tests", "//bootable/recovery/tests",
], ],
} }