Skip to content

Commit

Permalink
fix: android auto service binding fix
Browse files Browse the repository at this point in the history
  • Loading branch information
illuminati1911 authored and jokerttu committed Nov 28, 2024
1 parent 3567a3a commit 377f7d9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.GoogleMapOptions
import com.google.android.libraries.navigation.NavigationViewForAuto


open class AndroidAutoBaseScreen(carContext: CarContext) : Screen(carContext), SurfaceCallback, NavigationReadyListener {
open class AndroidAutoBaseScreen(carContext: CarContext) :
Screen(carContext), SurfaceCallback, NavigationReadyListener {
private val VIRTUAL_DISPLAY_NAME = "AndroidAutoNavScreen"
private var mVirtualDisplay: VirtualDisplay? = null
private var mPresentation: Presentation? = null
Expand All @@ -55,19 +55,25 @@ open class AndroidAutoBaseScreen(carContext: CarContext) : Screen(carContext), S

private fun initializeNavigationListener() {
GoogleMapsNavigationSessionManager.navigationReadyListener = this
mIsNavigationReady = GoogleMapsNavigationSessionManager.getInstance().isInitialized()
try {
mIsNavigationReady = GoogleMapsNavigationSessionManager.getInstance().isInitialized()
} catch (exception: RuntimeException) {
// If GoogleMapsNavigationSessionManager is not initialized navigation is not ready.
mIsNavigationReady = false
}
}

private fun initializeSurfaceCallback() {
carContext.getCarService(AppManager::class.java).setSurfaceCallback(this)
}

private val mLifeCycleObserver: LifecycleObserver = object : DefaultLifecycleObserver {
override fun onDestroy(owner: LifecycleOwner) {
GoogleMapsNavigationSessionManager.navigationReadyListener = null
mIsNavigationReady = false
private val mLifeCycleObserver: LifecycleObserver =
object : DefaultLifecycleObserver {
override fun onDestroy(owner: LifecycleOwner) {
GoogleMapsNavigationSessionManager.navigationReadyListener = null
mIsNavigationReady = false
}
}
}

private fun isSurfaceReady(surfaceContainer: SurfaceContainer): Boolean {
return surfaceContainer.surface != null &&
Expand Down Expand Up @@ -163,7 +169,7 @@ open class AndroidAutoBaseScreen(carContext: CarContext) : Screen(carContext), S
) {}
}

fun sendAutoScreenAvailabilityChangedEvent(isAvailable: Boolean) {
private fun sendAutoScreenAvailabilityChangedEvent(isAvailable: Boolean) {
GoogleMapsNavigationPlugin.getInstance()?.autoViewEventApi?.onAutoScreenAvailabilityChanged(
isAvailable
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private constructor(private val navigationSessionEventApi: NavigationSessionEven
return instance!!
}
}

private var navigator: Navigator? = null
private var isNavigationSessionInitialized = false
private var arrivalListener: Navigator.ArrivalListener? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ class SampleAndroidAutoSession(sessionInfo: SessionInfo): Session() {
lifecycle.addObserver(object: DefaultLifecycleObserver {
override fun onCreate(owner: LifecycleOwner) {
Log.i(TAG, "In onCreate()")
}

override fun onStart(owner: LifecycleOwner) {
Log.i(TAG, "In onStart()")
carContext
.bindService(
Intent(carContext, SampleAndroidAutoService::class.java),
Expand All @@ -51,6 +47,10 @@ class SampleAndroidAutoSession(sessionInfo: SessionInfo): Session() {
)
}

override fun onStart(owner: LifecycleOwner) {
Log.i(TAG, "In onStart()")
}

override fun onResume(owner: LifecycleOwner) {
Log.i(TAG, "In onResume()")
}
Expand All @@ -61,11 +61,11 @@ class SampleAndroidAutoSession(sessionInfo: SessionInfo): Session() {

override fun onStop(owner: LifecycleOwner) {
Log.i(TAG, "In onStop()")
carContext.unbindService(mServiceConnection)
}

override fun onDestroy(owner: LifecycleOwner) {
Log.i(TAG, "In onDestroy()")
carContext.unbindService(mServiceConnection)
}
})
}
Expand Down

0 comments on commit 377f7d9

Please sign in to comment.