Merge "health package: switch to aidl HealthInfo"

This commit is contained in:
Yifan Hong
2021-11-10 21:10:54 +00:00
committed by Gerrit Code Review
8 changed files with 134 additions and 83 deletions

View File

@@ -138,9 +138,11 @@ java_library_static {
"android.hardware.boot-V1.1-java", "android.hardware.boot-V1.1-java",
"android.hardware.boot-V1.2-java", "android.hardware.boot-V1.2-java",
"android.hardware.broadcastradio-V2.0-java", "android.hardware.broadcastradio-V2.0-java",
"android.hardware.health-V1.0-java", "android.hardware.health-V1.0-java", // HIDL
"android.hardware.health-V2.0-java", "android.hardware.health-V2.0-java", // HIDL
"android.hardware.health-V2.1-java", "android.hardware.health-V2.1-java", // HIDL
"android.hardware.health-V1-java", // AIDL
"android.hardware.health-translate-java",
"android.hardware.light-V1-java", "android.hardware.light-V1-java",
"android.hardware.tv.cec-V1.1-java", "android.hardware.tv.cec-V1.1-java",
"android.hardware.weaver-V1.0-java", "android.hardware.weaver-V1.0-java",

View File

@@ -17,7 +17,7 @@
package com.android.server; package com.android.server;
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent; import static com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import static com.android.server.health.Utils.copy; import static com.android.server.health.Utils.copyV1Battery;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.app.ActivityManager; import android.app.ActivityManager;
@@ -26,7 +26,7 @@ import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.hardware.health.V1_0.HealthInfo; import android.hardware.health.HealthInfo;
import android.hardware.health.V2_1.BatteryCapacityLevel; import android.hardware.health.V2_1.BatteryCapacityLevel;
import android.metrics.LogMaker; import android.metrics.LogMaker;
import android.os.BatteryManager; import android.os.BatteryManager;
@@ -138,7 +138,6 @@ public final class BatteryService extends SystemService {
private HealthInfo mHealthInfo; private HealthInfo mHealthInfo;
private final HealthInfo mLastHealthInfo = new HealthInfo(); private final HealthInfo mLastHealthInfo = new HealthInfo();
private android.hardware.health.V2_1.HealthInfo mHealthInfo2p1;
private boolean mBatteryLevelCritical; private boolean mBatteryLevelCritical;
private int mLastBatteryStatus; private int mLastBatteryStatus;
private int mLastBatteryHealth; private int mLastBatteryHealth;
@@ -354,8 +353,8 @@ public final class BatteryService extends SystemService {
} }
private boolean shouldShutdownLocked() { private boolean shouldShutdownLocked() {
if (mHealthInfo2p1.batteryCapacityLevel != BatteryCapacityLevel.UNSUPPORTED) { if (mHealthInfo.batteryCapacityLevel != BatteryCapacityLevel.UNSUPPORTED) {
return (mHealthInfo2p1.batteryCapacityLevel == BatteryCapacityLevel.CRITICAL); return (mHealthInfo.batteryCapacityLevel == BatteryCapacityLevel.CRITICAL);
} }
if (mHealthInfo.batteryLevel > 0) { if (mHealthInfo.batteryLevel > 0) {
return false; return false;
@@ -397,7 +396,7 @@ public final class BatteryService extends SystemService {
// shut down gracefully if temperature is too high (> 68.0C by default) // shut down gracefully if temperature is too high (> 68.0C by default)
// wait until the system has booted before attempting to display the // wait until the system has booted before attempting to display the
// shutdown dialog. // shutdown dialog.
if (mHealthInfo.batteryTemperature > mShutdownBatteryTemperature) { if (mHealthInfo.batteryTemperatureTenthsCelsius > mShutdownBatteryTemperature) {
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -414,27 +413,23 @@ public final class BatteryService extends SystemService {
} }
} }
private void update(android.hardware.health.V2_1.HealthInfo info) { private void update(android.hardware.health.HealthInfo info) {
traceBegin("HealthInfoUpdate"); traceBegin("HealthInfoUpdate");
Trace.traceCounter(Trace.TRACE_TAG_POWER, "BatteryChargeCounter", Trace.traceCounter(
info.legacy.legacy.batteryChargeCounter); Trace.TRACE_TAG_POWER, "BatteryChargeCounter", info.batteryChargeCounterUah);
Trace.traceCounter(Trace.TRACE_TAG_POWER, "BatteryCurrent", Trace.traceCounter(Trace.TRACE_TAG_POWER, "BatteryCurrent", info.batteryCurrentMicroamps);
info.legacy.legacy.batteryCurrent); Trace.traceCounter(Trace.TRACE_TAG_POWER, "PlugType", plugType(info));
Trace.traceCounter(Trace.TRACE_TAG_POWER, "PlugType", Trace.traceCounter(Trace.TRACE_TAG_POWER, "BatteryStatus", info.batteryStatus);
plugType(info.legacy.legacy));
Trace.traceCounter(Trace.TRACE_TAG_POWER, "BatteryStatus",
info.legacy.legacy.batteryStatus);
synchronized (mLock) { synchronized (mLock) {
if (!mUpdatesStopped) { if (!mUpdatesStopped) {
mHealthInfo = info.legacy.legacy; mHealthInfo = info;
mHealthInfo2p1 = info;
// Process the new values. // Process the new values.
processValuesLocked(false); processValuesLocked(false);
mLock.notifyAll(); // for any waiters on new info mLock.notifyAll(); // for any waiters on new info
} else { } else {
copy(mLastHealthInfo, info.legacy.legacy); copyV1Battery(mLastHealthInfo, info);
} }
} }
traceEnd(); traceEnd();
@@ -470,11 +465,16 @@ public final class BatteryService extends SystemService {
// Let the battery stats keep track of the current level. // Let the battery stats keep track of the current level.
try { try {
mBatteryStats.setBatteryState(mHealthInfo.batteryStatus, mHealthInfo.batteryHealth, mBatteryStats.setBatteryState(
mPlugType, mHealthInfo.batteryLevel, mHealthInfo.batteryTemperature, mHealthInfo.batteryStatus,
mHealthInfo.batteryVoltage, mHealthInfo.batteryChargeCounter, mHealthInfo.batteryHealth,
mHealthInfo.batteryFullCharge, mPlugType,
mHealthInfo2p1.batteryChargeTimeToFullNowSeconds); mHealthInfo.batteryLevel,
mHealthInfo.batteryTemperatureTenthsCelsius,
mHealthInfo.batteryVoltageMillivolts,
mHealthInfo.batteryChargeCounterUah,
mHealthInfo.batteryFullChargeUah,
mHealthInfo.batteryChargeTimeToFullNowSeconds);
} catch (RemoteException e) { } catch (RemoteException e) {
// Should never happen. // Should never happen.
} }
@@ -482,17 +482,18 @@ public final class BatteryService extends SystemService {
shutdownIfNoPowerLocked(); shutdownIfNoPowerLocked();
shutdownIfOverTempLocked(); shutdownIfOverTempLocked();
if (force || (mHealthInfo.batteryStatus != mLastBatteryStatus || if (force
mHealthInfo.batteryHealth != mLastBatteryHealth || || (mHealthInfo.batteryStatus != mLastBatteryStatus
mHealthInfo.batteryPresent != mLastBatteryPresent || || mHealthInfo.batteryHealth != mLastBatteryHealth
mHealthInfo.batteryLevel != mLastBatteryLevel || || mHealthInfo.batteryPresent != mLastBatteryPresent
mPlugType != mLastPlugType || || mHealthInfo.batteryLevel != mLastBatteryLevel
mHealthInfo.batteryVoltage != mLastBatteryVoltage || || mPlugType != mLastPlugType
mHealthInfo.batteryTemperature != mLastBatteryTemperature || || mHealthInfo.batteryVoltageMillivolts != mLastBatteryVoltage
mHealthInfo.maxChargingCurrent != mLastMaxChargingCurrent || || mHealthInfo.batteryTemperatureTenthsCelsius != mLastBatteryTemperature
mHealthInfo.maxChargingVoltage != mLastMaxChargingVoltage || || mHealthInfo.maxChargingCurrentMicroamps != mLastMaxChargingCurrent
mHealthInfo.batteryChargeCounter != mLastChargeCounter || || mHealthInfo.maxChargingVoltageMicrovolts != mLastMaxChargingVoltage
mInvalidCharger != mLastInvalidCharger)) { || mHealthInfo.batteryChargeCounterUah != mLastChargeCounter
|| mInvalidCharger != mLastInvalidCharger)) {
if (mPlugType != mLastPlugType) { if (mPlugType != mLastPlugType) {
if (mLastPlugType == BATTERY_PLUGGED_NONE) { if (mLastPlugType == BATTERY_PLUGGED_NONE) {
@@ -549,8 +550,11 @@ public final class BatteryService extends SystemService {
if (mHealthInfo.batteryLevel != mLastBatteryLevel) { if (mHealthInfo.batteryLevel != mLastBatteryLevel) {
// Don't do this just from voltage or temperature changes, that is // Don't do this just from voltage or temperature changes, that is
// too noisy. // too noisy.
EventLog.writeEvent(EventLogTags.BATTERY_LEVEL, EventLog.writeEvent(
mHealthInfo.batteryLevel, mHealthInfo.batteryVoltage, mHealthInfo.batteryTemperature); EventLogTags.BATTERY_LEVEL,
mHealthInfo.batteryLevel,
mHealthInfo.batteryVoltageMillivolts,
mHealthInfo.batteryTemperatureTenthsCelsius);
} }
if (mBatteryLevelCritical && !mLastBatteryLevelCritical && if (mBatteryLevelCritical && !mLastBatteryLevelCritical &&
mPlugType == BATTERY_PLUGGED_NONE) { mPlugType == BATTERY_PLUGGED_NONE) {
@@ -656,11 +660,11 @@ public final class BatteryService extends SystemService {
mLastBatteryPresent = mHealthInfo.batteryPresent; mLastBatteryPresent = mHealthInfo.batteryPresent;
mLastBatteryLevel = mHealthInfo.batteryLevel; mLastBatteryLevel = mHealthInfo.batteryLevel;
mLastPlugType = mPlugType; mLastPlugType = mPlugType;
mLastBatteryVoltage = mHealthInfo.batteryVoltage; mLastBatteryVoltage = mHealthInfo.batteryVoltageMillivolts;
mLastBatteryTemperature = mHealthInfo.batteryTemperature; mLastBatteryTemperature = mHealthInfo.batteryTemperatureTenthsCelsius;
mLastMaxChargingCurrent = mHealthInfo.maxChargingCurrent; mLastMaxChargingCurrent = mHealthInfo.maxChargingCurrentMicroamps;
mLastMaxChargingVoltage = mHealthInfo.maxChargingVoltage; mLastMaxChargingVoltage = mHealthInfo.maxChargingVoltageMicrovolts;
mLastChargeCounter = mHealthInfo.batteryChargeCounter; mLastChargeCounter = mHealthInfo.batteryChargeCounterUah;
mLastBatteryLevelCritical = mBatteryLevelCritical; mLastBatteryLevelCritical = mBatteryLevelCritical;
mLastInvalidCharger = mInvalidCharger; mLastInvalidCharger = mInvalidCharger;
} }
@@ -683,13 +687,17 @@ public final class BatteryService extends SystemService {
intent.putExtra(BatteryManager.EXTRA_SCALE, BATTERY_SCALE); intent.putExtra(BatteryManager.EXTRA_SCALE, BATTERY_SCALE);
intent.putExtra(BatteryManager.EXTRA_ICON_SMALL, icon); intent.putExtra(BatteryManager.EXTRA_ICON_SMALL, icon);
intent.putExtra(BatteryManager.EXTRA_PLUGGED, mPlugType); intent.putExtra(BatteryManager.EXTRA_PLUGGED, mPlugType);
intent.putExtra(BatteryManager.EXTRA_VOLTAGE, mHealthInfo.batteryVoltage); intent.putExtra(BatteryManager.EXTRA_VOLTAGE, mHealthInfo.batteryVoltageMillivolts);
intent.putExtra(BatteryManager.EXTRA_TEMPERATURE, mHealthInfo.batteryTemperature); intent.putExtra(
BatteryManager.EXTRA_TEMPERATURE, mHealthInfo.batteryTemperatureTenthsCelsius);
intent.putExtra(BatteryManager.EXTRA_TECHNOLOGY, mHealthInfo.batteryTechnology); intent.putExtra(BatteryManager.EXTRA_TECHNOLOGY, mHealthInfo.batteryTechnology);
intent.putExtra(BatteryManager.EXTRA_INVALID_CHARGER, mInvalidCharger); intent.putExtra(BatteryManager.EXTRA_INVALID_CHARGER, mInvalidCharger);
intent.putExtra(BatteryManager.EXTRA_MAX_CHARGING_CURRENT, mHealthInfo.maxChargingCurrent); intent.putExtra(
intent.putExtra(BatteryManager.EXTRA_MAX_CHARGING_VOLTAGE, mHealthInfo.maxChargingVoltage); BatteryManager.EXTRA_MAX_CHARGING_CURRENT, mHealthInfo.maxChargingCurrentMicroamps);
intent.putExtra(BatteryManager.EXTRA_CHARGE_COUNTER, mHealthInfo.batteryChargeCounter); intent.putExtra(
BatteryManager.EXTRA_MAX_CHARGING_VOLTAGE,
mHealthInfo.maxChargingVoltageMicrovolts);
intent.putExtra(BatteryManager.EXTRA_CHARGE_COUNTER, mHealthInfo.batteryChargeCounterUah);
if (DEBUG) { if (DEBUG) {
Slog.d(TAG, "Sending ACTION_BATTERY_CHANGED. scale:" + BATTERY_SCALE Slog.d(TAG, "Sending ACTION_BATTERY_CHANGED. scale:" + BATTERY_SCALE
+ ", info:" + mHealthInfo.toString()); + ", info:" + mHealthInfo.toString());
@@ -709,9 +717,9 @@ public final class BatteryService extends SystemService {
event.putBoolean(BatteryManager.EXTRA_BATTERY_LOW, mSentLowBatteryBroadcast); event.putBoolean(BatteryManager.EXTRA_BATTERY_LOW, mSentLowBatteryBroadcast);
event.putInt(BatteryManager.EXTRA_SCALE, BATTERY_SCALE); event.putInt(BatteryManager.EXTRA_SCALE, BATTERY_SCALE);
event.putInt(BatteryManager.EXTRA_PLUGGED, mPlugType); event.putInt(BatteryManager.EXTRA_PLUGGED, mPlugType);
event.putInt(BatteryManager.EXTRA_VOLTAGE, mHealthInfo.batteryVoltage); event.putInt(BatteryManager.EXTRA_VOLTAGE, mHealthInfo.batteryVoltageMillivolts);
event.putInt(BatteryManager.EXTRA_TEMPERATURE, mHealthInfo.batteryTemperature); event.putInt(BatteryManager.EXTRA_TEMPERATURE, mHealthInfo.batteryTemperatureTenthsCelsius);
event.putInt(BatteryManager.EXTRA_CHARGE_COUNTER, mHealthInfo.batteryChargeCounter); event.putInt(BatteryManager.EXTRA_CHARGE_COUNTER, mHealthInfo.batteryChargeCounterUah);
event.putLong(BatteryManager.EXTRA_EVENT_TIMESTAMP, now); event.putLong(BatteryManager.EXTRA_EVENT_TIMESTAMP, now);
boolean queueWasEmpty = mBatteryLevelsEventQueue.isEmpty(); boolean queueWasEmpty = mBatteryLevelsEventQueue.isEmpty();
@@ -903,7 +911,7 @@ public final class BatteryService extends SystemService {
} }
try { try {
if (!mUpdatesStopped) { if (!mUpdatesStopped) {
copy(mLastHealthInfo, mHealthInfo); copyV1Battery(mLastHealthInfo, mHealthInfo);
} }
boolean update = true; boolean update = true;
switch (key) { switch (key) {
@@ -926,10 +934,10 @@ public final class BatteryService extends SystemService {
mHealthInfo.batteryLevel = Integer.parseInt(value); mHealthInfo.batteryLevel = Integer.parseInt(value);
break; break;
case "counter": case "counter":
mHealthInfo.batteryChargeCounter = Integer.parseInt(value); mHealthInfo.batteryChargeCounterUah = Integer.parseInt(value);
break; break;
case "temp": case "temp":
mHealthInfo.batteryTemperature = Integer.parseInt(value); mHealthInfo.batteryTemperatureTenthsCelsius = Integer.parseInt(value);
break; break;
case "invalid": case "invalid":
mInvalidCharger = Integer.parseInt(value); mInvalidCharger = Integer.parseInt(value);
@@ -973,7 +981,7 @@ public final class BatteryService extends SystemService {
private void setChargerAcOnline(boolean online, boolean forceUpdate) { private void setChargerAcOnline(boolean online, boolean forceUpdate) {
if (!mUpdatesStopped) { if (!mUpdatesStopped) {
copy(mLastHealthInfo, mHealthInfo); copyV1Battery(mLastHealthInfo, mHealthInfo);
} }
mHealthInfo.chargerAcOnline = online; mHealthInfo.chargerAcOnline = online;
mUpdatesStopped = true; mUpdatesStopped = true;
@@ -982,7 +990,7 @@ public final class BatteryService extends SystemService {
private void setBatteryLevel(int level, boolean forceUpdate) { private void setBatteryLevel(int level, boolean forceUpdate) {
if (!mUpdatesStopped) { if (!mUpdatesStopped) {
copy(mLastHealthInfo, mHealthInfo); copyV1Battery(mLastHealthInfo, mHealthInfo);
} }
mHealthInfo.batteryLevel = level; mHealthInfo.batteryLevel = level;
mUpdatesStopped = true; mUpdatesStopped = true;
@@ -991,7 +999,7 @@ public final class BatteryService extends SystemService {
private void unplugBattery(boolean forceUpdate, PrintWriter pw) { private void unplugBattery(boolean forceUpdate, PrintWriter pw) {
if (!mUpdatesStopped) { if (!mUpdatesStopped) {
copy(mLastHealthInfo, mHealthInfo); copyV1Battery(mLastHealthInfo, mHealthInfo);
} }
mHealthInfo.chargerAcOnline = false; mHealthInfo.chargerAcOnline = false;
mHealthInfo.chargerUsbOnline = false; mHealthInfo.chargerUsbOnline = false;
@@ -1003,7 +1011,7 @@ public final class BatteryService extends SystemService {
private void resetBattery(boolean forceUpdate, @Nullable PrintWriter pw) { private void resetBattery(boolean forceUpdate, @Nullable PrintWriter pw) {
if (mUpdatesStopped) { if (mUpdatesStopped) {
mUpdatesStopped = false; mUpdatesStopped = false;
copy(mHealthInfo, mLastHealthInfo); copyV1Battery(mHealthInfo, mLastHealthInfo);
Binder.withCleanCallingIdentity(() -> processValuesLocked(forceUpdate, pw)); Binder.withCleanCallingIdentity(() -> processValuesLocked(forceUpdate, pw));
} }
if (mBatteryInputSuspended) { if (mBatteryInputSuspended) {
@@ -1038,16 +1046,16 @@ public final class BatteryService extends SystemService {
pw.println(" AC powered: " + mHealthInfo.chargerAcOnline); pw.println(" AC powered: " + mHealthInfo.chargerAcOnline);
pw.println(" USB powered: " + mHealthInfo.chargerUsbOnline); pw.println(" USB powered: " + mHealthInfo.chargerUsbOnline);
pw.println(" Wireless powered: " + mHealthInfo.chargerWirelessOnline); pw.println(" Wireless powered: " + mHealthInfo.chargerWirelessOnline);
pw.println(" Max charging current: " + mHealthInfo.maxChargingCurrent); pw.println(" Max charging current: " + mHealthInfo.maxChargingCurrentMicroamps);
pw.println(" Max charging voltage: " + mHealthInfo.maxChargingVoltage); pw.println(" Max charging voltage: " + mHealthInfo.maxChargingVoltageMicrovolts);
pw.println(" Charge counter: " + mHealthInfo.batteryChargeCounter); pw.println(" Charge counter: " + mHealthInfo.batteryChargeCounterUah);
pw.println(" status: " + mHealthInfo.batteryStatus); pw.println(" status: " + mHealthInfo.batteryStatus);
pw.println(" health: " + mHealthInfo.batteryHealth); pw.println(" health: " + mHealthInfo.batteryHealth);
pw.println(" present: " + mHealthInfo.batteryPresent); pw.println(" present: " + mHealthInfo.batteryPresent);
pw.println(" level: " + mHealthInfo.batteryLevel); pw.println(" level: " + mHealthInfo.batteryLevel);
pw.println(" scale: " + BATTERY_SCALE); pw.println(" scale: " + BATTERY_SCALE);
pw.println(" voltage: " + mHealthInfo.batteryVoltage); pw.println(" voltage: " + mHealthInfo.batteryVoltageMillivolts);
pw.println(" temperature: " + mHealthInfo.batteryTemperature); pw.println(" temperature: " + mHealthInfo.batteryTemperatureTenthsCelsius);
pw.println(" technology: " + mHealthInfo.batteryTechnology); pw.println(" technology: " + mHealthInfo.batteryTechnology);
} else { } else {
Shell shell = new Shell(); Shell shell = new Shell();
@@ -1070,16 +1078,23 @@ public final class BatteryService extends SystemService {
batteryPluggedValue = OsProtoEnums.BATTERY_PLUGGED_WIRELESS; batteryPluggedValue = OsProtoEnums.BATTERY_PLUGGED_WIRELESS;
} }
proto.write(BatteryServiceDumpProto.PLUGGED, batteryPluggedValue); proto.write(BatteryServiceDumpProto.PLUGGED, batteryPluggedValue);
proto.write(BatteryServiceDumpProto.MAX_CHARGING_CURRENT, mHealthInfo.maxChargingCurrent); proto.write(
proto.write(BatteryServiceDumpProto.MAX_CHARGING_VOLTAGE, mHealthInfo.maxChargingVoltage); BatteryServiceDumpProto.MAX_CHARGING_CURRENT,
proto.write(BatteryServiceDumpProto.CHARGE_COUNTER, mHealthInfo.batteryChargeCounter); mHealthInfo.maxChargingCurrentMicroamps);
proto.write(
BatteryServiceDumpProto.MAX_CHARGING_VOLTAGE,
mHealthInfo.maxChargingVoltageMicrovolts);
proto.write(
BatteryServiceDumpProto.CHARGE_COUNTER, mHealthInfo.batteryChargeCounterUah);
proto.write(BatteryServiceDumpProto.STATUS, mHealthInfo.batteryStatus); proto.write(BatteryServiceDumpProto.STATUS, mHealthInfo.batteryStatus);
proto.write(BatteryServiceDumpProto.HEALTH, mHealthInfo.batteryHealth); proto.write(BatteryServiceDumpProto.HEALTH, mHealthInfo.batteryHealth);
proto.write(BatteryServiceDumpProto.IS_PRESENT, mHealthInfo.batteryPresent); proto.write(BatteryServiceDumpProto.IS_PRESENT, mHealthInfo.batteryPresent);
proto.write(BatteryServiceDumpProto.LEVEL, mHealthInfo.batteryLevel); proto.write(BatteryServiceDumpProto.LEVEL, mHealthInfo.batteryLevel);
proto.write(BatteryServiceDumpProto.SCALE, BATTERY_SCALE); proto.write(BatteryServiceDumpProto.SCALE, BATTERY_SCALE);
proto.write(BatteryServiceDumpProto.VOLTAGE, mHealthInfo.batteryVoltage); proto.write(BatteryServiceDumpProto.VOLTAGE, mHealthInfo.batteryVoltageMillivolts);
proto.write(BatteryServiceDumpProto.TEMPERATURE, mHealthInfo.batteryTemperature); proto.write(
BatteryServiceDumpProto.TEMPERATURE,
mHealthInfo.batteryTemperatureTenthsCelsius);
proto.write(BatteryServiceDumpProto.TECHNOLOGY, mHealthInfo.batteryTechnology); proto.write(BatteryServiceDumpProto.TECHNOLOGY, mHealthInfo.batteryTechnology);
} }
proto.flush(); proto.flush();
@@ -1207,14 +1222,14 @@ public final class BatteryService extends SystemService {
@Override @Override
public int getBatteryChargeCounter() { public int getBatteryChargeCounter() {
synchronized (mLock) { synchronized (mLock) {
return mHealthInfo.batteryChargeCounter; return mHealthInfo.batteryChargeCounterUah;
} }
} }
@Override @Override
public int getBatteryFullCharge() { public int getBatteryFullCharge() {
synchronized (mLock) { synchronized (mLock) {
return mHealthInfo.batteryFullCharge; return mHealthInfo.batteryFullChargeUah;
} }
} }

View File

@@ -16,6 +16,8 @@
package com.android.server.health; package com.android.server.health;
import static android.hardware.health.Translate.h2aTranslate;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.hardware.health.V2_0.IHealth; import android.hardware.health.V2_0.IHealth;
import android.hardware.health.V2_0.Result; import android.hardware.health.V2_0.Result;
@@ -64,12 +66,12 @@ class HealthHalCallbackHidl extends IHealthInfoCallback.Stub
propsLatest.batteryChargeTimeToFullNowSeconds = propsLatest.batteryChargeTimeToFullNowSeconds =
Constants.BATTERY_CHARGE_TIME_TO_FULL_NOW_SECONDS_UNSUPPORTED; Constants.BATTERY_CHARGE_TIME_TO_FULL_NOW_SECONDS_UNSUPPORTED;
mCallback.update(propsLatest); mCallback.update(h2aTranslate(propsLatest));
} }
@Override @Override
public void healthInfoChanged_2_1(android.hardware.health.V2_1.HealthInfo props) { public void healthInfoChanged_2_1(android.hardware.health.V2_1.HealthInfo props) {
mCallback.update(props); mCallback.update(h2aTranslate(props));
} }
// on new service registered // on new service registered

View File

@@ -27,6 +27,5 @@ public interface HealthInfoCallback {
* *
* @param props the new health info. * @param props the new health info.
*/ */
// TODO(b/177269435): AIDL void update(android.hardware.health.HealthInfo props);
void update(android.hardware.health.V2_1.HealthInfo props);
} }

View File

@@ -68,8 +68,7 @@ public abstract class HealthServiceWrapper {
* service-specific error when calling {@code getHealthInfo}, e.g. it is unsupported. * service-specific error when calling {@code getHealthInfo}, e.g. it is unsupported.
* @throws RemoteException for any transaction-level errors * @throws RemoteException for any transaction-level errors
*/ */
// TODO(b/177269435): AIDL public abstract android.hardware.health.HealthInfo getHealthInfo() throws RemoteException;
public abstract android.hardware.health.V1_0.HealthInfo getHealthInfo() throws RemoteException;
/** /**
* Create a new HealthServiceWrapper instance. * Create a new HealthServiceWrapper instance.

View File

@@ -16,9 +16,11 @@
package com.android.server.health; package com.android.server.health;
import static android.hardware.health.Translate.h2aTranslate;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.hardware.health.V1_0.HealthInfo; import android.hardware.health.HealthInfo;
import android.hardware.health.V2_0.IHealth; import android.hardware.health.V2_0.IHealth;
import android.hardware.health.V2_0.Result; import android.hardware.health.V2_0.Result;
import android.hidl.manager.V1_0.IServiceManager; import android.hidl.manager.V1_0.IServiceManager;
@@ -155,7 +157,7 @@ final class HealthServiceWrapperHidl extends HealthServiceWrapper {
service.getHealthInfo( service.getHealthInfo(
(result, value) -> { (result, value) -> {
if (result == Result.SUCCESS) { if (result == Result.SUCCESS) {
ret.value = value.legacy; ret.value = h2aTranslate(value.legacy);
} }
}); });
return ret.value; return ret.value;

View File

@@ -50,4 +50,36 @@ public class Utils {
dst.batteryChargeCounter = src.batteryChargeCounter; dst.batteryChargeCounter = src.batteryChargeCounter;
dst.batteryTechnology = src.batteryTechnology; dst.batteryTechnology = src.batteryTechnology;
} }
/**
* Copy battery fields of {@link android.hardware.health.HealthInfo} V1. This excludes
* non-battery fields like {@link android.hardware.health.HealthInfo#diskStats diskStats} and
* {@link android.hardware.health.HealthInfo#storageInfos storageInfos}
*
* @param dst destination
* @param src source
*/
public static void copyV1Battery(
android.hardware.health.HealthInfo dst, android.hardware.health.HealthInfo src) {
dst.chargerAcOnline = src.chargerAcOnline;
dst.chargerUsbOnline = src.chargerUsbOnline;
dst.chargerWirelessOnline = src.chargerWirelessOnline;
dst.maxChargingCurrentMicroamps = src.maxChargingCurrentMicroamps;
dst.maxChargingVoltageMicrovolts = src.maxChargingVoltageMicrovolts;
dst.batteryStatus = src.batteryStatus;
dst.batteryHealth = src.batteryHealth;
dst.batteryPresent = src.batteryPresent;
dst.batteryLevel = src.batteryLevel;
dst.batteryVoltageMillivolts = src.batteryVoltageMillivolts;
dst.batteryTemperatureTenthsCelsius = src.batteryTemperatureTenthsCelsius;
dst.batteryCurrentMicroamps = src.batteryCurrentMicroamps;
dst.batteryCycleCount = src.batteryCycleCount;
dst.batteryFullChargeUah = src.batteryFullChargeUah;
dst.batteryChargeCounterUah = src.batteryChargeCounterUah;
dst.batteryTechnology = src.batteryTechnology;
dst.batteryCurrentAverageMicroamps = src.batteryCurrentAverageMicroamps;
dst.batteryCapacityLevel = src.batteryCapacityLevel;
dst.batteryChargeTimeToFullNowSeconds = src.batteryChargeTimeToFullNowSeconds;
dst.batteryFullChargeDesignCapacityUah = src.batteryFullChargeDesignCapacityUah;
}
} }

View File

@@ -3977,7 +3977,7 @@ public class StatsPullAtomService extends SystemService {
if (mHealthService == null) { if (mHealthService == null) {
return StatsManager.PULL_SKIP; return StatsManager.PULL_SKIP;
} }
android.hardware.health.V1_0.HealthInfo healthInfo; android.hardware.health.HealthInfo healthInfo;
try { try {
healthInfo = mHealthService.getHealthInfo(); healthInfo = mHealthService.getHealthInfo();
} catch (RemoteException | IllegalStateException e) { } catch (RemoteException | IllegalStateException e) {
@@ -3993,13 +3993,13 @@ public class StatsPullAtomService extends SystemService {
pulledValue = healthInfo.batteryLevel; pulledValue = healthInfo.batteryLevel;
break; break;
case FrameworkStatsLog.REMAINING_BATTERY_CAPACITY: case FrameworkStatsLog.REMAINING_BATTERY_CAPACITY:
pulledValue = healthInfo.batteryChargeCounter; pulledValue = healthInfo.batteryChargeCounterUah;
break; break;
case FrameworkStatsLog.FULL_BATTERY_CAPACITY: case FrameworkStatsLog.FULL_BATTERY_CAPACITY:
pulledValue = healthInfo.batteryFullCharge; pulledValue = healthInfo.batteryFullChargeUah;
break; break;
case FrameworkStatsLog.BATTERY_VOLTAGE: case FrameworkStatsLog.BATTERY_VOLTAGE:
pulledValue = healthInfo.batteryVoltage; pulledValue = healthInfo.batteryVoltageMillivolts;
break; break;
case FrameworkStatsLog.BATTERY_CYCLE_COUNT: case FrameworkStatsLog.BATTERY_CYCLE_COUNT:
pulledValue = healthInfo.batteryCycleCount; pulledValue = healthInfo.batteryCycleCount;