More bmgr work; fix clear-data signalling
The 'list sets' and 'restore token#' commands from bmgr now do what they are supposed to. At this point we see the restore target's data being cleared properly and its agent being launched and invoked for restore.
This commit is contained in:
@@ -36,9 +36,14 @@ public final class Bmgr {
|
||||
private String mCurArgData;
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Bmgr().run(args);
|
||||
try {
|
||||
new Bmgr().run(args);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Exception caught:");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void run(String[] args) {
|
||||
boolean validCommand = false;
|
||||
if (args.length < 1) {
|
||||
@@ -70,6 +75,11 @@ public final class Bmgr {
|
||||
doList();
|
||||
return;
|
||||
}
|
||||
|
||||
if ("restore".equals(op)) {
|
||||
doRestore();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void doRun() {
|
||||
@@ -114,6 +124,10 @@ public final class Bmgr {
|
||||
try {
|
||||
int curTransport = mBmgr.getCurrentTransport();
|
||||
mRestore = mBmgr.beginRestoreSession(curTransport);
|
||||
if (mRestore == null) {
|
||||
System.err.println(BMGR_NOT_RUNNING_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
if ("sets".equals(arg)) {
|
||||
doListRestoreSets();
|
||||
@@ -127,13 +141,12 @@ public final class Bmgr {
|
||||
}
|
||||
|
||||
private void doListTransports() {
|
||||
|
||||
}
|
||||
|
||||
private void doListRestoreSets() {
|
||||
try {
|
||||
RestoreSet[] sets = mRestore.getAvailableRestoreSets();
|
||||
if (sets.length == 0) {
|
||||
if (sets == null || sets.length == 0) {
|
||||
System.out.println("No restore sets available");
|
||||
} else {
|
||||
for (RestoreSet s : sets) {
|
||||
@@ -146,6 +159,37 @@ public final class Bmgr {
|
||||
}
|
||||
}
|
||||
|
||||
private void doRestore() {
|
||||
int token;
|
||||
try {
|
||||
token = Integer.parseInt(nextArg());
|
||||
} catch (NumberFormatException e) {
|
||||
showUsage();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
int curTransport = mBmgr.getCurrentTransport();
|
||||
mRestore = mBmgr.beginRestoreSession(curTransport);
|
||||
if (mRestore == null) {
|
||||
System.err.println(BMGR_NOT_RUNNING_ERR);
|
||||
return;
|
||||
}
|
||||
RestoreSet[] sets = mRestore.getAvailableRestoreSets();
|
||||
for (RestoreSet s : sets) {
|
||||
if (s.token == token) {
|
||||
System.out.println("Scheduling restore: " + s.name);
|
||||
mRestore.performRestore(token);
|
||||
break;
|
||||
}
|
||||
}
|
||||
mRestore.endRestoreSession();
|
||||
} catch (RemoteException e) {
|
||||
System.err.println(e.toString());
|
||||
System.err.println(BMGR_NOT_RUNNING_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
private String nextArg() {
|
||||
if (mNextArg >= mArgs.length) {
|
||||
return null;
|
||||
@@ -161,7 +205,7 @@ public final class Bmgr {
|
||||
System.err.println(" bmgr list sets");
|
||||
System.err.println(" #bmgr list transports");
|
||||
System.err.println(" #bmgr transport which#");
|
||||
System.err.println(" #bmgr restore set#");
|
||||
System.err.println(" bmgr restore token#");
|
||||
System.err.println(" bmgr run");
|
||||
}
|
||||
}
|
||||
@@ -46,11 +46,11 @@ public class RestoreSet implements Parcelable {
|
||||
public int token;
|
||||
|
||||
|
||||
RestoreSet() {
|
||||
public RestoreSet() {
|
||||
// Leave everything zero / null
|
||||
}
|
||||
|
||||
RestoreSet(String _name, String _dev, int _token) {
|
||||
public RestoreSet(String _name, String _dev, int _token) {
|
||||
name = _name;
|
||||
device = _dev;
|
||||
token = _token;
|
||||
|
||||
@@ -112,11 +112,9 @@ public class LocalTransport extends IBackupTransport.Stub {
|
||||
// Restore handling
|
||||
public RestoreSet[] getAvailableRestoreSets() throws android.os.RemoteException {
|
||||
// one hardcoded restore set
|
||||
RestoreSet[] set = new RestoreSet[1];
|
||||
set[0].device = "flash";
|
||||
set[0].name = "Local disk image";
|
||||
set[0].token = 0;
|
||||
return set;
|
||||
RestoreSet set = new RestoreSet("Local disk image", "flash", 0);
|
||||
RestoreSet[] array = { set };
|
||||
return array;
|
||||
}
|
||||
|
||||
public PackageInfo[] getAppSet(int token) throws android.os.RemoteException {
|
||||
|
||||
@@ -121,6 +121,7 @@ class BackupManagerService extends IBackupManager.Stub {
|
||||
private volatile boolean mClearingData;
|
||||
|
||||
private int mTransportId;
|
||||
private RestoreSession mActiveRestoreSession;
|
||||
|
||||
private File mStateDir;
|
||||
private File mDataDir;
|
||||
@@ -427,7 +428,7 @@ class BackupManagerService extends IBackupManager.Stub {
|
||||
break;
|
||||
|
||||
default:
|
||||
Log.e(TAG, "creating unknown transport " + transportID);
|
||||
Log.e(TAG, "Asked for unknown transport " + transportID);
|
||||
}
|
||||
return transport;
|
||||
}
|
||||
@@ -495,7 +496,7 @@ class BackupManagerService extends IBackupManager.Stub {
|
||||
throws android.os.RemoteException {
|
||||
synchronized(mClearDataLock) {
|
||||
mClearingData = false;
|
||||
notifyAll();
|
||||
mClearDataLock.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -962,12 +963,22 @@ class BackupManagerService extends IBackupManager.Stub {
|
||||
// Hand off a restore session
|
||||
public IRestoreSession beginRestoreSession(int transportID) {
|
||||
mContext.enforceCallingPermission("android.permission.BACKUP", "beginRestoreSession");
|
||||
return null;
|
||||
|
||||
synchronized(this) {
|
||||
if (mActiveRestoreSession != null) {
|
||||
Log.d(TAG, "Restore session requested but one already active");
|
||||
return null;
|
||||
}
|
||||
mActiveRestoreSession = new RestoreSession(transportID);
|
||||
}
|
||||
return mActiveRestoreSession;
|
||||
}
|
||||
|
||||
// ----- Restore session -----
|
||||
|
||||
class RestoreSession extends IRestoreSession.Stub {
|
||||
private static final String TAG = "RestoreSession";
|
||||
|
||||
private IBackupTransport mRestoreTransport = null;
|
||||
RestoreSet[] mRestoreSets = null;
|
||||
|
||||
@@ -980,12 +991,18 @@ class BackupManagerService extends IBackupManager.Stub {
|
||||
mContext.enforceCallingPermission("android.permission.BACKUP",
|
||||
"getAvailableRestoreSets");
|
||||
|
||||
try {
|
||||
synchronized(this) {
|
||||
if (mRestoreSets == null) {
|
||||
mRestoreSets = mRestoreTransport.getAvailableRestoreSets();
|
||||
}
|
||||
return mRestoreSets;
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
Log.d(TAG, "getAvailableRestoreSets exception");
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public int performRestore(int token) throws android.os.RemoteException {
|
||||
@@ -1001,6 +1018,8 @@ class BackupManagerService extends IBackupManager.Stub {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (DEBUG) Log.v(TAG, "No current restore set, not doing restore");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -1011,6 +1030,13 @@ class BackupManagerService extends IBackupManager.Stub {
|
||||
|
||||
mRestoreTransport.endSession();
|
||||
mRestoreTransport = null;
|
||||
synchronized(BackupManagerService.this) {
|
||||
if (BackupManagerService.this.mActiveRestoreSession == this) {
|
||||
BackupManagerService.this.mActiveRestoreSession = null;
|
||||
} else {
|
||||
Log.e(TAG, "ending non-current restore session");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user