1ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate/*
2ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * Copyright (C) 2009 The Android Open Source Project
3ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate *
4ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * Licensed under the Apache License, Version 2.0 (the "License");
5ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * you may not use this file except in compliance with the License.
6ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * You may obtain a copy of the License at
7ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate *
8ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate *      http://www.apache.org/licenses/LICENSE-2.0
9ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate *
10ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * Unless required by applicable law or agreed to in writing, software
11ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * distributed under the License is distributed on an "AS IS" BASIS,
12ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * See the License for the specific language governing permissions and
14ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * limitations under the License.
15ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate */
16ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
17ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tatepackage com.android.commands.bmgr;
18ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
194528186e0d65fc68ef0dd1941aa2ac8aefcd55a3Christopher Tateimport android.app.backup.RestoreSet;
204528186e0d65fc68ef0dd1941aa2ac8aefcd55a3Christopher Tateimport android.app.backup.IBackupManager;
214528186e0d65fc68ef0dd1941aa2ac8aefcd55a3Christopher Tateimport android.app.backup.IRestoreObserver;
224528186e0d65fc68ef0dd1941aa2ac8aefcd55a3Christopher Tateimport android.app.backup.IRestoreSession;
23ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tateimport android.os.RemoteException;
24ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tateimport android.os.ServiceManager;
25ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
26284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tateimport java.util.HashSet;
27284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate
28ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tatepublic final class Bmgr {
29ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    IBackupManager mBmgr;
30ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    IRestoreSession mRestore;
31ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
32ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    static final String BMGR_NOT_RUNNING_ERR =
33ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            "Error: Could not access the Backup Manager.  Is the system running?";
34ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    static final String TRANSPORT_NOT_RUNNING_ERR =
35ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        "Error: Could not access the backup transport.  Is the system running?";
36ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
37ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    private String[] mArgs;
38ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    private int mNextArg;
39ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
40ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    public static void main(String[] args) {
41f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate        try {
42f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate            new Bmgr().run(args);
43f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate        } catch (Exception e) {
44f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate            System.err.println("Exception caught:");
45f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate            e.printStackTrace();
46f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate        }
47ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    }
48f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate
49ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    public void run(String[] args) {
50ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        if (args.length < 1) {
51ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            showUsage();
52ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            return;
53ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        }
54ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
55ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        mBmgr = IBackupManager.Stub.asInterface(ServiceManager.getService("backup"));
56ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        if (mBmgr == null) {
57ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            System.err.println(BMGR_NOT_RUNNING_ERR);
58ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            return;
59ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        }
60ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
61ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        mArgs = args;
62ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        String op = args[0];
63ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        mNextArg = 1;
64ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
656ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        if ("enabled".equals(op)) {
666ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            doEnabled();
676ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            return;
686ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        }
696ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate
706ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        if ("enable".equals(op)) {
716ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            doEnable();
726ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            return;
736ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        }
746ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate
75ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        if ("run".equals(op)) {
76ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            doRun();
77ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            return;
78ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        }
79ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
80ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        if ("backup".equals(op)) {
81ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            doBackup();
82ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            return;
83ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        }
84ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
85ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        if ("list".equals(op)) {
86ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            doList();
87ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            return;
88ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        }
89f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate
90f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate        if ("restore".equals(op)) {
91f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate            doRestore();
92f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate            return;
93f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate        }
94abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate
95abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate        if ("transport".equals(op)) {
96abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate            doTransport();
97abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate            return;
98abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate        }
99abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate
100d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate        if ("wipe".equals(op)) {
101d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate            doWipe();
102d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate            return;
103d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate        }
104d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate
105abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate        System.err.println("Unknown command");
106abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate        showUsage();
107ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    }
108ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
1096ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate    private String enableToString(boolean enabled) {
1106ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        return enabled ? "enabled" : "disabled";
1116ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate    }
1126ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate
1136ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate    private void doEnabled() {
1146ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        try {
1156ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            boolean isEnabled = mBmgr.isBackupEnabled();
1166ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            System.out.println("Backup Manager currently "
1176ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate                    + enableToString(isEnabled));
1186ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        } catch (RemoteException e) {
1196ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            System.err.println(e.toString());
1206ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            System.err.println(BMGR_NOT_RUNNING_ERR);
1216ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        }
1226ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate    }
1236ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate
1246ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate    private void doEnable() {
1256ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        String arg = nextArg();
1266ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        if (arg == null) {
1276ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            showUsage();
1286ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            return;
1296ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        }
1306ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate
1316ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        try {
1326ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            boolean enable = Boolean.parseBoolean(arg);
1336ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            mBmgr.setBackupEnabled(enable);
1346ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            System.out.println("Backup Manager now " + enableToString(enable));
1356ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        } catch (NumberFormatException e) {
1366ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            showUsage();
1376ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            return;
1386ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        } catch (RemoteException e) {
1396ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            System.err.println(e.toString());
1406ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate            System.err.println(BMGR_NOT_RUNNING_ERR);
1416ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        }
1426ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate    }
1436ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate
144ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    private void doRun() {
145ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        try {
146ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            mBmgr.backupNow();
147ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        } catch (RemoteException e) {
148ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            System.err.println(e.toString());
149ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            System.err.println(BMGR_NOT_RUNNING_ERR);
150ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        }
151ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    }
152ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
153ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    private void doBackup() {
154ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        String pkg = nextArg();
1554a627c71ff53a4fca1f961f4b1dcc0461df18a06Christopher Tate        if (pkg == null) {
156ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            showUsage();
157ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            return;
158ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        }
159ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
160ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        try {
161ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            mBmgr.dataChanged(pkg);
162ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        } catch (RemoteException e) {
163ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            System.err.println(e.toString());
164ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            System.err.println(BMGR_NOT_RUNNING_ERR);
165ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        }
166ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    }
167ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
168abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate    private void doTransport() {
169abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate        try {
1709171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate            String which = nextArg();
1717e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate            if (which == null) {
1727e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate                showUsage();
1737e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate                return;
1747e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate            }
1757e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate
1769171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate            String old = mBmgr.selectBackupTransport(which);
1779171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate            if (old == null) {
1789171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate                System.out.println("Unknown transport '" + which
1799171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate                        + "' specified; no changes made.");
1809171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate            } else {
1819171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate                System.out.println("Selected transport " + which + " (formerly " + old + ")");
1829171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate            }
183abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate        } catch (RemoteException e) {
184abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate            System.err.println(e.toString());
185abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate            System.err.println(BMGR_NOT_RUNNING_ERR);
186abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate        }
187abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate    }
188abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate
189d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate    private void doWipe() {
190d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate        String pkg = nextArg();
191d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate        if (pkg == null) {
192d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate            showUsage();
193d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate            return;
194d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate        }
195d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate
196d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate        try {
197d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate            mBmgr.clearBackupData(pkg);
198d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate            System.out.println("Wiped backup data for " + pkg);
199d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate        } catch (RemoteException e) {
200d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate            System.err.println(e.toString());
201d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate            System.err.println(BMGR_NOT_RUNNING_ERR);
202d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate        }
203d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate    }
204d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate
205ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    private void doList() {
206ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        String arg = nextArg();     // sets, transports, packages set#
207ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        if ("transports".equals(arg)) {
208ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            doListTransports();
209ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            return;
210ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        }
211ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
212ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        // The rest of the 'list' options work with a restore session on the current transport
213ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        try {
21444ab8453e1c4c46790f792a46d026fa1017d8cfeChris Tate            mRestore = mBmgr.beginRestoreSession(null, null);
215f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate            if (mRestore == null) {
216f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate                System.err.println(BMGR_NOT_RUNNING_ERR);
217f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate                return;
218f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate            }
219ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
220ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            if ("sets".equals(arg)) {
221ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate                doListRestoreSets();
2229171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate            } else if ("transports".equals(arg)) {
2239171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate                doListTransports();
224ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            }
225ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
226ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            mRestore.endRestoreSession();
227ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        } catch (RemoteException e) {
228ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            System.err.println(e.toString());
229ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            System.err.println(BMGR_NOT_RUNNING_ERR);
230ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        }
231ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    }
232ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
233ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    private void doListTransports() {
2349171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        try {
2359171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate            String current = mBmgr.getCurrentTransport();
2369171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate            String[] transports = mBmgr.listAllTransports();
2379171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate            if (transports == null || transports.length == 0) {
2389171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate                System.out.println("No transports available.");
2399171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate                return;
2409171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate            }
2419171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate
2429171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate            for (String t : transports) {
2439171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate                String pad = (t.equals(current)) ? "  * " : "    ";
2449171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate                System.out.println(pad + t);
2459171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate            }
2469171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        } catch (RemoteException e) {
2479171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate            System.err.println(e.toString());
2489171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate            System.err.println(BMGR_NOT_RUNNING_ERR);
2499171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        }
250ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    }
251ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
252ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    private void doListRestoreSets() {
253ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        try {
2542d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate            RestoreObserver observer = new RestoreObserver();
2552d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate            int err = mRestore.getAvailableRestoreSets(observer);
2562d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate            if (err != 0) {
2572d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate                System.out.println("Unable to request restore sets");
258ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            } else {
2592d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate                observer.waitForCompletion();
2602d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate                printRestoreSets(observer.sets);
261ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            }
262ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        } catch (RemoteException e) {
263ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            System.err.println(e.toString());
264ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            System.err.println(TRANSPORT_NOT_RUNNING_ERR);
265ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        }
266ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    }
267ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
268c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate    private void printRestoreSets(RestoreSet[] sets) {
26904686f428995fde3f6f5f5f12ccdd135f885ac84Fabrice Di Meglio        if (sets == null || sets.length == 0) {
27004686f428995fde3f6f5f5f12ccdd135f885ac84Fabrice Di Meglio            System.out.println("No restore sets");
27104686f428995fde3f6f5f5f12ccdd135f885ac84Fabrice Di Meglio            return;
27204686f428995fde3f6f5f5f12ccdd135f885ac84Fabrice Di Meglio        }
273c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate        for (RestoreSet s : sets) {
27477095d49f203eed6a6742f2605ca319e7360af32Christian Sonntag            System.out.println("  " + Long.toHexString(s.token) + " : " + s.name);
275c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate        }
276c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate    }
277c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate
2784a64bded06a0299785c295a975e2818308eb53e2Joe Onorato    class RestoreObserver extends IRestoreObserver.Stub {
2794a64bded06a0299785c295a975e2818308eb53e2Joe Onorato        boolean done;
2802d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate        RestoreSet[] sets = null;
2812d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate
2822d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate        public void restoreSetsAvailable(RestoreSet[] result) {
2832d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate            synchronized (this) {
2842d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate                sets = result;
2852d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate                done = true;
2862d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate                this.notify();
2872d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate            }
2882d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate        }
2892d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate
2904a64bded06a0299785c295a975e2818308eb53e2Joe Onorato        public void restoreStarting(int numPackages) {
2914a64bded06a0299785c295a975e2818308eb53e2Joe Onorato            System.out.println("restoreStarting: " + numPackages + " packages");
2924a64bded06a0299785c295a975e2818308eb53e2Joe Onorato        }
2934a64bded06a0299785c295a975e2818308eb53e2Joe Onorato
2949c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate        public void onUpdate(int nowBeingRestored, String currentPackage) {
2959c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate            System.out.println("onUpdate: " + nowBeingRestored + " = " + currentPackage);
2964a64bded06a0299785c295a975e2818308eb53e2Joe Onorato        }
2974a64bded06a0299785c295a975e2818308eb53e2Joe Onorato
2984a64bded06a0299785c295a975e2818308eb53e2Joe Onorato        public void restoreFinished(int error) {
2994a64bded06a0299785c295a975e2818308eb53e2Joe Onorato            System.out.println("restoreFinished: " + error);
3004a64bded06a0299785c295a975e2818308eb53e2Joe Onorato            synchronized (this) {
3014a64bded06a0299785c295a975e2818308eb53e2Joe Onorato                done = true;
3024a64bded06a0299785c295a975e2818308eb53e2Joe Onorato                this.notify();
3034a64bded06a0299785c295a975e2818308eb53e2Joe Onorato            }
3044a64bded06a0299785c295a975e2818308eb53e2Joe Onorato        }
3057d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate
3067d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate        public void waitForCompletion() {
3077d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            // The restoreFinished() callback will throw the 'done' flag; we
3087d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            // just sit and wait on that notification.
3097d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            synchronized (this) {
3107d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate                while (!this.done) {
3117d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate                    try {
3127d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate                        this.wait();
3137d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate                    } catch (InterruptedException ex) {
3147d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate                    }
3157d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate                }
3167d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            }
3177d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate        }
3184a64bded06a0299785c295a975e2818308eb53e2Joe Onorato    }
3194a64bded06a0299785c295a975e2818308eb53e2Joe Onorato
320f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate    private void doRestore() {
3217d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate        String arg = nextArg();
3227e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate        if (arg == null) {
3237e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate            showUsage();
3247e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate            return;
3257e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate        }
3267e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate
3277d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate        if (arg.indexOf('.') >= 0) {
3287d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            // it's a package name
3297d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            doRestorePackage(arg);
3307d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate        } else {
3317d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            try {
332485c3a16cef38136a821e79a5fe37df4e1779d28Christian Sonntag                long token = Long.parseLong(arg, 16);
333284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate                HashSet<String> filter = null;
334284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate                while ((arg = nextArg()) != null) {
335284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate                    if (filter == null) filter = new HashSet<String>();
336284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate                    filter.add(arg);
337284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate                }
338284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate
339284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate                doRestoreAll(token, filter);
3407d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            } catch (NumberFormatException e) {
3417d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate                showUsage();
3427d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate                return;
3437d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            }
3447d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate        }
3457d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate
3467d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate        System.out.println("done");
3477d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate    }
3487d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate
3497d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate    private void doRestorePackage(String pkg) {
350f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate        try {
35144ab8453e1c4c46790f792a46d026fa1017d8cfeChris Tate            mRestore = mBmgr.beginRestoreSession(pkg, null);
3527d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            if (mRestore == null) {
3537d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate                System.err.println(BMGR_NOT_RUNNING_ERR);
3547d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate                return;
3557d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            }
3567d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate
3577d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            RestoreObserver observer = new RestoreObserver();
3587d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            int err = mRestore.restorePackage(pkg, observer);
3597d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            if (err == 0) {
3607d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate                // Off and running -- wait for the restore to complete
3617d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate                observer.waitForCompletion();
3627d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            } else {
3637d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate                System.err.println("Unable to restore package " + pkg);
3647d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            }
3657d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate
3667d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            // And finally shut down the session
3677d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            mRestore.endRestoreSession();
3687d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate        } catch (RemoteException e) {
3697d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            System.err.println(e.toString());
3707d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate            System.err.println(BMGR_NOT_RUNNING_ERR);
371f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate        }
3727d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate    }
373f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate
374284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate    private void doRestoreAll(long token, HashSet<String> filter) {
3754a64bded06a0299785c295a975e2818308eb53e2Joe Onorato        RestoreObserver observer = new RestoreObserver();
3764a64bded06a0299785c295a975e2818308eb53e2Joe Onorato
377f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate        try {
378c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate            boolean didRestore = false;
37944ab8453e1c4c46790f792a46d026fa1017d8cfeChris Tate            mRestore = mBmgr.beginRestoreSession(null, null);
380f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate            if (mRestore == null) {
381f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate                System.err.println(BMGR_NOT_RUNNING_ERR);
382f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate                return;
383f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate            }
3842d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate            RestoreSet[] sets = null;
3852d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate            int err = mRestore.getAvailableRestoreSets(observer);
3861398e27bb0f5768cbbd5b9d9fd7c8675da63ccb0Christopher Tate            if (err == 0) {
3872d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate                observer.waitForCompletion();
3882d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate                sets = observer.sets;
3897a0fc8776782a18374ec6e3b4418027c3c685b1aChris Tate                if (sets != null) {
3907a0fc8776782a18374ec6e3b4418027c3c685b1aChris Tate                    for (RestoreSet s : sets) {
3917a0fc8776782a18374ec6e3b4418027c3c685b1aChris Tate                        if (s.token == token) {
3927a0fc8776782a18374ec6e3b4418027c3c685b1aChris Tate                            System.out.println("Scheduling restore: " + s.name);
393284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate                            if (filter == null) {
394284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate                                didRestore = (mRestore.restoreAll(token, observer) == 0);
395284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate                            } else {
396284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate                                String[] names = new String[filter.size()];
397284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate                                filter.toArray(names);
398284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate                                didRestore = (mRestore.restoreSome(token, observer, names) == 0);
399284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate                            }
4007a0fc8776782a18374ec6e3b4418027c3c685b1aChris Tate                            break;
4017a0fc8776782a18374ec6e3b4418027c3c685b1aChris Tate                        }
40284780f56f441deb4ff736987986daeaf64db17a4Christopher Tate                    }
403f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate                }
404f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate            }
405c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate            if (!didRestore) {
406c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate                if (sets == null || sets.length == 0) {
407c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate                    System.out.println("No available restore sets; no restore performed");
408c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate                } else {
409c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate                    System.out.println("No matching restore set token.  Available sets:");
410c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate                    printRestoreSets(sets);
411c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate                }
412c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate            }
41308e40b858e8a3266c5519a83fda6f7505f1c14dbChristopher Tate
4140e0b4ae5bc5c652c8339d71ed9667e1e37baaa03Christopher Tate            // if we kicked off a restore successfully, we have to wait for it
4150e0b4ae5bc5c652c8339d71ed9667e1e37baaa03Christopher Tate            // to complete before we can shut down the restore session safely
4160e0b4ae5bc5c652c8339d71ed9667e1e37baaa03Christopher Tate            if (didRestore) {
4177d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate                observer.waitForCompletion();
41808e40b858e8a3266c5519a83fda6f7505f1c14dbChristopher Tate            }
41908e40b858e8a3266c5519a83fda6f7505f1c14dbChristopher Tate
42008e40b858e8a3266c5519a83fda6f7505f1c14dbChristopher Tate            // once the restore has finished, close down the session and we're done
421f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate            mRestore.endRestoreSession();
422f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate        } catch (RemoteException e) {
423f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate            System.err.println(e.toString());
424f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate            System.err.println(BMGR_NOT_RUNNING_ERR);
425f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate        }
426f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate    }
427f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate
428ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    private String nextArg() {
429ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        if (mNextArg >= mArgs.length) {
430ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate            return null;
431ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        }
432ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        String arg = mArgs[mNextArg];
433ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        mNextArg++;
434ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        return arg;
435ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    }
436ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
437ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    private static void showUsage() {
438ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        System.err.println("usage: bmgr [backup|restore|list|transport|run]");
4399171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("       bmgr backup PACKAGE");
4406ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        System.err.println("       bmgr enable BOOL");
4416ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        System.err.println("       bmgr enabled");
4429171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("       bmgr list transports");
443ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        System.err.println("       bmgr list sets");
4449171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("       bmgr transport WHICH");
4459171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("       bmgr restore TOKEN");
446284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate        System.err.println("       bmgr restore TOKEN PACKAGE...");
4477d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate        System.err.println("       bmgr restore PACKAGE");
448ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate        System.err.println("       bmgr run");
449d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate        System.err.println("       bmgr wipe PACKAGE");
4509171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("");
4519171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("The 'backup' command schedules a backup pass for the named package.");
4529171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("Note that the backup pass will effectively be a no-op if the package");
4539171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("does not actually have changed data to store.");
4549171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("");
4556ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        System.err.println("The 'enable' command enables or disables the entire backup mechanism.");
4566ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        System.err.println("If the argument is 'true' it will be enabled, otherwise it will be");
4576ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        System.err.println("disabled.  When disabled, neither backup or restore operations will");
4586ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        System.err.println("be performed.");
4596ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        System.err.println("");
4606ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        System.err.println("The 'enabled' command reports the current enabled/disabled state of");
4616ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        System.err.println("the backup mechanism.");
4626ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate        System.err.println("");
4639171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("The 'list transports' command reports the names of the backup transports");
4649171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("currently available on the device.  These names can be passed as arguments");
4659171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("to the 'transport' command.  The currently selected transport is indicated");
4669171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("with a '*' character.");
4679171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("");
4689171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("The 'list sets' command reports the token and name of each restore set");
4699171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("available to the device via the current transport.");
4709171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("");
4719171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("The 'transport' command designates the named transport as the currently");
4729171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("active one.  This setting is persistent across reboots.");
4739171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("");
474284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate        System.err.println("The 'restore' command when given just a restore token initiates a full-system");
4757d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate        System.err.println("restore operation from the currently active transport.  It will deliver");
4767d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate        System.err.println("the restore set designated by the TOKEN argument to each application");
4777d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate        System.err.println("that had contributed data to that restore set.");
4787d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate        System.err.println("");
479284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate        System.err.println("The 'restore' command when given a token and one or more package names");
480284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate        System.err.println("initiates a restore operation of just those given packages from the restore");
481284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate        System.err.println("set designated by the TOKEN argument.  It is effectively the same as the");
482284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate        System.err.println("'restore' operation supplying only a token, but applies a filter to the");
483284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate        System.err.println("set of applications to be restored.");
484284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate        System.err.println("");
485284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate        System.err.println("The 'restore' command when given just a package name intiates a restore of");
4867d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate        System.err.println("just that one package according to the restore set selection algorithm");
4877d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate        System.err.println("used by the RestoreSession.restorePackage() method.");
4889171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("");
4899171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("The 'run' command causes any scheduled backup operation to be initiated");
4909171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("immediately, without the usual waiting period for batching together");
4919171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate        System.err.println("data changes.");
492d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate        System.err.println("");
493d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate        System.err.println("The 'wipe' command causes all backed-up data for the given package to be");
494d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate        System.err.println("erased from the current transport's storage.  The next backup operation");
495d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate        System.err.println("that the given application performs will rewrite its entire data set.");
496ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    }
4975e8a4b842c20dd47b82e9915f1bd730ee1b0d46dJoe Onorato}
498