Skip to content

Commit 8fb08f3

Browse files
committed
Merge branch 'copilot/mute-microphone-action' into develop
2 parents 24b4cf9 + 0edd32d commit 8fb08f3

File tree

12 files changed

+113
-3
lines changed

12 files changed

+113
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- #727 Actions to send SMS messages: "Send SMS" and "Compose SMS"
1818
- #1819 Explain how to enable the accessibility service restricted setting
1919
- #661 Action to execute shell commands.
20+
- #1066 Action to mute/unmute microphone.
2021

2122
## Removed
2223

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,24 @@ sealed class ActionData : Comparable<ActionData> {
183183
}
184184
}
185185

186+
@Serializable
187+
sealed class Microphone : ActionData() {
188+
@Serializable
189+
data object Mute : Microphone() {
190+
override val id = ActionId.MUTE_MICROPHONE
191+
}
192+
193+
@Serializable
194+
data object Unmute : Microphone() {
195+
override val id = ActionId.UNMUTE_MICROPHONE
196+
}
197+
198+
@Serializable
199+
data object Toggle : Microphone() {
200+
override val id = ActionId.TOGGLE_MUTE_MICROPHONE
201+
}
202+
}
203+
186204
@Serializable
187205
sealed class Flashlight : ActionData() {
188206
abstract val lens: CameraLens

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ object ActionDataEntityMapper {
317317
}
318318
}
319319

320+
ActionId.MUTE_MICROPHONE -> ActionData.Microphone.Mute
321+
ActionId.UNMUTE_MICROPHONE -> ActionData.Microphone.Unmute
322+
ActionId.TOGGLE_MUTE_MICROPHONE -> ActionData.Microphone.Toggle
323+
320324
ActionId.TOGGLE_FLASHLIGHT,
321325
ActionId.ENABLE_FLASHLIGHT,
322326
ActionId.CHANGE_FLASHLIGHT_STRENGTH,
@@ -1139,6 +1143,9 @@ object ActionDataEntityMapper {
11391143
ActionId.VOLUME_UNMUTE to "volume_unmute",
11401144
ActionId.VOLUME_MUTE to "volume_mute",
11411145
ActionId.VOLUME_TOGGLE_MUTE to "volume_toggle_mute",
1146+
ActionId.MUTE_MICROPHONE to "mute_microphone",
1147+
ActionId.UNMUTE_MICROPHONE to "unmute_microphone",
1148+
ActionId.TOGGLE_MUTE_MICROPHONE to "toggle_mute_microphone",
11421149

11431150
ActionId.EXPAND_NOTIFICATION_DRAWER to "expand_notification_drawer",
11441151
ActionId.TOGGLE_NOTIFICATION_DRAWER to "toggle_notification_drawer",

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ enum class ActionId {
5656
VOLUME_UNMUTE,
5757
VOLUME_MUTE,
5858
VOLUME_TOGGLE_MUTE,
59+
MUTE_MICROPHONE,
60+
UNMUTE_MICROPHONE,
61+
TOGGLE_MUTE_MICROPHONE,
5962

6063
EXPAND_NOTIFICATION_DRAWER,
6164
TOGGLE_NOTIFICATION_DRAWER,

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ class ActionUiHelper(
6060
}
6161

6262
if (action.device != null) {
63-
val name = if (action.device.name.isBlank()) {
63+
val name = action.device.name.ifBlank {
6464
getString(R.string.unknown_device_name)
65-
} else {
66-
action.device.name
6765
}
6866

6967
val nameToShow = if (showDeviceDescriptors) {
@@ -603,6 +601,10 @@ class ActionUiHelper(
603601
R.string.action_send_sms_description,
604602
arrayOf(action.message, action.number),
605603
)
604+
605+
ActionData.Microphone.Mute -> getString(R.string.action_mute_microphone)
606+
ActionData.Microphone.Toggle -> getString(R.string.action_toggle_mute_microphone)
607+
ActionData.Microphone.Unmute -> getString(R.string.action_unmute_microphone)
606608
}
607609

608610
fun getIcon(action: ActionData): ComposeIconInfo = when (action) {

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import androidx.compose.material.icons.outlined.Keyboard
4141
import androidx.compose.material.icons.outlined.KeyboardHide
4242
import androidx.compose.material.icons.outlined.Link
4343
import androidx.compose.material.icons.outlined.Lock
44+
import androidx.compose.material.icons.outlined.Mic
45+
import androidx.compose.material.icons.outlined.MicOff
4446
import androidx.compose.material.icons.outlined.MoreVert
4547
import androidx.compose.material.icons.outlined.Nfc
4648
import androidx.compose.material.icons.outlined.NotStarted
@@ -170,6 +172,9 @@ object ActionUtils {
170172
ActionId.VOLUME_UNMUTE -> ActionCategory.VOLUME
171173
ActionId.VOLUME_MUTE -> ActionCategory.VOLUME
172174
ActionId.VOLUME_TOGGLE_MUTE -> ActionCategory.VOLUME
175+
ActionId.MUTE_MICROPHONE -> ActionCategory.VOLUME
176+
ActionId.UNMUTE_MICROPHONE -> ActionCategory.VOLUME
177+
ActionId.TOGGLE_MUTE_MICROPHONE -> ActionCategory.VOLUME
173178

174179
ActionId.EXPAND_NOTIFICATION_DRAWER -> ActionCategory.NAVIGATION
175180
ActionId.TOGGLE_NOTIFICATION_DRAWER -> ActionCategory.NAVIGATION
@@ -289,6 +294,9 @@ object ActionUtils {
289294
ActionId.VOLUME_UNMUTE -> R.string.action_volume_unmute
290295
ActionId.VOLUME_MUTE -> R.string.action_volume_mute
291296
ActionId.VOLUME_TOGGLE_MUTE -> R.string.action_toggle_mute
297+
ActionId.MUTE_MICROPHONE -> R.string.action_mute_microphone
298+
ActionId.UNMUTE_MICROPHONE -> R.string.action_unmute_microphone
299+
ActionId.TOGGLE_MUTE_MICROPHONE -> R.string.action_toggle_mute_microphone
292300
ActionId.EXPAND_NOTIFICATION_DRAWER -> R.string.action_expand_notification_drawer
293301
ActionId.TOGGLE_NOTIFICATION_DRAWER -> R.string.action_toggle_notification_drawer
294302
ActionId.EXPAND_QUICK_SETTINGS -> R.string.action_expand_quick_settings
@@ -413,6 +421,9 @@ object ActionUtils {
413421
ActionId.VOLUME_UNMUTE -> R.drawable.ic_outline_volume_up_24
414422
ActionId.VOLUME_MUTE -> R.drawable.ic_outline_volume_mute_24
415423
ActionId.VOLUME_TOGGLE_MUTE -> R.drawable.ic_outline_volume_mute_24
424+
ActionId.MUTE_MICROPHONE -> null
425+
ActionId.UNMUTE_MICROPHONE -> null
426+
ActionId.TOGGLE_MUTE_MICROPHONE -> null
416427
ActionId.EXPAND_NOTIFICATION_DRAWER -> null
417428
ActionId.TOGGLE_NOTIFICATION_DRAWER -> null
418429
ActionId.EXPAND_QUICK_SETTINGS -> null
@@ -507,6 +518,9 @@ object ActionUtils {
507518
ActionId.VOLUME_MUTE,
508519
ActionId.VOLUME_UNMUTE,
509520
ActionId.VOLUME_TOGGLE_MUTE,
521+
ActionId.MUTE_MICROPHONE,
522+
ActionId.UNMUTE_MICROPHONE,
523+
ActionId.TOGGLE_MUTE_MICROPHONE,
510524
ActionId.TOGGLE_DND_MODE,
511525
ActionId.ENABLE_DND_MODE,
512526
ActionId.DISABLE_DND_MODE,
@@ -653,6 +667,9 @@ object ActionUtils {
653667
ActionId.VOLUME_MUTE,
654668
ActionId.VOLUME_UNMUTE,
655669
ActionId.VOLUME_TOGGLE_MUTE,
670+
ActionId.MUTE_MICROPHONE,
671+
ActionId.UNMUTE_MICROPHONE,
672+
ActionId.TOGGLE_MUTE_MICROPHONE,
656673
ActionId.TOGGLE_DND_MODE,
657674
ActionId.DISABLE_DND_MODE,
658675
ActionId.ENABLE_DND_MODE,
@@ -784,6 +801,9 @@ object ActionUtils {
784801
ActionId.VOLUME_UNMUTE -> Icons.AutoMirrored.Outlined.VolumeUp
785802
ActionId.VOLUME_MUTE -> Icons.AutoMirrored.Outlined.VolumeMute
786803
ActionId.VOLUME_TOGGLE_MUTE -> Icons.AutoMirrored.Outlined.VolumeMute
804+
ActionId.MUTE_MICROPHONE -> Icons.Outlined.MicOff
805+
ActionId.UNMUTE_MICROPHONE -> Icons.Outlined.Mic
806+
ActionId.TOGGLE_MUTE_MICROPHONE -> Icons.Outlined.MicOff
787807
ActionId.EXPAND_NOTIFICATION_DRAWER -> KeyMapperIcons.TopPanelOpen
788808
ActionId.TOGGLE_NOTIFICATION_DRAWER -> KeyMapperIcons.TopPanelClose
789809
ActionId.EXPAND_QUICK_SETTINGS -> KeyMapperIcons.TopPanelOpen

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,18 @@ class CreateActionDelegate(
309309
return action
310310
}
311311

312+
ActionId.MUTE_MICROPHONE -> {
313+
return ActionData.Microphone.Mute
314+
}
315+
316+
ActionId.UNMUTE_MICROPHONE -> {
317+
return ActionData.Microphone.Unmute
318+
}
319+
320+
ActionId.TOGGLE_MUTE_MICROPHONE -> {
321+
return ActionData.Microphone.Toggle
322+
}
323+
312324
ActionId.VOLUME_INCREASE_STREAM,
313325
ActionId.VOLUME_DECREASE_STREAM,
314326
-> {

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,30 @@ class PerformActionsUseCaseImpl @AssistedInject constructor(
359359
result = audioAdapter.unmuteVolume(showVolumeUi = action.showVolumeUi)
360360
}
361361

362+
is ActionData.Microphone.Mute -> {
363+
result = audioAdapter.muteMicrophone().onSuccess {
364+
toastAdapter.show(resourceProvider.getString(R.string.toast_microphone_muted))
365+
}
366+
}
367+
368+
is ActionData.Microphone.Unmute -> {
369+
result = audioAdapter.unmuteMicrophone().onSuccess {
370+
toastAdapter.show(resourceProvider.getString(R.string.toast_microphone_unmuted))
371+
}
372+
}
373+
374+
is ActionData.Microphone.Toggle -> {
375+
result = if (audioAdapter.isMicrophoneMuted) {
376+
audioAdapter.unmuteMicrophone().onSuccess {
377+
toastAdapter.show(resourceProvider.getString(R.string.toast_microphone_unmuted))
378+
}
379+
} else {
380+
audioAdapter.muteMicrophone().onSuccess {
381+
toastAdapter.show(resourceProvider.getString(R.string.toast_microphone_muted))
382+
}
383+
}
384+
}
385+
362386
is ActionData.TapScreen -> {
363387
result = service.tapScreen(action.x, action.y, inputEventAction)
364388
}

base/src/main/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@
201201
<string name="toast_no_sound_files">You have saved no sound files!</string>
202202
<string name="toast_granted_itself_write_secure_settings_with_shizuku">Key Mapper has used Shizuku to grant itself WRITE_SECURE_SETTINGS permission</string>
203203
<string name="toast_granted_itself_write_secure_settings_with_root">Key Mapper has used Root to grant itself WRITE_SECURE_SETTINGS permission</string>
204+
<string name="toast_microphone_muted">Microphone muted</string>
205+
<string name="toast_microphone_unmuted">Microphone unmuted</string>
204206
<!-- Toasts -->
205207

206208
<!-- Extra labels -->
@@ -883,6 +885,9 @@
883885
<string name="action_volume_mute">Mute volume</string>
884886
<string name="action_toggle_mute">Toggle mute</string>
885887
<string name="action_volume_unmute">Unmute volume</string>
888+
<string name="action_mute_microphone">Mute microphone</string>
889+
<string name="action_unmute_microphone">Unmute microphone</string>
890+
<string name="action_toggle_mute_microphone">Toggle mute microphone</string>
886891
<string name="action_volume_show_dialog">Show volume dialog</string>
887892
<string name="action_increase_stream">Increase stream</string>
888893
<string name="action_increase_stream_formatted">Increase %s stream</string>

system/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<uses-permission android:name="android.permission.CALL_PHONE" />
2525
<uses-permission android:name="android.permission.SEND_SMS"
2626
tools:ignore="SmsAndCallLogPolicy" />
27+
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
2728

2829
<uses-feature
2930
android:name="android.hardware.telephony"

0 commit comments

Comments
 (0)