| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.os; |
| 18 |
|
| 19 |
import android.annotation.IntDef; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.Nullable; |
| 22 |
import android.hardware.thermal.V2_0.TemperatureType; |
| 23 |
import android.hardware.thermal.V2_0.ThrottlingSeverity; |
| 24 |
|
| 25 |
import com.android.internal.util.Preconditions; |
| 26 |
|
| 27 |
import java.lang.annotation.Retention; |
| 28 |
import java.lang.annotation.RetentionPolicy; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public final class Temperature implements Parcelable { |
| 36 |
|
| 37 |
private final float mValue; |
| 38 |
|
| 39 |
private final int mType; |
| 40 |
|
| 41 |
private final String mName; |
| 42 |
|
| 43 |
private final int mStatus; |
| 44 |
|
| 45 |
@IntDef(prefix = { "THROTTLING_" }, value = { |
| 46 |
THROTTLING_NONE, |
| 47 |
THROTTLING_LIGHT, |
| 48 |
THROTTLING_MODERATE, |
| 49 |
THROTTLING_SEVERE, |
| 50 |
THROTTLING_CRITICAL, |
| 51 |
THROTTLING_EMERGENCY, |
| 52 |
THROTTLING_SHUTDOWN, |
| 53 |
}) |
| 54 |
@Retention(RetentionPolicy.SOURCE) |
| 55 |
public @interface ThrottlingStatus {} |
| 56 |
|
| 57 |
|
| 58 |
public static final int THROTTLING_NONE = ThrottlingSeverity.NONE; |
| 59 |
public static final int THROTTLING_LIGHT = ThrottlingSeverity.LIGHT; |
| 60 |
public static final int THROTTLING_MODERATE = ThrottlingSeverity.MODERATE; |
| 61 |
public static final int THROTTLING_SEVERE = ThrottlingSeverity.SEVERE; |
| 62 |
public static final int THROTTLING_CRITICAL = ThrottlingSeverity.CRITICAL; |
| 63 |
public static final int THROTTLING_EMERGENCY = ThrottlingSeverity.EMERGENCY; |
| 64 |
public static final int THROTTLING_SHUTDOWN = ThrottlingSeverity.SHUTDOWN; |
| 65 |
|
| 66 |
@IntDef(prefix = { "TYPE_" }, value = { |
| 67 |
TYPE_UNKNOWN, |
| 68 |
TYPE_CPU, |
| 69 |
TYPE_GPU, |
| 70 |
TYPE_BATTERY, |
| 71 |
TYPE_SKIN, |
| 72 |
TYPE_USB_PORT, |
| 73 |
TYPE_POWER_AMPLIFIER, |
| 74 |
TYPE_BCL_VOLTAGE, |
| 75 |
TYPE_BCL_CURRENT, |
| 76 |
TYPE_BCL_PERCENTAGE, |
| 77 |
TYPE_NPU, |
| 78 |
}) |
| 79 |
@Retention(RetentionPolicy.SOURCE) |
| 80 |
public @interface Type {} |
| 81 |
|
| 82 |
|
| 83 |
public static final int TYPE_UNKNOWN = TemperatureType.UNKNOWN; |
| 84 |
public static final int TYPE_CPU = TemperatureType.CPU; |
| 85 |
public static final int TYPE_GPU = TemperatureType.GPU; |
| 86 |
public static final int TYPE_BATTERY = TemperatureType.BATTERY; |
| 87 |
public static final int TYPE_SKIN = TemperatureType.SKIN; |
| 88 |
public static final int TYPE_USB_PORT = TemperatureType.USB_PORT; |
| 89 |
public static final int TYPE_POWER_AMPLIFIER = TemperatureType.POWER_AMPLIFIER; |
| 90 |
public static final int TYPE_BCL_VOLTAGE = TemperatureType.BCL_VOLTAGE; |
| 91 |
public static final int TYPE_BCL_CURRENT = TemperatureType.BCL_CURRENT; |
| 92 |
public static final int TYPE_BCL_PERCENTAGE = TemperatureType.BCL_PERCENTAGE; |
| 93 |
public static final int TYPE_NPU = TemperatureType.NPU; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public static boolean isValidType(@Type int type) { |
| 101 |
return type >= TYPE_UNKNOWN && type <= TYPE_NPU; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public static boolean isValidStatus(@ThrottlingStatus int status) { |
| 110 |
return status >= THROTTLING_NONE && status <= THROTTLING_SHUTDOWN; |
| 111 |
} |
| 112 |
|
| 113 |
public Temperature(float value, @Type int type, |
| 114 |
@NonNull String name, @ThrottlingStatus int status) { |
| 115 |
Preconditions.checkArgument(isValidType(type), "Invalid Type"); |
| 116 |
Preconditions.checkArgument(isValidStatus(status) , "Invalid Status"); |
| 117 |
mValue = value; |
| 118 |
mType = type; |
| 119 |
mName = Preconditions.checkStringNotEmpty(name); |
| 120 |
mStatus = status; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
public float getValue() { |
| 129 |
return mValue; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public @Type int getType() { |
| 138 |
return mType; |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
public String getName() { |
| 147 |
return mName; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
public @ThrottlingStatus int getStatus() { |
| 156 |
return mStatus; |
| 157 |
} |
| 158 |
|
| 159 |
@Override |
| 160 |
public String toString() { |
| 161 |
return "Temperature{mValue=" + mValue + ", mType=" + mType |
| 162 |
+ ", mName=" + mName + ", mStatus=" + mStatus + "}"; |
| 163 |
} |
| 164 |
|
| 165 |
@Override |
| 166 |
public int hashCode() { |
| 167 |
int hash = mName.hashCode(); |
| 168 |
hash = 31 * hash + Float.hashCode(mValue); |
| 169 |
hash = 31 * hash + mType; |
| 170 |
hash = 31 * hash + mStatus; |
| 171 |
return hash; |
| 172 |
} |
| 173 |
|
| 174 |
@Override |
| 175 |
public boolean equals(@Nullable Object o) { |
| 176 |
if (!(o instanceof Temperature)) { |
| 177 |
return false; |
| 178 |
} |
| 179 |
Temperature other = (Temperature) o; |
| 180 |
return other.mValue == mValue && other.mType == mType |
| 181 |
&& other.mName.equals(mName) && other.mStatus == mStatus; |
| 182 |
} |
| 183 |
|
| 184 |
@Override |
| 185 |
public void writeToParcel(Parcel p, int flags) { |
| 186 |
p.writeFloat(mValue); |
| 187 |
p.writeInt(mType); |
| 188 |
p.writeString(mName); |
| 189 |
p.writeInt(mStatus); |
| 190 |
} |
| 191 |
|
| 192 |
public static final @android.annotation.NonNull Parcelable.Creator<Temperature> CREATOR = |
| 193 |
new Parcelable.Creator<Temperature>() { |
| 194 |
@Override |
| 195 |
public Temperature createFromParcel(Parcel p) { |
| 196 |
float value = p.readFloat(); |
| 197 |
int type = p.readInt(); |
| 198 |
String name = p.readString(); |
| 199 |
int status = p.readInt(); |
| 200 |
return new Temperature(value, type, name, status); |
| 201 |
} |
| 202 |
|
| 203 |
@Override |
| 204 |
public Temperature[] newArray(int size) { |
| 205 |
return new Temperature[size]; |
| 206 |
} |
| 207 |
|
| 208 |
}; |
| 209 |
|
| 210 |
@Override |
| 211 |
public int describeContents() { |
| 212 |
return 0; |
| 213 |
} |
| 214 |
} |