Add system API for querying the available restore dataset for a package

Bug 20123585

Change-Id: Ife6e77a224b5d4175178aacdb7c285e9944b9eab
This commit is contained in:
Christopher Tate
2015-04-08 20:05:30 -07:00
parent 7f7e1d13c0
commit 511d02fcc3
5 changed files with 50 additions and 1 deletions

View File

@@ -5912,6 +5912,7 @@ package android.app.backup {
method public android.app.backup.RestoreSession beginRestoreSession();
method public void dataChanged();
method public static void dataChanged(java.lang.String);
method public long getAvailableRestoreToken(java.lang.String);
method public java.lang.String getCurrentTransport();
method public boolean isBackupEnabled();
method public java.lang.String[] listAllTransports();

View File

@@ -339,4 +339,30 @@ public class BackupManager {
}
}
}
/**
* Ask the framework which dataset, if any, the given package's data would be
* restored from if we were to install it right now.
*
* <p>Callers must hold the android.permission.BACKUP permission to use this method.
*
* @param packageName The name of the package whose most-suitable dataset we
* wish to look up
* @return The dataset token from which a restore should be attempted, or zero if
* no suitable data is available.
*
* @hide
*/
@SystemApi
public long getAvailableRestoreToken(String packageName) {
checkServiceBinder();
if (sService != null) {
try {
return sService.getAvailableRestoreToken(packageName);
} catch (RemoteException e) {
Log.e(TAG, "getAvailableRestoreToken() couldn't connect");
}
}
return 0;
}
}

View File

@@ -313,4 +313,17 @@ interface IBackupManager {
* is being queried.
*/
boolean isBackupServiceActive(int whichUser);
/**
* Ask the framework which dataset, if any, the given package's data would be
* restored from if we were to install it right now.
*
* <p>Callers must hold the android.permission.BACKUP permission to use this method.
*
* @param packageName The name of the package whose most-suitable dataset we
* wish to look up
* @return The dataset token from which a restore should be attempted, or zero if
* no suitable data is available.
*/
long getAvailableRestoreToken(String packageName);
}

View File

@@ -2209,7 +2209,10 @@ public class BackupManagerService {
// Get the restore-set token for the best-available restore set for this package:
// the active set if possible, else the ancestral one. Returns zero if none available.
long getAvailableRestoreToken(String packageName) {
public long getAvailableRestoreToken(String packageName) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
"getAvailableRestoreToken");
long token = mAncestralToken;
synchronized (mQueueLock) {
if (mEverStoredApps.contains(packageName)) {

View File

@@ -316,6 +316,12 @@ public class Trampoline extends IBackupManager.Stub {
}
}
@Override
public long getAvailableRestoreToken(String packageName) {
BackupManagerService svc = mService;
return (svc != null) ? svc.getAvailableRestoreToken(packageName) : 0;
}
@Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);