From 14a2935809e73a9d824888dc837f2f017100fd26 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Mon, 16 May 2011 16:22:06 -0700 Subject: bu - add handling for both 'backup' and 'restore' modes Requires a parallel change in adb to support the new syntax. Change-Id: Iff30cb247e424b6817af121c018f3c4e40b9f81a --- cmds/bu/src/com/android/commands/bu/Backup.java | 44 +++++++++++++++++-------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/cmds/bu/src/com/android/commands/bu/Backup.java b/cmds/bu/src/com/android/commands/bu/Backup.java index 2b8d6aa..f3f0432 100644 --- a/cmds/bu/src/com/android/commands/bu/Backup.java +++ b/cmds/bu/src/com/android/commands/bu/Backup.java @@ -27,10 +27,11 @@ import java.io.IOException; import java.util.ArrayList; public final class Backup { - static final String TAG = "Backup"; + static final String TAG = "bu"; - private static String[] mArgs; - private int mNextArg; + static String[] mArgs; + int mNextArg; + IBackupManager mBackupManager; public static void main(String[] args) { mArgs = args; @@ -43,12 +44,23 @@ public final class Backup { } public void run() { - IBackupManager bmgr = IBackupManager.Stub.asInterface(ServiceManager.getService("backup")); - if (bmgr == null) { + mBackupManager = IBackupManager.Stub.asInterface(ServiceManager.getService("backup")); + if (mBackupManager == null) { System.err.println("ERROR: could not contact backup manager"); return; } + String arg = nextArg(); + if (arg.equals("backup")) { + doFullBackup(); + } else if (arg.equals("restore")) { + doFullRestore(); + } else { + System.err.println("ERROR: invalid operation '" + arg + "'"); + } + } + + private void doFullBackup() { ArrayList packages = new ArrayList(); boolean saveApks = false; boolean saveShared = false; @@ -56,7 +68,6 @@ public final class Backup { String arg; while ((arg = nextArg()) != null) { - if (arg.startsWith("-")) { if ("-apk".equals(arg)) { saveApks = true; @@ -69,8 +80,9 @@ public final class Backup { } else if ("-all".equals(arg)) { doEverything = true; } else { - System.err.println("ERROR: unknown flag " + arg); - return; + System.err.println("WARNING: unknown backup flag " + arg); + Log.w(TAG, "Unknown backup flag " + arg); + continue; } } else { // Not a flag; treat as a package name @@ -79,19 +91,22 @@ public final class Backup { } if (doEverything && packages.size() > 0) { - System.err.println("ERROR: -all used with specific package set"); - return; + System.err.println("WARNING: -all used with explicit backup package set"); + Log.w(TAG, "-all passed for backup along with specific package names"); } - if (!doEverything && packages.size() == 0) { - System.err.println("ERROR: no packages supplied and -all not used"); + if (!doEverything && !saveShared && packages.size() == 0) { + System.err.println( + "ERROR: no packages supplied for backup and neither -shared nor -all given"); + Log.e(TAG, "no backup packages supplied and neither -shared nor -all given"); return; } try { ParcelFileDescriptor fd = ParcelFileDescriptor.dup(FileDescriptor.out); String[] packArray = new String[packages.size()]; - bmgr.fullBackup(fd, saveApks, saveShared, doEverything, packages.toArray(packArray)); + mBackupManager.fullBackup(fd, saveApks, saveShared, doEverything, + packages.toArray(packArray)); } catch (IOException e) { System.err.println("ERROR: cannot dup System.out"); } catch (RemoteException e) { @@ -99,6 +114,9 @@ public final class Backup { } } + private void doFullRestore() { + } + private String nextArg() { if (mNextArg >= mArgs.length) { return null; -- cgit v1.1