14a64bded06a0299785c295a975e2818308eb53e2Joe Onorato#!/bin/bash
24a64bded06a0299785c295a975e2818308eb53e2Joe Onorato
31f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# Copyright (C) 2009 The Android Open Source Project
41f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens#
51f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# Licensed under the Apache License, Version 2.0 (the "License");
61f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# you may not use this file except in compliance with the License.
71f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# You may obtain a copy of the License at
81f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens#
91f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens#      http://www.apache.org/licenses/LICENSE-2.0
101f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens#
111f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# Unless required by applicable law or agreed to in writing, software
121f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# distributed under the License is distributed on an "AS IS" BASIS,
131f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
141f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# See the License for the specific language governing permissions and
151f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# limitations under the License.
161f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens
170cfeb25707c87af285cc993967be486d9c95a176Omari Stephens# uncomment for debugging
180cfeb25707c87af285cc993967be486d9c95a176Omari Stephens#export DRY_RUN="echo"
190cfeb25707c87af285cc993967be486d9c95a176Omari Stephenssource test_backup_common.sh
201f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens
21aa6e73a6c850694550b59a0911727dcb23c4837dOmari Stephens# figure out what packages are participating in backup
220cfeb25707c87af285cc993967be486d9c95a176Omari Stephensb_pkgs=$(a shell dumpsys backup | \
23aa6e73a6c850694550b59a0911727dcb23c4837dOmari Stephens         ruby -e 'p_stanza = STDIN.read.match(/Participants:.*?(?=Ever)/m)[0]
24aa6e73a6c850694550b59a0911727dcb23c4837dOmari Stephens                  puts p_stanza.scan(/^    (.+?)\s*$/).flatten.join(" ")')
251f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens
26aa6e73a6c850694550b59a0911727dcb23c4837dOmari Stephens# wipe data for the package participating in backup
270cfeb25707c87af285cc993967be486d9c95a176Omari Stephensfor pkg in $b_pkgs; do
280cfeb25707c87af285cc993967be486d9c95a176Omari Stephens    a shell bmgr wipe "$pkg"
29864ed1a9d7f7a18db7415322728f6208a0eaf9d5Omari Stephensdone
30864ed1a9d7f7a18db7415322728f6208a0eaf9d5Omari Stephens
31864ed1a9d7f7a18db7415322728f6208a0eaf9d5Omari Stephensecho 'Waiting 5 seconds for things to settle...'
32864ed1a9d7f7a18db7415322728f6208a0eaf9d5Omari Stephenssleep 5
33864ed1a9d7f7a18db7415322728f6208a0eaf9d5Omari Stephens
341f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# run adb as root so we can poke at com.android.backuptest's data
350cfeb25707c87af285cc993967be486d9c95a176Omari Stephensadb_root
361f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens
371f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens# show commands as we go
381f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephensset -x
391f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens
404a64bded06a0299785c295a975e2818308eb53e2Joe Onorato# set the transport
41aa6e73a6c850694550b59a0911727dcb23c4837dOmari Stephens#a shell bmgr transport com.google.android.backup/.BackupTransportService
424a64bded06a0299785c295a975e2818308eb53e2Joe Onorato
434a64bded06a0299785c295a975e2818308eb53e2Joe Onorato# load up the three files
440cfeb25707c87af285cc993967be486d9c95a176Omari Stephensa shell \
45864ed1a9d7f7a18db7415322728f6208a0eaf9d5Omari Stephens   "rm /data/data/com.android.backuptest/files/file.txt ; \
46864ed1a9d7f7a18db7415322728f6208a0eaf9d5Omari Stephens    rm /data/data/com.android.backuptest/files/another_file.txt ; \
47864ed1a9d7f7a18db7415322728f6208a0eaf9d5Omari Stephens    rm /data/data/com.android.backuptest/files/empty.txt ; \
481f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens    mkdir /data/data/com.android.backuptest ; \
491f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens    mkdir /data/data/com.android.backuptest/files ; \
501f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens    mkdir /data/data/com.android.backuptest/shared_prefs ; \
51864ed1a9d7f7a18db7415322728f6208a0eaf9d5Omari Stephens    echo -n \"<map><int name=\\\"pref\\\" value=\\\"1\\\" /></map>\" \
52864ed1a9d7f7a18db7415322728f6208a0eaf9d5Omari Stephens            > /data/data/com.android.backuptest/shared_prefs/raw.xml ; \
531f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens    echo -n first file > /data/data/com.android.backuptest/files/file.txt ; \
541f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens    echo -n asdf > /data/data/com.android.backuptest/files/another_file.txt ; \
551f808c6f6ed893bb50c94cf5be676712e4d68b9bOmari Stephens    echo -n "" > /data/data/com.android.backuptest/files/empty.txt ; \
56864ed1a9d7f7a18db7415322728f6208a0eaf9d5Omari Stephens    date >> /data/data/com.android.backuptest/files/3.txt ; \
574a64bded06a0299785c295a975e2818308eb53e2Joe Onorato"
58864ed1a9d7f7a18db7415322728f6208a0eaf9d5Omari Stephens#    echo -n 3 > /data/data/com.android.backuptest/files/3.txt ; \
594a64bded06a0299785c295a975e2818308eb53e2Joe Onorato
604a64bded06a0299785c295a975e2818308eb53e2Joe Onorato# say that the data has changed
610cfeb25707c87af285cc993967be486d9c95a176Omari Stephensa shell bmgr backup com.android.backuptest
624a64bded06a0299785c295a975e2818308eb53e2Joe Onorato
634a64bded06a0299785c295a975e2818308eb53e2Joe Onorato# run the backup
640cfeb25707c87af285cc993967be486d9c95a176Omari Stephensa shell bmgr run
65dc355a90a3d9d34f66316928a53f61ac35ab4781Joe Onorato
66