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

Handle cases where native API is present but unavailable #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pmundt
Copy link

@pmundt pmundt commented May 10, 2019

The isPresent test only lets us know whether the native getFromLocation and getFromLocationName APIs are available, but doesn't say anything about the APIs ability to return results. In cases where either of these APIs fail, despite being present, an empty list is returned, which is then passed off as a success to the higher levels. From the flutter client side, this then results in a null gRPC call, despite having otherwise succeeded at the lower levels and consequently having failed to raise any exceptions.

The simplest solution, and the one used here, is to test the number of addresses returned by the native APIs, and in cases where this is 0, simply throw a NotAvailableException.

A more elaborate solution would be to check the number of addresses returned, and fall back on an alternative method of lookup, but this is left as future work.

This should also provide an improvement to the situation observed in issue #19

The isPresent test only lets us know whether the native getFromLocation and getFromLocationName APIs are
available, but doesn't say anything about the APIs ability to return results. In cases where either of these APIs fail,
despite being present, an empty list is returned, which is then passed off as a success to the higher levels. From
the flutter client side, this then results in a null gRPC call, despite having otherwise succeeded at the lower levels
and consequently having failed to raise any exceptions.

The simplest solution, and the one used here, is to test the number of addresses returned by the native APIs,
and in cases where this is 0, simply throw a NotAvailableException.

A more elaborate solution would be to check the number of addresses returned, and fall back on an alternative
method of lookup, but this is left as future work.
@aloisdeniel
Copy link
Owner

I have difficulties to understand : having no result from a call is really different than an unavailable APIs. What if there's really no result ? Then the client would think that there's an error and would retry again ?

Mayber it is in the definition of the Android APIs. I will look more closely as soon as I have more free time ! :)

Thanks for the contribution !

@pmundt
Copy link
Author

pmundt commented May 12, 2019

Unfortunately, from an API point of view, there is no way to determine whether there is no result or whether the service is simply unavailable. You can see the comment on the isPresent method:

https://developer.android.com/reference/android/location/Geocoder#isPresent()

which states that

Returns true if the Geocoder methods getFromLocation and getFromLocationName are implemented. Lack of network connectivity may still cause these methods to return null or empty lists.

The end result of which is when these APIs are available but not functional, a null or empty list is returned. Others have also observed this issue:

https://stackoverflow.com/questions/24804982/geocoder-returns-empty-list-on-real-device

On one of my devices isPresent suggests that the APIs are available, but I only receive back an empty list, regardless of which coordinates I hand it, and regardless of the connection state. For the moment, I am trapping the exception at the flutter application level and can then wrap up the local and remote lookup methods in a set of helper routines - this is sufficient to fallback on the remote method in case the local implementation does not return anything, and also allows for checking the connectivity state to try and see if the reason the local implementation is not returning anything is connection-based or not.

Unfortunately the way the native API has been implemented, there is no way to determine whether the lack of a result is because the result doesn't exist, the service is simply unavailable, or whether the service works at all.

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.

2 participants