From 4b6fa6106b735e9ab54618e3493d40fecae620e4 Mon Sep 17 00:00:00 2001 From: Benjamin Schwartz Date: Mon, 8 Mar 2021 10:06:29 -0800 Subject: [PATCH] powerstats: Add null checks to clients of power stats api Bug: 182092453 Test: Presubmit Change-Id: Iaa59fb6cb01c6ac41aba15b206ea98dcc796bee4 --- .../com/android/server/powerstats/ProtoStreamUtils.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/core/java/com/android/server/powerstats/ProtoStreamUtils.java b/services/core/java/com/android/server/powerstats/ProtoStreamUtils.java index 746a09882f930..688f0bf5e55f0 100644 --- a/services/core/java/com/android/server/powerstats/ProtoStreamUtils.java +++ b/services/core/java/com/android/server/powerstats/ProtoStreamUtils.java @@ -111,6 +111,8 @@ public class ProtoStreamUtils { static class StateResidencyResultUtils { public static void adjustTimeSinceBootToEpoch(StateResidencyResult[] stateResidencyResult, long startWallTime) { + if (stateResidencyResult == null) return; + for (int i = 0; i < stateResidencyResult.length; i++) { final int stateLength = stateResidencyResult[i].stateResidencyData.length; for (int j = 0; j < stateLength; j++) { @@ -320,6 +322,8 @@ public class ProtoStreamUtils { static class EnergyMeasurementUtils { public static void adjustTimeSinceBootToEpoch(EnergyMeasurement[] energyMeasurement, long startWallTime) { + if (energyMeasurement == null) return; + for (int i = 0; i < energyMeasurement.length; i++) { energyMeasurement[i].timestampMs += startWallTime; } @@ -539,6 +543,8 @@ public class ProtoStreamUtils { static class EnergyConsumerResultUtils { public static void adjustTimeSinceBootToEpoch(EnergyConsumerResult[] energyConsumerResult, long startWallTime) { + if (energyConsumerResult == null) return; + for (int i = 0; i < energyConsumerResult.length; i++) { energyConsumerResult[i].timestampMs += startWallTime; }