Skip to content

Commit

Permalink
get_args: process /data/cache/command
Browse files Browse the repository at this point in the history
Change-Id: I744cdc5a72f53fd1224de242e30ff261e6104900
  • Loading branch information
bigbiff authored and epicX67 committed Nov 4, 2021
1 parent 54a0206 commit 3d3814a
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 31 deletions.
2 changes: 1 addition & 1 deletion etc/init.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 1 addition & 18 deletions install/get_args.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion openrecoveryscript.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 9 additions & 1 deletion partition.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 22 additions & 1 deletion partitionmanager.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion partitions.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -130,6 +130,7 @@ class TWPartition
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
Expand Down
20 changes: 13 additions & 7 deletions startupArgs.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:"));
Expand Down Expand Up @@ -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("=");
Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions startupArgs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class startupArgs {
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;
Expand Down
1 change: 0 additions & 1 deletion twrpinstall/include/twinstall/get_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3d3814a

Please sign in to comment.