Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/crowdin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Crowdin - sync translations

on:
push:
branches:
- 'develop'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

jobs:
synchronize-with-crowdin:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: crowdin action
uses: crowdin/github-action@v3
if: github.event.repository.fork == false
with:
upload_sources: true
upload_translations: false
download_translations: true
localization_branch_name: l10n/develop
create_pull_request: true
pull_request_title: 'New Crowdin Translations'
pull_request_body: 'New Crowdin translations by [Crowdin GH Action](https://github.com/crowdin/github-action)'
pull_request_base_branch_name: 'develop'
env:
# A classic GitHub Personal Access Token with the 'repo' scope selected (the user should have write access to the repository).
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# A numeric ID, found at https://crowdin.com/project/<projectName>/tools/api
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}

# Visit https://crowdin.com/settings#api-key to create this token
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
29 changes: 0 additions & 29 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,32 +166,3 @@ jobs:
with:
name: ${{ env.APK_NAME }}
path: app/build/outputs/apk/ci/${{ env.APK_NAME }}.apk

synchronize-with-crowdin:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: crowdin action
uses: crowdin/github-action@v2
if: github.event.repository.fork == false
with:
upload_sources: true
upload_translations: false
download_translations: true
localization_branch_name: l10n/develop
create_pull_request: true
pull_request_title: 'New Crowdin Translations'
pull_request_body: 'New Crowdin translations by [Crowdin GH Action](https://github.com/crowdin/github-action)'
pull_request_base_branch_name: 'develop'
env:
# A classic GitHub Personal Access Token with the 'repo' scope selected (the user should have write access to the repository).
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# A numeric ID, found at https://crowdin.com/project/<projectName>/tools/api
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}

# Visit https://crowdin.com/settings#api-key to create this token
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
## [4.7.1](https://github.com/sds100/KeyMapper/releases/tag/v4.7.1)

#### 19 November 2026

## Added

- More Chinese translations.

## Fixed

- Crash on Android 13+ in the accessibility service input method due to a few AOSP bugs. The accessibility service input method feature is now only enabled when necessary. This should reduce the random crashes for users who don't need the feature.
- Crash when a display is disconnected while floating buttons are showing.
- Crash in the quick settings tiles due to inconsistent lifecycle state management.
- Crash when checking Shizuku permission due to a bug in their service.
- Crash in the accessibility service when Android backs up the app. Backup is now only enabled on Android 16+. This is caused by a feature in AOSP that the Dagger Hilt team can not work around.
- #2317 Voice assistant action now works when Gemini is the default assistant.

## [4.7.0](https://github.com/sds100/KeyMapper/releases/tag/v4.7.0)

#### 08 November 2026
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<application
android:name="io.github.sds100.keymapper.KeyMapperApp"
android:allowBackup="true"
android:allowBackup="@bool/allow_backup"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
Expand All @@ -42,6 +42,12 @@
tools:ignore="GoogleAppIndexingWarning,MissingTvBanner">
<!-- Allow clear text traffic due to the HTTP Request Action. -->

<!-- Use KeyMapperApp during backup and restore so Hilt components don't crash.
Only respected on Android 16+. See @bool/allow_backup. -->
<property
android:name="android.app.backup.PROPERTY_USE_RESTRICTED_BACKUP_MODE"
android:value="false" />

<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
4 changes: 2 additions & 2 deletions app/version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION_NAME=4.7.0
VERSION_CODE=292
VERSION_NAME=4.7.1
VERSION_CODE=295
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import io.github.sds100.keymapper.common.BuildConfigProvider
import io.github.sds100.keymapper.common.models.ShellExecutionMode
import io.github.sds100.keymapper.common.utils.KMError
import io.github.sds100.keymapper.common.utils.firstBlocking
import io.github.sds100.keymapper.common.utils.isSuccess
import io.github.sds100.keymapper.common.utils.onFailure
import io.github.sds100.keymapper.common.utils.onSuccess
import io.github.sds100.keymapper.common.utils.valueOrNull
Expand Down Expand Up @@ -56,9 +55,7 @@ class LazyActionErrorSnapshot(
private val isCompatibleImeEnabled by lazy { keyMapperImeHelper.isCompatibleImeEnabled() }
private val isCompatibleImeChosen by lazy { keyMapperImeHelper.isCompatibleImeChosen() }
private val isVoiceAssistantInstalled by lazy { packageManager.isVoiceAssistantInstalled() }
private val isDeviceAssistantInstalled by lazy {
packageManager.getDeviceAssistantPackage().isSuccess
}
private val isDeviceAssistantInstalled by lazy { packageManager.isDeviceAssistantInstalled() }
private val grantedPermissions: MutableMap<Permission, Boolean> = mutableMapOf()
private val flashLenses by lazy {
buildSet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import io.github.sds100.keymapper.system.camera.CameraAdapter
import io.github.sds100.keymapper.system.devices.DevicesAdapter
import io.github.sds100.keymapper.system.display.DisplayAdapter
import io.github.sds100.keymapper.system.display.DisplayInfo
import io.github.sds100.keymapper.system.display.getDisplaySafe
import io.github.sds100.keymapper.system.files.FileAdapter
import io.github.sds100.keymapper.system.files.FileUtils
import io.github.sds100.keymapper.system.inputevents.Scancode
Expand Down Expand Up @@ -272,7 +273,7 @@ class PerformActionsUseCaseImpl @AssistedInject constructor(

is ActionData.Rotation.CycleRotations -> {
result = displayAdapter.disableAutoRotate().then {
val currentOrientation = getActiveDisplay()!!.rotation
val currentOrientation = getActiveDisplay().rotation

val index = action.orientations.indexOf(currentOrientation)

Expand Down Expand Up @@ -371,7 +372,7 @@ class PerformActionsUseCaseImpl @AssistedInject constructor(
}

is ActionData.TapScreen -> {
val displaySize = getActiveDisplay()!!.logicalSize
val displaySize = getActiveDisplay().logicalSize
val point =
scaleCoordinate(action.x, action.y, action.screenResolution, displaySize)

Expand All @@ -381,7 +382,7 @@ class PerformActionsUseCaseImpl @AssistedInject constructor(
}

is ActionData.SwipeScreen -> {
val displaySize = getActiveDisplay()!!.logicalSize
val displaySize = getActiveDisplay().logicalSize
val start = scaleCoordinate(
action.xStart,
action.yStart,
Expand All @@ -405,7 +406,7 @@ class PerformActionsUseCaseImpl @AssistedInject constructor(
}

is ActionData.PinchScreen -> {
val displaySize = getActiveDisplay()!!.logicalSize
val displaySize = getActiveDisplay().logicalSize
val point =
scaleCoordinate(action.x, action.y, action.screenResolution, displaySize)
val distance =
Expand Down Expand Up @@ -587,7 +588,7 @@ class PerformActionsUseCaseImpl @AssistedInject constructor(
}

is ActionData.Rotation.SwitchOrientation -> {
val currentOrientation = getActiveDisplay()!!.rotation
val currentOrientation = getActiveDisplay().rotation

if (currentOrientation == Orientation.ORIENTATION_180 ||
currentOrientation == Orientation.ORIENTATION_0
Expand Down Expand Up @@ -1299,8 +1300,8 @@ class PerformActionsUseCaseImpl @AssistedInject constructor(
return a != null && b != null && a == b
}

private fun getActiveDisplay(): DisplayInfo? =
displayAdapter.getDisplay(service.getActiveDisplayId())
private fun getActiveDisplay(): DisplayInfo =
displayAdapter.getDisplaySafe(service.getActiveDisplayId())
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.github.sds100.keymapper.base.utils.ui.ResourceProvider
import io.github.sds100.keymapper.base.utils.ui.showDialog
import io.github.sds100.keymapper.common.utils.SizeKM
import io.github.sds100.keymapper.system.display.DisplayAdapter
import io.github.sds100.keymapper.system.display.getDisplaySafe
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand Down Expand Up @@ -71,7 +72,9 @@ class ScreenshotPickerDelegate(
*/
fun screenResolution(): SizeKM {
val activeDisplay =
displayAdapter.getDisplay(displayAdapter.activityDisplayId ?: Display.DEFAULT_DISPLAY)!!
displayAdapter.getDisplaySafe(
displayAdapter.activityDisplayId ?: Display.DEFAULT_DISPLAY,
)

return screenshotResolution.value ?: loadedResolution.value ?: activeDisplay.logicalSize
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.github.sds100.keymapper.system.camera.CameraAdapter
import io.github.sds100.keymapper.system.devices.DevicesAdapter
import io.github.sds100.keymapper.system.display.DisplayAdapter
import io.github.sds100.keymapper.system.display.DisplayInfo
import io.github.sds100.keymapper.system.display.getDisplaySafe
import io.github.sds100.keymapper.system.foldable.FoldableAdapter
import io.github.sds100.keymapper.system.foldable.HingeState
import io.github.sds100.keymapper.system.foldable.isClosed
Expand Down Expand Up @@ -55,13 +56,13 @@ class LazyConstraintSnapshot(
private val connectedBluetoothDevices: Set<BluetoothDeviceInfo> by lazy {
devicesAdapter.connectedBluetoothDevices.value
}
private val orientation: Orientation by lazy { getActiveDisplay()!!.rotation }
private val orientation: Orientation by lazy { getActiveDisplay().rotation }
private val physicalOrientation: PhysicalOrientation by lazy {
displayAdapter.cachedPhysicalOrientation
}
private val isScreenOn: Boolean by lazy { displayAdapter.isScreenOn.firstBlocking() }
private val displaySize: SizeKM by lazy {
getActiveDisplay()!!.physicalSize
getActiveDisplay().physicalSize
}

private val appsPlayingMedia: List<String> by lazy {
Expand Down Expand Up @@ -261,8 +262,8 @@ class LazyConstraintSnapshot(
return isSatisfied != constraint.isNot
}

private fun getActiveDisplay(): DisplayInfo? {
return displayAdapter.getDisplay(accessibilityService.getActiveDisplayId())
private fun getActiveDisplay(): DisplayInfo {
return displayAdapter.getDisplaySafe(accessibilityService.getActiveDisplayId())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.github.sds100.keymapper.data.repositories.PreferenceRepository
import io.github.sds100.keymapper.system.camera.CameraAdapter
import io.github.sds100.keymapper.system.camera.CameraLens
import io.github.sds100.keymapper.system.display.DisplayAdapter
import io.github.sds100.keymapper.system.display.getDisplaySafe
import io.github.sds100.keymapper.system.inputmethod.ImeInfo
import io.github.sds100.keymapper.system.inputmethod.InputMethodAdapter
import io.github.sds100.keymapper.system.network.NetworkAdapter
Expand Down Expand Up @@ -66,9 +67,9 @@ class CreateConstraintUseCaseImpl @Inject constructor(
displayAdapter.displays.value.flatMap { it.supportedSizes }.toSet()

override fun getCurrentResolution(): SizeKM {
return displayAdapter.getDisplay(
return displayAdapter.getDisplaySafe(
displayAdapter.activityDisplayId ?: Display.DEFAULT_DISPLAY,
)!!.physicalSize
).physicalSize
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ private const val MAX_ACTION_TARGET_DEPTH = 10

fun AccessibilityService.getActiveDisplayIdExt(): Int {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
rootInActiveWindow?.window?.displayId ?: Display.DEFAULT_DISPLAY
// The window's display id can be INVALID_DISPLAY (-1).
(rootInActiveWindow?.window?.displayId ?: Display.DEFAULT_DISPLAY)
.coerceAtLeast(Display.DEFAULT_DISPLAY)
} else {
Display.DEFAULT_DISPLAY
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ abstract class BaseAccessibilityServiceController(
// This is required for receive TYPE_WINDOWS_CHANGED events so can
// detect when to show/hide overlays.
.withFlag(AccessibilityServiceInfo.FLAG_RETRIEVE_INTERACTIVE_WINDOWS)
.withFlag(AccessibilityServiceInfo.FLAG_INPUT_METHOD_EDITOR)
.withFlag(AccessibilityServiceInfo.FLAG_ENABLE_ACCESSIBILITY_VOLUME)

return@lazy flags
Expand Down Expand Up @@ -270,6 +269,44 @@ abstract class BaseAccessibilityServiceController(
}
}.launchIn(service.lifecycleScope)

/*
* Only request the accessibility input method when something uses it, because the
* framework has bugs that crash the app whenever FLAG_INPUT_METHOD_EDITOR is set:
*
* - Android 13: InputMethod$SessionImpl.invalidateInput dereferences a null connection.
* "NullPointerException: ...RemoteAccessibilityInputConnection.isSameConnection(...) on
* a null object reference at android.accessibilityservice.InputMethod$SessionImpl
* .invalidateInput (InputMethod.java:520)". Fixed in Android 14.
* - Android 14+: IAccessibilityServiceClientWrapper.startInput dereferences a null
* EditorInfo. "NullPointerException: ...EditorInfo.makeCompatible(int) on a null object
* reference at android.accessibilityservice.AccessibilityService
* $IAccessibilityServiceClientWrapper.lambda$startInput$16
* (AccessibilityService.java:3175)". Not fixed as of Android 17.
*
* On Android 13+ the Text and IME actions use the accessibility input method's input
* connection, and changing the keyboard on input focus uses its onStartInput.
*/
combine(
changeImeOnInputFocusFlow,
detectKeyMapsUseCase.allKeyMapList,
) { changeImeOnInputFocus, keyMaps ->
val useInputMethod = changeImeOnInputFocus ||
keyMaps.any { model ->
model.keyMap.isEnabled &&
model.keyMap.actionList.any {
it.data is ActionData.Text || it.data is ActionData.PerformImeAction
}
}

serviceFlags.update { flags ->
if (useInputMethod) {
flags.withFlag(AccessibilityServiceInfo.FLAG_INPUT_METHOD_EDITOR)
} else {
flags.minusFlag(AccessibilityServiceInfo.FLAG_INPUT_METHOD_EDITOR)
}
}
}.launchIn(service.lifecycleScope)

service.lifecycleScope.launch {
accessibilityNodeRecorder.recordState.collectLatest { state ->
outputEvents.emit(RecordAccessibilityNodeEvent.OnRecordNodeStateChanged(state))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,18 @@ class ToggleKeyMapperKeyboardTile :
override fun onStartListening() {
super.onStartListening()

lifecycleRegistry.currentState = Lifecycle.State.STARTED
// A queued listening message can arrive after onDestroy.
if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
lifecycleRegistry.currentState = Lifecycle.State.STARTED
}
}

override fun onStopListening() {
if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
lifecycleRegistry.currentState = Lifecycle.State.CREATED
}

super.onStopListening()
}

override fun onDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,22 @@ class ToggleMappingsTile :
}

override fun onStartListening() {
lifecycleRegistry.currentState = Lifecycle.State.STARTED
// A queued listening message can arrive after onDestroy.
if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
lifecycleRegistry.currentState = Lifecycle.State.STARTED
}

super.onStartListening()
}

override fun onStopListening() {
if (lifecycleRegistry.currentState != Lifecycle.State.DESTROYED) {
lifecycleRegistry.currentState = Lifecycle.State.CREATED
}

super.onStopListening()
}

override fun onDestroy() {
lifecycleRegistry.currentState = Lifecycle.State.DESTROYED
super.onDestroy()
Expand Down
Loading
Loading