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