@Test public void readData() throws IOException { Date traceDateTime = new Date((long)1412161675045.0); double dumpsysEpochTimestamp = (new Date((long)1.412361724E12)).getTime(); List<WakelockInfo> wakelockInfos = null; String filepath = "" + Util.FILE_SEPARATOR + TraceDataConst.FileName.BATTERYINFO_FILE; Mockito.when(filereader.fileExist(filepath)).thenReturn(true); Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(getMockedFileData()); traceDataReader.setFileReader(filereader); wakelockInfos = traceDataReader.readData("", "2.2", dumpsysEpochTimestamp, traceDateTime); wakelockInfos = traceDataReader.readData("", "4.2", dumpsysEpochTimestamp, traceDateTime); assertEquals(7, wakelockInfos.size(),0); }
@Override public List<WakelockInfo> readData(String directory, String osVersion, double dumpsysEpochTimestamp, Date traceDateTime){ List<WakelockInfo> wakelockInfos = new ArrayList<WakelockInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BATTERYINFO_FILE; String[] lines = null; if (!filereader.fileExist(filepath)) { return wakelockInfos; } if (osVersion != null && osVersion.compareTo("2.3") < 0) { LOGGER.info("OS 2.2(Froyo) or earlier does not has the wakelock timeline"); } try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Wakelock Info file: "+filepath); } if(lines != null && lines.length > 0){ WakelockState wakelockState; for (String strLineBuf : lines) { int index = strLineBuf.indexOf(TraceDataConst.WAKELOCK_ACQUIRED); if (index < 0) { index = strLineBuf.indexOf(TraceDataConst.WAKELOCK_RELEASED); } if (index > 0) { String actualWakelockstate = strLineBuf.substring(index, index+10); String strFields[] = strLineBuf.trim().split(" "); try { double bTimeStamp = dumpsysEpochTimestamp - Util.convertTime(strFields[0]); if (bTimeStamp > traceDateTime.getTime()) { bTimeStamp = (bTimeStamp - traceDateTime.getTime())/1000; if (TraceDataConst.WAKELOCK_RELEASED.equals(actualWakelockstate)) { wakelockState = WakelockState.WAKELOCK_RELEASED; } else { wakelockState = WakelockState.WAKELOCK_ACQUIRED; } wakelockInfos.add(new WakelockInfo(bTimeStamp, wakelockState)); LOGGER.info("Trace Start: " + traceDateTime.getTime() + "\nWakelock Time: " + bTimeStamp + " Wakelock state: " + actualWakelockstate + " strFields " + Arrays.toString(strFields)); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing wakelock event: " + Arrays.toString(strFields) + " found wakelock in " + index, e); } } } } return wakelockInfos; }
WakelockInfoReaderImpl extends PeripheralBase implements IWakelockInfoReader { @Override public List<WakelockInfo> readData(String directory, String osVersion, double dumpsysEpochTimestamp, Date traceDateTime){ List<WakelockInfo> wakelockInfos = new ArrayList<WakelockInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BATTERYINFO_FILE; String[] lines = null; if (!filereader.fileExist(filepath)) { return wakelockInfos; } if (osVersion != null && osVersion.compareTo("2.3") < 0) { LOGGER.info("OS 2.2(Froyo) or earlier does not has the wakelock timeline"); } try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Wakelock Info file: "+filepath); } if(lines != null && lines.length > 0){ WakelockState wakelockState; for (String strLineBuf : lines) { int index = strLineBuf.indexOf(TraceDataConst.WAKELOCK_ACQUIRED); if (index < 0) { index = strLineBuf.indexOf(TraceDataConst.WAKELOCK_RELEASED); } if (index > 0) { String actualWakelockstate = strLineBuf.substring(index, index+10); String strFields[] = strLineBuf.trim().split(" "); try { double bTimeStamp = dumpsysEpochTimestamp - Util.convertTime(strFields[0]); if (bTimeStamp > traceDateTime.getTime()) { bTimeStamp = (bTimeStamp - traceDateTime.getTime())/1000; if (TraceDataConst.WAKELOCK_RELEASED.equals(actualWakelockstate)) { wakelockState = WakelockState.WAKELOCK_RELEASED; } else { wakelockState = WakelockState.WAKELOCK_ACQUIRED; } wakelockInfos.add(new WakelockInfo(bTimeStamp, wakelockState)); LOGGER.info("Trace Start: " + traceDateTime.getTime() + "\nWakelock Time: " + bTimeStamp + " Wakelock state: " + actualWakelockstate + " strFields " + Arrays.toString(strFields)); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing wakelock event: " + Arrays.toString(strFields) + " found wakelock in " + index, e); } } } } return wakelockInfos; } }
WakelockInfoReaderImpl extends PeripheralBase implements IWakelockInfoReader { @Override public List<WakelockInfo> readData(String directory, String osVersion, double dumpsysEpochTimestamp, Date traceDateTime){ List<WakelockInfo> wakelockInfos = new ArrayList<WakelockInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BATTERYINFO_FILE; String[] lines = null; if (!filereader.fileExist(filepath)) { return wakelockInfos; } if (osVersion != null && osVersion.compareTo("2.3") < 0) { LOGGER.info("OS 2.2(Froyo) or earlier does not has the wakelock timeline"); } try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Wakelock Info file: "+filepath); } if(lines != null && lines.length > 0){ WakelockState wakelockState; for (String strLineBuf : lines) { int index = strLineBuf.indexOf(TraceDataConst.WAKELOCK_ACQUIRED); if (index < 0) { index = strLineBuf.indexOf(TraceDataConst.WAKELOCK_RELEASED); } if (index > 0) { String actualWakelockstate = strLineBuf.substring(index, index+10); String strFields[] = strLineBuf.trim().split(" "); try { double bTimeStamp = dumpsysEpochTimestamp - Util.convertTime(strFields[0]); if (bTimeStamp > traceDateTime.getTime()) { bTimeStamp = (bTimeStamp - traceDateTime.getTime())/1000; if (TraceDataConst.WAKELOCK_RELEASED.equals(actualWakelockstate)) { wakelockState = WakelockState.WAKELOCK_RELEASED; } else { wakelockState = WakelockState.WAKELOCK_ACQUIRED; } wakelockInfos.add(new WakelockInfo(bTimeStamp, wakelockState)); LOGGER.info("Trace Start: " + traceDateTime.getTime() + "\nWakelock Time: " + bTimeStamp + " Wakelock state: " + actualWakelockstate + " strFields " + Arrays.toString(strFields)); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing wakelock event: " + Arrays.toString(strFields) + " found wakelock in " + index, e); } } } } return wakelockInfos; }  }
WakelockInfoReaderImpl extends PeripheralBase implements IWakelockInfoReader { @Override public List<WakelockInfo> readData(String directory, String osVersion, double dumpsysEpochTimestamp, Date traceDateTime){ List<WakelockInfo> wakelockInfos = new ArrayList<WakelockInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BATTERYINFO_FILE; String[] lines = null; if (!filereader.fileExist(filepath)) { return wakelockInfos; } if (osVersion != null && osVersion.compareTo("2.3") < 0) { LOGGER.info("OS 2.2(Froyo) or earlier does not has the wakelock timeline"); } try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Wakelock Info file: "+filepath); } if(lines != null && lines.length > 0){ WakelockState wakelockState; for (String strLineBuf : lines) { int index = strLineBuf.indexOf(TraceDataConst.WAKELOCK_ACQUIRED); if (index < 0) { index = strLineBuf.indexOf(TraceDataConst.WAKELOCK_RELEASED); } if (index > 0) { String actualWakelockstate = strLineBuf.substring(index, index+10); String strFields[] = strLineBuf.trim().split(" "); try { double bTimeStamp = dumpsysEpochTimestamp - Util.convertTime(strFields[0]); if (bTimeStamp > traceDateTime.getTime()) { bTimeStamp = (bTimeStamp - traceDateTime.getTime())/1000; if (TraceDataConst.WAKELOCK_RELEASED.equals(actualWakelockstate)) { wakelockState = WakelockState.WAKELOCK_RELEASED; } else { wakelockState = WakelockState.WAKELOCK_ACQUIRED; } wakelockInfos.add(new WakelockInfo(bTimeStamp, wakelockState)); LOGGER.info("Trace Start: " + traceDateTime.getTime() + "\nWakelock Time: " + bTimeStamp + " Wakelock state: " + actualWakelockstate + " strFields " + Arrays.toString(strFields)); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing wakelock event: " + Arrays.toString(strFields) + " found wakelock in " + index, e); } } } } return wakelockInfos; }  @Override List<WakelockInfo> readData(String directory, String osVersion, double dumpsysEpochTimestamp, Date traceDateTime); }
WakelockInfoReaderImpl extends PeripheralBase implements IWakelockInfoReader { @Override public List<WakelockInfo> readData(String directory, String osVersion, double dumpsysEpochTimestamp, Date traceDateTime){ List<WakelockInfo> wakelockInfos = new ArrayList<WakelockInfo>(); String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BATTERYINFO_FILE; String[] lines = null; if (!filereader.fileExist(filepath)) { return wakelockInfos; } if (osVersion != null && osVersion.compareTo("2.3") < 0) { LOGGER.info("OS 2.2(Froyo) or earlier does not has the wakelock timeline"); } try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed to read Wakelock Info file: "+filepath); } if(lines != null && lines.length > 0){ WakelockState wakelockState; for (String strLineBuf : lines) { int index = strLineBuf.indexOf(TraceDataConst.WAKELOCK_ACQUIRED); if (index < 0) { index = strLineBuf.indexOf(TraceDataConst.WAKELOCK_RELEASED); } if (index > 0) { String actualWakelockstate = strLineBuf.substring(index, index+10); String strFields[] = strLineBuf.trim().split(" "); try { double bTimeStamp = dumpsysEpochTimestamp - Util.convertTime(strFields[0]); if (bTimeStamp > traceDateTime.getTime()) { bTimeStamp = (bTimeStamp - traceDateTime.getTime())/1000; if (TraceDataConst.WAKELOCK_RELEASED.equals(actualWakelockstate)) { wakelockState = WakelockState.WAKELOCK_RELEASED; } else { wakelockState = WakelockState.WAKELOCK_ACQUIRED; } wakelockInfos.add(new WakelockInfo(bTimeStamp, wakelockState)); LOGGER.info("Trace Start: " + traceDateTime.getTime() + "\nWakelock Time: " + bTimeStamp + " Wakelock state: " + actualWakelockstate + " strFields " + Arrays.toString(strFields)); } } catch (Exception e) { LOGGER.warn("Unexpected error parsing wakelock event: " + Arrays.toString(strFields) + " found wakelock in " + index, e); } } } } return wakelockInfos; }  @Override List<WakelockInfo> readData(String directory, String osVersion, double dumpsysEpochTimestamp, Date traceDateTime);  }