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

Commit 80c405f6 authored by Tianjie Xu's avatar Tianjie Xu Committed by Gerrit Code Review
Browse files

Merge "Clean up some global variables in common.h"

parents 7965a95a 164c60a4
Loading
Loading
Loading
Loading
+0 −13
Original line number Diff line number Diff line
@@ -18,21 +18,8 @@

#include <string>

// Not using the command-line defined macro here because this header could be included by
// device-specific recovery libraries. We static assert the value consistency in recovery.cpp.
static constexpr int kRecoveryApiVersion = 3;

class RecoveryUI;
struct selabel_handle;

extern struct selabel_handle* sehandle;
extern RecoveryUI* ui;
extern bool has_cache;

// The current stage, e.g. "1/2".
extern std::string stage;

// The reason argument provided in "--reason=".
extern const char* reason;

bool is_ro_debuggable();
+4 −1
Original line number Diff line number Diff line
@@ -60,7 +60,8 @@
using namespace std::chrono_literals;

static constexpr int kRecoveryApiVersion = 3;
// Assert the version defined in code and in Android.mk are consistent.
// We define RECOVERY_API_VERSION in Android.mk, which will be picked up by build system and packed
// into target_files.zip. Assert the version defined in code and in Android.mk are consistent.
static_assert(kRecoveryApiVersion == RECOVERY_API_VERSION, "Mismatching recovery API versions.");

// Default allocation of progress bar segments to operations
@@ -621,6 +622,8 @@ InstallResult InstallPackage(Package* package, const std::string_view package_id
  InstallResult result;
  std::vector<std::string> log_buffer;

  ui->Print("Supported API: %d\n", kRecoveryApiVersion);

  ui->Print("Finding update package...\n");
  LOG(INFO) << "Update package id: " << package_id;
  if (!package) {
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ void rotate_logs(const char* last_log_file, const char* last_kmsg_file);
void check_and_fclose(FILE* fp, const std::string& name);

void copy_log_file_to_pmsg(const std::string& source, const std::string& destination);
void copy_logs(bool save_current_log, bool has_cache, const selabel_handle* sehandle);
void copy_logs(bool save_current_log);
void reset_tmplog_offset();

void save_kernel_log(const char* destination);
+3 −0
Original line number Diff line number Diff line
@@ -53,3 +53,6 @@ int format_volume(const std::string& volume, const std::string& directory);
// Ensure that all and only the volumes that packages expect to find
// mounted (/tmp and /cache) are mounted.  Returns 0 on success.
int setup_install_mounts();

// Returns true if there is /cache in the volumes.
bool HasCache();
+8 −9
Original line number Diff line number Diff line
@@ -178,9 +178,8 @@ void reset_tmplog_offset() {
  tmplog_offset = 0;
}

static void copy_log_file(const std::string& source, const std::string& destination, bool append,
                          const selabel_handle* sehandle) {
  FILE* dest_fp = fopen_path(destination, append ? "ae" : "we", sehandle);
static void copy_log_file(const std::string& source, const std::string& destination, bool append) {
  FILE* dest_fp = fopen_path(destination, append ? "ae" : "we", logging_sehandle);
  if (dest_fp == nullptr) {
    PLOG(ERROR) << "Can't open " << destination;
  } else {
@@ -203,7 +202,7 @@ static void copy_log_file(const std::string& source, const std::string& destinat
  }
}

void copy_logs(bool save_current_log, bool has_cache, const selabel_handle* sehandle) {
void copy_logs(bool save_current_log) {
  // We only rotate and record the log of the current session if explicitly requested. This usually
  // happens after wipes, installation from BCB or menu selections. This is to avoid unnecessary
  // rotation (and possible deletion) of log files, if it does not do anything loggable.
@@ -216,7 +215,7 @@ void copy_logs(bool save_current_log, bool has_cache, const selabel_handle* seha
  copy_log_file_to_pmsg(Paths::Get().temporary_install_file(), LAST_INSTALL_FILE);

  // We can do nothing for now if there's no /cache partition.
  if (!has_cache) {
  if (!HasCache()) {
    return;
  }

@@ -225,9 +224,9 @@ void copy_logs(bool save_current_log, bool has_cache, const selabel_handle* seha
  rotate_logs(LAST_LOG_FILE, LAST_KMSG_FILE);

  // Copy logs to cache so the system can find out what happened.
  copy_log_file(Paths::Get().temporary_log_file(), LOG_FILE, true, sehandle);
  copy_log_file(Paths::Get().temporary_log_file(), LAST_LOG_FILE, false, sehandle);
  copy_log_file(Paths::Get().temporary_install_file(), LAST_INSTALL_FILE, false, sehandle);
  copy_log_file(Paths::Get().temporary_log_file(), LOG_FILE, true);
  copy_log_file(Paths::Get().temporary_log_file(), LAST_LOG_FILE, false);
  copy_log_file(Paths::Get().temporary_install_file(), LAST_INSTALL_FILE, false);
  save_kernel_log(LAST_KMSG_FILE);
  chmod(LOG_FILE, 0600);
  chown(LOG_FILE, AID_SYSTEM, AID_SYSTEM);
@@ -319,7 +318,7 @@ bool RestoreLogFilesAfterFormat(const std::vector<saved_log_file>& log_files) {
  // Reset the pointer so we copy from the beginning of the temp
  // log.
  reset_tmplog_offset();
  copy_logs(true /* save_current_log */, true /* has_cache */, logging_sehandle);
  copy_logs(true /* save_current_log */);

  return true;
}
Loading