From 4fd6c26410cd210a7948f94407d9b2f551badbdc Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 19 Jan 2016 14:22:24 -0800 Subject: [PATCH] Stop rebooting into recovery if uncrypt fails. uncrypt needs to be called when an OTA package sits on /data. If uncrypt fails or gets skipped (likely due to unexpected runtime restart during the reboot), we should abort the rebooting. Because otherwise a) it would fail for sure when reboots into recovery; b) useful logs would be gone once it reboots. Bug: 26444951 Change-Id: Ic3bc682b03f003f197e277ed6b6886e85f364754 --- .../java/com/android/server/SystemServer.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index ee5f23fe028cc..1a305f31bbbf0 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -31,8 +31,11 @@ import android.content.res.Resources.Theme; import android.os.Build; import android.os.Environment; import android.os.FactoryTest; +import android.os.FileUtils; import android.os.IPowerManager; import android.os.Looper; +import android.os.PowerManager; +import android.os.RecoverySystem; import android.os.RemoteException; import android.os.ServiceManager; import android.os.StrictMode; @@ -95,6 +98,8 @@ import com.android.server.wm.WindowManagerService; import dalvik.system.VMRuntime; +import java.io.File; +import java.io.IOException; import java.util.Locale; import java.util.Timer; import java.util.TimerTask; @@ -144,6 +149,9 @@ public final class SystemServer { private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst"; + private static final String UNCRYPT_PACKAGE_FILE = "/cache/recovery/uncrypt_file"; + private static final String BLOCK_MAP_FILE = "/cache/recovery/block.map"; + /** * Default theme used by the system context. This is used to style * system-provided dialogs, such as the Power Off dialog, and other @@ -324,6 +332,30 @@ public final class SystemServer { reason = null; } + // If it's a pending reboot into recovery to apply an update, + // always make sure uncrypt gets executed properly when needed. + // If '/cache/recovery/block.map' hasn't been created, stop the + // reboot which will fail for sure, and get a chance to capture a + // bugreport when that's still feasible. (Bug; 26444951) + if (PowerManager.REBOOT_RECOVERY.equals(reason)) { + File packageFile = new File(UNCRYPT_PACKAGE_FILE); + if (packageFile.exists()) { + String filename = null; + try { + filename = FileUtils.readTextFile(packageFile, 0, null); + } catch (IOException e) { + Slog.e(TAG, "Error reading uncrypt package file", e); + } + + if (filename != null && filename.startsWith("/data")) { + if (!new File(BLOCK_MAP_FILE).exists()) { + Slog.e(TAG, "Can't find block map file, uncrypt failed or " + + "unexpected runtime restart?"); + return; + } + } + } + } ShutdownThread.rebootOrShutdown(null, reboot, reason); } }