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

Commit 511d02fc authored by Christopher Tate's avatar Christopher Tate
Browse files

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

Bug 20123585

Change-Id: Ife6e77a224b5d4175178aacdb7c285e9944b9eab
parent 7f7e1d13
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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();
+26 −0
Original line number Diff line number Diff line
@@ -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;
    }
}
+13 −0
Original line number Diff line number Diff line
@@ -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);
}
+4 −1
Original line number Diff line number Diff line
@@ -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)) {
+6 −0
Original line number Diff line number Diff line
@@ -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);