From 2c4b946f05b52b465000b5228d7e0a1933eb84d2 Mon Sep 17 00:00:00 2001 From: Mat Bevilacqua Date: Mon, 5 Oct 2020 16:42:26 -0700 Subject: [PATCH] Fix failing cts tests On devices where certain PowerStats HAL data is unavailable the data logger in PowerStatsService is disabled. Check for null before attempting to write the data to incident reports. Bug: 168528724 Test: Verified tests pass on devices with and without necessary PowerStats HAL data. Change-Id: I41b4e75ff673e4c3874c1ef6041d0a0b8102aa16 --- .../android/server/powerstats/PowerStatsService.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/powerstats/PowerStatsService.java b/services/core/java/com/android/server/powerstats/PowerStatsService.java index fd609c14276c9..81883f3012e99 100644 --- a/services/core/java/com/android/server/powerstats/PowerStatsService.java +++ b/services/core/java/com/android/server/powerstats/PowerStatsService.java @@ -16,6 +16,7 @@ package com.android.server.powerstats; +import android.annotation.Nullable; import android.content.Context; import android.os.Binder; import android.os.Environment; @@ -48,8 +49,11 @@ public class PowerStatsService extends SystemService { private Context mContext; private IPowerStatsHALWrapper mPowerStatsHALWrapper; + @Nullable private PowerStatsLogger mPowerStatsLogger; + @Nullable private BatteryTrigger mBatteryTrigger; + @Nullable private TimerTrigger mTimerTrigger; @VisibleForTesting @@ -88,7 +92,11 @@ public class PowerStatsService extends SystemService { if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; if (args.length > 0 && "--proto".equals(args[0])) { - mPowerStatsLogger.writeToFile(fd); + if (mPowerStatsLogger == null) { + Log.e(TAG, "PowerStats HAL is not initialized. No data available."); + } else { + mPowerStatsLogger.writeToFile(fd); + } } } }