Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the application version to 2.2.0-beta1 and introduces CarKeyReceiver and SilentAudioPlayer to enhance steering wheel button support, especially for proprietary Chinese headunits. The CarKeyReceiver manages various media button broadcast actions, and the SilentAudioPlayer ensures the app maintains media focus. Review feedback highlights the need for Android 14-compliant receiver registration, the use of type-safe getParcelableExtra for newer API levels, the removal of unused functions, and safer unregistration of the receiver.
| val filter = android.content.IntentFilter().apply { | ||
| priority = 1000 | ||
| com.andrerinas.headunitrevived.connection.CarKeyReceiver.ACTIONS.forEach { addAction(it) } | ||
| } | ||
| try { | ||
| registerReceiver(carKeyReceiver, filter) |
There was a problem hiding this comment.
Starting with Android 14 (API 34), apps must specify RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED when registering a receiver for non-system broadcasts. Since CarKeyReceiver is intended to receive broadcasts from other apps (proprietary headunit events), it must be registered as exported. Additionally, using ContextCompat.registerReceiver ensures compatibility across different Android versions and I've cleaned up the redundant package names.
val filter = IntentFilter().apply {
priority = 1000
CarKeyReceiver.ACTIONS.forEach { addAction(it) }
}
try {
carKeyReceiver?.let {
ContextCompat.registerReceiver(this, it, filter, ContextCompat.RECEIVER_EXPORTED)
}
} catch (e: Exception) {|
|
||
| // 1. Standard Media Button extraction | ||
| if (action == "android.intent.action.MEDIA_BUTTON" || action == "hy.intent.action.MEDIA_BUTTON") { | ||
| val event = intent.getParcelableExtra<KeyEvent>(Intent.EXTRA_KEY_EVENT) |
There was a problem hiding this comment.
The single-argument getParcelableExtra is deprecated in API 33. Since the project targets API 36, you should use the type-safe version or IntentCompat from the AndroidX Core library to maintain compatibility.
val event = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT, KeyEvent::class.java)
} else {
@Suppress("DEPRECATION")
intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT)
}| private fun handleGenericKey(code: Int, commManager: CommManager) { | ||
| // Generic handler for unknown Learning-Codes | ||
| // In the future, this should hook into the Key Learning settings | ||
| AppLog.i("CarKeyReceiver: Handling generic/learned keycode: $code") | ||
| commManager.send(code, true) | ||
| commManager.send(code, false) | ||
| } |
…e.kt Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
This is added in branch 2.2.0 and will be merged/released soon. |
No description provided.