Add a settings import/export receiver

If you install a signed release build and want to switch to an unsigned
debug build, that involves an uninstall and reinstall, which by default
will lose your configuration. Modify scripts/pull_config.sh and
scripts/push_config.sh so it works on release builds, not just debug
builds, and update README.md to tell you to export your config before
doing this kind of upgrade.
This commit is contained in:
James Babcock committed 2026-08-30 12:25:06 -07:00
1 parent f4c43090f5
commit 3e8be93833
7 files changed
+271 -6

No files matched your search

+30 -4
View File
@@ -3,12 +3,21 @@
# Usage: push_config.sh [input-file] (default: faceclaw_settings.xml)
# Validates the XML, force-stops the app (so a running instance doesn't
# overwrite the pushed file from its in-memory prefs), then installs it.
#
# Uses run-as on debuggable (dev) builds. On release builds, where run-as is
# refused, falls back to the FaceclawSettingsPortReceiver broadcast: the file
# is staged in the app's external files dir and the receiver (adb-only; see
# its javadoc) validates and installs it, then exits so the next launch
# re-reads settings from disk.
set -euo pipefail
source "$(cd "$(dirname "$0")" && pwd)/adbutil.sh"
PACKAGE=com.faceclaw.app
PREFS=shared_prefs/faceclaw_settings.xml
IN="${1:-faceclaw_settings.xml}"
STAGE=/data/local/tmp/faceclaw_settings_push.xml
IMPORT_REMOTE=/sdcard/Android/data/$PACKAGE/files/faceclaw-settings-import.xml
if [ ! -f "$IN" ]; then
echo "Error: $IN not found" >&2
@@ -24,8 +33,25 @@ else
exit 1
fi
MODE="$(adb_preflight "$PACKAGE")"
adb shell am force-stop "$PACKAGE"
adb push "$IN" "$STAGE"
adb shell run-as "$PACKAGE" cp "$STAGE" "$PREFS"
adb shell rm "$STAGE"
echo "Pushed $IN to $PREFS (app was force-stopped; relaunch it to pick up the new settings)"
if [ "$MODE" = debug ]; then
adb push "$IN" "$STAGE"
adb shell run-as "$PACKAGE" cp "$STAGE" "$PREFS"
adb shell rm "$STAGE"
echo "Pushed $IN to $PREFS (app was force-stopped; relaunch it to pick up the new settings)"
else
echo "Release build installed; using settings-port broadcast..."
adb push "$IN" "$IMPORT_REMOTE" >/dev/null
RESULT="$(adb shell am broadcast -n "$PACKAGE/.FaceclawSettingsPortReceiver" \
-a com.faceclaw.app.SETTINGS_IMPORT)"
if ! printf '%s' "$RESULT" | grep -q 'data="imported:'; then
printf '%s\n' "$RESULT" >&2
adb shell rm -f "$IMPORT_REMOTE"
echo "Error: import broadcast did not report success (old app version?)" >&2
exit 1
fi
echo "Pushed $IN to $PREFS via settings-port import (previous settings kept as $PREFS.bak)"
fi