fix: Home button service filters keys only while Glass isn't Home #35

Merged
namillis merged 1 commit from fix/a11y-key-filtering into main 2026-11-25 19:41:20 +00:00
Owner

Fixes two bugs in the Home button service that #34 added. When Glass is already the default Home, the service now leaves other apps' keys alone, as if it were off. And in the 4 seconds after a volume change, Google TV Home showing up is sent back to Glass again. Gabriel (the repo owner) asked for this PR to be opened and merged without further review.

One commit: 0d5d21a, on top of current main 920db0d (the #34 merge).

Terms used below:

  • Home button service: the optional accessibility service from #34. When Glass is not the default Home, it catches the remote's Home button and opens Glass. Long-press Home opens Recents; this PR doesn't change that.
  • Default Home: the app Android opens for Home. In Glass's own settings, Default home & backup > Default home has the ADB setup: over the TV's own debugging connection, it makes Glass the default Home and disables Google TV Home. Its restore button turns Google TV Home back on.
  • Stock launcher: the TV's built-in home screen (com.google.android.apps.tv.launcherx on Google TV, com.google.android.tvlauncher on older Android TV).
  • Key filtering: the accessibility mode that sends every key press on the TV to the service before any app gets it. Projectivy, CleanYourTV and Key Mapper users report that on many TVs a held volume key moves one step per press while any service filters keys.
  • Volume pause: after each volume change, #34 turns key filtering off for 4 seconds so a held volume key ramps. Filtering stays on the rest of the time while Glass isn't Home.

What changed

  • Filtering only while it is needed (HomeButtonService.java, res/xml/home_button_service.xml). In #34 the service's config turned key filtering on, and the service turned it on again every time it started, even when Glass was already the default Home. Then the service could do nothing with Home, but every key still went through it, with the volume-hold problem above. Now the config leaves filtering off. The service turns it on only while Glass is not the default Home and no volume pause is running, and calls Android's setServiceInfo only when that answer changes.
  • Noticing when the default Home changes (HomeButtonService.java, LauncherActivity.java). The service checks the default Home when it starts, when a stock launcher window appears, and after each Home press it handles. That last check also covers a Home app chosen in Android's own settings. It also checks when the ADB setup or restore finishes and when Glass's settings open, through a new HomeButtonService.refreshIfRunning().
  • Home during the volume pause (HomeButtonService.java). In #34 the pause also switched off the part that sends a stock launcher window back to Glass. A Home press during the pause reaches Google TV Home, because filtering is off then. So in those 4 seconds Google TV Home stayed on screen. That part now depends only on Glass not being the default Home.
  • Rule and tests (HomeOverridePlan.java, HomeOverridePlanTest.java). The rule is the new HomeOverridePlan.wantsKeyFiltering(glassIsHome, volumePaused): on only when Glass is not Home and there is no pause. Four new tests cover it, one of them checking that HomeOverridePlan.shouldReclaim still sends Google TV Home back to Glass during a pause.
  • Docs (CHANGELOG.md). The Unreleased Home button entry says filtering stays off when Glass is Home, and that Home during the pause comes back to Glass.

No settings, screens or permissions change, so there are no screenshots.

How it was checked

  • On the head, each as its own Gradle run: 312 unit tests pass (4 new), 0 failed. Lint has 0 errors and 9 warnings, the same 9 as main. assembleDebug builds.

  • Emulator (Android TV 14, API 34). "Filtering on" means dumpsys accessibility lists Android's key filter (KeyboardInterceptor). The stock launcher was opened with am start, the same path an app's Home request or a Home press during the pause takes:

    State Filtering Stock launcher opened from Glass
    Stock launcher is the default Home on Glass comes back
    Right after a volume press off; back on at the next check, about 6 s later (the pause is 4 s) Glass comes back
    Stock launcher disabled, so Glass is Home (what the ADB setup does), then Glass settings opened turns off not tried
    Service switched on while Glass is Home stays off (checked at 0.3, 1 and 3 s) not tried
    Stock launcher enabled again and made Home (what the restore does) on Glass comes back
  • The #34 build: these checks ran on 054ab85, which has the same files as main's #34 code. With Glass as Home, filtering was on, and opening the stock launcher during the volume pause left it in front.

Not covered yet

  • A real remote: the Home key itself, holding volume and long-press Home. The emulator's injected keys skip key filtering, so these were not exercised.
  • The ADB setup and restore buttons themselves. Their effect was reproduced with pm disable-user and pm enable, and the re-check was triggered by opening settings.
  • Choosing a Home app in Android's own settings.
  • A Google TV device where launcherx is the stock launcher.

Pattern harvest

Rule candidate: a mode that costs every other app something (here, key filtering) should be requested at runtime from one rule that says when it is needed, with every state the rule depends on re-checked when it can change. It shouldn't be declared always-on in a config file.

Trying it

Debug APK in Gabriel's Downloads: GlassLauncher-a11y-key-filtering-0d5d21a-debug.apk, sha256 b92188339f1c895488bb26b31f07e4008cc30be0e83ce6b423965404c492b36a, built from the head. On a TV where Glass is the default Home, turn the service on and hold volume in a video app: it should ramp the same as with the service off.

Fixes two bugs in the Home button service that [#34](https://git.namillis.me/namillis/GlassLauncherTV/pulls/34) added. When Glass is already the default Home, the service now leaves other apps' keys alone, as if it were off. And in the 4 seconds after a volume change, Google TV Home showing up is sent back to Glass again. Gabriel (the repo owner) asked for this PR to be opened and merged without further review. **One commit:** `0d5d21a`, on top of current main `920db0d` (the #34 merge). Terms used below: - **Home button service:** the optional accessibility service from #34. When Glass is not the default Home, it catches the remote's Home button and opens Glass. Long-press Home opens Recents; this PR doesn't change that. - **Default Home:** the app Android opens for Home. In Glass's own settings, **Default home & backup > Default home** has the **ADB setup**: over the TV's own debugging connection, it makes Glass the default Home and disables Google TV Home. Its **restore** button turns Google TV Home back on. - **Stock launcher:** the TV's built-in home screen (`com.google.android.apps.tv.launcherx` on Google TV, `com.google.android.tvlauncher` on older Android TV). - **Key filtering:** the accessibility mode that sends every key press on the TV to the service before any app gets it. Projectivy, CleanYourTV and Key Mapper users report that on many TVs a held volume key moves one step per press while any service filters keys. - **Volume pause:** after each volume change, #34 turns key filtering off for 4 seconds so a held volume key ramps. Filtering stays on the rest of the time while Glass isn't Home. ## What changed - **Filtering only while it is needed (`HomeButtonService.java`, `res/xml/home_button_service.xml`).** In #34 the service's config turned key filtering on, and the service turned it on again every time it started, even when Glass was already the default Home. Then the service could do nothing with Home, but every key still went through it, with the volume-hold problem above. Now the config leaves filtering off. The service turns it on only while Glass is not the default Home and no volume pause is running, and calls Android's `setServiceInfo` only when that answer changes. - **Noticing when the default Home changes (`HomeButtonService.java`, `LauncherActivity.java`).** The service checks the default Home when it starts, when a stock launcher window appears, and after each Home press it handles. That last check also covers a Home app chosen in Android's own settings. It also checks when the ADB setup or restore finishes and when Glass's settings open, through a new `HomeButtonService.refreshIfRunning()`. - **Home during the volume pause (`HomeButtonService.java`).** In #34 the pause also switched off the part that sends a stock launcher window back to Glass. A Home press during the pause reaches Google TV Home, because filtering is off then. So in those 4 seconds Google TV Home stayed on screen. That part now depends only on Glass not being the default Home. - **Rule and tests (`HomeOverridePlan.java`, `HomeOverridePlanTest.java`).** The rule is the new `HomeOverridePlan.wantsKeyFiltering(glassIsHome, volumePaused)`: on only when Glass is not Home and there is no pause. Four new tests cover it, one of them checking that `HomeOverridePlan.shouldReclaim` still sends Google TV Home back to Glass during a pause. - **Docs (`CHANGELOG.md`).** The Unreleased Home button entry says filtering stays off when Glass is Home, and that Home during the pause comes back to Glass. No settings, screens or permissions change, so there are no screenshots. ## How it was checked - **On the head, each as its own Gradle run:** 312 unit tests pass (4 new), 0 failed. Lint has 0 errors and 9 warnings, the same 9 as main. `assembleDebug` builds. - **Emulator (Android TV 14, API 34).** "Filtering on" means `dumpsys accessibility` lists Android's key filter (`KeyboardInterceptor`). The stock launcher was opened with `am start`, the same path an app's Home request or a Home press during the pause takes: | State | Filtering | Stock launcher opened from Glass | |---|---|---| | Stock launcher is the default Home | on | Glass comes back | | Right after a volume press | off; back on at the next check, about 6 s later (the pause is 4 s) | Glass comes back | | Stock launcher disabled, so Glass is Home (what the ADB setup does), then Glass settings opened | turns off | not tried | | Service switched on while Glass is Home | stays off (checked at 0.3, 1 and 3 s) | not tried | | Stock launcher enabled again and made Home (what the restore does) | on | Glass comes back | - **The #34 build:** these checks ran on `054ab85`, which has the same files as main's #34 code. With Glass as Home, filtering was on, and opening the stock launcher during the volume pause left it in front. ## Not covered yet - A real remote: the Home key itself, holding volume and long-press Home. The emulator's injected keys skip key filtering, so these were not exercised. - The ADB setup and restore buttons themselves. Their effect was reproduced with `pm disable-user` and `pm enable`, and the re-check was triggered by opening settings. - Choosing a Home app in Android's own settings. - A Google TV device where `launcherx` is the stock launcher. ## Pattern harvest Rule candidate: a mode that costs every other app something (here, key filtering) should be requested at runtime from one rule that says when it is needed, with every state the rule depends on re-checked when it can change. It shouldn't be declared always-on in a config file. ## Trying it Debug APK in Gabriel's Downloads: `GlassLauncher-a11y-key-filtering-0d5d21a-debug.apk`, sha256 `b92188339f1c895488bb26b31f07e4008cc30be0e83ce6b423965404c492b36a`, built from the head. On a TV where Glass is the default Home, turn the service on and hold volume in a video app: it should ramp the same as with the service off.
Key filtering was requested in the service XML and turned on again on every
connect, even when Glass is already the default Home (the ADB setup). Then
the service could do nothing with Home, but every key still passed through
it and held volume keys stopped repeating. Filtering is now off in the XML
and requested at runtime only while HomeOverridePlan.wantsKeyFiltering says
so: Glass not Home, and no volume pause. The ADB setup, its restore and
opening settings ask the running service to re-check the default Home, and
so does each Home press it handles.

Also fixes the volume pause turning off the stock-launcher reclaim: a Home
press during the 4 s pause left the stock launcher in front. The reclaim now
depends only on Glass not being Home.

Four new HomeOverridePlan tests.
Author
Owner

Intent. Make the Home button service from #34 cost other apps nothing when it has nothing to do. When Glass is already the default Home, key filtering stays off, so holding volume works as if the service were off. Also, Google TV Home appearing during the 4-second volume pause is sent back to Glass again, as #34 meant it to be.

Not goals:

  • changing what Home, long-press Home or the volume pause do while Glass isn't the default Home;
  • new settings, screens or permissions;
  • the hold-Home Control Center (separate work);
  • a release.
**Intent.** Make the Home button service from #34 cost other apps nothing when it has nothing to do. When Glass is already the default Home, key filtering stays off, so holding volume works as if the service were off. Also, Google TV Home appearing during the 4-second volume pause is sent back to Glass again, as #34 meant it to be. **Not goals:** - changing what Home, long-press Home or the volume pause do while Glass isn't the default Home; - new settings, screens or permissions; - the hold-Home Control Center (separate work); - a release.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
namillis/GlassLauncherTV!35
No description provided.