recovery: Get a proper shell environment in recovery
* Root ADB shell by default * Try and get adb_keys from /data * Nicer mkshrc * Build a reboot command Change-Id: I80b0e2aa5eb7142eaa9f157709f4e029077d8dfa
This commit is contained in:
parent
9e4271094a
commit
64106f94e4
2 changed files with 35 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
// Copyright (C) 2018 The Android Open Source Project
|
// Copyright (C) 2018 The Android Open Source Project
|
||||||
|
// Copyright (C) 2019 The LineageOS Project
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -171,6 +172,7 @@ cc_binary {
|
||||||
],
|
],
|
||||||
|
|
||||||
static_libs: [
|
static_libs: [
|
||||||
|
"libc++fs",
|
||||||
"librecovery",
|
"librecovery",
|
||||||
"librecovery_ui_default",
|
"librecovery_ui_default",
|
||||||
],
|
],
|
||||||
|
@ -182,6 +184,8 @@ cc_binary {
|
||||||
"minadbd",
|
"minadbd",
|
||||||
"mke2fs.conf.recovery",
|
"mke2fs.conf.recovery",
|
||||||
"mke2fs.recovery",
|
"mke2fs.recovery",
|
||||||
|
"mkshrc.recovery",
|
||||||
|
"reboot.recovery",
|
||||||
"recovery_deps",
|
"recovery_deps",
|
||||||
"ueventd.rc.recovery",
|
"ueventd.rc.recovery",
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 The Android Open Source Project
|
* Copyright (C) 2018 The Android Open Source Project
|
||||||
|
* Copyright (C) 2019 The LineageOS Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -31,6 +32,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -60,6 +62,8 @@
|
||||||
#include "recovery_utils/logging.h"
|
#include "recovery_utils/logging.h"
|
||||||
#include "recovery_utils/roots.h"
|
#include "recovery_utils/roots.h"
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
static constexpr const char* COMMAND_FILE = "/cache/recovery/command";
|
static constexpr const char* COMMAND_FILE = "/cache/recovery/command";
|
||||||
static constexpr const char* LOCALE_FILE = "/cache/recovery/last_locale";
|
static constexpr const char* LOCALE_FILE = "/cache/recovery/last_locale";
|
||||||
|
|
||||||
|
@ -77,6 +81,9 @@ static std::string get_build_type() {
|
||||||
return android::base::GetProperty("ro.build.type", "");
|
return android::base::GetProperty("ro.build.type", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static constexpr const char* adb_keys_data = "/data/misc/adb/adb_keys";
|
||||||
|
static constexpr const char* adb_keys_root = "/adb_keys";
|
||||||
|
|
||||||
static void UiLogger(android::base::LogId log_buffer_id, android::base::LogSeverity severity,
|
static void UiLogger(android::base::LogId log_buffer_id, android::base::LogSeverity severity,
|
||||||
const char* tag, const char* file, unsigned int line, const char* message) {
|
const char* tag, const char* file, unsigned int line, const char* message) {
|
||||||
android::base::KernelLogger(log_buffer_id, severity, tag, file, line, message);
|
android::base::KernelLogger(log_buffer_id, severity, tag, file, line, message);
|
||||||
|
@ -194,6 +201,20 @@ static std::string load_locale_from_cache() {
|
||||||
return android::base::Trim(content);
|
return android::base::Trim(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void copy_userdata_files() {
|
||||||
|
if (ensure_path_mounted("/data") == 0) {
|
||||||
|
if (access(adb_keys_root, F_OK) != 0) {
|
||||||
|
if (access(adb_keys_data, R_OK) == 0) {
|
||||||
|
std::error_code ec; // to invoke the overloaded copy_file() that won't throw.
|
||||||
|
if (!fs::copy_file(adb_keys_data, adb_keys_root, ec)) {
|
||||||
|
PLOG(ERROR) << "Failed to copy adb keys";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ensure_path_unmounted("/data");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Sets the usb config to 'state'.
|
// Sets the usb config to 'state'.
|
||||||
static bool SetUsbConfig(const std::string& state) {
|
static bool SetUsbConfig(const std::string& state) {
|
||||||
android::base::SetProperty("sys.usb.config", state);
|
android::base::SetProperty("sys.usb.config", state);
|
||||||
|
@ -338,6 +359,10 @@ int main(int argc, char** argv) {
|
||||||
// Take action to refresh pmsg contents
|
// Take action to refresh pmsg contents
|
||||||
__android_log_pmsg_file_read(LOG_ID_SYSTEM, ANDROID_LOG_INFO, filter, logrotate, &do_rotate);
|
__android_log_pmsg_file_read(LOG_ID_SYSTEM, ANDROID_LOG_INFO, filter, logrotate, &do_rotate);
|
||||||
|
|
||||||
|
// Clear umask for packages that copy files out to /tmp and then over
|
||||||
|
// to /system without properly setting all permissions (eg. gapps).
|
||||||
|
umask(0);
|
||||||
|
|
||||||
time_t start = time(nullptr);
|
time_t start = time(nullptr);
|
||||||
|
|
||||||
// redirect_stdio should be called only in non-sideload mode. Otherwise we may have two logger
|
// redirect_stdio should be called only in non-sideload mode. Otherwise we may have two logger
|
||||||
|
@ -480,6 +505,12 @@ int main(int argc, char** argv) {
|
||||||
std::thread listener_thread(ListenRecoverySocket, ui, std::ref(action));
|
std::thread listener_thread(ListenRecoverySocket, ui, std::ref(action));
|
||||||
listener_thread.detach();
|
listener_thread.detach();
|
||||||
|
|
||||||
|
// Set up adb_keys and enable root before starting ADB.
|
||||||
|
if (IsRoDebuggable() && !fastboot) {
|
||||||
|
copy_userdata_files();
|
||||||
|
android::base::SetProperty("service.adb.root", "1");
|
||||||
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// We start adbd in recovery for the device with userdebug build or a unlocked bootloader.
|
// We start adbd in recovery for the device with userdebug build or a unlocked bootloader.
|
||||||
std::string usb_config =
|
std::string usb_config =
|
||||||
|
|
Loading…
Reference in a new issue