Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f4d38053 authored by Greg Kaiser's avatar Greg Kaiser Committed by Android (Google) Code Review
Browse files

Merge "ContextHubManager: Avoid bad NanoApp objects" into nyc-dev

parents f86ce783 cb83bd04
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -15495,6 +15495,7 @@ package android.hardware.location {
  public class NanoApp {
  public class NanoApp {
    ctor public NanoApp();
    ctor public NanoApp();
    ctor public NanoApp(int, byte[]);
    method public int describeContents();
    method public int describeContents();
    method public byte[] getAppBinary();
    method public byte[] getAppBinary();
    method public int getAppId();
    method public int getAppId();
+55 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package android.hardware.location;
import android.annotation.SystemApi;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
import android.util.Log;


/** A class describing nano apps.
/** A class describing nano apps.
 * A nano app is a piece of executable code that can be
 * A nano app is a piece of executable code that can be
@@ -31,10 +32,15 @@ import android.os.Parcelable;
 */
 */
@SystemApi
@SystemApi
public class NanoApp {
public class NanoApp {
    private final String TAG = "NanoApp";

    private final String UNKNOWN = "Unknown";

    private String mPublisher;
    private String mPublisher;
    private String mName;
    private String mName;


    private int mAppId;
    private int mAppId;
    private boolean mAppIdSet;
    private int mAppVersion;
    private int mAppVersion;


    private int mNeededReadMemBytes;
    private int mNeededReadMemBytes;
@@ -45,7 +51,48 @@ public class NanoApp {
    private int[] mOutputEvents;
    private int[] mOutputEvents;
    private byte[] mAppBinary;
    private byte[] mAppBinary;


    /**
     * If this version of the constructor is used, the methods
     * {@link #setAppBinary(byte[])} and {@link #setAppId(int)} must be called
     * prior to passing this object to any managers.
     *
     * @see #NanoApp(int, byte[])
     */
    public NanoApp() {
    public NanoApp() {
        this(0, 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[])
     */
    public NanoApp(int 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;
    }
    }


    /**
    /**
@@ -73,6 +120,7 @@ public class NanoApp {
     */
     */
    public void setAppId(int appId) {
    public void setAppId(int appId) {
        mAppId = appId;
        mAppId = appId;
        mAppIdSet = true;
    }
    }


    /**
    /**
@@ -256,6 +304,13 @@ public class NanoApp {
    }
    }


    public void writeToParcel(Parcel out, int flags) {
    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(mPublisher);
        out.writeString(mName);
        out.writeString(mName);
        out.writeInt(mAppId);
        out.writeInt(mAppId);