Debian Codegraph @

core/java/android/hardware/input/InputDeviceBatteryState.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 * Battery implementation for input devices.
26 *
27 * @hide
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 }