Skip to content

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

Add Windows (PowerShell) versions of the scripts

pananon00b82cea45dc
diff --git a/README.md b/README.md
index 7ab7c1b4a..8d19b7b83 100644
--- a/README.md
+++ b/README.md
@@ -61,6 +61,22 @@ TV_HOST=192.168.1.50 launcher/build-and-install.sh
Needs JDK 17 and the Android SDK (platform 34, build-tools 34.0.0). On macOS:
`brew install openjdk@17 android-commandlinetools && sdkmanager "platforms;android-34" "build-tools;34.0.0"`.
+### Windows
+
+PowerShell versions of the scripts sit next to the bash ones. With Android Studio installed, nothing
+else is needed: the script uses Android Studio's bundled JDK and the default SDK location, and Gradle
+downloads platform 34 and build-tools 34.0.0 on the first build if the SDK licence is accepted.
+
+```powershell
+python -m venv tools\venv; tools\venv\Scripts\python.exe -m pip install -r tools\requirements.txt
+powershell -ExecutionPolicy Bypass -File launcher\build-and-install.ps1 -TvHost 192.168.1.50
+powershell -ExecutionPolicy Bypass -File tools\disable.ps1 -TvHost 192.168.1.50 examples\xiaomi-mi-tv-4a\debloat.txt
+powershell -ExecutionPolicy Bypass -File tools\restore.ps1 -TvHost 192.168.1.50 examples\xiaomi-mi-tv-4a\debloat.txt
+```
+
+`build-and-install.ps1` stops before touching the stock launcher if the install or setting the new
+home screen fails.
+
## Talking to the TV by hand
```bash
@@ -75,6 +91,9 @@ tools/restore.sh examples/xiaomi-mi-tv-4a/debloat.txt # undo it, restore
### Gotchas we hit
+- **Windows PowerShell 5.1 prepends a byte-order mark** to text piped into a native program, which
+ turned the first `--batch` command into `pm` ("inaccessible or not found"). `tools/tv.py` now
+ reads stdin as `utf-8-sig`, and the `.ps1` scripts pipe UTF-8 without a BOM.
- **macOS: `adb connect` says "No route to host"** while the port is clearly open. Recent macOS
treats the Google-signed `adb` as its own app under Local Network privacy and silently blocks it.
`tools/tv.py` avoids the binary entirely.
diff --git a/launcher/build-and-install.ps1 b/launcher/build-and-install.ps1
new file mode 100644
index 000000000..eaab3dc74
--- /dev/null
+++ b/launcher/build-and-install.ps1
@@ -0,0 +1,46 @@
+# Windows version of build-and-install.sh: build the launcher APK and install it on the TV as the
+# default home screen. Uses Android Studio's bundled JDK and the default SDK location unless
+# JAVA_HOME / ANDROID_HOME are set.
+#
+# Usage: launcher\build-and-install.ps1 -TvHost 192.168.1.50 [-StockLauncher com.google.android.tvlauncher]
+param(
+ [string]$TvHost = $env:TV_HOST,
+ [string]$StockLauncher = 'com.google.android.tvlauncher'
+)
+$ErrorActionPreference = 'Stop'
+# Pipe plain UTF-8 to native commands; the default here prepends a BOM that corrupts the first command.
+$OutputEncoding = New-Object System.Text.UTF8Encoding $false
+if (-not $TvHost) { throw 'pass -TvHost <tv ip> or set $env:TV_HOST' }
+$env:TV_HOST = $TvHost
+Set-Location $PSScriptRoot
+
+if (-not $env:JAVA_HOME -or -not (Test-Path "$env:JAVA_HOME\bin\java.exe")) {
+ $jbr = Get-ChildItem 'C:\Program Files\Android' -Directory -ErrorAction SilentlyContinue |
+ ForEach-Object { Join-Path $_.FullName 'jbr' } | Where-Object { Test-Path "$_\bin\java.exe" } | Select-Object -First 1
+ if (-not $jbr) { throw 'Set JAVA_HOME to a JDK 17+ (Android Studio ships one in its jbr folder)' }
+ $env:JAVA_HOME = $jbr
+}
+$sdk = if ($env:ANDROID_HOME) { $env:ANDROID_HOME } else { "$env:LOCALAPPDATA\Android\Sdk" }
+if (-not (Test-Path local.properties)) {
+ "sdk.dir=$($sdk -replace '\\', '\\')" | Out-File -Encoding ascii local.properties
+}
+
+.\gradlew.bat assembleDebug -q --console=plain
+if ($LASTEXITCODE -ne 0) { throw 'Gradle build failed' }
+
+$py = '..\tools\venv\Scripts\python.exe'
+$apk = 'app\build\outputs\apk\debug\app-debug.apk'
+& $py -I ..\tools\b64push.py $apk /data/local/tmp/tvhome.apk
+if ($LASTEXITCODE -ne 0) { throw 'APK upload failed' }
+$out = & $py -I ..\tools\tv.py 'pm install -r /data/local/tmp/tvhome.apk; rm -f /data/local/tmp/tvhome.apk'
+Write-Host $out
+if ("$out" -notmatch 'Success') { throw 'pm install failed; the stock launcher was left untouched' }
+$out = & $py -I ..\tools\tv.py 'cmd package set-home-activity --user 0 com.gathin.tvhome'
+Write-Host $out
+if ("$out" -match 'Error') { throw 'could not set the new launcher as home; the stock launcher was left untouched' }
+@(
+ 'pm grant com.gathin.tvhome android.permission.ACCESS_FINE_LOCATION 2>/dev/null; echo location-granted',
+ 'cmd package set-home-activity --user 0 com.gathin.tvhome',
+ "pm disable-user --user 0 $StockLauncher"
+) | & $py -I ..\tools\tv.py --batch
+Write-Host 'Installed. Press Home on the remote to see it.'
diff --git a/tools/disable.ps1 b/tools/disable.ps1
new file mode 100644
index 000000000..89962bf8e
--- /dev/null
+++ b/tools/disable.ps1
@@ -0,0 +1,22 @@
+# Windows version of disable.sh: disable every package listed in a debloat file on the TV
+# (one package per line, # comments allowed). Packages are disabled for user 0, never uninstalled.
+# Undo with tools\restore.ps1 <same file>.
+#
+# Usage: tools\disable.ps1 -TvHost 192.168.1.50 examples\xiaomi-mi-tv-4a\debloat.txt
+param(
+ [Parameter(Mandatory = $true, Position = 0)][string]$List,
+ [string]$TvHost = $env:TV_HOST
+)
+$ErrorActionPreference = 'Stop'
+# Pipe plain UTF-8 to native commands; the default here prepends a BOM that corrupts the first command.
+$OutputEncoding = New-Object System.Text.UTF8Encoding $false
+$repo = Split-Path -Parent $PSScriptRoot
+$List = (Resolve-Path $List).Path
+$py = Join-Path $repo 'tools\venv\Scripts\python.exe'
+if (-not (Test-Path $py)) { throw 'run: python -m venv tools\venv; tools\venv\Scripts\python.exe -m pip install -r tools\requirements.txt' }
+if (-not $TvHost) { throw 'pass -TvHost <tv ip> or set $env:TV_HOST' }
+$env:TV_HOST = $TvHost
+
+$pkgs = Get-Content $List | ForEach-Object { ($_ -replace '#.*$', '').Trim() } | Where-Object { $_ }
+$cmds = @($pkgs | ForEach-Object { "pm disable-user --user 0 $_" }) + 'pm list packages -d'
+$cmds | & $py -I (Join-Path $repo 'tools\tv.py') --batch
diff --git a/tools/restore.ps1 b/tools/restore.ps1
new file mode 100644
index 000000000..8bcfc4a0f
--- /dev/null
+++ b/tools/restore.ps1
@@ -0,0 +1,28 @@
+# Windows version of restore.sh: re-enable every package listed in a debloat file, restore the
+# stock launcher as home and reset animation scales. Pass the same list you used with disable.ps1.
+#
+# Usage: tools\restore.ps1 -TvHost 192.168.1.50 examples\xiaomi-mi-tv-4a\debloat.txt [-Stock stock.launcher.package]
+param(
+ [Parameter(Mandatory = $true, Position = 0)][string]$List,
+ [string]$Stock = 'com.google.android.tvlauncher',
+ [string]$TvHost = $env:TV_HOST
+)
+$ErrorActionPreference = 'Stop'
+# Pipe plain UTF-8 to native commands; the default here prepends a BOM that corrupts the first command.
+$OutputEncoding = New-Object System.Text.UTF8Encoding $false
+$repo = Split-Path -Parent $PSScriptRoot
+$List = (Resolve-Path $List).Path
+$py = Join-Path $repo 'tools\venv\Scripts\python.exe'
+if (-not $TvHost) { throw 'pass -TvHost <tv ip> or set $env:TV_HOST' }
+$env:TV_HOST = $TvHost
+
+$pkgs = Get-Content $List | ForEach-Object { ($_ -replace '#.*$', '').Trim() } | Where-Object { $_ }
+$cmds = @($pkgs | ForEach-Object { "pm enable $_" }) + @(
+ "pm enable $Stock",
+ "cmd package set-home-activity --user 0 $Stock",
+ 'settings put global window_animation_scale 1.0',
+ 'settings put global transition_animation_scale 1.0',
+ 'settings put global animator_duration_scale 1.0',
+ 'pm list packages -d'
+)
+$cmds | & $py -I (Join-Path $repo 'tools\tv.py') --batch
diff --git a/tools/tv.py b/tools/tv.py
index 6336f3cc6..cd45ce079 100644
--- a/tools/tv.py
+++ b/tools/tv.py
@@ -55,7 +55,9 @@ def main():
dev.pull(args[1], args[2])
print(f"pulled {args[1]} -> {args[2]}")
elif args[0] == "--batch":
- # one shell command per stdin line, each run separately on the same connection
+ # one shell command per stdin line, each run separately on the same connection.
+ # utf-8-sig drops the BOM Windows PowerShell may prepend to piped stdin.
+ sys.stdin.reconfigure(encoding="utf-8-sig")
for line in sys.stdin:
line = line.strip()
if not line or line.startswith("#"):