Skip to content
This repository was archived by the owner on Nov 23, 2022. It is now read-only.

Commit

Permalink
Add option to uninstall TWRP app from /system
Browse files Browse the repository at this point in the history
Change-Id: Ibe372a372333c357810be2afcb3796723ca370cb
  • Loading branch information
Dees-Troy committed May 16, 2019
1 parent 9f5dd31 commit 76bbd3a
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 13 deletions.
2 changes: 2 additions & 0 deletions data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,11 +909,13 @@ void DataManager::SetDefaultValues()
#ifdef TW_OEM_BUILD
LOGINFO("TW_OEM_BUILD := true\n");
mConst.SetValue("tw_oem_build", "1");
mConst.SetValue("tw_app_installed_in_system", "0");
#else
mConst.SetValue("tw_oem_build", "0");
mPersist.SetValue("tw_app_prompt", "1");
mPersist.SetValue("tw_app_install_system", "1");
mData.SetValue("tw_app_install_status", "0"); // 0 = no status, 1 = not installed, 2 = already installed
mData.SetValue("tw_app_installed_in_system", "0");
#endif

mData.SetValue("tw_enable_adb_backup", "0");
Expand Down
70 changes: 57 additions & 13 deletions gui/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ GUIAction::GUIAction(xml_node<>* node)
ADD_ACTION(twcmd);
ADD_ACTION(setbootslot);
ADD_ACTION(installapp);
ADD_ACTION(uninstalltwrpsystemapp);
ADD_ACTION(repackimage);
ADD_ACTION(fixabrecoverybootloop);
}
Expand Down Expand Up @@ -1919,19 +1920,9 @@ int GUIAction::checkforapp(std::string arg __unused)
DataManager::SetValue("tw_app_install_status", 1); // 0 = no status, 1 = not installed, 2 = already installed or do not install
goto exit;
}
if (PartitionManager.Mount_By_Path(PartitionManager.Get_Android_Root_Path(), false)) {
string base_path = PartitionManager.Get_Android_Root_Path();
if (TWFunc::Path_Exists(PartitionManager.Get_Android_Root_Path() + "/system"))
base_path += "/system"; // For devices with system as a root file system (e.g. Pixel)
string install_path = base_path + "/priv-app";
if (!TWFunc::Path_Exists(install_path))
install_path = base_path + "/app";
install_path += "/twrpapp";
if (TWFunc::Path_Exists(install_path)) {
LOGINFO("App found at '%s'\n", install_path.c_str());
DataManager::SetValue("tw_app_install_status", 2); // 0 = no status, 1 = not installed, 2 = already installed or do not install
goto exit;
}
if (TWFunc::Is_TWRP_App_In_System()) {
DataManager::SetValue("tw_app_install_status", 2); // 0 = no status, 1 = not installed, 2 = already installed or do not install
goto exit;
}
if (PartitionManager.Mount_By_Path("/data", false)) {
const char parent_path[] = "/data/app";
Expand Down Expand Up @@ -2058,6 +2049,59 @@ int GUIAction::installapp(std::string arg __unused)
return 0;
}

int GUIAction::uninstalltwrpsystemapp(std::string arg __unused)
{
int op_status = 1;
operation_start("Uninstall TWRP System App");
if (!simulate)
{
int Mount_System_RO = DataManager::GetIntValue("tw_mount_system_ro");
TWPartition* Part = PartitionManager.Find_Partition_By_Path(PartitionManager.Get_Android_Root_Path());
if (!Part) {
LOGERR("Unabled to find system partition.\n");
goto exit;
}
if (!Part->UnMount(true)) {
goto exit;
}
if (Mount_System_RO > 0) {
DataManager::SetValue("tw_mount_system_ro", 0);
Part->Change_Mount_Read_Only(false);
}
if (Part->Mount(true)) {
string base_path = PartitionManager.Get_Android_Root_Path();
if (TWFunc::Path_Exists(PartitionManager.Get_Android_Root_Path() + "/system"))
base_path += "/system"; // For devices with system as a root file system (e.g. Pixel)
string uninstall_path = base_path + "/priv-app";
if (!TWFunc::Path_Exists(uninstall_path))
uninstall_path = base_path + "/app";
uninstall_path += "/twrpapp";
if (TWFunc::Path_Exists(uninstall_path)) {
LOGINFO("Uninstalling TWRP App from '%s'\n", uninstall_path.c_str());
if (TWFunc::removeDir(uninstall_path, false) == 0) {
sync();
op_status = 0;
DataManager::SetValue("tw_app_installed_in_system", 0);
DataManager::SetValue("tw_app_install_status", 0);
} else {
LOGERR("Unable to remove TWRP app from system.\n");
}
} else {
LOGINFO("didn't find TWRP app in '%s'\n", uninstall_path.c_str());
}
}
Part->UnMount(true);
if (Mount_System_RO > 0) {
DataManager::SetValue("tw_mount_system_ro", Mount_System_RO);
Part->Change_Mount_Read_Only(true);
}
} else
simulate_progress_bar();
exit:
operation_end(0);
return 0;
}

int GUIAction::repackimage(std::string arg __unused)
{
int op_status = 1;
Expand Down
1 change: 1 addition & 0 deletions gui/objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ class GUIAction : public GUIObject, public ActionObject
int twcmd(std::string arg);
int setbootslot(std::string arg);
int installapp(std::string arg);
int uninstalltwrpsystemapp(std::string arg);
int repackimage(std::string arg);
int fixabrecoverybootloop(std::string arg);

Expand Down
12 changes: 12 additions & 0 deletions gui/theme/common/landscape.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3433,6 +3433,18 @@
<action function="page">confirm_action</action>
</actions>
</listitem>
<listitem name="{@uninstall_twrp_system_app=Uninstall TWRP App from System}">
<condition var1="tw_app_installed_in_system" var2="1"/>
<actions>
<action function="set">tw_back=advanced</action>
<action function="set">tw_action=uninstalltwrpsystemapp</action>
<action function="set">tw_text1={@uninstall_twrp_system_app_confirm=Uninstall TWRP App from System?}</action>
<action function="set">tw_action_text1={@uninstalling_twrp_system_app=Uninstalling TWRP App from System...}</action>
<action function="set">tw_complete_text1={@uninstall_twrp_system_app_complete=Uninstall TWRP App from System Complete}</action>
<action function="set">tw_slider_text={@swipe_to_confirm=Swipe to Confirm}</action>
<action function="page">confirm_action</action>
</actions>
</listitem>
</listbox>

<action>
Expand Down
4 changes: 4 additions & 0 deletions gui/theme/common/languages/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@
<string name="reboot_install_app_system">Install as a System App</string>
<string name="reboot_installing_app">Installing App...</string>
<string name="swipe_to_install_app">Swipe to Install TWRP App</string>
<string name="uninstall_twrp_system_app">Uninstall TWRP App from System</string>
<string name="uninstall_twrp_system_app_confirm">Uninstall TWRP App from System?</string>
<string name="uninstalling_twrp_system_app">Uninstalling TWRP App from System...</string>
<string name="uninstall_twrp_system_app_complete">Uninstall TWRP App from System Complete</string>
<string name="swipe_flash">Swipe to confirm Flash</string>
<string name="confirm_action">Confirm Action</string>
<string name="back_cancel">Press back button to cancel.</string>
Expand Down
12 changes: 12 additions & 0 deletions gui/theme/common/portrait.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3594,6 +3594,18 @@
<action function="page">confirm_action</action>
</actions>
</listitem>
<listitem name="{@uninstall_twrp_system_app=Uninstall TWRP App from System}">
<condition var1="tw_app_installed_in_system" var2="1"/>
<actions>
<action function="set">tw_back=advanced</action>
<action function="set">tw_action=uninstalltwrpsystemapp</action>
<action function="set">tw_text1={@uninstall_twrp_system_app_confirm=Uninstall TWRP App from System?}</action>
<action function="set">tw_action_text1={@uninstalling_twrp_system_app=Uninstalling TWRP App from System...}</action>
<action function="set">tw_complete_text1={@uninstall_twrp_system_app_complete=Uninstall TWRP App from System Complete}</action>
<action function="set">tw_slider_text={@swipe_to_confirm=Swipe to Confirm}</action>
<action function="page">confirm_action</action>
</actions>
</listitem>
</listbox>

<action>
Expand Down
12 changes: 12 additions & 0 deletions gui/theme/common/watch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4205,6 +4205,18 @@
<action function="page">confirm_action</action>
</actions>
</listitem>
<listitem name="{@uninstall_twrp_system_app=Uninstall TWRP App from System}">
<condition var1="tw_app_installed_in_system" var2="1"/>
<actions>
<action function="set">tw_back=advanced</action>
<action function="set">tw_action=uninstalltwrpsystemapp</action>
<action function="set">tw_text1={@uninstall_twrp_system_app_confirm=Uninstall TWRP App from System?}</action>
<action function="set">tw_action_text1={@uninstalling_twrp_system_app=Uninstalling TWRP App from System...}</action>
<action function="set">tw_complete_text1={@uninstall_twrp_system_app_complete=Uninstall TWRP App from System Complete}</action>
<action function="set">tw_slider_text={@swipe_to_confirm=Swipe to Confirm}</action>
<action function="page">confirm_action</action>
</actions>
</listitem>
</listbox>

<button>
Expand Down
1 change: 1 addition & 0 deletions partitionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,7 @@ void TWPartitionManager::Update_System_Details(void) {
if ((*iter)->Mount_Point == Get_Android_Root_Path()) {
int backup_display_size = (int)((*iter)->Backup_Size / 1048576LLU);
DataManager::SetValue(TW_BACKUP_SYSTEM_SIZE, backup_display_size);
TWFunc::Is_TWRP_App_In_System();
} else if ((*iter)->Mount_Point == "/data" || (*iter)->Mount_Point == "/datadata") {
data_size += (int)((*iter)->Backup_Size / 1048576LLU);
} else if ((*iter)->Mount_Point == "/cache") {
Expand Down
19 changes: 19 additions & 0 deletions twrp-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,4 +1228,23 @@ void TWFunc::check_selinux_support() {
}
}
}

bool TWFunc::Is_TWRP_App_In_System() {
if (PartitionManager.Mount_By_Path(PartitionManager.Get_Android_Root_Path(), false)) {
string base_path = PartitionManager.Get_Android_Root_Path();
if (TWFunc::Path_Exists(PartitionManager.Get_Android_Root_Path() + "/system"))
base_path += "/system"; // For devices with system as a root file system (e.g. Pixel)
string install_path = base_path + "/priv-app";
if (!TWFunc::Path_Exists(install_path))
install_path = base_path + "/app";
install_path += "/twrpapp";
if (TWFunc::Path_Exists(install_path)) {
LOGINFO("App found at '%s'\n", install_path.c_str());
DataManager::SetValue("tw_app_installed_in_system", 1);
return true;
}
}
DataManager::SetValue("tw_app_installed_in_system", 0);
return false;
}
#endif // ndef BUILD_TWRPTAR_MAIN
1 change: 1 addition & 0 deletions twrp-functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class TWFunc
static int stream_adb_backup(string &Restore_Name); // Tell ADB Backup to Stream to TWRP from GUI selection
static std::string get_cache_dir(); // return the cache partition existence
static void check_selinux_support(); // print whether selinux support is enabled to console
static bool Is_TWRP_App_In_System(); // Check if the TWRP app is installed in the system partition

private:
static void Copy_Log(string Source, string Destination);
Expand Down

0 comments on commit 76bbd3a

Please sign in to comment.