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

Commit 2e7c7652 authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Implements death recipient handler at ContextHubEndpointBroker

Bug: 378487799
Flag: android.chre.flags.offload_implementation
Test: make services

Change-Id: I1a50d511dca33f5e072258aae9705e47b80b028c
parent e9979035
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.hardware.contexthub.HubServiceInfo;
import android.hardware.contexthub.IContextHubEndpoint;
import android.hardware.contexthub.IContextHubEndpointCallback;
import android.hardware.location.IContextHubTransactionCallback;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

@@ -35,7 +36,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
 *
 * @hide
 */
public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub {
public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
        implements IBinder.DeathRecipient {
    private static final String TAG = "ContextHubEndpointBroker";

    /** The context of the service. */
@@ -140,4 +142,16 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub {
    public void sendMessageDeliveryStatus(int sessionId, int messageSeqNumber, byte errorCode) {
        // TODO(b/381102453): Implement this
    }

    /** Invoked when the underlying binder of this broker has died at the client process. */
    @Override
    public void binderDied() {
        unregister();
    }

    /* package */ void attachDeathRecipient() throws RemoteException {
        if (mContextHubEndpointCallback != null) {
            mContextHubEndpointCallback.asBinder().linkToDeath(this, 0 /* flags */);
        }
    }
}
+8 −1
Original line number Diff line number Diff line
@@ -152,7 +152,14 @@ import java.util.concurrent.ConcurrentHashMap;
                        callback);
        mEndpointMap.put(endpointId, broker);

        // TODO(b/378487799): Add death recipient
        try {
            broker.attachDeathRecipient();
        } catch (RemoteException e) {
            // The client process has died, so we close the connection and return null
            Log.e(TAG, "Failed to attach death recipient to client", e);
            broker.unregister();
            return null;
        }

        Log.d(TAG, "Registered endpoint with ID = " + endpointId);
        return IContextHubEndpoint.Stub.asInterface(broker);