Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

launcher: the install stops unless the TV shows the WRITE_SECURE_SETTINGS state it asked for

Rasmus Kjær Damgaard91d3a10fae6b
diff --git a/launcher/build-and-install.ps1 b/launcher/build-and-install.ps1
index f4e6bd599..6dd519db5 100644
--- a/launcher/build-and-install.ps1
+++ b/launcher/build-and-install.ps1
@@ -157,9 +157,16 @@ if ($InputKeyService) { Enable-Service 'InputKeyService' }
if ($HomeKeyService) { Enable-Service 'HomeKeyService' }
# The grant follows the switch on every install: pm install -r keeps a grant, so a run without the switch takes it
# back. WRITE_SECURE_SETTINGS opens every secure and global setting, not only the accessibility list.
+# tv.py does not hand back the TV shell's exit status, so each side prints its marker only once the TV shows the
+# state it wants, and the install stops when the marker is missing (see build-and-install.sh).
+$secure = 'android.permission.WRITE_SECURE_SETTINGS'
if ($RestoreKeyServices) {
- 'pm grant com.gathin.tvhome android.permission.WRITE_SECURE_SETTINGS && echo restore-granted' | & $py -I ..\tools\tv.py --batch
+ $step = "pm grant com.gathin.tvhome $secure && echo restore-granted"; $mark = 'restore-granted'
} else {
- 'pm revoke com.gathin.tvhome android.permission.WRITE_SECURE_SETTINGS 2>/dev/null; echo secure-settings-revoked' | & $py -I ..\tools\tv.py --batch
+ $step = "pm revoke com.gathin.tvhome $secure; s=`$(dumpsys package com.gathin.tvhome); case `"`$s`" in *`"${secure}: granted=true`"*) ;; *`"$secure`"*) echo secure-settings-revoked ;; esac"
+ $mark = 'secure-settings-revoked'
}
+$out = ($step | & $py -I ..\tools\tv.py --batch) -join "`n"
+Write-Host $out
+if ($out -notmatch [regex]::Escape($mark)) { throw "WRITE_SECURE_SETTINGS is not in the state this install asked for ($mark missing)" }
Write-Host 'Installed. Press Home on the remote to see it.'
diff --git a/launcher/build-and-install.sh b/launcher/build-and-install.sh
index b9b32821c..ba29e618e 100755
--- a/launcher/build-and-install.sh
+++ b/launcher/build-and-install.sh
@@ -225,9 +225,18 @@ if [ "${INPUT_KEY_SERVICE:-0}" = 1 ]; then enable_service InputKeyService; fi
if [ "${HOME_KEY_SERVICE:-0}" = 1 ]; then enable_service HomeKeyService; fi
# The grant follows the switch on every install: pm install -r keeps a grant, so a run without the switch takes it
# back. WRITE_SECURE_SETTINGS opens every secure and global setting, not only the accessibility list.
+# tv.py does not hand back the TV shell's exit status, so each side prints its marker only once the TV shows the
+# state it wants, and the install stops when the marker is missing. The revoke is judged by the package's
+# permission state rather than pm's exit status, so a permission that was never granted counts as revoked, and a
+# dumpsys that does not list the permission at all prints nothing.
+SECURE=android.permission.WRITE_SECURE_SETTINGS
if [ "${RESTORE_KEY_SERVICES:-0}" = 1 ]; then
- "$PY" -I ../tools/tv.py "pm grant com.gathin.tvhome android.permission.WRITE_SECURE_SETTINGS && echo restore-granted"
+ STEP="pm grant com.gathin.tvhome $SECURE && echo restore-granted"; MARK=restore-granted
else
- "$PY" -I ../tools/tv.py "pm revoke com.gathin.tvhome android.permission.WRITE_SECURE_SETTINGS 2>/dev/null; echo secure-settings-revoked"
+ STEP="pm revoke com.gathin.tvhome $SECURE; s=\$(dumpsys package com.gathin.tvhome); case \"\$s\" in *\"$SECURE: granted=true\"*) ;; *\"$SECURE\"*) echo secure-settings-revoked ;; esac"
+ MARK=secure-settings-revoked
fi
+OUT=$("$PY" -I ../tools/tv.py "$STEP")
+echo "$OUT"
+case "$OUT" in *"$MARK"*) ;; *) echo "ERROR: WRITE_SECURE_SETTINGS is not in the state this install asked for ($MARK missing)" >&2; exit 1 ;; esac
echo "Installed. Press Home on the remote to see it."