@Test public void testBrokenFile() throws Exception { DiskMetricsCollectorWithProcFile collector = new DiskMetricsCollectorWithProcFile() .setPath(createFile("I am a weird android"), createFile("manufacturer")); DiskMetrics snapshot = new DiskMetrics(); assertThat(collector.getSnapshot(snapshot)).isFalse(); }
@Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; }
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; } }
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; }  }
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; }  @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(DiskMetrics snapshot); synchronized void enable(); @Override DiskMetrics createMetrics(); static boolean isSupported(); }
DiskMetricsCollector extends SystemMetricsCollector<DiskMetrics> { @Override @ThreadSafe(enableChecks = false) public synchronized boolean getSnapshot(DiskMetrics snapshot) { checkNotNull(snapshot, "Null value passed to getSnapshot!"); if (!mIsEnabled) { return false; } try { ProcFileReader ioReader = mProcIoFileReader.get(); if (ioReader == null) { ioReader = new ProcFileReader(getIoFilePath()); mProcIoFileReader.set(ioReader); } ioReader.reset(); if (!ioReader.isValid()) { return false; } snapshot.rcharBytes = readField(ioReader); snapshot.wcharBytes = readField(ioReader); snapshot.syscrCount = readField(ioReader); snapshot.syscwCount = readField(ioReader); snapshot.readBytes = readField(ioReader); snapshot.writeBytes = readField(ioReader); snapshot.cancelledWriteBytes = readField(ioReader); ProcFileReader statReader = mProcStatFileReader.get(); if (statReader == null) { statReader = new ProcFileReader(getStatFilePath()); mProcStatFileReader.set(statReader); } statReader.reset(); if (!statReader.isValid()) { return false; } int index = 0; while (index < PROC_STAT_MAJOR_FAULTS_FIELD) { statReader.skipSpaces(); index++; } snapshot.majorFaults = statReader.readNumber(); while (index < PROC_STAT_BLKIO_TICKS_FIELD) { statReader.skipSpaces(); index++; } snapshot.blkIoTicks = statReader.readNumber(); } catch (ProcFileReader.ParseException pe) { SystemMetricsLogger.wtf(TAG, "Unable to parse disk field", pe); return false; } return true; }  @Override @ThreadSafe(enableChecks = false) synchronized boolean getSnapshot(DiskMetrics snapshot); synchronized void enable(); @Override DiskMetrics createMetrics(); static boolean isSupported();  }