Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2c4b946f authored by Mat Bevilacqua's avatar Mat Bevilacqua
Browse files

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
parent 0572a76b
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -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,10 +92,14 @@ public class PowerStatsService extends SystemService {
            if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;

            if (args.length > 0 && "--proto".equals(args[0])) {
                if (mPowerStatsLogger == null) {
                    Log.e(TAG, "PowerStats HAL is not initialized.  No data available.");
                } else {
                    mPowerStatsLogger.writeToFile(fd);
                }
            }
        }
    }

    @Override
    public void onBootPhase(int phase) {