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

Commit 537efd66 authored by Yifei Zhang's avatar Yifei Zhang Committed by Android (Google) Code Review
Browse files

Merge changes I5db76661,I6b0aa64e into main

* changes:
  contexthub: reject endpoint registration with null cb
  HubEndpoint: reject session if no lifecycle cb
parents 34e11dc8 812d5ec9
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -126,7 +126,16 @@ public class HubEndpoint {
                    if (sessionExists) {
                        Log.w(
                                TAG,
                                "onSessionOpenComplete: session already exists, id=" + sessionId);
                                "onSessionOpenRequest: session already exists, id=" + sessionId);
                    }

                    if (mLifecycleCallback == null) {
                        Log.w(
                                TAG,
                                "onSessionOpenRequest: "
                                        + "failed to open session, no lifecycle callback attached",
                                new Exception());
                        rejectSession(sessionId);
                    }

                    if (!sessionExists && mLifecycleCallback != null) {
+12 −15
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.location.contexthub;

import android.annotation.NonNull;
import android.app.AppOpsManager;
import android.content.Context;
import android.hardware.contexthub.EndpointInfo;
@@ -64,7 +65,7 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
     * Internal interface used to invoke client callbacks.
     */
    interface CallbackConsumer {
        void accept(IContextHubEndpointCallback callback) throws RemoteException;
        void accept(@NonNull IContextHubEndpointCallback callback) throws RemoteException;
    }

    /** The context of the service. */
@@ -86,7 +87,7 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
    private final EndpointInfo mHalEndpointInfo;

    /** The remote callback interface for this endpoint. */
    private final IContextHubEndpointCallback mContextHubEndpointCallback;
    @NonNull private final IContextHubEndpointCallback mContextHubEndpointCallback;

    /** True if this endpoint is registered with the service/HAL. */
    @GuardedBy("mRegistrationLock")
@@ -158,7 +159,7 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
            IEndpointCommunication hubInterface,
            ContextHubEndpointManager endpointManager,
            EndpointInfo halEndpointInfo,
            IContextHubEndpointCallback callback,
            @NonNull IContextHubEndpointCallback callback,
            String packageName,
            String attributionTag,
            ContextHubTransactionManager transactionManager) {
@@ -419,10 +420,8 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
    }

    /* package */ void attachDeathRecipient() throws RemoteException {
        if (mContextHubEndpointCallback != null) {
        mContextHubEndpointCallback.asBinder().linkToDeath(this, 0 /* flags */);
    }
    }

    /* package */ void onEndpointSessionOpenRequest(
            int sessionId, HubEndpointInfo initiator, String serviceDescriptor) {
@@ -664,7 +663,6 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
     * @return false if the callback threw a RemoteException
     */
    private boolean invokeCallback(CallbackConsumer consumer) {
        if (mContextHubEndpointCallback != null) {
        acquireWakeLock();
        try {
            consumer.accept(mContextHubEndpointCallback);
@@ -673,7 +671,6 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
            releaseWakeLock();
            return false;
        }
        }
        return true;
    }

+2 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.location.contexthub;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.content.Context;
import android.hardware.contexthub.ContextHubInfo;
import android.hardware.contexthub.EndpointInfo;
@@ -240,7 +241,7 @@ import java.util.function.Consumer;
     */
    /* package */ IContextHubEndpoint registerEndpoint(
            HubEndpointInfo pendingEndpointInfo,
            IContextHubEndpointCallback callback,
            @NonNull IContextHubEndpointCallback callback,
            String packageName,
            String attributionTag)
            throws RemoteException {
+4 −0
Original line number Diff line number Diff line
@@ -792,6 +792,10 @@ public class ContextHubService extends IContextHubService.Stub {
            Log.e(TAG, "Endpoint manager failed to initialize");
            throw new UnsupportedOperationException("Endpoint registration is not supported");
        }
        if (callback == null) {
            Log.e(TAG, "Endpoint callback is invalid");
            throw new IllegalArgumentException("registerEndpoint must have a non-null callback");
        }
        return mEndpointManager.registerEndpoint(
                pendingHubEndpointInfo, callback, packageName, attributionTag);
    }