Merge "Rename Battery to BatteryState." into sc-dev

This commit is contained in:
TreeHugger Robot
2021-04-29 16:30:16 +00:00
committed by Android (Google) Code Review
6 changed files with 29 additions and 24 deletions

View File

@@ -17136,11 +17136,11 @@ package android.graphics.text {
package android.hardware {
public abstract class Battery {
ctor public Battery();
public abstract class BatteryState {
ctor public BatteryState();
method @FloatRange(from=-1.0F, to=1.0f) public abstract float getCapacity();
method public abstract int getStatus();
method public abstract boolean hasBattery();
method public abstract boolean isPresent();
field public static final int STATUS_CHARGING = 2; // 0x2
field public static final int STATUS_DISCHARGING = 3; // 0x3
field public static final int STATUS_FULL = 5; // 0x5
@@ -47130,7 +47130,7 @@ package android.view {
public final class InputDevice implements android.os.Parcelable {
method public int describeContents();
method @NonNull public android.hardware.Battery getBattery();
method @NonNull public android.hardware.BatteryState getBatteryState();
method public int getControllerNumber();
method public String getDescriptor();
method public static android.view.InputDevice getDevice(int);

View File

@@ -24,9 +24,9 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* The Battery class is a representation of a single battery on a device.
* The BatteryState class is a representation of a single battery on a device.
*/
public abstract class Battery {
public abstract class BatteryState {
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = { "STATUS_" }, value = {
@@ -55,7 +55,7 @@ public abstract class Battery {
*
* @return True if the hardware has a battery, else false.
*/
public abstract boolean hasBattery();
public abstract boolean isPresent();
/**
* Get the battery status.
@@ -66,7 +66,7 @@ public abstract class Battery {
/**
* Get remaining battery capacity as float percentage [0.0f, 1.0f] of total capacity
* Returns -1 when battery capacity can't be read.
* Returns NaN when battery capacity can't be read.
*
* @return the battery capacity.
*/

View File

@@ -19,28 +19,28 @@ package android.hardware.input;
import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN;
import static android.os.IInputConstants.INVALID_BATTERY_CAPACITY;
import android.hardware.Battery;
import android.hardware.BatteryState;
/**
* Battery implementation for input devices.
*
* @hide
*/
public final class InputDeviceBattery extends Battery {
private static final float NULL_BATTERY_CAPACITY = -1.0f;
public final class InputDeviceBatteryState extends BatteryState {
private static final float NULL_BATTERY_CAPACITY = Float.NaN;
private final InputManager mInputManager;
private final int mDeviceId;
private final boolean mHasBattery;
InputDeviceBattery(InputManager inputManager, int deviceId, boolean hasBattery) {
InputDeviceBatteryState(InputManager inputManager, int deviceId, boolean hasBattery) {
mInputManager = inputManager;
mDeviceId = deviceId;
mHasBattery = hasBattery;
}
@Override
public boolean hasBattery() {
public boolean isPresent() {
return mHasBattery;
}

View File

@@ -1571,12 +1571,12 @@ public final class InputManager {
}
/**
* Gets a battery object associated with an input device, assuming it has one.
* Gets a battery state object associated with an input device, assuming it has one.
* @return The battery, never null.
* @hide
*/
public InputDeviceBattery getInputDeviceBattery(int deviceId, boolean hasBattery) {
return new InputDeviceBattery(this, deviceId, hasBattery);
public InputDeviceBatteryState getInputDeviceBatteryState(int deviceId, boolean hasBattery) {
return new InputDeviceBatteryState(this, deviceId, hasBattery);
}
/**

View File

@@ -141,6 +141,11 @@ public final class Light implements Parcelable {
return mId;
}
@Override
public String toString() {
return "[Name=" + mName + " Id=" + mId + " Type=" + mType + " Ordinal=" + mOrdinal + "]";
}
/**
* Returns the id of the light.
*

View File

@@ -22,7 +22,7 @@ import android.annotation.RequiresPermission;
import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.hardware.Battery;
import android.hardware.BatteryState;
import android.hardware.SensorManager;
import android.hardware.input.InputDeviceIdentifier;
import android.hardware.input.InputManager;
@@ -88,7 +88,7 @@ public final class InputDevice implements Parcelable {
private SensorManager mSensorManager;
@GuardedBy("mMotionRanges")
private Battery mBattery;
private BatteryState mBatteryState;
@GuardedBy("mMotionRanges")
private LightsManager mLightsManager;
@@ -848,19 +848,19 @@ public final class InputDevice implements Parcelable {
}
/**
* Gets the battery object associated with the device, if there is one.
* Gets the battery state object associated with the device, if there is one.
* Even if the device does not have a battery, the result is never null.
* Use {@link Battery#hasBattery} to determine whether a battery is
* Use {@link BatteryState#isPresent} to determine whether a battery is
* present.
*
* @return The battery object associated with the device, never null.
*/
@NonNull
public Battery getBattery() {
if (mBattery == null) {
mBattery = InputManager.getInstance().getInputDeviceBattery(mId, mHasBattery);
public BatteryState getBatteryState() {
if (mBatteryState == null) {
mBatteryState = InputManager.getInstance().getInputDeviceBatteryState(mId, mHasBattery);
}
return mBattery;
return mBatteryState;
}
/**