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

Fix crash due to null context reference in LocationBroadcastReceiver #272

Merged
merged 1 commit into from
Nov 3, 2018

Conversation

andrlee
Copy link
Contributor

@andrlee andrlee commented Nov 3, 2018

Fix crashes and introduce temporary refactor for TelemetryUtils class until libtelemetry is fully rewritten.
Although this change is backwards compatible, it impacts @mapbox/navigation-android. Specifically, NavigationState class, which public constructor became deprecated.

@Deprecated
public NavigationState(NavigationMetadata navigationMetadata) {
  this.navigationMetadata = navigationMetadata;
}

the new recommended way of instantiating this class is via this static factory:

public static NavigationState create(NavigationMetadata navigationMetadata, Context context) {
  return new NavigationState(navigationMetadata.setDeviceInfo(context));
}

The motivation behind this change is extracting Context as much as possible from utility class. What it means for navigation sdk: if switch from public constructor to static factory is not happening, we will be loosing all device info fields, such as plugged, networkType and etc.
@Guardiola31337 @danesfeder please let me know if i need to create a ticket in android nav repo to track this change.

Stack trace of this crash:

Crashed: main
       at com.mapbox.android.telemetry.TelemetryUtils.obtainApplicationState(TelemetryUtils.java:100)
       at com.mapbox.android.telemetry.LocationEvent.(LocationEvent.java:44)
       at com.mapbox.android.telemetry.LocationMapper.createLocationEvent(LocationMapper.java:32)
       at com.mapbox.android.telemetry.LocationMapper.from(LocationMapper.java:18)
       at com.mapbox.android.telemetry.LocationReceiver.sendEvent(LocationReceiver.java:47)
       at com.mapbox.android.telemetry.LocationReceiver.onReceive(LocationReceiver.java:26)
       at android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:311)
       at android.support.v4.content.LocalBroadcastManager.access$000(LocalBroadcastManager.java:47)
       at android.support.v4.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:120)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6938)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Copy link
Contributor

@danesfeder danesfeder left a comment

Choose a reason for hiding this comment

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

@andrlee this looks good, thanks! One minor comment I wanted to double check on.


MapDragendEvent setDeviceInfo(Context context) {
this.batteryLevel = TelemetryUtils.obtainBatteryLevel(context);
this.pluggedIn = TelemetryUtils.isPluggedIn(context);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is cellularNetworkType not being set in this event for a reason?

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.

3 participants