summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2018-10-20 01:37:01 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2018-10-20 01:37:01 +0000
commitaeb77b3b91cedb29637bb95bcfb98f4eefe92d4d (patch)
treef7adfa03db8949207f6eb3914640f0421d8a4af2
parentf4cdeaa057b538992cd49e4e6cf763c6e98775ac (diff)
parent622ebcb4dd8a7b07dc1990129fd6090e838d03c1 (diff)
Merge "Stores ContextHubInfo in ContextHubClientBroker"
-rw-r--r--services/core/java/com/android/server/location/ContextHubClientBroker.java17
-rw-r--r--services/core/java/com/android/server/location/ContextHubClientManager.java19
-rw-r--r--services/core/java/com/android/server/location/ContextHubService.java6
3 files changed, 24 insertions, 18 deletions
diff --git a/services/core/java/com/android/server/location/ContextHubClientBroker.java b/services/core/java/com/android/server/location/ContextHubClientBroker.java
index b29b7cf5a712..99a04d7b144f 100644
--- a/services/core/java/com/android/server/location/ContextHubClientBroker.java
+++ b/services/core/java/com/android/server/location/ContextHubClientBroker.java
@@ -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;
@@ -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.
@@ -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;
}
@@ -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 {
@@ -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();
}
/**
diff --git a/services/core/java/com/android/server/location/ContextHubClientManager.java b/services/core/java/com/android/server/location/ContextHubClientManager.java
index 4243f02a15b2..eda8c6f8b418 100644
--- a/services/core/java/com/android/server/location/ContextHubClientManager.java
+++ b/services/core/java/com/android/server/location/ContextHubClientManager.java
@@ -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;
@@ -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();
@@ -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");
}
@@ -198,10 +198,11 @@ import java.util.function.Consumer;
ContextHubClientBroker broker = null;
int id = mNextHostEndpointId;
for (int i = 0; i <= MAX_CLIENT_ID; i++) {
- if (!mHostEndPointIdToClientMap.containsKey((short)id)) {
+ if (!mHostEndPointIdToClientMap.containsKey((short) id)) {
broker = new ContextHubClientBroker(
- mContext, mContextHubProxy, this, contextHubId, (short)id, clientCallback);
- mHostEndPointIdToClientMap.put((short)id, broker);
+ mContext, mContextHubProxy, this, contextHubInfo, (short) id,
+ clientCallback);
+ mHostEndPointIdToClientMap.put((short) id, broker);
mNextHostEndpointId = (id == MAX_CLIENT_ID) ? 0 : id + 1;
break;
}
diff --git a/services/core/java/com/android/server/location/ContextHubService.java b/services/core/java/com/android/server/location/ContextHubService.java
index 27509deb958f..96e9337a7932 100644
--- a/services/core/java/com/android/server/location/ContextHubService.java
+++ b/services/core/java/com/android/server/location/ContextHubService.java
@@ -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 {
@@ -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);
}
/**