diff options
| author | Android (Google) Code Review <android-gerrit@google.com> | 2009-07-07 11:52:01 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-07-07 11:52:01 -0700 |
| commit | 2c5a3aeba3f7c0d362829c57a8fffdba0a0e81c1 (patch) | |
| tree | dc7e585283046818bd31d1b3f96b6a623f4eba22 /core | |
| parent | 04f0b05ea04a4a13d6a15b36eaa27b2ec364f313 (diff) | |
| parent | c8daa769256b039b6bc4c5acbe6b558cd776c00a (diff) | |
| download | frameworks_base-2c5a3aeba3f7c0d362829c57a8fffdba0a0e81c1.zip frameworks_base-2c5a3aeba3f7c0d362829c57a8fffdba0a0e81c1.tar.gz frameworks_base-2c5a3aeba3f7c0d362829c57a8fffdba0a0e81c1.tar.bz2 | |
Merge change 6326 into donut
* changes:
BackupManager wrapper class improvements
Diffstat (limited to 'core')
| -rw-r--r-- | core/java/android/backup/BackupManager.java | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/core/java/android/backup/BackupManager.java b/core/java/android/backup/BackupManager.java index 5b4ac0d..34a1a0c 100644 --- a/core/java/android/backup/BackupManager.java +++ b/core/java/android/backup/BackupManager.java @@ -19,6 +19,7 @@ package android.backup; import android.content.Context; import android.os.RemoteException; import android.os.ServiceManager; +import android.util.Log; /** * BackupManager is the interface to the system's backup service. @@ -39,14 +40,17 @@ import android.os.ServiceManager; * @hide pending API solidification */ public class BackupManager { + private static final String TAG = "BackupManager"; + private Context mContext; - private IBackupManager mService; + private static IBackupManager sService; - /** - * Defined backup transports understood by {@link IBackupManager.selectBackupTransport}. - */ - public static final int TRANSPORT_LOCAL = 1; - public static final int TRANSPORT_GOOGLE = 2; + private static void checkServiceBinder() { + if (sService == null) { + sService = IBackupManager.Stub.asInterface( + ServiceManager.getService(Context.BACKUP_SERVICE)); + } + } /** * Constructs a BackupManager object through which the application can @@ -58,8 +62,6 @@ public class BackupManager { */ public BackupManager(Context context) { mContext = context; - mService = IBackupManager.Stub.asInterface( - ServiceManager.getService(Context.BACKUP_SERVICE)); } /** @@ -68,10 +70,31 @@ public class BackupManager { * {@link android.app.BackupAgent} subclass will be scheduled when you call this method. */ public void dataChanged() { - if (mService != null) { + checkServiceBinder(); + if (sService != null) { + try { + sService.dataChanged(mContext.getPackageName()); + } catch (RemoteException e) { + Log.d(TAG, "dataChanged() couldn't connect"); + } + } + } + + /** + * Convenience method for callers who need to indicate that some other package + * needs a backup pass. This can be relevant in the case of groups of packages + * that share a uid, for example. + * + * This method requires that the application hold the "android.permission.BACKUP" + * permission if the package named in the argument is not the caller's own. + */ + public static void dataChanged(String packageName) { + checkServiceBinder(); + if (sService != null) { try { - mService.dataChanged(mContext.getPackageName()); + sService.dataChanged(packageName); } catch (RemoteException e) { + Log.d(TAG, "dataChanged(pkg) couldn't connect"); } } } @@ -85,10 +108,12 @@ public class BackupManager { */ public IRestoreSession beginRestoreSession(String transport) { IRestoreSession binder = null; - if (mService != null) { + checkServiceBinder(); + if (sService != null) { try { - binder = mService.beginRestoreSession(transport); + binder = sService.beginRestoreSession(transport); } catch (RemoteException e) { + Log.d(TAG, "beginRestoreSession() couldn't connect"); } } return binder; |
