blob: 36123e3d4229cb8d769cce67678764405f4c6f84 [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
18import android.annotation.SystemApi;
Arthur Ishiguro27155bc2017-11-02 11:30:41 -070019import android.hardware.contexthub.V1_0.ContextHub;
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080020import android.os.Parcel;
21import android.os.Parcelable;
22
23import java.util.Arrays;
24
25/**
26 * @hide
Peng Xu9ff7d222016-02-11 13:02:05 -080027 */
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080028@SystemApi
Arthur Ishiguro9f22dd52017-12-13 09:02:05 -080029public class ContextHubInfo implements Parcelable {
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080030 private int mId;
31 private String mName;
32 private String mVendor;
33 private String mToolchain;
34 private int mPlatformVersion;
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080035 private int mToolchainVersion;
36 private float mPeakMips;
37 private float mStoppedPowerDrawMw;
38 private float mSleepPowerDrawMw;
39 private float mPeakPowerDrawMw;
Ashutosh Joshib741e3b2016-03-29 09:19:56 -070040 private int mMaxPacketLengthBytes;
Arthur Ishiguro27155bc2017-11-02 11:30:41 -070041 private byte mChreApiMajorVersion;
42 private byte mChreApiMinorVersion;
43 private short mChrePatchVersion;
44 private long mChrePlatformId;
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080045
46 private int[] mSupportedSensors;
47
48 private MemoryRegion[] mMemoryRegions;
49
Arthur Ishiguro27155bc2017-11-02 11:30:41 -070050 /*
Arthur Ishiguro6cc8d47c2017-11-14 15:20:42 -080051 * TODO(b/67734082): Deprecate this constructor and mark private fields as final.
Arthur Ishiguro27155bc2017-11-02 11:30:41 -070052 */
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080053 public ContextHubInfo() {
54 }
55
56 /**
Arthur Ishiguro27155bc2017-11-02 11:30:41 -070057 * @hide
58 */
59 public ContextHubInfo(ContextHub contextHub) {
60 mId = contextHub.hubId;
61 mName = contextHub.name;
62 mVendor = contextHub.vendor;
63 mToolchain = contextHub.toolchain;
64 mPlatformVersion = contextHub.platformVersion;
65 mToolchainVersion = contextHub.toolchainVersion;
66 mPeakMips = contextHub.peakMips;
67 mStoppedPowerDrawMw = contextHub.stoppedPowerDrawMw;
68 mSleepPowerDrawMw = contextHub.sleepPowerDrawMw;
69 mPeakPowerDrawMw = contextHub.peakPowerDrawMw;
70 mMaxPacketLengthBytes = contextHub.maxSupportedMsgLen;
71 mChrePlatformId = contextHub.chrePlatformId;
72 mChreApiMajorVersion = contextHub.chreApiMajorVersion;
73 mChreApiMinorVersion = contextHub.chreApiMinorVersion;
74 mChrePatchVersion = contextHub.chrePatchVersion;
75
76 mSupportedSensors = new int[0];
77 mMemoryRegions = new MemoryRegion[0];
78 }
79
80 /**
Ashutosh Joshib741e3b2016-03-29 09:19:56 -070081 * returns the maximum number of bytes that can be sent per message to the hub
82 *
83 * @return int - maximum bytes that can be transmitted in a
84 * single packet
85 */
86 public int getMaxPacketLengthBytes() {
87 return mMaxPacketLengthBytes;
88 }
89
90 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -080091 * get the context hub unique identifer
92 *
93 * @return int - unique system wide identifier
94 */
95 public int getId() {
96 return mId;
97 }
98
99 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800100 * get a string as a hub name
101 *
102 * @return String - a name for the hub
103 */
104 public String getName() {
105 return mName;
106 }
107
108 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800109 * get a string as the vendor name
110 *
111 * @return String - a name for the vendor
112 */
113 public String getVendor() {
114 return mVendor;
115 }
116
117 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800118 * get tool chain string
119 *
120 * @return String - description of the tool chain
121 */
122 public String getToolchain() {
123 return mToolchain;
124 }
125
126 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800127 * get platform version
128 *
129 * @return int - platform version number
130 */
131 public int getPlatformVersion() {
132 return mPlatformVersion;
133 }
134
135 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800136 * get static platform version number
137 *
138 * @return int - platform version number
139 */
140 public int getStaticSwVersion() {
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700141 return (mChreApiMajorVersion << 24) | (mChreApiMinorVersion << 16) | (mChrePatchVersion);
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800142 }
143
144 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800145 * get the tool chain version
146 *
147 * @return int - the tool chain version
148 */
149 public int getToolchainVersion() {
150 return mToolchainVersion;
151 }
152
153 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800154 * get the peak processing mips the hub can support
155 *
156 * @return float - peak MIPS that this hub can deliver
157 */
158 public float getPeakMips() {
159 return mPeakMips;
160 }
161
162 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800163 * get the stopped power draw in milliwatts
164 * This assumes that the hub enter a stopped state - which is
165 * different from the sleep state. Latencies on exiting the
166 * sleep state are typically higher and expect to be in multiple
167 * milliseconds.
168 *
169 * @return float - power draw by the hub in stopped state
170 */
171 public float getStoppedPowerDrawMw() {
172 return mStoppedPowerDrawMw;
173 }
174
175 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800176 * get the power draw of the hub in sleep mode. This assumes
177 * that the hub supports a sleep mode in which the power draw is
178 * lower than the power consumed when the hub is actively
179 * processing. As a guideline, assume that the hub should be
180 * able to enter sleep mode if it knows reliably on completion
181 * of some task that the next interrupt/scheduled work item is
182 * at least 250 milliseconds later.
183 *
184 * @return float - sleep power draw in milli watts
185 */
186 public float getSleepPowerDrawMw() {
187 return mSleepPowerDrawMw;
188 }
189
190 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800191 * get the peak powe draw of the hub. This is the power consumed
192 * by the hub at maximum load.
193 *
194 * @return float - peak power draw
195 */
196 public float getPeakPowerDrawMw() {
197 return mPeakPowerDrawMw;
198 }
199
200 /**
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800201 * get the sensors supported by this hub
202 *
203 * @return int[] - all the supported sensors on this hub
204 *
205 * @see ContextHubManager
206 */
207 public int[] getSupportedSensors() {
208 return Arrays.copyOf(mSupportedSensors, mSupportedSensors.length);
209 }
210
211 /**
212 * get the various memory regions on this hub
213 *
214 * @return MemoryRegion[] - all the memory regions on this hub
215 *
216 * @see MemoryRegion
217 */
218 public MemoryRegion[] getMemoryRegions() {
219 return Arrays.copyOf(mMemoryRegions, mMemoryRegions.length);
220 }
221
222 /**
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700223 * @return the CHRE platform ID as defined in chre/version.h
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700224 */
225 public long getChrePlatformId() {
226 return mChrePlatformId;
227 }
228
229 /**
230 * @return the CHRE API's major version as defined in chre/version.h
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700231 */
232 public byte getChreApiMajorVersion() {
233 return mChreApiMajorVersion;
234 }
235
236 /**
237 * @return the CHRE API's minor version as defined in chre/version.h
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700238 */
239 public byte getChreApiMinorVersion() {
240 return mChreApiMinorVersion;
241 }
242
243 /**
244 * @return the CHRE patch version as defined in chre/version.h
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700245 */
246 public short getChrePatchVersion() {
247 return mChrePatchVersion;
248 }
249
Ashutosh Joshi6239cc62016-04-04 16:19:29 -0700250 @Override
251 public String toString() {
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700252 String retVal = "";
Arthur Ishiguroab7113d2017-12-15 14:32:51 -0800253 retVal += "ID/handle : " + mId;
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700254 retVal += ", Name : " + mName;
255 retVal += "\n\tVendor : " + mVendor;
256 retVal += ", Toolchain : " + mToolchain;
257 retVal += ", Toolchain version: 0x" + Integer.toHexString(mToolchainVersion);
258 retVal += "\n\tPlatformVersion : 0x" + Integer.toHexString(mPlatformVersion);
259 retVal += ", SwVersion : "
260 + mChreApiMajorVersion + "." + mChreApiMinorVersion + "." + mChrePatchVersion;
261 retVal += ", CHRE platform ID: 0x" + Long.toHexString(mChrePlatformId);
262 retVal += "\n\tPeakMips : " + mPeakMips;
263 retVal += ", StoppedPowerDraw : " + mStoppedPowerDrawMw + " mW";
264 retVal += ", PeakPowerDraw : " + mPeakPowerDrawMw + " mW";
265 retVal += ", MaxPacketLength : " + mMaxPacketLengthBytes + " Bytes";
Ashutosh Joshi6239cc62016-04-04 16:19:29 -0700266
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700267 return retVal;
Ashutosh Joshi6239cc62016-04-04 16:19:29 -0700268 }
269
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800270 private ContextHubInfo(Parcel in) {
271 mId = in.readInt();
272 mName = in.readString();
273 mVendor = in.readString();
274 mToolchain = in.readString();
275 mPlatformVersion = in.readInt();
276 mToolchainVersion = in.readInt();
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800277 mPeakMips = in.readFloat();
278 mStoppedPowerDrawMw = in.readFloat();
279 mSleepPowerDrawMw = in.readFloat();
280 mPeakPowerDrawMw = in.readFloat();
destradaa6469c232016-04-27 17:53:23 -0700281 mMaxPacketLengthBytes = in.readInt();
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700282 mChrePlatformId = in.readLong();
283 mChreApiMajorVersion = in.readByte();
284 mChreApiMinorVersion = in.readByte();
285 mChrePatchVersion = (short) in.readInt();
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800286
287 int numSupportedSensors = in.readInt();
288 mSupportedSensors = new int[numSupportedSensors];
289 in.readIntArray(mSupportedSensors);
290 mMemoryRegions = in.createTypedArray(MemoryRegion.CREATOR);
291 }
292
293 public int describeContents() {
294 return 0;
295 }
296
297 public void writeToParcel(Parcel out, int flags) {
298 out.writeInt(mId);
299 out.writeString(mName);
300 out.writeString(mVendor);
301 out.writeString(mToolchain);
302 out.writeInt(mPlatformVersion);
303 out.writeInt(mToolchainVersion);
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800304 out.writeFloat(mPeakMips);
305 out.writeFloat(mStoppedPowerDrawMw);
306 out.writeFloat(mSleepPowerDrawMw);
307 out.writeFloat(mPeakPowerDrawMw);
destradaa6469c232016-04-27 17:53:23 -0700308 out.writeInt(mMaxPacketLengthBytes);
Arthur Ishiguro27155bc2017-11-02 11:30:41 -0700309 out.writeLong(mChrePlatformId);
310 out.writeByte(mChreApiMajorVersion);
311 out.writeByte(mChreApiMinorVersion);
312 out.writeInt(mChrePatchVersion);
Ashutosh Joshi1d1ac542016-01-18 17:19:27 -0800313
314 out.writeInt(mSupportedSensors.length);
315 out.writeIntArray(mSupportedSensors);
316 out.writeTypedArray(mMemoryRegions, flags);
317 }
318
319 public static final Parcelable.Creator<ContextHubInfo> CREATOR
320 = new Parcelable.Creator<ContextHubInfo>() {
321 public ContextHubInfo createFromParcel(Parcel in) {
322 return new ContextHubInfo(in);
323 }
324
325 public ContextHubInfo[] newArray(int size) {
326 return new ContextHubInfo[size];
327 }
328 };
destradaa6469c232016-04-27 17:53:23 -0700329}