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

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

Merge "Converts HAL reason to HubEndpoint.Reason" into main

parents 41ef600b 1281393c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -276,7 +276,8 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub
        }
        if (mContextHubEndpointCallback != null) {
            try {
                mContextHubEndpointCallback.onSessionClosed(sessionId, reason);
                mContextHubEndpointCallback.onSessionClosed(
                        sessionId, ContextHubServiceUtil.toAppHubEndpointReason(reason));
            } catch (RemoteException e) {
                Log.e(TAG, "RemoteException while calling onSessionClosed", e);
            }
+33 −0
Original line number Diff line number Diff line
@@ -19,10 +19,12 @@ package com.android.server.location.contexthub;
import android.Manifest;
import android.content.Context;
import android.hardware.contexthub.EndpointInfo;
import android.hardware.contexthub.HubEndpoint;
import android.hardware.contexthub.HubEndpointInfo;
import android.hardware.contexthub.HubMessage;
import android.hardware.contexthub.HubServiceInfo;
import android.hardware.contexthub.Message;
import android.hardware.contexthub.Reason;
import android.hardware.contexthub.V1_0.AsyncEventType;
import android.hardware.contexthub.V1_0.ContextHubMsg;
import android.hardware.contexthub.V1_0.HostEndPoint;
@@ -502,4 +504,35 @@ import java.util.List;
                message.content,
                HubMessage.DeliveryParams.makeBasic().setResponseRequired(isReliable));
    }

    /**
     * Converts a byte integer defined by Reason.aidl to HubEndpoint.Reason values exposed to apps.
     *
     * @param reason The Reason.aidl value
     * @return The converted HubEndpoint.Reason value
     */
    /* package */
    static @HubEndpoint.Reason int toAppHubEndpointReason(byte reason) {
        switch (reason) {
            case Reason.UNSPECIFIED:
            case Reason.OUT_OF_MEMORY:
            case Reason.TIMEOUT:
                return HubEndpoint.REASON_FAILURE;
            case Reason.OPEN_ENDPOINT_SESSION_REQUEST_REJECTED:
                return HubEndpoint.REASON_OPEN_ENDPOINT_SESSION_REQUEST_REJECTED;
            case Reason.CLOSE_ENDPOINT_SESSION_REQUESTED:
                return HubEndpoint.REASON_CLOSE_ENDPOINT_SESSION_REQUESTED;
            case Reason.ENDPOINT_INVALID:
                return HubEndpoint.REASON_ENDPOINT_INVALID;
            case Reason.ENDPOINT_GONE:
            case Reason.ENDPOINT_CRASHED:
            case Reason.HUB_RESET:
                return HubEndpoint.REASON_ENDPOINT_STOPPED;
            case Reason.PERMISSION_DENIED:
                return HubEndpoint.REASON_PERMISSION_DENIED;
            default:
                Log.w(TAG, "toAppHubEndpointReason: invalid reason: " + reason);
                return HubEndpoint.REASON_FAILURE;
        }
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -198,7 +198,8 @@ class HubInfoRegistry implements ContextHubHalEndpointCallback.IEndpointLifecycl
                removedInfoList.toArray(new HubEndpointInfo[removedInfoList.size()]),
                (cb, infoList) -> {
                    try {
                        cb.onEndpointsStopped(infoList, reason);
                        cb.onEndpointsStopped(
                                infoList, ContextHubServiceUtil.toAppHubEndpointReason(reason));
                    } catch (RemoteException e) {
                        if (e instanceof DeadObjectException) {
                            Log.w(TAG, "onEndpointStopped: callback died, unregistering");