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 269ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tateimport java.util.ArrayList; 27284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tateimport java.util.HashSet; 28284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate 29ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tatepublic final class Bmgr { 30ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate IBackupManager mBmgr; 31ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate IRestoreSession mRestore; 32ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 33ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate static final String BMGR_NOT_RUNNING_ERR = 34ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate "Error: Could not access the Backup Manager. Is the system running?"; 35ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate static final String TRANSPORT_NOT_RUNNING_ERR = 36ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate "Error: Could not access the backup transport. Is the system running?"; 37ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 38ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate private String[] mArgs; 39ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate private int mNextArg; 40ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 41ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate public static void main(String[] args) { 42f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate try { 43f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate new Bmgr().run(args); 44f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate } catch (Exception e) { 45f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate System.err.println("Exception caught:"); 46f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate e.printStackTrace(); 47f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate } 48ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 49f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate 50ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate public void run(String[] args) { 51ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate if (args.length < 1) { 52ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate showUsage(); 53ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate return; 54ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 55ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 56ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate mBmgr = IBackupManager.Stub.asInterface(ServiceManager.getService("backup")); 57ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate if (mBmgr == null) { 58ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate System.err.println(BMGR_NOT_RUNNING_ERR); 59ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate return; 60ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 61ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 62ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate mArgs = args; 63ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate String op = args[0]; 64ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate mNextArg = 1; 65ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 666ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate if ("enabled".equals(op)) { 676ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate doEnabled(); 686ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate return; 696ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate } 706ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate 716ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate if ("enable".equals(op)) { 726ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate doEnable(); 736ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate return; 746ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate } 756ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate 76ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate if ("run".equals(op)) { 77ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate doRun(); 78ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate return; 79ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 80ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 81ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate if ("backup".equals(op)) { 82ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate doBackup(); 83ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate return; 84ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 85ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 86ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate if ("list".equals(op)) { 87ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate doList(); 88ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate return; 89ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 90f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate 91f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate if ("restore".equals(op)) { 92f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate doRestore(); 93f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate return; 94f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate } 95abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate 96abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate if ("transport".equals(op)) { 97abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate doTransport(); 98abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate return; 99abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate } 100abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate 101d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate if ("wipe".equals(op)) { 102d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate doWipe(); 103d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate return; 104d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate } 105d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate 1069ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate if ("fullbackup".equals(op)) { 1079ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate doFullTransportBackup(); 1089ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate return; 1099ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate } 1109ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate 111abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate System.err.println("Unknown command"); 112abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate showUsage(); 113ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 114ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 1156ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate private String enableToString(boolean enabled) { 1166ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate return enabled ? "enabled" : "disabled"; 1176ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate } 1186ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate 1196ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate private void doEnabled() { 1206ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate try { 1216ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate boolean isEnabled = mBmgr.isBackupEnabled(); 1226ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate System.out.println("Backup Manager currently " 1236ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate + enableToString(isEnabled)); 1246ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate } catch (RemoteException e) { 1256ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate System.err.println(e.toString()); 1266ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate System.err.println(BMGR_NOT_RUNNING_ERR); 1276ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate } 1286ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate } 1296ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate 1306ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate private void doEnable() { 1316ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate String arg = nextArg(); 1326ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate if (arg == null) { 1336ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate showUsage(); 1346ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate return; 1356ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate } 1366ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate 1376ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate try { 1386ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate boolean enable = Boolean.parseBoolean(arg); 1396ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate mBmgr.setBackupEnabled(enable); 1406ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate System.out.println("Backup Manager now " + enableToString(enable)); 1416ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate } catch (NumberFormatException e) { 1426ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate showUsage(); 1436ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate return; 1446ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate } catch (RemoteException e) { 1456ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate System.err.println(e.toString()); 1466ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate System.err.println(BMGR_NOT_RUNNING_ERR); 1476ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate } 1486ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate } 1496ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate 150ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate private void doRun() { 151ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate try { 152ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate mBmgr.backupNow(); 153ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } catch (RemoteException e) { 154ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate System.err.println(e.toString()); 155ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate System.err.println(BMGR_NOT_RUNNING_ERR); 156ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 157ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 158ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 159ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate private void doBackup() { 160ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate String pkg = nextArg(); 1614a627c71ff53a4fca1f961f4b1dcc0461df18a06Christopher Tate if (pkg == null) { 162ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate showUsage(); 163ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate return; 164ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 165ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 166ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate try { 167ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate mBmgr.dataChanged(pkg); 168ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } catch (RemoteException e) { 169ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate System.err.println(e.toString()); 170ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate System.err.println(BMGR_NOT_RUNNING_ERR); 171ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 172ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 173ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 1749ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate private void doFullTransportBackup() { 1759ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate System.out.println("Performing full transport backup"); 1769ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate 1779ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate String pkg; 178ab225b301b8b13a141053a33d5dd5eeccfc69887Christopher Tate ArrayList<String> allPkgs = new ArrayList<String>(); 1799ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate while ((pkg = nextArg()) != null) { 180ab225b301b8b13a141053a33d5dd5eeccfc69887Christopher Tate allPkgs.add(pkg); 181ab225b301b8b13a141053a33d5dd5eeccfc69887Christopher Tate } 182ab225b301b8b13a141053a33d5dd5eeccfc69887Christopher Tate if (allPkgs.size() > 0) { 1839ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate try { 184ab225b301b8b13a141053a33d5dd5eeccfc69887Christopher Tate mBmgr.fullTransportBackup(allPkgs.toArray(new String[allPkgs.size()])); 1859ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate } catch (RemoteException e) { 1869ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate System.err.println(e.toString()); 1879ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate System.err.println(BMGR_NOT_RUNNING_ERR); 1889ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate } 1899ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate } 1909ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate } 1919ff53a7100b1a40f5d2df3eb19a2f3f2fff39a46Christopher Tate 192abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate private void doTransport() { 193abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate try { 1949171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate String which = nextArg(); 1957e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate if (which == null) { 1967e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate showUsage(); 1977e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate return; 1987e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate } 1997e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate 2009171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate String old = mBmgr.selectBackupTransport(which); 2019171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate if (old == null) { 2029171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.out.println("Unknown transport '" + which 2039171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate + "' specified; no changes made."); 2049171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate } else { 2059171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.out.println("Selected transport " + which + " (formerly " + old + ")"); 2069171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate } 207abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate } catch (RemoteException e) { 208abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate System.err.println(e.toString()); 209abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate System.err.println(BMGR_NOT_RUNNING_ERR); 210abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate } 211abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate } 212abce4e8714bed26a2b37b20ad3f02cf619d71c9aChristopher Tate 213d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate private void doWipe() { 214b0183f0ae311966cff0e10e8139c56f97288d1f2Christopher Tate String transport = nextArg(); 215b0183f0ae311966cff0e10e8139c56f97288d1f2Christopher Tate if (transport == null) { 216b0183f0ae311966cff0e10e8139c56f97288d1f2Christopher Tate showUsage(); 217b0183f0ae311966cff0e10e8139c56f97288d1f2Christopher Tate return; 218b0183f0ae311966cff0e10e8139c56f97288d1f2Christopher Tate } 219b0183f0ae311966cff0e10e8139c56f97288d1f2Christopher Tate 220d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate String pkg = nextArg(); 221d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate if (pkg == null) { 222d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate showUsage(); 223d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate return; 224d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate } 225d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate 226d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate try { 227b0183f0ae311966cff0e10e8139c56f97288d1f2Christopher Tate mBmgr.clearBackupData(transport, pkg); 228b0183f0ae311966cff0e10e8139c56f97288d1f2Christopher Tate System.out.println("Wiped backup data for " + pkg + " on " + transport); 229d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate } catch (RemoteException e) { 230d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate System.err.println(e.toString()); 231d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate System.err.println(BMGR_NOT_RUNNING_ERR); 232d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate } 233d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate } 234d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate 235ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate private void doList() { 236ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate String arg = nextArg(); // sets, transports, packages set# 237ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate if ("transports".equals(arg)) { 238ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate doListTransports(); 239ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate return; 240ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 241ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 242ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate // The rest of the 'list' options work with a restore session on the current transport 243ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate try { 24444ab8453e1c4c46790f792a46d026fa1017d8cfeChris Tate mRestore = mBmgr.beginRestoreSession(null, null); 245f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate if (mRestore == null) { 246f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate System.err.println(BMGR_NOT_RUNNING_ERR); 247f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate return; 248f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate } 249ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 250ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate if ("sets".equals(arg)) { 251ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate doListRestoreSets(); 2529171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate } else if ("transports".equals(arg)) { 2539171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate doListTransports(); 254ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 255ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 256ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate mRestore.endRestoreSession(); 257ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } catch (RemoteException e) { 258ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate System.err.println(e.toString()); 259ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate System.err.println(BMGR_NOT_RUNNING_ERR); 260ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 261ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 262ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 263ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate private void doListTransports() { 2649171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate try { 2659171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate String current = mBmgr.getCurrentTransport(); 2669171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate String[] transports = mBmgr.listAllTransports(); 2679171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate if (transports == null || transports.length == 0) { 2689171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.out.println("No transports available."); 2699171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate return; 2709171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate } 2719171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate 2729171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate for (String t : transports) { 2739171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate String pad = (t.equals(current)) ? " * " : " "; 2749171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.out.println(pad + t); 2759171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate } 2769171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate } catch (RemoteException e) { 2779171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println(e.toString()); 2789171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println(BMGR_NOT_RUNNING_ERR); 2799171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate } 280ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 281ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 282ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate private void doListRestoreSets() { 283ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate try { 2842d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate RestoreObserver observer = new RestoreObserver(); 2852d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate int err = mRestore.getAvailableRestoreSets(observer); 2862d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate if (err != 0) { 2872d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate System.out.println("Unable to request restore sets"); 288ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } else { 2892d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate observer.waitForCompletion(); 2902d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate printRestoreSets(observer.sets); 291ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 292ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } catch (RemoteException e) { 293ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate System.err.println(e.toString()); 294ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate System.err.println(TRANSPORT_NOT_RUNNING_ERR); 295ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 296ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 297ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 298c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate private void printRestoreSets(RestoreSet[] sets) { 29904686f428995fde3f6f5f5f12ccdd135f885ac84Fabrice Di Meglio if (sets == null || sets.length == 0) { 30004686f428995fde3f6f5f5f12ccdd135f885ac84Fabrice Di Meglio System.out.println("No restore sets"); 30104686f428995fde3f6f5f5f12ccdd135f885ac84Fabrice Di Meglio return; 30204686f428995fde3f6f5f5f12ccdd135f885ac84Fabrice Di Meglio } 303c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate for (RestoreSet s : sets) { 30477095d49f203eed6a6742f2605ca319e7360af32Christian Sonntag System.out.println(" " + Long.toHexString(s.token) + " : " + s.name); 305c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate } 306c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate } 307c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate 3084a64bded06a0299785c295a975e2818308eb53e2Joe Onorato class RestoreObserver extends IRestoreObserver.Stub { 3094a64bded06a0299785c295a975e2818308eb53e2Joe Onorato boolean done; 3102d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate RestoreSet[] sets = null; 3112d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate 3122d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate public void restoreSetsAvailable(RestoreSet[] result) { 3132d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate synchronized (this) { 3142d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate sets = result; 3152d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate done = true; 3162d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate this.notify(); 3172d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate } 3182d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate } 3192d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate 3204a64bded06a0299785c295a975e2818308eb53e2Joe Onorato public void restoreStarting(int numPackages) { 3214a64bded06a0299785c295a975e2818308eb53e2Joe Onorato System.out.println("restoreStarting: " + numPackages + " packages"); 3224a64bded06a0299785c295a975e2818308eb53e2Joe Onorato } 3234a64bded06a0299785c295a975e2818308eb53e2Joe Onorato 3249c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate public void onUpdate(int nowBeingRestored, String currentPackage) { 3259c3cee9824026764275e4d84ba9b5d9fdc5da690Christopher Tate System.out.println("onUpdate: " + nowBeingRestored + " = " + currentPackage); 3264a64bded06a0299785c295a975e2818308eb53e2Joe Onorato } 3274a64bded06a0299785c295a975e2818308eb53e2Joe Onorato 3284a64bded06a0299785c295a975e2818308eb53e2Joe Onorato public void restoreFinished(int error) { 3294a64bded06a0299785c295a975e2818308eb53e2Joe Onorato System.out.println("restoreFinished: " + error); 3304a64bded06a0299785c295a975e2818308eb53e2Joe Onorato synchronized (this) { 3314a64bded06a0299785c295a975e2818308eb53e2Joe Onorato done = true; 3324a64bded06a0299785c295a975e2818308eb53e2Joe Onorato this.notify(); 3334a64bded06a0299785c295a975e2818308eb53e2Joe Onorato } 3344a64bded06a0299785c295a975e2818308eb53e2Joe Onorato } 3357d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate 3367d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate public void waitForCompletion() { 3377d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate // The restoreFinished() callback will throw the 'done' flag; we 3387d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate // just sit and wait on that notification. 3397d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate synchronized (this) { 3407d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate while (!this.done) { 3417d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate try { 3427d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate this.wait(); 3437d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate } catch (InterruptedException ex) { 3447d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate } 3457d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate } 3467d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate } 3477d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate } 3484a64bded06a0299785c295a975e2818308eb53e2Joe Onorato } 3494a64bded06a0299785c295a975e2818308eb53e2Joe Onorato 350f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate private void doRestore() { 3517d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate String arg = nextArg(); 3527e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate if (arg == null) { 3537e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate showUsage(); 3547e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate return; 3557e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate } 3567e76ff1c409bc22e89ed09ef90161164dae40838Christopher Tate 357fbec21ff43c8a35e95fca9ce40351350608974e9Christopher Tate if (arg.indexOf('.') >= 0 || arg.equals("android")) { 3587d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate // it's a package name 3597d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate doRestorePackage(arg); 3607d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate } else { 3617d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate try { 362485c3a16cef38136a821e79a5fe37df4e1779d28Christian Sonntag long token = Long.parseLong(arg, 16); 363284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate HashSet<String> filter = null; 364284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate while ((arg = nextArg()) != null) { 365284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate if (filter == null) filter = new HashSet<String>(); 366284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate filter.add(arg); 367284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate } 368284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate 369284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate doRestoreAll(token, filter); 3707d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate } catch (NumberFormatException e) { 3717d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate showUsage(); 3727d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate return; 3737d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate } 3747d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate } 3757d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate 3767d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate System.out.println("done"); 3777d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate } 3787d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate 3797d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate private void doRestorePackage(String pkg) { 380f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate try { 38144ab8453e1c4c46790f792a46d026fa1017d8cfeChris Tate mRestore = mBmgr.beginRestoreSession(pkg, null); 3827d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate if (mRestore == null) { 3837d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate System.err.println(BMGR_NOT_RUNNING_ERR); 3847d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate return; 3857d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate } 3867d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate 3877d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate RestoreObserver observer = new RestoreObserver(); 3887d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate int err = mRestore.restorePackage(pkg, observer); 3897d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate if (err == 0) { 3907d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate // Off and running -- wait for the restore to complete 3917d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate observer.waitForCompletion(); 3927d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate } else { 3937d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate System.err.println("Unable to restore package " + pkg); 3947d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate } 3957d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate 3967d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate // And finally shut down the session 3977d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate mRestore.endRestoreSession(); 3987d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate } catch (RemoteException e) { 3997d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate System.err.println(e.toString()); 4007d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate System.err.println(BMGR_NOT_RUNNING_ERR); 401f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate } 4027d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate } 403f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate 404284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate private void doRestoreAll(long token, HashSet<String> filter) { 4054a64bded06a0299785c295a975e2818308eb53e2Joe Onorato RestoreObserver observer = new RestoreObserver(); 4064a64bded06a0299785c295a975e2818308eb53e2Joe Onorato 407f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate try { 408c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate boolean didRestore = false; 40944ab8453e1c4c46790f792a46d026fa1017d8cfeChris Tate mRestore = mBmgr.beginRestoreSession(null, null); 410f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate if (mRestore == null) { 411f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate System.err.println(BMGR_NOT_RUNNING_ERR); 412f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate return; 413f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate } 4142d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate RestoreSet[] sets = null; 4152d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate int err = mRestore.getAvailableRestoreSets(observer); 4161398e27bb0f5768cbbd5b9d9fd7c8675da63ccb0Christopher Tate if (err == 0) { 4172d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate observer.waitForCompletion(); 4182d449afe3d075020bdd1115bcc15c9383cbce122Christopher Tate sets = observer.sets; 4197a0fc8776782a18374ec6e3b4418027c3c685b1aChris Tate if (sets != null) { 4207a0fc8776782a18374ec6e3b4418027c3c685b1aChris Tate for (RestoreSet s : sets) { 4217a0fc8776782a18374ec6e3b4418027c3c685b1aChris Tate if (s.token == token) { 4227a0fc8776782a18374ec6e3b4418027c3c685b1aChris Tate System.out.println("Scheduling restore: " + s.name); 423284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate if (filter == null) { 424284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate didRestore = (mRestore.restoreAll(token, observer) == 0); 425284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate } else { 426284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate String[] names = new String[filter.size()]; 427284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate filter.toArray(names); 428284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate didRestore = (mRestore.restoreSome(token, observer, names) == 0); 429284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate } 4307a0fc8776782a18374ec6e3b4418027c3c685b1aChris Tate break; 4317a0fc8776782a18374ec6e3b4418027c3c685b1aChris Tate } 43284780f56f441deb4ff736987986daeaf64db17a4Christopher Tate } 433f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate } 434f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate } 435c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate if (!didRestore) { 436c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate if (sets == null || sets.length == 0) { 437c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate System.out.println("No available restore sets; no restore performed"); 438c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate } else { 439c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate System.out.println("No matching restore set token. Available sets:"); 440c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate printRestoreSets(sets); 441c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate } 442c73a218c2663e6ae3ec8a9ab8b9524f95702ade9Christopher Tate } 44308e40b858e8a3266c5519a83fda6f7505f1c14dbChristopher Tate 4440e0b4ae5bc5c652c8339d71ed9667e1e37baaa03Christopher Tate // if we kicked off a restore successfully, we have to wait for it 4450e0b4ae5bc5c652c8339d71ed9667e1e37baaa03Christopher Tate // to complete before we can shut down the restore session safely 4460e0b4ae5bc5c652c8339d71ed9667e1e37baaa03Christopher Tate if (didRestore) { 4477d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate observer.waitForCompletion(); 44808e40b858e8a3266c5519a83fda6f7505f1c14dbChristopher Tate } 44908e40b858e8a3266c5519a83fda6f7505f1c14dbChristopher Tate 45008e40b858e8a3266c5519a83fda6f7505f1c14dbChristopher Tate // once the restore has finished, close down the session and we're done 451f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate mRestore.endRestoreSession(); 452f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate } catch (RemoteException e) { 453f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate System.err.println(e.toString()); 454f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate System.err.println(BMGR_NOT_RUNNING_ERR); 455f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate } 456f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate } 457f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate 458ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate private String nextArg() { 459ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate if (mNextArg >= mArgs.length) { 460ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate return null; 461ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 462ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate String arg = mArgs[mNextArg]; 463ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate mNextArg++; 464ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate return arg; 465ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 466ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate 467ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate private static void showUsage() { 468ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate System.err.println("usage: bmgr [backup|restore|list|transport|run]"); 4699171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println(" bmgr backup PACKAGE"); 4706ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate System.err.println(" bmgr enable BOOL"); 4716ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate System.err.println(" bmgr enabled"); 4729171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println(" bmgr list transports"); 473ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate System.err.println(" bmgr list sets"); 4749171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println(" bmgr transport WHICH"); 4759171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println(" bmgr restore TOKEN"); 476284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate System.err.println(" bmgr restore TOKEN PACKAGE..."); 4777d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate System.err.println(" bmgr restore PACKAGE"); 478ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate System.err.println(" bmgr run"); 479b0183f0ae311966cff0e10e8139c56f97288d1f2Christopher Tate System.err.println(" bmgr wipe TRANSPORT PACKAGE"); 480ab225b301b8b13a141053a33d5dd5eeccfc69887Christopher Tate System.err.println(" bmgr fullbackup PACKAGE..."); 4819171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println(""); 4829171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println("The 'backup' command schedules a backup pass for the named package."); 4839171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println("Note that the backup pass will effectively be a no-op if the package"); 4849171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println("does not actually have changed data to store."); 4859171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println(""); 4866ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate System.err.println("The 'enable' command enables or disables the entire backup mechanism."); 4876ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate System.err.println("If the argument is 'true' it will be enabled, otherwise it will be"); 4886ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate System.err.println("disabled. When disabled, neither backup or restore operations will"); 4896ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate System.err.println("be performed."); 4906ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate System.err.println(""); 4916ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate System.err.println("The 'enabled' command reports the current enabled/disabled state of"); 4926ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate System.err.println("the backup mechanism."); 4936ef58a1509b9d3348a33ca5686917796c2759aa5Christopher Tate System.err.println(""); 4949171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println("The 'list transports' command reports the names of the backup transports"); 4959171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println("currently available on the device. These names can be passed as arguments"); 496ab225b301b8b13a141053a33d5dd5eeccfc69887Christopher Tate System.err.println("to the 'transport' and 'wipe' commands. The currently active transport"); 497b0183f0ae311966cff0e10e8139c56f97288d1f2Christopher Tate System.err.println("is indicated with a '*' character."); 4989171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println(""); 4999171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println("The 'list sets' command reports the token and name of each restore set"); 500ab225b301b8b13a141053a33d5dd5eeccfc69887Christopher Tate System.err.println("available to the device via the currently active transport."); 5019171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println(""); 5029171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println("The 'transport' command designates the named transport as the currently"); 5039171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println("active one. This setting is persistent across reboots."); 5049171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println(""); 505284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate System.err.println("The 'restore' command when given just a restore token initiates a full-system"); 5067d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate System.err.println("restore operation from the currently active transport. It will deliver"); 5077d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate System.err.println("the restore set designated by the TOKEN argument to each application"); 5087d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate System.err.println("that had contributed data to that restore set."); 5097d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate System.err.println(""); 510284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate System.err.println("The 'restore' command when given a token and one or more package names"); 511284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate System.err.println("initiates a restore operation of just those given packages from the restore"); 512284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate System.err.println("set designated by the TOKEN argument. It is effectively the same as the"); 513284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate System.err.println("'restore' operation supplying only a token, but applies a filter to the"); 514284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate System.err.println("set of applications to be restored."); 515284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate System.err.println(""); 516284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate System.err.println("The 'restore' command when given just a package name intiates a restore of"); 5177d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate System.err.println("just that one package according to the restore set selection algorithm"); 5187d411a3b947ba82d1d57f73c0fa698c3b9c95892Christopher Tate System.err.println("used by the RestoreSession.restorePackage() method."); 5199171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println(""); 5209171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println("The 'run' command causes any scheduled backup operation to be initiated"); 5219171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println("immediately, without the usual waiting period for batching together"); 5229171749700853305f3e6abbcdbd9e02f3a71d459Christopher Tate System.err.println("data changes."); 523d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate System.err.println(""); 524d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate System.err.println("The 'wipe' command causes all backed-up data for the given package to be"); 525b0183f0ae311966cff0e10e8139c56f97288d1f2Christopher Tate System.err.println("erased from the given transport's storage. The next backup operation"); 526d23d7f2d12c20314e1e8ff206fafc8f21745ca2dChristopher Tate System.err.println("that the given application performs will rewrite its entire data set."); 527b0183f0ae311966cff0e10e8139c56f97288d1f2Christopher Tate System.err.println("Transport names to use here are those reported by 'list transports'."); 528ab225b301b8b13a141053a33d5dd5eeccfc69887Christopher Tate System.err.println(""); 529ab225b301b8b13a141053a33d5dd5eeccfc69887Christopher Tate System.err.println("The 'fullbackup' command induces a full-data stream backup for one or more"); 530ab225b301b8b13a141053a33d5dd5eeccfc69887Christopher Tate System.err.println("packages. The data is sent via the currently active transport."); 531ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate } 5325e8a4b842c20dd47b82e9915f1bd730ee1b0d46dJoe Onorato} 533