Skip to content

Commit

Permalink
updates to fix error handling in several different situations (#719)
Browse files Browse the repository at this point in the history
Co-authored-by: Andy Carra <rksh@wigle.net>
  • Loading branch information
rksh and Andy Carra authored Dec 1, 2024
1 parent eede48c commit 9fe8a0a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class BackgroundGuiHandler extends Handler {
public static final String FILEPATH = "filepath";
public static final String TRANSIDS = "transIds";

public static BackgroundAlertDialog alertDialog;
private FragmentActivity context;
private final Object lock;
private final ProgressPanel pp;
Expand Down Expand Up @@ -246,7 +247,11 @@ public void handleMessage( final Message msg ) {
}

private void showError(final FragmentManager fm, final Message msg, final Status status) {
final BackgroundAlertDialog alertDialog = BackgroundAlertDialog.newInstance(msg, status);
if (null != alertDialog && alertDialog.isVisible()) {
//ALIBI: one alert dialog at a time
alertDialog.dismiss();
}
alertDialog = BackgroundAlertDialog.newInstance(msg, status);
try {
final Activity a = MainActivity.getMainActivity();
if (null != a && !a.isFinishing()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ public void onTaskFailed(int httpStatus, JSONObject error) {
intent.putExtra("error", e);
status = Status.EXCEPTION;
} else {
bundle.putString( BackgroundGuiHandler.ERROR, "Unable to connect. (data: "+WiGLEApiManager.hasDataConnection(context)+")");
final String translated = context != null? context.getString(R.string.no_wigle_conn): "Unable to connect.";
bundle.putString( BackgroundGuiHandler.ERROR, translated+" (data: "+WiGLEApiManager.hasDataConnection(context)+")");
}
} catch (JSONException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,11 @@ else if ( newOK && NETWORK_PROVIDER.equals( newLocation.getProvider() ) ) {
// initialize previous location
prevLocation = currentLocation;
} else if (prevLocation != null){
Logging.warn("Location timestamp ("+ currentLocation.getTime()+") <= previous location timestamp ("+ prevLocation.getTime()+")");
//ALIBI: we're ignoring this rather than trying to slot it in only because we'd need an in-memory or DB route otherwise.
if (currentLocation.getTime() != prevLocation.getTime()) {
Logging.warn("Location timestamp (" + currentLocation.getTime() + ") < previous location timestamp (" + prevLocation.getTime() + ")");
//ALIBI: we're ignoring this rather than trying to slot it in only because we'd need an in-memory or DB route otherwise.
}
//ALIBI: no log message required for equal.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
Expand All @@ -15,7 +16,6 @@
import androidx.annotation.NonNull;

import com.appmattus.certificatetransparency.CTInterceptorBuilder;
import com.google.android.gms.common.api.Api;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;

Expand Down Expand Up @@ -700,8 +700,15 @@ public static boolean hasDataConnection(final Context context) {
Logging.error("null ConnectivityManager trying to determine connection info");
return false;
}
NetworkInfo activeNetworkInfo = connectivityManager != null ? connectivityManager.getActiveNetworkInfo() : null;
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
final Network n = connectivityManager.getActiveNetwork();
if (null != n) {
final NetworkCapabilities cap = connectivityManager.getNetworkCapabilities(n);
if (cap.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) &&
cap.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)) {
return true;
}
}
return false;
}

/**
Expand Down

0 comments on commit 9fe8a0a

Please sign in to comment.