Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/test-and-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,17 @@ jobs:
run: flutter pub global activate patrol_cli ${{ env.patrol_cli_version }}
- name: Run flutter pub get
run: flutter pub get
- name: Clean up runner disk space (if needed)
run: |
echo "Running cleanup..."

# Remove large, unneeded packages
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/share/boost

echo "Cleanup complete. Free space after cleanup:"
df -h
- name: Create and start emulator
run: |
echo "Installing system image"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,8 @@ open class AndroidAutoBaseScreen(carContext: CarContext) :
private fun initializeNavigationListener() {
GoogleMapsNavigationSessionManager.navigationReadyListener = this
mIsNavigationReady =
try {
GoogleMapsNavigationSessionManager.getInstance().isInitialized()
} catch (exception: RuntimeException) {
// If GoogleMapsNavigationSessionManager is not initialized navigation is not ready.
false
}
GoogleMapsNavigatorHolder.getInitializationState() ==
GoogleNavigatorInitializationState.INITIALIZED
}

private fun initializeSurfaceCallback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ package com.google.maps.flutter.navigation

class GoogleMapsNavigationInspectorHandler(private val viewRegistry: GoogleMapsViewRegistry) :
NavigationInspector {
private fun manager(): GoogleMapsNavigationSessionManager {
return GoogleMapsNavigationSessionManager.getInstance()
}

override fun isViewAttachedToSession(viewId: Long): Boolean {
/// Is session exists, it's automatically attached to any existing view.
if (viewRegistry.getNavigationView(viewId.toInt()) != null) {
return manager().isInitialized()
return GoogleMapsNavigatorHolder.getInitializationState() ==
GoogleNavigatorInitializationState.INITIALIZED
}
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.maps.flutter.navigation

import android.app.Application
import androidx.lifecycle.Lifecycle
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
Expand All @@ -25,10 +26,11 @@ import io.flutter.embedding.engine.plugins.lifecycle.FlutterLifecycleAdapter
/** GoogleMapsNavigationPlugin */
class GoogleMapsNavigationPlugin : FlutterPlugin, ActivityAware {
companion object {
private var instance: GoogleMapsNavigationPlugin? = null
private val instances = mutableListOf<GoogleMapsNavigationPlugin>()

/** Returns the first instance, which should always be the main Flutter engine. */
fun getInstance(): GoogleMapsNavigationPlugin? {
return instance
return instances.firstOrNull()
}
}

Expand All @@ -40,11 +42,12 @@ class GoogleMapsNavigationPlugin : FlutterPlugin, ActivityAware {
private var viewMessageHandler: GoogleMapsViewMessageHandler? = null
private var imageRegistryMessageHandler: GoogleMapsImageRegistryMessageHandler? = null
private var autoViewMessageHandler: GoogleMapsAutoViewMessageHandler? = null
internal var sessionManager: GoogleMapsNavigationSessionManager? = null

private var lifecycle: Lifecycle? = null

override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
instance = this
synchronized(instances) { instances.add(this) }

// Init view registry and its method channel handlers
viewRegistry = GoogleMapsViewRegistry()
Expand All @@ -57,18 +60,25 @@ class GoogleMapsNavigationPlugin : FlutterPlugin, ActivityAware {
imageRegistryMessageHandler = GoogleMapsImageRegistryMessageHandler(imageRegistry!!)
ImageRegistryApi.setUp(binding.binaryMessenger, imageRegistryMessageHandler)

// Setup auto map view method channel handlers
autoViewMessageHandler = GoogleMapsAutoViewMessageHandler(viewRegistry!!)
AutoMapViewApi.setUp(binding.binaryMessenger, autoViewMessageHandler)
autoViewEventApi = AutoViewEventApi(binding.binaryMessenger)

// Setup navigation session manager
val app = binding.applicationContext as Application
val navigationSessionEventApi = NavigationSessionEventApi(binding.binaryMessenger)
sessionManager = GoogleMapsNavigationSessionManager(navigationSessionEventApi, app)

// Setup platform view factory and its method channel handlers
viewEventApi = ViewEventApi(binding.binaryMessenger)
val factory = GoogleMapsViewFactory(viewRegistry!!, viewEventApi!!, imageRegistry!!)
binding.platformViewRegistry.registerViewFactory("google_navigation_flutter", factory)

// Setup auto map view method channel handlers
autoViewMessageHandler = GoogleMapsAutoViewMessageHandler(viewRegistry!!)
AutoMapViewApi.setUp(binding.binaryMessenger, autoViewMessageHandler)
autoViewEventApi = AutoViewEventApi(binding.binaryMessenger)
// Setup navigation session message handler with this instance's session manager
val sessionMessageHandler = GoogleMapsNavigationSessionMessageHandler(sessionManager!!)
NavigationSessionApi.setUp(binding.binaryMessenger, sessionMessageHandler)

// Setup navigation session manager and its method channel handlers
GoogleMapsNavigationSessionManager.createInstance(binding.binaryMessenger)
val inspectorHandler = GoogleMapsNavigationInspectorHandler(viewRegistry!!)
NavigationInspector.setUp(binding.binaryMessenger, inspectorHandler)
}
Expand All @@ -80,36 +90,37 @@ class GoogleMapsNavigationPlugin : FlutterPlugin, ActivityAware {
AutoMapViewApi.setUp(binding.binaryMessenger, null)
NavigationInspector.setUp(binding.binaryMessenger, null)

GoogleMapsNavigationSessionManager.destroyInstance()
binding.applicationContext.unregisterComponentCallbacks(viewRegistry)

// Cleanup references
sessionManager = null
viewRegistry = null
viewMessageHandler = null
imageRegistryMessageHandler = null
viewEventApi = null
imageRegistry = null
autoViewMessageHandler = null
autoViewEventApi = null
instance = null

synchronized(instances) { instances.remove(this) }
}

private fun attachActivity(binding: ActivityPluginBinding) {
lifecycle =
FlutterLifecycleAdapter.getActivityLifecycle(binding).also { lc ->
viewRegistry?.let(lc::addObserver)
GoogleMapsNavigationSessionManager.getInstanceOrNull()?.let(lc::addObserver)
sessionManager?.let(lc::addObserver)
}
GoogleMapsNavigationSessionManager.getInstanceOrNull()?.onActivityCreated(binding.activity)
sessionManager?.onActivityCreated(binding.activity)
}

private fun detachActivity(forConfigChange: Boolean) {
lifecycle?.let { lc ->
viewRegistry?.let(lc::removeObserver)
GoogleMapsNavigationSessionManager.getInstanceOrNull()?.let(lc::removeObserver)
sessionManager?.let(lc::removeObserver)
}

GoogleMapsNavigationSessionManager.getInstanceOrNull()?.onActivityDestroyed(forConfigChange)
sessionManager?.onActivityDestroyed(forConfigChange)
lifecycle = null
}

Expand Down
Loading
Loading