Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 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 | #include "../Macros.h" |
| 18 | |
| 19 | #include "BatteryInputMapper.h" |
| 20 | |
| 21 | namespace android { |
| 22 | |
| 23 | BatteryInputMapper::BatteryInputMapper(InputDeviceContext& deviceContext) |
| 24 | : InputMapper(deviceContext) {} |
| 25 | |
| 26 | uint32_t BatteryInputMapper::getSources() { |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | void BatteryInputMapper::populateDeviceInfo(InputDeviceInfo* info) { |
| 31 | InputMapper::populateDeviceInfo(info); |
| 32 | |
| 33 | info->setHasBattery(true); |
| 34 | } |
| 35 | |
| 36 | void BatteryInputMapper::process(const RawEvent* rawEvent) {} |
| 37 | |
| 38 | std::optional<int32_t> BatteryInputMapper::getBatteryCapacity() { |
| 39 | return getDeviceContext().getBatteryCapacity(); |
| 40 | } |
| 41 | |
| 42 | std::optional<int32_t> BatteryInputMapper::getBatteryStatus() { |
| 43 | return getDeviceContext().getBatteryStatus(); |
| 44 | } |
| 45 | |
| 46 | void BatteryInputMapper::dump(std::string& dump) { |
| 47 | dump += INDENT2 "Battery Input Mapper:\n"; |
| 48 | dump += getBatteryCapacity().has_value() |
| 49 | ? StringPrintf(INDENT3 "Capacity: %d\n", getBatteryCapacity().value()) |
| 50 | : StringPrintf(INDENT3 "Capacity: Unknown"); |
| 51 | |
| 52 | std::string status; |
| 53 | switch (getBatteryStatus().value_or(BATTERY_STATUS_UNKNOWN)) { |
| 54 | case BATTERY_STATUS_CHARGING: |
| 55 | status = "Charging"; |
| 56 | break; |
| 57 | case BATTERY_STATUS_DISCHARGING: |
| 58 | status = "Discharging"; |
| 59 | break; |
| 60 | case BATTERY_STATUS_NOT_CHARGING: |
| 61 | status = "Not charging"; |
| 62 | break; |
| 63 | case BATTERY_STATUS_FULL: |
| 64 | status = "Full"; |
| 65 | break; |
| 66 | default: |
| 67 | status = "Unknown"; |
| 68 | } |
| 69 | dump += StringPrintf(INDENT3 "Status: %s\n", status.c_str()); |
| 70 | } |
| 71 | |
| 72 | } // namespace android |