Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SharedApp backwards compatible and removable #6303

Closed
wants to merge 1 commit into from

Conversation

kmadsen
Copy link
Contributor

@kmadsen kmadsen commented Sep 9, 2022

Description

Resolves #6253

There is an incompatibility with SharedApp where it can only be setup once and it is the only opportunity to specify custom services https://github.com/mapbox/mapbox-navigation-android/pull/6213/files#r964971123

Every time the SharedApp.setup function changes it will break compatibility with anything that uses it. Converting the SharedApp to a MapboxNavigationObserver to resolve it and removing customizability so it can stay backwards compatible.

On the topic of, creating custom services like MapboxAudioGuidance. We should be discussing public api options for how to do so, that way the SharedApp will not break compatibility with AA. Am also considering that custom services can be swapped with MapboxNavigationApp.unregisterObserver and MapboxNavigationApp.registerObserver, which are going to be forever backwards compatible and they are public.

There is no public interface for declaring custom services so it should be removed from this SharedApp.setup function.

@kmadsen kmadsen requested a review from a team as a code owner September 9, 2022 16:35
@kmadsen kmadsen force-pushed the km-shared-app-backwards-compatible branch 2 times, most recently from 80d1dd4 to 1ecfb3f Compare September 9, 2022 16:41
CHANGELOG.md Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 9, 2022

Codecov Report

Merging #6303 (c9a1859) into main (c9a1859) will not change coverage.
The diff coverage is n/a.

❗ Current head c9a1859 differs from pull request most recent head 50ad972. Consider uploading reports for the commit 50ad972 to get more accurate results

Impacted file tree graph

@@            Coverage Diff            @@
##               main    #6303   +/-   ##
=========================================
  Coverage     68.89%   68.89%           
  Complexity     4454     4454           
=========================================
  Files           668      668           
  Lines         26688    26688           
  Branches       3147     3147           
=========================================
  Hits          18387    18387           
  Misses         7093     7093           
  Partials       1208     1208           

@kmadsen
Copy link
Contributor Author

kmadsen commented Sep 9, 2022

EDIT: solution was to register the MapboxAudioGuidance before the AudioGuidanceStateController

instrumentation test ran into this

Process: com.mapbox.navigation.instrumentation_tests, PID: 4267
java.lang.IllegalStateException: Class MapboxAudioGuidance is not been registered to MapboxNavigationApp
	at com.mapbox.navigation.core.lifecycle.MapboxNavigationOwner.getObserver(MapboxNavigationOwner.kt:75)
	at com.mapbox.navigation.core.lifecycle.MapboxNavigationOwner.getObserver(MapboxNavigationOwner.kt:70)
	at com.mapbox.navigation.core.lifecycle.MapboxNavigationAppDelegate.getObserver(MapboxNavigationAppDelegate.kt:66)
	at com.mapbox.navigation.core.lifecycle.MapboxNavigationApp.getObserver(MapboxNavigationApp.kt:168)
	at com.mapbox.navigation.ui.app.internal.controller.AudioGuidanceStateController.onAttached(AudioGuidanceStateController.kt:50)
	at com.mapbox.navigation.core.lifecycle.MapboxNavigationOwner.register(MapboxNavigationOwner.kt:48)
	at com.mapbox.navigation.core.lifecycle.MapboxNavigationAppDelegate.registerObserver(MapboxNavigationAppDelegate.kt:53)
	at com.mapbox.navigation.core.lifecycle.MapboxNavigationApp.registerObserver(MapboxNavigationApp.kt:150)
	at 

@kmadsen kmadsen force-pushed the km-shared-app-backwards-compatible branch 2 times, most recently from f5a607e to d98d130 Compare September 9, 2022 17:44
@kmadsen kmadsen changed the title Make SharedApp backwards compatible Make SharedApp backwards compatible and removable Sep 9, 2022
@kmadsen kmadsen force-pushed the km-shared-app-backwards-compatible branch from d98d130 to 5b1eb0d Compare September 9, 2022 20:47
@kmadsen kmadsen marked this pull request as draft September 9, 2022 20:54
@kmadsen
Copy link
Contributor Author

kmadsen commented Sep 9, 2022

Back to draft on this one because I'm thinking it will create discussion.
It is also incomplete because it requires a merge, and a release and an update.

EDIT: actually i'm not finding more changes to make here so will leave it opn

@kmadsen kmadsen marked this pull request as ready for review September 9, 2022 21:04
@kmadsen kmadsen force-pushed the km-shared-app-backwards-compatible branch from 5b1eb0d to 9c502e1 Compare September 9, 2022 21:06
@kmadsen kmadsen force-pushed the km-shared-app-backwards-compatible branch from 9c502e1 to 50ad972 Compare September 9, 2022 21:13
@@ -109,7 +109,7 @@ class NavigationView @JvmOverloads constructor(
keepScreenOn = true
captureSystemBarsInsets()

SharedApp.setup(context.applicationContext as Application)
MapboxNavigationApp.registerObserver(SharedApp)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should be changing how SharedApp is integrated with NavigationView. Instead, we should leave SharedApp.setup(Application) call here and move MapboxNavigationApp.registerObserver(SharedApp) call inside SharedApp.setup method.
Registering SharedApp as MapboxNavigationObserver is an implementation detail that should be hidden from the public.

Copy link
Contributor Author

@kmadsen kmadsen Sep 12, 2022

Choose a reason for hiding this comment

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

Adding the point that SharedApp is still internal, but what we will want is a public version of SharedApp and then it can register an internal MapboxNavigationObserver object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why should setup(Application) be required though? The application context is passed to NavigationOptions

Copy link
Contributor

Choose a reason for hiding this comment

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

I added the application context requirement to get early access to the Context before MapboxNavigation and NavigationOptions are initialized.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But why does SharedApp need the early access to the Context. Everything that uses the context would be better to get it from MapboxNavigationObserver

@tomaszrybakiewicz
Copy link
Contributor

After applying the fix from this PR I am getting crash when opening "Default NavigationView" activity 2x in QA-Test-App:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.mapbox.navigation.qa_test_app, PID: 4971
    java.lang.IllegalStateException: There are multiple DataStores active for the same file: /data/user/0/com.mapbox.navigation.qa_test_app/files/datastore/mapbox_navigation_preferences.preferences_pb. You should either maintain your DataStore as a singleton or confirm that there is no two DataStore's active on the same file (by confirming that the scope is cancelled).
        at androidx.datastore.core.SingleProcessDataStore$file$2.invoke(SingleProcessDataStore.kt:168)
        at androidx.datastore.core.SingleProcessDataStore$file$2.invoke(SingleProcessDataStore.kt:163)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at androidx.datastore.core.SingleProcessDataStore.getFile(SingleProcessDataStore.kt:163)
        at androidx.datastore.core.SingleProcessDataStore.readData(SingleProcessDataStore.kt:380)
        at androidx.datastore.core.SingleProcessDataStore.readDataOrHandleCorruption(SingleProcessDataStore.kt:359)
        at androidx.datastore.core.SingleProcessDataStore.readAndInit(SingleProcessDataStore.kt:322)
        at androidx.datastore.core.SingleProcessDataStore.readAndInitOrPropagateFailure(SingleProcessDataStore.kt:311)
        at androidx.datastore.core.SingleProcessDataStore.handleRead(SingleProcessDataStore.kt:261)
        at androidx.datastore.core.SingleProcessDataStore.access$handleRead(SingleProcessDataStore.kt:76)
        at androidx.datastore.core.SingleProcessDataStore$actor$3.invokeSuspend(SingleProcessDataStore.kt:239)
        at androidx.datastore.core.SingleProcessDataStore$actor$3.invoke(Unknown Source:8)
        at androidx.datastore.core.SingleProcessDataStore$actor$3.invoke(Unknown Source:4)
        at androidx.datastore.core.SimpleActor$offer$2.invokeSuspend(SimpleActor.kt:122)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

@kmadsen kmadsen mentioned this pull request Sep 12, 2022
@kmadsen
Copy link
Contributor Author

kmadsen commented Sep 13, 2022

After some more discussion, SharedApp is not a class we really intend to make public. So making it backwards compatible is not the highest priority.

An initiative to install components with a public api is better served by the component installer

For android auto, we're looking for something along these lines #6304 where we can SharedApp from android auto.

@kmadsen
Copy link
Contributor Author

kmadsen commented Sep 15, 2022

Closing this one because we're planning on removing SharedApp from libnavui-androidauto entirely. Sharing public interfaces will be done as a separate effort. The approach will be more like this one #6304

@kmadsen kmadsen closed this Sep 15, 2022
@kmadsen kmadsen deleted the km-shared-app-backwards-compatible branch September 15, 2022 17:11
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.

Add ability to remove SharedApp state controllers
2 participants