get_args: process /data/cache/command

Change-Id: I744cdc5a72f53fd1224de242e30ff261e6104900
This commit is contained in:
bigbiff
2021-08-03 18:21:39 -04:00
parent b2cce1055e
commit aed1bdfe59
9 changed files with 50 additions and 31 deletions

View File

@@ -41,7 +41,7 @@ on init
mkdir /system
mkdir /data
mkdir /cache
symlink /data/cache /cache
mkdir /sideload
mkdir /mnt/system
mount tmpfs tmpfs /tmp

View File

@@ -1,8 +1,6 @@
#include "twinstall/get_args.h"
std::string stage;
bool has_cache = false;
static constexpr const char* COMMAND_FILE = "/cache/recovery/command";
// command line args come from, in decreasing precedence:
// - the actual command line
@@ -12,6 +10,7 @@ std::vector<std::string> args::get_args(const int *argc, char*** const argv) {
CHECK_GT(*argc, 0);
bootloader_message boot = {};
std::string err;
if (!read_bootloader_message(&boot, &err)) {
LOG(ERROR) << err;
@@ -54,22 +53,6 @@ std::vector<std::string> args::get_args(const int *argc, char*** const argv) {
}
}
// --- if that doesn't work, try the command file (if we have /cache).
if (args.size() == 1 && has_cache) {
std::string content;
if (ensure_path_mounted(COMMAND_FILE) == 0 &&
android::base::ReadFileToString(COMMAND_FILE, &content)) {
std::vector<std::string> tokens = android::base::Split(content, "\n");
// All the arguments in COMMAND_FILE are needed (unlike the BCB message,
// COMMAND_FILE doesn't use filename as the first argument).
for (auto it = tokens.begin(); it != tokens.end(); it++) {
// Skip empty and '\0'-filled tokens.
if (!it->empty() && (*it)[0] != '\0') args.push_back(std::move(*it));
}
LOG(INFO) << "Got " << args.size() << " arguments from " << COMMAND_FILE;
}
}
// Write the arguments (excluding the filename in args[0]) back into the
// bootloader control block. So the device will always boot into recovery to
// finish the pending work, until finish_recovery() is called.

View File

@@ -1,5 +1,5 @@
/*
Copyright 2003 to 2017 TeamWin
Copyright 2003 to 2021 TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify

View File

@@ -1,5 +1,5 @@
/*
Copyright 2013 to 2020 TeamWin
Copyright 2013 to 2021 TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
@@ -1779,6 +1779,14 @@ bool TWPartition::Wipe_AndSec(void) {
return true;
}
bool TWPartition::Wipe_Data_Cache(void) {
if (!Mount(true))
return false;
gui_msg(Msg("wiping=Wiping {1}")(Mount_Point + "/cache/"));
TWFunc::removeDir(Mount_Point + "/cache/", true);
return true;
}
bool TWPartition::Can_Repair() {
if (Mount_Read_Only)
return false;

View File

@@ -1,5 +1,5 @@
/*
Copyright 2014 to 2020 TeamWin
Copyright 2014 to 2021 TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
@@ -63,6 +63,7 @@
#include "twcommon.h"
#include "partitions.hpp"
#include "data.hpp"
#include "startupArgs.hpp"
#include "twrp-functions.hpp"
#include "fixContexts.hpp"
#include "exclude.hpp"
@@ -1401,6 +1402,16 @@ int TWPartitionManager::Wipe_By_Path(string Path) {
if (Local_Path == "/system")
Local_Path = Get_Android_Root_Path();
if (Path == "/cache") {
TWPartition* cache = Find_Partition_By_Path("/cache");
if (cache == nullptr) {
TWPartition* dat = Find_Partition_By_Path("/data");
if (dat) {
dat->Wipe_Data_Cache();
found = true;
}
}
}
// Iterate through all partitions
for (iter = Partitions.begin(); iter != Partitions.end(); iter++) {
if ((*iter)->Mount_Point == Local_Path || (!(*iter)->Symlink_Mount_Point.empty() && (*iter)->Symlink_Mount_Point == Local_Path)) {
@@ -1766,6 +1777,16 @@ void TWPartitionManager::Post_Decrypt(const string& Block_Device) {
TWPartition* dat = Find_Partition_By_Path("/data");
if (dat != NULL) {
// reparse for /cache/recovery/command
static constexpr const char* COMMAND_FILE = "/data/cache/command";
if (TWFunc::Path_Exists(COMMAND_FILE)) {
startupArgs startup;
std::string content;
TWFunc::read_file(COMMAND_FILE, content);
std::vector<std::string> args = {content};
startup.processRecoveryArgs(args, 0);
}
DataManager::SetValue(TW_IS_DECRYPTED, 1);
dat->Is_Decrypted = true;
if (!Block_Device.empty()) {

View File

@@ -1,5 +1,5 @@
/*
Copyright 2014 to 2017 TeamWin
Copyright 2014 to 2021 TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
@@ -130,6 +130,7 @@ public:
bool Wipe(string New_File_System); // Wipes the partition
bool Wipe(); // Wipes the partition
bool Wipe_AndSec(); // Wipes android secure
bool Wipe_Data_Cache(); // Wipe /data/cache with devices that have no cache partition
bool Can_Repair(); // Checks to see if we have everything needed to be able to repair the current file system
uint64_t Get_Max_FileSize(); // get partition maxFileSie
bool Repair(); // Repairs the current file system

View File

@@ -1,5 +1,5 @@
/*
Copyright 2012-2020 TeamWin
Copyright 2012-2021 TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
@@ -24,6 +24,13 @@ void startupArgs::parse(int *argc, char ***argv) {
LOGINFO("Startup Commands: ");
for (index = 1; index < args.size(); index++) {
if (!processRecoveryArgs(args, index))
break;
}
printf("\n");
}
bool startupArgs::processRecoveryArgs(std::vector<std::string> args, int index) {
if (args[index].find(RESCUE_PARTY) != std::string::npos) {
gui_print("\n\n");
gui_msg(Msg(msg::kError, "rescue_party0=Android Rescue Party trigger! Possible solutions? Either:"));
@@ -53,7 +60,7 @@ void startupArgs::parse(int *argc, char ***argv) {
std::string ORSCommand = "install " + arg;
SkipDecryption = arg.find("@") == 1;
if (!OpenRecoveryScript::Insert_ORS_Command(ORSCommand))
break;
return false;
}
} else if (args[index].find(SEND_INTENT) != std::string::npos) {
std::string::size_type eq_pos = args[index].find("=");
@@ -65,17 +72,16 @@ void startupArgs::parse(int *argc, char ***argv) {
}
} else if (args[index].find(WIPE_DATA) != std::string::npos) {
if (!OpenRecoveryScript::Insert_ORS_Command("wipe data\n"))
break;
return false;
} else if (args[index].find(WIPE_CACHE) != std::string::npos) {
if (!OpenRecoveryScript::Insert_ORS_Command("wipe cache\n"))
break;
return false;
} else if (args[index].find(NANDROID) != std::string::npos) {
DataManager::SetValue(TW_BACKUP_NAME, gui_parse_text("{@auto_generate}"));
if (!OpenRecoveryScript::Insert_ORS_Command("backup BSDCAE\n"))
break;
return false;
}
}
printf("\n");
return true;
}
bool startupArgs::Should_Skip_Decryption() {

View File

@@ -45,6 +45,7 @@ public:
bool Should_Skip_Decryption();
std::string Get_Intent();
bool Get_Fastboot_Mode();
bool processRecoveryArgs(std::vector<std::string> args, int index);
private:
bool SkipDecryption = false;

View File

@@ -4,7 +4,6 @@
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/strings.h>
#include "recovery_utils/roots.h"
#include "bootloader_message/include/bootloader_message/bootloader_message.h"