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

Commit 79132bde authored by David Anderson's avatar David Anderson Committed by Android (Google) Code Review
Browse files

Merge "BatteryManager: Add new battery properties from the Health V3 HAL." into main

parents bc87e322 da893ff4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -31851,6 +31851,7 @@ package android.os {
    method public long computeChargeTimeRemaining();
    method public int getIntProperty(int);
    method public long getLongProperty(int);
    method @FlaggedApi("android.os.battery_part_status_api") @Nullable public String getStringProperty(int);
    method public boolean isCharging();
    field public static final String ACTION_CHARGING = "android.os.action.CHARGING";
    field public static final String ACTION_DISCHARGING = "android.os.action.DISCHARGING";
+5 −0
Original line number Diff line number Diff line
@@ -10044,12 +10044,17 @@ package android.os {
    field @RequiresPermission(android.Manifest.permission.BATTERY_STATS) public static final int BATTERY_PROPERTY_CHARGING_POLICY = 9; // 0x9
    field @RequiresPermission(android.Manifest.permission.BATTERY_STATS) public static final int BATTERY_PROPERTY_FIRST_USAGE_DATE = 8; // 0x8
    field @RequiresPermission(android.Manifest.permission.BATTERY_STATS) public static final int BATTERY_PROPERTY_MANUFACTURING_DATE = 7; // 0x7
    field @FlaggedApi("android.os.battery_part_status_api") @RequiresPermission(android.Manifest.permission.BATTERY_STATS) public static final int BATTERY_PROPERTY_PART_STATUS = 12; // 0xc
    field @FlaggedApi("android.os.battery_part_status_api") @RequiresPermission(android.Manifest.permission.BATTERY_STATS) public static final int BATTERY_PROPERTY_SERIAL_NUMBER = 11; // 0xb
    field public static final int CHARGING_POLICY_ADAPTIVE_AC = 3; // 0x3
    field public static final int CHARGING_POLICY_ADAPTIVE_AON = 2; // 0x2
    field public static final int CHARGING_POLICY_ADAPTIVE_LONGLIFE = 4; // 0x4
    field public static final int CHARGING_POLICY_DEFAULT = 1; // 0x1
    field public static final String EXTRA_EVENTS = "android.os.extra.EVENTS";
    field public static final String EXTRA_EVENT_TIMESTAMP = "android.os.extra.EVENT_TIMESTAMP";
    field @FlaggedApi("android.os.battery_part_status_api") public static final int PART_STATUS_ORIGINAL = 1; // 0x1
    field @FlaggedApi("android.os.battery_part_status_api") public static final int PART_STATUS_REPLACED = 2; // 0x2
    field @FlaggedApi("android.os.battery_part_status_api") public static final int PART_STATUS_UNSUPPORTED = 0; // 0x0
  }
  public final class BatterySaverPolicyConfig implements android.os.Parcelable {
+87 −0
Original line number Diff line number Diff line
@@ -17,9 +17,11 @@
package android.os;

import static android.os.Flags.FLAG_STATE_OF_HEALTH_PUBLIC;
import static android.os.Flags.FLAG_BATTERY_PART_STATUS_API;

import android.Manifest.permission;
import android.annotation.FlaggedApi;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
@@ -236,6 +238,31 @@ public class BatteryManager {
    public static final int CHARGING_POLICY_ADAPTIVE_LONGLIFE =
                                            OsProtoEnums.CHARGING_POLICY_ADAPTIVE_LONGLIFE; // = 4

    // values for "battery part status" property
    /**
     * Battery part status is not supported.
     * @hide
     */
    @SystemApi
    @FlaggedApi(FLAG_BATTERY_PART_STATUS_API)
    public static final int PART_STATUS_UNSUPPORTED = 0;

    /**
     * Battery is the original device battery.
     * @hide
     */
    @SystemApi
    @FlaggedApi(FLAG_BATTERY_PART_STATUS_API)
    public static final int PART_STATUS_ORIGINAL = 1;

    /**
     * Battery has been replaced.
     * @hide
     */
    @SystemApi
    @FlaggedApi(FLAG_BATTERY_PART_STATUS_API)
    public static final int PART_STATUS_REPLACED = 2;

    /** @hide */
    @SuppressLint("UnflaggedApi") // TestApi without associated feature.
    @TestApi
@@ -366,6 +393,32 @@ public class BatteryManager {
    @FlaggedApi(FLAG_STATE_OF_HEALTH_PUBLIC)
    public static final int BATTERY_PROPERTY_STATE_OF_HEALTH = 10;

    /**
     * Battery part serial number.
     *
     * <p class="note">
     * The sender must hold the {@link android.Manifest.permission#BATTERY_STATS} permission.
     *
     * @hide
     */
    @RequiresPermission(permission.BATTERY_STATS)
    @SystemApi
    @FlaggedApi(FLAG_BATTERY_PART_STATUS_API)
    public static final int BATTERY_PROPERTY_SERIAL_NUMBER = 11;

    /**
     * Battery part status from a BATTERY_PART_STATUS_* value.
     *
     * <p class="note">
     * The sender must hold the {@link android.Manifest.permission#BATTERY_STATS} permission.
     *
     * @hide
     */
    @RequiresPermission(permission.BATTERY_STATS)
    @SystemApi
    @FlaggedApi(FLAG_BATTERY_PART_STATUS_API)
    public static final int BATTERY_PROPERTY_PART_STATUS = 12;

    private final Context mContext;
    private final IBatteryStats mBatteryStats;
    private final IBatteryPropertiesRegistrar mBatteryPropertiesRegistrar;
@@ -430,6 +483,25 @@ public class BatteryManager {
        return ret;
    }

    /**
     * Same as queryProperty, but for strings.
     */
    private String queryStringProperty(int id) {
        if (mBatteryPropertiesRegistrar == null) {
            return null;
        }

        try {
            BatteryProperty prop = new BatteryProperty();
            if (mBatteryPropertiesRegistrar.getProperty(id, prop) == 0) {
                return prop.getString();
            }
            return null;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Return the value of a battery property of integer type.
     *
@@ -463,6 +535,21 @@ public class BatteryManager {
        return queryProperty(id);
    }

    /**
     * Return the value of a battery property of String type. If the
     * platform does not provide the property queried, this value will
     * be null.
     *
     * @param id identifier of the requested property.
     *
     * @return the property value, or null if not supported.
     */
    @Nullable
    @FlaggedApi(FLAG_BATTERY_PART_STATUS_API)
    public String getStringProperty(int id) {
        return queryStringProperty(id);
    }

    /**
     * Return true if the plugType given is wired
     * @param plugType {@link #BATTERY_PLUGGED_AC}, {@link #BATTERY_PLUGGED_USB},
+16 −3
Original line number Diff line number Diff line
@@ -28,12 +28,14 @@ import android.os.Parcelable;
 */
public class BatteryProperty implements Parcelable {
    private long mValueLong;
    private String mValueString;

    /**
     * @hide
     */
    public BatteryProperty() {
        mValueLong = Long.MIN_VALUE;
        mValueString = null;
    }

    /**
@@ -43,6 +45,13 @@ public class BatteryProperty implements Parcelable {
        return mValueLong;
    }

    /**
     * @hide
     */
    public String getString() {
        return mValueString;
    }

    /**
     * @hide
     */
@@ -50,10 +59,12 @@ public class BatteryProperty implements Parcelable {
        mValueLong = val;
    }

    /*
     * Parcel read/write code must be kept in sync with
     * frameworks/native/services/batteryservice/BatteryProperty.cpp
    /**
     * @hide
     */
    public void setString(String val) {
        mValueString = val;
    }

    private BatteryProperty(Parcel p) {
        readFromParcel(p);
@@ -61,10 +72,12 @@ public class BatteryProperty implements Parcelable {

    public void readFromParcel(Parcel p) {
        mValueLong = p.readLong();
        mValueString = p.readString8();
    }

    public void writeToParcel(Parcel p, int flags) {
        p.writeLong(mValueLong);
        p.writeString8(mValueString);
    }

    public static final @android.annotation.NonNull Parcelable.Creator<BatteryProperty> CREATOR
+8 −0
Original line number Diff line number Diff line
@@ -106,3 +106,11 @@ flag {
    bug: "305311707"
    is_fixed_read_only: true
}

flag {
    name: "battery_part_status_api"
    namespace: "phoenix"
    description: "Feature flag for adding Health HAL v3 APIs."
    is_fixed_read_only: true
    bug: "309792384"
}
Loading