@Test public void readData() throws IOException { List<WifiInfo> wifiInfos = null; Mockito.when(filereader.fileExist(wifi_events)).thenReturn(true); Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(getMockedFileData()); traceDataReader.setFileReader(filereader); wifiInfos = traceDataReader.readData("", 1.412361724E12, 1412361675045.0); assertEquals(11, wifiInfos.size(),0); assertEquals("WIFI_CONNECTED", wifiInfos.get(0).getWifiState().toString()); assertEquals("84:db:2f:0b:fe:f0", wifiInfos.get(0).getWifiMacAddress()); assertEquals("Elevate-FEF0", wifiInfos.get(0).getWifiSSID()); assertEquals("84:db:2f:0b:fe:f0", wifiInfos.get(0).getWifiMacAddress()); assertEquals("WIFI_DISCONNECTED", wifiInfos.get(1).getWifiState().toString()); }
@Override public List<WifiInfo> readData(String directory, double startTime, double traceDuration) { this.wifiActiveDuration = 0; List<WifiInfo> wifiInfos = new ArrayList<WifiInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.WIFI_FILE; if (!filereader.fileExist(filepath)) { return wifiInfos; } double dLastTimeStamp = 0.0; double dActiveDuration = 0.0; double beginTime = 0.0; double endTime = 0.0; String prevMacAddress = null; String prevRssi = null; String prevSsid = null; WifiState prevWifiState = null; WifiState lastWifiState = null; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Wifi info file: " + filepath); } if (lines != null && lines.length > 0) { firstLine = lines[0]; try { String strFieldsFirstLine[] = firstLine.split(" "); if (strFieldsFirstLine.length >= 2) { beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]), startTime); if (TraceDataConst.WIFI_OFF.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_DISABLED; } else if (TraceDataConst.WIFI_CONNECTED.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_CONNECTED; Matcher matcher = wifiPattern.matcher(firstLine); if (matcher.lookingAt()) { prevMacAddress = matcher.group(1); prevRssi = matcher.group(2); prevSsid = matcher.group(3); } else { LOGGER.warn("Unable to parse wifi connection params: " + firstLine); } } else if (TraceDataConst.WIFI_DISCONNECTED.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_DISCONNECTED; } else if (TraceDataConst.WIFI_CONNECTING.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_CONNECTING; } else if (TraceDataConst.WIFI_DISCONNECTING.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_DISCONNECTING; } else if (TraceDataConst.WIFI_SUSPENDED.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_SUSPENDED; } else { LOGGER.warn("Unknown wifi state: " + firstLine); prevWifiState = WifiState.WIFI_UNKNOWN; } lastWifiState = prevWifiState; dLastTimeStamp = beginTime; } else { LOGGER.warn("Invalid WiFi trace entry: " + firstLine); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing GPS event: " + firstLine, e); } for (int i = 1; i < lines.length; i++) { strLineBuf = lines[i]; String strFields[] = strLineBuf.split(" "); try { if (strFields.length >= 2) { String macAddress = null; String rssi = null; String ssid = null; WifiState wifiState = null; endTime = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); if (TraceDataConst.WIFI_OFF.equals(strFields[1])) { wifiState = WifiState.WIFI_DISABLED; } else if (TraceDataConst.WIFI_CONNECTED.equals(strFields[1])) { wifiState = WifiState.WIFI_CONNECTED; Matcher matcher = wifiPattern.matcher(strLineBuf); if (matcher.lookingAt()) { macAddress = matcher.group(1); rssi = matcher.group(2); ssid = matcher.group(3); } else { LOGGER.warn("Unable to parse wifi connection params: " + strLineBuf); } } else if (TraceDataConst.WIFI_DISCONNECTED.equals(strFields[1])) { wifiState = WifiState.WIFI_DISCONNECTED; } else if (TraceDataConst.WIFI_CONNECTING.equals(strFields[1])) { wifiState = WifiState.WIFI_CONNECTING; } else if (TraceDataConst.WIFI_DISCONNECTING.equals(strFields[1])) { wifiState = WifiState.WIFI_DISCONNECTING; } else if (TraceDataConst.WIFI_SUSPENDED.equals(strFields[1])) { wifiState = WifiState.WIFI_SUSPENDED; } else { LOGGER.warn("Unknown wifi state: " + strLineBuf); wifiState = WifiState.WIFI_UNKNOWN; } if (!wifiState.equals(lastWifiState)) { wifiInfos.add(new WifiInfo(beginTime, endTime, prevWifiState, prevMacAddress, prevRssi, prevSsid)); if (lastWifiState == WifiState.WIFI_CONNECTED || lastWifiState == WifiState.WIFI_CONNECTING || lastWifiState == WifiState.WIFI_DISCONNECTING) { dActiveDuration += (endTime - dLastTimeStamp); } lastWifiState = wifiState; dLastTimeStamp = endTime; beginTime = endTime; prevWifiState = wifiState; prevMacAddress = macAddress; prevRssi = rssi; prevSsid = ssid; } } else { LOGGER.warn("Invalid WiFi trace entry: " + strLineBuf); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing GPS event: " + strLineBuf, e); } } wifiInfos.add(new WifiInfo(beginTime, traceDuration, prevWifiState, prevMacAddress, prevRssi, prevSsid)); if (lastWifiState == WifiState.WIFI_CONNECTED || lastWifiState == WifiState.WIFI_CONNECTING || lastWifiState == WifiState.WIFI_DISCONNECTING) { dActiveDuration += Math.max(0, traceDuration - dLastTimeStamp); } this.wifiActiveDuration = dActiveDuration; Collections.sort(wifiInfos); } return wifiInfos; }
WifiInfoReaderImpl extends PeripheralBase implements IWifiInfoReader { @Override public List<WifiInfo> readData(String directory, double startTime, double traceDuration) { this.wifiActiveDuration = 0; List<WifiInfo> wifiInfos = new ArrayList<WifiInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.WIFI_FILE; if (!filereader.fileExist(filepath)) { return wifiInfos; } double dLastTimeStamp = 0.0; double dActiveDuration = 0.0; double beginTime = 0.0; double endTime = 0.0; String prevMacAddress = null; String prevRssi = null; String prevSsid = null; WifiState prevWifiState = null; WifiState lastWifiState = null; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Wifi info file: " + filepath); } if (lines != null && lines.length > 0) { firstLine = lines[0]; try { String strFieldsFirstLine[] = firstLine.split(" "); if (strFieldsFirstLine.length >= 2) { beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]), startTime); if (TraceDataConst.WIFI_OFF.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_DISABLED; } else if (TraceDataConst.WIFI_CONNECTED.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_CONNECTED; Matcher matcher = wifiPattern.matcher(firstLine); if (matcher.lookingAt()) { prevMacAddress = matcher.group(1); prevRssi = matcher.group(2); prevSsid = matcher.group(3); } else { LOGGER.warn("Unable to parse wifi connection params: " + firstLine); } } else if (TraceDataConst.WIFI_DISCONNECTED.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_DISCONNECTED; } else if (TraceDataConst.WIFI_CONNECTING.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_CONNECTING; } else if (TraceDataConst.WIFI_DISCONNECTING.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_DISCONNECTING; } else if (TraceDataConst.WIFI_SUSPENDED.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_SUSPENDED; } else { LOGGER.warn("Unknown wifi state: " + firstLine); prevWifiState = WifiState.WIFI_UNKNOWN; } lastWifiState = prevWifiState; dLastTimeStamp = beginTime; } else { LOGGER.warn("Invalid WiFi trace entry: " + firstLine); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing GPS event: " + firstLine, e); } for (int i = 1; i < lines.length; i++) { strLineBuf = lines[i]; String strFields[] = strLineBuf.split(" "); try { if (strFields.length >= 2) { String macAddress = null; String rssi = null; String ssid = null; WifiState wifiState = null; endTime = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); if (TraceDataConst.WIFI_OFF.equals(strFields[1])) { wifiState = WifiState.WIFI_DISABLED; } else if (TraceDataConst.WIFI_CONNECTED.equals(strFields[1])) { wifiState = WifiState.WIFI_CONNECTED; Matcher matcher = wifiPattern.matcher(strLineBuf); if (matcher.lookingAt()) { macAddress = matcher.group(1); rssi = matcher.group(2); ssid = matcher.group(3); } else { LOGGER.warn("Unable to parse wifi connection params: " + strLineBuf); } } else if (TraceDataConst.WIFI_DISCONNECTED.equals(strFields[1])) { wifiState = WifiState.WIFI_DISCONNECTED; } else if (TraceDataConst.WIFI_CONNECTING.equals(strFields[1])) { wifiState = WifiState.WIFI_CONNECTING; } else if (TraceDataConst.WIFI_DISCONNECTING.equals(strFields[1])) { wifiState = WifiState.WIFI_DISCONNECTING; } else if (TraceDataConst.WIFI_SUSPENDED.equals(strFields[1])) { wifiState = WifiState.WIFI_SUSPENDED; } else { LOGGER.warn("Unknown wifi state: " + strLineBuf); wifiState = WifiState.WIFI_UNKNOWN; } if (!wifiState.equals(lastWifiState)) { wifiInfos.add(new WifiInfo(beginTime, endTime, prevWifiState, prevMacAddress, prevRssi, prevSsid)); if (lastWifiState == WifiState.WIFI_CONNECTED || lastWifiState == WifiState.WIFI_CONNECTING || lastWifiState == WifiState.WIFI_DISCONNECTING) { dActiveDuration += (endTime - dLastTimeStamp); } lastWifiState = wifiState; dLastTimeStamp = endTime; beginTime = endTime; prevWifiState = wifiState; prevMacAddress = macAddress; prevRssi = rssi; prevSsid = ssid; } } else { LOGGER.warn("Invalid WiFi trace entry: " + strLineBuf); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing GPS event: " + strLineBuf, e); } } wifiInfos.add(new WifiInfo(beginTime, traceDuration, prevWifiState, prevMacAddress, prevRssi, prevSsid)); if (lastWifiState == WifiState.WIFI_CONNECTED || lastWifiState == WifiState.WIFI_CONNECTING || lastWifiState == WifiState.WIFI_DISCONNECTING) { dActiveDuration += Math.max(0, traceDuration - dLastTimeStamp); } this.wifiActiveDuration = dActiveDuration; Collections.sort(wifiInfos); } return wifiInfos; } }
WifiInfoReaderImpl extends PeripheralBase implements IWifiInfoReader { @Override public List<WifiInfo> readData(String directory, double startTime, double traceDuration) { this.wifiActiveDuration = 0; List<WifiInfo> wifiInfos = new ArrayList<WifiInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.WIFI_FILE; if (!filereader.fileExist(filepath)) { return wifiInfos; } double dLastTimeStamp = 0.0; double dActiveDuration = 0.0; double beginTime = 0.0; double endTime = 0.0; String prevMacAddress = null; String prevRssi = null; String prevSsid = null; WifiState prevWifiState = null; WifiState lastWifiState = null; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Wifi info file: " + filepath); } if (lines != null && lines.length > 0) { firstLine = lines[0]; try { String strFieldsFirstLine[] = firstLine.split(" "); if (strFieldsFirstLine.length >= 2) { beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]), startTime); if (TraceDataConst.WIFI_OFF.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_DISABLED; } else if (TraceDataConst.WIFI_CONNECTED.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_CONNECTED; Matcher matcher = wifiPattern.matcher(firstLine); if (matcher.lookingAt()) { prevMacAddress = matcher.group(1); prevRssi = matcher.group(2); prevSsid = matcher.group(3); } else { LOGGER.warn("Unable to parse wifi connection params: " + firstLine); } } else if (TraceDataConst.WIFI_DISCONNECTED.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_DISCONNECTED; } else if (TraceDataConst.WIFI_CONNECTING.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_CONNECTING; } else if (TraceDataConst.WIFI_DISCONNECTING.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_DISCONNECTING; } else if (TraceDataConst.WIFI_SUSPENDED.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_SUSPENDED; } else { LOGGER.warn("Unknown wifi state: " + firstLine); prevWifiState = WifiState.WIFI_UNKNOWN; } lastWifiState = prevWifiState; dLastTimeStamp = beginTime; } else { LOGGER.warn("Invalid WiFi trace entry: " + firstLine); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing GPS event: " + firstLine, e); } for (int i = 1; i < lines.length; i++) { strLineBuf = lines[i]; String strFields[] = strLineBuf.split(" "); try { if (strFields.length >= 2) { String macAddress = null; String rssi = null; String ssid = null; WifiState wifiState = null; endTime = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); if (TraceDataConst.WIFI_OFF.equals(strFields[1])) { wifiState = WifiState.WIFI_DISABLED; } else if (TraceDataConst.WIFI_CONNECTED.equals(strFields[1])) { wifiState = WifiState.WIFI_CONNECTED; Matcher matcher = wifiPattern.matcher(strLineBuf); if (matcher.lookingAt()) { macAddress = matcher.group(1); rssi = matcher.group(2); ssid = matcher.group(3); } else { LOGGER.warn("Unable to parse wifi connection params: " + strLineBuf); } } else if (TraceDataConst.WIFI_DISCONNECTED.equals(strFields[1])) { wifiState = WifiState.WIFI_DISCONNECTED; } else if (TraceDataConst.WIFI_CONNECTING.equals(strFields[1])) { wifiState = WifiState.WIFI_CONNECTING; } else if (TraceDataConst.WIFI_DISCONNECTING.equals(strFields[1])) { wifiState = WifiState.WIFI_DISCONNECTING; } else if (TraceDataConst.WIFI_SUSPENDED.equals(strFields[1])) { wifiState = WifiState.WIFI_SUSPENDED; } else { LOGGER.warn("Unknown wifi state: " + strLineBuf); wifiState = WifiState.WIFI_UNKNOWN; } if (!wifiState.equals(lastWifiState)) { wifiInfos.add(new WifiInfo(beginTime, endTime, prevWifiState, prevMacAddress, prevRssi, prevSsid)); if (lastWifiState == WifiState.WIFI_CONNECTED || lastWifiState == WifiState.WIFI_CONNECTING || lastWifiState == WifiState.WIFI_DISCONNECTING) { dActiveDuration += (endTime - dLastTimeStamp); } lastWifiState = wifiState; dLastTimeStamp = endTime; beginTime = endTime; prevWifiState = wifiState; prevMacAddress = macAddress; prevRssi = rssi; prevSsid = ssid; } } else { LOGGER.warn("Invalid WiFi trace entry: " + strLineBuf); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing GPS event: " + strLineBuf, e); } } wifiInfos.add(new WifiInfo(beginTime, traceDuration, prevWifiState, prevMacAddress, prevRssi, prevSsid)); if (lastWifiState == WifiState.WIFI_CONNECTED || lastWifiState == WifiState.WIFI_CONNECTING || lastWifiState == WifiState.WIFI_DISCONNECTING) { dActiveDuration += Math.max(0, traceDuration - dLastTimeStamp); } this.wifiActiveDuration = dActiveDuration; Collections.sort(wifiInfos); } return wifiInfos; }  }
WifiInfoReaderImpl extends PeripheralBase implements IWifiInfoReader { @Override public List<WifiInfo> readData(String directory, double startTime, double traceDuration) { this.wifiActiveDuration = 0; List<WifiInfo> wifiInfos = new ArrayList<WifiInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.WIFI_FILE; if (!filereader.fileExist(filepath)) { return wifiInfos; } double dLastTimeStamp = 0.0; double dActiveDuration = 0.0; double beginTime = 0.0; double endTime = 0.0; String prevMacAddress = null; String prevRssi = null; String prevSsid = null; WifiState prevWifiState = null; WifiState lastWifiState = null; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Wifi info file: " + filepath); } if (lines != null && lines.length > 0) { firstLine = lines[0]; try { String strFieldsFirstLine[] = firstLine.split(" "); if (strFieldsFirstLine.length >= 2) { beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]), startTime); if (TraceDataConst.WIFI_OFF.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_DISABLED; } else if (TraceDataConst.WIFI_CONNECTED.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_CONNECTED; Matcher matcher = wifiPattern.matcher(firstLine); if (matcher.lookingAt()) { prevMacAddress = matcher.group(1); prevRssi = matcher.group(2); prevSsid = matcher.group(3); } else { LOGGER.warn("Unable to parse wifi connection params: " + firstLine); } } else if (TraceDataConst.WIFI_DISCONNECTED.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_DISCONNECTED; } else if (TraceDataConst.WIFI_CONNECTING.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_CONNECTING; } else if (TraceDataConst.WIFI_DISCONNECTING.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_DISCONNECTING; } else if (TraceDataConst.WIFI_SUSPENDED.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_SUSPENDED; } else { LOGGER.warn("Unknown wifi state: " + firstLine); prevWifiState = WifiState.WIFI_UNKNOWN; } lastWifiState = prevWifiState; dLastTimeStamp = beginTime; } else { LOGGER.warn("Invalid WiFi trace entry: " + firstLine); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing GPS event: " + firstLine, e); } for (int i = 1; i < lines.length; i++) { strLineBuf = lines[i]; String strFields[] = strLineBuf.split(" "); try { if (strFields.length >= 2) { String macAddress = null; String rssi = null; String ssid = null; WifiState wifiState = null; endTime = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); if (TraceDataConst.WIFI_OFF.equals(strFields[1])) { wifiState = WifiState.WIFI_DISABLED; } else if (TraceDataConst.WIFI_CONNECTED.equals(strFields[1])) { wifiState = WifiState.WIFI_CONNECTED; Matcher matcher = wifiPattern.matcher(strLineBuf); if (matcher.lookingAt()) { macAddress = matcher.group(1); rssi = matcher.group(2); ssid = matcher.group(3); } else { LOGGER.warn("Unable to parse wifi connection params: " + strLineBuf); } } else if (TraceDataConst.WIFI_DISCONNECTED.equals(strFields[1])) { wifiState = WifiState.WIFI_DISCONNECTED; } else if (TraceDataConst.WIFI_CONNECTING.equals(strFields[1])) { wifiState = WifiState.WIFI_CONNECTING; } else if (TraceDataConst.WIFI_DISCONNECTING.equals(strFields[1])) { wifiState = WifiState.WIFI_DISCONNECTING; } else if (TraceDataConst.WIFI_SUSPENDED.equals(strFields[1])) { wifiState = WifiState.WIFI_SUSPENDED; } else { LOGGER.warn("Unknown wifi state: " + strLineBuf); wifiState = WifiState.WIFI_UNKNOWN; } if (!wifiState.equals(lastWifiState)) { wifiInfos.add(new WifiInfo(beginTime, endTime, prevWifiState, prevMacAddress, prevRssi, prevSsid)); if (lastWifiState == WifiState.WIFI_CONNECTED || lastWifiState == WifiState.WIFI_CONNECTING || lastWifiState == WifiState.WIFI_DISCONNECTING) { dActiveDuration += (endTime - dLastTimeStamp); } lastWifiState = wifiState; dLastTimeStamp = endTime; beginTime = endTime; prevWifiState = wifiState; prevMacAddress = macAddress; prevRssi = rssi; prevSsid = ssid; } } else { LOGGER.warn("Invalid WiFi trace entry: " + strLineBuf); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing GPS event: " + strLineBuf, e); } } wifiInfos.add(new WifiInfo(beginTime, traceDuration, prevWifiState, prevMacAddress, prevRssi, prevSsid)); if (lastWifiState == WifiState.WIFI_CONNECTED || lastWifiState == WifiState.WIFI_CONNECTING || lastWifiState == WifiState.WIFI_DISCONNECTING) { dActiveDuration += Math.max(0, traceDuration - dLastTimeStamp); } this.wifiActiveDuration = dActiveDuration; Collections.sort(wifiInfos); } return wifiInfos; }  @Override List<WifiInfo> readData(String directory, double startTime, double traceDuration); @Override double getWifiActiveDuration(); }
WifiInfoReaderImpl extends PeripheralBase implements IWifiInfoReader { @Override public List<WifiInfo> readData(String directory, double startTime, double traceDuration) { this.wifiActiveDuration = 0; List<WifiInfo> wifiInfos = new ArrayList<WifiInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.WIFI_FILE; if (!filereader.fileExist(filepath)) { return wifiInfos; } double dLastTimeStamp = 0.0; double dActiveDuration = 0.0; double beginTime = 0.0; double endTime = 0.0; String prevMacAddress = null; String prevRssi = null; String prevSsid = null; WifiState prevWifiState = null; WifiState lastWifiState = null; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Wifi info file: " + filepath); } if (lines != null && lines.length > 0) { firstLine = lines[0]; try { String strFieldsFirstLine[] = firstLine.split(" "); if (strFieldsFirstLine.length >= 2) { beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]), startTime); if (TraceDataConst.WIFI_OFF.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_DISABLED; } else if (TraceDataConst.WIFI_CONNECTED.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_CONNECTED; Matcher matcher = wifiPattern.matcher(firstLine); if (matcher.lookingAt()) { prevMacAddress = matcher.group(1); prevRssi = matcher.group(2); prevSsid = matcher.group(3); } else { LOGGER.warn("Unable to parse wifi connection params: " + firstLine); } } else if (TraceDataConst.WIFI_DISCONNECTED.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_DISCONNECTED; } else if (TraceDataConst.WIFI_CONNECTING.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_CONNECTING; } else if (TraceDataConst.WIFI_DISCONNECTING.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_DISCONNECTING; } else if (TraceDataConst.WIFI_SUSPENDED.equals(strFieldsFirstLine[1])) { prevWifiState = WifiState.WIFI_SUSPENDED; } else { LOGGER.warn("Unknown wifi state: " + firstLine); prevWifiState = WifiState.WIFI_UNKNOWN; } lastWifiState = prevWifiState; dLastTimeStamp = beginTime; } else { LOGGER.warn("Invalid WiFi trace entry: " + firstLine); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing GPS event: " + firstLine, e); } for (int i = 1; i < lines.length; i++) { strLineBuf = lines[i]; String strFields[] = strLineBuf.split(" "); try { if (strFields.length >= 2) { String macAddress = null; String rssi = null; String ssid = null; WifiState wifiState = null; endTime = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); if (TraceDataConst.WIFI_OFF.equals(strFields[1])) { wifiState = WifiState.WIFI_DISABLED; } else if (TraceDataConst.WIFI_CONNECTED.equals(strFields[1])) { wifiState = WifiState.WIFI_CONNECTED; Matcher matcher = wifiPattern.matcher(strLineBuf); if (matcher.lookingAt()) { macAddress = matcher.group(1); rssi = matcher.group(2); ssid = matcher.group(3); } else { LOGGER.warn("Unable to parse wifi connection params: " + strLineBuf); } } else if (TraceDataConst.WIFI_DISCONNECTED.equals(strFields[1])) { wifiState = WifiState.WIFI_DISCONNECTED; } else if (TraceDataConst.WIFI_CONNECTING.equals(strFields[1])) { wifiState = WifiState.WIFI_CONNECTING; } else if (TraceDataConst.WIFI_DISCONNECTING.equals(strFields[1])) { wifiState = WifiState.WIFI_DISCONNECTING; } else if (TraceDataConst.WIFI_SUSPENDED.equals(strFields[1])) { wifiState = WifiState.WIFI_SUSPENDED; } else { LOGGER.warn("Unknown wifi state: " + strLineBuf); wifiState = WifiState.WIFI_UNKNOWN; } if (!wifiState.equals(lastWifiState)) { wifiInfos.add(new WifiInfo(beginTime, endTime, prevWifiState, prevMacAddress, prevRssi, prevSsid)); if (lastWifiState == WifiState.WIFI_CONNECTED || lastWifiState == WifiState.WIFI_CONNECTING || lastWifiState == WifiState.WIFI_DISCONNECTING) { dActiveDuration += (endTime - dLastTimeStamp); } lastWifiState = wifiState; dLastTimeStamp = endTime; beginTime = endTime; prevWifiState = wifiState; prevMacAddress = macAddress; prevRssi = rssi; prevSsid = ssid; } } else { LOGGER.warn("Invalid WiFi trace entry: " + strLineBuf); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing GPS event: " + strLineBuf, e); } } wifiInfos.add(new WifiInfo(beginTime, traceDuration, prevWifiState, prevMacAddress, prevRssi, prevSsid)); if (lastWifiState == WifiState.WIFI_CONNECTED || lastWifiState == WifiState.WIFI_CONNECTING || lastWifiState == WifiState.WIFI_DISCONNECTING) { dActiveDuration += Math.max(0, traceDuration - dLastTimeStamp); } this.wifiActiveDuration = dActiveDuration; Collections.sort(wifiInfos); } return wifiInfos; }  @Override List<WifiInfo> readData(String directory, double startTime, double traceDuration); @Override double getWifiActiveDuration();  }