use of com.att.aro.core.peripheral.pojo.ScreenStateInfo.ScreenState in project VideoOptimzer by attdevsupport.
the class ScreenStateInfoReaderImpl method readData.
@Override
public List<ScreenStateInfo> readData(String directory, double startTime, double traceDuration) {
List<ScreenStateInfo> screenStateInfos = new ArrayList<ScreenStateInfo>();
String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.SCREEN_STATE_FILE;
if (!filereader.fileExist(filepath)) {
return screenStateInfos;
}
double beginTime = 0.0;
double endTime = 0.0;
ScreenState prevScreenState = null;
ScreenState screenState;
String prevBrigtness = null;
String brightness = null;
int prevTimeOut = 0;
int timeout = 0;
String firstLine;
String strLineBuf;
String[] lines = null;
try {
lines = filereader.readAllLine(filepath);
} catch (IOException e1) {
LOGGER.error("failed to open Screen State info file: " + filepath);
}
if (lines != null && lines.length > 0) {
firstLine = lines[0];
String[] strFieldsFirstLine = firstLine.split(" ");
if (strFieldsFirstLine.length >= 2) {
try {
beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]), startTime);
if (TraceDataConst.SCREEN_ON.equals(strFieldsFirstLine[1])) {
prevScreenState = ScreenState.SCREEN_ON;
if (strFieldsFirstLine.length >= 4) {
prevTimeOut = Integer.parseInt(strFieldsFirstLine[2]);
prevBrigtness = strFieldsFirstLine[3];
}
} else if (TraceDataConst.SCREEN_OFF.equals(strFieldsFirstLine[1])) {
prevScreenState = ScreenState.SCREEN_OFF;
} else {
LOGGER.warn("Unknown screen state: " + firstLine);
prevScreenState = ScreenState.SCREEN_UNKNOWN;
}
} catch (Exception e) {
LOGGER.warn("Unexpected error in screen events: " + firstLine, e);
}
} else {
LOGGER.warn("Unrecognized screen state event: " + firstLine);
}
for (int i = 1; i < lines.length; i++) {
strLineBuf = lines[i];
String[] strFields = strLineBuf.split(" ");
if (strFields.length >= 2) {
try {
endTime = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime);
brightness = null;
timeout = 0;
if (TraceDataConst.SCREEN_ON.equals(strFields[1])) {
screenState = ScreenState.SCREEN_ON;
if (strFields.length >= 4) {
timeout = Integer.parseInt(strFields[2]);
brightness = strFields[3];
}
} else if (TraceDataConst.SCREEN_OFF.equals(strFields[1])) {
screenState = ScreenState.SCREEN_OFF;
} else {
LOGGER.warn("Unknown screen state: " + strLineBuf);
screenState = ScreenState.SCREEN_UNKNOWN;
}
ScreenStateInfo screenInfo = new ScreenStateInfo(beginTime, endTime, prevScreenState, prevBrigtness, prevTimeOut);
screenStateInfos.add(screenInfo);
prevScreenState = screenState;
prevBrigtness = brightness;
prevTimeOut = timeout;
beginTime = endTime;
} catch (Exception e) {
LOGGER.warn("Unexpected error in screen events: " + strLineBuf, e);
}
} else {
LOGGER.warn("Unrecognized screen state event: " + strLineBuf);
}
}
screenStateInfos.add(new ScreenStateInfo(beginTime, traceDuration, prevScreenState, prevBrigtness, prevTimeOut));
}
return screenStateInfos;
}
Aggregations