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 | */ |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 16 | package android.hardware.location; |
| 17 | |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 18 | import android.annotation.SystemApi; |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
Greg Kaiser | cb83bd0 | 2016-04-07 15:43:38 -0700 | [diff] [blame] | 21 | import android.util.Log; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 22 | |
Arthur Ishiguro | 926c734 | 2018-11-01 12:13:00 -0700 | [diff] [blame] | 23 | import com.android.internal.util.Preconditions; |
| 24 | |
Peng Xu | 9ff7d22 | 2016-02-11 13:02:05 -0800 | [diff] [blame] | 25 | /** A class describing nano apps. |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 26 | * A nano app is a piece of executable code that can be |
| 27 | * downloaded onto a specific architecture. These are targtted |
| 28 | * for low power compute domains on a device. |
| 29 | * |
| 30 | * Nano apps are expected to be used only by bundled apps only |
| 31 | * at this time. |
| 32 | * |
Arthur Ishiguro | 581950c | 2018-01-05 10:57:46 -0800 | [diff] [blame] | 33 | * @deprecated Use {@link android.hardware.location.NanoAppBinary} instead to load a nanoapp with |
| 34 | * {@link android.hardware.location.ContextHubManager#loadNanoApp( |
| 35 | * ContextHubInfo, NanoAppBinary)}. |
| 36 | * |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 37 | * @hide |
| 38 | */ |
| 39 | @SystemApi |
Arthur Ishiguro | 581950c | 2018-01-05 10:57:46 -0800 | [diff] [blame] | 40 | @Deprecated |
Arthur Ishiguro | f3ab9cd | 2018-02-28 11:27:50 -0800 | [diff] [blame] | 41 | public class NanoApp implements Parcelable { |
Greg Kaiser | cb83bd0 | 2016-04-07 15:43:38 -0700 | [diff] [blame] | 42 | private final String TAG = "NanoApp"; |
| 43 | |
| 44 | private final String UNKNOWN = "Unknown"; |
| 45 | |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 46 | private String mPublisher; |
| 47 | private String mName; |
| 48 | |
Ashutosh Joshi | 6f64bf0 | 2017-01-17 15:39:31 -0800 | [diff] [blame] | 49 | private long mAppId; |
Greg Kaiser | cb83bd0 | 2016-04-07 15:43:38 -0700 | [diff] [blame] | 50 | private boolean mAppIdSet; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 51 | private int mAppVersion; |
| 52 | |
| 53 | private int mNeededReadMemBytes; |
| 54 | private int mNeededWriteMemBytes; |
| 55 | private int mNeededExecMemBytes; |
| 56 | |
| 57 | private int[] mNeededSensors; |
| 58 | private int[] mOutputEvents; |
| 59 | private byte[] mAppBinary; |
| 60 | |
Greg Kaiser | cb83bd0 | 2016-04-07 15:43:38 -0700 | [diff] [blame] | 61 | /** |
| 62 | * If this version of the constructor is used, the methods |
Ashutosh Joshi | 6f64bf0 | 2017-01-17 15:39:31 -0800 | [diff] [blame] | 63 | * {@link #setAppBinary(byte[])} and {@link #setAppId(long)} must be called |
Greg Kaiser | cb83bd0 | 2016-04-07 15:43:38 -0700 | [diff] [blame] | 64 | * prior to passing this object to any managers. |
| 65 | * |
Arthur Ishiguro | afaddaa | 2017-07-12 16:24:09 -0700 | [diff] [blame] | 66 | * @see #NanoApp(long, byte[]) |
Greg Kaiser | cb83bd0 | 2016-04-07 15:43:38 -0700 | [diff] [blame] | 67 | */ |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 68 | public NanoApp() { |
Arthur Ishiguro | afaddaa | 2017-07-12 16:24:09 -0700 | [diff] [blame] | 69 | this(0L, null); |
Greg Kaiser | cb83bd0 | 2016-04-07 15:43:38 -0700 | [diff] [blame] | 70 | mAppIdSet = false; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Initialize a NanoApp with the given id and binary. |
| 75 | * |
| 76 | * While this sets defaults for other fields, users will want to provide |
| 77 | * other values for those fields in most cases. |
| 78 | * |
| 79 | * @see #setPublisher(String) |
| 80 | * @see #setName(String) |
| 81 | * @see #setAppVersion(int) |
| 82 | * @see #setNeededReadMemBytes(int) |
| 83 | * @see #setNeededWriteMemBytes(int) |
| 84 | * @see #setNeededExecMemBytes(int) |
| 85 | * @see #setNeededSensors(int[]) |
| 86 | * @see #setOutputEvents(int[]) |
Ashutosh Joshi | 6f64bf0 | 2017-01-17 15:39:31 -0800 | [diff] [blame] | 87 | * |
| 88 | * @deprecated Use NanoApp(long, byte[]) instead |
Greg Kaiser | cb83bd0 | 2016-04-07 15:43:38 -0700 | [diff] [blame] | 89 | */ |
Ashutosh Joshi | 6f64bf0 | 2017-01-17 15:39:31 -0800 | [diff] [blame] | 90 | @Deprecated public NanoApp(int appId, byte[] appBinary) { |
| 91 | Log.w(TAG, "NanoApp(int, byte[]) is deprecated, please use NanoApp(long, byte[]) instead."); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Initialize a NanoApp with the given id and binary. |
| 96 | * |
| 97 | * While this sets defaults for other fields, users will want to provide |
| 98 | * other values for those fields in most cases. |
| 99 | * |
| 100 | * @see #setPublisher(String) |
| 101 | * @see #setName(String) |
| 102 | * @see #setAppVersion(int) |
| 103 | * @see #setNeededReadMemBytes(int) |
| 104 | * @see #setNeededWriteMemBytes(int) |
| 105 | * @see #setNeededExecMemBytes(int) |
| 106 | * @see #setNeededSensors(int[]) |
| 107 | * @see #setOutputEvents(int[]) |
| 108 | */ |
| 109 | public NanoApp(long appId, byte[] appBinary) { |
Greg Kaiser | cb83bd0 | 2016-04-07 15:43:38 -0700 | [diff] [blame] | 110 | mPublisher = UNKNOWN; |
| 111 | mName = UNKNOWN; |
| 112 | |
| 113 | mAppId = appId; |
| 114 | mAppIdSet = true; |
| 115 | mAppVersion = 0; |
| 116 | |
| 117 | mNeededReadMemBytes = 0; |
| 118 | mNeededWriteMemBytes = 0; |
| 119 | mNeededExecMemBytes = 0; |
| 120 | |
| 121 | mNeededSensors = new int[0]; |
| 122 | mOutputEvents = new int[0]; |
| 123 | mAppBinary = appBinary; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Set the publisher name |
| 128 | * |
| 129 | * @param publisher name of the publisher of this nano app |
| 130 | */ |
| 131 | public void setPublisher(String publisher) { |
| 132 | mPublisher = publisher; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * set the name of the app |
| 137 | * |
| 138 | * @param name name of the app |
| 139 | */ |
| 140 | public void setName(String name) { |
| 141 | mName = name; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * set the app identifier |
| 146 | * |
Ashutosh Joshi | 6f64bf0 | 2017-01-17 15:39:31 -0800 | [diff] [blame] | 147 | * @param appId app identifier |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 148 | */ |
Ashutosh Joshi | 6f64bf0 | 2017-01-17 15:39:31 -0800 | [diff] [blame] | 149 | public void setAppId(long appId) { |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 150 | mAppId = appId; |
Greg Kaiser | cb83bd0 | 2016-04-07 15:43:38 -0700 | [diff] [blame] | 151 | mAppIdSet = true; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Set the app version |
| 156 | * |
| 157 | * @param appVersion app version |
| 158 | */ |
| 159 | public void setAppVersion(int appVersion) { |
| 160 | mAppVersion = appVersion; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * set memory needed as read only |
| 165 | * |
| 166 | * @param neededReadMemBytes |
| 167 | * read only memory needed in bytes |
| 168 | */ |
| 169 | public void setNeededReadMemBytes(int neededReadMemBytes) { |
| 170 | mNeededReadMemBytes = neededReadMemBytes; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * set writable memory needed in bytes |
| 175 | * |
| 176 | * @param neededWriteMemBytes |
| 177 | * writable memory needed in bytes |
| 178 | */ |
| 179 | public void setNeededWriteMemBytes(int neededWriteMemBytes) { |
| 180 | mNeededWriteMemBytes = neededWriteMemBytes; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * set executable memory needed |
| 185 | * |
| 186 | * @param neededExecMemBytes |
| 187 | * executable memory needed in bytes |
| 188 | */ |
| 189 | public void setNeededExecMemBytes(int neededExecMemBytes) { |
| 190 | mNeededExecMemBytes = neededExecMemBytes; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * set the sensors needed for this app |
| 195 | * |
| 196 | * @param neededSensors |
| 197 | * needed Sensors |
| 198 | */ |
| 199 | public void setNeededSensors(int[] neededSensors) { |
Arthur Ishiguro | 926c734 | 2018-11-01 12:13:00 -0700 | [diff] [blame] | 200 | Preconditions.checkNotNull(neededSensors, "neededSensors must not be null"); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 201 | mNeededSensors = neededSensors; |
| 202 | } |
| 203 | |
| 204 | public void setOutputEvents(int[] outputEvents) { |
Arthur Ishiguro | 926c734 | 2018-11-01 12:13:00 -0700 | [diff] [blame] | 205 | Preconditions.checkNotNull(outputEvents, "outputEvents must not be null"); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 206 | mOutputEvents = outputEvents; |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * set output events returned by the nano app |
| 211 | * |
| 212 | * @param appBinary generated events |
| 213 | */ |
| 214 | public void setAppBinary(byte[] appBinary) { |
Arthur Ishiguro | 926c734 | 2018-11-01 12:13:00 -0700 | [diff] [blame] | 215 | Preconditions.checkNotNull(appBinary, "appBinary must not be null"); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 216 | mAppBinary = appBinary; |
| 217 | } |
| 218 | |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 219 | /** |
| 220 | * get the publisher name |
| 221 | * |
| 222 | * @return publisher name |
| 223 | */ |
| 224 | public String getPublisher() { |
Greg Kaiser | 1f3560e | 2016-04-11 12:49:21 -0700 | [diff] [blame] | 225 | return mPublisher; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /** |
| 229 | * get the name of the app |
| 230 | * |
| 231 | * @return app name |
| 232 | */ |
| 233 | public String getName() { |
Greg Kaiser | 1f3560e | 2016-04-11 12:49:21 -0700 | [diff] [blame] | 234 | return mName; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /** |
| 238 | * get the identifier of the app |
| 239 | * |
| 240 | * @return identifier for this app |
| 241 | */ |
Ashutosh Joshi | 6f64bf0 | 2017-01-17 15:39:31 -0800 | [diff] [blame] | 242 | public long getAppId() { |
Greg Kaiser | 1f3560e | 2016-04-11 12:49:21 -0700 | [diff] [blame] | 243 | return mAppId; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | /** |
| 247 | * get the app version |
| 248 | * |
| 249 | * @return app version |
| 250 | */ |
| 251 | public int getAppVersion() { |
Greg Kaiser | 1f3560e | 2016-04-11 12:49:21 -0700 | [diff] [blame] | 252 | return mAppVersion; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /** |
| 256 | * get the ammount of readable memory needed by this app |
| 257 | * |
| 258 | * @return readable memory needed in bytes |
| 259 | */ |
| 260 | public int getNeededReadMemBytes() { |
Greg Kaiser | 1f3560e | 2016-04-11 12:49:21 -0700 | [diff] [blame] | 261 | return mNeededReadMemBytes; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /** |
| 265 | * get the ammount og writable memory needed in bytes |
| 266 | * |
| 267 | * @return writable memory needed in bytes |
| 268 | */ |
| 269 | public int getNeededWriteMemBytes() { |
Greg Kaiser | 1f3560e | 2016-04-11 12:49:21 -0700 | [diff] [blame] | 270 | return mNeededWriteMemBytes; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /** |
| 274 | * executable memory needed in bytes |
| 275 | * |
| 276 | * @return executable memory needed in bytes |
| 277 | */ |
| 278 | public int getNeededExecMemBytes() { |
Greg Kaiser | 1f3560e | 2016-04-11 12:49:21 -0700 | [diff] [blame] | 279 | return mNeededExecMemBytes; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | /** |
| 283 | * get the sensors needed by this app |
| 284 | * |
| 285 | * @return sensors needed |
| 286 | */ |
| 287 | public int[] getNeededSensors() { |
Greg Kaiser | 1f3560e | 2016-04-11 12:49:21 -0700 | [diff] [blame] | 288 | return mNeededSensors; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | /** |
| 292 | * get the events generated by this app |
| 293 | * |
| 294 | * @return generated events |
| 295 | */ |
| 296 | public int[] getOutputEvents() { |
Greg Kaiser | 1f3560e | 2016-04-11 12:49:21 -0700 | [diff] [blame] | 297 | return mOutputEvents; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /** |
| 301 | * get the binary for this app |
| 302 | * |
| 303 | * @return app binary |
| 304 | */ |
| 305 | public byte[] getAppBinary() { |
Greg Kaiser | 1f3560e | 2016-04-11 12:49:21 -0700 | [diff] [blame] | 306 | return mAppBinary; |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | private NanoApp(Parcel in) { |
| 310 | mPublisher = in.readString(); |
| 311 | mName = in.readString(); |
| 312 | |
Ashutosh Joshi | 6f64bf0 | 2017-01-17 15:39:31 -0800 | [diff] [blame] | 313 | mAppId = in.readLong(); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 314 | mAppVersion = in.readInt(); |
| 315 | mNeededReadMemBytes = in.readInt(); |
| 316 | mNeededWriteMemBytes = in.readInt(); |
| 317 | mNeededExecMemBytes = in.readInt(); |
| 318 | |
| 319 | int mNeededSensorsLength = in.readInt(); |
| 320 | mNeededSensors = new int[mNeededSensorsLength]; |
| 321 | in.readIntArray(mNeededSensors); |
| 322 | |
| 323 | int mOutputEventsLength = in.readInt(); |
| 324 | mOutputEvents = new int[mOutputEventsLength]; |
| 325 | in.readIntArray(mOutputEvents); |
| 326 | |
| 327 | int binaryLength = in.readInt(); |
| 328 | mAppBinary = new byte[binaryLength]; |
| 329 | in.readByteArray(mAppBinary); |
| 330 | } |
| 331 | |
| 332 | public int describeContents() { |
| 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | public void writeToParcel(Parcel out, int flags) { |
Greg Kaiser | cb83bd0 | 2016-04-07 15:43:38 -0700 | [diff] [blame] | 337 | if (mAppBinary == null) { |
| 338 | throw new IllegalStateException("Must set non-null AppBinary for nanoapp " + mName); |
| 339 | } |
| 340 | if (!mAppIdSet) { |
| 341 | throw new IllegalStateException("Must set AppId for nanoapp " + mName); |
| 342 | } |
| 343 | |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 344 | out.writeString(mPublisher); |
| 345 | out.writeString(mName); |
Ashutosh Joshi | 6f64bf0 | 2017-01-17 15:39:31 -0800 | [diff] [blame] | 346 | out.writeLong(mAppId); |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 347 | out.writeInt(mAppVersion); |
| 348 | out.writeInt(mNeededReadMemBytes); |
| 349 | out.writeInt(mNeededWriteMemBytes); |
| 350 | out.writeInt(mNeededExecMemBytes); |
| 351 | |
| 352 | out.writeInt(mNeededSensors.length); |
| 353 | out.writeIntArray(mNeededSensors); |
| 354 | |
| 355 | out.writeInt(mOutputEvents.length); |
| 356 | out.writeIntArray(mOutputEvents); |
| 357 | |
| 358 | out.writeInt(mAppBinary.length); |
| 359 | out.writeByteArray(mAppBinary); |
| 360 | } |
| 361 | |
| 362 | public static final Parcelable.Creator<NanoApp> CREATOR |
| 363 | = new Parcelable.Creator<NanoApp>() { |
| 364 | public NanoApp createFromParcel(Parcel in) { |
| 365 | return new NanoApp(in); |
| 366 | } |
| 367 | |
| 368 | public NanoApp[] newArray(int size) { |
| 369 | return new NanoApp[size]; |
| 370 | } |
| 371 | }; |
Ashutosh Joshi | 6239cc6 | 2016-04-04 16:19:29 -0700 | [diff] [blame] | 372 | |
| 373 | @Override |
| 374 | public String toString() { |
| 375 | String retVal = "Id : " + mAppId; |
| 376 | retVal += ", Version : " + mAppVersion; |
| 377 | retVal += ", Name : " + mName; |
| 378 | retVal += ", Publisher : " + mPublisher; |
| 379 | |
| 380 | return retVal; |
| 381 | } |
Ashutosh Joshi | 1d1ac54 | 2016-01-18 17:19:27 -0800 | [diff] [blame] | 382 | } |