From 8f52c0a73dceedb9ea5ee933e92fb94cd7cdbf20 Mon Sep 17 00:00:00 2001 From: epicX Date: Wed, 24 Feb 2021 23:12:08 +0530 Subject: [PATCH] Added support for flash image in both slots Change-Id: Iafda62a5f77f7c1f564f1a2ec0a59aefaf5e1266 --- data.cpp | 3 +++ gui/action.cpp | 33 +++++++++++++++++++++++++++---- gui/partitionlist.cpp | 4 ++++ gui/theme/common/landscape.xml | 29 ++++++++++++++++++++++++++- gui/theme/common/languages/en.xml | 1 + gui/theme/common/portrait.xml | 29 ++++++++++++++++++++++++++- gui/theme/common/watch.xml | 29 ++++++++++++++++++++++++++- 7 files changed, 121 insertions(+), 7 deletions(-) diff --git a/data.cpp b/data.cpp index e7b2f613..d7c77ab8 100755 --- a/data.cpp +++ b/data.cpp @@ -928,6 +928,9 @@ void DataManager::SetDefaultValues() mConst.SetValue("tw_include_nano", "0"); #endif + mData.SetValue("tw_flash_both_slots", "0"); + mData.SetValue("tw_is_slot_part", "0"); + mData.SetValue("tw_enable_adb_backup", "0"); if (TWFunc::Path_Exists("/system/bin/magiskboot")) diff --git a/gui/action.cpp b/gui/action.cpp index a3108579..e7852876 100755 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -1810,16 +1810,41 @@ int GUIAction::stopmtp(std::string arg __unused) int GUIAction::flashimage(std::string arg __unused) { int op_status = 0; + bool flag = true; operation_start("Flash Image"); string path, filename; DataManager::GetValue("tw_zip_location", path); DataManager::GetValue("tw_file", filename); - if (PartitionManager.Flash_Image(path, filename)) - op_status = 0; // success - else - op_status = 1; // fail +#ifdef AB_OTA_UPDATER + string target = DataManager::GetStrValue("tw_flash_partition"); + unsigned int pos = target.find_last_of(';'); + string mount_point = pos != string::npos ? target.substr(0, pos) : ""; + TWPartition* t_part = PartitionManager.Find_Partition_By_Path(mount_point); + bool flash_in_both_slots = DataManager::GetIntValue("tw_flash_both_slots") ? true : false; + + if (t_part != NULL && (flash_in_both_slots && t_part->SlotSelect)) + { + string current_slot = PartitionManager.Get_Active_Slot_Display(); + bool pre_op_status = PartitionManager.Flash_Image(path, filename); + + PartitionManager.Set_Active_Slot(current_slot == "A" ? "B" : "A"); + op_status = (int) !(pre_op_status && PartitionManager.Flash_Image(path, filename)); + PartitionManager.Set_Active_Slot(current_slot); + + DataManager::SetValue("tw_flash_both_slots", 0); + flag = false; + } +#endif + if (flag) + { + if (PartitionManager.Flash_Image(path, filename)) + op_status = 0; // success + else + op_status = 1; // fail + } + operation_end(op_status); return 0; } diff --git a/gui/partitionlist.cpp b/gui/partitionlist.cpp index a5a68e0e..19153c50 100755 --- a/gui/partitionlist.cpp +++ b/gui/partitionlist.cpp @@ -180,6 +180,8 @@ void GUIPartitionList::MatchList(void) { pos = variablelist.find(searchvalue); if (pos != string::npos) { mList.at(i).selected = 1; + TWPartition* t_part = PartitionManager.Find_Partition_By_Path(mList.at(i).Mount_Point); + DataManager::SetValue("tw_is_slot_part", t_part != NULL ? (int) t_part->SlotSelect : 0); } else { mList.at(i).selected = 0; } @@ -272,6 +274,8 @@ void GUIPartitionList::NotifySelect(size_t item_selected) mList.at(item_selected).selected = 0; else mList.at(item_selected).selected = 1; + TWPartition* t_part = PartitionManager.Find_Partition_By_Path(mList.at(item_selected).Mount_Point); + DataManager::SetValue("tw_is_slot_part", t_part != NULL ? (int) t_part->SlotSelect : 0); int i; string variablelist; diff --git a/gui/theme/common/landscape.xml b/gui/theme/common/landscape.xml index b8c20988..3af7da6c 100755 --- a/gui/theme/common/landscape.xml +++ b/gui/theme/common/landscape.xml @@ -372,7 +372,10 @@ - flashimage_confirm + + tw_is_slot_part=0 + flashimage_confirm + @@ -711,6 +714,30 @@ + + + + {@swipe_flash=Swipe to confirm Flash} diff --git a/gui/theme/common/languages/en.xml b/gui/theme/common/languages/en.xml index 3bc7a142..16dccf52 100755 --- a/gui/theme/common/languages/en.xml +++ b/gui/theme/common/languages/en.xml @@ -740,6 +740,7 @@ Failed unmounting System Flashing A/B zip to inactive slot: {1} To flash additional zips, please reboot recovery to switch to the updated slot. + Flash to both slots Starting Ozip Decryption... Ozip Decryption Finished! WARNING: {1} wiped. FBE device should be booted into Android and not Recovery to set initial FBE policy after wipe. diff --git a/gui/theme/common/portrait.xml b/gui/theme/common/portrait.xml index 1dfb2ca6..9d478550 100755 --- a/gui/theme/common/portrait.xml +++ b/gui/theme/common/portrait.xml @@ -329,7 +329,10 @@ - flashimage_confirm + + tw_is_slot_part=0 + flashimage_confirm + @@ -662,6 +665,30 @@ + + + + {@swipe_flash=Swipe to confirm Flash} diff --git a/gui/theme/common/watch.xml b/gui/theme/common/watch.xml index 6dd019f5..c12cbf8d 100755 --- a/gui/theme/common/watch.xml +++ b/gui/theme/common/watch.xml @@ -442,7 +442,10 @@ - flashimage_type + + tw_is_slot_part=0 + flashimage_type + @@ -860,6 +863,30 @@ + + + +