Skip to content

Commit 304e70f

Browse files
committed
fix emulator scrips
1 parent c863695 commit 304e70f

File tree

6 files changed

+47
-132
lines changed

6 files changed

+47
-132
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ gradle-app.setting
5858

5959
## Android
6060
gen/
61+
62+
## Emulator
63+
app/backup.tar.gz

app/build.gradle.kts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -259,27 +259,3 @@ tasks.register<Exec>("startEmulator") {
259259
environment("JAVA_HOME", System.getProperty("java.home"))
260260
}
261261
}
262-
263-
tasks.register<Exec>("installEmulatorRelease") {
264-
group = "emulator"
265-
266-
dependsOn(tasks.getByName("assembleRelease"))
267-
268-
doFirst {
269-
commandLine("${project.projectDir}/development/scripts/install_app.sh")
270-
271-
environment("ANDROID_HOME", android.sdkDirectory.absolutePath)
272-
environment("JAVA_HOME", System.getProperty("java.home"))
273-
}
274-
}
275-
276-
tasks.register<Exec>("clearEmulatorAppData") {
277-
group = "emulator"
278-
279-
doFirst {
280-
commandLine("${project.projectDir}/development/scripts/clear_app_data.sh")
281-
282-
environment("ANDROID_HOME", android.sdkDirectory.absolutePath)
283-
environment("JAVA_HOME", System.getProperty("java.home"))
284-
}
285-
}

app/development/DEVELOPMENT.md

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55
It is possible to install and run Seedvault in an emulator. This is likely the path of least resistance, since you don't need to build AOSP from source to make and test code changes.
66

77
It's also helpful for quickly testing Seedvault on newer versions of Android.
8-
Please note that this process has only been tested on Linux.
8+
9+
Please note that this process has only been tested on Linux. If the scripts break with newer versions, try looking at the changes made to the pipeline defined in [.cirrus.yaml](../../.cirrus.yml).
910

1011
### Setup
1112

1213
After opening the project in Android Studio, try running the `app:provisionEmulator` Gradle task.
1314

14-
This task runs the script in `scripts/provision_emulator.sh`:
15-
16-
```bash
17-
./app/development/scripts/provision_emulator.sh "seedvault" "system-images;android-33;google_apis;x86_64"
18-
```
15+
This task runs the script in `scripts/provision_emulator.sh`
1916

2017
### Starting the emulator
2118

@@ -26,17 +23,6 @@ This task runs the script in `scripts/start_emulator.sh`:
2623

2724
```bash
2825
./app/development/scripts/start_emulator.sh "seedvault"
29-
```
30-
31-
### Testing changes
32-
33-
Once the emulator is provisioned and running, you should be able to use the `app:installEmulatorRelease`
34-
Gradle task to install updates.
35-
36-
This task depends on `app:assembleRelease` and runs the script in `scripts/install_app.sh`:
37-
38-
```bash
39-
./app/development/scripts/install_app.sh
4026
```
4127

4228
There's also an Android Studio [runtime configuration](https://developer.android.com/studio/run/rundebugconfig) `app-emulator` which will build, install, and automatically launch the `com.stevesoltys.seedvault.settings.SettingsActivity` as if you clicked `Backup` in settings.

app/development/scripts/clear_app_data.sh

Lines changed: 0 additions & 26 deletions
This file was deleted.

app/development/scripts/install_app.sh

Lines changed: 0 additions & 36 deletions
This file was deleted.

app/development/scripts/provision_emulator.sh

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ SYSTEM_IMAGE=$2
2121

2222
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
2323

24+
# replicates steps found in .cirrus.yml
25+
2426
echo "Downloading system image..."
2527
yes | "$ANDROID_HOME"/cmdline-tools/latest/bin/sdkmanager --install "$SYSTEM_IMAGE"
2628

@@ -58,46 +60,56 @@ fi
5860

5961
ADB="$ANDROID_HOME/platform-tools/adb -s $EMULATOR_DEVICE_NAME"
6062

63+
echo "Downloading seedvault test data"
64+
65+
if [ ! -f backup.tar.gz ]; then
66+
echo "Downloading test backup..."
67+
wget https://github.com/seedvault-app/seedvault-test-data/releases/download/3/backup.tar.gz
68+
fi
69+
6170
echo "Waiting for emulator to boot..."
62-
$ADB wait-for-device shell "while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;"
71+
$ADB wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
6372

6473
echo "Provisioning emulator for write access to '/system'..."
6574
$ADB root
66-
sleep 3 # wait for adb to restart
75+
sleep 5 # wait for adb to restart
6776
$ADB remount # remount /system as writable
68-
69-
echo "Rebooting emulator..."
70-
$ADB reboot # need to reboot first time we remount
71-
$ADB wait-for-device shell "while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;"
72-
73-
echo "Provisioning emulator for Seedvault..."
74-
"$SCRIPT_DIR"/install_app.sh
75-
76-
echo "Rebooting emulator..."
7777
$ADB reboot
78-
$ADB wait-for-device shell "while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;"
78+
$ADB wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
79+
$ADB root
80+
sleep 5
81+
$ADB remount
82+
sleep 5
7983

80-
echo "Disabling backup..."
81-
$ADB shell bmgr enable false
84+
echo "Installing Seedvault"
8285

83-
echo "Downloading and extracting test backup to '/sdcard/seedvault_baseline'..."
86+
com1='while [[ -z $('
87+
com2=' shell mount | grep "/system " | grep "(rw,") ]]; do sleep 1; done;'
88+
timeout 180s bash -c "${com1}${ADB}${com2}";
89+
$ADB wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
8490

85-
if [ ! -f backup.tar.gz ]; then
86-
echo "Downloading test backup..."
87-
wget --quiet https://github.com/seedvault-app/seedvault-test-data/releases/download/3/backup.tar.gz
88-
fi
91+
$ADB shell mkdir -p /sdcard/seedvault_baseline
92+
$ADB push backup.tar.gz /sdcard/seedvault_baseline/backup.tar.gz
93+
$ADB shell tar xzf /sdcard/seedvault_baseline/backup.tar.gz --directory=/sdcard/seedvault_baseline
8994

90-
$ADB root
91-
sleep 3 # wait for adb to restart
92-
$ADB push backup.tar.gz /sdcard
93-
rm backup.tar.gz
95+
ROOT_PROJECT_DIR=$SCRIPT_DIR/../../..
9496

95-
$ADB wait-for-device
96-
$ADB shell mkdir -p /sdcard/seedvault_baseline
97-
$ADB shell tar xzf /sdcard/backup.tar.gz --directory=/sdcard/seedvault_baseline
98-
$ADB shell rm /sdcard/backup.tar.gz
97+
$ADB shell mkdir -p /system/priv-app/Seedvault
98+
$ADB push "$ROOT_PROJECT_DIR"/app/build/outputs/apk/release/app-release.apk /system/priv-app/Seedvault/Seedvault.apk
99+
$ADB push "$ROOT_PROJECT_DIR"/permissions_com.stevesoltys.seedvault.xml /system/etc/permissions/privapp-permissions-seedvault.xml
100+
$ADB push "$ROOT_PROJECT_DIR"/allowlist_com.stevesoltys.seedvault.xml /system/etc/sysconfig/allowlist-seedvault.xml
101+
102+
# uncomment to enable installing contactsbackup
103+
# $ADB shell mkdir -p /system/priv-app/ContactsBackup;
104+
# $ADB push "$ROOT_PROJECT_DIR"/contactsbackup/build/outputs/apk/release/contactsbackup-release.apk /system/priv-app/ContactsBackup/contactsbackup.apk
105+
# $ADB push "$ROOT_PROJECT_DIR"/contactsbackup/default-permissions_org.calyxos.backup.contacts.xml /system/etc/default-permissions/default-permissions_org.calyxos.backup.contacts.xml
99106

100-
# sometimes a system dialog (e.g. launcher stopped) is showing and taking focus
101-
$ADB shell am broadcast -a android.intent.action.CLOSE_SYSTEM_DIALOGS
107+
$ADB shell bmgr enable true
108+
$ADB reboot
109+
$ADB wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
110+
sleep 15 # wait for android to recognize new transport
111+
$ADB shell bmgr transport com.stevesoltys.seedvault.transport.ConfigurableBackupTransport
112+
$ADB reboot
113+
$ADB wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
102114

103115
echo "Emulator '$EMULATOR_NAME' has been provisioned with Seedvault!"

0 commit comments

Comments
 (0)