Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 96e0be0f authored by Michal Karpinski's avatar Michal Karpinski
Browse files

Add BackupManager#isBackupServiceActive() system API

So that GMSCore can find out and disable restore flow
and Backup UI.

Bug: 33339643
Test: gts-tradefed run gts -m GtsGmscoreHostTestCases -t com.google.android.gts.devicepolicy.DeviceOwnerTest#testBackupServiceActive (new GTS test in companion CL)
Test: cts-tradefed run cts -m CtsDevicePolicyManagerTestCases -t com.android.cts.devicepolicy.DeviceOwnerTest#testBackupServiceEnabling
Change-Id: I62c38dec2395d3aa926566d128b0067ce7d62c26
parent 7d0e1f80
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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);
+24 −0
Original line number Diff line number Diff line
@@ -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
+3 −1
Original line number Diff line number Diff line
@@ -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;