From 7c9bbe948b446b6e995ea9fdd3a3226362372ca9 Mon Sep 17 00:00:00 2001 From: Hridya Valsaraju Date: Thu, 27 Sep 2018 10:41:01 -0700 Subject: [PATCH] Add support to read fastboot variable 'off-mode-charge' Bug: 78793464 Bug: 79480454 Test: fastboot getvar off-mode-charge Change-Id: I4c40847be292e8e2e420340f81bb624b247bc11b Merged-In: I4c40847be292e8e2e420340f81bb624b247bc11b (cherry picked from commit b05d278696cbb25e14085362651999204aa51b40) --- fastboot/constants.h | 1 + fastboot/device/commands.cpp | 1 + fastboot/device/variables.cpp | 22 ++++++++++++++++++++++ fastboot/device/variables.h | 2 ++ 4 files changed, 26 insertions(+) diff --git a/fastboot/constants.h b/fastboot/constants.h index ad2e1a173..c11d9defa 100644 --- a/fastboot/constants.h +++ b/fastboot/constants.h @@ -61,3 +61,4 @@ #define FB_VAR_IS_USERSPACE "is-userspace" #define FB_VAR_HW_REVISION "hw-revision" #define FB_VAR_VARIANT "variant" +#define FB_VAR_OFF_MODE_CHARGE_STATE "off-mode-charge" diff --git a/fastboot/device/commands.cpp b/fastboot/device/commands.cpp index e70de1b6d..4fa114821 100644 --- a/fastboot/device/commands.cpp +++ b/fastboot/device/commands.cpp @@ -95,6 +95,7 @@ bool GetVarHandler(FastbootDevice* device, const std::vector& args) {FB_VAR_PARTITION_TYPE, {GetPartitionType, GetAllPartitionArgsWithSlot}}, {FB_VAR_IS_LOGICAL, {GetPartitionIsLogical, GetAllPartitionArgsWithSlot}}, {FB_VAR_IS_USERSPACE, {GetIsUserspace, nullptr}}, + {FB_VAR_OFF_MODE_CHARGE_STATE, {GetOffModeChargeState, nullptr}}, {FB_VAR_HW_REVISION, {GetHardwareRevision, nullptr}}}; if (args.size() < 2) { diff --git a/fastboot/device/variables.cpp b/fastboot/device/variables.cpp index 77cd4bc25..bcf13a540 100644 --- a/fastboot/device/variables.cpp +++ b/fastboot/device/variables.cpp @@ -95,6 +95,28 @@ bool GetVariant(FastbootDevice* device, const std::vector& /* args return true; } +bool GetOffModeChargeState(FastbootDevice* device, const std::vector& /* args */, + std::string* message) { + auto fastboot_hal = device->fastboot_hal(); + if (!fastboot_hal) { + *message = "Fastboot HAL not found"; + return false; + } + + Result ret; + auto ret_val = + fastboot_hal->getOffModeChargeState([&](bool off_mode_charging_state, Result result) { + *message = off_mode_charging_state ? "1" : "0"; + ret = result; + }); + if (!ret_val.isOk() || (ret.status != Status::SUCCESS)) { + *message = "Unable to get off mode charge state"; + return false; + } + + return true; +} + bool GetCurrentSlot(FastbootDevice* device, const std::vector& /* args */, std::string* message) { std::string suffix = device->GetCurrentSlot(); diff --git a/fastboot/device/variables.h b/fastboot/device/variables.h index 0546942a8..b06881ead 100644 --- a/fastboot/device/variables.h +++ b/fastboot/device/variables.h @@ -53,6 +53,8 @@ bool GetIsUserspace(FastbootDevice* device, const std::vector& args bool GetHardwareRevision(FastbootDevice* device, const std::vector& args, std::string* message); bool GetVariant(FastbootDevice* device, const std::vector& args, std::string* message); +bool GetOffModeChargeState(FastbootDevice* device, const std::vector& args, + std::string* message); // Helpers for getvar all. std::vector> GetAllPartitionArgsWithSlot(FastbootDevice* device);