From 72a25f16ee937670b58f969186f26980b83d3e68 Mon Sep 17 00:00:00 2001 From: ykhung Date: Tue, 12 Oct 2021 16:32:18 +0800 Subject: [PATCH] Add try-catch to avoid IllegalStateException in the data parsing if the BatteryStats service is crashed, we will provide the default instance for all modules in the battery settings, but it will encounter the IllegalStateException if we try to parse its history content (reference: ag/15926630) Bug: 201729939 Test: make SettingsRoboTests Change-Id: Ifebb48551e371e7c4e121969cb92cf95aa026812 --- .../batterytip/detectors/HighUsageDetector.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java b/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java index 4b3f2df3a7f..8126dcc2a31 100644 --- a/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java +++ b/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java @@ -21,6 +21,7 @@ import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME; import android.content.Context; import android.os.BatteryUsageStats; import android.os.UidBatteryConsumer; +import android.util.Log; import androidx.annotation.VisibleForTesting; @@ -41,6 +42,8 @@ import java.util.concurrent.TimeUnit; * {@link BatteryTipDetector} since it need the most up-to-date {@code visibleTips} */ public class HighUsageDetector implements BatteryTipDetector { + private static final String TAG = "HighUsageDetector"; + private BatteryTipPolicy mPolicy; private BatteryUsageStats mBatteryUsageStats; private final BatteryInfo mBatteryInfo; @@ -113,6 +116,10 @@ public class HighUsageDetector implements BatteryTipDetector { @VisibleForTesting void parseBatteryData() { - mBatteryInfo.parseBatteryHistory(mDataParser); + try { + mBatteryInfo.parseBatteryHistory(mDataParser); + } catch (IllegalStateException e) { + Log.e(TAG, "parseBatteryData() failed", e); + } } }