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

Sunset telemetry service #351

Merged
merged 8 commits into from
Mar 6, 2019
Merged

Sunset telemetry service #351

merged 8 commits into from
Mar 6, 2019

Conversation

andrlee
Copy link
Contributor

@andrlee andrlee commented Mar 4, 2019

This refactor migrates location traces collection feature from being backed by Android Service.
Telemetry location traces collection relies on Service to do background work, this approach no longer works on apps that target Android 8.0 (API level 26) or higher due to OS limitations imposed on what apps can do while running in the background: https://developer.android.com/about/versions/oreo/background.

Refactor objectives:

  • Support location data collection while app is in background on Oreo and above.
  • Extract location collection component from core telemetry.
  • Achieve dependency inversion between core telemetry and location components.
  • Encapsulate location collection controller and build foundation for the state machine.
  • Integrate with existing mapbox core telemetry in backwards compatible way.

new HandlerThread("LocationSettingsChangeThread"),
applicationContext.getSharedPreferences(MAPBOX_SHARED_PREFERENCES, Context.MODE_PRIVATE),
// Provide empty token as it is not available yet
new MapboxTelemetry(applicationContext, "", LOCATION_COLLECTOR_USER_AGENT));
Copy link
Contributor

Choose a reason for hiding this comment

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

I am confused here as MapboxTelemetry is the API class we provide for MapSdk and AutoSDK, they will create a instance of MapboxTelemetry to push gesture events etc, but we create another instance here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MapboxTelemetry is no longer coupled with location collection and hence becomes responsible for eventing only. You can treat LocationCollectionClient as producer of location events, which are delivered to the api-events endpoint via MapboxTelemetry.


import static com.mapbox.android.telemetry.location.LocationCollectionClient.DEFAULT_SESSION_ROTATION_INTERVAL_HOURS;

public class MapboxTelemetryInitProvider extends ContentProvider {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need a ContentProvider here? Just for init?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it's a hacky way to execute your code at app startup

Changing implementation details around how session
id is managed due to limitation with what can be shared
with location pending intent.
@codecov
Copy link

codecov bot commented Mar 6, 2019

Codecov Report

Merging #351 into master will increase coverage by 2.06%.
The diff coverage is 40%.

@@             Coverage Diff              @@
##             master     #351      +/-   ##
============================================
+ Coverage     54.67%   56.73%   +2.06%     
+ Complexity      516      491      -25     
============================================
  Files           107      102       -5     
  Lines          3367     3190     -177     
  Branches        227      219       -8     
============================================
- Hits           1841     1810      -31     
+ Misses         1435     1293     -142     
+ Partials         91       87       -4

Copy link
Contributor

@Chaoba Chaoba left a comment

Choose a reason for hiding this comment

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

One comment, others look good to me

new HandlerThread("LocationSettingsChangeThread"),
new SessionIdentifier(defaultInterval),
applicationContext.getSharedPreferences(MAPBOX_SHARED_PREFERENCES, Context.MODE_PRIVATE),
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use TelemetryUtils.obtainSharedPreferences here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is intentional: TelemetryUtils should not be public, the plan is to downgrade its visibility to package private at some point. Hence i prefer to avoid creating any dependencies on it going forward.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, but keep in mind we may have strict mode issue here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you suggesting to access it on the background thread?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, my thought is that we could create a sharedPreference later and put all background threads in it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i need shared preferences at startup but i will make sure there's no impact on cold start by deferring init to background thread.

@andrlee andrlee merged commit 36dcdfc into master Mar 6, 2019
@andrlee andrlee deleted the al-sunset-telem-service branch March 28, 2019 00:10
@andrlee andrlee mentioned this pull request Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants