Skip to content

v0.4

Choose a tag to compare

@github-actions github-actions released this 10 Nov 21:26
· 57 commits to main since this release
8fb245a

AltShift v0.4 — hardware keyboard driver release for Android 8.0+ since v0.3.2. It replaces the previous foreground-service switching loop with a process-wide KeyboardMonitor, making detach switching independent of WRITE_SECURE_SETTINGS via IME-session APIs and adopting a 100% universal AOSP architecture with no hardcoded Gboard or OEM branches. It also introduces the 420dp tablet Dynamic Island, SwitchBackActivity picker trampoline, standardized IMPORTANCE_HIGH notification channels, a single-IME lockout warning, an About dialog with live hardware diagnostics, and a decoupled test/release CI pipeline.


🚀 Switching Core, IME Session & Universal AOSP

  • HardwareInputService.KeyboardMonitor: Moves input-device monitoring out of the deleted KeyboardSwitchService foreground service (removing FOREGROUND_SERVICE / FOREGROUND_SERVICE_SPECIAL_USE and the disconnect deadlock) into an application-scoped singleton on a dedicated AltShift-Input HandlerThread. Observes InputDeviceListener and DEFAULT_INPUT_METHOD / ENABLED_INPUT_METHODS with a 150 ms debounce, surviving IME unbinding via WeakReference<HardwareInputService>.
  • Permission-independent detach & AOSP resolution: switchToSoftKeyboardFromIme() tries switchToPreviousInputMethod() (API 28+) then switchInputMethod(resolveSoftKeyboardId()) without requiring WRITE_SECURE_SETTINGS. resolveSoftKeyboardId() picks persisted previous_input_method (if enabled) or the first enabled non-AltShift IME—eliminating the hardcoded com.google.android.inputmethod.latin lookup.
  • Presence detection & boot guard: Splits cost between main-thread-safe isPhysicalKeyboardReported() and off-main-thread findPhysicalKeyboard() (enabled, non-virtual SOURCE_KEYBOARD without SOURCE_TOUCHSCREEN, plus KEYBOARD_TYPE_ALPHABETIC on API 28+). BootReceiver starts the monitor only when auto-switch is enabled and at least one recovery path (WRITE_SECURE_SETTINGS, overlay, or notifications) is available.
  • Fallback view & crash containment: view_ime_fallback renders only while detached (stranded hides "Switch keyboard" and shows "Open Keyboard Settings"); launchHotkeyApp() keeps zero-allocation array scanning; all IME writes serialize on SWITCH_LOCK with live hasSecureSettingsPermission() checks and try/catch (RuntimeException) isolation across InputConnection, Settings.Secure, WindowManager, and notifications.

🎨 Dynamic Island, Picker Trampoline & Dashboard

  • KeyboardPromptOverlay: Bottom-center TYPE_APPLICATION_OVERLAY capsule (minWidth=420dp, 24dp above WindowInsets bottom on API 30+ / navigation_bar_height on API 26–29) with 12,000 ms auto-dismiss, synchronous shown reset in dismiss() / removeFailedView(), and callback reuse on repeated show().
  • SwitchBackActivity trampoline: Transparent singleInstance (noHistory, excludeFromRecents, FLAG_NOT_TOUCHABLE) activity hosting a 1×1 InputClientView so showInputMethodPicker() succeeds after a 200 ms delay. Focus return posts the inactive alert only after deliberate picker dismissal; a 15 s timeout exits silently, and dismissing the Dynamic Island never notifies.
  • About diagnostics, onboarding & dashboard: AboutDialog shows BuildConfig version and off-main-thread InputDevice diagnostics (Unavailable on error) with GitHub and EXTRA_RERUN actions; onboarding gates Steps 1–2 if no alternative IME is enabled; MainActivity polls hasSecureSettingsPermission() (1,000 ms while resumed + onWindowFocusChanged()) and observes DEFAULT_INPUT_METHOD (removing the EXTRA_OPEN_IME_PICKER resume hack).

🛡️ Notifications & CI/CD

  • Canonical channels & alerts: NotificationChannels.initialize() creates IMPORTANCE_HIGH altshift_keyboard_alerts and altshift_safety_warnings on startup while deleting six legacy IDs (auto_switch, keyboard_state*, warning_channel*). KeyboardWarningNotification (ID 2001) warns when AltShift is the sole enabled IME; KeyboardNotification (ID 1001) posts from SwitchBackActivity.onPickerDismissed() and clears on detach or AltShift reactivation.
  • Decoupled CI/CD & R8 signing: .github/workflows/build.yml splits test (./gradlew test lintDebug, JDK 21) and tag-gated release (KEYSTORE_BASE64, assembleDebug assembleRelease, softprops/action-gh-release@v2). app/build.gradle enables R8 + shrinkResources, env-based signingConfigs.release, and AltShift-v<version>.apk artifact naming.

🧪 Build, Tests & Verification

  • Version & toolchain: versionCode 7, versionName '0.4' (AltShift-v0.4.apk / AltShift-v0.4-debug.apk). Toolchain: minSdk 26, targetSdk 34, Java 21, Gradle 8.9, AGP 8.7.3.
  • Automated checks: CI gates on ./gradlew test lintDebug covering ModelTest (cosmetic final cleanup only), TransliterationTableTest, ThemeModeTest, and KeyLabelFormatterTest JVM suites.
  • Manual verification scope: KeyboardMonitor debounce, overlay lifecycle, focus-based picker detection, channel migration, and permission revocation have no instrumentation tests and were verified manually across API 26–34.

📥 Installation

Asset Description
AltShift-v0.4.apk Release build, R8-minified, signed with the CI release keystore.
AltShift-v0.4-debug.apk Debug build, unminified, signed with the local debug key.
adb install -r AltShift-v0.4.apk
adb shell ime enable ru.b1sted.altshift/.service.HardwareInputService
adb shell ime set ru.b1sted.altshift/.service.HardwareInputService

Optional provisioning grants:

adb shell pm grant ru.b1sted.altshift android.permission.WRITE_SECURE_SETTINGS
adb shell pm grant ru.b1sted.altshift android.permission.POST_NOTIFICATIONS
adb shell appops set ru.b1sted.altshift SYSTEM_ALERT_WINDOW allow

Note: Debug and release APKs use different signing keys (adb uninstall ru.b1sted.altshift is required when switching between them). Uninstalling wipes altshift_prefs (allowBackup="false") and revokes WRITE_SECURE_SETTINGS; without it, detach still works via IME-session switching while reattach uses the Dynamic Island or notification.


🔨 Building from Source

Requires JDK 21, Android SDK Platform 34 (Build-Tools 34.0.0), and sdk.dir in local.properties:

./gradlew test lintDebug assembleDebug
# Or signed release (with KEYSTORE_FILE / KEYSTORE_PASSWORD / KEY_ALIAS / KEY_PASSWORD or scripts/build-release.sh):
./gradlew assembleRelease

⚠️ Notes & Limitations

  • Permission-gated recovery: Dynamic Island requires SYSTEM_ALERT_WINDOW; inactive/lockout alerts require POST_NOTIFICATIONS on Android 13+; autonomous attach switching requires WRITE_SECURE_SETTINGS (without it, reattach relies on the Dynamic Island, notification, or fallback view).
  • Picker & API-level fallbacks: SwitchBackActivity infers picker dismissal from focus return (OEM choosers that keep focus hit the 15 s silent timeout; the 200 ms delay targets AOSP). API 26–29 uses navigation_bar_height for overlay positioning, and API 26–27 cannot filter KEYBOARD_TYPE_ALPHABETIC.
  • Safety check & fixed UI scope: hasAlternativeInputMethod() is capability-blind (treats any enabled non-AltShift IME as a fallback); Dynamic Island placement (420dp minWidth, bottom-center, 12 s timeout) is fixed; ЙЦУКЕН remains the only non-Latin layout.
  • Test scope & state wipe: New runtime behaviors are manually verified rather than instrumentation-tested, and allowBackup="false" resets preferences, WRITE_SECURE_SETTINGS, and the remembered IME on uninstall or pm clear.

🛡️ Security & Analysis (AltShift-v0.4.apk)


Full Changelog: v0.3.2...v0.4