diff options
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/os/CoolingDevice.aidl | 19 | ||||
| -rw-r--r-- | core/java/android/os/CoolingDevice.java | 166 | ||||
| -rw-r--r-- | core/java/android/os/IThermalService.aidl | 18 | ||||
| -rw-r--r-- | core/java/android/os/Temperature.java | 92 |
4 files changed, 256 insertions, 39 deletions
diff --git a/core/java/android/os/CoolingDevice.aidl b/core/java/android/os/CoolingDevice.aidl new file mode 100644 index 000000000000..478e4bd71e6d --- /dev/null +++ b/core/java/android/os/CoolingDevice.aidl @@ -0,0 +1,19 @@ +/* +** Copyright 2019, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +package android.os; + +parcelable CoolingDevice; diff --git a/core/java/android/os/CoolingDevice.java b/core/java/android/os/CoolingDevice.java new file mode 100644 index 000000000000..0e86a381932d --- /dev/null +++ b/core/java/android/os/CoolingDevice.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.os; + +import android.annotation.IntDef; +import android.annotation.NonNull; +import android.hardware.thermal.V2_0.CoolingType; + +import com.android.internal.util.Preconditions; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Cooling device values used by IThermalService. + * + * @hide + */ +public final class CoolingDevice implements Parcelable { + /** + * Current throttle state of the cooling device. The value can any unsigned integer + * numbers between 0 and max_state defined in its driver, usually representing the + * associated device's power state. 0 means device is not in throttling, higher value + * means deeper throttling. + */ + private final long mValue; + /** A cooling device type from ThermalHAL */ + private final int mType; + /** Name of this cooling device */ + private final String mName; + + @IntDef(prefix = { "TYPE_" }, value = { + TYPE_FAN, + TYPE_BATTERY, + TYPE_CPU, + TYPE_GPU, + TYPE_MODEM, + TYPE_NPU, + TYPE_COMPONENT, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface Type {} + + /** Keep in sync with hardware/interfaces/thermal/2.0/types.hal */ + /** Fan for active cooling */ + public static final int TYPE_FAN = CoolingType.FAN; + /** Battery charging cooling deivice */ + public static final int TYPE_BATTERY = CoolingType.BATTERY; + /** CPU cooling deivice */ + public static final int TYPE_CPU = CoolingType.CPU; + /** GPU cooling deivice */ + public static final int TYPE_GPU = CoolingType.GPU; + /** Modem cooling deivice */ + public static final int TYPE_MODEM = CoolingType.MODEM; + /** NPU/TPU cooling deivice */ + public static final int TYPE_NPU = CoolingType.NPU; + /** Generic passive cooling deivice */ + public static final int TYPE_COMPONENT = CoolingType.COMPONENT; + + /** + * Verify a valid cooling device type. + * + * @return true if a cooling device type is valid otherwise false. + */ + public static boolean isValidType(@Type int type) { + return type >= TYPE_FAN && type <= TYPE_COMPONENT; + } + + public CoolingDevice(long value, @Type int type, @NonNull String name) { + Preconditions.checkArgument(isValidType(type), "Invalid Type"); + mValue = value; + mType = type; + mName = Preconditions.checkStringNotEmpty(name); + } + + /** + * Return the cooling device value. + * + * @return a cooling device value in int. + */ + public long getValue() { + return mValue; + } + + /** + * Return the cooling device type. + * + * @return a cooling device type: TYPE_* + */ + public @Type int getType() { + return mType; + } + + /** + * Return the cooling device name. + * + * @return a cooling device name as String. + */ + public String getName() { + return mName; + } + + @Override + public String toString() { + return "CoolingDevice{mValue=" + mValue + ", mType=" + mType + ", mName=" + mName + "}"; + } + + @Override + public int hashCode() { + int hash = mName.hashCode(); + hash = 31 * hash + Long.hashCode(mValue); + hash = 31 * hash + mType; + return hash; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof CoolingDevice)) { + return false; + } + CoolingDevice other = (CoolingDevice) o; + return other.mValue == mValue && other.mType == mType && other.mName.equals(mName); + } + + @Override + public void writeToParcel(Parcel p, int flags) { + p.writeLong(mValue); + p.writeInt(mType); + p.writeString(mName); + } + + public static final @android.annotation.NonNull Parcelable.Creator<CoolingDevice> CREATOR = + new Parcelable.Creator<CoolingDevice>() { + @Override + public CoolingDevice createFromParcel(Parcel p) { + long value = p.readLong(); + int type = p.readInt(); + String name = p.readString(); + return new CoolingDevice(value, type, name); + } + + @Override + public CoolingDevice[] newArray(int size) { + return new CoolingDevice[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } +} diff --git a/core/java/android/os/IThermalService.aidl b/core/java/android/os/IThermalService.aidl index 9280cb9f18b8..8c989607e8db 100644 --- a/core/java/android/os/IThermalService.aidl +++ b/core/java/android/os/IThermalService.aidl @@ -16,6 +16,7 @@ package android.os; +import android.os.CoolingDevice; import android.os.IThermalEventListener; import android.os.IThermalStatusListener; import android.os.Temperature; @@ -52,7 +53,7 @@ interface IThermalService { /** * Get current temperature with its throttling status. - * @return list of android.os.Temperature + * @return list of {@link android.os.Temperature}. * {@hide} */ List<Temperature> getCurrentTemperatures(); @@ -87,4 +88,19 @@ interface IThermalService { * {@hide} */ int getCurrentThermalStatus(); + + /** + * Get current cooling devices. + * @return list of {@link android.os.CoolingDevice}. + * {@hide} + */ + List<CoolingDevice> getCurrentCoolingDevices(); + + /** + * Get current cooling devices on given type. + * @param type the cooling device type to query. + * @return list of {@link android.os.CoolingDevice}. + * {@hide} + */ + List<CoolingDevice> getCurrentCoolingDevicesWithType(in int type); } diff --git a/core/java/android/os/Temperature.java b/core/java/android/os/Temperature.java index be7e824c49fb..7caffcd2ddfd 100644 --- a/core/java/android/os/Temperature.java +++ b/core/java/android/os/Temperature.java @@ -17,9 +17,12 @@ package android.os; import android.annotation.IntDef; +import android.annotation.NonNull; import android.hardware.thermal.V2_0.TemperatureType; import android.hardware.thermal.V2_0.ThrottlingSeverity; +import com.android.internal.util.Preconditions; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -30,13 +33,13 @@ import java.lang.annotation.RetentionPolicy; */ public final class Temperature implements Parcelable { /** Temperature value */ - private float mValue; - /** A temperature type from ThermalHAL */ - private int mType; - /** Name of this temperature */ - private String mName; + private final float mValue; + /** A Temperature type from ThermalHAL */ + private final int mType; + /** Name of this Temperature */ + private final String mName; /** The level of the sensor is currently in throttling */ - private int mStatus; + private final int mStatus; @IntDef(prefix = { "THROTTLING_" }, value = { THROTTLING_NONE, @@ -75,7 +78,7 @@ public final class Temperature implements Parcelable { @Retention(RetentionPolicy.SOURCE) public @interface Type {} - /* Keep in sync with hardware/interfaces/thermal/2.0/types.hal */ + /** 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; @@ -89,9 +92,9 @@ public final class Temperature implements Parcelable { public static final int TYPE_NPU = TemperatureType.NPU; /** - * Verify a valid temperature type. + * Verify a valid Temperature type. * - * @return true if a temperature type is valid otherwise false. + * @return true if a Temperature type is valid otherwise false. */ public static boolean isValidType(@Type int type) { return type >= TYPE_UNKNOWN && type <= TYPE_NPU; @@ -106,67 +109,75 @@ public final class Temperature implements Parcelable { return status >= THROTTLING_NONE && status <= THROTTLING_SHUTDOWN; } - public Temperature() { - this(Float.NaN, TYPE_UNKNOWN, "", THROTTLING_NONE); - } - - public Temperature(float value, @Type int type, String name, @ThrottlingStatus int status) { + public Temperature(float value, @Type int type, + @NonNull String name, @ThrottlingStatus int status) { + Preconditions.checkArgument(isValidType(type), "Invalid Type"); + Preconditions.checkArgument(isValidStatus(status) , "Invalid Status"); mValue = value; - mType = isValidType(type) ? type : TYPE_UNKNOWN; - mName = name; - mStatus = isValidStatus(status) ? status : THROTTLING_NONE; + mType = type; + mName = Preconditions.checkStringNotEmpty(name); + mStatus = status; } /** - * Return the temperature value. + * Return the Temperature value. * - * @return a temperature value in floating point could be NaN. + * @return a Temperature value in floating point could be NaN. */ public float getValue() { return mValue; } /** - * Return the temperature type. + * Return the Temperature type. * - * @return a temperature type: TYPE_* + * @return a Temperature type: TYPE_* */ public @Type int getType() { return mType; } /** - * Return the temperature name. + * Return the Temperature name. * - * @return a temperature name as String. + * @return a Temperature name as String. */ public String getName() { return mName; } /** - * Return the temperature throttling status. + * Return the Temperature throttling status. * - * @return a temperature throttling status: THROTTLING_* + * @return a Temperature throttling status: THROTTLING_* */ public @ThrottlingStatus int getStatus() { return mStatus; } - private Temperature(Parcel p) { - readFromParcel(p); + @Override + public String toString() { + return "Temperature{mValue=" + mValue + ", mType=" + mType + + ", mName=" + mName + ", mStatus=" + mStatus + "}"; } - /** - * 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 int hashCode() { + int hash = mName.hashCode(); + hash = 31 * hash + Float.hashCode(mValue); + hash = 31 * hash + mType; + hash = 31 * hash + mStatus; + return hash; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Temperature)) { + return false; + } + Temperature other = (Temperature) o; + return other.mValue == mValue && other.mType == mType + && other.mName.equals(mName) && other.mStatus == mStatus; } @Override @@ -181,13 +192,18 @@ public final class Temperature implements Parcelable { new Parcelable.Creator<Temperature>() { @Override public Temperature createFromParcel(Parcel p) { - return new Temperature(p); + float value = p.readFloat(); + int type = p.readInt(); + String name = p.readString(); + int status = p.readInt(); + return new Temperature(value, type, name, status); } @Override public Temperature[] newArray(int size) { return new Temperature[size]; } + }; @Override |
