Merge "Add BackupManager#isBackupServiceActive() system API"

This commit is contained in:
TreeHugger Robot
2018-01-17 19:07:21 +00:00
committed by Android (Google) Code Review
3 changed files with 28 additions and 1 deletions

View File

@@ -430,6 +430,7 @@ package android.app.backup {
method public java.lang.String getCurrentTransport();
method public boolean isAppEligibleForBackup(java.lang.String);
method public boolean isBackupEnabled();
method public boolean isBackupServiceActive(android.os.UserHandle);
method public java.lang.String[] listAllTransports();
method public int requestBackup(java.lang.String[], android.app.backup.BackupObserver);
method public int requestBackup(java.lang.String[], android.app.backup.BackupObserver, android.app.backup.BackupManagerMonitor, int);

View File

@@ -27,6 +27,7 @@ import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.util.Log;
import android.util.Pair;
@@ -386,6 +387,29 @@ public class BackupManager {
return false;
}
/**
* Report whether the backup mechanism is currently active.
* When it is inactive, the device will not perform any backup operations, nor will it
* deliver data for restore, although clients can still safely call BackupManager methods.
*
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.BACKUP)
public boolean isBackupServiceActive(UserHandle user) {
mContext.enforceCallingPermission(android.Manifest.permission.BACKUP,
"isBackupServiceActive");
checkServiceBinder();
if (sService != null) {
try {
return sService.isBackupServiceActive(user.getIdentifier());
} catch (RemoteException e) {
Log.e(TAG, "isBackupEnabled() couldn't connect");
}
}
return false;
}
/**
* Enable/disable data restore at application install time. When enabled, app
* installation will include an attempt to fetch the app's historical data from

View File

@@ -177,12 +177,15 @@ public class Trampoline extends IBackupManager.Stub {
}
}
// IBackupManager binder API
/**
* Querying activity state of backup service. Calling this method before initialize yields
* undefined result.
* @param userHandle The user in which the activity state of backup service is queried.
* @return true if the service is active.
*/
@Override
public boolean isBackupServiceActive(final int userHandle) {
// TODO: http://b/22388012
if (userHandle == UserHandle.USER_SYSTEM) {
@@ -193,7 +196,6 @@ public class Trampoline extends IBackupManager.Stub {
return false;
}
// IBackupManager binder API
@Override
public void dataChanged(String packageName) throws RemoteException {
BackupManagerServiceInterface svc = mService;