From 87212ad6a86088f9b6342aadc480934e2f6548f7 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 19 Oct 2015 14:48:36 -0700 Subject: [PATCH] Clean up the uncrypted OTA package on bootup. An OTA package needs to be uncrypted before rebooting into recovery if it sits on an encrypted /data partition. Once uncrypt gets started, we cannot re-run it on the package again. Because the file may have been fully or particially uncrypted and we may end up with a corrupt file under recovery. Always clean up the package when the device boots into the normal system to avoid that. Bug: 24973532 Change-Id: I91682c103d1f2b603626c4bf8d818bced71e3674 --- core/java/android/os/RecoverySystem.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/java/android/os/RecoverySystem.java b/core/java/android/os/RecoverySystem.java index 8c544f44f2445..8e06fa7e4be8d 100644 --- a/core/java/android/os/RecoverySystem.java +++ b/core/java/android/os/RecoverySystem.java @@ -341,6 +341,10 @@ public class RecoverySystem { } finally { uncryptFile.close(); } + // UNCRYPT_FILE needs to be readable by system server on bootup. + if (!UNCRYPT_FILE.setReadable(true, false)) { + Log.e(TAG, "Error setting readable for " + UNCRYPT_FILE.getCanonicalPath()); + } Log.w(TAG, "!!! REBOOTING TO INSTALL " + filename + " !!!"); // If the package is on the /data partition, write the block map file @@ -501,6 +505,25 @@ public class RecoverySystem { Log.e(TAG, "Error reading recovery log", e); } + if (UNCRYPT_FILE.exists()) { + String filename = null; + try { + filename = FileUtils.readTextFile(UNCRYPT_FILE, 0, null); + } catch (IOException e) { + Log.e(TAG, "Error reading uncrypt file", e); + } + + // Remove the OTA package on /data that has been (possibly + // partially) processed. (Bug: 24973532) + if (filename != null && filename.startsWith("/data")) { + if (UNCRYPT_FILE.delete()) { + Log.i(TAG, "Deleted: " + filename); + } else { + Log.e(TAG, "Can't delete: " + filename); + } + } + } + // Delete everything in RECOVERY_DIR except those beginning // with LAST_PREFIX String[] names = RECOVERY_DIR.list();