• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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  */
16 package android.hardware.location;
17 
18 import android.annotation.NonNull;
19 import android.annotation.Nullable;
20 import android.annotation.SystemApi;
21 import android.hardware.contexthub.V1_0.ContextHub;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 import android.util.proto.ProtoOutputStream;
25 
26 import java.util.Arrays;
27 
28 /**
29  * @hide
30  */
31 @SystemApi
32 public class ContextHubInfo implements Parcelable {
33     private int mId;
34     private String mName;
35     private String mVendor;
36     private String mToolchain;
37     private int mPlatformVersion;
38     private int mToolchainVersion;
39     private float mPeakMips;
40     private float mStoppedPowerDrawMw;
41     private float mSleepPowerDrawMw;
42     private float mPeakPowerDrawMw;
43     private int mMaxPacketLengthBytes;
44     private byte mChreApiMajorVersion;
45     private byte mChreApiMinorVersion;
46     private short mChrePatchVersion;
47     private long mChrePlatformId;
48 
49     private int[] mSupportedSensors;
50 
51     private MemoryRegion[] mMemoryRegions;
52 
53     /*
54      * TODO(b/67734082): Deprecate this constructor and mark private fields as final.
55      */
ContextHubInfo()56     public ContextHubInfo() {
57     }
58 
59     /**
60      * @hide
61      */
ContextHubInfo(ContextHub contextHub)62     public ContextHubInfo(ContextHub contextHub) {
63         mId = contextHub.hubId;
64         mName = contextHub.name;
65         mVendor = contextHub.vendor;
66         mToolchain = contextHub.toolchain;
67         mPlatformVersion = contextHub.platformVersion;
68         mToolchainVersion = contextHub.toolchainVersion;
69         mPeakMips = contextHub.peakMips;
70         mStoppedPowerDrawMw = contextHub.stoppedPowerDrawMw;
71         mSleepPowerDrawMw = contextHub.sleepPowerDrawMw;
72         mPeakPowerDrawMw = contextHub.peakPowerDrawMw;
73         mMaxPacketLengthBytes = contextHub.maxSupportedMsgLen;
74         mChrePlatformId = contextHub.chrePlatformId;
75         mChreApiMajorVersion = contextHub.chreApiMajorVersion;
76         mChreApiMinorVersion = contextHub.chreApiMinorVersion;
77         mChrePatchVersion = contextHub.chrePatchVersion;
78 
79         mSupportedSensors = new int[0];
80         mMemoryRegions = new MemoryRegion[0];
81     }
82 
83     /**
84      * returns the maximum number of bytes that can be sent per message to the hub
85      *
86      * @return int - maximum bytes that can be transmitted in a
87      *         single packet
88      */
getMaxPacketLengthBytes()89     public int getMaxPacketLengthBytes() {
90         return mMaxPacketLengthBytes;
91     }
92 
93     /**
94      * get the context hub unique identifer
95      *
96      * @return int - unique system wide identifier
97      */
getId()98     public int getId() {
99         return mId;
100     }
101 
102     /**
103      * get a string as a hub name
104      *
105      * @return String - a name for the hub
106      */
getName()107     public String getName() {
108         return mName;
109     }
110 
111     /**
112      * get a string as the vendor name
113      *
114      * @return String - a name for the vendor
115      */
getVendor()116     public String getVendor() {
117         return mVendor;
118     }
119 
120     /**
121      * get tool chain string
122      *
123      * @return String - description of the tool chain
124      */
getToolchain()125     public String getToolchain() {
126         return mToolchain;
127     }
128 
129     /**
130      * get platform version
131      *
132      * @return int - platform version number
133      */
getPlatformVersion()134     public int getPlatformVersion() {
135         return mPlatformVersion;
136     }
137 
138     /**
139      * get static platform version number
140      *
141      * @return int - platform version number
142      */
getStaticSwVersion()143     public int getStaticSwVersion() {
144         return (mChreApiMajorVersion << 24) | (mChreApiMinorVersion << 16) | (mChrePatchVersion);
145     }
146 
147     /**
148      * get the tool chain version
149      *
150      * @return int - the tool chain version
151      */
getToolchainVersion()152     public int getToolchainVersion() {
153         return mToolchainVersion;
154     }
155 
156     /**
157      * get the peak processing mips the hub can support
158      *
159      * @return float - peak MIPS that this hub can deliver
160      */
getPeakMips()161     public float getPeakMips() {
162         return mPeakMips;
163     }
164 
165     /**
166      * get the stopped power draw in milliwatts
167      * This assumes that the hub enter a stopped state - which is
168      * different from the sleep state. Latencies on exiting the
169      * sleep state are typically higher and expect to be in multiple
170      * milliseconds.
171      *
172      * @return float - power draw by the hub in stopped state
173      */
getStoppedPowerDrawMw()174     public float getStoppedPowerDrawMw() {
175         return mStoppedPowerDrawMw;
176     }
177 
178     /**
179      * get the power draw of the hub in sleep mode. This assumes
180      * that the hub supports a sleep mode in which the power draw is
181      * lower than the power consumed when the hub is actively
182      * processing. As a guideline, assume that the hub should be
183      * able to enter sleep mode if it knows reliably on completion
184      * of some task that the next interrupt/scheduled work item is
185      * at least 250 milliseconds later.
186      *
187      * @return float - sleep power draw in milli watts
188      */
getSleepPowerDrawMw()189     public float getSleepPowerDrawMw() {
190         return mSleepPowerDrawMw;
191     }
192 
193     /**
194      * get the peak powe draw of the hub. This is the power consumed
195      * by the hub at maximum load.
196      *
197      * @return float - peak power draw
198      */
getPeakPowerDrawMw()199     public float getPeakPowerDrawMw() {
200         return mPeakPowerDrawMw;
201     }
202 
203     /**
204      * get the sensors supported by this hub
205      *
206      * @return int[] - all the supported sensors on this hub
207      *
208      * @see ContextHubManager
209      */
getSupportedSensors()210     public int[] getSupportedSensors() {
211         return Arrays.copyOf(mSupportedSensors, mSupportedSensors.length);
212     }
213 
214     /**
215      * get the various memory regions on this hub
216      *
217      * @return MemoryRegion[] - all the memory regions on this hub
218      *
219      * @see MemoryRegion
220      */
getMemoryRegions()221     public MemoryRegion[] getMemoryRegions() {
222         return Arrays.copyOf(mMemoryRegions, mMemoryRegions.length);
223     }
224 
225     /**
226      * @return the CHRE platform ID as defined in chre/version.h
227      */
getChrePlatformId()228     public long getChrePlatformId() {
229         return mChrePlatformId;
230     }
231 
232     /**
233      * @return the CHRE API's major version as defined in chre/version.h
234      */
getChreApiMajorVersion()235     public byte getChreApiMajorVersion() {
236         return mChreApiMajorVersion;
237     }
238 
239     /**
240      * @return the CHRE API's minor version as defined in chre/version.h
241      */
getChreApiMinorVersion()242     public byte getChreApiMinorVersion() {
243         return mChreApiMinorVersion;
244     }
245 
246     /**
247      * @return the CHRE patch version as defined in chre/version.h
248      */
getChrePatchVersion()249     public short getChrePatchVersion() {
250         return mChrePatchVersion;
251     }
252 
253     @NonNull
254     @Override
toString()255     public String toString() {
256         String retVal = "";
257         retVal += "ID/handle : " + mId;
258         retVal += ", Name : " + mName;
259         retVal += "\n\tVendor : " + mVendor;
260         retVal += ", Toolchain : " + mToolchain;
261         retVal += ", Toolchain version: 0x" + Integer.toHexString(mToolchainVersion);
262         retVal += "\n\tPlatformVersion : 0x" + Integer.toHexString(mPlatformVersion);
263         retVal += ", SwVersion : "
264                 + mChreApiMajorVersion + "." + mChreApiMinorVersion + "." + mChrePatchVersion;
265         retVal += ", CHRE platform ID: 0x" + Long.toHexString(mChrePlatformId);
266         retVal += "\n\tPeakMips : " + mPeakMips;
267         retVal += ", StoppedPowerDraw : " + mStoppedPowerDrawMw + " mW";
268         retVal += ", PeakPowerDraw : " + mPeakPowerDrawMw + " mW";
269         retVal += ", MaxPacketLength : " + mMaxPacketLengthBytes + " Bytes";
270 
271         return retVal;
272     }
273 
274     /**
275      * Dump the internal state as a ContextHubInfoProto to the given ProtoOutputStream.
276      *
277      * If the output belongs to a sub message, the caller is responsible for wrapping this function
278      * between {@link ProtoOutputStream#start(long)} and {@link ProtoOutputStream#end(long)}.
279      *
280      * @hide
281      */
dump(ProtoOutputStream proto)282     public void dump(ProtoOutputStream proto) {
283         proto.write(ContextHubInfoProto.ID, mId);
284         proto.write(ContextHubInfoProto.NAME, mName);
285         proto.write(ContextHubInfoProto.VENDOR, mVendor);
286         proto.write(ContextHubInfoProto.TOOLCHAIN, mToolchain);
287         proto.write(ContextHubInfoProto.PLATFORM_VERSION, mPlatformVersion);
288         proto.write(ContextHubInfoProto.STATIC_SW_VERSION, getStaticSwVersion());
289         proto.write(ContextHubInfoProto.TOOLCHAIN_VERSION, mToolchainVersion);
290         proto.write(ContextHubInfoProto.CHRE_PLATFORM_ID, mChrePlatformId);
291         proto.write(ContextHubInfoProto.PEAK_MIPS, mPeakMips);
292         proto.write(ContextHubInfoProto.STOPPED_POWER_DRAW_MW, mStoppedPowerDrawMw);
293         proto.write(ContextHubInfoProto.SLEEP_POWER_DRAW_MW, mSleepPowerDrawMw);
294         proto.write(ContextHubInfoProto.PEAK_POWER_DRAW_MW, mPeakPowerDrawMw);
295         proto.write(ContextHubInfoProto.MAX_PACKET_LENGTH_BYTES, mMaxPacketLengthBytes);
296     }
297 
298     @Override
equals(@ullable Object object)299     public boolean equals(@Nullable Object object) {
300         if (object == this) {
301             return true;
302         }
303 
304         boolean isEqual = false;
305         if (object instanceof ContextHubInfo) {
306             ContextHubInfo other = (ContextHubInfo) object;
307             isEqual = (other.getId() == mId)
308                     && other.getName().equals(mName)
309                     && other.getVendor().equals(mVendor)
310                     && other.getToolchain().equals(mToolchain)
311                     && (other.getToolchainVersion() == mToolchainVersion)
312                     && (other.getStaticSwVersion() == getStaticSwVersion())
313                     && (other.getChrePlatformId() == mChrePlatformId)
314                     && (other.getPeakMips() == mPeakMips)
315                     && (other.getStoppedPowerDrawMw() == mStoppedPowerDrawMw)
316                     && (other.getSleepPowerDrawMw() == mSleepPowerDrawMw)
317                     && (other.getPeakPowerDrawMw() == mPeakPowerDrawMw)
318                     && (other.getMaxPacketLengthBytes() == mMaxPacketLengthBytes)
319                     && Arrays.equals(other.getSupportedSensors(), mSupportedSensors)
320                     && Arrays.equals(other.getMemoryRegions(), mMemoryRegions);
321         }
322 
323         return isEqual;
324     }
325 
ContextHubInfo(Parcel in)326     private ContextHubInfo(Parcel in) {
327         mId = in.readInt();
328         mName = in.readString();
329         mVendor = in.readString();
330         mToolchain = in.readString();
331         mPlatformVersion = in.readInt();
332         mToolchainVersion = in.readInt();
333         mPeakMips = in.readFloat();
334         mStoppedPowerDrawMw = in.readFloat();
335         mSleepPowerDrawMw = in.readFloat();
336         mPeakPowerDrawMw = in.readFloat();
337         mMaxPacketLengthBytes = in.readInt();
338         mChrePlatformId = in.readLong();
339         mChreApiMajorVersion = in.readByte();
340         mChreApiMinorVersion = in.readByte();
341         mChrePatchVersion = (short) in.readInt();
342 
343         int numSupportedSensors = in.readInt();
344         mSupportedSensors = new int[numSupportedSensors];
345         in.readIntArray(mSupportedSensors);
346         mMemoryRegions = in.createTypedArray(MemoryRegion.CREATOR);
347     }
348 
describeContents()349     public int describeContents() {
350         return 0;
351     }
352 
writeToParcel(Parcel out, int flags)353     public void writeToParcel(Parcel out, int flags) {
354         out.writeInt(mId);
355         out.writeString(mName);
356         out.writeString(mVendor);
357         out.writeString(mToolchain);
358         out.writeInt(mPlatformVersion);
359         out.writeInt(mToolchainVersion);
360         out.writeFloat(mPeakMips);
361         out.writeFloat(mStoppedPowerDrawMw);
362         out.writeFloat(mSleepPowerDrawMw);
363         out.writeFloat(mPeakPowerDrawMw);
364         out.writeInt(mMaxPacketLengthBytes);
365         out.writeLong(mChrePlatformId);
366         out.writeByte(mChreApiMajorVersion);
367         out.writeByte(mChreApiMinorVersion);
368         out.writeInt(mChrePatchVersion);
369 
370         out.writeInt(mSupportedSensors.length);
371         out.writeIntArray(mSupportedSensors);
372         out.writeTypedArray(mMemoryRegions, flags);
373     }
374 
375     public static final @android.annotation.NonNull Parcelable.Creator<ContextHubInfo> CREATOR
376             = new Parcelable.Creator<ContextHubInfo>() {
377         public ContextHubInfo createFromParcel(Parcel in) {
378             return new ContextHubInfo(in);
379         }
380 
381         public ContextHubInfo[] newArray(int size) {
382             return new ContextHubInfo[size];
383         }
384     };
385 }
386