Repository navigation
v0.4
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 deletedKeyboardSwitchServiceforeground service (removingFOREGROUND_SERVICE/FOREGROUND_SERVICE_SPECIAL_USEand the disconnect deadlock) into an application-scoped singleton on a dedicatedAltShift-InputHandlerThread. ObservesInputDeviceListenerandDEFAULT_INPUT_METHOD/ENABLED_INPUT_METHODSwith a150 msdebounce, surviving IME unbinding viaWeakReference<HardwareInputService>.- Permission-independent detach & AOSP resolution:
switchToSoftKeyboardFromIme()triesswitchToPreviousInputMethod()(API 28+) thenswitchInputMethod(resolveSoftKeyboardId())without requiringWRITE_SECURE_SETTINGS.resolveSoftKeyboardId()picks persistedprevious_input_method(if enabled) or the first enabled non-AltShift IME—eliminating the hardcodedcom.google.android.inputmethod.latinlookup. - Presence detection & boot guard: Splits cost between main-thread-safe
isPhysicalKeyboardReported()and off-main-threadfindPhysicalKeyboard()(enabled, non-virtualSOURCE_KEYBOARDwithoutSOURCE_TOUCHSCREEN, plusKEYBOARD_TYPE_ALPHABETICon API 28+).BootReceiverstarts 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_fallbackrenders only while detached (strandedhides "Switch keyboard" and shows "Open Keyboard Settings");launchHotkeyApp()keeps zero-allocation array scanning; all IME writes serialize onSWITCH_LOCKwith livehasSecureSettingsPermission()checks andtry/catch (RuntimeException)isolation acrossInputConnection,Settings.Secure,WindowManager, and notifications.
🎨 Dynamic Island, Picker Trampoline & Dashboard
KeyboardPromptOverlay: Bottom-centerTYPE_APPLICATION_OVERLAYcapsule (minWidth=420dp,24dpaboveWindowInsetsbottom on API 30+ /navigation_bar_heighton API 26–29) with12,000 msauto-dismiss, synchronousshownreset indismiss()/removeFailedView(), and callback reuse on repeatedshow().SwitchBackActivitytrampoline: TransparentsingleInstance(noHistory,excludeFromRecents,FLAG_NOT_TOUCHABLE) activity hosting a 1×1InputClientViewsoshowInputMethodPicker()succeeds after a200 msdelay. Focus return posts the inactive alert only after deliberate picker dismissal; a15 stimeout exits silently, and dismissing the Dynamic Island never notifies.- About diagnostics, onboarding & dashboard:
AboutDialogshowsBuildConfigversion and off-main-threadInputDevicediagnostics (Unavailableon error) with GitHub andEXTRA_RERUNactions; onboarding gates Steps 1–2 if no alternative IME is enabled;MainActivitypollshasSecureSettingsPermission()(1,000 mswhile resumed +onWindowFocusChanged()) and observesDEFAULT_INPUT_METHOD(removing theEXTRA_OPEN_IME_PICKERresume hack).
🛡️ Notifications & CI/CD
- Canonical channels & alerts:
NotificationChannels.initialize()createsIMPORTANCE_HIGHaltshift_keyboard_alertsandaltshift_safety_warningson startup while deleting six legacy IDs (auto_switch,keyboard_state*,warning_channel*).KeyboardWarningNotification(ID2001) warns when AltShift is the sole enabled IME;KeyboardNotification(ID1001) posts fromSwitchBackActivity.onPickerDismissed()and clears on detach or AltShift reactivation. - Decoupled CI/CD & R8 signing:
.github/workflows/build.ymlsplitstest(./gradlew test lintDebug, JDK 21) and tag-gatedrelease(KEYSTORE_BASE64,assembleDebug assembleRelease,softprops/action-gh-release@v2).app/build.gradleenables R8 +shrinkResources, env-basedsigningConfigs.release, andAltShift-v<version>.apkartifact 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 lintDebugcoveringModelTest(cosmeticfinalcleanup only),TransliterationTableTest,ThemeModeTest, andKeyLabelFormatterTestJVM suites. - Manual verification scope:
KeyboardMonitordebounce, 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.HardwareInputServiceOptional 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 allowNote: Debug and release APKs use different signing keys (
adb uninstall ru.b1sted.altshiftis required when switching between them). Uninstalling wipesaltshift_prefs(allowBackup="false") and revokesWRITE_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 requirePOST_NOTIFICATIONSon Android 13+; autonomous attach switching requiresWRITE_SECURE_SETTINGS(without it, reattach relies on the Dynamic Island, notification, or fallback view). - Picker & API-level fallbacks:
SwitchBackActivityinfers picker dismissal from focus return (OEM choosers that keep focus hit the15 ssilent timeout; the200 msdelay targets AOSP). API 26–29 usesnavigation_bar_heightfor overlay positioning, and API 26–27 cannot filterKEYBOARD_TYPE_ALPHABETIC. - Safety check & fixed UI scope:
hasAlternativeInputMethod()is capability-blind (treats any enabled non-AltShift IME as a fallback); Dynamic Island placement (420dpminWidth, bottom-center,12 stimeout) 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 orpm clear.
🛡️ Security & Analysis (AltShift-v0.4.apk)
- VirusTotal: Scan report
- Pithus: Static analysis
Full Changelog: v0.3.2...v0.4