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

Commit 2c697fb4 authored by Ashutosh Joshi's avatar Ashutosh Joshi
Browse files

Revert "Added handling apps query response from context hub"

This reverts commit adf75e31.

Change-Id: I8391eb57c3a53e686bd817d27860fa6f785113f1
parent 439a298b
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -15271,7 +15271,6 @@ package android.hardware.location {
    ctor public ContextHubInfo();
    method public int describeContents();
    method public int getId();
    method public int getMaxPacketLengthBytes();
    method public android.hardware.location.MemoryRegion[] getMemoryRegions();
    method public java.lang.String getName();
    method public float getPeakMips();
@@ -15299,6 +15298,10 @@ package android.hardware.location {
    method public int sendMessage(int, int, android.hardware.location.ContextHubMessage);
    method public int unloadNanoApp(int);
    method public int unregisterCallback(android.hardware.location.ContextHubManager.Callback);
    field public static final int ANY_HUB = -1; // 0xffffffff
    field public static final int MSG_DATA_SEND = 3; // 0x3
    field public static final int MSG_LOAD_NANO_APP = 1; // 0x1
    field public static final int MSG_UNLOAD_NANO_APP = 2; // 0x2
  }
  public static abstract class ContextHubManager.Callback {
@@ -15492,7 +15495,7 @@ package android.hardware.location {
  public class NanoAppInstanceInfo {
    ctor public NanoAppInstanceInfo();
    method public int describeContents();
    method public long getAppId();
    method public int getAppId();
    method public int getAppVersion();
    method public int getContexthubId();
    method public int getHandle();
@@ -15503,6 +15506,17 @@ package android.hardware.location {
    method public int getNeededWriteMemBytes();
    method public int[] getOutputEvents();
    method public java.lang.String getPublisher();
    method public void setAppId(int);
    method public void setAppVersion(int);
    method public void setContexthubId(int);
    method public void setHandle(int);
    method public void setName(java.lang.String);
    method public void setNeededExecMemBytes(int);
    method public void setNeededReadMemBytes(int);
    method public void setNeededSensors(int[]);
    method public void setNeededWriteMemBytes(int);
    method public void setOutputEvents(int[]);
    method public void setPublisher(java.lang.String);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.hardware.location.NanoAppInstanceInfo> CREATOR;
  }
+1 −23
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ public class ContextHubInfo {
    private float mStoppedPowerDrawMw;
    private float mSleepPowerDrawMw;
    private float mPeakPowerDrawMw;
    private int mMaxPacketLengthBytes;

    private int[] mSupportedSensors;

@@ -46,27 +45,6 @@ public class ContextHubInfo {
    public ContextHubInfo() {
    }

    /**
     * returns the maximum number of bytes that can be sent per message to the hub
     *
     * @return int - maximum bytes that can be transmitted in a
     *         single packet
     */
    public int getMaxPacketLengthBytes() {
        return mMaxPacketLengthBytes;
    }

    /**
     * set the context hub unique identifer
     *
     * @param bytes - Maximum number of bytes per message
     *
     * @hide
     */
    public void setMaxPacketLenBytes(int bytes) {
        mMaxPacketLengthBytes = bytes;
    }

    /**
     * get the context hub unique identifer
     *
+29 −17
Original line number Diff line number Diff line
@@ -42,6 +42,23 @@ public final class ContextHubManager {
    private Callback mCallback;
    private Handler mCallbackHandler;

    /**
     * A special context hub identifier meaning any possible hub on the system.
     */
    public static final int ANY_HUB       = -1;
    /**
     * A constant denoting a message to load a a Nano App
     */
    public static final int MSG_LOAD_NANO_APP   = 1;
    /**
     * A constant denoting a message to unload a a Nano App
     */
    public static final int MSG_UNLOAD_NANO_APP = 2;
    /**
     * A constant denoting a message to send a message
     */
    public static final int MSG_DATA_SEND       = 3;

    /**
     * An interface to receive asynchronous communication from the context hub.
     */
@@ -52,7 +69,7 @@ public final class ContextHubManager {
         * Callback function called on message receipt from context hub.
         *
         * @param hubHandle Handle (system-wide unique identifier) of the hub of the message.
         * @param nanoAppHandle Handle (unique identifier) for app instance that sent the message.
         * @param nanoAppHandle Handle (unique identifier) for the app that sent the message.
         * @param message The context hub message.
         *
         * @see ContextHubMessage
@@ -72,7 +89,7 @@ public final class ContextHubManager {
        try {
            retVal = getBinder().getContextHubHandles();
        } catch (RemoteException e) {
            Log.w(TAG, "Could not fetch context hub handles : " + e);
            Log.e(TAG, "Could not fetch context hub handles : " + e);
        }
        return retVal;
    }
@@ -90,7 +107,7 @@ public final class ContextHubManager {
        try {
            retVal = getBinder().getContextHubInfo(hubHandle);
        } catch (RemoteException e) {
            Log.w(TAG, "Could not fetch context hub info :" + e);
            Log.e(TAG, "Could not fetch context hub info :" + e);
        }

        return retVal;
@@ -109,7 +126,6 @@ public final class ContextHubManager {
     */
    public int loadNanoApp(int hubHandle, NanoApp app) {
        int retVal = -1;

        if (app == null) {
            return retVal;
        }
@@ -117,7 +133,7 @@ public final class ContextHubManager {
        try {
            retVal = getBinder().loadNanoApp(hubHandle, app);
        } catch (RemoteException e) {
            Log.w(TAG, "Could not load nanoApp :" + e);
            Log.e(TAG, "Could not fetch load nanoApp :" + e);
        }

        return retVal;
@@ -136,7 +152,7 @@ public final class ContextHubManager {
        try {
            retVal = getBinder().unloadNanoApp(nanoAppHandle);
        } catch (RemoteException e) {
            Log.w(TAG, "Could not fetch unload nanoApp :" + e);
            Log.e(TAG, "Could not fetch unload nanoApp :" + e);
        }

        return retVal;
@@ -156,7 +172,7 @@ public final class ContextHubManager {
        try {
            retVal = getBinder().getNanoAppInstanceInfo(nanoAppHandle);
        } catch (RemoteException e) {
            Log.w(TAG, "Could not fetch nanoApp info :" + e);
            Log.e(TAG, "Could not fetch nanoApp info :" + e);
        }

        return retVal;
@@ -177,7 +193,7 @@ public final class ContextHubManager {
        try {
            retVal = getBinder().findNanoAppOnHub(hubHandle, filter);
        } catch (RemoteException e) {
            Log.w(TAG, "Could not query nanoApp instance :" + e);
            Log.e(TAG, "Could not query nanoApp instance :" + e);
        }
        return retVal;
    }
@@ -196,14 +212,10 @@ public final class ContextHubManager {
    public int sendMessage(int hubHandle, int nanoAppHandle, ContextHubMessage message) {
        int retVal = -1;

        if (message == null || message.getData() == null) {
            Log.w(TAG, "null ptr");
            return retVal;
        }
        try {
            retVal = getBinder().sendMessage(hubHandle, nanoAppHandle, message);
        } catch (RemoteException e) {
            Log.w(TAG, "Could not send message :" + e.toString());
            Log.e(TAG, "Could not fetch send message :" + e.toString());
        }

        return retVal;
@@ -235,7 +247,7 @@ public final class ContextHubManager {
    public int registerCallback(Callback callback, Handler handler) {
        synchronized(this) {
            if (mCallback != null) {
                Log.w(TAG, "Max number of callbacks reached!");
                Log.e(TAG, "Max number of callbacks reached!");
                return -1;
            }
            mCallback = callback;
@@ -256,7 +268,7 @@ public final class ContextHubManager {
    public int unregisterCallback(Callback callback) {
      synchronized(this) {
          if (callback != mCallback) {
              Log.w(TAG, "Cannot recognize callback!");
              Log.e(TAG, "Cannot recognize callback!");
              return -1;
          }

@@ -299,11 +311,11 @@ public final class ContextHubManager {
            try {
                getBinder().registerCallback(mClientCallback);
            } catch (RemoteException e) {
                Log.w(TAG, "Could not register callback:" + e);
                Log.e(TAG, "Could not register callback:" + e);
            }

        } else {
            Log.w(TAG, "failed to getService");
            Log.d(TAG, "failed to getService");
        }
    }

+3 −8
Original line number Diff line number Diff line
@@ -16,10 +16,10 @@

package android.hardware.location;


import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

import java.util.Arrays;

@@ -32,9 +32,6 @@ public class ContextHubMessage {
    private int mVersion;
    private byte[]mData;

    private static final String TAG = "ContextHubMessage";


    /**
     * Get the message type
     *
@@ -109,11 +106,9 @@ public class ContextHubMessage {
    private ContextHubMessage(Parcel in) {
        mType = in.readInt();
        mVersion = in.readInt();
        int bufferLength = in.readInt();
        mData = new byte[bufferLength];
        in.readByteArray(mData);
        byte[] byteBuffer = new byte[in.readInt()];
        in.readByteArray(byteBuffer);
    }

    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(mType);
        out.writeInt(mVersion);
+48 −105
Original line number Diff line number Diff line
@@ -29,30 +29,12 @@ import java.util.HashMap;
 */
public class ContextHubService extends IContextHubService.Stub {

    public static final String CONTEXTHUB_SERVICE = "contexthub_service";

    private static final String TAG = "ContextHubService";
    private static final String HARDWARE_PERMISSION = Manifest.permission.LOCATION_HARDWARE;
    private static final String ENFORCE_HW_PERMISSION_MESSAGE = "Permission '"
            + HARDWARE_PERMISSION + "' not granted to access ContextHub Hardware";


    public static final int ANY_HUB             = -1;
    public static final int MSG_LOAD_NANO_APP   = 5;
    public static final int MSG_UNLOAD_NANO_APP = 2;

    private static final String PRE_LOADED_GENERIC_UNKNOWN = "Preloaded app, unknown";
    private static final String PRE_LOADED_APP_NAME = PRE_LOADED_GENERIC_UNKNOWN;
    private static final String PRE_LOADED_APP_PUBLISHER = PRE_LOADED_GENERIC_UNKNOWN;
    private static final int PRE_LOADED_APP_MEM_REQ = 0;

    private static final int MSG_HEADER_SIZE = 4;
    private static final int MSG_FIELD_TYPE = 0;
    private static final int MSG_FIELD_VERSION = 1;
    private static final int MSG_FIELD_HUB_HANDLE = 2;
    private static final int MSG_FIELD_APP_INSTANCE = 3;

    private static final int OS_APP_INSTANCE = -1;
    public static final String CONTEXTHUB_SERVICE = "contexthub_service";

    private final Context mContext;

@@ -60,27 +42,44 @@ public class ContextHubService extends IContextHubService.Stub {
    private ContextHubInfo[] mContextHubInfo;
    private IContextHubCallback mCallback;

    private native int nativeSendMessage(int[] header, byte[] data);
    private native ContextHubInfo[] nativeInitialize();


    public ContextHubService(Context context) {
        mContext = context;
        mContextHubInfo = nativeInitialize();
        mNanoAppHash = new HashMap<Integer, NanoAppInstanceInfo>();

        for (int i = 0; i < mContextHubInfo.length; i++) {
            Log.d(TAG, "ContextHub[" + i + "] id: " + mContextHubInfo[i].getId()
            Log.v(TAG, "ContextHub[" + i + "] id: " + mContextHubInfo[i].getId()
                  + ", name:  " + mContextHubInfo[i].getName());
        }
    }

    private native int nativeSendMessage(int[] header, byte[] data);
    private native ContextHubInfo[] nativeInitialize();

    @Override
    public int registerCallback(IContextHubCallback callback) throws RemoteException{
        checkPermissions();
        synchronized(this) {
        mCallback = callback;
        return 0;
    }


    private int onMessageReceipt(int[] header, byte[] data) {
        if (mCallback != null) {
            // TODO : Defend against unexpected header sizes
            //        Add abstraction for magic numbers
            //        onMessageRecipt should pass the right arguments
            ContextHubMessage msg = new ContextHubMessage(header[0], header[1], data);

            try {
                mCallback.onMessageReceipt(0, 0, msg);
            } catch (Exception e) {
                Log.e(TAG, "Exception " + e + " when calling remote callback");
                return -1;
            }
        } else {
            Log.d(TAG, "Message Callback is NULL");
        }

        return 0;
    }

@@ -119,17 +118,14 @@ public class ContextHubService extends IContextHubService.Stub {
        }

        // Call Native interface here
        int[] msgHeader = new int[MSG_HEADER_SIZE];
        msgHeader[MSG_FIELD_HUB_HANDLE] = contextHubHandle;
        msgHeader[MSG_FIELD_APP_INSTANCE] = OS_APP_INSTANCE;
        msgHeader[MSG_FIELD_VERSION] = 0;
        msgHeader[MSG_FIELD_TYPE] = MSG_LOAD_NANO_APP;
        int[] msgHeader = new int[8];
        msgHeader[0] = contextHubHandle;
        msgHeader[1] = app.getAppId();
        msgHeader[2] = app.getAppVersion();
        msgHeader[3] = ContextHubManager.MSG_LOAD_NANO_APP;
        msgHeader[4] = 0; // Loading hints

        if (nativeSendMessage(msgHeader, app.getAppBinary()) != 0) {
            return -1;
        }
        // Do not add an entry to mNanoAppInstance Hash yet. The HAL may reject the app
        return 0;
        return nativeSendMessage(msgHeader, app.getAppBinary());
    }

    @Override
@@ -141,18 +137,12 @@ public class ContextHubService extends IContextHubService.Stub {
        }

        // Call Native interface here
        int[] msgHeader = new int[MSG_HEADER_SIZE];
        msgHeader[MSG_FIELD_HUB_HANDLE] = ANY_HUB;
        msgHeader[MSG_FIELD_APP_INSTANCE] = OS_APP_INSTANCE;
        msgHeader[MSG_FIELD_VERSION] = 0;
        msgHeader[MSG_FIELD_TYPE] = MSG_UNLOAD_NANO_APP;

        if(nativeSendMessage(msgHeader, null) != 0) {
            return -1;
        }
        int[] msgHeader = new int[8];
        msgHeader[0] = info.getContexthubId();
        msgHeader[1] = ContextHubManager.MSG_UNLOAD_NANO_APP;
        msgHeader[2] = info.getHandle();

        // Do not add an entry to mNanoAppInstance Hash yet. The HAL may reject the app
        return 0;
        return nativeSendMessage(msgHeader, null);
    }

    @Override
@@ -193,12 +183,12 @@ public class ContextHubService extends IContextHubService.Stub {
    public int sendMessage(int hubHandle, int nanoAppHandle, ContextHubMessage msg)
            throws RemoteException {
        checkPermissions();

        int[] msgHeader = new int[MSG_HEADER_SIZE];
        msgHeader[MSG_FIELD_HUB_HANDLE] = hubHandle;
        msgHeader[MSG_FIELD_APP_INSTANCE] = nanoAppHandle;
        msgHeader[MSG_FIELD_VERSION] = msg.getVersion();
        msgHeader[MSG_FIELD_TYPE] = msg.getMsgType();
        int[] msgHeader = new int[8];
        msgHeader[0] = ContextHubManager.MSG_DATA_SEND;
        msgHeader[1] = hubHandle;
        msgHeader[2] = nanoAppHandle;
        msgHeader[3] = msg.getMsgType();
        msgHeader[4] = msg.getVersion();

        return nativeSendMessage(msgHeader, msg.getData());
    }
@@ -206,52 +196,5 @@ public class ContextHubService extends IContextHubService.Stub {
    private void checkPermissions() {
        mContext.enforceCallingPermission(HARDWARE_PERMISSION, ENFORCE_HW_PERMISSION_MESSAGE);
    }

    private int onMessageReceipt(int[] header, byte[] data) {
        if (header == null || data == null || header.length < MSG_HEADER_SIZE) {
            return  -1;
}
        synchronized(this) {
            if (mCallback != null) {
                ContextHubMessage msg = new ContextHubMessage(header[MSG_FIELD_TYPE],
                        header[MSG_FIELD_VERSION],
                        data);

                try {
                    mCallback.onMessageReceipt(header[MSG_FIELD_HUB_HANDLE],
                            header[MSG_FIELD_APP_INSTANCE],
                            msg);
                } catch (Exception e) {
                    Log.w(TAG, "Exception " + e + " when calling remote callback");
                    return -1;
                }
            } else {
                Log.d(TAG, "Message Callback is NULL");
            }
        }

        return 0;
    }

    private int addAppInstance(int hubHandle, int appInstanceHandle, long appId, int appVersion) {
        // App Id encodes vendor & version
        NanoAppInstanceInfo appInfo = new NanoAppInstanceInfo();

        appInfo.setAppId(appId);
        appInfo.setAppVersion(appVersion);
        appInfo.setName(PRE_LOADED_APP_NAME);
        appInfo.setContexthubId(hubHandle);
        appInfo.setHandle(appInstanceHandle);
        appInfo.setPublisher(PRE_LOADED_APP_PUBLISHER);
        appInfo.setNeededExecMemBytes(PRE_LOADED_APP_MEM_REQ);
        appInfo.setNeededReadMemBytes(PRE_LOADED_APP_MEM_REQ);
        appInfo.setNeededWriteMemBytes(PRE_LOADED_APP_MEM_REQ);

        mNanoAppHash.put(appInstanceHandle, appInfo);
        Log.d(TAG, "Added app instance " + appInstanceHandle + " with id " + appId
              + " version " + appVersion);

        return 0;
    }
}
Loading