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