Merge "Allow entering rescue mode via recovery UI."

This commit is contained in:
Tao Bao 2019-04-18 21:45:50 +00:00 committed by Gerrit Code Review
commit b951138ebe
9 changed files with 60 additions and 17 deletions

View file

@ -31,6 +31,7 @@
#include <atomic> #include <atomic>
#include <functional> #include <functional>
#include <map> #include <map>
#include <vector>
#include <android-base/file.h> #include <android-base/file.h>
#include <android-base/logging.h> #include <android-base/logging.h>
@ -42,6 +43,7 @@
#include "fuse_sideload.h" #include "fuse_sideload.h"
#include "install/install.h" #include "install/install.h"
#include "minadbd_types.h" #include "minadbd_types.h"
#include "otautil/sysutil.h"
#include "recovery_ui/ui.h" #include "recovery_ui/ui.h"
using CommandFunction = std::function<bool()>; using CommandFunction = std::function<bool()>;
@ -228,7 +230,7 @@ static void ListenAndExecuteMinadbdCommands(
// b11. exit the listening loop // b11. exit the listening loop
// //
static void CreateMinadbdServiceAndExecuteCommands( static void CreateMinadbdServiceAndExecuteCommands(
const std::map<MinadbdCommands, CommandFunction>& command_map) { const std::map<MinadbdCommands, CommandFunction>& command_map, bool rescue_mode) {
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
android::base::unique_fd recovery_socket; android::base::unique_fd recovery_socket;
@ -245,9 +247,16 @@ static void CreateMinadbdServiceAndExecuteCommands(
} }
if (child == 0) { if (child == 0) {
recovery_socket.reset(); recovery_socket.reset();
execl("/system/bin/minadbd", "minadbd", "--socket_fd", std::vector<std::string> minadbd_commands = {
std::to_string(minadbd_socket.release()).c_str(), nullptr); "/system/bin/minadbd",
"--socket_fd",
std::to_string(minadbd_socket.release()),
};
if (rescue_mode) {
minadbd_commands.push_back("--rescue");
}
auto exec_args = StringVectorToNullTerminatedArray(minadbd_commands);
execv(exec_args[0], exec_args.data());
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
} }
@ -280,7 +289,7 @@ static void CreateMinadbdServiceAndExecuteCommands(
signal(SIGPIPE, SIG_DFL); signal(SIGPIPE, SIG_DFL);
} }
int apply_from_adb(RecoveryUI* ui) { int ApplyFromAdb(RecoveryUI* ui, bool rescue_mode) {
// Save the usb state to restore after the sideload operation. // Save the usb state to restore after the sideload operation.
std::string usb_state = android::base::GetProperty("sys.usb.state", "none"); std::string usb_state = android::base::GetProperty("sys.usb.state", "none");
// Clean up state and stop adbd. // Clean up state and stop adbd.
@ -289,16 +298,20 @@ int apply_from_adb(RecoveryUI* ui) {
return INSTALL_ERROR; return INSTALL_ERROR;
} }
ui->Print( if (!rescue_mode) {
"\n\nNow send the package you want to apply\n" ui->Print(
"to the device with \"adb sideload <filename>\"...\n"); "\n\nNow send the package you want to apply\n"
"to the device with \"adb sideload <filename>\"...\n");
} else {
ui->Print("\n\nWaiting for rescue commands...\n");
}
int install_result = INSTALL_ERROR; int install_result = INSTALL_ERROR;
std::map<MinadbdCommands, CommandFunction> command_map{ std::map<MinadbdCommands, CommandFunction> command_map{
{ MinadbdCommands::kInstall, std::bind(&AdbInstallPackageHandler, ui, &install_result) }, { MinadbdCommands::kInstall, std::bind(&AdbInstallPackageHandler, ui, &install_result) },
}; };
CreateMinadbdServiceAndExecuteCommands(command_map); CreateMinadbdServiceAndExecuteCommands(command_map, rescue_mode);
// Clean up before switching to the older state, for example setting the state // Clean up before switching to the older state, for example setting the state
// to none sets sys/class/android_usb/android0/enable to 0. // to none sets sys/class/android_usb/android0/enable to 0.

View file

@ -18,4 +18,4 @@
#include <recovery_ui/ui.h> #include <recovery_ui/ui.h>
int apply_from_adb(RecoveryUI* ui); int ApplyFromAdb(RecoveryUI* ui, bool rescue_mode);

View file

@ -31,10 +31,13 @@
#include "minadbd_services.h" #include "minadbd_services.h"
#include "minadbd_types.h" #include "minadbd_types.h"
using namespace std::string_literals;
int main(int argc, char** argv) { int main(int argc, char** argv) {
android::base::InitLogging(argv, &android::base::StderrLogger); android::base::InitLogging(argv, &android::base::StderrLogger);
// TODO(xunchang) implement a command parser // TODO(xunchang) implement a command parser
if (argc != 3 || strcmp("--socket_fd", argv[1]) != 0) { if ((argc != 3 && argc != 4) || argv[1] != "--socket_fd"s ||
(argc == 4 && argv[3] != "--rescue"s)) {
LOG(ERROR) << "minadbd has invalid arguments, argc: " << argc; LOG(ERROR) << "minadbd has invalid arguments, argc: " << argc;
exit(kMinadbdArgumentsParsingError); exit(kMinadbdArgumentsParsingError);
} }
@ -50,7 +53,12 @@ int main(int argc, char** argv) {
} }
SetMinadbdSocketFd(socket_fd); SetMinadbdSocketFd(socket_fd);
adb_device_banner = "sideload"; if (argc == 4) {
SetMinadbdRescueMode(true);
adb_device_banner = "rescue";
} else {
adb_device_banner = "sideload";
}
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);

View file

@ -45,10 +45,16 @@
#include "sysdeps.h" #include "sysdeps.h"
static int minadbd_socket = -1; static int minadbd_socket = -1;
static bool rescue_mode = false;
void SetMinadbdSocketFd(int socket_fd) { void SetMinadbdSocketFd(int socket_fd) {
minadbd_socket = socket_fd; minadbd_socket = socket_fd;
} }
void SetMinadbdRescueMode(bool rescue) {
rescue_mode = rescue;
}
static bool WriteCommandToFd(MinadbdCommands cmd, int fd) { static bool WriteCommandToFd(MinadbdCommands cmd, int fd) {
char message[kMinadbdMessageSize]; char message[kMinadbdMessageSize];
memcpy(message, kMinadbdCommandPrefix, strlen(kMinadbdStatusPrefix)); memcpy(message, kMinadbdCommandPrefix, strlen(kMinadbdStatusPrefix));

View file

@ -17,3 +17,5 @@
#pragma once #pragma once
void SetMinadbdSocketFd(int socket_fd); void SetMinadbdSocketFd(int socket_fd);
void SetMinadbdRescueMode(bool);

View file

@ -538,12 +538,20 @@ static Device::BuiltinAction prompt_and_wait(Device* device, int status) {
break; break;
} }
case Device::APPLY_ADB_SIDELOAD: case Device::APPLY_ADB_SIDELOAD:
case Device::APPLY_SDCARD: { case Device::APPLY_SDCARD:
case Device::ENTER_RESCUE: {
save_current_log = true; save_current_log = true;
bool adb = (chosen_action == Device::APPLY_ADB_SIDELOAD);
if (adb) { bool adb = true;
status = apply_from_adb(ui); if (chosen_action == Device::ENTER_RESCUE) {
// Switch to graphics screen.
ui->ShowText(false);
status = ApplyFromAdb(ui, true /* rescue_mode */);
ui->ShowText(true);
} else if (chosen_action == Device::APPLY_ADB_SIDELOAD) {
status = ApplyFromAdb(ui, false /* rescue_mode */);
} else { } else {
adb = false;
status = ApplyFromSdcard(device, ui); status = ApplyFromSdcard(device, ui);
} }
@ -926,7 +934,7 @@ Device::BuiltinAction start_recovery(Device* device, const std::vector<std::stri
if (!sideload_auto_reboot) { if (!sideload_auto_reboot) {
ui->ShowText(true); ui->ShowText(true);
} }
status = apply_from_adb(ui); status = ApplyFromAdb(ui, false /* rescue_mode */);
ui->Print("\nInstall from ADB complete (status: %d).\n", status); ui->Print("\nInstall from ADB complete (status: %d).\n", status);
if (sideload_auto_reboot) { if (sideload_auto_reboot) {
ui->Print("Rebooting automatically.\n"); ui->Print("Rebooting automatically.\n");

View file

@ -423,6 +423,10 @@ int main(int argc, char** argv) {
device->RemoveMenuItemForAction(Device::ENTER_FASTBOOT); device->RemoveMenuItemForAction(Device::ENTER_FASTBOOT);
} }
if (!is_ro_debuggable()) {
device->RemoveMenuItemForAction(Device::ENTER_RESCUE);
}
ui->SetBackground(RecoveryUI::NONE); ui->SetBackground(RecoveryUI::NONE);
if (show_text) ui->ShowText(true); if (show_text) ui->ShowText(true);

View file

@ -37,6 +37,7 @@ static std::vector<std::pair<std::string, Device::BuiltinAction>> g_menu_actions
{ "View recovery logs", Device::VIEW_RECOVERY_LOGS }, { "View recovery logs", Device::VIEW_RECOVERY_LOGS },
{ "Run graphics test", Device::RUN_GRAPHICS_TEST }, { "Run graphics test", Device::RUN_GRAPHICS_TEST },
{ "Run locale test", Device::RUN_LOCALE_TEST }, { "Run locale test", Device::RUN_LOCALE_TEST },
{ "Enter rescue", Device::ENTER_RESCUE },
{ "Power off", Device::SHUTDOWN }, { "Power off", Device::SHUTDOWN },
}; };

View file

@ -50,6 +50,7 @@ class Device {
KEY_INTERRUPTED = 13, KEY_INTERRUPTED = 13,
ENTER_FASTBOOT = 14, ENTER_FASTBOOT = 14,
ENTER_RECOVERY = 15, ENTER_RECOVERY = 15,
ENTER_RESCUE = 16,
}; };
explicit Device(RecoveryUI* ui); explicit Device(RecoveryUI* ui);