Skip to content

Commit

Permalink
Add some missing states for audio sensor and correct mic muted intent…
Browse files Browse the repository at this point in the history
… condition (#4350)

* Add some missing states for audio sensor

* Correct improper SDK check for mic muted intent action

* Update wear intent receivers

* Correct mic muted sensor update type
  • Loading branch information
dshokouhi authored Apr 20, 2024
1 parent 177a040 commit 4d9498c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,19 @@ open class HomeAssistantApplication : Application() {
}
)

// Add extra audio receiver for devices that support it
// Listen for microphone mute changes
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
registerReceiver(
sensorReceiver,
IntentFilter(AudioManager.ACTION_MICROPHONE_MUTE_CHANGED)
)
}

// Listen for speakerphone state changes
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
registerReceiver(
sensorReceiver,
IntentFilter().apply {
addAction(AudioManager.ACTION_MICROPHONE_MUTE_CHANGED)
addAction(AudioManager.ACTION_SPEAKERPHONE_STATE_CHANGED)
}
IntentFilter(AudioManager.ACTION_SPEAKERPHONE_STATE_CHANGED)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AudioSensorManager : SensorManager {
commonR.string.sensor_description_mic_muted,
"mdi:microphone-off",
updateType =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
SensorManager.BasicSensor.UpdateType.INTENT
} else {
SensorManager.BasicSensor.UpdateType.WORKER
Expand Down Expand Up @@ -226,6 +226,8 @@ class AudioSensorManager : SensorManager {
AudioManager.MODE_IN_CALL -> "in_call"
AudioManager.MODE_IN_COMMUNICATION -> "in_communication"
AudioManager.MODE_CALL_SCREENING -> "call_screening"
AudioManager.MODE_CALL_REDIRECT -> "call_redirect"
AudioManager.MODE_COMMUNICATION_REDIRECT -> "communication_redirect"
else -> STATE_UNKNOWN
}

Expand All @@ -235,6 +237,8 @@ class AudioSensorManager : SensorManager {
AudioManager.MODE_IN_CALL -> "mdi:phone"
AudioManager.MODE_IN_COMMUNICATION -> "mdi:message-video"
AudioManager.MODE_CALL_SCREENING -> "mdi:microphone-message"
AudioManager.MODE_CALL_REDIRECT -> "mdi:phone"
AudioManager.MODE_COMMUNICATION_REDIRECT -> "mdi:message-video"
else -> "mdi:volume-low"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,19 @@ open class HomeAssistantApplication : Application() {
}
)

// Add extra audio receiver for devices that support it
// Listen for microphone mute changes
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
registerReceiver(
sensorReceiver,
IntentFilter(AudioManager.ACTION_MICROPHONE_MUTE_CHANGED)
)
}

// Listen for speakerphone state changes
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
registerReceiver(
sensorReceiver,
IntentFilter().apply {
addAction(AudioManager.ACTION_MICROPHONE_MUTE_CHANGED)
addAction(AudioManager.ACTION_SPEAKERPHONE_STATE_CHANGED)
}
IntentFilter(AudioManager.ACTION_SPEAKERPHONE_STATE_CHANGED)
)
}

Expand Down

0 comments on commit 4d9498c

Please sign in to comment.