diff options
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/content/Context.java | 9 | ||||
| -rw-r--r-- | core/java/android/os/IThermalEventListener.aidl | 3 | ||||
| -rw-r--r-- | core/java/android/os/IThermalService.aidl | 23 | ||||
| -rw-r--r-- | core/java/android/os/PowerManager.java | 7 | ||||
| -rw-r--r-- | core/java/android/os/Temperature.java | 137 |
5 files changed, 146 insertions, 33 deletions
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index ccf8417bee56..2aa32c4b9cff 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -4227,6 +4227,15 @@ public abstract class Context { /** * Use with {@link #getSystemService(String)} to retrieve a + * {@link android.os.ThermalService} for accessing the thermal service. + * + * @see #getSystemService(String) + * @hide + */ + public static final String THERMAL_SERVICE = "thermalservice"; + + /** + * Use with {@link #getSystemService(String)} to retrieve a * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service. * * @see #getSystemService(String) diff --git a/core/java/android/os/IThermalEventListener.aidl b/core/java/android/os/IThermalEventListener.aidl index 9a6de605c597..fc93b5c94330 100644 --- a/core/java/android/os/IThermalEventListener.aidl +++ b/core/java/android/os/IThermalEventListener.aidl @@ -27,6 +27,5 @@ oneway interface IThermalEventListener { * Called when a thermal throttling start/stop event is received. * @param temperature the temperature at which the event was generated. */ - void notifyThrottling( - in boolean isThrottling, in Temperature temperature); + void notifyThrottling(in Temperature temperature); } diff --git a/core/java/android/os/IThermalService.aidl b/core/java/android/os/IThermalService.aidl index e388edaa5441..287a5edde03f 100644 --- a/core/java/android/os/IThermalService.aidl +++ b/core/java/android/os/IThermalService.aidl @@ -19,6 +19,8 @@ package android.os; import android.os.IThermalEventListener; import android.os.Temperature; +import java.util.List; + /** * {@hide} */ @@ -30,22 +32,29 @@ interface IThermalService { */ void registerThermalEventListener(in IThermalEventListener listener); /** + * Register a listener for thermal events on given temperature type. + * @param listener the IThermalEventListener to be notified. + * @param type the temperature type IThermalEventListener to be notified. + * {@hide} + */ + void registerThermalEventListenerWithType(in IThermalEventListener listener, in int type); + /** * Unregister a previously-registered listener for thermal events. * @param listener the IThermalEventListener to no longer be notified. * {@hide} */ void unregisterThermalEventListener(in IThermalEventListener listener); /** - * Send a thermal throttling start/stop notification to all listeners. - * @param temperature the temperature at which the event was generated. + * Get current temperature with its throttling status. + * @return list of android.os.Temperature * {@hide} */ - oneway void notifyThrottling( - in boolean isThrottling, in Temperature temperature); + List<Temperature> getCurrentTemperatures(); /** - * Return whether system performance is currently thermal throttling. - * @return true if thermal throttling is currently in effect + * Get current temperature with its throttling status on given temperature type. + * @param type the temperature type to query. + * @return list of android.os.Temperature * {@hide} */ - boolean isThrottling(); + List<Temperature> getCurrentTemperaturesWithType(in int type); } diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index e0b2c7853eba..27c281d56f4d 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -477,6 +477,13 @@ public final class PowerManager { public static final String SHUTDOWN_BATTERY_THERMAL_STATE = "thermal,battery"; /** + * The value to pass as the 'reason' argument to android_reboot() when device temperature + * is too high. + * @hide + */ + public static final String SHUTDOWN_THERMAL_STATE = "thermal"; + + /** * The value to pass as the 'reason' argument to android_reboot() when device is running * critically low on battery. * @hide diff --git a/core/java/android/os/Temperature.java b/core/java/android/os/Temperature.java index 8767731e748a..37ed52c1fd2c 100644 --- a/core/java/android/os/Temperature.java +++ b/core/java/android/os/Temperature.java @@ -16,6 +16,13 @@ package android.os; +import android.annotation.IntDef; +import android.hardware.thermal.V2_0.TemperatureType; +import android.hardware.thermal.V2_0.ThrottlingSeverity; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + /** * Temperature values used by IThermalService. */ @@ -24,24 +31,89 @@ package android.os; * @hide */ public class Temperature implements Parcelable { - /* Temperature value */ + /** Temperature value */ private float mValue; - /* A temperature type from HardwarePropertiesManager */ + /** A temperature type from ThermalHAL */ private int mType; + /** Name of this temperature */ + private String mName; + /** The level of the sensor is currently in throttling */ + private int mStatus; + + /** @hide */ + @IntDef(prefix = { "THROTTLING_" }, value = { + THROTTLING_NONE, + THROTTLING_LIGHT, + THROTTLING_MODERATE, + THROTTLING_SEVERE, + THROTTLING_CRITICAL, + THROTTLING_WARNING, + THROTTLING_SHUTDOWN, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface ThrottlingStatus {} + + /** Keep in sync with hardware/interfaces/thermal/2.0/types.hal */ + public static final int THROTTLING_NONE = ThrottlingSeverity.NONE; + public static final int THROTTLING_LIGHT = ThrottlingSeverity.LIGHT; + public static final int THROTTLING_MODERATE = ThrottlingSeverity.MODERATE; + public static final int THROTTLING_SEVERE = ThrottlingSeverity.SEVERE; + public static final int THROTTLING_CRITICAL = ThrottlingSeverity.CRITICAL; + public static final int THROTTLING_WARNING = ThrottlingSeverity.WARNING; + public static final int THROTTLING_SHUTDOWN = ThrottlingSeverity.SHUTDOWN; + + /** @hide */ + @IntDef(prefix = { "TYPE_" }, value = { + TYPE_UNKNOWN, + TYPE_CPU, + TYPE_GPU, + TYPE_BATTERY, + TYPE_SKIN, + TYPE_USB_PORT, + TYPE_POWER_AMPLIFIER, + TYPE_BCL_VOLTAGE, + TYPE_BCL_CURRENT, + TYPE_BCL_PERCENTAGE, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface Type {} + + /* Keep in sync with hardware/interfaces/thermal/2.0/types.hal */ + public static final int TYPE_UNKNOWN = TemperatureType.UNKNOWN; + public static final int TYPE_CPU = TemperatureType.CPU; + public static final int TYPE_GPU = TemperatureType.GPU; + public static final int TYPE_BATTERY = TemperatureType.BATTERY; + public static final int TYPE_SKIN = TemperatureType.SKIN; + public static final int TYPE_USB_PORT = TemperatureType.USB_PORT; + public static final int TYPE_POWER_AMPLIFIER = TemperatureType.POWER_AMPLIFIER; + public static final int TYPE_BCL_VOLTAGE = TemperatureType.BCL_VOLTAGE; + public static final int TYPE_BCL_CURRENT = TemperatureType.BCL_CURRENT; + public static final int TYPE_BCL_PERCENTAGE = TemperatureType.BCL_PERCENTAGE; + + /** + * Verify a valid temperature type. + * + * @return true if a temperature type is valid otherwise false. + */ + public static boolean isValidType(int type) { + return type >= TYPE_UNKNOWN && type <= TYPE_BCL_PERCENTAGE; + } public Temperature() { - this(HardwarePropertiesManager.UNDEFINED_TEMPERATURE, - Integer.MIN_VALUE); + this(Float.NaN, TYPE_UNKNOWN, "", THROTTLING_NONE); } - public Temperature(float value, int type) { + public Temperature(float value, @Type int type, String name, int status) { mValue = value; - mType = type; + mType = isValidType(type) ? type : TYPE_UNKNOWN; + mName = name; + mStatus = status; } /** * Return the temperature value. - * @return a temperature value in floating point. + * + * @return a temperature value in floating point could be NaN. */ public float getValue() { return mValue; @@ -49,18 +121,30 @@ public class Temperature implements Parcelable { /** * Return the temperature type. - * @return a temperature type: - * HardwarePropertiesManager.DEVICE_TEMPERATURE_CPU, etc. + * + * @return a temperature type: TYPE_* */ - public int getType() { + public @Type int getType() { return mType; } - /* - * Parcel read/write code must be kept in sync with - * frameworks/native/services/thermalservice/aidl/android/os/ - * Temperature.cpp + /** + * Return the temperature name. + * + * @return a temperature name as String. + */ + public String getName() { + return mName; + } + + /** + * Return the temperature throttling status. + * + * @return a temperature throttling status: THROTTLING_* */ + public @ThrottlingStatus int getStatus() { + return mStatus; + } private Temperature(Parcel p) { readFromParcel(p); @@ -68,31 +152,36 @@ public class Temperature implements Parcelable { /** * Fill in Temperature members from a Parcel. + * * @param p the parceled Temperature object. */ public void readFromParcel(Parcel p) { mValue = p.readFloat(); mType = p.readInt(); + mName = p.readString(); + mStatus = p.readInt(); } @Override public void writeToParcel(Parcel p, int flags) { p.writeFloat(mValue); p.writeInt(mType); + p.writeString(mName); + p.writeInt(mStatus); } public static final Parcelable.Creator<Temperature> CREATOR = new Parcelable.Creator<Temperature>() { - @Override - public Temperature createFromParcel(Parcel p) { - return new Temperature(p); - } - - @Override - public Temperature[] newArray(int size) { - return new Temperature[size]; - } - }; + @Override + public Temperature createFromParcel(Parcel p) { + return new Temperature(p); + } + + @Override + public Temperature[] newArray(int size) { + return new Temperature[size]; + } + }; @Override public int describeContents() { |
