@Test public void readEventsFileData() throws IOException { Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(new String[] { "now at 11038786578074 nsecs", "[ 11040.931026] /dev/input/event6: EV_ABS ABS_MT_POSITION_X 0000044b", "[ 11052.610105] /dev/input/event5: EV_KEY KEY_VOLUMEUP DOWN", "[ 11052.610105] /dev/input/event5: EV_KEY KEY_VOLUMEDOWN DOWN", "[ 11052.610105] /dev/input/event5: EV_KEY KEY_POWER DOWN", "[ 11052.610105] /dev/input/event5: EV_KEY KEY_HOME DOWN", "[ 11052.610105] /dev/input/event5: EV_KEY KEY_MENU DOWN", "[ 11052.610105] /dev/input/event5: EV_KEY KEY_SEARCH DOWN", "[ 11052.610105] /dev/input/event5: EV_KEY KEY_BACK DOWN", }); List<UserEvent> listUserEvent = traceDataReader.readGetEventsFile(traceFolder, 0, 0); assertEquals(8.0, listUserEvent.size(), 0); assertEquals("SCREEN_TOUCH", listUserEvent.get(0).getEventType().toString()); assertEquals("KEY_VOLUP", listUserEvent.get(1).getEventType().toString()); }
public List<UserEvent> readGetEventsFile(String directory, double eventTime0, double startTime) { List<UserEvent> userEvents = new ArrayList<UserEvent>(); String filePath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.USER_GETEVENTS_FILE; String[] lines = null; try { lines = filereader.readAllLine(filePath); } catch (IOException e) { LOGGER.error("failed to read user event file: " + filePath); } if (lines != null && lines.length > 0) { int idx = 1; double monotonicTime = 0; for (String lineBuf : lines) { if (idx == 1) { String monotonicFields[] = lineBuf.split(" "); if (monotonicFields.length > 2) { monotonicTime = (Double.parseDouble(monotonicFields[2])) / 1000000000; } idx++; continue; } if (lineBuf.trim().isEmpty() || lineBuf.contains("add device") || lineBuf.contains("name:")) { continue; } UserEvent.UserEventType actionType = UserEvent.UserEventType.EVENT_UNKNOWN; if (lineBuf.contains(TraceDataConst.GetEvent.SCREEN)) { actionType = UserEventType.SCREEN_TOUCH; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY)) { if (lineBuf.contains(TraceDataConst.GetEvent.KEY_POWER)) { actionType = UserEventType.KEY_POWER; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_VOLUP)) { actionType = UserEventType.KEY_VOLUP; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_VOLDOWN)) { actionType = UserEventType.KEY_VOLDOWN; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_HOME)) { actionType = UserEventType.KEY_HOME; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_MENU)) { actionType = UserEventType.KEY_MENU; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_BACK)) { actionType = UserEventType.KEY_BACK; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_SEARCH)) { actionType = UserEventType.KEY_SEARCH; } else { actionType = UserEventType.KEY_KEY; } } else { continue; } String strFields[] = lineBuf.split("]"); if (strFields[0].indexOf('[') != -1) { strFields[0] = strFields[0].substring(strFields[0].indexOf('[') + 1, strFields[0].length()); } String timeArray[] = strFields[0].split(" "); Double currentTime = Double.parseDouble(timeArray[timeArray.length - 1]); double dTimeStamp = currentTime - monotonicTime; userEvents.add(new UserEvent(actionType, dTimeStamp, dTimeStamp)); } } return userEvents; }
UserEventReaderImpl extends PeripheralBase implements IUserEventReader { public List<UserEvent> readGetEventsFile(String directory, double eventTime0, double startTime) { List<UserEvent> userEvents = new ArrayList<UserEvent>(); String filePath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.USER_GETEVENTS_FILE; String[] lines = null; try { lines = filereader.readAllLine(filePath); } catch (IOException e) { LOGGER.error("failed to read user event file: " + filePath); } if (lines != null && lines.length > 0) { int idx = 1; double monotonicTime = 0; for (String lineBuf : lines) { if (idx == 1) { String monotonicFields[] = lineBuf.split(" "); if (monotonicFields.length > 2) { monotonicTime = (Double.parseDouble(monotonicFields[2])) / 1000000000; } idx++; continue; } if (lineBuf.trim().isEmpty() || lineBuf.contains("add device") || lineBuf.contains("name:")) { continue; } UserEvent.UserEventType actionType = UserEvent.UserEventType.EVENT_UNKNOWN; if (lineBuf.contains(TraceDataConst.GetEvent.SCREEN)) { actionType = UserEventType.SCREEN_TOUCH; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY)) { if (lineBuf.contains(TraceDataConst.GetEvent.KEY_POWER)) { actionType = UserEventType.KEY_POWER; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_VOLUP)) { actionType = UserEventType.KEY_VOLUP; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_VOLDOWN)) { actionType = UserEventType.KEY_VOLDOWN; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_HOME)) { actionType = UserEventType.KEY_HOME; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_MENU)) { actionType = UserEventType.KEY_MENU; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_BACK)) { actionType = UserEventType.KEY_BACK; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_SEARCH)) { actionType = UserEventType.KEY_SEARCH; } else { actionType = UserEventType.KEY_KEY; } } else { continue; } String strFields[] = lineBuf.split("]"); if (strFields[0].indexOf('[') != -1) { strFields[0] = strFields[0].substring(strFields[0].indexOf('[') + 1, strFields[0].length()); } String timeArray[] = strFields[0].split(" "); Double currentTime = Double.parseDouble(timeArray[timeArray.length - 1]); double dTimeStamp = currentTime - monotonicTime; userEvents.add(new UserEvent(actionType, dTimeStamp, dTimeStamp)); } } return userEvents; } }
UserEventReaderImpl extends PeripheralBase implements IUserEventReader { public List<UserEvent> readGetEventsFile(String directory, double eventTime0, double startTime) { List<UserEvent> userEvents = new ArrayList<UserEvent>(); String filePath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.USER_GETEVENTS_FILE; String[] lines = null; try { lines = filereader.readAllLine(filePath); } catch (IOException e) { LOGGER.error("failed to read user event file: " + filePath); } if (lines != null && lines.length > 0) { int idx = 1; double monotonicTime = 0; for (String lineBuf : lines) { if (idx == 1) { String monotonicFields[] = lineBuf.split(" "); if (monotonicFields.length > 2) { monotonicTime = (Double.parseDouble(monotonicFields[2])) / 1000000000; } idx++; continue; } if (lineBuf.trim().isEmpty() || lineBuf.contains("add device") || lineBuf.contains("name:")) { continue; } UserEvent.UserEventType actionType = UserEvent.UserEventType.EVENT_UNKNOWN; if (lineBuf.contains(TraceDataConst.GetEvent.SCREEN)) { actionType = UserEventType.SCREEN_TOUCH; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY)) { if (lineBuf.contains(TraceDataConst.GetEvent.KEY_POWER)) { actionType = UserEventType.KEY_POWER; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_VOLUP)) { actionType = UserEventType.KEY_VOLUP; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_VOLDOWN)) { actionType = UserEventType.KEY_VOLDOWN; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_HOME)) { actionType = UserEventType.KEY_HOME; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_MENU)) { actionType = UserEventType.KEY_MENU; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_BACK)) { actionType = UserEventType.KEY_BACK; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_SEARCH)) { actionType = UserEventType.KEY_SEARCH; } else { actionType = UserEventType.KEY_KEY; } } else { continue; } String strFields[] = lineBuf.split("]"); if (strFields[0].indexOf('[') != -1) { strFields[0] = strFields[0].substring(strFields[0].indexOf('[') + 1, strFields[0].length()); } String timeArray[] = strFields[0].split(" "); Double currentTime = Double.parseDouble(timeArray[timeArray.length - 1]); double dTimeStamp = currentTime - monotonicTime; userEvents.add(new UserEvent(actionType, dTimeStamp, dTimeStamp)); } } return userEvents; }  }
UserEventReaderImpl extends PeripheralBase implements IUserEventReader { public List<UserEvent> readGetEventsFile(String directory, double eventTime0, double startTime) { List<UserEvent> userEvents = new ArrayList<UserEvent>(); String filePath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.USER_GETEVENTS_FILE; String[] lines = null; try { lines = filereader.readAllLine(filePath); } catch (IOException e) { LOGGER.error("failed to read user event file: " + filePath); } if (lines != null && lines.length > 0) { int idx = 1; double monotonicTime = 0; for (String lineBuf : lines) { if (idx == 1) { String monotonicFields[] = lineBuf.split(" "); if (monotonicFields.length > 2) { monotonicTime = (Double.parseDouble(monotonicFields[2])) / 1000000000; } idx++; continue; } if (lineBuf.trim().isEmpty() || lineBuf.contains("add device") || lineBuf.contains("name:")) { continue; } UserEvent.UserEventType actionType = UserEvent.UserEventType.EVENT_UNKNOWN; if (lineBuf.contains(TraceDataConst.GetEvent.SCREEN)) { actionType = UserEventType.SCREEN_TOUCH; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY)) { if (lineBuf.contains(TraceDataConst.GetEvent.KEY_POWER)) { actionType = UserEventType.KEY_POWER; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_VOLUP)) { actionType = UserEventType.KEY_VOLUP; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_VOLDOWN)) { actionType = UserEventType.KEY_VOLDOWN; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_HOME)) { actionType = UserEventType.KEY_HOME; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_MENU)) { actionType = UserEventType.KEY_MENU; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_BACK)) { actionType = UserEventType.KEY_BACK; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_SEARCH)) { actionType = UserEventType.KEY_SEARCH; } else { actionType = UserEventType.KEY_KEY; } } else { continue; } String strFields[] = lineBuf.split("]"); if (strFields[0].indexOf('[') != -1) { strFields[0] = strFields[0].substring(strFields[0].indexOf('[') + 1, strFields[0].length()); } String timeArray[] = strFields[0].split(" "); Double currentTime = Double.parseDouble(timeArray[timeArray.length - 1]); double dTimeStamp = currentTime - monotonicTime; userEvents.add(new UserEvent(actionType, dTimeStamp, dTimeStamp)); } } return userEvents; }  List<UserEvent> readGetEventsFile(String directory, double eventTime0, double startTime); @Override List<UserEvent> readData(String directory, double eventTime0, double startTime); }
UserEventReaderImpl extends PeripheralBase implements IUserEventReader { public List<UserEvent> readGetEventsFile(String directory, double eventTime0, double startTime) { List<UserEvent> userEvents = new ArrayList<UserEvent>(); String filePath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.USER_GETEVENTS_FILE; String[] lines = null; try { lines = filereader.readAllLine(filePath); } catch (IOException e) { LOGGER.error("failed to read user event file: " + filePath); } if (lines != null && lines.length > 0) { int idx = 1; double monotonicTime = 0; for (String lineBuf : lines) { if (idx == 1) { String monotonicFields[] = lineBuf.split(" "); if (monotonicFields.length > 2) { monotonicTime = (Double.parseDouble(monotonicFields[2])) / 1000000000; } idx++; continue; } if (lineBuf.trim().isEmpty() || lineBuf.contains("add device") || lineBuf.contains("name:")) { continue; } UserEvent.UserEventType actionType = UserEvent.UserEventType.EVENT_UNKNOWN; if (lineBuf.contains(TraceDataConst.GetEvent.SCREEN)) { actionType = UserEventType.SCREEN_TOUCH; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY)) { if (lineBuf.contains(TraceDataConst.GetEvent.KEY_POWER)) { actionType = UserEventType.KEY_POWER; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_VOLUP)) { actionType = UserEventType.KEY_VOLUP; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_VOLDOWN)) { actionType = UserEventType.KEY_VOLDOWN; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_HOME)) { actionType = UserEventType.KEY_HOME; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_MENU)) { actionType = UserEventType.KEY_MENU; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_BACK)) { actionType = UserEventType.KEY_BACK; } else if (lineBuf.contains(TraceDataConst.GetEvent.KEY_SEARCH)) { actionType = UserEventType.KEY_SEARCH; } else { actionType = UserEventType.KEY_KEY; } } else { continue; } String strFields[] = lineBuf.split("]"); if (strFields[0].indexOf('[') != -1) { strFields[0] = strFields[0].substring(strFields[0].indexOf('[') + 1, strFields[0].length()); } String timeArray[] = strFields[0].split(" "); Double currentTime = Double.parseDouble(timeArray[timeArray.length - 1]); double dTimeStamp = currentTime - monotonicTime; userEvents.add(new UserEvent(actionType, dTimeStamp, dTimeStamp)); } } return userEvents; }  List<UserEvent> readGetEventsFile(String directory, double eventTime0, double startTime); @Override List<UserEvent> readData(String directory, double eventTime0, double startTime);  }