Loading services/core/java/com/android/server/location/ContextHubClientBroker.java +10 −7 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.content.Context; import android.hardware.contexthub.V1_0.ContextHubMsg; import android.hardware.contexthub.V1_0.IContexthub; import android.hardware.contexthub.V1_0.Result; import android.hardware.location.ContextHubInfo; import android.hardware.location.ContextHubTransaction; import android.hardware.location.IContextHubClient; import android.hardware.location.IContextHubClientCallback; Loading Loading @@ -57,9 +58,9 @@ public class ContextHubClientBroker extends IContextHubClient.Stub private final ContextHubClientManager mClientManager; /* * The ID of the hub that this client is attached to. * The object describing the hub that this client is attached to. */ private final int mAttachedContextHubId; private final ContextHubInfo mAttachedContextHubInfo; /* * The host end point ID of this client. Loading @@ -85,11 +86,12 @@ public class ContextHubClientBroker extends IContextHubClient.Stub /* package */ ContextHubClientBroker( Context context, IContexthub contextHubProxy, ContextHubClientManager clientManager, int contextHubId, short hostEndPointId, IContextHubClientCallback callback) { ContextHubInfo contextHubInfo, short hostEndPointId, IContextHubClientCallback callback) { mContext = context; mContextHubProxy = contextHubProxy; mClientManager = clientManager; mAttachedContextHubId = contextHubId; mAttachedContextHubInfo = contextHubInfo; mHostEndPointId = hostEndPointId; mCallbackInterface = callback; } Loading Loading @@ -119,11 +121,12 @@ public class ContextHubClientBroker extends IContextHubClient.Stub ContextHubMsg messageToNanoApp = ContextHubServiceUtil.createHidlContextHubMessage( mHostEndPointId, message); int contextHubId = mAttachedContextHubInfo.getId(); try { result = mContextHubProxy.sendMessageToHub(mAttachedContextHubId, messageToNanoApp); result = mContextHubProxy.sendMessageToHub(contextHubId, messageToNanoApp); } catch (RemoteException e) { Log.e(TAG, "RemoteException in sendMessageToNanoApp (target hub ID = " + mAttachedContextHubId + ")", e); + contextHubId + ")", e); result = Result.UNKNOWN_FAILURE; } } else { Loading Loading @@ -156,7 +159,7 @@ public class ContextHubClientBroker extends IContextHubClient.Stub * @return the ID of the context hub this client is attached to */ /* package */ int getAttachedContextHubId() { return mAttachedContextHubId; return mAttachedContextHubInfo.getId(); } /** Loading services/core/java/com/android/server/location/ContextHubClientManager.java +10 −9 Original line number Diff line number Diff line Loading @@ -19,13 +19,13 @@ package com.android.server.location; import android.content.Context; import android.hardware.contexthub.V1_0.ContextHubMsg; import android.hardware.contexthub.V1_0.IContexthub; import android.hardware.location.ContextHubInfo; import android.hardware.location.IContextHubClient; import android.hardware.location.IContextHubClientCallback; import android.hardware.location.NanoAppMessage; import android.os.RemoteException; import android.util.Log; import java.util.NoSuchElementException; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; Loading Loading @@ -80,15 +80,15 @@ import java.util.function.Consumer; * Registers a new client with the service. * * @param clientCallback the callback interface of the client to register * @param contextHubId the ID of the hub this client is attached to * @param contextHubInfo the object describing the hub this client is attached to * * @return the client interface * * @throws IllegalStateException if max number of clients have already registered */ /* package */ IContextHubClient registerClient( IContextHubClientCallback clientCallback, int contextHubId) { ContextHubClientBroker broker = createNewClientBroker(clientCallback, contextHubId); IContextHubClientCallback clientCallback, ContextHubInfo contextHubInfo) { ContextHubClientBroker broker = createNewClientBroker(clientCallback, contextHubInfo); try { broker.attachDeathRecipient(); Loading Loading @@ -183,14 +183,14 @@ import java.util.function.Consumer; * manager. * * @param clientCallback the callback interface of the client to register * @param contextHubId the ID of the hub this client is attached to * @param contextHubInfo the object describing the hub this client is attached to * * @return the ContextHubClientBroker object * * @throws IllegalStateException if max number of clients have already registered */ private synchronized ContextHubClientBroker createNewClientBroker( IContextHubClientCallback clientCallback, int contextHubId) { IContextHubClientCallback clientCallback, ContextHubInfo contextHubInfo) { if (mHostEndPointIdToClientMap.size() == MAX_CLIENT_ID + 1) { throw new IllegalStateException("Could not register client - max limit exceeded"); } Loading @@ -200,7 +200,8 @@ import java.util.function.Consumer; for (int i = 0; i <= MAX_CLIENT_ID; i++) { if (!mHostEndPointIdToClientMap.containsKey((short) id)) { broker = new ContextHubClientBroker( mContext, mContextHubProxy, this, contextHubId, (short)id, clientCallback); mContext, mContextHubProxy, this, contextHubInfo, (short) id, clientCallback); mHostEndPointIdToClientMap.put((short) id, broker); mNextHostEndpointId = (id == MAX_CLIENT_ID) ? 0 : id + 1; break; Loading services/core/java/com/android/server/location/ContextHubService.java +4 −2 Original line number Diff line number Diff line Loading @@ -170,8 +170,9 @@ public class ContextHubService extends IContextHubService.Stub { HashMap<Integer, IContextHubClient> defaultClientMap = new HashMap<>(); for (int contextHubId : mContextHubIdToInfoMap.keySet()) { ContextHubInfo contextHubInfo = mContextHubIdToInfoMap.get(contextHubId); IContextHubClient client = mClientManager.registerClient( createDefaultClientCallback(contextHubId), contextHubId); createDefaultClientCallback(contextHubId), contextHubInfo); defaultClientMap.put(contextHubId, client); try { Loading Loading @@ -623,7 +624,8 @@ public class ContextHubService extends IContextHubService.Stub { throw new NullPointerException("Cannot register client with null callback"); } return mClientManager.registerClient(clientCallback, contextHubId); ContextHubInfo contextHubInfo = mContextHubIdToInfoMap.get(contextHubId); return mClientManager.registerClient(clientCallback, contextHubInfo); } /** Loading Loading
services/core/java/com/android/server/location/ContextHubClientBroker.java +10 −7 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.content.Context; import android.hardware.contexthub.V1_0.ContextHubMsg; import android.hardware.contexthub.V1_0.IContexthub; import android.hardware.contexthub.V1_0.Result; import android.hardware.location.ContextHubInfo; import android.hardware.location.ContextHubTransaction; import android.hardware.location.IContextHubClient; import android.hardware.location.IContextHubClientCallback; Loading Loading @@ -57,9 +58,9 @@ public class ContextHubClientBroker extends IContextHubClient.Stub private final ContextHubClientManager mClientManager; /* * The ID of the hub that this client is attached to. * The object describing the hub that this client is attached to. */ private final int mAttachedContextHubId; private final ContextHubInfo mAttachedContextHubInfo; /* * The host end point ID of this client. Loading @@ -85,11 +86,12 @@ public class ContextHubClientBroker extends IContextHubClient.Stub /* package */ ContextHubClientBroker( Context context, IContexthub contextHubProxy, ContextHubClientManager clientManager, int contextHubId, short hostEndPointId, IContextHubClientCallback callback) { ContextHubInfo contextHubInfo, short hostEndPointId, IContextHubClientCallback callback) { mContext = context; mContextHubProxy = contextHubProxy; mClientManager = clientManager; mAttachedContextHubId = contextHubId; mAttachedContextHubInfo = contextHubInfo; mHostEndPointId = hostEndPointId; mCallbackInterface = callback; } Loading Loading @@ -119,11 +121,12 @@ public class ContextHubClientBroker extends IContextHubClient.Stub ContextHubMsg messageToNanoApp = ContextHubServiceUtil.createHidlContextHubMessage( mHostEndPointId, message); int contextHubId = mAttachedContextHubInfo.getId(); try { result = mContextHubProxy.sendMessageToHub(mAttachedContextHubId, messageToNanoApp); result = mContextHubProxy.sendMessageToHub(contextHubId, messageToNanoApp); } catch (RemoteException e) { Log.e(TAG, "RemoteException in sendMessageToNanoApp (target hub ID = " + mAttachedContextHubId + ")", e); + contextHubId + ")", e); result = Result.UNKNOWN_FAILURE; } } else { Loading Loading @@ -156,7 +159,7 @@ public class ContextHubClientBroker extends IContextHubClient.Stub * @return the ID of the context hub this client is attached to */ /* package */ int getAttachedContextHubId() { return mAttachedContextHubId; return mAttachedContextHubInfo.getId(); } /** Loading
services/core/java/com/android/server/location/ContextHubClientManager.java +10 −9 Original line number Diff line number Diff line Loading @@ -19,13 +19,13 @@ package com.android.server.location; import android.content.Context; import android.hardware.contexthub.V1_0.ContextHubMsg; import android.hardware.contexthub.V1_0.IContexthub; import android.hardware.location.ContextHubInfo; import android.hardware.location.IContextHubClient; import android.hardware.location.IContextHubClientCallback; import android.hardware.location.NanoAppMessage; import android.os.RemoteException; import android.util.Log; import java.util.NoSuchElementException; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; Loading Loading @@ -80,15 +80,15 @@ import java.util.function.Consumer; * Registers a new client with the service. * * @param clientCallback the callback interface of the client to register * @param contextHubId the ID of the hub this client is attached to * @param contextHubInfo the object describing the hub this client is attached to * * @return the client interface * * @throws IllegalStateException if max number of clients have already registered */ /* package */ IContextHubClient registerClient( IContextHubClientCallback clientCallback, int contextHubId) { ContextHubClientBroker broker = createNewClientBroker(clientCallback, contextHubId); IContextHubClientCallback clientCallback, ContextHubInfo contextHubInfo) { ContextHubClientBroker broker = createNewClientBroker(clientCallback, contextHubInfo); try { broker.attachDeathRecipient(); Loading Loading @@ -183,14 +183,14 @@ import java.util.function.Consumer; * manager. * * @param clientCallback the callback interface of the client to register * @param contextHubId the ID of the hub this client is attached to * @param contextHubInfo the object describing the hub this client is attached to * * @return the ContextHubClientBroker object * * @throws IllegalStateException if max number of clients have already registered */ private synchronized ContextHubClientBroker createNewClientBroker( IContextHubClientCallback clientCallback, int contextHubId) { IContextHubClientCallback clientCallback, ContextHubInfo contextHubInfo) { if (mHostEndPointIdToClientMap.size() == MAX_CLIENT_ID + 1) { throw new IllegalStateException("Could not register client - max limit exceeded"); } Loading @@ -200,7 +200,8 @@ import java.util.function.Consumer; for (int i = 0; i <= MAX_CLIENT_ID; i++) { if (!mHostEndPointIdToClientMap.containsKey((short) id)) { broker = new ContextHubClientBroker( mContext, mContextHubProxy, this, contextHubId, (short)id, clientCallback); mContext, mContextHubProxy, this, contextHubInfo, (short) id, clientCallback); mHostEndPointIdToClientMap.put((short) id, broker); mNextHostEndpointId = (id == MAX_CLIENT_ID) ? 0 : id + 1; break; Loading
services/core/java/com/android/server/location/ContextHubService.java +4 −2 Original line number Diff line number Diff line Loading @@ -170,8 +170,9 @@ public class ContextHubService extends IContextHubService.Stub { HashMap<Integer, IContextHubClient> defaultClientMap = new HashMap<>(); for (int contextHubId : mContextHubIdToInfoMap.keySet()) { ContextHubInfo contextHubInfo = mContextHubIdToInfoMap.get(contextHubId); IContextHubClient client = mClientManager.registerClient( createDefaultClientCallback(contextHubId), contextHubId); createDefaultClientCallback(contextHubId), contextHubInfo); defaultClientMap.put(contextHubId, client); try { Loading Loading @@ -623,7 +624,8 @@ public class ContextHubService extends IContextHubService.Stub { throw new NullPointerException("Cannot register client with null callback"); } return mClientManager.registerClient(clientCallback, contextHubId); ContextHubInfo contextHubInfo = mContextHubIdToInfoMap.get(contextHubId); return mClientManager.registerClient(clientCallback, contextHubInfo); } /** Loading