summaryrefslogtreecommitdiffstats
path: root/partitionmanager.cpp
diff options
context:
space:
mode:
authorEthan Yonker <dees_troy@teamw.in>2016-12-05 22:25:19 +0100
committerEthan Yonker <dees_troy@teamw.in>2016-12-13 21:04:48 +0100
commit1b190166eb1295c6339f6100e4fbb92c81b81ea6 (patch)
tree6493cc3a385c67f079d52873b97963656cf084d2 /partitionmanager.cpp
parentSupport new AB OTA zips (diff)
downloadandroid_bootable_recovery-1b190166eb1295c6339f6100e4fbb92c81b81ea6.tar
android_bootable_recovery-1b190166eb1295c6339f6100e4fbb92c81b81ea6.tar.gz
android_bootable_recovery-1b190166eb1295c6339f6100e4fbb92c81b81ea6.tar.bz2
android_bootable_recovery-1b190166eb1295c6339f6100e4fbb92c81b81ea6.tar.lz
android_bootable_recovery-1b190166eb1295c6339f6100e4fbb92c81b81ea6.tar.xz
android_bootable_recovery-1b190166eb1295c6339f6100e4fbb92c81b81ea6.tar.zst
android_bootable_recovery-1b190166eb1295c6339f6100e4fbb92c81b81ea6.zip
Diffstat (limited to 'partitionmanager.cpp')
-rw-r--r--partitionmanager.cpp64
1 files changed, 63 insertions, 1 deletions
diff --git a/partitionmanager.cpp b/partitionmanager.cpp
index 079d476b3..9e23ccb94 100644
--- a/partitionmanager.cpp
+++ b/partitionmanager.cpp
@@ -64,12 +64,26 @@ extern "C" {
#include "gui/pages.hpp"
#endif
+#ifdef AB_OTA_UPDATER
+#include <hardware/hardware.h>
+#include <hardware/boot_control.h>
+#endif
+
extern bool datamedia;
TWPartitionManager::TWPartitionManager(void) {
mtp_was_enabled = false;
mtp_write_fd = -1;
stop_backup.set_value(0);
+#ifdef AB_OTA_UPDATER
+ char slot_suffix[PROPERTY_VALUE_MAX];
+ property_get("ro.boot.slot_suffix", slot_suffix, "_a");
+ Active_Slot_Display = "";
+ if (strcmp(slot_suffix, "_a") == 0)
+ Set_Active_Slot("A");
+ else
+ Set_Active_Slot("B");
+#endif
}
int TWPartitionManager::Process_Fstab(string Fstab_Filename, bool Display_Error) {
@@ -182,6 +196,9 @@ int TWPartitionManager::Process_Fstab(string Fstab_Filename, bool Display_Error)
#endif
Update_System_Details();
UnMount_Main_Partitions();
+#ifdef AB_OTA_UPDATER
+ DataManager::SetValue("tw_active_slot", Get_Active_Slot_Display());
+#endif
return true;
}
@@ -290,6 +307,8 @@ void TWPartitionManager::Output_Partition(TWPartition* Part) {
printf("Can_Flash_Img ");
if (Part->Is_Adopted_Storage)
printf("Is_Adopted_Storage ");
+ if (Part->SlotSelect)
+ printf("SlotSelect ");
printf("\n");
if (!Part->SubPartition_Of.empty())
printf(" SubPartition_Of: %s\n", Part->SubPartition_Of.c_str());
@@ -1376,8 +1395,8 @@ void TWPartitionManager::Update_System_Details(void) {
gui_msg("update_part_details=Updating partition details...");
for (iter = Partitions.begin(); iter != Partitions.end(); iter++) {
+ (*iter)->Update_Size(true);
if ((*iter)->Can_Be_Mounted) {
- (*iter)->Update_Size(true);
if ((*iter)->Mount_Point == "/system") {
int backup_display_size = (int)((*iter)->Backup_Size / 1048576LLU);
DataManager::SetValue(TW_BACKUP_SYSTEM_SIZE, backup_display_size);
@@ -2473,3 +2492,46 @@ void TWPartitionManager::Remove_Partition_By_Path(string Path) {
}
}
}
+
+void TWPartitionManager::Set_Active_Slot(const string& Slot) {
+ if (Slot != "A" && Slot != "B") {
+ LOGERR("Set_Active_Slot invalid slot '%s'\n", Slot.c_str());
+ return;
+ }
+ if (Active_Slot_Display == Slot)
+ return;
+ LOGINFO("Setting active slot %s\n", Slot.c_str());
+#ifdef AB_OTA_UPDATER
+ if (!Active_Slot_Display.empty()) {
+ const hw_module_t *hw_module;
+ boot_control_module_t *module;
+ int ret;
+ ret = hw_get_module("bootctrl", &hw_module);
+ if (ret != 0) {
+ LOGERR("Error getting bootctrl module.\n");
+ } else {
+ module = (boot_control_module_t*) hw_module;
+ module->init(module);
+ int slot_number = 0;
+ if (Slot == "B")
+ slot_number = 1;
+ if (module->setActiveBootSlot(module, slot_number))
+ gui_msg(Msg(msg::kError, "unable_set_boot_slot=Error changing bootloader boot slot to {1}")(Slot));
+ }
+ DataManager::SetValue("tw_active_slot", Slot); // Doing this outside of this if block may result in a seg fault because the DataManager may not be ready yet
+ }
+#else
+ LOGERR("Boot slot feature not present\n");
+#endif
+ Active_Slot_Display = Slot;
+ if (Fstab_Processed())
+ Update_System_Details();
+}
+string TWPartitionManager::Get_Active_Slot_Suffix() {
+ if (Active_Slot_Display == "A")
+ return "_a";
+ return "_b";
+}
+string TWPartitionManager::Get_Active_Slot_Display() {
+ return Active_Slot_Display;
+}