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

Commit 71400045 authored by Android (Google) Code Review's avatar Android (Google) Code Review Committed by The Android Open Source Project
Browse files

am febde5fc: Merge change 4389 into donut

Merge commit 'febde5fc'

* commit 'febde5fc':
  More bmgr work; fix clear-data signalling
parents c1760fa8 febde5fc
Loading
Loading
Loading
Loading
+49 −5
Original line number Diff line number Diff line
@@ -36,7 +36,12 @@ public final class Bmgr {
    private String mCurArgData;

    public static void main(String[] args) {
        try {
            new Bmgr().run(args);
        } catch (Exception e) {
            System.err.println("Exception caught:");
            e.printStackTrace();
        }
    }

    public void run(String[] args) {
@@ -70,6 +75,11 @@ public final class Bmgr {
            doList();
            return;
        }

        if ("restore".equals(op)) {
            doRestore();
            return;
        }
    }

    private void doRun() {
@@ -114,6 +124,10 @@ public final class Bmgr {
        try {
            int curTransport = mBmgr.getCurrentTransport();
            mRestore = mBmgr.beginRestoreSession(curTransport);
            if (mRestore == null) {
                System.err.println(BMGR_NOT_RUNNING_ERR);
                return;
            }

            if ("sets".equals(arg)) {
                doListRestoreSets();
@@ -127,13 +141,12 @@ public final class Bmgr {
    }

    private void doListTransports() {
        
    }

    private void doListRestoreSets() {
        try {
            RestoreSet[] sets = mRestore.getAvailableRestoreSets();
            if (sets.length == 0) {
            if (sets == null || sets.length == 0) {
                System.out.println("No restore sets available");
            } else {
                for (RestoreSet s : sets) {
@@ -146,6 +159,37 @@ public final class Bmgr {
        }
    }

    private void doRestore() {
        int token;
        try {
            token = Integer.parseInt(nextArg());
        } catch (NumberFormatException e) {
            showUsage();
            return;
        }

        try {
            int curTransport = mBmgr.getCurrentTransport();
            mRestore = mBmgr.beginRestoreSession(curTransport);
            if (mRestore == null) {
                System.err.println(BMGR_NOT_RUNNING_ERR);
                return;
            }
            RestoreSet[] sets = mRestore.getAvailableRestoreSets();
            for (RestoreSet s : sets) {
                if (s.token == token) {
                    System.out.println("Scheduling restore: " + s.name);
                    mRestore.performRestore(token);
                    break;
                }
            }
            mRestore.endRestoreSession();
        } catch (RemoteException e) {
            System.err.println(e.toString());
            System.err.println(BMGR_NOT_RUNNING_ERR);
        }
    }

    private String nextArg() {
        if (mNextArg >= mArgs.length) {
            return null;
@@ -161,7 +205,7 @@ public final class Bmgr {
        System.err.println("       bmgr list sets");
        System.err.println("       #bmgr list transports");
        System.err.println("       #bmgr transport which#");
        System.err.println("       #bmgr restore set#");
        System.err.println("       bmgr restore token#");
        System.err.println("       bmgr run");
    }
}
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -46,11 +46,11 @@ public class RestoreSet implements Parcelable {
    public int token;


    RestoreSet() {
    public RestoreSet() {
        // Leave everything zero / null
    }

    RestoreSet(String _name, String _dev, int _token) {
    public RestoreSet(String _name, String _dev, int _token) {
        name = _name;
        device = _dev;
        token = _token;
+3 −5
Original line number Diff line number Diff line
@@ -112,11 +112,9 @@ public class LocalTransport extends IBackupTransport.Stub {
    // Restore handling
    public RestoreSet[] getAvailableRestoreSets() throws android.os.RemoteException {
        // one hardcoded restore set
        RestoreSet[] set = new RestoreSet[1];
        set[0].device = "flash";
        set[0].name = "Local disk image";
        set[0].token = 0;
        return set;
        RestoreSet set = new RestoreSet("Local disk image", "flash", 0);
        RestoreSet[] array = { set };
        return array;
    }

    public PackageInfo[] getAppSet(int token) throws android.os.RemoteException {
+29 −3
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ class BackupManagerService extends IBackupManager.Stub {
    private volatile boolean mClearingData;

    private int mTransportId;
    private RestoreSession mActiveRestoreSession;

    private File mStateDir;
    private File mDataDir;
@@ -427,7 +428,7 @@ class BackupManagerService extends IBackupManager.Stub {
            break;

        default:
            Log.e(TAG, "creating unknown transport " + transportID);
            Log.e(TAG, "Asked for unknown transport " + transportID);
        }
        return transport;
    }
@@ -495,7 +496,7 @@ class BackupManagerService extends IBackupManager.Stub {
                throws android.os.RemoteException {
            synchronized(mClearDataLock) {
                mClearingData = false;
                notifyAll();
                mClearDataLock.notifyAll();
            }
        }
    }
@@ -962,12 +963,22 @@ class BackupManagerService extends IBackupManager.Stub {
    // Hand off a restore session
    public IRestoreSession beginRestoreSession(int transportID) {
        mContext.enforceCallingPermission("android.permission.BACKUP", "beginRestoreSession");

        synchronized(this) {
            if (mActiveRestoreSession != null) {
                Log.d(TAG, "Restore session requested but one already active");
                return null;
            }
            mActiveRestoreSession = new RestoreSession(transportID);
        }
        return mActiveRestoreSession;
    }

    // ----- Restore session -----

    class RestoreSession extends IRestoreSession.Stub {
        private static final String TAG = "RestoreSession";

        private IBackupTransport mRestoreTransport = null;
        RestoreSet[] mRestoreSets = null;

@@ -980,12 +991,18 @@ class BackupManagerService extends IBackupManager.Stub {
            mContext.enforceCallingPermission("android.permission.BACKUP",
                    "getAvailableRestoreSets");

            try {
            synchronized(this) {
                if (mRestoreSets == null) {
                    mRestoreSets = mRestoreTransport.getAvailableRestoreSets();
                }
                return mRestoreSets;
            }
            } catch (RuntimeException e) {
                Log.d(TAG, "getAvailableRestoreSets exception");
                e.printStackTrace();
                throw e;
            }
        }

        public int performRestore(int token) throws android.os.RemoteException {
@@ -1001,6 +1018,8 @@ class BackupManagerService extends IBackupManager.Stub {
                        return 0;
                    }
                }
            } else {
                if (DEBUG) Log.v(TAG, "No current restore set, not doing restore");
            }
            return -1;
        }
@@ -1011,6 +1030,13 @@ class BackupManagerService extends IBackupManager.Stub {

            mRestoreTransport.endSession();
            mRestoreTransport = null;
            synchronized(BackupManagerService.this) {
                if (BackupManagerService.this.mActiveRestoreSession == this) {
                    BackupManagerService.this.mActiveRestoreSession = null;
                } else {
                    Log.e(TAG, "ending non-current restore session");
                }
            }
        }
    }