diff options
| -rw-r--r-- | services/core/java/com/android/server/location/contexthub/ContextHubEndpointBroker.java | 4 | ||||
| -rw-r--r-- | services/core/java/com/android/server/location/contexthub/ContextHubEndpointManager.java | 10 |
2 files changed, 10 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubEndpointBroker.java b/services/core/java/com/android/server/location/contexthub/ContextHubEndpointBroker.java index 4a533f42ffea..ef73463122ff 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubEndpointBroker.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubEndpointBroker.java @@ -186,7 +186,9 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub /** Invoked when the underlying binder of this broker has died at the client process. */ @Override public void binderDied() { - unregister(); + if (mIsRegistered.get()) { + unregister(); + } } /* package */ void attachDeathRecipient() throws RemoteException { diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubEndpointManager.java b/services/core/java/com/android/server/location/contexthub/ContextHubEndpointManager.java index 8c5095f35f0d..155a92a21368 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubEndpointManager.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubEndpointManager.java @@ -65,8 +65,12 @@ import java.util.concurrent.ConcurrentHashMap; /** Variables for managing endpoint ID creation */ private final Object mEndpointLock = new Object(); + /** + * The next available endpoint ID to register. Per EndpointId.aidl definition, dynamic + * endpoint IDs must have the left-most bit as 1, and the values 0/-1 are invalid. + */ @GuardedBy("mEndpointLock") - private long mNextEndpointId = 0; + private long mNextEndpointId = -2; /** The minimum session ID reservable by endpoints (retrieved from HAL) */ private final int mMinSessionId; @@ -282,10 +286,10 @@ import java.util.concurrent.ConcurrentHashMap; /** @return an available endpoint ID */ private long getNewEndpointId() { synchronized (mEndpointLock) { - if (mNextEndpointId == Long.MAX_VALUE) { + if (mNextEndpointId >= 0) { throw new IllegalStateException("Too many endpoints connected"); } - return mNextEndpointId++; + return mNextEndpointId--; } } |