| 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.CoolingType; |
| 23 |
|
| 24 |
import com.android.internal.util.Preconditions; |
| 25 |
|
| 26 |
import java.lang.annotation.Retention; |
| 27 |
import java.lang.annotation.RetentionPolicy; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public final class CoolingDevice implements Parcelable { |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
private final long mValue; |
| 42 |
|
| 43 |
private final int mType; |
| 44 |
|
| 45 |
private final String mName; |
| 46 |
|
| 47 |
@IntDef(prefix = { "TYPE_" }, value = { |
| 48 |
TYPE_FAN, |
| 49 |
TYPE_BATTERY, |
| 50 |
TYPE_CPU, |
| 51 |
TYPE_GPU, |
| 52 |
TYPE_MODEM, |
| 53 |
TYPE_NPU, |
| 54 |
TYPE_COMPONENT, |
| 55 |
}) |
| 56 |
@Retention(RetentionPolicy.SOURCE) |
| 57 |
public @interface Type {} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public static final int TYPE_FAN = CoolingType.FAN; |
| 62 |
|
| 63 |
public static final int TYPE_BATTERY = CoolingType.BATTERY; |
| 64 |
|
| 65 |
public static final int TYPE_CPU = CoolingType.CPU; |
| 66 |
|
| 67 |
public static final int TYPE_GPU = CoolingType.GPU; |
| 68 |
|
| 69 |
public static final int TYPE_MODEM = CoolingType.MODEM; |
| 70 |
|
| 71 |
public static final int TYPE_NPU = CoolingType.NPU; |
| 72 |
|
| 73 |
public static final int TYPE_COMPONENT = CoolingType.COMPONENT; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public static boolean isValidType(@Type int type) { |
| 81 |
return type >= TYPE_FAN && type <= TYPE_COMPONENT; |
| 82 |
} |
| 83 |
|
| 84 |
public CoolingDevice(long value, @Type int type, @NonNull String name) { |
| 85 |
Preconditions.checkArgument(isValidType(type), "Invalid Type"); |
| 86 |
mValue = value; |
| 87 |
mType = type; |
| 88 |
mName = Preconditions.checkStringNotEmpty(name); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
public long getValue() { |
| 97 |
return mValue; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
public @Type int getType() { |
| 106 |
return mType; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
public String getName() { |
| 115 |
return mName; |
| 116 |
} |
| 117 |
|
| 118 |
@Override |
| 119 |
public String toString() { |
| 120 |
return "CoolingDevice{mValue=" + mValue + ", mType=" + mType + ", mName=" + mName + "}"; |
| 121 |
} |
| 122 |
|
| 123 |
@Override |
| 124 |
public int hashCode() { |
| 125 |
int hash = mName.hashCode(); |
| 126 |
hash = 31 * hash + Long.hashCode(mValue); |
| 127 |
hash = 31 * hash + mType; |
| 128 |
return hash; |
| 129 |
} |
| 130 |
|
| 131 |
@Override |
| 132 |
public boolean equals(@Nullable Object o) { |
| 133 |
if (!(o instanceof CoolingDevice)) { |
| 134 |
return false; |
| 135 |
} |
| 136 |
CoolingDevice other = (CoolingDevice) o; |
| 137 |
return other.mValue == mValue && other.mType == mType && other.mName.equals(mName); |
| 138 |
} |
| 139 |
|
| 140 |
@Override |
| 141 |
public void writeToParcel(Parcel p, int flags) { |
| 142 |
p.writeLong(mValue); |
| 143 |
p.writeInt(mType); |
| 144 |
p.writeString(mName); |
| 145 |
} |
| 146 |
|
| 147 |
public static final @android.annotation.NonNull Parcelable.Creator<CoolingDevice> CREATOR = |
| 148 |
new Parcelable.Creator<CoolingDevice>() { |
| 149 |
@Override |
| 150 |
public CoolingDevice createFromParcel(Parcel p) { |
| 151 |
long value = p.readLong(); |
| 152 |
int type = p.readInt(); |
| 153 |
String name = p.readString(); |
| 154 |
return new CoolingDevice(value, type, name); |
| 155 |
} |
| 156 |
|
| 157 |
@Override |
| 158 |
public CoolingDevice[] newArray(int size) { |
| 159 |
return new CoolingDevice[size]; |
| 160 |
} |
| 161 |
}; |
| 162 |
|
| 163 |
@Override |
| 164 |
public int describeContents() { |
| 165 |
return 0; |
| 166 |
} |
| 167 |
} |