summaryrefslogtreecommitdiffstats
path: root/cmds/bu
diff options
context:
space:
mode:
authorChristopher Tate <ctate@google.com>2011-05-16 16:22:06 -0700
committerChristopher Tate <ctate@google.com>2011-05-16 16:57:32 -0700
commit14a2935809e73a9d824888dc837f2f017100fd26 (patch)
tree408f6decede257f9c219355bb470906fefac84f1 /cmds/bu
parent4383243d0067d76a07966ff2178ea4d0c20271d3 (diff)
downloadframeworks_base-14a2935809e73a9d824888dc837f2f017100fd26.zip
frameworks_base-14a2935809e73a9d824888dc837f2f017100fd26.tar.gz
frameworks_base-14a2935809e73a9d824888dc837f2f017100fd26.tar.bz2
bu - add handling for both 'backup' and 'restore' modes
Requires a parallel change in adb to support the new syntax. Change-Id: Iff30cb247e424b6817af121c018f3c4e40b9f81a
Diffstat (limited to 'cmds/bu')
-rw-r--r--cmds/bu/src/com/android/commands/bu/Backup.java44
1 files 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<String> packages = new ArrayList<String>();
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;