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

Commit 92396128 authored by Imre Sunyi's avatar Imre Sunyi Committed by Jean-Baptiste Queru
Browse files

Support showing "Cold" battery health.

The Linux kernel supports reporting "cold" battery health to sysfs.
Android framework has not implemented this and it defaults to "unknown"
This adds handling the cold battery health.

Change-Id: Idcc156aae6aabce73391081143f79d052edf332e
parent bd1454f5
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -114001,6 +114001,17 @@
 visibility="public"
>
</constructor>
<field name="BATTERY_HEALTH_COLD"
 type="int"
 transient="false"
 volatile="false"
 value="7"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="BATTERY_HEALTH_DEAD"
 type="int"
 transient="false"
+1 −0
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ public class BatteryManager {
    public static final int BATTERY_HEALTH_DEAD = 4;
    public static final int BATTERY_HEALTH_OVER_VOLTAGE = 5;
    public static final int BATTERY_HEALTH_UNSPECIFIED_FAILURE = 6;
    public static final int BATTERY_HEALTH_COLD = 7;

    // values of the "plugged" field in the ACTION_BATTERY_CHANGED intent.
    // These must be powers of 2.
+5 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ struct BatteryManagerConstants {
    jint healthDead;
    jint healthOverVoltage;
    jint healthUnspecifiedFailure;
    jint healthCold;
};
static BatteryManagerConstants gConstants;

@@ -104,6 +105,7 @@ static jint getBatteryStatus(const char* status)
static jint getBatteryHealth(const char* status)
{
    switch (status[0]) {
        case 'C': return gConstants.healthCold;         // Cold
        case 'D': return gConstants.healthDead;         // Dead
        case 'G': return gConstants.healthGood;         // Good
        case 'O': {
@@ -390,6 +392,9 @@ int register_android_server_BatteryService(JNIEnv* env)
    gConstants.healthUnspecifiedFailure = env->GetStaticIntField(clazz, 
            env->GetStaticFieldID(clazz, "BATTERY_HEALTH_UNSPECIFIED_FAILURE", "I"));
    
    gConstants.healthCold = env->GetStaticIntField(clazz,
            env->GetStaticFieldID(clazz, "BATTERY_HEALTH_COLD", "I"));

    return jniRegisterNativeMethods(env, "com/android/server/BatteryService", sMethods, NELEM(sMethods));
}