am b3f7fe44: am 22375e4a: Merge "Make RestoreSession.getAvailableRestoreSets() asynchronous" into froyo

Merge commit 'b3f7fe44f5a3a6a4c04d4102eb61f29edf83129c' into kraken

* commit 'b3f7fe44f5a3a6a4c04d4102eb61f29edf83129c':
  Make RestoreSession.getAvailableRestoreSets() asynchronous
This commit is contained in:
Christopher Tate
2010-03-30 13:17:23 -07:00
committed by Android Git Automerger
7 changed files with 180 additions and 34 deletions

View File

@@ -16,12 +16,26 @@
package android.app.backup;
import android.app.backup.RestoreSet;
/**
* Callback class for receiving progress reports during a restore operation.
*
* @hide
*/
interface IRestoreObserver {
oneway interface IRestoreObserver {
/**
* Supply a list of the restore datasets available from the current transport. This
* method is invoked as a callback following the application's use of the
* {@link android.app.backup.IRestoreSession.getAvailableRestoreSets} method.
*
* @param result An array of {@link android.app.backup.RestoreSet RestoreSet} objects
* describing all of the available datasets that are candidates for restoring to
* the current device. If no applicable datasets exist, {@code result} will be
* {@code null}.
*/
void restoreSetsAvailable(in RestoreSet[] result);
/**
* The restore operation has begun.
*
@@ -32,8 +46,8 @@ interface IRestoreObserver {
/**
* An indication of which package is being restored currently, out of the
* total number provided in the restoreStarting() callback. This method
* is not guaranteed to be called.
* total number provided in the {@link #restoreStarting(int numPackages)} callback.
* This method is not guaranteed to be called.
*
* @param nowBeingRestored The index, between 1 and the numPackages parameter
* to the restoreStarting() callback, of the package now being restored.

View File

@@ -29,12 +29,12 @@ interface IRestoreSession {
/**
* Ask the current transport what the available restore sets are.
*
* @return A bundle containing two elements: an int array under the key
* "tokens" whose entries are a transport-private identifier for each backup set;
* and a String array under the key "names" whose entries are the user-meaningful
* text corresponding to the backup sets at each index in the tokens array.
* @param observer This binder points to an object whose onRestoreSetsAvailable()
* method will be called to supply the results of the transport's lookup.
* @return Zero on success; nonzero on error. The observer will only receive a
* result callback if this method returned zero.
*/
RestoreSet[] getAvailableRestoreSets();
int getAvailableRestoreSets(IRestoreObserver observer);
/**
* Restore the given set onto the device, replacing the current data of any app

View File

@@ -17,19 +17,35 @@
package android.app.backup;
import java.lang.String;
import android.app.backup.RestoreSet;
/**
* Callback class for receiving progress reports during a restore operation. These
* methods will all be called on your application's main thread.
*/
public abstract class RestoreObserver {
/**
* Supply a list of the restore datasets available from the current transport. This
* method is invoked as a callback following the application's use of the
* {@link android.app.backup.IRestoreSession.getAvailableRestoreSets} method.
*
* @param result An array of {@link android.app.backup.RestoreSet RestoreSet} objects
* describing all of the available datasets that are candidates for restoring to
* the current device. If no applicable datasets exist, {@code result} will be
* {@code null}.
*
* @hide
*/
public void restoreSetsAvailable(RestoreSet[] result) {
}
/**
* The restore operation has begun.
*
* @param numPackages The total number of packages being processed in
* this restore operation.
*/
void restoreStarting(int numPackages) {
public void restoreStarting(int numPackages) {
}
/**
@@ -45,7 +61,7 @@ public abstract class RestoreObserver {
* indication of the backup manager's progress through the overall restore process.
* @param currentPackage The name of the package now being restored.
*/
void onUpdate(int nowBeingRestored, String currentPackage) {
public void onUpdate(int nowBeingRestored, String currentPackage) {
}
/**
@@ -55,6 +71,6 @@ public abstract class RestoreObserver {
* @param error Zero on success; a nonzero error code if the restore operation
* as a whole failed.
*/
void restoreFinished(int error) {
public void restoreFinished(int error) {
}
}

View File

@@ -40,19 +40,22 @@ public class RestoreSession {
/**
* Ask the current transport what the available restore sets are.
*
* @return A bundle containing two elements: an int array under the key
* "tokens" whose entries are a transport-private identifier for each backup set;
* and a String array under the key "names" whose entries are the user-meaningful
* text corresponding to the backup sets at each index in the tokens array.
* On error, returns null.
* @param observer a RestoreObserver object whose restoreSetsAvailable() method will
* be called on the application's main thread in order to supply the results of
* the restore set lookup by the backup transport. This parameter must not be
* null.
* @return Zero on success, nonzero on error. The observer's restoreSetsAvailable()
* method will only be called if this method returned zero.
*/
public RestoreSet[] getAvailableRestoreSets() {
public int getAvailableRestoreSets(RestoreObserver observer) {
int err = -1;
RestoreObserverWrapper obsWrapper = new RestoreObserverWrapper(mContext, observer);
try {
return mBinder.getAvailableRestoreSets();
err = mBinder.getAvailableRestoreSets(obsWrapper);
} catch (RemoteException e) {
Log.d(TAG, "Can't contact server to get available sets");
return null;
}
return err;
}
/**
@@ -151,6 +154,7 @@ public class RestoreSession {
static final int MSG_RESTORE_STARTING = 1;
static final int MSG_UPDATE = 2;
static final int MSG_RESTORE_FINISHED = 3;
static final int MSG_RESTORE_SETS_AVAILABLE = 4;
RestoreObserverWrapper(Context context, RestoreObserver appObserver) {
mHandler = new Handler(context.getMainLooper()) {
@@ -166,6 +170,9 @@ public class RestoreSession {
case MSG_RESTORE_FINISHED:
mAppObserver.restoreFinished(msg.arg1);
break;
case MSG_RESTORE_SETS_AVAILABLE:
mAppObserver.restoreSetsAvailable((RestoreSet[])msg.obj);
break;
}
}
};
@@ -173,6 +180,11 @@ public class RestoreSession {
}
// Binder calls into this object just enqueue on the main-thread handler
public void restoreSetsAvailable(RestoreSet[] result) {
mHandler.sendMessage(
mHandler.obtainMessage(MSG_RESTORE_SETS_AVAILABLE, result));
}
public void restoreStarting(int numPackages) {
mHandler.sendMessage(
mHandler.obtainMessage(MSG_RESTORE_STARTING, numPackages, 0));