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 { package android.hardware {
public abstract class Battery { public abstract class BatteryState {
ctor public Battery(); ctor public BatteryState();
method @FloatRange(from=-1.0F, to=1.0f) public abstract float getCapacity(); method @FloatRange(from=-1.0F, to=1.0f) public abstract float getCapacity();
method public abstract int getStatus(); 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_CHARGING = 2; // 0x2
field public static final int STATUS_DISCHARGING = 3; // 0x3 field public static final int STATUS_DISCHARGING = 3; // 0x3
field public static final int STATUS_FULL = 5; // 0x5 field public static final int STATUS_FULL = 5; // 0x5
@@ -47130,7 +47130,7 @@ package android.view {
public final class InputDevice implements android.os.Parcelable { public final class InputDevice implements android.os.Parcelable {
method public int describeContents(); method public int describeContents();
method @NonNull public android.hardware.Battery getBattery(); method @NonNull public android.hardware.BatteryState getBatteryState();
method public int getControllerNumber(); method public int getControllerNumber();
method public String getDescriptor(); method public String getDescriptor();
method public static android.view.InputDevice getDevice(int); method public static android.view.InputDevice getDevice(int);

View File

@@ -24,9 +24,9 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; 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 */ /** @hide */
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = { "STATUS_" }, value = { @IntDef(prefix = { "STATUS_" }, value = {
@@ -55,7 +55,7 @@ public abstract class Battery {
* *
* @return True if the hardware has a battery, else false. * @return True if the hardware has a battery, else false.
*/ */
public abstract boolean hasBattery(); public abstract boolean isPresent();
/** /**
* Get the battery status. * 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 * 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. * @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.BatteryManager.BATTERY_STATUS_UNKNOWN;
import static android.os.IInputConstants.INVALID_BATTERY_CAPACITY; import static android.os.IInputConstants.INVALID_BATTERY_CAPACITY;
import android.hardware.Battery; import android.hardware.BatteryState;
/** /**
* Battery implementation for input devices. * Battery implementation for input devices.
* *
* @hide * @hide
*/ */
public final class InputDeviceBattery extends Battery { public final class InputDeviceBatteryState extends BatteryState {
private static final float NULL_BATTERY_CAPACITY = -1.0f; private static final float NULL_BATTERY_CAPACITY = Float.NaN;
private final InputManager mInputManager; private final InputManager mInputManager;
private final int mDeviceId; private final int mDeviceId;
private final boolean mHasBattery; private final boolean mHasBattery;
InputDeviceBattery(InputManager inputManager, int deviceId, boolean hasBattery) { InputDeviceBatteryState(InputManager inputManager, int deviceId, boolean hasBattery) {
mInputManager = inputManager; mInputManager = inputManager;
mDeviceId = deviceId; mDeviceId = deviceId;
mHasBattery = hasBattery; mHasBattery = hasBattery;
} }
@Override @Override
public boolean hasBattery() { public boolean isPresent() {
return mHasBattery; 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. * @return The battery, never null.
* @hide * @hide
*/ */
public InputDeviceBattery getInputDeviceBattery(int deviceId, boolean hasBattery) { public InputDeviceBatteryState getInputDeviceBatteryState(int deviceId, boolean hasBattery) {
return new InputDeviceBattery(this, deviceId, hasBattery); return new InputDeviceBatteryState(this, deviceId, hasBattery);
} }
/** /**

View File

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

View File

@@ -22,7 +22,7 @@ import android.annotation.RequiresPermission;
import android.annotation.TestApi; import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context; import android.content.Context;
import android.hardware.Battery; import android.hardware.BatteryState;
import android.hardware.SensorManager; import android.hardware.SensorManager;
import android.hardware.input.InputDeviceIdentifier; import android.hardware.input.InputDeviceIdentifier;
import android.hardware.input.InputManager; import android.hardware.input.InputManager;
@@ -88,7 +88,7 @@ public final class InputDevice implements Parcelable {
private SensorManager mSensorManager; private SensorManager mSensorManager;
@GuardedBy("mMotionRanges") @GuardedBy("mMotionRanges")
private Battery mBattery; private BatteryState mBatteryState;
@GuardedBy("mMotionRanges") @GuardedBy("mMotionRanges")
private LightsManager mLightsManager; 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. * 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. * present.
* *
* @return The battery object associated with the device, never null. * @return The battery object associated with the device, never null.
*/ */
@NonNull @NonNull
public Battery getBattery() { public BatteryState getBatteryState() {
if (mBattery == null) { if (mBatteryState == null) {
mBattery = InputManager.getInstance().getInputDeviceBattery(mId, mHasBattery); mBatteryState = InputManager.getInstance().getInputDeviceBatteryState(mId, mHasBattery);
} }
return mBattery; return mBatteryState;
} }
/** /**