Loading services/core/java/com/android/server/powerstats/PowerStatsDataStorage.java +21 −12 Original line number Diff line number Diff line Loading @@ -220,33 +220,39 @@ public class PowerStatsDataStorage { public void write(byte[] data) { if (data != null && data.length > 0) { mLock.lock(); long currentTimeMillis = System.currentTimeMillis(); try { long currentTimeMillis = System.currentTimeMillis(); DataElement dataElement = new DataElement(data); mFileRotator.rewriteActive(new DataRewriter(dataElement.toByteArray()), currentTimeMillis); mFileRotator.maybeRotate(currentTimeMillis); } catch (IOException e) { Slog.e(TAG, "Failed to write to on-device storage: " + e); } } finally { mLock.unlock(); } } } /** * Reads all DataElements stored in on-device storage. For each * DataElement retrieved from on-device storage, callback is called. */ public void read(DataElementReadCallback callback) throws IOException { mLock.lock(); try { mFileRotator.readMatching(new DataReader(callback), Long.MIN_VALUE, Long.MAX_VALUE); } finally { mLock.unlock(); } } /** * Deletes all stored log data. */ public void deleteLogs() { mLock.lock(); try { File[] files = mDataStorageDir.listFiles(); for (int i = 0; i < files.length; i++) { int versionDot = mDataStorageFilename.lastIndexOf('.'); Loading @@ -256,5 +262,8 @@ public class PowerStatsDataStorage { files[i].delete(); } } } finally { mLock.unlock(); } } } services/core/java/com/android/server/powerstats/PowerStatsLogger.java +8 −8 Original line number Diff line number Diff line Loading @@ -159,12 +159,12 @@ public final class PowerStatsLogger extends Handler { EnergyMeasurementUtils.packProtoMessage(energyMeasurement, pos); if (DEBUG) EnergyMeasurementUtils.print(energyMeasurement); } catch (IOException e) { Slog.e(TAG, "Failed to write energy meter data to incident report."); Slog.e(TAG, "Failed to write energy meter data to incident report.", e); } } }); } catch (IOException e) { Slog.e(TAG, "Failed to write energy meter info to incident report."); Slog.e(TAG, "Failed to write energy meter info to incident report.", e); } pos.flush(); Loading Loading @@ -200,12 +200,12 @@ public final class PowerStatsLogger extends Handler { EnergyConsumerResultUtils.packProtoMessage(energyConsumerResult, pos, true); if (DEBUG) EnergyConsumerResultUtils.print(energyConsumerResult); } catch (IOException e) { Slog.e(TAG, "Failed to write energy model data to incident report."); Slog.e(TAG, "Failed to write energy model data to incident report.", e); } } }); } catch (IOException e) { Slog.e(TAG, "Failed to write energy model info to incident report."); Slog.e(TAG, "Failed to write energy model info to incident report.", e); } pos.flush(); Loading Loading @@ -241,12 +241,12 @@ public final class PowerStatsLogger extends Handler { StateResidencyResultUtils.packProtoMessage(stateResidencyResult, pos); if (DEBUG) StateResidencyResultUtils.print(stateResidencyResult); } catch (IOException e) { Slog.e(TAG, "Failed to write residency data to incident report."); Slog.e(TAG, "Failed to write residency data to incident report.", e); } } }); } catch (IOException e) { Slog.e(TAG, "Failed to write residency data to incident report."); Slog.e(TAG, "Failed to write residency data to incident report.", e); } pos.flush(); Loading @@ -267,7 +267,7 @@ public final class PowerStatsLogger extends Handler { final FileInputStream fis = new FileInputStream(cachedFile.getPath()); fis.read(dataCached); } catch (IOException e) { Slog.e(TAG, "Failed to read cached data from file"); Slog.e(TAG, "Failed to read cached data from file", e); } // If the cached and current data are different, delete the data store. Loading @@ -291,7 +291,7 @@ public final class PowerStatsLogger extends Handler { fos.write(data); atomicCachedFile.finishWrite(fos); } catch (IOException e) { Slog.e(TAG, "Failed to write current data to cached file"); Slog.e(TAG, "Failed to write current data to cached file", e); } } Loading Loading
services/core/java/com/android/server/powerstats/PowerStatsDataStorage.java +21 −12 Original line number Diff line number Diff line Loading @@ -220,33 +220,39 @@ public class PowerStatsDataStorage { public void write(byte[] data) { if (data != null && data.length > 0) { mLock.lock(); long currentTimeMillis = System.currentTimeMillis(); try { long currentTimeMillis = System.currentTimeMillis(); DataElement dataElement = new DataElement(data); mFileRotator.rewriteActive(new DataRewriter(dataElement.toByteArray()), currentTimeMillis); mFileRotator.maybeRotate(currentTimeMillis); } catch (IOException e) { Slog.e(TAG, "Failed to write to on-device storage: " + e); } } finally { mLock.unlock(); } } } /** * Reads all DataElements stored in on-device storage. For each * DataElement retrieved from on-device storage, callback is called. */ public void read(DataElementReadCallback callback) throws IOException { mLock.lock(); try { mFileRotator.readMatching(new DataReader(callback), Long.MIN_VALUE, Long.MAX_VALUE); } finally { mLock.unlock(); } } /** * Deletes all stored log data. */ public void deleteLogs() { mLock.lock(); try { File[] files = mDataStorageDir.listFiles(); for (int i = 0; i < files.length; i++) { int versionDot = mDataStorageFilename.lastIndexOf('.'); Loading @@ -256,5 +262,8 @@ public class PowerStatsDataStorage { files[i].delete(); } } } finally { mLock.unlock(); } } }
services/core/java/com/android/server/powerstats/PowerStatsLogger.java +8 −8 Original line number Diff line number Diff line Loading @@ -159,12 +159,12 @@ public final class PowerStatsLogger extends Handler { EnergyMeasurementUtils.packProtoMessage(energyMeasurement, pos); if (DEBUG) EnergyMeasurementUtils.print(energyMeasurement); } catch (IOException e) { Slog.e(TAG, "Failed to write energy meter data to incident report."); Slog.e(TAG, "Failed to write energy meter data to incident report.", e); } } }); } catch (IOException e) { Slog.e(TAG, "Failed to write energy meter info to incident report."); Slog.e(TAG, "Failed to write energy meter info to incident report.", e); } pos.flush(); Loading Loading @@ -200,12 +200,12 @@ public final class PowerStatsLogger extends Handler { EnergyConsumerResultUtils.packProtoMessage(energyConsumerResult, pos, true); if (DEBUG) EnergyConsumerResultUtils.print(energyConsumerResult); } catch (IOException e) { Slog.e(TAG, "Failed to write energy model data to incident report."); Slog.e(TAG, "Failed to write energy model data to incident report.", e); } } }); } catch (IOException e) { Slog.e(TAG, "Failed to write energy model info to incident report."); Slog.e(TAG, "Failed to write energy model info to incident report.", e); } pos.flush(); Loading Loading @@ -241,12 +241,12 @@ public final class PowerStatsLogger extends Handler { StateResidencyResultUtils.packProtoMessage(stateResidencyResult, pos); if (DEBUG) StateResidencyResultUtils.print(stateResidencyResult); } catch (IOException e) { Slog.e(TAG, "Failed to write residency data to incident report."); Slog.e(TAG, "Failed to write residency data to incident report.", e); } } }); } catch (IOException e) { Slog.e(TAG, "Failed to write residency data to incident report."); Slog.e(TAG, "Failed to write residency data to incident report.", e); } pos.flush(); Loading @@ -267,7 +267,7 @@ public final class PowerStatsLogger extends Handler { final FileInputStream fis = new FileInputStream(cachedFile.getPath()); fis.read(dataCached); } catch (IOException e) { Slog.e(TAG, "Failed to read cached data from file"); Slog.e(TAG, "Failed to read cached data from file", e); } // If the cached and current data are different, delete the data store. Loading @@ -291,7 +291,7 @@ public final class PowerStatsLogger extends Handler { fos.write(data); atomicCachedFile.finishWrite(fos); } catch (IOException e) { Slog.e(TAG, "Failed to write current data to cached file"); Slog.e(TAG, "Failed to write current data to cached file", e); } } Loading