FileDocCategorySizeDatePackage
RecoverySystem.javaAPI DocAndroid 1.5 API4515Wed May 06 22:41:56 BST 2009com.android.internal.os

RecoverySystem

public class RecoverySystem extends Object
Utility class for interacting with the Android recovery partition. The recovery partition is a small standalone system which can perform operations that are difficult while the main system is running, like upgrading system software or reformatting the data partition. Note that most of these operations must be run as root.
hide

Fields Summary
private static final String
TAG
private static File
RECOVERY_DIR
private static File
COMMAND_FILE
private static File
LOG_FILE
private static int
LOG_FILE_MAX_LENGTH
Constructors Summary
Methods Summary
private static voidbootCommand(java.lang.String arg)
Reboot into the recovery system with the supplied argument.

param
arg to pass to the recovery utility.
throws
IOException if something goes wrong.

        RECOVERY_DIR.mkdirs();  // In case we need it
        COMMAND_FILE.delete();  // In case it's not writable
        LOG_FILE.delete();

        FileWriter command = new FileWriter(COMMAND_FILE);
        try {
            command.write(arg);
            command.write("\n");
        } finally {
            command.close();
        }

        // Having written the command file, go ahead and reboot
        Power.reboot("recovery");
        throw new IOException("Reboot failed (no permissions?)");
    
public static java.lang.StringhandleAftermath()
Called after booting to process and remove recovery-related files.

return
the log file from recovery, or null if none was found.

        // Record the tail of the LOG_FILE
        String log = null;
        try {
            log = FileUtils.readTextFile(LOG_FILE, -LOG_FILE_MAX_LENGTH, "...\n");
        } catch (FileNotFoundException e) {
            Log.i(TAG, "No recovery log file");
        } catch (IOException e) {
            Log.e(TAG, "Error reading recovery log", e);
        }

        // Delete everything in RECOVERY_DIR
        String[] names = RECOVERY_DIR.list();
        for (int i = 0; names != null && i < names.length; i++) {
            File f = new File(RECOVERY_DIR, names[i]);
            if (!f.delete()) {
                Log.e(TAG, "Can't delete: " + f);
            } else {
                Log.i(TAG, "Deleted: " + f);
            }
        }

        return log;
    
public static voidrebootAndUpdate(java.io.File update)
Reboot into the recovery system to install a system update.

param
update package to install (must be in /cache or /data).
throws
IOException if something goes wrong.


                                    
           
        String path = update.getCanonicalPath();
        if (path.startsWith("/cache/")) {
            path = "CACHE:" + path.substring(7);
        } else if (path.startsWith("/data/")) {
            path = "DATA:" + path.substring(6);
        } else {
            throw new IllegalArgumentException(
                    "Must start with /cache or /data: " + path);
        }
        bootCommand("--update_package=" + path);
    
public static voidrebootAndWipe()
Reboot into the recovery system to wipe the /data partition.

param
extras to add to the RECOVERY_COMPLETED intent after rebooting.
throws
IOException if something goes wrong.

        bootCommand("--wipe_data");