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

Commit ee659622 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make IPowerStats nullable in SystemHealthManager"

parents d5a3bb44 40b0deff
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++) {