use of com.att.aro.core.peripheral.pojo.WakelockInfo.WakelockState in project VideoOptimzer by attdevsupport.
the class WakelockInfoReaderImpl method readData.
@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) {
// Look for +/-wake_lock
int index = strLineBuf.indexOf(TraceDataConst.WAKELOCK_ACQUIRED);
if (index < 0) {
index = strLineBuf.indexOf(TraceDataConst.WAKELOCK_RELEASED);
}
// If either +/-wake_lock found
if (index > 0) {
String actualWakelockstate = strLineBuf.substring(index, index + 10);
String[] strFields = strLineBuf.trim().split(" ");
try {
// Get timestamp of wakelock event
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;
}
Aggregations