diff options
author | Shreyas Basarge <snb@google.com> | 2017-01-13 14:48:56 +0000 |
---|---|---|
committer | Shreyas Basarge <snb@google.com> | 2017-01-24 17:28:48 +0000 |
commit | 865303fce57b968f5bd7efb4dd23ccb1a3747b93 (patch) | |
tree | d4fac32c678adc66ce81fc77c252a41b00107f5f /cmds/bmgr | |
parent | 1628b97e54d7f56352d7f3ad9c6b4166d56082a5 (diff) |
API to select backup transport
This cl adds an API to select a backup
transport by its component name and
receive a callback when BackupManager
is bound to the transport. Calling this API
will make BackupManager bind to the transport
if it isn't already bound to it.
Also fixes the issue where BackupManager would
detect only one transport per package.
Ref: go/backup-transport-switching
Bug: 33616220
Test: Manually tested. GTS tests will be put up shortly.
Change-Id: I8c23bdbb84ceb05eb1fad9b3a8b9c4441cb06c74
Diffstat (limited to 'cmds/bmgr')
-rw-r--r-- | cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java | 71 |
1 files changed, 65 insertions, 6 deletions
diff --git a/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java b/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java index 780db5e26c35..7e913913dfae 100644 --- a/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java +++ b/cmds/bmgr/src/com/android/commands/bmgr/Bmgr.java @@ -18,20 +18,24 @@ package com.android.commands.bmgr; import android.app.backup.BackupManager; import android.app.backup.BackupProgress; -import android.app.backup.RestoreSet; import android.app.backup.IBackupManager; import android.app.backup.IBackupObserver; import android.app.backup.IRestoreObserver; import android.app.backup.IRestoreSession; +import android.app.backup.RestoreSet; +import android.app.backup.ISelectBackupTransportCallback; +import android.content.ComponentName; import android.content.pm.IPackageManager; import android.content.pm.PackageInfo; import android.os.RemoteException; import android.os.ServiceManager; import android.os.UserHandle; +import android.util.Log; import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.concurrent.CountDownLatch; public final class Bmgr { IBackupManager mBmgr; @@ -363,6 +367,11 @@ public final class Bmgr { return; } + if ("-c".equals(which)) { + doTransportByComponent(); + return; + } + String old = mBmgr.selectBackupTransport(which); if (old == null) { System.out.println("Unknown transport '" + which @@ -370,12 +379,50 @@ public final class Bmgr { } else { System.out.println("Selected transport " + which + " (formerly " + old + ")"); } + } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(BMGR_NOT_RUNNING_ERR); } } + private void doTransportByComponent() { + String which = nextArg(); + if (which == null) { + showUsage(); + return; + } + + final CountDownLatch latch = new CountDownLatch(1); + + try { + mBmgr.selectBackupTransportAsync(ComponentName.unflattenFromString(which), + new ISelectBackupTransportCallback.Stub() { + @Override + public void onSuccess(String transportName) { + System.out.println("Success. Selected transport: " + transportName); + latch.countDown(); + } + + @Override + public void onFailure(int reason) { + System.err.println("Failure. error=" + reason); + latch.countDown(); + } + }); + } catch (RemoteException e) { + System.err.println(e.toString()); + System.err.println(BMGR_NOT_RUNNING_ERR); + return; + } + + try { + latch.await(); + } catch (InterruptedException e) { + System.err.println("Operation interrupted."); + } + } + private void doWipe() { String transport = nextArg(); if (transport == null) { @@ -427,7 +474,16 @@ public final class Bmgr { } private void doListTransports() { + String arg = nextArg(); + try { + if ("-c".equals(arg)) { + for (ComponentName transport : mBmgr.listAllTransportComponents()) { + System.out.println(transport.flattenToShortString()); + } + return; + } + String current = mBmgr.getCurrentTransport(); String[] transports = mBmgr.listAllTransports(); if (transports == null || transports.length == 0) { @@ -649,9 +705,9 @@ public final class Bmgr { System.err.println(" bmgr backup PACKAGE"); System.err.println(" bmgr enable BOOL"); System.err.println(" bmgr enabled"); - System.err.println(" bmgr list transports"); + System.err.println(" bmgr list transports [-c]"); System.err.println(" bmgr list sets"); - System.err.println(" bmgr transport WHICH"); + System.err.println(" bmgr transport WHICH|-c WHICH_COMPONENT"); System.err.println(" bmgr restore TOKEN"); System.err.println(" bmgr restore TOKEN PACKAGE..."); System.err.println(" bmgr restore PACKAGE"); @@ -673,15 +729,18 @@ public final class Bmgr { System.err.println("the backup mechanism."); System.err.println(""); System.err.println("The 'list transports' command reports the names of the backup transports"); - System.err.println("currently available on the device. These names can be passed as arguments"); + System.err.println("BackupManager is currently bound to. These names can be passed as arguments"); System.err.println("to the 'transport' and 'wipe' commands. The currently active transport"); - System.err.println("is indicated with a '*' character."); + System.err.println("is indicated with a '*' character. If -c flag is used, all available"); + System.err.println("transport components on the device are listed. These can be used with"); + System.err.println("the component variant of 'transport' command."); System.err.println(""); System.err.println("The 'list sets' command reports the token and name of each restore set"); System.err.println("available to the device via the currently active transport."); System.err.println(""); System.err.println("The 'transport' command designates the named transport as the currently"); - System.err.println("active one. This setting is persistent across reboots."); + System.err.println("active one. This setting is persistent across reboots. If -c flag is"); + System.err.println("specified, the following string is treated as a component name."); System.err.println(""); System.err.println("The 'restore' command when given just a restore token initiates a full-system"); System.err.println("restore operation from the currently active transport. It will deliver"); |