-
Notifications
You must be signed in to change notification settings - Fork 120
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
Telemetry module #282
Conversation
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<>(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit unnecessary log?
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit constant
There was a problem hiding this comment.
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."); |
There was a problem hiding this comment.
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."); |
There was a problem hiding this comment.
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."); |
There was a problem hiding this comment.
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."); |
There was a problem hiding this comment.
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."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit unnecessary log?
@tobrun Thanks much for the review, I've addressed now the most immediate issues. Care to give it another pass? |
Extracted from the main SDK and refactored for a more loosely coupled architecture. Please note this is still a WIP.
Next steps
/cc: @mapbox/android