Loading core/java/android/app/SystemServiceRegistry.java +1 −1 Original line number Diff line number Diff line Loading @@ -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)); }}); Loading core/java/android/os/health/SystemHealthManager.java +17 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -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; } Loading Loading @@ -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) { Loading Loading @@ -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++) { Loading Loading
core/java/android/app/SystemServiceRegistry.java +1 −1 Original line number Diff line number Diff line Loading @@ -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)); }}); Loading
core/java/android/os/health/SystemHealthManager.java +17 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -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; } Loading Loading @@ -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) { Loading Loading @@ -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++) { Loading