use of net.wigle.wigleandroid.WiGLEAuthException in project wigle-wifi-wardriving by wiglenet.
the class ApiDownloader method subRun.
@Override
protected void subRun() throws IOException, InterruptedException, WiGLEAuthException {
String result = null;
try {
result = doDownload(this.connectionMethod);
if (cacheFilename != null) {
cacheResult(result);
}
final JSONObject json = new JSONObject(result);
listener.requestComplete(json, false);
} catch (final WiGLEAuthException waex) {
// ALIBI: allow auth exception through
throw waex;
} catch (final JSONException ex) {
MainActivity.error("ex: " + ex + " result: " + result, ex);
}
}
use of net.wigle.wigleandroid.WiGLEAuthException in project wigle-wifi-wardriving by wiglenet.
the class KmlDownloader method subRun.
@Override
protected void subRun() throws IOException, InterruptedException, WiGLEAuthException {
status = Status.UNKNOWN;
final Bundle bundle = new Bundle();
sendBundledMessage(Status.DOWNLOADING.ordinal(), bundle);
String result = null;
try {
result = doDownload(this.connectionMethod);
writeSharefile(result, cacheFilename);
final JSONObject json = new JSONObject("{success: " + true + ", file:\"" + (MainActivity.hasSD() ? MainActivity.getSDPath() : context.getDir("kml", Context.MODE_PRIVATE).getAbsolutePath() + "/") + cacheFilename + "\"}");
sendBundledMessage(Status.SUCCESS.ordinal(), bundle);
listener.requestComplete(json, false);
} catch (final WiGLEAuthException waex) {
// ALIBI: allow auth exception through
sendBundledMessage(Status.FAIL.ordinal(), bundle);
throw waex;
} catch (final JSONException ex) {
sendBundledMessage(Status.FAIL.ordinal(), bundle);
MainActivity.error("ex: " + ex + " result: " + result, ex);
}
}
use of net.wigle.wigleandroid.WiGLEAuthException in project wigle-wifi-wardriving by wiglenet.
the class AbstractProgressApiRequest method downloadTokenAndStart.
@Override
protected /**
* need to DRY this up vs. the exception-based version in ApiDownloader
*/
void downloadTokenAndStart(final Fragment fragment) {
final ApiDownloader task = new ApiDownloader(fragment.getActivity(), ListFragment.lameStatic.dbHelper, null, MainActivity.TOKEN_URL, true, false, true, AbstractApiRequest.REQUEST_POST, new ApiListener() {
@Override
public void requestComplete(final JSONObject json, final boolean isCache) throws WiGLEAuthException {
try {
// {"success": true, "authname": "AID...", "token": "..."}
if (json.getBoolean("success")) {
final String authname = json.getString("authname");
final String token = json.getString("token");
final SharedPreferences prefs = fragment.getContext().getSharedPreferences(ListFragment.SHARED_PREFS, 0);
final SharedPreferences.Editor edit = prefs.edit();
edit.putString(ListFragment.PREF_AUTHNAME, authname);
edit.apply();
TokenAccess.setApiToken(prefs, token);
// execute ourselves, the pending task
start();
} else if (json.has("credential_0")) {
String message = "login failed for " + json.getString("credential_0");
MainActivity.warn(message);
final Bundle bundle = new Bundle();
sendBundledMessage(Status.BAD_LOGIN.ordinal(), bundle);
} else {
final Bundle bundle = new Bundle();
sendBundledMessage(Status.BAD_LOGIN.ordinal(), bundle);
}
} catch (final JSONException ex) {
final Bundle bundle = new Bundle();
sendBundledMessage(Status.BAD_LOGIN.ordinal(), bundle);
} catch (final Exception e) {
MainActivity.error("Failed to log in " + e + " payload: " + json, e);
final Bundle bundle = new Bundle();
sendBundledMessage(Status.BAD_LOGIN.ordinal(), bundle);
}
}
});
task.start();
}
use of net.wigle.wigleandroid.WiGLEAuthException in project wigle-wifi-wardriving by wiglenet.
the class AbstractBackgroundTask method run.
@Override
public final void run() {
// set thread name
setName(name + "-" + getName());
try {
MainActivity.info("setting background thread priority (-20 highest, 19 lowest) to: " + THREAD_PRIORITY);
Process.setThreadPriority(THREAD_PRIORITY);
subRun();
} catch (InterruptedException ex) {
MainActivity.info(name + " interrupted: " + ex);
} catch (final WiGLEAuthException waex) {
// DEBUG: MainActivity.error("auth error", waex);
Bundle errorBundle = new Bundle();
errorBundle.putCharSequence("AUTH_ERROR", waex.getMessage());
sendBundledMessage(BackgroundGuiHandler.AUTHENTICATION_ERROR, errorBundle);
} catch (final IOException ioex) {
MainActivity.error("connection error", ioex);
Bundle errorBundle = new Bundle();
errorBundle.putString(BackgroundGuiHandler.ERROR, "IOException");
errorBundle.putCharSequence("CONN_ERROR", ioex.getMessage());
sendBundledMessage(BackgroundGuiHandler.CONNECTION_ERROR, errorBundle);
} catch (final Exception ex) {
dbHelper.deathDialog(name, ex);
}
}
use of net.wigle.wigleandroid.WiGLEAuthException in project wigle-wifi-wardriving by wiglenet.
the class ObservationImporter method getResultString.
@Override
protected String getResultString(final BufferedReader reader) throws IOException, InterruptedException {
Bundle bundle = new Bundle();
try {
JsonFactory f = new MappingJsonFactory();
JsonParser jp = f.createParser(reader);
JsonToken current;
current = jp.nextToken();
if (current != JsonToken.START_OBJECT) {
System.out.println("Error: root should be object: quiting.");
return null;
}
Integer total = 0;
while (jp.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jp.getCurrentName();
current = jp.nextToken();
if (fieldName.equals("success")) {
if (current.isBoolean()) {
if (current == JsonToken.VALUE_TRUE) {
MainActivity.info("successful load");
} else {
MainActivity.error("MyObserved success: false");
status = Status.EXCEPTION;
bundle.putString(BackgroundGuiHandler.ERROR, "ERROR: success: false");
}
}
} else if (fieldName.equals("count")) {
total = jp.getIntValue();
MainActivity.info("received " + total + " observations");
if (total > 0) {
status = Status.SUCCESS;
}
} else if (fieldName.equals("results")) {
if (current == JsonToken.START_ARRAY) {
// For each of the records in the array
int i = 0;
while (jp.nextToken() != JsonToken.END_ARRAY) {
String netId = jp.getValueAsString();
// DEBUG: MainActivity.info(netId);
final String ssid = "";
final int frequency = 0;
final String capabilities = "";
final int level = 0;
final Network network = new Network(netId, ssid, frequency, capabilities, level, NetworkType.WIFI);
final Location location = new Location("wigle");
final boolean newForRun = true;
ListFragment.lameStatic.dbHelper.blockingAddObservation(network, location, newForRun);
if ((i % 1000) == 0) {
MainActivity.info("lineCount: " + i + " of " + total);
}
if (total == 0) {
total = 1;
}
final int percentDone = (i * 1000) / total;
sendPercentTimesTen(percentDone, bundle);
i++;
}
} else {
System.out.println("Error: records should be an array: skipping.");
jp.skipChildren();
}
} else {
System.out.println("Unprocessed property: " + fieldName);
jp.skipChildren();
}
}
} catch (InterruptedException e) {
e.printStackTrace();
status = Status.EXCEPTION;
bundle.putString(BackgroundGuiHandler.ERROR, "Connection problem: " + e);
throw e;
} catch (Exception e) {
e.printStackTrace();
status = Status.EXCEPTION;
bundle.putString(BackgroundGuiHandler.ERROR, "ERROR: " + e + " (from " + e.getCause() + ")");
return status.toString();
} finally {
if (status == null) {
status = Status.FAIL;
}
try {
listener.requestComplete(null, false);
} catch (WiGLEAuthException waex) {
MainActivity.error("Unable to download data - authorization failed");
status = Status.BAD_LOGIN;
}
}
return status.toString();
}
Aggregations