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

Commit ed470daf authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Remove HIDL references in ContextHubClientBroker/Manager

Bug: 194285834
Test: Presubmits
Change-Id: I91394259f819005cecf297d3268e85b4b4fb95bc
parent ab1d302c
Loading
Loading
Loading
Loading
+6 −11
Original line number Original line Diff line number Diff line
@@ -30,8 +30,6 @@ import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledAfter;
import android.compat.annotation.EnabledAfter;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.hardware.contexthub.V1_0.ContextHubMsg;
import android.hardware.contexthub.V1_0.Result;
import android.hardware.location.ContextHubInfo;
import android.hardware.location.ContextHubInfo;
import android.hardware.location.ContextHubManager;
import android.hardware.location.ContextHubManager;
import android.hardware.location.ContextHubTransaction;
import android.hardware.location.ContextHubTransaction;
@@ -383,23 +381,20 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
                checkNanoappPermsAsync();
                checkNanoappPermsAsync();
            }
            }


            ContextHubMsg messageToNanoApp =
                    ContextHubServiceUtil.createHidlContextHubMessage(mHostEndPointId, message);

            int contextHubId = mAttachedContextHubInfo.getId();
            try {
            try {
                result = mContextHubProxy.getHub().sendMessageToHub(contextHubId, messageToNanoApp);
                result = mContextHubProxy.sendMessageToContextHub(
                    mHostEndPointId, mAttachedContextHubInfo.getId(), message);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
                Log.e(TAG, "RemoteException in sendMessageToNanoApp (target hub ID = "
                Log.e(TAG, "RemoteException in sendMessageToNanoApp (target hub ID = "
                        + contextHubId + ")", e);
                        + mAttachedContextHubInfo.getId() + ")", e);
                result = Result.UNKNOWN_FAILURE;
                result = ContextHubTransaction.RESULT_FAILED_UNKNOWN;
            }
            }
        } else {
        } else {
            Log.e(TAG, "Failed to send message to nanoapp: client connection is closed");
            Log.e(TAG, "Failed to send message to nanoapp: client connection is closed");
            result = Result.UNKNOWN_FAILURE;
            result = ContextHubTransaction.RESULT_FAILED_UNKNOWN;
        }
        }


        return ContextHubServiceUtil.toTransactionResult(result);
        return result;
    }
    }


    /**
    /**
+11 −12
Original line number Original line Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.server.location.contexthub;
import android.annotation.IntDef;
import android.annotation.IntDef;
import android.app.PendingIntent;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Context;
import android.hardware.contexthub.V1_0.ContextHubMsg;
import android.hardware.location.ContextHubInfo;
import android.hardware.location.ContextHubInfo;
import android.hardware.location.IContextHubClient;
import android.hardware.location.IContextHubClient;
import android.hardware.location.IContextHubClientCallback;
import android.hardware.location.IContextHubClientCallback;
@@ -227,37 +226,37 @@ import java.util.function.Consumer;
     * Handles a message sent from a nanoapp.
     * Handles a message sent from a nanoapp.
     *
     *
     * @param contextHubId the ID of the hub where the nanoapp sent the message from
     * @param contextHubId the ID of the hub where the nanoapp sent the message from
     * @param hostEndpointId The host endpoint ID of the client that this message is for.
     * @param message the message send by a nanoapp
     * @param message the message send by a nanoapp
     * @param nanoappPermissions the set of permissions the nanoapp holds
     * @param nanoappPermissions the set of permissions the nanoapp holds
     * @param messagePermissions the set of permissions that should be used for attributing
     * @param messagePermissions the set of permissions that should be used for attributing
     * permissions when this message is consumed by a client
     * permissions when this message is consumed by a client
     */
     */
    /* package */ void onMessageFromNanoApp(
    /* package */ void onMessageFromNanoApp(
            int contextHubId, ContextHubMsg message, List<String> nanoappPermissions,
            int contextHubId, short hostEndpointId, NanoAppMessage message,
            List<String> messagePermissions) {
            List<String> nanoappPermissions, List<String> messagePermissions) {
        NanoAppMessage clientMessage = ContextHubServiceUtil.createNanoAppMessage(message);

        if (DEBUG_LOG_ENABLED) {
        if (DEBUG_LOG_ENABLED) {
            Log.v(TAG, "Received " + clientMessage);
            Log.v(TAG, "Received " + message);
        }
        }


        if (clientMessage.isBroadcastMessage()) {
        if (message.isBroadcastMessage()) {
            // Broadcast messages shouldn't be sent with any permissions tagged per CHRE API
            // Broadcast messages shouldn't be sent with any permissions tagged per CHRE API
            // requirements.
            // requirements.
            if (!messagePermissions.isEmpty()) {
            if (!messagePermissions.isEmpty()) {
                Log.wtf(TAG, "Received broadcast message with permissions from " + message.appName);
                Log.wtf(TAG, "Received broadcast message with permissions from "
                        + message.getNanoAppId());
            }
            }


            broadcastMessage(
            broadcastMessage(
                    contextHubId, clientMessage, nanoappPermissions, messagePermissions);
                    contextHubId, message, nanoappPermissions, messagePermissions);
        } else {
        } else {
            ContextHubClientBroker proxy = mHostEndPointIdToClientMap.get(message.hostEndPoint);
            ContextHubClientBroker proxy = mHostEndPointIdToClientMap.get(hostEndpointId);
            if (proxy != null) {
            if (proxy != null) {
                proxy.sendMessageToClient(
                proxy.sendMessageToClient(
                        clientMessage, nanoappPermissions, messagePermissions);
                        message, nanoappPermissions, messagePermissions);
            } else {
            } else {
                Log.e(TAG, "Cannot send message to unregistered client (host endpoint ID = "
                Log.e(TAG, "Cannot send message to unregistered client (host endpoint ID = "
                        + message.hostEndPoint + ")");
                        + hostEndpointId + ")");
            }
            }
        }
        }
    }
    }
+3 −1
Original line number Original line Diff line number Diff line
@@ -636,8 +636,10 @@ public class ContextHubService extends IContextHubService.Stub {
    private void handleClientMessageCallback(
    private void handleClientMessageCallback(
            int contextHubId, ContextHubMsg message, List<String> nanoappPermissions,
            int contextHubId, ContextHubMsg message, List<String> nanoappPermissions,
            List<String> messagePermissions) {
            List<String> messagePermissions) {
        NanoAppMessage clientMessage = ContextHubServiceUtil.createNanoAppMessage(message);
        mClientManager.onMessageFromNanoApp(
        mClientManager.onMessageFromNanoApp(
                contextHubId, message, nanoappPermissions, messagePermissions);
                contextHubId, message.hostEndPoint, clientMessage, nanoappPermissions,
                messagePermissions);
    }
    }


    /**
    /**
+46 −7
Original line number Original line Diff line number Diff line
@@ -17,10 +17,13 @@ package com.android.server.location.contexthub;


import android.annotation.Nullable;
import android.annotation.Nullable;
import android.hardware.contexthub.V1_0.ContextHub;
import android.hardware.contexthub.V1_0.ContextHub;
import android.hardware.contexthub.V1_0.ContextHubMsg;
import android.hardware.contexthub.V1_1.Setting;
import android.hardware.contexthub.V1_1.Setting;
import android.hardware.contexthub.V1_1.SettingValue;
import android.hardware.contexthub.V1_1.SettingValue;
import android.hardware.contexthub.V1_2.IContexthubCallback;
import android.hardware.contexthub.V1_2.IContexthubCallback;
import android.hardware.location.ContextHubInfo;
import android.hardware.location.ContextHubInfo;
import android.hardware.location.ContextHubTransaction;
import android.hardware.location.NanoAppMessage;
import android.os.RemoteException;
import android.os.RemoteException;
import android.util.Log;
import android.util.Log;
import android.util.Pair;
import android.util.Pair;
@@ -148,21 +151,55 @@ public abstract class IContextHubWrapper {
    public abstract void onAirplaneModeSettingChanged(boolean enabled);
    public abstract void onAirplaneModeSettingChanged(boolean enabled);


    /**
    /**
     * @return True if this version of the Contexthub HAL supports microphone
     * @return True if this version of the Contexthub HAL supports microphone disable setting
     * disable setting notifications.
     * notifications.
     */
     */
    public abstract boolean supportsMicrophoneDisableSettingNotifications();
    public abstract boolean supportsMicrophoneDisableSettingNotifications();


    /**
    /**
     * Notifies the Contexthub implementation of a microphone disable setting
     * Notifies the Contexthub implementation of a microphone disable setting change.
     * change.
     */
     */
    public abstract void onMicrophoneDisableSettingChanged(boolean enabled);
    public abstract void onMicrophoneDisableSettingChanged(boolean enabled);


    private static class ContextHubWrapperV1_0 extends IContextHubWrapper {
    /**
     * Sends a message to the Context Hub.
     *
     * @param hostEndpointId The host endpoint ID of the sender.
     * @param contextHubId   The ID of the Context Hub to send the message to.
     * @param message        The message to send.
     * @return the result of the message sending.
     */
    @ContextHubTransaction.Result
    public abstract int sendMessageToContextHub(
            short hostEndpointId, int contextHubId, NanoAppMessage message)
            throws RemoteException;

    /**
     * An abstract call that defines methods common to all HIDL IContextHubWrappers.
     */
    private abstract static class ContextHubWrapperHidl extends IContextHubWrapper {
        private android.hardware.contexthub.V1_0.IContexthub mHub;

        ContextHubWrapperHidl(android.hardware.contexthub.V1_0.IContexthub hub) {
            mHub = hub;
        }

        @ContextHubTransaction.Result
        public int sendMessageToContextHub(
                short hostEndpointId, int contextHubId, NanoAppMessage message)
                throws RemoteException {
            ContextHubMsg messageToNanoApp =
                    ContextHubServiceUtil.createHidlContextHubMessage(hostEndpointId, message);
            return ContextHubServiceUtil.toTransactionResult(
                    mHub.sendMessageToHub(contextHubId, messageToNanoApp));
        }
    }

    private static class ContextHubWrapperV1_0 extends ContextHubWrapperHidl {
        private android.hardware.contexthub.V1_0.IContexthub mHub;
        private android.hardware.contexthub.V1_0.IContexthub mHub;


        ContextHubWrapperV1_0(android.hardware.contexthub.V1_0.IContexthub hub) {
        ContextHubWrapperV1_0(android.hardware.contexthub.V1_0.IContexthub hub) {
            super(hub);
            mHub = hub;
            mHub = hub;
        }
        }


@@ -212,10 +249,11 @@ public abstract class IContextHubWrapper {
        }
        }
    }
    }


    private static class ContextHubWrapperV1_1 extends IContextHubWrapper {
    private static class ContextHubWrapperV1_1 extends ContextHubWrapperHidl {
        private android.hardware.contexthub.V1_1.IContexthub mHub;
        private android.hardware.contexthub.V1_1.IContexthub mHub;


        ContextHubWrapperV1_1(android.hardware.contexthub.V1_1.IContexthub hub) {
        ContextHubWrapperV1_1(android.hardware.contexthub.V1_1.IContexthub hub) {
            super(hub);
            mHub = hub;
            mHub = hub;
        }
        }


@@ -271,7 +309,7 @@ public abstract class IContextHubWrapper {
        }
        }
    }
    }


    private static class ContextHubWrapperV1_2 extends IContextHubWrapper
    private static class ContextHubWrapperV1_2 extends ContextHubWrapperHidl
            implements android.hardware.contexthub.V1_2.IContexthub.getHubs_1_2Callback {
            implements android.hardware.contexthub.V1_2.IContexthub.getHubs_1_2Callback {
        private final android.hardware.contexthub.V1_2.IContexthub mHub;
        private final android.hardware.contexthub.V1_2.IContexthub mHub;


@@ -279,6 +317,7 @@ public abstract class IContextHubWrapper {
                new Pair<>(Collections.emptyList(), Collections.emptyList());
                new Pair<>(Collections.emptyList(), Collections.emptyList());


        ContextHubWrapperV1_2(android.hardware.contexthub.V1_2.IContexthub hub) {
        ContextHubWrapperV1_2(android.hardware.contexthub.V1_2.IContexthub hub) {
            super(hub);
            mHub = hub;
            mHub = hub;
        }
        }