Skip to content
This repository has been archived by the owner on May 2, 2021. It is now read-only.

Commit

Permalink
log format: fields changed, special entry added
Browse files Browse the repository at this point in the history
major changes in log format (see source)
added special type of log entry for no visible wifi, closes #2
  • Loading branch information
tjanson committed Mar 15, 2015
1 parent 5993153 commit cd9c1f7
Showing 1 changed file with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.content.Intent;
import android.net.wifi.ScanResult;
import android.os.Build;

import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -32,6 +33,9 @@ public int compare(ScanResult e1, ScanResult e2) {
private static final String WIFI_SCAN_TIMER = "wifi-scan-timer";
private static Timer wifiScanTimer;

private static final int NOT_SPECIAL = 0;
private static final int SPECIAL_NO_VISIBLE_WIFI = 1;

public WifiBroadcastReceiver(MainActivity m) {
this.m = m;
wifiScanTimer = new Timer(WIFI_SCAN_TIMER);
Expand All @@ -48,13 +52,21 @@ public void onReceive(Context context, Intent intent) {
String combined = "";
Pattern filter = makeFilter();

Boolean atLeastOneLogged = false;
for (ScanResult wifi : scanResultList) {
if (!filter.matcher(wifi.SSID).matches()) {
continue;
}
atLeastOneLogged = true;

combined += convertFrequencyToChannel(wifi.frequency) + " " + wifi.SSID + " [" + wifi.BSSID + "]" + ": " + wifi.level + "\n";
log(wifi);
log(wifi, NOT_SPECIAL);
}

// if no log entry was triggered (i.e., no wifis that matched the filter),
// write special entry signifying that no wifi was in range
if (!atLeastOneLogged) {
log(null, SPECIAL_NO_VISIBLE_WIFI);
}

m.wifiListString = combined;
Expand All @@ -69,19 +81,34 @@ public void run() {
}, MainActivity.WIFI_SCAN_DELAY_MILLIS);
}

private void log(ScanResult wifi) {
private void log(ScanResult wifi, int specialCode) {
if (m.loggingEnabled) {
String csvLine = m.currentLocation.getLatitude()
+ "," + m.currentLocation.getLongitude()
+ "," + m.currentLocation.getAltitude()
+ "," + m.currentLocation.getAccuracy()
+ "," + m.lastLocationUpdateTime.getTime()
+ "," + wifi.SSID // TODO: escape commas
+ "," + wifi.BSSID
+ "," + wifi.level
+ "," + m.lastWifiScanTime.getTime()
+ "," + convertFrequencyToChannel(wifi.frequency)
+ "," + MainActivity.sessionId;
String csvLine = MainActivity.LOG_FORMAT_VERSION
+ "," + Build.MODEL
+ "," + MainActivity.sessionId
+ "," + m.currentLocation.getLatitude()
+ "," + m.currentLocation.getLongitude()
+ "," + m.currentLocation.getAltitude()
+ "," + m.currentLocation.getAccuracy()
+ "," + m.currentLocation.getSpeed()
+ "," + specialCode
+ "," + (m.lastLocationUpdateTime.getTime() - m.lastWifiScanTime.getTime());

if (specialCode == NOT_SPECIAL) {
csvLine += "," + wifi.SSID // FIXME: escape commas
+ "," + wifi.BSSID
+ "," + wifi.level
+ "," + convertFrequencyToChannel(wifi.frequency);
} else if (specialCode == SPECIAL_NO_VISIBLE_WIFI) {
csvLine += ",,,,";
} else {
throw new IllegalArgumentException(Integer.toString(specialCode));
}

// FIXME last in case it might contain messed up characters
// this really needs to be escaped properly, same for SSID above
// (which can apparently contain arbitrary characters - dear god...)
csvLine += "," + "'" + m.wifiFilterET.getText().toString() + "'";

m.diskLog.info(csvLine);
}
Expand Down

0 comments on commit cd9c1f7

Please sign in to comment.