Skip to content

Commit

Permalink
Properly cleanup disconnected AM/RHMI apps
Browse files Browse the repository at this point in the history
  • Loading branch information
hufman committed Dec 4, 2023
1 parent b2852f2 commit ae5765a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package io.bimmergestalt.headunit

import androidx.collection.SparseArrayCompat
import de.bmw.idrive.BMWRemoting
import de.bmw.idrive.BMWRemotingClient
import de.bmw.idrive.BaseBMWRemotingServer
import io.bimmergestalt.headunit.Utils.values
import io.bimmergestalt.headunit.managers.AMManager
import io.bimmergestalt.headunit.managers.RHMIManager
import io.flutter.Log
Expand Down Expand Up @@ -98,10 +96,10 @@ class BMWRemotingServerImpl(val client: BMWRemotingClient,

override fun am_dispose(handle: Int?) {
Log.i(TAG, "am_dispose")
val amHandle = amHandle ?: return
if (amHandle != handle) {
throw BMWRemoting.IllegalArgumentException(-1, "Incorrect AM handle")
}
val amHandle = amHandle ?: return
amManager.unregisterAppsByHandle(amHandle)
amManager.removeEventHandler(amHandle)
this.amHandle = null
Expand Down Expand Up @@ -276,10 +274,10 @@ class BMWRemotingServerImpl(val client: BMWRemotingClient,

override fun rhmi_dispose(handle: Int?) {
Log.i(TAG, "rhmi_dispose")
val rhmiHandle = rhmiHandle ?: return
if (rhmiHandle != handle) {
throw BMWRemoting.IllegalArgumentException(-1, "Incorrect RHMI handle")
}
val rhmiHandle = rhmiHandle ?: return
rhmiManager.unregisterAppsByHandle(rhmiHandle)
rhmiManager.removeActionHandler(rhmiHandle)
rhmiManager.removeEventHandler(rhmiHandle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AMManager(val callbacks: HeadunitCallbacks) {
}

fun unregisterApp(appId: String) {
val existing = knownApps[appId]
val existing = knownApps.remove(appId)
if (existing != null) {
callbacks.amUnregisterApp(appId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class RHMIManager(val callbacks: HeadunitCallbacks) {
}

fun unregisterApp(appId: String) {
val existing = knownApps[appId]
val existing = knownApps.remove(appId)
if (existing != null) {
callbacks.rhmiUnregisterApp(appId)
}
Expand Down Expand Up @@ -82,6 +82,7 @@ class RHMIManager(val callbacks: HeadunitCallbacks) {
value.id
// assume the destination model is ID
}
is Boolean -> value
is ByteArray -> value
is Number -> value
is String -> value
Expand Down

0 comments on commit ae5765a

Please sign in to comment.