| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.hardware.input; |
| 18 |
|
| 19 |
import static android.os.BatteryManager.BATTERY_STATUS_UNKNOWN; |
| 20 |
import static android.os.IInputConstants.INVALID_BATTERY_CAPACITY; |
| 21 |
|
| 22 |
import android.hardware.BatteryState; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public final class InputDeviceBatteryState extends BatteryState { |
| 30 |
private static final float NULL_BATTERY_CAPACITY = Float.NaN; |
| 31 |
|
| 32 |
private final InputManager mInputManager; |
| 33 |
private final int mDeviceId; |
| 34 |
private final boolean mHasBattery; |
| 35 |
|
| 36 |
InputDeviceBatteryState(InputManager inputManager, int deviceId, boolean hasBattery) { |
| 37 |
mInputManager = inputManager; |
| 38 |
mDeviceId = deviceId; |
| 39 |
mHasBattery = hasBattery; |
| 40 |
} |
| 41 |
|
| 42 |
@Override |
| 43 |
public boolean isPresent() { |
| 44 |
return mHasBattery; |
| 45 |
} |
| 46 |
|
| 47 |
@Override |
| 48 |
public int getStatus() { |
| 49 |
if (!mHasBattery) { |
| 50 |
return BATTERY_STATUS_UNKNOWN; |
| 51 |
} |
| 52 |
return mInputManager.getBatteryStatus(mDeviceId); |
| 53 |
} |
| 54 |
|
| 55 |
@Override |
| 56 |
public float getCapacity() { |
| 57 |
if (mHasBattery) { |
| 58 |
int capacity = mInputManager.getBatteryCapacity(mDeviceId); |
| 59 |
if (capacity != INVALID_BATTERY_CAPACITY) { |
| 60 |
return (float) capacity / 100.0f; |
| 61 |
} |
| 62 |
} |
| 63 |
return NULL_BATTERY_CAPACITY; |
| 64 |
} |
| 65 |
} |