Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9514eb19 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Revert "Some cleanups to recovery.""

parents 46fb0a6a 8584fcf6
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -17,16 +17,15 @@
#ifndef RECOVERY_COMMON_H
#define RECOVERY_COMMON_H

#include <stdbool.h>
#include <stdio.h>
#include <stdarg.h>

#define STRINGIFY(x) #x
#define EXPAND(x) STRINGIFY(x)

class RecoveryUI;

extern RecoveryUI* ui;
extern bool modified_flash;
typedef struct fstab_rec Volume;

// fopen a file, mounting volumes and making parent dirs as necessary.
FILE* fopen_path(const char *path, const char *mode);
+2 −0
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@
#include "ui.h"
#include "verifier.h"

extern RecoveryUI* ui;

#define ASSUMED_UPDATE_BINARY_NAME  "META-INF/com/google/android/update-binary"
#define PUBLIC_KEYS_FILE "/res/keys"
static constexpr const char* METADATA_PATH = "META-INF/com/android/metadata";
+2 −1
Original line number Diff line number Diff line
@@ -20,9 +20,10 @@
#include <string>
#include <ziparchive/zip_archive.h>

#include "common.h"

enum { INSTALL_SUCCESS, INSTALL_ERROR, INSTALL_CORRUPT, INSTALL_NONE, INSTALL_SKIPPED,
        INSTALL_RETRY };

// Install the package specified by root_path.  If INSTALL_SUCCESS is
// returned and *wipe_cache is true on exit, caller should wipe the
// cache partition.
+2 −2
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@
#include <stdint.h>
#include <string>

#include <openssl/sha.h>
#include "openssl/sha.h"

static std::string print_sha1(const uint8_t* sha1, size_t len) {
    const char* hex = "0123456789abcdef";
+57 −53
Original line number Diff line number Diff line
@@ -69,6 +69,8 @@
#include "ui.h"
#include "screen_ui.h"

struct selabel_handle *sehandle;

static const struct option OPTIONS[] = {
  { "update_package", required_argument, NULL, 'u' },
  { "retry_count", required_argument, NULL, 'n' },
@@ -117,17 +119,14 @@ static const int BATTERY_READ_TIMEOUT_IN_SEC = 10;
// 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* DEFAULT_LOCALE = "en_US";

static std::string locale;
static const char* stage = nullptr;
static const char* reason = nullptr;
static bool has_cache = false;
constexpr const char* RECOVERY_WIPE = "/etc/recovery.wipe";

RecoveryUI* ui = nullptr;
RecoveryUI* ui = NULL;
static const char* locale = "en_US";
char* stage = NULL;
char* reason = NULL;
bool modified_flash = false;
struct selabel_handle* sehandle;
static bool has_cache = false;

/*
 * The recovery tool communicates with the main system through /cache files.
@@ -207,9 +206,6 @@ FILE* fopen_path(const char *path, const char *mode) {
// close a file, log an error if the error indicator is set
static void check_and_fclose(FILE *fp, const char *name) {
    fflush(fp);
    if (fsync(fileno(fp)) == -1) {
        PLOG(ERROR) << "Failed to fsync " << name;
    }
    if (ferror(fp)) {
        PLOG(ERROR) << "Error in " << name;
    }
@@ -519,19 +515,25 @@ static void copy_logs() {
// clear the recovery command and prepare to boot a (hopefully working) system,
// copy our log file to cache as well (for the system to read). This function is
// idempotent: call it as many times as you like.
static void finish_recovery() {
static void
finish_recovery() {
    // Save the locale to cache, so if recovery is next started up
    // without a --locale argument (eg, directly from the bootloader)
    // it will use the last-known locale.
    if (!locale.empty() && has_cache) {
    if (locale != NULL) {
        size_t len = strlen(locale);
        __pmsg_write(LOCALE_FILE, locale, len);
        if (has_cache) {
            LOG(INFO) << "Saving locale \"" << locale << "\"";

            FILE* fp = fopen_path(LOCALE_FILE, "w");
        if (!android::base::WriteStringToFd(locale, fileno(fp))) {
            PLOG(ERROR) << "Failed to save locale to " << LOCALE_FILE;
        }
            if (fp != NULL) {
                fwrite(locale, 1, len, fp);
                fflush(fp);
                fsync(fileno(fp));
                check_and_fclose(fp, LOCALE_FILE);
            }
        }
    }

    copy_logs();

@@ -1280,32 +1282,40 @@ print_property(const char *key, const char *name, void *cookie) {
    printf("%s=%s\n", key, name);
}

static std::string load_locale_from_cache() {
    if (ensure_path_mounted(LOCALE_FILE) != 0) {
        LOG(ERROR) << "Can't mount " << LOCALE_FILE;
        return "";
static void
load_locale_from_cache() {
    FILE* fp = fopen_path(LOCALE_FILE, "r");
    char buffer[80];
    if (fp != NULL) {
        fgets(buffer, sizeof(buffer), fp);
        int j = 0;
        unsigned int i;
        for (i = 0; i < sizeof(buffer) && buffer[i]; ++i) {
            if (!isspace(buffer[i])) {
                buffer[j++] = buffer[i];
            }

    std::string content;
    if (!android::base::ReadFileToString(LOCALE_FILE, &content)) {
        PLOG(ERROR) << "Can't read " << LOCALE_FILE;
        return "";
        }

    return android::base::Trim(content);
        buffer[j] = 0;
        locale = strdup(buffer);
        check_and_fclose(fp, LOCALE_FILE);
    }
}

void ui_print(const char* format, ...) {
    std::string buffer;
static RecoveryUI* gCurrentUI = NULL;

void
ui_print(const char* format, ...) {
    char buffer[256];

    va_list ap;
    va_start(ap, format);
    android::base::StringAppendV(&buffer, format, ap);
    vsnprintf(buffer, sizeof(buffer), format, ap);
    va_end(ap);

    if (ui != nullptr) {
        ui->Print("%s", buffer.c_str());
    if (gCurrentUI != NULL) {
        gCurrentUI->Print("%s", buffer);
    } else {
        fputs(buffer.c_str(), stdout);
        fputs(buffer, stdout);
    }
}

@@ -1314,8 +1324,8 @@ static constexpr char log_characters[] = "VDIWEF";
void UiLogger(android::base::LogId id, android::base::LogSeverity severity,
               const char* tag, const char* file, unsigned int line,
               const char* message) {
    if (severity >= android::base::ERROR && ui != nullptr) {
        ui->Print("E:%s\n", message);
    if (severity >= android::base::ERROR && gCurrentUI != NULL) {
        gCurrentUI->Print("E:%s\n", message);
    } else {
        fprintf(stdout, "%c:%s\n", log_characters[severity], message);
    }
@@ -1563,24 +1573,18 @@ int main(int argc, char **argv) {
        }
    }

    if (locale.empty()) {
        if (has_cache) {
            locale = load_locale_from_cache();
    if (locale == nullptr && has_cache) {
        load_locale_from_cache();
    }

        if (locale.empty()) {
            locale = DEFAULT_LOCALE;
        }
    }

    printf("locale is [%s]\n", locale.c_str());
    printf("locale is [%s]\n", locale);
    printf("stage is [%s]\n", stage);
    printf("reason is [%s]\n", reason);

    Device* device = make_device();
    ui = device->GetUI();
    gCurrentUI = ui;

    ui->SetLocale(locale.c_str());
    ui->SetLocale(locale);
    ui->Init();
    // Set background string to "installing security update" for security update,
    // otherwise set it to "installing system update".
Loading