File: CoolingDevice.java

package info (click to toggle)
android-platform-frameworks-base 1%3A10.0.0%2Br36-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 321,788 kB
  • sloc: java: 962,234; cpp: 274,314; xml: 242,770; python: 5,060; sh: 1,432; ansic: 494; makefile: 47; sed: 19
file content (166 lines) | stat: -rw-r--r-- 5,063 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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;
    }
}