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

[Android Auto] Start declaring apis with java interop #6292

Merged
merged 1 commit into from
Sep 9, 2022

Conversation

kmadsen
Copy link
Contributor

@kmadsen kmadsen commented Sep 8, 2022

Description

I'm taking an idea from the maps repository. There is a CarJavaInterfaceChecker which helps verify interfaces with java.

We are declaring stable apis https://github.com/mapbox/navigation-sdks/issues/1904

There has also been a request for java mapbox/mapbox-navigation-android-examples#139.

So it is best we get started with defining apis that work will work with java.

@kmadsen kmadsen requested a review from a team as a code owner September 8, 2022 22:37
@kmadsen kmadsen added the Android Auto Bugs, improvements and feature requests on Android Auto. label Sep 8, 2022
@kmadsen kmadsen force-pushed the km-androidauto-java-interop branch 2 times, most recently from be8dbbd to 49942ec Compare September 9, 2022 00:18
@kmadsen kmadsen force-pushed the km-androidauto-java-interop branch from f2b63c9 to 83db7ec Compare September 9, 2022 22:03
@kmadsen kmadsen force-pushed the km-androidauto-java-interop branch from 83db7ec to 25a0c4a Compare September 9, 2022 22:10
@kmadsen kmadsen enabled auto-merge (squash) September 9, 2022 22:28
@codecov
Copy link

codecov bot commented Sep 9, 2022

Codecov Report

Merging #6292 (25a0c4a) into main (c9a1859) will decrease coverage by 0.03%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #6292      +/-   ##
============================================
- Coverage     68.89%   68.85%   -0.04%     
+ Complexity     4454     4453       -1     
============================================
  Files           668      668              
  Lines         26688    26690       +2     
  Branches       3147     3147              
============================================
- Hits          18387    18378       -9     
- Misses         7093     7104      +11     
  Partials       1208     1208              
Impacted Files Coverage Δ
...x/navigation/core/lifecycle/MapboxNavigationApp.kt 18.75% <0.00%> (-1.25%) ⬇️
...om/mapbox/navigation/dropin/NavigationViewModel.kt 0.00% <0.00%> (-69.24%) ⬇️

@kmadsen kmadsen merged commit 9bc938b into main Sep 9, 2022
@kmadsen kmadsen deleted the km-androidauto-java-interop branch September 9, 2022 22:53
@@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone.
#### Features
#### Bug fixes and improvements
- Optimized calls to modify route arrow layer visibility. [#6308](https://github.com/mapbox/mapbox-navigation-android/pull/6308)
- Provide better java support for `MapboxNavigationApp`. [#6292](https://github.com/mapbox/mapbox-navigation-android/pull/6292)
Copy link
Contributor

@RingerJK RingerJK Sep 12, 2022

Choose a reason for hiding this comment

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

should we automate checks if any of public objects' functions or public static functions don't have java interrupt @kmadsen ?

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.

Hmm I don't know I just lost some confidence in the @JvmStatic https://mapbox.atlassian.net/browse/NAVSDK-544

https://issuetracker.google.com/issues/158393309

java.lang.IncompatibleClassChangeError: The method 'com.mapbox.navigation.core.lifecycle.MapboxNavigationApp com.mapbox.navigation.core.lifecycle.MapboxNavigationApp.registerObserver(com.mapbox.navigation.core.lifecycle.MapboxNavigationObserver)' was expected to be of type virtual but instead was found to be of type static (declaration of 'com.mapbox.androidauto.MapboxCarApp' appears in /data/app/~~wWRVVkoksDjAWyl1zcYreA==/com.mapbox.navigation.qa_test_app-grYQDy8r9n-vE5Z1qLuR0Q==/base.apk!classes5.dex)

It changes the method signature so any changes will risk SEMVER

Copy link
Contributor Author

Choose a reason for hiding this comment

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

2.8 is the first stable version for MapboxNavigationApp so this could be fine. But for other functions that have had previous stable versions - it will change the method signature.

Copy link
Contributor

Choose a reason for hiding this comment

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

The crash looks like it should be fixed by #6316.

* Java interoperability. Provides access to any registered observer instance. If multiple
* instances of the same class have been registered, the first observer will be returned.
*
* @throws IllegalStateException when the class has not been registered.
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we want to add @Throws annotation? It provides better java interoperability. Although in this case it doesn't matter since IllegalStateException is unchecked. However, I think it's a good pattern.

}
}

interface Consumer<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is java.util.function.Consumer, why do you need this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't use it because it requires api 24

Screen Shot 2022-09-12 at 12 52 13 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Auto Bugs, improvements and feature requests on Android Auto.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants