AOSP10 TWRP Merge: fix conflicts and update libraries needed

This allows flame to boot TWRP. Still will need to work on
super partition for vendor and system access.

The plan will be to cherry-pick any updates to android-9.0
through gerrit.twrp.me to this branch as a WIP.
diff --git a/crypto/fde/cryptfs.cpp b/crypto/fde/cryptfs.cpp
index 5b8757c..8352296 100644
--- a/crypto/fde/cryptfs.cpp
+++ b/crypto/fde/cryptfs.cpp
@@ -256,7 +256,7 @@
 
     if (should_use_keymaster()) {
         if (scrypt_keymaster(passwd, salt, newpw, (void*)ftr)) {
-            SLOGE("scrypt failed\n");
+            SLOGE("scrypt failed");
         } else {
             rc = 0;
         }
@@ -293,7 +293,7 @@
         ++crypt_ftr->failed_decrypt_count;
 
         if (ascii_passwd_updated) {
-            SLOGI("Ascii password was updated\n");
+            SLOGI("Ascii password was updated");
         } else {
             /* Code in else part would execute only once:
              * When device is upgraded from L->M release.
@@ -305,14 +305,14 @@
             if (crypt_ftr->crypt_type == CRYPT_TYPE_DEFAULT) {
                 new_passwd = (char*)malloc(strlen(DEFAULT_HEX_PASSWORD) + 1);
                 if (new_passwd == NULL) {
-                    SLOGE("System out of memory. Password verification  incomplete\n");
+                    SLOGE("System out of memory. Password verification  incomplete");
                     goto out;
                 }
                 strlcpy(new_passwd, DEFAULT_HEX_PASSWORD, strlen(DEFAULT_HEX_PASSWORD) + 1);
             } else {
                 new_passwd = (char*)malloc(strlen(passwd) * 2 + 1);
                 if (new_passwd == NULL) {
-                    SLOGE("System out of memory. Password verification  incomplete\n");
+                    SLOGE("System out of memory. Password verification  incomplete");
                     goto out;
                 }
                 convert_key_to_hex_ascii_for_upgrade((const unsigned char*)passwd,
@@ -322,7 +322,7 @@
                                        (char*) crypt_ftr->crypto_type_name);
             if (key_index >=0) {
                 crypt_ftr->failed_decrypt_count = 0;
-                SLOGI("Hex password verified...will try to update with Ascii value\n");
+                SLOGI("Hex password verified...will try to update with Ascii value");
                 /* Before updating password, tie that with keymaster to tie with ROT */
 
                 if (get_keymaster_hw_fde_passwd(passwd, newpw,
@@ -336,9 +336,9 @@
 
                 if (passwd_updated >= 0) {
                     crypt_ftr->flags |= CRYPT_ASCII_PASSWORD_UPDATED;
-                    SLOGI("Ascii password recorded and updated\n");
+                    SLOGI("Ascii password recorded and updated");
                 } else {
-                    SLOGI("Passwd verified, could not update...Will try next time\n");
+                    SLOGI("Passwd verified, could not update...Will try next time");
                 }
             } else {
                 ++crypt_ftr->failed_decrypt_count;
@@ -412,10 +412,10 @@
             // so) because we really should be using a proper deterministic
             // RSA padding function, such as PKCS1.
             memcpy(to_sign + 1, object, min((size_t)RSA_KEY_SIZE_BYTES - 1, object_size));
-            SLOGI("Signing safely-padded object\n");
+            SLOGI("Signing safely-padded object");
             break;
         default:
-            SLOGE("Unknown KDF type %d\n", ftr->kdf_type);
+            SLOGE("Unknown KDF type %d", ftr->kdf_type);
             return -1;
     }
 
@@ -549,7 +549,7 @@
             return -1;
         }
         /*if (put_crypt_ftr_and_key(ftr) != 0) {
-            SLOGE("Failed to write upgraded key to disk\n");
+            SLOGE("Failed to write upgraded key to disk");
         }*/
         SLOGD("Key upgraded successfully\n");
         return 0;
@@ -930,8 +930,8 @@
            crypt_ftr->crypto_type_name, master_key_ascii,
            real_blk_name, extra_params);
 
-  SLOGI("target_type = %s\n", tgt->target_type);
-  SLOGI("real_blk_name = %s, extra_params = %s\n", real_blk_name, extra_params);
+  SLOGI("target_type = %s", tgt->target_type);
+  SLOGI("real_blk_name = %s, extra_params = %s", real_blk_name, extra_params);
 #else
   convert_key_to_hex_ascii(master_key, crypt_ftr->keysize, master_key_ascii);
   strlcpy(tgt->target_type, "crypt", DM_MAX_TYPE_NAME);
@@ -1205,13 +1205,13 @@
                        INTERMEDIATE_BUF_SIZE);
 
     if (rc) {
-        SLOGE("scrypt failed\n");
+        SLOGE("scrypt failed");
         return -1;
     }
 
     if (keymaster_sign_object(ftr, ikey, INTERMEDIATE_BUF_SIZE,
                               &signature, &signature_size)) {
-        SLOGE("Keymaster signing failed\n");
+        SLOGE("Keymaster signing failed");
         return -1;
     }
 
@@ -1220,7 +1220,7 @@
     free(signature);
 
     if (rc) {
-        SLOGE("scrypt failed\n");
+        SLOGE("scrypt failed");
         return -1;
     }
 
@@ -1242,7 +1242,7 @@
   /* Turn the password into an intermediate key and IV that can decrypt the
      master key */
   if (kdf(passwd, salt, ikey, kdf_params)) {
-    SLOGE("kdf failed\n");
+    SLOGE("kdf failed");
     return -1;
   }
 
@@ -1308,7 +1308,7 @@
                                  decrypted_master_key, kdf, kdf_params,
                                  intermediate_key, intermediate_key_size);
     if (ret != 0) {
-        SLOGW("failure decrypting master key\n");
+        SLOGW("failure decrypting master key");
     }
 
     return ret;
@@ -1332,13 +1332,6 @@
 
   int key_index = 0;
   if(is_hw_disk_encryption((char*)crypt_ftr->crypto_type_name)) {
-    if (crypt_ftr->flags & CRYPT_FORCE_COMPLETE) {
-       if (decrypt_master_key(passwd, decrypted_master_key, crypt_ftr, 0, 0)) {
-           printf("Failed to decrypt master key\n");
-           rc = -1;
-           goto errout;
-       }
-    }
     key_index = verify_and_update_hw_fde_passwd(passwd, crypt_ftr);
     if (key_index < 0) {
       rc = -1;
@@ -1349,7 +1342,7 @@
 #ifndef CONFIG_HW_DISK_ENCRYPT_PERF
         if (create_crypto_blk_dev(crypt_ftr, (unsigned char*)&key_index,
                             real_blkdev, crypto_blkdev, label, 0)) {
-          SLOGE("Error creating decrypted block device\n");
+          SLOGE("Error creating decrypted block device");
           rc = -1;
           goto errout;
         }
@@ -1357,7 +1350,7 @@
       } else {
         if (create_crypto_blk_dev(crypt_ftr, decrypted_master_key,
                             real_blkdev, crypto_blkdev, label, 0)) {
-          SLOGE("Error creating decrypted block device\n");
+          SLOGE("Error creating decrypted block device");
           rc = -1;
           goto errout;
         }
@@ -1403,7 +1396,7 @@
   //char real_blkdev[MAXPATHLEN];
   char tmp_mount_point[64];
   unsigned int orig_failed_decrypt_count;
-  int rc = 0;
+  int rc;
   int use_keymaster = 0;
   unsigned char* intermediate_key = 0;
   size_t intermediate_key_size = 0;
@@ -1446,7 +1439,7 @@
   if (rc == 0 && memcmp(scrypted_intermediate_key,
                         crypt_ftr->scrypted_intermediate_key,
                         sizeof(scrypted_intermediate_key)) == 0) {
-    SLOGI("Password matches\n");
+    SLOGI("Password matches");
     rc = 0;
   } else {
     /* Try mounting the file system anyway, just in case the problem's with
@@ -1461,7 +1454,7 @@
       rc = -1;
     } else {
       /* Success! */
-      SLOGI("Password did not match but decrypted drive mounted - continue\n");
+      SLOGI("Password did not match but decrypted drive mounted - continue");
       umount(tmp_mount_point);
       rc = 0;
     }
@@ -1501,7 +1494,7 @@
         const unsigned char* key, int keysize, char* out_crypto_blkdev) {
     int fd = open(real_blkdev, O_RDONLY|O_CLOEXEC);
     if (fd == -1) {
-        SLOGE("Failed to open %s: %s\n", real_blkdev, strerror(errno));
+        SLOGE("Failed to open %s: %s", real_blkdev, strerror(errno));
         return -1;
     }
 
@@ -1510,7 +1503,7 @@
     close(fd);
 
     if (nr_sec == 0) {
-        SLOGE("Failed to get size of %s: %s\n", real_blkdev, strerror(errno));
+        SLOGE("Failed to get size of %s: %s", real_blkdev, strerror(errno));
         return -1;
     }
 
@@ -1542,12 +1535,12 @@
     property_get("ro.crypto.state", encrypted_state, "");
     if ( master_key_saved || strcmp(encrypted_state, "encrypted") ) {
         SLOGE("encrypted fs already validated or not running with encryption,"
-              " aborting\n");
+              " aborting");
         return -1;
     }
 
     if (get_crypt_ftr_and_key(crypt_ftr)) {
-        SLOGE("Error getting crypt footer and key\n");
+        SLOGE("Error getting crypt footer and key");
         return -1;
     }
 
@@ -1558,11 +1551,11 @@
 int cryptfs_check_passwd_hw(const char* passwd)
 {
     struct crypt_mnt_ftr crypt_ftr;
-    int rc = 0;
+    int rc;
     unsigned char master_key[KEY_LEN_BYTES];
     /* get key */
     if (get_crypt_ftr_and_key(&crypt_ftr)) {
-        SLOGE("Error getting crypt footer and key\n");
+        SLOGE("Error getting crypt footer and key");
         return -1;
     }
 
@@ -1576,7 +1569,7 @@
          */
         rc = cryptfs_get_master_key(&crypt_ftr, passwd, master_key);
         if (rc) {
-            SLOGE("password doesn't match\n");
+            SLOGE("password doesn't match");
             return rc;
         }
 
@@ -1584,7 +1577,7 @@
             DATA_MNT_POINT, CRYPTO_BLOCK_DEVICE);
 
         if (rc) {
-            SLOGE("Default password did not match on reboot encryption\n");
+            SLOGE("Default password did not match on reboot encryption");
             return rc;
         }
     } else {
@@ -1600,7 +1593,7 @@
 int cryptfs_check_passwd(const char *passwd)
 {
     /*if (e4crypt_is_native()) {
-        SLOGE("cryptfs_check_passwd not valid for file encryption\n");
+        SLOGE("cryptfs_check_passwd not valid for file encryption");
         return -1;
     }*/
 
@@ -1609,7 +1602,7 @@
 
     rc = check_unmounted_and_get_ftr(&crypt_ftr);
     if (rc) {
-        SLOGE("Could not get footer\n");
+        SLOGE("Could not get footer");
         return rc;
     }
 
@@ -1622,7 +1615,7 @@
                                  DATA_MNT_POINT, CRYPTO_BLOCK_DEVICE);
 
     if (rc) {
-        SLOGE("Password did not match\n");
+        SLOGE("Password did not match");
         return rc;
     }
 
@@ -1635,7 +1628,7 @@
         rc = test_mount_encrypted_fs(&crypt_ftr, DEFAULT_PASSWORD,
                                      DATA_MNT_POINT, CRYPTO_BLOCK_DEVICE);
         if (rc) {
-            SLOGE("Default password did not match on reboot encryption\n");
+            SLOGE("Default password did not match on reboot encryption");
             return rc;
         }
     }
@@ -1652,17 +1645,17 @@
 
     property_get("ro.crypto.state", encrypted_state, "");
     if (strcmp(encrypted_state, "encrypted") ) {
-        SLOGE("device not encrypted, aborting\n");
+        SLOGE("device not encrypted, aborting");
         return -2;
     }
 
     if (!master_key_saved) {
-        SLOGE("encrypted fs not yet mounted, aborting\n");
+        SLOGE("encrypted fs not yet mounted, aborting");
         return -1;
     }
 
     if (!saved_mount_point) {
-        SLOGE("encrypted fs failed to save mount point, aborting\n");
+        SLOGE("encrypted fs failed to save mount point, aborting");
         return -1;
     }
 
@@ -1742,7 +1735,7 @@
                             &intermediate_key_size);
 
     if (rc) {
-        SLOGE("Can't calculate intermediate key\n");
+        SLOGE("Can't calculate intermediate key");
         return rc;
     }
 
@@ -1760,7 +1753,7 @@
     free(intermediate_key);
 
     if (rc) {
-        SLOGE("Can't scrypt intermediate key\n");
+        SLOGE("Can't scrypt intermediate key");
         return rc;
     }