Skip to content

Commit ac47d21

Browse files
committed
#1394 remove detect screen off option and use shell for key event actions
1 parent 3cab7a1 commit ac47d21

File tree

26 files changed

+48
-211
lines changed

26 files changed

+48
-211
lines changed

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionData.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ sealed class ActionData : Comparable<ActionData> {
4848
data class InputKeyEvent(
4949
val keyCode: Int,
5050
val metaState: Int = 0,
51-
// TODO remove this option
52-
val useShell: Boolean = false,
5351
val device: Device? = null,
5452
) : ActionData() {
5553

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionDataEntityMapper.kt

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ object ActionDataEntityMapper {
7979
entity.extras.getData(ActionEntity.EXTRA_KEY_EVENT_DEVICE_NAME)
8080
.valueOrNull() ?: ""
8181

82-
val useShell =
83-
entity.extras.getData(ActionEntity.EXTRA_KEY_EVENT_USE_SHELL).then {
84-
(it == "true").success()
85-
}.valueOrNull() ?: false
86-
8782
val device = if (deviceDescriptor != null) {
8883
ActionData.InputKeyEvent.Device(deviceDescriptor, deviceName)
8984
} else {
@@ -93,7 +88,6 @@ object ActionDataEntityMapper {
9388
ActionData.InputKeyEvent(
9489
keyCode = entity.data.toInt(),
9590
metaState = metaState,
96-
useShell = useShell,
9791
device = device,
9892
)
9993
}
@@ -724,15 +718,6 @@ object ActionDataEntityMapper {
724718
)
725719

726720
is ActionData.InputKeyEvent -> sequence {
727-
if (data.useShell) {
728-
val string = if (data.useShell) {
729-
"true"
730-
} else {
731-
"false"
732-
}
733-
yield(EntityExtra(ActionEntity.EXTRA_KEY_EVENT_USE_SHELL, string))
734-
}
735-
736721
if (data.metaState != 0) {
737722
yield(
738723
EntityExtra(

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionErrorSnapshot.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,6 @@ class LazyActionErrorSnapshot(
156156
return getAppError(action.packageName)
157157
}
158158

159-
is ActionData.InputKeyEvent ->
160-
if (
161-
action.useShell && !isPermissionGranted(Permission.ROOT)
162-
) {
163-
return SystemError.PermissionDenied(Permission.ROOT)
164-
}
165-
166159
is ActionData.Sound.SoundFile -> {
167160
soundsManager.getSound(action.soundUid).onFailure { error ->
168161
return error

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionUiHelper.kt

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,46 +46,43 @@ class ActionUiHelper(
4646
}
4747

4848
// only a key code can be inputted through the shell
49-
if (action.useShell) {
50-
getString(R.string.description_keyevent_through_shell, keyCodeString)
51-
} else {
52-
val metaStateString = buildString {
53-
for (label in KeyCodeStrings.MODIFIER_LABELS.entries) {
54-
val modifier = label.key
55-
val labelRes = label.value
5649

57-
if (action.metaState.hasFlag(modifier)) {
58-
append("${getString(labelRes)} + ")
59-
}
60-
}
61-
}
50+
val metaStateString = buildString {
51+
for (label in KeyCodeStrings.MODIFIER_LABELS.entries) {
52+
val modifier = label.key
53+
val labelRes = label.value
6254

63-
if (action.device != null) {
64-
val name = if (action.device.name.isBlank()) {
65-
getString(R.string.unknown_device_name)
66-
} else {
67-
action.device.name
55+
if (action.metaState.hasFlag(modifier)) {
56+
append("${getString(labelRes)} + ")
6857
}
58+
}
59+
}
6960

70-
val nameToShow = if (showDeviceDescriptors) {
71-
InputDeviceUtils.appendDeviceDescriptorToName(
72-
action.device.descriptor,
73-
name,
74-
)
75-
} else {
76-
name
77-
}
61+
if (action.device != null) {
62+
val name = if (action.device.name.isBlank()) {
63+
getString(R.string.unknown_device_name)
64+
} else {
65+
action.device.name
66+
}
7867

79-
getString(
80-
R.string.description_keyevent_from_device,
81-
arrayOf(metaStateString, keyCodeString, nameToShow),
68+
val nameToShow = if (showDeviceDescriptors) {
69+
InputDeviceUtils.appendDeviceDescriptorToName(
70+
action.device.descriptor,
71+
name,
8272
)
8373
} else {
84-
getString(
85-
R.string.description_keyevent,
86-
args = arrayOf(metaStateString, keyCodeString),
87-
)
74+
name
8875
}
76+
77+
getString(
78+
R.string.description_keyevent_from_device,
79+
arrayOf(metaStateString, keyCodeString, nameToShow),
80+
)
81+
} else {
82+
getString(
83+
R.string.description_keyevent,
84+
args = arrayOf(metaStateString, keyCodeString),
85+
)
8986
}
9087
}
9188

@@ -262,7 +259,7 @@ class ActionUiHelper(
262259
R.string.action_toggle_front_flashlight_with_strength,
263260
action.strengthPercent.toPercentString(),
264261

265-
)
262+
)
266263
} else {
267264
getString(
268265
R.string.action_toggle_flashlight_with_strength,

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,12 +852,12 @@ object ActionUtils {
852852
}
853853

854854
fun ActionData.canBeHeldDown(): Boolean = when (this) {
855-
is ActionData.InputKeyEvent -> !useShell
855+
is ActionData.InputKeyEvent -> true
856856
else -> false
857857
}
858858

859859
fun ActionData.canUseImeToPerform(): Boolean = when (this) {
860-
is ActionData.InputKeyEvent -> !useShell
860+
is ActionData.InputKeyEvent -> true
861861
is ActionData.Text -> true
862862
else -> false
863863
}

base/src/main/java/io/github/sds100/keymapper/base/actions/ChooseActionViewModel.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ class ChooseActionViewModel @Inject constructor(
211211
-> R.string.action_toggle_keyboard_message
212212

213213
ActionId.SECURE_LOCK_DEVICE -> R.string.action_secure_lock_device_message
214-
ActionId.POWER_ON_OFF_DEVICE -> R.string.action_power_on_off_device_message
215214

216215
else -> null
217216
}

base/src/main/java/io/github/sds100/keymapper/base/actions/keyevent/ConfigKeyEventActionViewModel.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ class ConfigKeyEventActionViewModel @Inject constructor(
105105
keyEventState.value = KeyEventState(
106106
Success(action.keyCode),
107107
inputDevice,
108-
useShell = action.useShell,
109108
metaState = action.metaState,
110109
)
111110
}
@@ -121,10 +120,6 @@ class ConfigKeyEventActionViewModel @Inject constructor(
121120
keyEventState.value = keyEventState.value.copy(keyCode = keyCodeState)
122121
}
123122

124-
fun setUseShell(checked: Boolean) {
125-
keyEventState.value = keyEventState.value.copy(useShell = checked)
126-
}
127-
128123
@SuppressLint("NullSafeMutableLiveData")
129124
fun chooseNoDevice() {
130125
keyEventState.value = keyEventState.value.copy(chosenDevice = null)
@@ -157,7 +152,6 @@ class ConfigKeyEventActionViewModel @Inject constructor(
157152
ActionData.InputKeyEvent(
158153
keyCode = keyCode,
159154
metaState = keyEventState.value.metaState,
160-
useShell = keyEventState.value.useShell,
161155
device = device,
162156
),
163157
)
@@ -171,7 +165,6 @@ class ConfigKeyEventActionViewModel @Inject constructor(
171165
): ConfigKeyEventUiState {
172166
val keyCode = state.keyCode
173167
val metaState = state.metaState
174-
val useShell = state.useShell
175168
val chosenDevice = state.chosenDevice
176169

177170
val keyCodeString = when (keyCode) {
@@ -226,9 +219,8 @@ class ConfigKeyEventActionViewModel @Inject constructor(
226219
keyCodeErrorMessage = keyCode.errorOrNull()?.getFullMessage(this),
227220
keyCodeLabel = keyCodeLabel,
228221
showKeyCodeLabel = keyCode.isSuccess,
229-
isUseShellChecked = useShell,
230-
isDevicePickerShown = !useShell,
231-
isModifierListShown = !useShell,
222+
isDevicePickerShown = true,
223+
isModifierListShown = true,
232224
modifierListItems = modifierListItems,
233225
isDoneButtonEnabled = keyCode.isSuccess,
234226
deviceListItems = deviceListItems,
@@ -239,7 +231,6 @@ class ConfigKeyEventActionViewModel @Inject constructor(
239231
private data class KeyEventState(
240232
val keyCode: KMResult<Int> = KMError.EmptyText,
241233
val chosenDevice: InputDeviceInfo? = null,
242-
val useShell: Boolean = false,
243234
val metaState: Int = 0,
244235
)
245236
}
@@ -249,7 +240,6 @@ data class ConfigKeyEventUiState(
249240
val keyCodeErrorMessage: String?,
250241
val keyCodeLabel: String,
251242
val showKeyCodeLabel: Boolean,
252-
val isUseShellChecked: Boolean,
253243
val isDevicePickerShown: Boolean,
254244
val isModifierListShown: Boolean,
255245
val modifierListItems: List<CheckBoxListItem>,

base/src/main/java/io/github/sds100/keymapper/base/constraints/ChooseConstraintViewModel.kt

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,20 @@ class ChooseConstraintViewModel @Inject constructor(
137137
ConstraintId.APP_NOT_IN_FOREGROUND,
138138
ConstraintId.APP_PLAYING_MEDIA,
139139
ConstraintId.APP_NOT_PLAYING_MEDIA,
140-
-> onSelectAppConstraint(constraintType)
140+
-> onSelectAppConstraint(constraintType)
141141

142142
ConstraintId.MEDIA_PLAYING -> returnResult.emit(Constraint.MediaPlaying())
143143
ConstraintId.MEDIA_NOT_PLAYING -> returnResult.emit(Constraint.NoMediaPlaying())
144144

145145
ConstraintId.BT_DEVICE_CONNECTED,
146146
ConstraintId.BT_DEVICE_DISCONNECTED,
147-
-> onSelectBluetoothConstraint(
147+
-> onSelectBluetoothConstraint(
148148
constraintType,
149149
)
150150

151-
ConstraintId.SCREEN_ON -> onSelectScreenOnConstraint()
152-
ConstraintId.SCREEN_OFF -> onSelectScreenOffConstraint()
151+
ConstraintId.SCREEN_ON -> returnResult.emit(Constraint.ScreenOn())
152+
153+
ConstraintId.SCREEN_OFF -> returnResult.emit(Constraint.ScreenOff())
153154

154155
ConstraintId.ORIENTATION_PORTRAIT ->
155156
returnResult.emit(Constraint.OrientationPortrait())
@@ -184,13 +185,13 @@ class ChooseConstraintViewModel @Inject constructor(
184185

185186
ConstraintId.WIFI_CONNECTED,
186187
ConstraintId.WIFI_DISCONNECTED,
187-
-> onSelectWifiConnectedConstraint(
188+
-> onSelectWifiConnectedConstraint(
188189
constraintType,
189190
)
190191

191192
ConstraintId.IME_CHOSEN,
192193
ConstraintId.IME_NOT_CHOSEN,
193-
-> onSelectImeChosenConstraint(constraintType)
194+
-> onSelectImeChosenConstraint(constraintType)
194195

195196
ConstraintId.DEVICE_IS_LOCKED ->
196197
returnResult.emit(Constraint.DeviceIsLocked())
@@ -353,28 +354,6 @@ class ChooseConstraintViewModel @Inject constructor(
353354
}
354355
}
355356

356-
private suspend fun onSelectScreenOnConstraint() {
357-
val response = showDialog(
358-
"screen_on_constraint_limitation",
359-
DialogModel.Ok(getString(R.string.dialog_message_screen_constraints_limitation)),
360-
)
361-
362-
response ?: return
363-
364-
returnResult.emit(Constraint.ScreenOn())
365-
}
366-
367-
private suspend fun onSelectScreenOffConstraint() {
368-
val response = showDialog(
369-
"screen_on_constraint_limitation",
370-
DialogModel.Ok(getString(R.string.dialog_message_screen_constraints_limitation)),
371-
)
372-
373-
response ?: return
374-
375-
returnResult.emit(Constraint.ScreenOff())
376-
}
377-
378357
private suspend fun onSelectBluetoothConstraint(type: ConstraintId) {
379358
val response = showDialog(
380359
"bluetooth_device_constraint_limitation",

base/src/main/java/io/github/sds100/keymapper/base/detection/DetectKeyMapsUseCase.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import io.github.sds100.keymapper.data.repositories.GroupRepository
2828
import io.github.sds100.keymapper.data.repositories.KeyMapRepository
2929
import io.github.sds100.keymapper.data.repositories.PreferenceRepository
3030
import io.github.sds100.keymapper.system.popup.ToastAdapter
31-
import io.github.sds100.keymapper.system.root.SuAdapter
3231
import io.github.sds100.keymapper.system.vibrator.VibratorAdapter
3332
import io.github.sds100.keymapper.system.volume.VolumeAdapter
3433
import kotlinx.coroutines.CoroutineScope
@@ -46,7 +45,6 @@ class DetectKeyMapsUseCaseImpl @AssistedInject constructor(
4645
private val floatingButtonRepository: FloatingButtonRepository,
4746
private val groupRepository: GroupRepository,
4847
private val preferenceRepository: PreferenceRepository,
49-
private val suAdapter: SuAdapter,
5048
private val volumeAdapter: VolumeAdapter,
5149
private val toastAdapter: ToastAdapter,
5250
private val resourceProvider: ResourceProvider,
@@ -137,14 +135,6 @@ class DetectKeyMapsUseCaseImpl @AssistedInject constructor(
137135
keyMapList.filter { it.keyMap.trigger.triggerFromOtherApps }.map { it.keyMap }
138136
}.flowOn(Dispatchers.Default)
139137

140-
override val detectScreenOffTriggers: Flow<Boolean> =
141-
combine(
142-
allKeyMapList,
143-
suAdapter.isRootGranted,
144-
) { keyMapList, isRootPermissionGranted ->
145-
keyMapList.any { it.keyMap.trigger.screenOffTrigger } && isRootPermissionGranted
146-
}.flowOn(Dispatchers.Default)
147-
148138
override val defaultLongPressDelay: Flow<Long> =
149139
preferenceRepository.get(Keys.defaultLongPressDelay)
150140
.map { it ?: PreferenceDefaults.LONG_PRESS_DELAY }
@@ -239,7 +229,6 @@ interface DetectKeyMapsUseCase {
239229
val allKeyMapList: Flow<List<DetectKeyMapModel>>
240230
val requestFingerprintGestureDetection: Flow<Boolean>
241231
val keyMapsToTriggerFromOtherApps: Flow<List<KeyMap>>
242-
val detectScreenOffTriggers: Flow<Boolean>
243232

244233
val defaultLongPressDelay: Flow<Long>
245234
val defaultDoublePressDelay: Flow<Long>

base/src/main/java/io/github/sds100/keymapper/base/home/KeyMapListItemCreator.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,6 @@ class KeyMapListItemCreator(
362362
labels.add(getString(R.string.flag_long_press_double_vibration))
363363
}
364364

365-
if (trigger.isDetectingWhenScreenOffAllowed() && trigger.screenOffTrigger) {
366-
labels.add(getString(R.string.flag_detect_triggers_screen_off))
367-
}
368-
369365
if (trigger.triggerFromOtherApps) {
370366
labels.add(getString(R.string.flag_trigger_from_other_apps))
371367
}

0 commit comments

Comments
 (0)