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

Commit 40b0deff authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Make IPowerStats nullable in SystemHealthManager

"powerstats" service is unavailable in the ephemeral mode,
therefore it needs to be allowed to be missing.

Test: atest --instant CtsOsTestCases:android.os.health.cts.SystemHealthManagerTest
Bug: 288124045

Change-Id: If6bfe6a2e445670f01b16893c1dc31269bbcb30b
parent b6aba377
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1119,7 +1119,7 @@ public final class SystemServiceRegistry {
            @Override
            public SystemHealthManager createService(ContextImpl ctx) throws ServiceNotFoundException {
                IBinder batteryStats = ServiceManager.getServiceOrThrow(BatteryStats.SERVICE_NAME);
                IBinder powerStats = ServiceManager.getServiceOrThrow(Context.POWER_STATS_SERVICE);
                IBinder powerStats = ServiceManager.getService(Context.POWER_STATS_SERVICE);
                return new SystemHealthManager(IBatteryStats.Stub.asInterface(batteryStats),
                        IPowerStatsService.Stub.asInterface(powerStats));
            }});
+17 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.os.health;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemService;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
@@ -57,7 +58,9 @@ import java.util.concurrent.ExecutionException;
 */
@SystemService(Context.SYSTEM_HEALTH_SERVICE)
public class SystemHealthManager {
    @NonNull
    private final IBatteryStats mBatteryStats;
    @Nullable
    private final IPowerStatsService mPowerStats;
    private PowerMonitor[] mPowerMonitorsInfo;

@@ -74,7 +77,8 @@ public class SystemHealthManager {
    }

    /** {@hide} */
    public SystemHealthManager(IBatteryStats batteryStats, IPowerStatsService powerStats) {
    public SystemHealthManager(@NonNull IBatteryStats batteryStats,
            @Nullable IPowerStatsService powerStats) {
        mBatteryStats = batteryStats;
        mPowerStats = powerStats;
    }
@@ -185,6 +189,12 @@ public class SystemHealthManager {
                return;
            }
            try {
                if (mPowerStats == null) {
                    mPowerMonitorsInfo = new PowerMonitor[0];
                    future.complete(mPowerMonitorsInfo);
                    return;
                }

                mPowerStats.getSupportedPowerMonitors(new ResultReceiver(null) {
                    @Override
                    protected void onReceiveResult(int resultCode, Bundle resultData) {
@@ -227,6 +237,12 @@ public class SystemHealthManager {
     */
    public void getPowerMonitorReadings(@NonNull PowerMonitor[] powerMonitors,
            @NonNull CompletableFuture<PowerMonitorReadings> future) {
        if (mPowerStats == null) {
            future.completeExceptionally(
                    new IllegalArgumentException("Unsupported power monitor"));
            return;
        }

        Arrays.sort(powerMonitors, POWER_MONITOR_COMPARATOR);
        int[] indices = new int[powerMonitors.length];
        for (int i = 0; i < powerMonitors.length; i++) {