1 /* 2 * Copyright (C) 2014 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.os; 18 19 import android.annotation.NonNull; 20 21 /** 22 * Battery manager local system service interface. 23 * 24 * @hide Only for use within the system server. 25 */ 26 public abstract class BatteryManagerInternal { 27 /** 28 * Returns true if the device is plugged into any of the specified plug types. 29 * 30 * This is a simple accessor that's safe to be called from any locks, but internally it may 31 * wait on the battery service lock. 32 */ isPowered(int plugTypeSet)33 public abstract boolean isPowered(int plugTypeSet); 34 35 /** 36 * Returns the current plug type. 37 * 38 * This is a simple accessor that's safe to be called from any locks, but internally it may 39 * wait on the battery service lock. 40 */ getPlugType()41 public abstract int getPlugType(); 42 43 /** 44 * Returns battery level as a percentage. 45 * 46 * This is a simple accessor that's safe to be called from any locks, but internally it may 47 * wait on the battery service lock. 48 */ getBatteryLevel()49 public abstract int getBatteryLevel(); 50 51 /** 52 * Returns battery health status as an integer representing the current battery health constant. 53 * 54 * This is a simple accessor that's safe to be called from any locks, but internally it may 55 * wait on the battery service lock. 56 */ getBatteryHealth()57 public abstract int getBatteryHealth(); 58 59 /** 60 * Instantaneous battery capacity in uA-h, as defined in the HealthInfo HAL struct. 61 * Please note apparently it could be bigger than {@link #getBatteryFullCharge}. 62 * 63 * This is a simple accessor that's safe to be called from any locks, but internally it may 64 * wait on the battery service lock. 65 * 66 * @see android.hardware.health.V1_0.HealthInfo#batteryChargeCounter 67 */ getBatteryChargeCounter()68 public abstract int getBatteryChargeCounter(); 69 70 /** 71 * Battery charge value when it is considered to be "full" in uA-h , as defined in the 72 * HealthInfo HAL struct. 73 * 74 * This is a simple accessor that's safe to be called from any locks, but internally it may 75 * wait on the battery service lock. 76 * 77 * @see android.hardware.health.V1_0.HealthInfo#batteryFullCharge 78 */ getBatteryFullCharge()79 public abstract int getBatteryFullCharge(); 80 81 /** 82 * Returns whether we currently consider the battery level to be low. 83 * 84 * This is a simple accessor that's safe to be called from any locks, but internally it may 85 * wait on the battery service lock. 86 */ getBatteryLevelLow()87 public abstract boolean getBatteryLevelLow(); 88 89 public interface ChargingPolicyChangeListener { onChargingPolicyChanged(int newPolicy)90 void onChargingPolicyChanged(int newPolicy); 91 } 92 93 /** 94 * Register a listener for changes to {@link BatteryManager#BATTERY_PROPERTY_CHARGING_POLICY}. 95 * The charging policy can't be added to the BATTERY_CHANGED intent because it requires 96 * the BATTERY_STATS permission. 97 */ registerChargingPolicyChangeListener( @onNull ChargingPolicyChangeListener chargingPolicyChangeListener)98 public abstract void registerChargingPolicyChangeListener( 99 @NonNull ChargingPolicyChangeListener chargingPolicyChangeListener); 100 101 /** 102 * Returns the value of {@link BatteryManager#BATTERY_PROPERTY_CHARGING_POLICY}. 103 * This will return {@link Integer#MIN_VALUE} if the device does not support the property. 104 * 105 * @see BatteryManager#getIntProperty(int) 106 */ getChargingPolicy()107 public abstract int getChargingPolicy(); 108 109 /** 110 * Returns a non-zero value if an unsupported charger is attached. 111 * 112 * This is a simple accessor that's safe to be called from any locks, but internally it may 113 * wait on the battery service lock. 114 */ getInvalidCharger()115 public abstract int getInvalidCharger(); 116 117 /** 118 * Sets battery AC charger to enabled/disabled, and freezes the battery state. 119 */ setChargerAcOnline(boolean online, boolean forceUpdate)120 public abstract void setChargerAcOnline(boolean online, boolean forceUpdate); 121 122 /** 123 * Sets battery level, and freezes the battery state. 124 */ setBatteryLevel(int level, boolean forceUpdate)125 public abstract void setBatteryLevel(int level, boolean forceUpdate); 126 127 /** 128 * Unplugs battery, and freezes the battery state. 129 */ unplugBattery(boolean forceUpdate)130 public abstract void unplugBattery(boolean forceUpdate); 131 132 /** 133 * Unfreezes battery state, returning to current hardware values. 134 */ resetBattery(boolean forceUpdate)135 public abstract void resetBattery(boolean forceUpdate); 136 137 /** 138 * Suspend charging even if plugged in. 139 */ suspendBatteryInput()140 public abstract void suspendBatteryInput(); 141 } 142