Merge change 6326 into donut
* changes: BackupManager wrapper class improvements
This commit is contained in:
@@ -19,6 +19,7 @@ package android.backup;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BackupManager is the interface to the system's backup service.
|
* BackupManager is the interface to the system's backup service.
|
||||||
@@ -39,14 +40,17 @@ import android.os.ServiceManager;
|
|||||||
* @hide pending API solidification
|
* @hide pending API solidification
|
||||||
*/
|
*/
|
||||||
public class BackupManager {
|
public class BackupManager {
|
||||||
private Context mContext;
|
private static final String TAG = "BackupManager";
|
||||||
private IBackupManager mService;
|
|
||||||
|
|
||||||
/**
|
private Context mContext;
|
||||||
* Defined backup transports understood by {@link IBackupManager.selectBackupTransport}.
|
private static IBackupManager sService;
|
||||||
*/
|
|
||||||
public static final int TRANSPORT_LOCAL = 1;
|
private static void checkServiceBinder() {
|
||||||
public static final int TRANSPORT_GOOGLE = 2;
|
if (sService == null) {
|
||||||
|
sService = IBackupManager.Stub.asInterface(
|
||||||
|
ServiceManager.getService(Context.BACKUP_SERVICE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a BackupManager object through which the application can
|
* Constructs a BackupManager object through which the application can
|
||||||
@@ -58,8 +62,6 @@ public class BackupManager {
|
|||||||
*/
|
*/
|
||||||
public BackupManager(Context context) {
|
public BackupManager(Context context) {
|
||||||
mContext = 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.
|
* {@link android.app.BackupAgent} subclass will be scheduled when you call this method.
|
||||||
*/
|
*/
|
||||||
public void dataChanged() {
|
public void dataChanged() {
|
||||||
if (mService != null) {
|
checkServiceBinder();
|
||||||
|
if (sService != null) {
|
||||||
try {
|
try {
|
||||||
mService.dataChanged(mContext.getPackageName());
|
sService.dataChanged(mContext.getPackageName());
|
||||||
} catch (RemoteException e) {
|
} 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 {
|
||||||
|
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) {
|
public IRestoreSession beginRestoreSession(String transport) {
|
||||||
IRestoreSession binder = null;
|
IRestoreSession binder = null;
|
||||||
if (mService != null) {
|
checkServiceBinder();
|
||||||
|
if (sService != null) {
|
||||||
try {
|
try {
|
||||||
binder = mService.beginRestoreSession(transport);
|
binder = sService.beginRestoreSession(transport);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
Log.d(TAG, "beginRestoreSession() couldn't connect");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return binder;
|
return binder;
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ public class BackupTestActivity extends ListActivity
|
|||||||
static final String PREF_KEY = "pref";
|
static final String PREF_KEY = "pref";
|
||||||
static final String FILE_NAME = "file.txt";
|
static final String FILE_NAME = "file.txt";
|
||||||
|
|
||||||
|
BackupManager sBm = new BackupManager(this);
|
||||||
|
|
||||||
Test[] mTests = new Test[] {
|
Test[] mTests = new Test[] {
|
||||||
new Test("Show File") {
|
new Test("Show File") {
|
||||||
void run() {
|
void run() {
|
||||||
@@ -85,8 +87,7 @@ public class BackupTestActivity extends ListActivity
|
|||||||
output.close();
|
output.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BackupManager bm = new BackupManager(BackupTestActivity.this);
|
sBm.dataChanged();
|
||||||
bm.dataChanged();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new Test("Clear File") {
|
new Test("Clear File") {
|
||||||
@@ -100,14 +101,12 @@ public class BackupTestActivity extends ListActivity
|
|||||||
output.close();
|
output.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BackupManager bm = new BackupManager(BackupTestActivity.this);
|
sBm.dataChanged();
|
||||||
bm.dataChanged();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new Test("Poke") {
|
new Test("Poke") {
|
||||||
void run() {
|
void run() {
|
||||||
BackupManager bm = new BackupManager(BackupTestActivity.this);
|
sBm.dataChanged();
|
||||||
bm.dataChanged();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new Test("Show Shared Pref") {
|
new Test("Show Shared Pref") {
|
||||||
@@ -126,8 +125,7 @@ public class BackupTestActivity extends ListActivity
|
|||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
editor.putInt(PREF_KEY, val+1);
|
editor.putInt(PREF_KEY, val+1);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
BackupManager bm = new BackupManager(BackupTestActivity.this);
|
sBm.dataChanged();
|
||||||
bm.dataChanged();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new Test("Backup Helpers") {
|
new Test("Backup Helpers") {
|
||||||
|
|||||||
Reference in New Issue
Block a user