blob: b5da381a4f9913e83989bfd7773cc8b83fde862e [file] [log] [blame]
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -08001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package android.hardware.location;
17
Arthur Ishiguro1eef69f2018-11-08 15:17:11 -080018import android.annotation.Nullable;
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080019import android.annotation.SystemApi;
Arthur Ishiguro27155bc2017-11-02 11:30:41 -070020import android.hardware.contexthub.V1_0.ContextHub;
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080021import android.os.Parcel;
22import android.os.Parcelable;
23
24import java.util.Arrays;
25
26/**
27 * @hide
Peng Xu9ff7d222016-02-11 13:02:05 -080028 */
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080029@SystemApi
Arthur Ishiguro9f22dd52017-12-13 09:02:05 -080030public class ContextHubInfo implements Parcelable {
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080031 private int mId;
32 private String mName;
33 private String mVendor;
34 private String mToolchain;
35 private int mPlatformVersion;
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080036 private int mToolchainVersion;
37 private float mPeakMips;
38 private float mStoppedPowerDrawMw;
39 private float mSleepPowerDrawMw;
40 private float mPeakPowerDrawMw;
Ashutosh Joshib741e3b2016-03-29 09:19:56 -070041 private int mMaxPacketLengthBytes;
Arthur Ishiguro27155bc2017-11-02 11:30:41 -070042 private byte mChreApiMajorVersion;
43 private byte mChreApiMinorVersion;
44 private short mChrePatchVersion;
45 private long mChrePlatformId;
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080046
47 private int[] mSupportedSensors;
48
49 private MemoryRegion[] mMemoryRegions;
50
Arthur Ishiguro27155bc2017-11-02 11:30:41 -070051 /*
Arthur Ishiguro6cc8d47c2017-11-14 15:20:42 -080052 * TODO(b/67734082): Deprecate this constructor and mark private fields as final.
Arthur Ishiguro27155bc2017-11-02 11:30:41 -070053 */
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080054 public ContextHubInfo() {
55 }
56
57 /**
Arthur Ishiguro27155bc2017-11-02 11:30:41 -070058 * @hide
59 */
60 public ContextHubInfo(ContextHub contextHub) {
61 mId = contextHub.hubId;
62 mName = contextHub.name;
63 mVendor = contextHub.vendor;
64 mToolchain = contextHub.toolchain;
65 mPlatformVersion = contextHub.platformVersion;
66 mToolchainVersion = contextHub.toolchainVersion;
67 mPeakMips = contextHub.peakMips;
68 mStoppedPowerDrawMw = contextHub.stoppedPowerDrawMw;
69 mSleepPowerDrawMw = contextHub.sleepPowerDrawMw;
70 mPeakPowerDrawMw = contextHub.peakPowerDrawMw;
71 mMaxPacketLengthBytes = contextHub.maxSupportedMsgLen;
72 mChrePlatformId = contextHub.chrePlatformId;
73 mChreApiMajorVersion = contextHub.chreApiMajorVersion;
74 mChreApiMinorVersion = contextHub.chreApiMinorVersion;
75 mChrePatchVersion = contextHub.chrePatchVersion;
76
77 mSupportedSensors = new int[0];
78 mMemoryRegions = new MemoryRegion[0];
79 }
80
81 /**
Ashutosh Joshib741e3b2016-03-29 09:19:56 -070082 * returns the maximum number of bytes that can be sent per message to the hub
83 *
84 * @return int - maximum bytes that can be transmitted in a
85 * single packet
86 */
87 public int getMaxPacketLengthBytes() {
88 return mMaxPacketLengthBytes;
89 }
90
91 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080092 * get the context hub unique identifer
93 *
94 * @return int - unique system wide identifier
95 */
96 public int getId() {
97 return mId;
98 }
99
100 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800101 * get a string as a hub name
102 *
103 * @return String - a name for the hub
104 */
105 public String getName() {
106 return mName;
107 }
108
109 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800110 * get a string as the vendor name
111 *
112 * @return String - a name for the vendor
113 */
114 public String getVendor() {
115 return mVendor;
116 }
117
118 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800119 * get tool chain string
120 *
121 * @return String - description of the tool chain
122 */
123 public String getToolchain() {
124 return mToolchain;
125 }
126
127 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800128 * get platform version
129 *
130 * @return int - platform version number
131 */
132 public int getPlatformVersion() {
133 return mPlatformVersion;
134 }
135
136 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800137 * get static platform version number
138 *
139 * @return int - platform version number
140 */
141 public int getStaticSwVersion() {
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700142 return (mChreApiMajorVersion << 24) | (mChreApiMinorVersion << 16) | (mChrePatchVersion);
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800143 }
144
145 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800146 * get the tool chain version
147 *
148 * @return int - the tool chain version
149 */
150 public int getToolchainVersion() {
151 return mToolchainVersion;
152 }
153
154 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800155 * get the peak processing mips the hub can support
156 *
157 * @return float - peak MIPS that this hub can deliver
158 */
159 public float getPeakMips() {
160 return mPeakMips;
161 }
162
163 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800164 * get the stopped power draw in milliwatts
165 * This assumes that the hub enter a stopped state - which is
166 * different from the sleep state. Latencies on exiting the
167 * sleep state are typically higher and expect to be in multiple
168 * milliseconds.
169 *
170 * @return float - power draw by the hub in stopped state
171 */
172 public float getStoppedPowerDrawMw() {
173 return mStoppedPowerDrawMw;
174 }
175
176 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800177 * get the power draw of the hub in sleep mode. This assumes
178 * that the hub supports a sleep mode in which the power draw is
179 * lower than the power consumed when the hub is actively
180 * processing. As a guideline, assume that the hub should be
181 * able to enter sleep mode if it knows reliably on completion
182 * of some task that the next interrupt/scheduled work item is
183 * at least 250 milliseconds later.
184 *
185 * @return float - sleep power draw in milli watts
186 */
187 public float getSleepPowerDrawMw() {
188 return mSleepPowerDrawMw;
189 }
190
191 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800192 * get the peak powe draw of the hub. This is the power consumed
193 * by the hub at maximum load.
194 *
195 * @return float - peak power draw
196 */
197 public float getPeakPowerDrawMw() {
198 return mPeakPowerDrawMw;
199 }
200
201 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800202 * get the sensors supported by this hub
203 *
204 * @return int[] - all the supported sensors on this hub
205 *
206 * @see ContextHubManager
207 */
208 public int[] getSupportedSensors() {
209 return Arrays.copyOf(mSupportedSensors, mSupportedSensors.length);
210 }
211
212 /**
213 * get the various memory regions on this hub
214 *
215 * @return MemoryRegion[] - all the memory regions on this hub
216 *
217 * @see MemoryRegion
218 */
219 public MemoryRegion[] getMemoryRegions() {
220 return Arrays.copyOf(mMemoryRegions, mMemoryRegions.length);
221 }
222
223 /**
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700224 * @return the CHRE platform ID as defined in chre/version.h
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700225 */
226 public long getChrePlatformId() {
227 return mChrePlatformId;
228 }
229
230 /**
231 * @return the CHRE API's major version as defined in chre/version.h
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700232 */
233 public byte getChreApiMajorVersion() {
234 return mChreApiMajorVersion;
235 }
236
237 /**
238 * @return the CHRE API's minor version as defined in chre/version.h
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700239 */
240 public byte getChreApiMinorVersion() {
241 return mChreApiMinorVersion;
242 }
243
244 /**
245 * @return the CHRE patch version as defined in chre/version.h
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700246 */
247 public short getChrePatchVersion() {
248 return mChrePatchVersion;
249 }
250
Ashutosh Joshi6239cc62016-04-04 16:19:29 -0700251 @Override
252 public String toString() {
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700253 String retVal = "";
Arthur Ishiguroab7113d2017-12-15 14:32:51 -0800254 retVal += "ID/handle : " + mId;
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700255 retVal += ", Name : " + mName;
256 retVal += "\n\tVendor : " + mVendor;
257 retVal += ", Toolchain : " + mToolchain;
258 retVal += ", Toolchain version: 0x" + Integer.toHexString(mToolchainVersion);
259 retVal += "\n\tPlatformVersion : 0x" + Integer.toHexString(mPlatformVersion);
260 retVal += ", SwVersion : "
261 + mChreApiMajorVersion + "." + mChreApiMinorVersion + "." + mChrePatchVersion;
262 retVal += ", CHRE platform ID: 0x" + Long.toHexString(mChrePlatformId);
263 retVal += "\n\tPeakMips : " + mPeakMips;
264 retVal += ", StoppedPowerDraw : " + mStoppedPowerDrawMw + " mW";
265 retVal += ", PeakPowerDraw : " + mPeakPowerDrawMw + " mW";
266 retVal += ", MaxPacketLength : " + mMaxPacketLengthBytes + " Bytes";
Ashutosh Joshi6239cc62016-04-04 16:19:29 -0700267
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700268 return retVal;
Ashutosh Joshi6239cc62016-04-04 16:19:29 -0700269 }
270
Arthur Ishiguro1eef69f2018-11-08 15:17:11 -0800271 @Override
272 public boolean equals(@Nullable Object object) {
273 if (object == this) {
274 return true;
275 }
276
277 boolean isEqual = false;
278 if (object instanceof ContextHubInfo) {
279 ContextHubInfo other = (ContextHubInfo) object;
280 isEqual = (other.getId() == mId)
281 && other.getName().equals(mName)
282 && other.getVendor().equals(mVendor)
283 && other.getToolchain().equals(mToolchain)
284 && (other.getToolchainVersion() == mToolchainVersion)
285 && (other.getStaticSwVersion() == getStaticSwVersion())
286 && (other.getChrePlatformId() == mChrePlatformId)
287 && (other.getPeakMips() == mPeakMips)
288 && (other.getStoppedPowerDrawMw() == mStoppedPowerDrawMw)
289 && (other.getSleepPowerDrawMw() == mSleepPowerDrawMw)
290 && (other.getPeakPowerDrawMw() == mPeakPowerDrawMw)
291 && (other.getMaxPacketLengthBytes() == mMaxPacketLengthBytes)
292 && Arrays.equals(other.getSupportedSensors(), mSupportedSensors)
293 && Arrays.equals(other.getMemoryRegions(), mMemoryRegions);
294 }
295
296 return isEqual;
297 }
298
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800299 private ContextHubInfo(Parcel in) {
300 mId = in.readInt();
301 mName = in.readString();
302 mVendor = in.readString();
303 mToolchain = in.readString();
304 mPlatformVersion = in.readInt();
305 mToolchainVersion = in.readInt();
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800306 mPeakMips = in.readFloat();
307 mStoppedPowerDrawMw = in.readFloat();
308 mSleepPowerDrawMw = in.readFloat();
309 mPeakPowerDrawMw = in.readFloat();
destradaa6469c232016-04-27 17:53:23 -0700310 mMaxPacketLengthBytes = in.readInt();
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700311 mChrePlatformId = in.readLong();
312 mChreApiMajorVersion = in.readByte();
313 mChreApiMinorVersion = in.readByte();
314 mChrePatchVersion = (short) in.readInt();
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800315
316 int numSupportedSensors = in.readInt();
317 mSupportedSensors = new int[numSupportedSensors];
318 in.readIntArray(mSupportedSensors);
319 mMemoryRegions = in.createTypedArray(MemoryRegion.CREATOR);
320 }
321
322 public int describeContents() {
323 return 0;
324 }
325
326 public void writeToParcel(Parcel out, int flags) {
327 out.writeInt(mId);
328 out.writeString(mName);
329 out.writeString(mVendor);
330 out.writeString(mToolchain);
331 out.writeInt(mPlatformVersion);
332 out.writeInt(mToolchainVersion);
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800333 out.writeFloat(mPeakMips);
334 out.writeFloat(mStoppedPowerDrawMw);
335 out.writeFloat(mSleepPowerDrawMw);
336 out.writeFloat(mPeakPowerDrawMw);
destradaa6469c232016-04-27 17:53:23 -0700337 out.writeInt(mMaxPacketLengthBytes);
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700338 out.writeLong(mChrePlatformId);
339 out.writeByte(mChreApiMajorVersion);
340 out.writeByte(mChreApiMinorVersion);
341 out.writeInt(mChrePatchVersion);
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800342
343 out.writeInt(mSupportedSensors.length);
344 out.writeIntArray(mSupportedSensors);
345 out.writeTypedArray(mMemoryRegions, flags);
346 }
347
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700348 public static final @android.annotation.NonNull Parcelable.Creator<ContextHubInfo> CREATOR
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800349 = new Parcelable.Creator<ContextHubInfo>() {
350 public ContextHubInfo createFromParcel(Parcel in) {
351 return new ContextHubInfo(in);
352 }
353
354 public ContextHubInfo[] newArray(int size) {
355 return new ContextHubInfo[size];
356 }
357 };
destradaa6469c232016-04-27 17:53:23 -0700358}