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

Telemetry module #282

Merged
merged 25 commits into from
Jan 25, 2017
Merged

Telemetry module #282

merged 25 commits into from
Jan 25, 2017

Conversation

zugaldia
Copy link
Member

@zugaldia zugaldia commented Jan 20, 2017

Extracted from the main SDK and refactored for a more loosely coupled architecture. Please note this is still a WIP.

Next steps

  • Improve logging (bring back Timber).
  • App testing (battery usage, data quality, memory leaks via Leak Canary).
    • Hook up location updates in local broadcast receiver.
  • Team review

/cc: @mapbox/android

@zugaldia zugaldia changed the title [WIP] Telemetry module Telemetry module Jan 24, 2017
@zugaldia
Copy link
Member Author

I've included all the changes I wanted for this iteration, CI is approving.

@tobrun or @ivovandongen please review.

private DisplayMetrics displayMetrics = null;
private Intent batteryStatus = null;
private TelemetryClient client = null;
private Vector<Hashtable<String, Object>> events = new Vector<>();
Copy link
Member

Choose a reason for hiding this comment

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

Is their a reason why Vector > List for this use-case?

Copy link
Member Author

@zugaldia zugaldia Jan 24, 2017

Choose a reason for hiding this comment

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

I believe the rationale behind using Vector here is that all operations are synchronized as we expect events coming from different threads. I'd explore other approaches in a separate ticket.

*
* @return MapboxTelemetry
*/
public static MapboxTelemetry getInstance() {
Copy link
Member

Choose a reason for hiding this comment

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

synchronised keyword for thread safety or annotate the method to be called only from main thread?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. This got lost somehow, added now.

* @param accessToken The accessToken associated with the application
* @param locationEngine Initialize telemetry with a custom location engine
*/
public void initialize(@NonNull Context context, @NonNull String accessToken,
Copy link
Member

Choose a reason for hiding this comment

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

Some thoughts: I'm not a big supporter of the Singleton paradigm with a separate initialization method. I think this can be overcome by using a separate parameterized getInstance method and handling those parameters as static (see MapboxMap.java in GL SDK) or by extracting some logic and wrapping it around a factory or other design pattern.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. Let's ticket that separately.

return;
}

Timber.v("Initializing telemetry.");
Copy link
Member

Choose a reason for hiding this comment

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

Nit unnecessary log?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. Notice all this log calls are .v as in verbose. These can easily be filtered out by the right Timber Tree. Either way, we can remove these after the SDK happens and we're sure the refactor is working as expected.

context.getPackageName(), PackageManager.GET_SERVICES);
if (packageInfo.services != null) {
for (ServiceInfo service : packageInfo.services) {
if (TextUtils.equals("com.mapbox.services.android.telemetry.service.TelemetryService", service.name)) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit constant

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, extracted as TelemetryConstants.TELEMETRY_SERVICE_NAME.

@Override
public void onCreate() {
// Enable location listening for lifecycle of app
Timber.v("Create event.");
Copy link
Member

Choose a reason for hiding this comment

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

Nit unnecessary log?

*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Timber.v("Start command event.");
Copy link
Member

Choose a reason for hiding this comment

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

Nit unnecessary log?

*/
@Override
public void onTaskRemoved(Intent rootIntent) {
Timber.v("Task removed event.");
Copy link
Member

Choose a reason for hiding this comment

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

Nit unnecessary log?

*/
@Override
public void onDestroy() {
Timber.v("Destroy event.");
Copy link
Member

Choose a reason for hiding this comment

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

Nit unnecessary log?


private void shutdownTelemetryService() {
try {
Timber.v("Unregistering location receiver.");
Copy link
Member

Choose a reason for hiding this comment

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

Nit unnecessary log?

@cammace cammace added this to the v2.0.0 milestone Jan 24, 2017
@zugaldia
Copy link
Member Author

@tobrun Thanks much for the review, I've addressed now the most immediate issues. Care to give it another pass?

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.

3 participants