diff options
author | Omari Stephens <xsdg@android.com> | 2009-08-03 20:23:55 -0700 |
---|---|---|
committer | Omari Stephens <xsdg@android.com> | 2009-08-03 20:23:55 -0700 |
commit | 1f808c6f6ed893bb50c94cf5be676712e4d68b9b (patch) | |
tree | c9a5ecbabbf568e4449ad45a6f184000405bd1c1 /tests/backup | |
parent | a05f75d61aa4e779f2fdf466267b47e7df213566 (diff) | |
download | frameworks_base-1f808c6f6ed893bb50c94cf5be676712e4d68b9b.zip frameworks_base-1f808c6f6ed893bb50c94cf5be676712e4d68b9b.tar.gz frameworks_base-1f808c6f6ed893bb50c94cf5be676712e4d68b9b.tar.bz2 |
Make test_backup and test_restore usable again
- Add copyright headers
- Allow the user to pass options (like '-s FOO') to adb
- Restart device adb as root if needed
- Make test_restore to infer a restore set
Diffstat (limited to 'tests/backup')
-rwxr-xr-x | tests/backup/test_backup.sh | 55 | ||||
-rwxr-xr-x | tests/backup/test_restore.sh | 53 |
2 files changed, 84 insertions, 24 deletions
diff --git a/tests/backup/test_backup.sh b/tests/backup/test_backup.sh index dbf9ed2..dd3907c 100755 --- a/tests/backup/test_backup.sh +++ b/tests/backup/test_backup.sh @@ -1,27 +1,54 @@ #!/bin/bash +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +ADB_OPTS="$@" + +#FIXME: what was this for? #adb kill-server +# run adb as root so we can poke at com.android.backuptest's data +root_status=$(adb $ADB_OPTS root) +if [ "x$root_status" != "xadbd is already running as root" ]; then + sleep 2 + adb $ADB_OPTS 'wait-for-device' +fi + +# show commands as we go +set -x + # set the transport -adb shell bmgr transport 1 +adb $ADB_OPTS shell bmgr transport com.google.android.backup/.BackupTransportService # 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 ; \ - mkdir /data/data/com.android.backuptest/shared_prefs ; \ - echo -n \"<map><int name=\\\"pref\\\" value=\\\"1\\\" /></map>\" > /data/data/com.android.backuptest/shared_prefs/raw.xml ; \ - 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 ; \ - echo -n "" > /data/data/com.android.backuptest/files/empty.txt ; \ +adb $ADB_OPTS shell \ + "rm /data/data/com.android.backuptest/files/* ; \ + mkdir /data/data/com.android.backuptest ; \ + mkdir /data/data/com.android.backuptest/files ; \ + mkdir /data/data/com.android.backuptest/shared_prefs ; \ + echo -n \"<map><int name=\\\"pref\\\" value=\\\"1\\\" /></map>\" > /data/data com.android.backuptest/shared_prefs/raw.xml ; \ + 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 ; \ + echo -n "" > /data/data/com.android.backuptest/files/empty.txt ; \ " # say that the data has changed -adb shell bmgr backup com.android.backuptest +adb $ADB_OPTS shell bmgr backup com.android.backuptest # run the backup -adb shell bmgr run - - +adb $ADB_OPTS shell bmgr run diff --git a/tests/backup/test_restore.sh b/tests/backup/test_restore.sh index ccf29cf..8de70cb 100755 --- a/tests/backup/test_restore.sh +++ b/tests/backup/test_restore.sh @@ -1,8 +1,25 @@ #!/bin/bash +# Copyright (C) 2009 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +ADB_OPTS="$@" + function check_file { - data=$(adb shell cat /data/data/com.android.backuptest/$1) + data=$(adb $ADB_OPTS shell cat /data/data/com.android.backuptest/$1) if [ "$data" = "$2" ] ; then echo "$1 has correct value [$2]" else @@ -12,24 +29,39 @@ function check_file fi } +# run adb as root so we can poke at com.android.backuptest's data +root_status=$(adb $ADB_OPTS root) +if [ "x$root_status" != "xadbd is already running as root" ]; then + echo -n "Restarting adb as root..." + sleep 2 + adb $ADB_OPTS 'wait-for-device' + echo done. +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/*" +adb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/files" +adb $ADB_OPTS shell "rm /data/data/com.android.backuptest/files/*" echo --- Previous shared_prefs -adb shell "ls -l /data/data/com.android.backuptest/shared_prefs" -adb shell "rm /data/data/com.android.backuptest/shared_prefs/*" +adb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/shared_prefs" +adb $ADB_OPTS shell "rm /data/data/com.android.backuptest/shared_prefs/*" echo --- Erased files and shared_prefs -adb shell "ls -l /data/data/com.android.backuptest/files" -adb shell "ls -l /data/data/com.android.backuptest/shared_prefs" +adb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/files" +adb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/shared_prefs" echo --- echo echo echo +# FIXME: there's probably a smarter way to do this +# FIXME: if we can get the android ID, that's probably the safest thing to do +# pick the most recent set and restore from it +restore_set=$(adb $ADB_OPTS shell bmgr list sets | head -n1 | awk '{print $1}') + # run the restore -adb shell bmgr restore 0 +printf "Restoring from set %d (hex: 0x%x)\n" $restore_set $restore_set +adb $ADB_OPTS shell bmgr restore $restore_set echo echo @@ -46,8 +78,9 @@ echo echo echo echo --- Restored files -adb shell "ls -l /data/data/com.android.backuptest/files" +adb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/files" echo --- Restored shared_prefs -adb shell "ls -l /data/data/com.android.backuptest/shared_prefs" +adb $ADB_OPTS shell "ls -l /data/data/com.android.backuptest/shared_prefs" echo --- echo + |