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

Commit f4ab2b10 authored by Christopher Tate's avatar Christopher Tate Committed by Android (Google) Code Review
Browse files

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

parents b88e1227 511d02fc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5915,6 +5915,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);