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

bugfix: netInfo can be null even when there is connectivity. #445

Merged
merged 2 commits into from
Apr 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/main/java/com/mixpanel/android/util/HttpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ public boolean isOnline(Context context, OfflineMode offlineMode) {
final ConnectivityManager cm =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo netInfo = cm.getActiveNetworkInfo();
isOnline = netInfo != null && netInfo.isConnectedOrConnecting();
MPLog.v(LOGTAG, "ConnectivityManager says we " + (isOnline ? "are" : "are not") + " online");
if (netInfo == null) {
isOnline = true;
MPLog.v(LOGTAG, "A default network has not been set so we cannot be certain whether we are offline");
} else {
isOnline = netInfo.isConnectedOrConnecting();
MPLog.v(LOGTAG, "ConnectivityManager says we " + (isOnline ? "are" : "are not") + " online");
}
} catch (final SecurityException e) {
isOnline = true;
MPLog.v(LOGTAG, "Don't have permission to check connectivity, will assume we are online");
Expand Down