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

Commit 521d92bc authored by Ashutosh Joshi's avatar Ashutosh Joshi Committed by Android (Google) Code Review
Browse files

Merge "Fix error in width of nanoAppId"

parents 7986b529 6f64bf05
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -16938,10 +16938,11 @@ package android.hardware.location {
  public class NanoApp {
    ctor public NanoApp();
    ctor public NanoApp(int, byte[]);
    ctor public deprecated NanoApp(int, byte[]);
    ctor public NanoApp(long, byte[]);
    method public int describeContents();
    method public byte[] getAppBinary();
    method public int getAppId();
    method public long getAppId();
    method public int getAppVersion();
    method public java.lang.String getName();
    method public int getNeededExecMemBytes();
@@ -16951,7 +16952,7 @@ package android.hardware.location {
    method public int[] getOutputEvents();
    method public java.lang.String getPublisher();
    method public void setAppBinary(byte[]);
    method public void setAppId(int);
    method public void setAppId(long);
    method public void setAppVersion(int);
    method public void setName(java.lang.String);
    method public void setNeededExecMemBytes(int);
+29 −8
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ public class NanoApp {
    private String mPublisher;
    private String mName;

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

@@ -53,7 +53,7 @@ public class NanoApp {

    /**
     * If this version of the constructor is used, the methods
     * {@link #setAppBinary(byte[])} and {@link #setAppId(int)} must be called
     * {@link #setAppBinary(byte[])} and {@link #setAppId(long)} must be called
     * prior to passing this object to any managers.
     *
     * @see #NanoApp(int, byte[])
@@ -63,6 +63,27 @@ public class NanoApp {
        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.
     *
@@ -78,7 +99,7 @@ public class NanoApp {
     * @see #setNeededSensors(int[])
     * @see #setOutputEvents(int[])
     */
    public NanoApp(int appId, byte[] appBinary) {
    public NanoApp(long appId, byte[] appBinary) {
        mPublisher = UNKNOWN;
        mName = UNKNOWN;

@@ -116,9 +137,9 @@ public class NanoApp {
    /**
     * set the app identifier
     *
     * @param appId  add identifier
     * @param appId  app identifier
     */
    public void setAppId(int appId) {
    public void setAppId(long appId) {
        mAppId = appId;
        mAppIdSet = true;
    }
@@ -209,7 +230,7 @@ public class NanoApp {
     *
     * @return identifier for this app
     */
    public int getAppId() {
    public long getAppId() {
        return mAppId;
    }

@@ -280,7 +301,7 @@ public class NanoApp {
        mPublisher = in.readString();
        mName = in.readString();

        mAppId = in.readInt();
        mAppId = in.readLong();
        mAppVersion = in.readInt();
        mNeededReadMemBytes = in.readInt();
        mNeededWriteMemBytes = in.readInt();
@@ -313,7 +334,7 @@ public class NanoApp {

        out.writeString(mPublisher);
        out.writeString(mName);
        out.writeInt(mAppId);
        out.writeLong(mAppId);
        out.writeInt(mAppVersion);
        out.writeInt(mNeededReadMemBytes);
        out.writeInt(mNeededWriteMemBytes);
+0 −39
Original line number Diff line number Diff line
@@ -120,36 +120,6 @@ public class ContextHubService extends IContextHubService.Stub {
        return mContextHubInfo[contextHubHandle];
    }

    // TODO(b/30808791): Remove this when NanoApp's API is correctly treating
    // app IDs as 64-bits.
    private static long parseAppId(NanoApp app) {
        // NOTE: If this shifting seems odd (since it's actually "ONAN"), note
        //     that it matches how this is defined in context_hub.h.
        final int HEADER_MAGIC =
            (((int)'N' <<  0) |
             ((int)'A' <<  8) |
             ((int)'N' << 16) |
             ((int)'O' << 24));
        final int HEADER_MAGIC_OFFSET = 4;
        final int HEADER_APP_ID_OFFSET = 8;

        ByteBuffer header = ByteBuffer.wrap(app.getAppBinary())
            .order(ByteOrder.LITTLE_ENDIAN);

        try {
            if (header.getInt(HEADER_MAGIC_OFFSET) == HEADER_MAGIC) {
                // This is a legitimate nanoapp header.  Let's grab the app ID.
                return header.getLong(HEADER_APP_ID_OFFSET);
            }
        } catch (IndexOutOfBoundsException e) {
            // The header is undersized.  We'll fall through to our code
            // path below, which handles being unable to parse the header.
        }
        // We failed to parse the header.  Even through it's probably wrong,
        // let's give NanoApp's idea of our ID.  This is at least consistent.
        return app.getAppId();
    }

    @Override
    public int loadNanoApp(int contextHubHandle, NanoApp app) throws RemoteException {
        checkPermissions();
@@ -169,15 +139,6 @@ public class ContextHubService extends IContextHubService.Stub {
        msgHeader[HEADER_FIELD_MSG_TYPE] = MSG_LOAD_NANO_APP;

        long appId = app.getAppId();
        // TODO(b/30808791): Remove this hack when the NanoApp API is fixed,
        //     and getAppId() returns a 'long' instead of an 'int'.
        if ((appId >> 32) != 0) {
            // We're unlikely to notice this warning, but at least
            // we can avoid running our hack logic.
            Log.w(TAG, "Code has not been updated since API fix.");
        } else {
            appId = parseAppId(app);
        }

        msgHeader[HEADER_FIELD_LOAD_APP_ID_LO] = (int)(appId & 0xFFFFFFFF);
        msgHeader[HEADER_FIELD_LOAD_APP_ID_HI] = (int)((appId >> 32) & 0xFFFFFFFF);