Skip to content

try to get more swc buttons to work#339

Closed
andreknieriem wants to merge 6 commits intomainfrom
swc-again
Closed

try to get more swc buttons to work#339
andreknieriem wants to merge 6 commits intomainfrom
swc-again

Conversation

@andreknieriem
Copy link
Copy Markdown
Owner

No description provided.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +539 to +544
val filter = android.content.IntentFilter().apply {
priority = 1000
com.andrerinas.headunitrevived.connection.CarKeyReceiver.ACTIONS.forEach { addAction(it) }
}
try {
registerReceiver(carKeyReceiver, filter)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh my fault...

Comment thread app/src/main/java/com/andrerinas/headunitrevived/aap/AapService.kt Outdated

// 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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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)
            }

Comment on lines +127 to +133
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)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The function handleGenericKey is defined but never used within this class. It should be removed to keep the codebase clean.

andreknieriem and others added 5 commits April 2, 2026 12:37
@andreknieriem
Copy link
Copy Markdown
Owner Author

This is added in branch 2.2.0 and will be merged/released soon.

@andreknieriem andreknieriem deleted the swc-again branch April 13, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant