From 18aea279ca7e191c664007ca9a8753999d40f58f Mon Sep 17 00:00:00 2001 From: Captain Throwback Date: Thu, 29 Oct 2020 12:43:17 -0400 Subject: [PATCH] fde: move crypto state & type setting to function In order to make sure the crypto state and type is set properly if the device is encrypted, move this check to a function and call it in cases where the default password is being used and in cases where it isn't. This will ensure that an unencrypted device isn't set as encrypted by mistake. Change-Id: I736f9cbee0e95d7390a09c8235b9914feddaceaf --- partitionmanager.cpp | 14 ++++++++++---- partitions.hpp | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/partitionmanager.cpp b/partitionmanager.cpp index f263b5f7..866abfb3 100755 --- a/partitionmanager.cpp +++ b/partitionmanager.cpp @@ -135,6 +135,14 @@ TWPartitionManager::TWPartitionManager(void) { #endif } +int TWPartitionManager::Set_FDE_Encrypt_Status(void) { + property_set("ro.crypto.state", "encrypted"); + property_set("ro.crypto.type", "block"); + // Sleep for a bit so that services can start if needed + sleep(1); + return 0; +} + int TWPartitionManager::Process_Fstab(string Fstab_Filename, bool Display_Error) { FILE *fstabFile; char fstab_line[MAX_FSTAB_LINE_LENGTH]; @@ -443,6 +451,7 @@ void TWPartitionManager::Decrypt_Data() { } } } else { + Set_FDE_Encrypt_Status(); int password_type = cryptfs_get_password_type(); if (password_type == CRYPT_TYPE_DEFAULT) { LOGINFO("Device is encrypted with the default password, attempting to decrypt.\n"); @@ -1864,10 +1873,7 @@ int TWPartitionManager::Decrypt_Device(string Password, int user_id) { property_get("ro.crypto.state", crypto_state, "error"); if (strcmp(crypto_state, "error") == 0) { - property_set("ro.crypto.state", "encrypted"); - property_set("ro.crypto.type", "block"); - // Sleep for a bit so that services can start if needed - sleep(1); + Set_FDE_Encrypt_Status(); } if (DataManager::GetIntValue(TW_IS_FBE)) { diff --git a/partitions.hpp b/partitions.hpp index c0c9d25a..284baebe 100755 --- a/partitions.hpp +++ b/partitions.hpp @@ -390,6 +390,7 @@ public: void Setup_Super_Partition(); // Setup the super partition for backup and restore bool Recreate_Logs_Dir(); // Recreate TWRP_AB_LOGS_DIR after wipe std::vector* Get_Users_List(); // Returns pointer to list of users + int Set_FDE_Encrypt_Status(); // Sets encryption state for FDE devices (ro.crypto.state and ro.crypto.type) private: void Setup_Settings_Storage_Partition(TWPartition* Part); // Sets up settings storage