Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 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 | |
Arthur Ishiguro | 1eef69f | 2018-11-08 15:17:11 -0800 | [diff] [blame] | 18 | import android.annotation.Nullable; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Arthur Ishiguro | 27155bc | 2017-11-02 11:30:41 -0700 | [diff] [blame] | 20 | import android.hardware.contexthub.V1_0.ContextHub; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | |
| 24 | import java.util.Arrays; |
| 25 | |
| 26 | /** |
| 27 | * @hide |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 28 | */ |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 29 | @SystemApi |
Arthur Ishiguro | 9f22dd5 | 2017-12-13 09:02:05 -0800 | [diff] [blame] | 30 | public class ContextHubInfo implements Parcelable { |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 31 | private int mId; |
| 32 | private String mName; |
| 33 | private String mVendor; |
| 34 | private String mToolchain; |
| 35 | private int mPlatformVersion; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 36 | private int mToolchainVersion; |
| 37 | private float mPeakMips; |
| 38 | private float mStoppedPowerDrawMw; |
| 39 | private float mSleepPowerDrawMw; |
| 40 | private float mPeakPowerDrawMw; |
Ashutosh Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 41 | private int mMaxPacketLengthBytes; |
Arthur Ishiguro | 27155bc | 2017-11-02 11:30:41 -0700 | [diff] [blame] | 42 | private byte mChreApiMajorVersion; |
| 43 | private byte mChreApiMinorVersion; |
| 44 | private short mChrePatchVersion; |
| 45 | private long mChrePlatformId; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 46 | |
| 47 | private int[] mSupportedSensors; |
| 48 | |
| 49 | private MemoryRegion[] mMemoryRegions; |
| 50 | |
Arthur Ishiguro | 27155bc | 2017-11-02 11:30:41 -0700 | [diff] [blame] | 51 | /* |
Arthur Ishiguro | 6cc8d47c | 2017-11-14 15:20:42 -0800 | [diff] [blame] | 52 | * TODO(b/67734082): Deprecate this constructor and mark private fields as final. |
Arthur Ishiguro | 27155bc | 2017-11-02 11:30:41 -0700 | [diff] [blame] | 53 | */ |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 54 | public ContextHubInfo() { |
| 55 | } |
| 56 | |
| 57 | /** |
Arthur Ishiguro | 27155bc | 2017-11-02 11:30:41 -0700 | [diff] [blame] | 58 | * @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 Joshi | b741e3b | 2016-03-29 09:19:56 -0700 | [diff] [blame] | 82 | * 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 Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 92 | * 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 Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 101 | * 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 Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 110 | * 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 Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 119 | * 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 Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 128 | * get platform version |
| 129 | * |
| 130 | * @return int - platform version number |
| 131 | */ |
| 132 | public int getPlatformVersion() { |
| 133 | return mPlatformVersion; |
| 134 | } |
| 135 | |
| 136 | /** |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 137 | * get static platform version number |
| 138 | * |
| 139 | * @return int - platform version number |
| 140 | */ |
| 141 | public int getStaticSwVersion() { |
Arthur Ishiguro | 27155bc | 2017-11-02 11:30:41 -0700 | [diff] [blame] | 142 | return (mChreApiMajorVersion << 24) | (mChreApiMinorVersion << 16) | (mChrePatchVersion); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /** |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 146 | * 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 Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 155 | * 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 Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 164 | * 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 Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 177 | * 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 Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 192 | * 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 Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 202 | * 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 Ishiguro | 27155bc | 2017-11-02 11:30:41 -0700 | [diff] [blame] | 224 | * @return the CHRE platform ID as defined in chre/version.h |
Arthur Ishiguro | 27155bc | 2017-11-02 11:30:41 -0700 | [diff] [blame] | 225 | */ |
| 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 Ishiguro | 27155bc | 2017-11-02 11:30:41 -0700 | [diff] [blame] | 232 | */ |
| 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 Ishiguro | 27155bc | 2017-11-02 11:30:41 -0700 | [diff] [blame] | 239 | */ |
| 240 | public byte getChreApiMinorVersion() { |
| 241 | return mChreApiMinorVersion; |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * @return the CHRE patch version as defined in chre/version.h |
Arthur Ishiguro | 27155bc | 2017-11-02 11:30:41 -0700 | [diff] [blame] | 246 | */ |
| 247 | public short getChrePatchVersion() { |
| 248 | return mChrePatchVersion; |
| 249 | } |
| 250 | |
Ashutosh Joshi | 6239cc6 | 2016-04-04 16:19:29 -0700 | [diff] [blame] | 251 | @Override |
| 252 | public String toString() { |
Arthur Ishiguro | 27155bc | 2017-11-02 11:30:41 -0700 | [diff] [blame] | 253 | String retVal = ""; |
Arthur Ishiguro | ab7113d | 2017-12-15 14:32:51 -0800 | [diff] [blame] | 254 | retVal += "ID/handle : " + mId; |
Arthur Ishiguro | 27155bc | 2017-11-02 11:30:41 -0700 | [diff] [blame] | 255 | 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 Joshi | 6239cc6 | 2016-04-04 16:19:29 -0700 | [diff] [blame] | 267 | |
Arthur Ishiguro | 27155bc | 2017-11-02 11:30:41 -0700 | [diff] [blame] | 268 | return retVal; |
Ashutosh Joshi | 6239cc6 | 2016-04-04 16:19:29 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Arthur Ishiguro | 1eef69f | 2018-11-08 15:17:11 -0800 | [diff] [blame] | 271 | @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 Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 299 | 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 Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 306 | mPeakMips = in.readFloat(); |
| 307 | mStoppedPowerDrawMw = in.readFloat(); |
| 308 | mSleepPowerDrawMw = in.readFloat(); |
| 309 | mPeakPowerDrawMw = in.readFloat(); |
destradaa | 6469c23 | 2016-04-27 17:53:23 -0700 | [diff] [blame] | 310 | mMaxPacketLengthBytes = in.readInt(); |
Arthur Ishiguro | 27155bc | 2017-11-02 11:30:41 -0700 | [diff] [blame] | 311 | mChrePlatformId = in.readLong(); |
| 312 | mChreApiMajorVersion = in.readByte(); |
| 313 | mChreApiMinorVersion = in.readByte(); |
| 314 | mChrePatchVersion = (short) in.readInt(); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 315 | |
| 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 Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 333 | out.writeFloat(mPeakMips); |
| 334 | out.writeFloat(mStoppedPowerDrawMw); |
| 335 | out.writeFloat(mSleepPowerDrawMw); |
| 336 | out.writeFloat(mPeakPowerDrawMw); |
destradaa | 6469c23 | 2016-04-27 17:53:23 -0700 | [diff] [blame] | 337 | out.writeInt(mMaxPacketLengthBytes); |
Arthur Ishiguro | 27155bc | 2017-11-02 11:30:41 -0700 | [diff] [blame] | 338 | out.writeLong(mChrePlatformId); |
| 339 | out.writeByte(mChreApiMajorVersion); |
| 340 | out.writeByte(mChreApiMinorVersion); |
| 341 | out.writeInt(mChrePatchVersion); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 342 | |
| 343 | out.writeInt(mSupportedSensors.length); |
| 344 | out.writeIntArray(mSupportedSensors); |
| 345 | out.writeTypedArray(mMemoryRegions, flags); |
| 346 | } |
| 347 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 348 | public static final @android.annotation.NonNull Parcelable.Creator<ContextHubInfo> CREATOR |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 349 | = 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 | }; |
destradaa | 6469c23 | 2016-04-27 17:53:23 -0700 | [diff] [blame] | 358 | } |