Merge "recovery: Print the actually required battery level."
This commit is contained in:
committed by
Gerrit Code Review
commit
ca456f3964
+60
-58
@@ -116,12 +116,6 @@ static const char *LAST_LOG_FILE = "/cache/recovery/last_log";
|
|||||||
// We will try to apply the update package 5 times at most in case of an I/O error or
|
// We will try to apply the update package 5 times at most in case of an I/O error or
|
||||||
// bspatch | imgpatch error.
|
// bspatch | imgpatch error.
|
||||||
static const int RETRY_LIMIT = 4;
|
static const int RETRY_LIMIT = 4;
|
||||||
static const int BATTERY_READ_TIMEOUT_IN_SEC = 10;
|
|
||||||
// GmsCore enters recovery mode to install package when having enough battery
|
|
||||||
// percentage. Normally, the threshold is 40% without charger and 20% with charger.
|
|
||||||
// So we should check battery with a slightly lower limitation.
|
|
||||||
static const int BATTERY_OK_PERCENTAGE = 20;
|
|
||||||
static const int BATTERY_WITH_CHARGER_OK_PERCENTAGE = 15;
|
|
||||||
static constexpr const char* RECOVERY_WIPE = "/etc/recovery.wipe";
|
static constexpr const char* RECOVERY_WIPE = "/etc/recovery.wipe";
|
||||||
static constexpr const char* DEFAULT_LOCALE = "en-US";
|
static constexpr const char* DEFAULT_LOCALE = "en-US";
|
||||||
|
|
||||||
@@ -1265,58 +1259,65 @@ void UiLogger(android::base::LogId /* id */, android::base::LogSeverity severity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_battery_ok() {
|
static bool is_battery_ok(int* required_battery_level) {
|
||||||
struct healthd_config healthd_config = {
|
struct healthd_config healthd_config = {
|
||||||
.batteryStatusPath = android::String8(android::String8::kEmptyString),
|
.batteryStatusPath = android::String8(android::String8::kEmptyString),
|
||||||
.batteryHealthPath = android::String8(android::String8::kEmptyString),
|
.batteryHealthPath = android::String8(android::String8::kEmptyString),
|
||||||
.batteryPresentPath = android::String8(android::String8::kEmptyString),
|
.batteryPresentPath = android::String8(android::String8::kEmptyString),
|
||||||
.batteryCapacityPath = android::String8(android::String8::kEmptyString),
|
.batteryCapacityPath = android::String8(android::String8::kEmptyString),
|
||||||
.batteryVoltagePath = android::String8(android::String8::kEmptyString),
|
.batteryVoltagePath = android::String8(android::String8::kEmptyString),
|
||||||
.batteryTemperaturePath = android::String8(android::String8::kEmptyString),
|
.batteryTemperaturePath = android::String8(android::String8::kEmptyString),
|
||||||
.batteryTechnologyPath = android::String8(android::String8::kEmptyString),
|
.batteryTechnologyPath = android::String8(android::String8::kEmptyString),
|
||||||
.batteryCurrentNowPath = android::String8(android::String8::kEmptyString),
|
.batteryCurrentNowPath = android::String8(android::String8::kEmptyString),
|
||||||
.batteryCurrentAvgPath = android::String8(android::String8::kEmptyString),
|
.batteryCurrentAvgPath = android::String8(android::String8::kEmptyString),
|
||||||
.batteryChargeCounterPath = android::String8(android::String8::kEmptyString),
|
.batteryChargeCounterPath = android::String8(android::String8::kEmptyString),
|
||||||
.batteryFullChargePath = android::String8(android::String8::kEmptyString),
|
.batteryFullChargePath = android::String8(android::String8::kEmptyString),
|
||||||
.batteryCycleCountPath = android::String8(android::String8::kEmptyString),
|
.batteryCycleCountPath = android::String8(android::String8::kEmptyString),
|
||||||
.energyCounter = NULL,
|
.energyCounter = nullptr,
|
||||||
.boot_min_cap = 0,
|
.boot_min_cap = 0,
|
||||||
.screen_on = NULL
|
.screen_on = nullptr
|
||||||
};
|
};
|
||||||
healthd_board_init(&healthd_config);
|
healthd_board_init(&healthd_config);
|
||||||
|
|
||||||
android::BatteryMonitor monitor;
|
android::BatteryMonitor monitor;
|
||||||
monitor.init(&healthd_config);
|
monitor.init(&healthd_config);
|
||||||
|
|
||||||
int wait_second = 0;
|
static constexpr int BATTERY_READ_TIMEOUT_IN_SEC = 10;
|
||||||
while (true) {
|
int wait_second = 0;
|
||||||
int charge_status = monitor.getChargeStatus();
|
while (true) {
|
||||||
// Treat unknown status as charged.
|
int charge_status = monitor.getChargeStatus();
|
||||||
bool charged = (charge_status != android::BATTERY_STATUS_DISCHARGING &&
|
// Treat unknown status as charged.
|
||||||
charge_status != android::BATTERY_STATUS_NOT_CHARGING);
|
bool charged = (charge_status != android::BATTERY_STATUS_DISCHARGING &&
|
||||||
android::BatteryProperty capacity;
|
charge_status != android::BATTERY_STATUS_NOT_CHARGING);
|
||||||
android::status_t status = monitor.getProperty(android::BATTERY_PROP_CAPACITY, &capacity);
|
android::BatteryProperty capacity;
|
||||||
ui_print("charge_status %d, charged %d, status %d, capacity %" PRId64 "\n", charge_status,
|
android::status_t status = monitor.getProperty(android::BATTERY_PROP_CAPACITY, &capacity);
|
||||||
charged, status, capacity.valueInt64);
|
ui_print("charge_status %d, charged %d, status %d, capacity %" PRId64 "\n", charge_status,
|
||||||
// At startup, the battery drivers in devices like N5X/N6P take some time to load
|
charged, status, capacity.valueInt64);
|
||||||
// the battery profile. Before the load finishes, it reports value 50 as a fake
|
// At startup, the battery drivers in devices like N5X/N6P take some time to load
|
||||||
// capacity. BATTERY_READ_TIMEOUT_IN_SEC is set that the battery drivers are expected
|
// the battery profile. Before the load finishes, it reports value 50 as a fake
|
||||||
// to finish loading the battery profile earlier than 10 seconds after kernel startup.
|
// capacity. BATTERY_READ_TIMEOUT_IN_SEC is set that the battery drivers are expected
|
||||||
if (status == 0 && capacity.valueInt64 == 50) {
|
// to finish loading the battery profile earlier than 10 seconds after kernel startup.
|
||||||
if (wait_second < BATTERY_READ_TIMEOUT_IN_SEC) {
|
if (status == 0 && capacity.valueInt64 == 50) {
|
||||||
sleep(1);
|
if (wait_second < BATTERY_READ_TIMEOUT_IN_SEC) {
|
||||||
wait_second++;
|
sleep(1);
|
||||||
continue;
|
wait_second++;
|
||||||
}
|
continue;
|
||||||
}
|
}
|
||||||
// If we can't read battery percentage, it may be a device without battery. In this
|
|
||||||
// situation, use 100 as a fake battery percentage.
|
|
||||||
if (status != 0) {
|
|
||||||
capacity.valueInt64 = 100;
|
|
||||||
}
|
|
||||||
return (charged && capacity.valueInt64 >= BATTERY_WITH_CHARGER_OK_PERCENTAGE) ||
|
|
||||||
(!charged && capacity.valueInt64 >= BATTERY_OK_PERCENTAGE);
|
|
||||||
}
|
}
|
||||||
|
// If we can't read battery percentage, it may be a device without battery. In this situation,
|
||||||
|
// use 100 as a fake battery percentage.
|
||||||
|
if (status != 0) {
|
||||||
|
capacity.valueInt64 = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GmsCore enters recovery mode to install package when having enough battery percentage.
|
||||||
|
// Normally, the threshold is 40% without charger and 20% with charger. So we should check
|
||||||
|
// battery with a slightly lower limitation.
|
||||||
|
static constexpr int BATTERY_OK_PERCENTAGE = 20;
|
||||||
|
static constexpr int BATTERY_WITH_CHARGER_OK_PERCENTAGE = 15;
|
||||||
|
*required_battery_level = charged ? BATTERY_WITH_CHARGER_OK_PERCENTAGE : BATTERY_OK_PERCENTAGE;
|
||||||
|
return capacity.valueInt64 >= *required_battery_level;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the retry count to |retry_count| in BCB.
|
// Set the retry count to |retry_count| in BCB.
|
||||||
@@ -1544,9 +1545,10 @@ int main(int argc, char **argv) {
|
|||||||
// to log the update attempt since update_package is non-NULL.
|
// to log the update attempt since update_package is non-NULL.
|
||||||
modified_flash = true;
|
modified_flash = true;
|
||||||
|
|
||||||
if (retry_count == 0 && !is_battery_ok()) {
|
int required_battery_level;
|
||||||
ui->Print("battery capacity is not enough for installing package, needed is %d%%\n",
|
if (retry_count == 0 && !is_battery_ok(&required_battery_level)) {
|
||||||
BATTERY_OK_PERCENTAGE);
|
ui->Print("battery capacity is not enough for installing package: %d%% needed\n",
|
||||||
|
required_battery_level);
|
||||||
// Log the error code to last_install when installation skips due to
|
// Log the error code to last_install when installation skips due to
|
||||||
// low battery.
|
// low battery.
|
||||||
log_failure_code(kLowBattery, update_package);
|
log_failure_code(kLowBattery, update_package);
|
||||||
|
|||||||
Reference in New Issue
Block a user