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

Issue 508 - Update Location Services (v2) #1336

Merged
merged 8 commits into from Sep 8, 2017
Merged

Issue 508 - Update Location Services (v2) #1336

merged 8 commits into from Sep 8, 2017

Conversation

heyjamesknight
Copy link
Contributor

  • Added LocationClient
    • Hides old Android/new Play Services implementations behind a shared Interface.
    • Moved old Location code into AndroidLocationClient.
    • Created new GoogleLocationClient which uses Play Service's FusedLocationProvider to provide Location updates.
  • Updated Location Activities to use the new LocationClient
    • GeoPointActivity, GeoPointMapActivity, GeoPointOsmMapActivity, GeoShapeGoogleMapActivity, GeoTraceGoogleMapActivity, GeoTraceOsmMapActivity were updated.
    • GeoShapeOsmActivity was left using the legacy code, as the new LocationClient does not provide a way to determine if specific LocationProviders are available.
  • Added Unit Tests for LocationClient implementations.
  • Added Robolectric tests for Activities.
  • Removed legacy InfoLogger from 2013.

@heyjamesknight
Copy link
Contributor Author

Copying @lognaturel's comment from the previous PR:

Things we should try on real devices:
not having Play Services installed -- GeoPoint with no map and GeoShape with Open Street Map should still work
slower device, compare against currently-released version

@lognaturel
Copy link
Member

@mmarciniak90 this one is going to be super fun to test because it has to be done outside! Also, for verifying GeoTrace, we're going to need to do some moving around so hopefully you can take the opportunity for a nice walk with a backpack full of phones. 😊

The goal here is to make sure that the behavior of the geo widgets is either the same or improved in terms of how long it takes to acquire high-accuracy readings and resource usage (battery/memory). Unfortunately, documentation isn't super clear on what the behavior used to be and what improvements we should expect. In particular, with the previous APIs we had no control or visibility in how often the position was refreshed. @jknightco examined the behavior of his Nexus 5 and went for a refresh frequency of 5 seconds. With the old APIs, different devices may have had dramatically different behavior so it might be helpful to establish some kind of baseline. I'm planning on taking a 30 minute walk with a geotrace from v1.9.1 in automatic mode taking readings every 20 seconds. I'll then report the accuracy of those readings and the change in battery %. Then I'll do the same route with this new branch and compare. I will also try to do the same in a vehicle. If anyone has other ideas for verifying the behavior on real devices, that would be great.

In general, the details of these widgets aren't deeply documented so as we're identifying their actual behavior it would be helpful to write things down.

@heyjamesknight
Copy link
Contributor Author

@mmarciniak90 if you have any questions about expected behavior on any of the Activities (or anything related to these updates) I believe I have a relatively good understanding of what each should be doing at this point.

@mmarciniak90
Copy link
Contributor

I finished first part of tests. I have observed improvements on all devices.

  • On apk without these changes, the best accuracy was about ~20m and this accuracy was achieved in about ~20-35 seconds (depend on device).
  • On apk with these changes, the best accuracy was 10m and this accuracy was achieved in about 14-25 seconds . Achieving 20m accuracy takes only about 3-5 seconds.

@lognaturel
Copy link
Member

That's great, @mmarciniak90! Is that indoors by any chance? Outdoors I can get to 4.551 pretty quickly with both versions.

@mmarciniak90
Copy link
Contributor

I finished an outdoors tests. Results were compared on version 1.9.1 and on apk from pr.
Testes were executed on:

  • Sony Z3 with Android 6.0,
  • Huawei Y5 with Android 5.1,
  • Samsung J1 with Android 4.4.

ODK version 1.9.1
Devices connected to WIFI.
Location mode : High accuracy

Android 6.0 Android 5.1 Android 4.4
6 sec - 25 m 7 sec - 15 m 5 sec - 32 m
37 sec - 7m 11 sec - 5 m 16 sec - 8 m
battery usage 2% battery usage 4% unnoticeable battery usage

ODK version 1.9.1
Devices were not connected to WIFI.
Location mode : GPS only

Android 6.0 Android 5.1 Android 4.4
33 sec - 8 m 6 sec - 5 m 28 sec - 6 m
battery usage 1% battery usage 1% battery usage 1%

ODK pr/#1336
Devices connected to WIFI.
Location mode : High accuracy

Android 6.0 Android 5.1 Android 4.4
4 sec - 4 m 25 sec - 6 m 13 sec - 8 m
unnoticeable battery usage unnoticeable battery usage unnoticeable battery usage

ODK pr/#1336
Devices were not connected to WIFI.
Location mode : GPS only

Android 6.0 Android 5.1 Android 4.4
39 sec - 9 m Location provider problem Location provider problem
unnoticeable battery usage Location provider problem Location provider problem

screenshot_2017-08-17-11-57-52

@lognaturel
Copy link
Member

Thanks, @mmarciniak90! Interesting about the location provider problem, hopefully there's a fix for that.

I went on a couple of geotrace walks today. I had some initial frustrations because currently traces reset when the screen locks or the orientation changes. I was hoping for an accuracy comparison but accuracy is not currently collected in traces. I have documented these things in an idealized geo widget spec that we can continue evolving so we can make a set of improvements at once.

device version start battery % end battery % points
Moto G4 1.9.1 94 90 25
Moto G4 pr/#1336 90 87 27
Galaxy Tab A 1.9.1 29 26 23
Galaxy Tab A pr/#1336 19 16 28

No significant difference in power consumption. The traces looked similar so there aren't any wild changes in accuracy.

@grzesiek2010
Copy link
Member

grzesiek2010 commented Aug 24, 2017

I tested this pr today.
Overall I think it works a little better (when it works). I agree with Marzena it doesn't work for GPS Only mode at all and unfortunately I was able to notice the same behavior for High accuracy too (don't know why it works randomly).
That's why I decided not to collect precise result as it's not easy because of that bug. We need to fix that first and then we can continue testing. I tested geotrace too and it looks ok.
@jknightco do you know what is wrong?

@heyjamesknight
Copy link
Contributor Author

Hey folks, back from Greece, sorry for the delays. Looking into what's wrong today.

@heyjamesknight
Copy link
Contributor Author

Looks to be a timing issue related to when getLocationAvailability() returns true with the new Fused Location API. Would explain why it always shows with GPS and only sometimes with high priority—sometimes we already have a cached location ready with High Accuracy whereas GPS is always going to require a fix.

Looking to see what's the best route forward here.

@heyjamesknight
Copy link
Contributor Author

Fixed the error, but still not receiving location updates when only GPS is on. Looking into it now.

@heyjamesknight
Copy link
Contributor Author

heyjamesknight commented Aug 28, 2017

Ha Ha! The bug was inside me all along: I walked out of the city center and was able to finally get a GPS signal no problem. Derp.

The good news is everything should be working great now.

@lognaturel
Copy link
Member

Wow, cities are something! I don't have a device running Android < 6.0 to verify on but I did verify that all modes work on my devices. @grzesiek2010 could you please take another verification pass?

@grzesiek2010
Copy link
Member

Sure I'll do that.

@grzesiek2010
Copy link
Member

grzesiek2010 commented Sep 1, 2017

I've tested geotrace using two devices. I've used automatic mode recording one point every 30sec.

Location mode : High accuracy

device version time start battery % end battery %
Android 5.0.1 ODK Collect 1.9.1 20min 89 77
Android 5.0.1 ODK pr/#1336 20min 75 66
Android 6.0.1 ODK Collect 1.9.1 20min 85 78
Android 6.0.1 ODK pr/#1336 20min 93 87

Location mode : GPS Only

device version time start battery % end battery %
Android 5.0.1 ODK Collect 1.9.1 30min 48 33
Android 5.0.1 ODK pr/#1336 30min 65 52
Android 6.0.1 ODK Collect 1.9.1 30min 77 68
Android 6.0.1 ODK pr/#1336 30min 66 57

Summarizing both tables new functionality probably takes a little less battery or the same in the worst case.

I have also noticed that I lost my location in a few cases using ODK Collect 1.9.1 and I've never noticed the same problem using the new one - looks like an improvement.

I was in transits of course it's not a fake data from one place 😃

I'll add results of testing simple location widget when I finish.

@heyjamesknight
Copy link
Contributor Author

GeoTrace is actually a place where we can see some pretty drastic battery improvements—I didn't realize previously that the user was able to set how often they wanted to record a data point. We could change the update frequency based on that value and see some pretty serious improvements.

@lognaturel
Copy link
Member

@jknightco Very true! The ideal would be for the update to happen right before the next point is collected, right? Any ideas on how you'd set it based on the user preference? Exactly matching it doesn't seem right. Especially in a vehicle, if the update frequency is too low values could get pretty far off. I'm imagining that if the trace refresh is 1 minute and the update frequency is also 1 minute I could just miss getting a new position before the next point is taken.

@heyjamesknight
Copy link
Contributor Author

heyjamesknight commented Sep 1, 2017 via email

@mmarciniak90
Copy link
Contributor

I tested a 'GPS Only' mode. I verified this fix on devices with Android: v4.2, v4.4, v5.1.
The problem is no longer visible.
I did not notice a regression on higher Android versions.

@grzesiek2010
Copy link
Member

and I can confirm it works properly using the lowest supported API 16. I used Samsung Galaxy Young S6310 Android 4.1.2.
So what's next? @jknightco are you going to implement those improvements you mentioned as a part of this pr or it should be a separate one?

@lognaturel
Copy link
Member

Let's merge this first since it's now a clear improvement. We're still in our after-release freeze since we'll almost certainly have to put out a 1.10.2 release for getodk/javarosa#180 so we'll wait until that's done.

@heyjamesknight
Copy link
Contributor Author

@lognaturel Merge should be ready to go now, pending CI passes.

@mmarciniak90
Copy link
Contributor

Confirmed during release testing.

@opendatakit-bot unlabel "needs testing"

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.

5 participants