kaipee/android-backup-removal

Keycode sending on data backup

tigattack opened this issue · 2 comments

I noticed the commented-out keycode commands in backup L52-56.

Unsure if you had plans, but I made it work this way:

# Run backup in separate process
adb backup -f "$APP".ab -apk -shared "PKG_NAME" &
# Get backup PID
pid=$!
# Trap interrupt (ctrl+c) so we can stop the backup if script is stopped
trap "kill $pid" INT

echo "Data backup PID: $pid"
echo "Accepting backup..."

# Accept backup prompt, allowing for a short delay
sleep 1
adb shell input keyevent KEYCODE_TAB
adb shell input keyevent KEYCODE_TAB
# Sleep to allow for delay in keyboard to popping up
sleep 1
adb shell input keyevent KEYCODE_BACK
adb shell input keyevent KEYCODE_TAB
adb shell input keyevent KEYCODE_ENTER

# Wait for backup to complete
wait $pid
rc=$?

echo "Data backup complete. Exit code: $rc"

### This line must be replaced since the former `if [ $?..` is no longer relevant
if [ $rc -eq 0 ]; then

Exactly the same snippet, bar "backup" output messages, can be applied to the restore script.

Thanks @tigattack , yeah I was playing around with it but never tried any further to get it working.
Go ahead and submit a pull request and I'll merge it in.

I actually just went ahead and added it in. Tested and works great, thanks!