diff options
| author | Ashutosh Joshi <ashutoshj@google.com> | 2016-04-01 20:48:13 +0000 |
|---|---|---|
| committer | Ashutosh Joshi <ashutoshj@google.com> | 2016-04-01 20:49:28 +0000 |
| commit | 2c697fb4a8b8f8c0a2acf1fb15027f363f74c2dc (patch) | |
| tree | 8fc2a1d8c3ed152267cd11f16cda157bcfb0b124 /core/java/android | |
| parent | 439a298b1f7372c58f5613025a3513e2dd401f78 (diff) | |
Revert "Added handling apps query response from context hub"
This reverts commit adf75e31f52a7a935a66a884fb55631c7309ee75.
Change-Id: I8391eb57c3a53e686bd817d27860fa6f785113f1
Diffstat (limited to 'core/java/android')
6 files changed, 94 insertions, 189 deletions
diff --git a/core/java/android/hardware/location/ContextHubInfo.java b/core/java/android/hardware/location/ContextHubInfo.java index ae44f1d68c3c..644e29fcaedf 100644 --- a/core/java/android/hardware/location/ContextHubInfo.java +++ b/core/java/android/hardware/location/ContextHubInfo.java @@ -37,7 +37,6 @@ public class ContextHubInfo { private float mStoppedPowerDrawMw; private float mSleepPowerDrawMw; private float mPeakPowerDrawMw; - private int mMaxPacketLengthBytes; private int[] mSupportedSensors; @@ -47,27 +46,6 @@ public class 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 * * @return int - unique system wide identifier @@ -396,4 +374,4 @@ public class ContextHubInfo { return new ContextHubInfo[size]; } }; -}
\ No newline at end of file +} diff --git a/core/java/android/hardware/location/ContextHubManager.java b/core/java/android/hardware/location/ContextHubManager.java index 89edaa9780f6..4ddf7673b58c 100644 --- a/core/java/android/hardware/location/ContextHubManager.java +++ b/core/java/android/hardware/location/ContextHubManager.java @@ -43,6 +43,23 @@ public final class ContextHubManager { 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. */ public abstract static class Callback { @@ -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"); } } diff --git a/core/java/android/hardware/location/ContextHubMessage.java b/core/java/android/hardware/location/ContextHubMessage.java index bca2ae6d2e8f..954e97dc7fce 100644 --- a/core/java/android/hardware/location/ContextHubMessage.java +++ b/core/java/android/hardware/location/ContextHubMessage.java @@ -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); diff --git a/core/java/android/hardware/location/ContextHubService.java b/core/java/android/hardware/location/ContextHubService.java index b65e24e3b81e..274babe6a930 100644 --- a/core/java/android/hardware/location/ContextHubService.java +++ b/core/java/android/hardware/location/ContextHubService.java @@ -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 { + public int registerCallback(IContextHubCallback callback) throws RemoteException{ checkPermissions(); - synchronized(this) { - mCallback = callback; + 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; - - 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; + 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 + + 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 @@ -176,7 +166,7 @@ public class ContextHubService extends IContextHubService.Stub { for(Integer nanoAppInstance : mNanoAppHash.keySet()) { NanoAppInstanceInfo info = mNanoAppHash.get(nanoAppInstance); - if (filter.testMatch(info)){ + if(filter.testMatch(info)){ foundInstances.add(nanoAppInstance); } } @@ -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; - } } + diff --git a/core/java/android/hardware/location/NanoAppFilter.java b/core/java/android/hardware/location/NanoAppFilter.java index 8db70e9c53f1..369f9e44e8d9 100644 --- a/core/java/android/hardware/location/NanoAppFilter.java +++ b/core/java/android/hardware/location/NanoAppFilter.java @@ -20,7 +20,6 @@ package android.hardware.location; import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; -import android.util.Log; /** * @hide @@ -28,8 +27,6 @@ import android.util.Log; @SystemApi public class NanoAppFilter { - private static final String TAG = "NanoAppFilter"; - // The appId, can be set to APP_ID_ANY private long mAppId; @@ -57,10 +54,6 @@ public class NanoAppFilter { * If this flag is set, only versions strictly less than the version specified shall match. */ public static final int FLAGS_VERSION_LESS_THAN = 4; - /** - * If this flag is set, only versions strictly equal to the - * version specified shall match. - */ public static final int FLAGS_VERSION_STRICTLY_EQUAL = 8; /** @@ -124,9 +117,14 @@ public class NanoAppFilter { * @return true if this is a match, false otherwise */ public boolean testMatch(NanoAppInstanceInfo info) { - return (mContextHubId == HUB_ANY || info.getContexthubId() == mContextHubId) && + if ((mContextHubId == HUB_ANY || info.getContexthubId() == mContextHubId) && (mAppId == APP_ANY || info.getAppId() == mAppId) && - (versionsMatch(mVersionRestrictionMask, mAppVersion, info.getAppVersion())); + // (mAppIdVendorMask == VENDOR_ANY) TODO : Expose Vendor mask cleanly + (versionsMatch(mVersionRestrictionMask, mAppVersion, info.getAppVersion()))) { + return true; + } else { + return false; + } } public static final Parcelable.Creator<NanoAppFilter> CREATOR diff --git a/core/java/android/hardware/location/NanoAppInstanceInfo.java b/core/java/android/hardware/location/NanoAppInstanceInfo.java index 977f645db199..ac62919b7931 100644 --- a/core/java/android/hardware/location/NanoAppInstanceInfo.java +++ b/core/java/android/hardware/location/NanoAppInstanceInfo.java @@ -29,7 +29,7 @@ public class NanoAppInstanceInfo { private String mPublisher; private String mName; - private long mAppId; + private int mAppId; private int mAppVersion; private int mNeededReadMemBytes; @@ -59,8 +59,6 @@ public class NanoAppInstanceInfo { * set the publisher name for the app * * @param publisher - name of the publisher - * - * @hide */ public void setPublisher(String publisher) { mPublisher = publisher; @@ -79,8 +77,6 @@ public class NanoAppInstanceInfo { * set the name of the app * * @param name - name of the app - * - * @hide */ public void setName(String name) { mName = name; @@ -91,7 +87,7 @@ public class NanoAppInstanceInfo { * * @return int - application identifier */ - public long getAppId() { + public int getAppId() { return mAppId; } @@ -99,10 +95,8 @@ public class NanoAppInstanceInfo { * Set the application identifier * * @param appId - application identifier - * - * @hide */ - public void setAppId(long appId) { + public void setAppId(int appId) { mAppId = appId; } @@ -119,8 +113,6 @@ public class NanoAppInstanceInfo { * Set the application version * * @param appVersion - version of the app - * - * @hide */ public void setAppVersion(int appVersion) { mAppVersion = appVersion; @@ -139,8 +131,6 @@ public class NanoAppInstanceInfo { * Set the read memory needed by the app * * @param neededReadMemBytes - readable Memory needed in bytes - * - * @hide */ public void setNeededReadMemBytes(int neededReadMemBytes) { mNeededReadMemBytes = neededReadMemBytes; @@ -160,8 +150,6 @@ public class NanoAppInstanceInfo { * * @param neededWriteMemBytes - writable memory needed by the * app - * - * @hide */ public void setNeededWriteMemBytes(int neededWriteMemBytes) { mNeededWriteMemBytes = neededWriteMemBytes; @@ -181,8 +169,6 @@ public class NanoAppInstanceInfo { * * @param neededExecMemBytes - executable memory needed by the * app - * - * @hide */ public void setNeededExecMemBytes(int neededExecMemBytes) { mNeededExecMemBytes = neededExecMemBytes; @@ -201,8 +187,6 @@ public class NanoAppInstanceInfo { * set the sensors needed by this app * * @param neededSensors - all the sensors needed by this app - * - * @hide */ public void setNeededSensors(int[] neededSensors) { mNeededSensors = neededSensors; @@ -222,8 +206,6 @@ public class NanoAppInstanceInfo { * * @param outputEvents - the events that may be generated by * this app - * - * @hide */ public void setOutputEvents(int[] outputEvents) { mOutputEvents = outputEvents; @@ -242,8 +224,6 @@ public class NanoAppInstanceInfo { * set the context hub identifier * * @param contexthubId - system wide unique identifier - * - * @hide */ public void setContexthubId(int contexthubId) { mContexthubId = contexthubId; @@ -262,8 +242,6 @@ public class NanoAppInstanceInfo { * set the handle for an app instance * * @param handle - handle to this instance - * - * @hide */ public void setHandle(int handle) { mHandle = handle; @@ -274,7 +252,7 @@ public class NanoAppInstanceInfo { mPublisher = in.readString(); mName = in.readString(); - mAppId = in.readLong(); + mAppId = in.readInt(); mAppVersion = in.readInt(); mNeededReadMemBytes = in.readInt(); mNeededWriteMemBytes = in.readInt(); @@ -296,7 +274,7 @@ public class NanoAppInstanceInfo { public void writeToParcel(Parcel out, int flags) { out.writeString(mPublisher); out.writeString(mName); - out.writeLong(mAppId); + out.writeInt(mAppId); out.writeInt(mAppVersion); out.writeInt(mContexthubId); out.writeInt(mNeededReadMemBytes); @@ -308,6 +286,7 @@ public class NanoAppInstanceInfo { out.writeInt(mOutputEvents.length); out.writeIntArray(mOutputEvents); + } public static final Parcelable.Creator<NanoAppInstanceInfo> CREATOR |
