diff --git a/base/src/main/java/io/github/sds100/keymapper/base/actions/ActionData.kt b/base/src/main/java/io/github/sds100/keymapper/base/actions/ActionData.kt index b4a736d56f..40e75c0a08 100644 --- a/base/src/main/java/io/github/sds100/keymapper/base/actions/ActionData.kt +++ b/base/src/main/java/io/github/sds100/keymapper/base/actions/ActionData.kt @@ -183,6 +183,24 @@ sealed class ActionData : Comparable { } } + @Serializable + sealed class Microphone : ActionData() { + @Serializable + data object Mute : Microphone() { + override val id = ActionId.MUTE_MICROPHONE + } + + @Serializable + data object UnMute : Microphone() { + override val id = ActionId.UNMUTE_MICROPHONE + } + + @Serializable + data object Toggle : Microphone() { + override val id = ActionId.TOGGLE_MUTE_MICROPHONE + } + } + @Serializable sealed class Flashlight : ActionData() { abstract val lens: CameraLens diff --git a/base/src/main/java/io/github/sds100/keymapper/base/actions/ActionDataEntityMapper.kt b/base/src/main/java/io/github/sds100/keymapper/base/actions/ActionDataEntityMapper.kt index 1c9c617769..bb9518bec6 100644 --- a/base/src/main/java/io/github/sds100/keymapper/base/actions/ActionDataEntityMapper.kt +++ b/base/src/main/java/io/github/sds100/keymapper/base/actions/ActionDataEntityMapper.kt @@ -317,6 +317,10 @@ object ActionDataEntityMapper { } } + ActionId.MUTE_MICROPHONE -> ActionData.Microphone.Mute + ActionId.UNMUTE_MICROPHONE -> ActionData.Microphone.UnMute + ActionId.TOGGLE_MUTE_MICROPHONE -> ActionData.Microphone.Toggle + ActionId.TOGGLE_FLASHLIGHT, ActionId.ENABLE_FLASHLIGHT, ActionId.CHANGE_FLASHLIGHT_STRENGTH, @@ -1139,6 +1143,9 @@ object ActionDataEntityMapper { ActionId.VOLUME_UNMUTE to "volume_unmute", ActionId.VOLUME_MUTE to "volume_mute", ActionId.VOLUME_TOGGLE_MUTE to "volume_toggle_mute", + ActionId.MUTE_MICROPHONE to "mute_microphone", + ActionId.UNMUTE_MICROPHONE to "unmute_microphone", + ActionId.TOGGLE_MUTE_MICROPHONE to "toggle_mute_microphone", ActionId.EXPAND_NOTIFICATION_DRAWER to "expand_notification_drawer", ActionId.TOGGLE_NOTIFICATION_DRAWER to "toggle_notification_drawer", diff --git a/base/src/main/java/io/github/sds100/keymapper/base/actions/ActionId.kt b/base/src/main/java/io/github/sds100/keymapper/base/actions/ActionId.kt index 002e2c8ac5..ff3c192f52 100644 --- a/base/src/main/java/io/github/sds100/keymapper/base/actions/ActionId.kt +++ b/base/src/main/java/io/github/sds100/keymapper/base/actions/ActionId.kt @@ -56,6 +56,9 @@ enum class ActionId { VOLUME_UNMUTE, VOLUME_MUTE, VOLUME_TOGGLE_MUTE, + MUTE_MICROPHONE, + UNMUTE_MICROPHONE, + TOGGLE_MUTE_MICROPHONE, EXPAND_NOTIFICATION_DRAWER, TOGGLE_NOTIFICATION_DRAWER, diff --git a/base/src/main/java/io/github/sds100/keymapper/base/actions/ActionUtils.kt b/base/src/main/java/io/github/sds100/keymapper/base/actions/ActionUtils.kt index 2804bcb5d4..e59b19bb2f 100644 --- a/base/src/main/java/io/github/sds100/keymapper/base/actions/ActionUtils.kt +++ b/base/src/main/java/io/github/sds100/keymapper/base/actions/ActionUtils.kt @@ -170,6 +170,9 @@ object ActionUtils { ActionId.VOLUME_UNMUTE -> ActionCategory.VOLUME ActionId.VOLUME_MUTE -> ActionCategory.VOLUME ActionId.VOLUME_TOGGLE_MUTE -> ActionCategory.VOLUME + ActionId.MUTE_MICROPHONE -> ActionCategory.VOLUME + ActionId.UNMUTE_MICROPHONE -> ActionCategory.VOLUME + ActionId.TOGGLE_MUTE_MICROPHONE -> ActionCategory.VOLUME ActionId.EXPAND_NOTIFICATION_DRAWER -> ActionCategory.NAVIGATION ActionId.TOGGLE_NOTIFICATION_DRAWER -> ActionCategory.NAVIGATION @@ -289,6 +292,9 @@ object ActionUtils { ActionId.VOLUME_UNMUTE -> R.string.action_volume_unmute ActionId.VOLUME_MUTE -> R.string.action_volume_mute ActionId.VOLUME_TOGGLE_MUTE -> R.string.action_toggle_mute + ActionId.MUTE_MICROPHONE -> R.string.action_mute_microphone + ActionId.UNMUTE_MICROPHONE -> R.string.action_unmute_microphone + ActionId.TOGGLE_MUTE_MICROPHONE -> R.string.action_toggle_mute_microphone ActionId.EXPAND_NOTIFICATION_DRAWER -> R.string.action_expand_notification_drawer ActionId.TOGGLE_NOTIFICATION_DRAWER -> R.string.action_toggle_notification_drawer ActionId.EXPAND_QUICK_SETTINGS -> R.string.action_expand_quick_settings @@ -413,6 +419,9 @@ object ActionUtils { ActionId.VOLUME_UNMUTE -> R.drawable.ic_outline_volume_up_24 ActionId.VOLUME_MUTE -> R.drawable.ic_outline_volume_mute_24 ActionId.VOLUME_TOGGLE_MUTE -> R.drawable.ic_outline_volume_mute_24 + ActionId.MUTE_MICROPHONE -> null + ActionId.UNMUTE_MICROPHONE -> null + ActionId.TOGGLE_MUTE_MICROPHONE -> null ActionId.EXPAND_NOTIFICATION_DRAWER -> null ActionId.TOGGLE_NOTIFICATION_DRAWER -> null ActionId.EXPAND_QUICK_SETTINGS -> null @@ -507,6 +516,9 @@ object ActionUtils { ActionId.VOLUME_MUTE, ActionId.VOLUME_UNMUTE, ActionId.VOLUME_TOGGLE_MUTE, + ActionId.MUTE_MICROPHONE, + ActionId.UNMUTE_MICROPHONE, + ActionId.TOGGLE_MUTE_MICROPHONE, ActionId.TOGGLE_DND_MODE, ActionId.ENABLE_DND_MODE, ActionId.DISABLE_DND_MODE, @@ -653,6 +665,9 @@ object ActionUtils { ActionId.VOLUME_MUTE, ActionId.VOLUME_UNMUTE, ActionId.VOLUME_TOGGLE_MUTE, + ActionId.MUTE_MICROPHONE, + ActionId.UNMUTE_MICROPHONE, + ActionId.TOGGLE_MUTE_MICROPHONE, ActionId.TOGGLE_DND_MODE, ActionId.DISABLE_DND_MODE, ActionId.ENABLE_DND_MODE, @@ -784,6 +799,9 @@ object ActionUtils { ActionId.VOLUME_UNMUTE -> Icons.AutoMirrored.Outlined.VolumeUp ActionId.VOLUME_MUTE -> Icons.AutoMirrored.Outlined.VolumeMute ActionId.VOLUME_TOGGLE_MUTE -> Icons.AutoMirrored.Outlined.VolumeMute + ActionId.MUTE_MICROPHONE -> Icons.Outlined.MicOff + ActionId.UNMUTE_MICROPHONE -> Icons.Outlined.Mic + ActionId.TOGGLE_MUTE_MICROPHONE -> Icons.Outlined.MicOff ActionId.EXPAND_NOTIFICATION_DRAWER -> KeyMapperIcons.TopPanelOpen ActionId.TOGGLE_NOTIFICATION_DRAWER -> KeyMapperIcons.TopPanelClose ActionId.EXPAND_QUICK_SETTINGS -> KeyMapperIcons.TopPanelOpen diff --git a/base/src/main/java/io/github/sds100/keymapper/base/actions/CreateActionDelegate.kt b/base/src/main/java/io/github/sds100/keymapper/base/actions/CreateActionDelegate.kt index 9a118c931c..242acddff2 100644 --- a/base/src/main/java/io/github/sds100/keymapper/base/actions/CreateActionDelegate.kt +++ b/base/src/main/java/io/github/sds100/keymapper/base/actions/CreateActionDelegate.kt @@ -309,6 +309,18 @@ class CreateActionDelegate( return action } + ActionId.MUTE_MICROPHONE -> { + return ActionData.Microphone.Mute + } + + ActionId.UNMUTE_MICROPHONE -> { + return ActionData.Microphone.UnMute + } + + ActionId.TOGGLE_MUTE_MICROPHONE -> { + return ActionData.Microphone.Toggle + } + ActionId.VOLUME_INCREASE_STREAM, ActionId.VOLUME_DECREASE_STREAM, -> { diff --git a/base/src/main/java/io/github/sds100/keymapper/base/actions/PerformActionsUseCase.kt b/base/src/main/java/io/github/sds100/keymapper/base/actions/PerformActionsUseCase.kt index a07e9212c0..da45dc599e 100644 --- a/base/src/main/java/io/github/sds100/keymapper/base/actions/PerformActionsUseCase.kt +++ b/base/src/main/java/io/github/sds100/keymapper/base/actions/PerformActionsUseCase.kt @@ -358,6 +358,18 @@ class PerformActionsUseCaseImpl @AssistedInject constructor( result = audioAdapter.unmuteVolume(showVolumeUi = action.showVolumeUi) } + is ActionData.Microphone.Mute -> { + result = audioAdapter.muteMicrophone() + } + + is ActionData.Microphone.UnMute -> { + result = audioAdapter.unmuteMicrophone() + } + + is ActionData.Microphone.Toggle -> { + result = audioAdapter.toggleMuteMicrophone() + } + is ActionData.TapScreen -> { result = service.tapScreen(action.x, action.y, inputEventAction) } diff --git a/base/src/main/res/values/strings.xml b/base/src/main/res/values/strings.xml index 0b3f3507a5..d57142d79b 100644 --- a/base/src/main/res/values/strings.xml +++ b/base/src/main/res/values/strings.xml @@ -883,6 +883,9 @@ Mute volume Toggle mute Unmute volume + Mute microphone + Unmute microphone + Toggle mute microphone Show volume dialog Increase stream Increase %s stream diff --git a/system/src/main/java/io/github/sds100/keymapper/system/volume/AndroidVolumeAdapter.kt b/system/src/main/java/io/github/sds100/keymapper/system/volume/AndroidVolumeAdapter.kt index e6e254ec66..cff3ae54ac 100644 --- a/system/src/main/java/io/github/sds100/keymapper/system/volume/AndroidVolumeAdapter.kt +++ b/system/src/main/java/io/github/sds100/keymapper/system/volume/AndroidVolumeAdapter.kt @@ -125,6 +125,21 @@ class AndroidVolumeAdapter @Inject constructor( override fun isDndEnabled(): Boolean = notificationManager.currentInterruptionFilter != NotificationManager.INTERRUPTION_FILTER_ALL + override fun muteMicrophone(): KMResult<*> { + audioManager.isMicrophoneMute = true + return Success(Unit) + } + + override fun unmuteMicrophone(): KMResult<*> { + audioManager.isMicrophoneMute = false + return Success(Unit) + } + + override fun toggleMuteMicrophone(): KMResult<*> { + audioManager.isMicrophoneMute = !audioManager.isMicrophoneMute + return Success(Unit) + } + private fun DndMode.convert(): Int = when (this) { DndMode.ALARMS -> NotificationManager.INTERRUPTION_FILTER_ALARMS DndMode.PRIORITY -> NotificationManager.INTERRUPTION_FILTER_PRIORITY diff --git a/system/src/main/java/io/github/sds100/keymapper/system/volume/VolumeAdapter.kt b/system/src/main/java/io/github/sds100/keymapper/system/volume/VolumeAdapter.kt index 2c71fd9020..42c214d918 100644 --- a/system/src/main/java/io/github/sds100/keymapper/system/volume/VolumeAdapter.kt +++ b/system/src/main/java/io/github/sds100/keymapper/system/volume/VolumeAdapter.kt @@ -14,6 +14,10 @@ interface VolumeAdapter { fun showVolumeUi(): KMResult<*> fun setRingerMode(mode: RingerMode): KMResult<*> + fun muteMicrophone(): KMResult<*> + fun unmuteMicrophone(): KMResult<*> + fun toggleMuteMicrophone(): KMResult<*> + fun isDndEnabled(): Boolean fun enableDndMode(dndMode: DndMode): KMResult<*> fun disableDndMode(): KMResult<*>