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

Commit 0da0ee6f authored by Joe Onorato's avatar Joe Onorato Committed by The Android Open Source Project
Browse files

am 4a64bded: Add some helpful tests scripts for backup and make bmgr restore...

am 4a64bded: Add some helpful tests scripts for backup and make bmgr restore wait until the backup is done.

Merge commit '4a64bded'

* commit '4a64bded':
  Add some helpful tests scripts for backup and make bmgr restore wait until the backup is done.
parents 848358f6 4a64bded
Loading
Loading
Loading
Loading
+33 −11
Original line number Diff line number Diff line
@@ -35,16 +35,6 @@ public final class Bmgr {
    private String[] mArgs;
    private int mNextArg;
    private String mCurArgData;
    private RestoreObserver mObserver = new RestoreObserver();

    class RestoreObserver extends IRestoreObserver.Stub {
        public void restoreStarting(int numPackages) {
        }
        public void onUpdate(int nowBeingRestored) {
        }
        public void restoreFinished(int error) {
        }
    }

    public static void main(String[] args) {
        try {
@@ -191,6 +181,25 @@ public final class Bmgr {
        }
    }

    class RestoreObserver extends IRestoreObserver.Stub {
        boolean done;
        public void restoreStarting(int numPackages) {
            System.out.println("restoreStarting: " + numPackages + " packages");
        }

        public void onUpdate(int nowBeingRestored) {
            System.out.println("onUpdate: " + nowBeingRestored);
        }

        public void restoreFinished(int error) {
            System.out.println("restoreFinished: " + error);
            synchronized (this) {
                done = true;
                this.notify();
            }
        }
    }

    private void doRestore() {
        int token;
        try {
@@ -200,6 +209,8 @@ public final class Bmgr {
            return;
        }

        RestoreObserver observer = new RestoreObserver();

        try {
            int curTransport = mBmgr.getCurrentTransport();
            mRestore = mBmgr.beginRestoreSession(curTransport);
@@ -211,7 +222,7 @@ public final class Bmgr {
            for (RestoreSet s : sets) {
                if (s.token == token) {
                    System.out.println("Scheduling restore: " + s.name);
                    mRestore.performRestore(token, mObserver);
                    mRestore.performRestore(token, observer);
                    break;
                }
            }
@@ -220,6 +231,17 @@ public final class Bmgr {
            System.err.println(e.toString());
            System.err.println(BMGR_NOT_RUNNING_ERR);
        }

        // now wait for it to be done
        synchronized (observer) {
            while (!observer.done) {
                try {
                    observer.wait();
                } catch (InterruptedException ex) {
                }
            }
        }
        System.out.println("done");
    }

    private String nextArg() {
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ public class BackupTestAgent extends BackupHelperAgent
{
    public void onCreate() {
        addHelper("data_files", new FileBackupHelper(this, BackupTestActivity.FILE_NAME));
        addHelper("more_data_files", new FileBackupHelper(this, "another_file.txt"));
        addHelper("more_data_files", new FileBackupHelper(this, "another_file.txt", "3.txt"));
    }
}
+21 −0
Original line number Diff line number Diff line
#!/bin/bash

#adb kill-server

# set the transport
adb shell bmgr transport 1

# load up the three files
adb shell "rm /data/data/com.android.backuptest/files/* ; \
           mkdir /data/data/com.android.backuptest ; \
           mkdir /data/data/com.android.backuptest/files ; \
           echo -n first file > /data/data/com.android.backuptest/files/file.txt ; \
           echo -n asdf > /data/data/com.android.backuptest/files/another_file.txt ; \
           echo -n 3 > /data/data/com.android.backuptest/files/3.txt ; \
"

# say that the data has changed
adb shell bmgr backup com.android.backuptest

# run the backup
adb shell bmgr run
+45 −0
Original line number Diff line number Diff line
#!/bin/bash

function check_file
{
    data=$(adb shell cat /data/data/com.android.backuptest/files/$1)
    if [ "$data" = "$2" ] ; then
        echo "$1 has correct value [$2]"
    else
        echo $1 is INCORRECT
        echo "   value:    [$data]"
        echo "   expected: [$2]"
    fi
}

# delete the old data
echo --- Previous files
adb shell "ls -l /data/data/com.android.backuptest/files"
adb shell "rm /data/data/com.android.backuptest/files/*"
echo --- Erased files
adb shell "ls -l /data/data/com.android.backuptest/files"
echo ---

echo
echo
echo

# run the restore
adb shell bmgr restore 0

echo
echo
echo

# check the results
check_file file.txt "first file"
check_file another_file.txt "asdf"
check_file 3.txt "3"

echo
echo
echo
echo --- Restored files
adb shell "ls -l /data/data/com.android.backuptest/files"
echo ---
echo