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

Commit 6ae82e5d authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I367f977b,Ie64dc512 into main

* changes:
  Check if registered before unregistering in binder death
  Fix service endpoint ID generation logic
parents 6ac7dbfd e579ecb0
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -186,8 +186,10 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
    /** Invoked when the underlying binder of this broker has died at the client process. */
    @Override
    public void binderDied() {
        if (mIsRegistered.get()) {
            unregister();
        }
    }

    /* package */ void attachDeathRecipient() throws RemoteException {
        if (mContextHubEndpointCallback != null) {
+7 −3
Original line number Diff line number Diff line
@@ -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--;
        }
    }