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

Commit 88cc919c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I0913fafa,I91394259

* changes:
  Remove HIDL references in ContextHubTransactionManager
  Remove HIDL references in ContextHubClientBroker/Manager
parents 9dffffc9 c296119f
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 + ")");
            }
            }
        }
        }
    }
    }
+22 −18
Original line number Original line Diff line number Diff line
@@ -151,7 +151,8 @@ public class ContextHubService extends IContextHubService.Stub {


        @Override
        @Override
        public void handleTxnResult(int transactionId, int result) {
        public void handleTxnResult(int transactionId, int result) {
            handleTransactionResultCallback(mContextHubId, transactionId, result);
            handleTransactionResultCallback(mContextHubId, transactionId,
                    result == TransactionResult.SUCCESS);
        }
        }


        @Override
        @Override
@@ -213,7 +214,7 @@ public class ContextHubService extends IContextHubService.Stub {
        mContextHubInfoList = new ArrayList<>(mContextHubIdToInfoMap.values());
        mContextHubInfoList = new ArrayList<>(mContextHubIdToInfoMap.values());
        mClientManager = new ContextHubClientManager(mContext, mContextHubWrapper);
        mClientManager = new ContextHubClientManager(mContext, mContextHubWrapper);
        mTransactionManager = new ContextHubTransactionManager(
        mTransactionManager = new ContextHubTransactionManager(
                mContextHubWrapper.getHub(), mClientManager, mNanoAppStateManager);
                mContextHubWrapper, mClientManager, mNanoAppStateManager);
        mSensorPrivacyManagerInternal =
        mSensorPrivacyManagerInternal =
                LocalServices.getService(SensorPrivacyManagerInternal.class);
                LocalServices.getService(SensorPrivacyManagerInternal.class);


@@ -559,7 +560,7 @@ public class ContextHubService extends IContextHubService.Stub {


    /**
    /**
     * Performs a query at the specified hub.
     * Performs a query at the specified hub.
     *
     * <p>
     * This method should only be invoked internally by the service, either to update the service
     * This method should only be invoked internally by the service, either to update the service
     * cache or as a result of an explicit query requested by a client through the sendMessage API.
     * cache or as a result of an explicit query requested by a client through the sendMessage API.
     *
     *
@@ -636,8 +637,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);
    }
    }


    /**
    /**
@@ -662,7 +665,7 @@ public class ContextHubService extends IContextHubService.Stub {


    /**
    /**
     * A helper function to handle an unload response from the Context Hub for the old API.
     * A helper function to handle an unload response from the Context Hub for the old API.
     *
     * <p>
     * TODO(b/69270990): Remove this once the old APIs are obsolete.
     * TODO(b/69270990): Remove this once the old APIs are obsolete.
     */
     */
    private void handleUnloadResponseOldApi(int contextHubId, int result) {
    private void handleUnloadResponseOldApi(int contextHubId, int result) {
@@ -676,10 +679,11 @@ public class ContextHubService extends IContextHubService.Stub {
     *
     *
     * @param contextHubId  the ID of the hub the response came from
     * @param contextHubId  the ID of the hub the response came from
     * @param transactionId the ID of the transaction
     * @param transactionId the ID of the transaction
     * @param result        the result of the transaction reported by the hub
     * @param success       true if the transaction succeeded
     */
     */
    private void handleTransactionResultCallback(int contextHubId, int transactionId, int result) {
    private void handleTransactionResultCallback(int contextHubId, int transactionId,
        mTransactionManager.onTransactionResponse(transactionId, result);
            boolean success) {
        mTransactionManager.onTransactionResponse(transactionId, success);
    }
    }


    /**
    /**
@@ -1092,8 +1096,8 @@ public class ContextHubService extends IContextHubService.Stub {
    }
    }


    /**
    /**
     * Obtains the latest microphone disabled setting for the current user
     * Obtains the latest microphone disabled setting for the current user and notifies the Context
     * and notifies the Context Hub.
     * Hub.
     */
     */
    private void sendMicrophoneDisableSettingUpdateForCurrentUser() {
    private void sendMicrophoneDisableSettingUpdateForCurrentUser() {
        boolean isEnabled = mSensorPrivacyManagerInternal.isSensorPrivacyEnabled(
        boolean isEnabled = mSensorPrivacyManagerInternal.isSensorPrivacyEnabled(
@@ -1120,9 +1124,9 @@ public class ContextHubService extends IContextHubService.Stub {
    }
    }


    /**
    /**
     * Send a microphone disable settings update whenever the foreground user changes.
     * Send a microphone disable settings update whenever the foreground user changes. We always
     * We always send a settings update regardless of the previous state for the same user
     * send a settings update regardless of the previous state for the same user since the CHRE
     * since the CHRE framework is expected to handle repeated identical setting update.
     * framework is expected to handle repeated identical setting update.
     */
     */
    public void onUserChanged() {
    public void onUserChanged() {
        Log.d(TAG, "User changed to id: " + getCurrentUserId());
        Log.d(TAG, "User changed to id: " + getCurrentUserId());
+25 −32
Original line number Original line Diff line number Diff line
@@ -16,9 +16,6 @@


package com.android.server.location.contexthub;
package com.android.server.location.contexthub;


import android.hardware.contexthub.V1_0.IContexthub;
import android.hardware.contexthub.V1_0.Result;
import android.hardware.contexthub.V1_0.TransactionResult;
import android.hardware.location.ContextHubTransaction;
import android.hardware.location.ContextHubTransaction;
import android.hardware.location.IContextHubTransactionCallback;
import android.hardware.location.IContextHubTransactionCallback;
import android.hardware.location.NanoAppBinary;
import android.hardware.location.NanoAppBinary;
@@ -40,7 +37,7 @@ import java.util.concurrent.atomic.AtomicInteger;


/**
/**
 * Manages transactions at the Context Hub Service.
 * Manages transactions at the Context Hub Service.
 *
 * <p>
 * This class maintains a queue of transaction requests made to the ContextHubService by clients,
 * This class maintains a queue of transaction requests made to the ContextHubService by clients,
 * and executes them through the Context Hub. At any point in time, either the transaction queue is
 * and executes them through the Context Hub. At any point in time, either the transaction queue is
 * empty, or there is a pending transaction that is waiting for an asynchronous response from the
 * empty, or there is a pending transaction that is waiting for an asynchronous response from the
@@ -64,7 +61,7 @@ import java.util.concurrent.atomic.AtomicInteger;
    /*
    /*
     * The proxy to talk to the Context Hub
     * The proxy to talk to the Context Hub
     */
     */
    private final IContexthub mContextHubProxy;
    private final IContextHubWrapper mContextHubProxy;


    /*
    /*
     * The manager for all clients for the service.
     * The manager for all clients for the service.
@@ -120,7 +117,7 @@ import java.util.concurrent.atomic.AtomicInteger;
    }
    }


    /* package */ ContextHubTransactionManager(
    /* package */ ContextHubTransactionManager(
            IContexthub contextHubProxy, ContextHubClientManager clientManager,
            IContextHubWrapper contextHubProxy, ContextHubClientManager clientManager,
            NanoAppStateManager nanoAppStateManager) {
            NanoAppStateManager nanoAppStateManager) {
        mContextHubProxy = contextHubProxy;
        mContextHubProxy = contextHubProxy;
        mClientManager = clientManager;
        mClientManager = clientManager;
@@ -143,15 +140,13 @@ import java.util.concurrent.atomic.AtomicInteger;
                nanoAppBinary.getNanoAppId(), packageName) {
                nanoAppBinary.getNanoAppId(), packageName) {
            @Override
            @Override
                /* package */ int onTransact() {
                /* package */ int onTransact() {
                android.hardware.contexthub.V1_0.NanoAppBinary hidlNanoAppBinary =
                        ContextHubServiceUtil.createHidlNanoAppBinary(nanoAppBinary);
                try {
                try {
                    return mContextHubProxy.loadNanoApp(
                    return mContextHubProxy.loadNanoapp(
                            contextHubId, hidlNanoAppBinary, this.getTransactionId());
                            contextHubId, nanoAppBinary, this.getTransactionId());
                } catch (RemoteException e) {
                } catch (RemoteException e) {
                    Log.e(TAG, "RemoteException while trying to load nanoapp with ID 0x" +
                    Log.e(TAG, "RemoteException while trying to load nanoapp with ID 0x" +
                            Long.toHexString(nanoAppBinary.getNanoAppId()), e);
                            Long.toHexString(nanoAppBinary.getNanoAppId()), e);
                    return Result.UNKNOWN_FAILURE;
                    return ContextHubTransaction.RESULT_FAILED_UNKNOWN;
                }
                }
            }
            }


@@ -194,12 +189,12 @@ import java.util.concurrent.atomic.AtomicInteger;
            @Override
            @Override
                /* package */ int onTransact() {
                /* package */ int onTransact() {
                try {
                try {
                    return mContextHubProxy.unloadNanoApp(
                    return mContextHubProxy.unloadNanoapp(
                            contextHubId, nanoAppId, this.getTransactionId());
                            contextHubId, nanoAppId, this.getTransactionId());
                } catch (RemoteException e) {
                } catch (RemoteException e) {
                    Log.e(TAG, "RemoteException while trying to unload nanoapp with ID 0x" +
                    Log.e(TAG, "RemoteException while trying to unload nanoapp with ID 0x" +
                            Long.toHexString(nanoAppId), e);
                            Long.toHexString(nanoAppId), e);
                    return Result.UNKNOWN_FAILURE;
                    return ContextHubTransaction.RESULT_FAILED_UNKNOWN;
                }
                }
            }
            }


@@ -237,12 +232,12 @@ import java.util.concurrent.atomic.AtomicInteger;
            @Override
            @Override
                /* package */ int onTransact() {
                /* package */ int onTransact() {
                try {
                try {
                    return mContextHubProxy.enableNanoApp(
                    return mContextHubProxy.enableNanoapp(
                            contextHubId, nanoAppId, this.getTransactionId());
                            contextHubId, nanoAppId, this.getTransactionId());
                } catch (RemoteException e) {
                } catch (RemoteException e) {
                    Log.e(TAG, "RemoteException while trying to enable nanoapp with ID 0x" +
                    Log.e(TAG, "RemoteException while trying to enable nanoapp with ID 0x" +
                            Long.toHexString(nanoAppId), e);
                            Long.toHexString(nanoAppId), e);
                    return Result.UNKNOWN_FAILURE;
                    return ContextHubTransaction.RESULT_FAILED_UNKNOWN;
                }
                }
            }
            }


@@ -274,12 +269,12 @@ import java.util.concurrent.atomic.AtomicInteger;
            @Override
            @Override
                /* package */ int onTransact() {
                /* package */ int onTransact() {
                try {
                try {
                    return mContextHubProxy.disableNanoApp(
                    return mContextHubProxy.disableNanoapp(
                            contextHubId, nanoAppId, this.getTransactionId());
                            contextHubId, nanoAppId, this.getTransactionId());
                } catch (RemoteException e) {
                } catch (RemoteException e) {
                    Log.e(TAG, "RemoteException while trying to disable nanoapp with ID 0x" +
                    Log.e(TAG, "RemoteException while trying to disable nanoapp with ID 0x" +
                            Long.toHexString(nanoAppId), e);
                            Long.toHexString(nanoAppId), e);
                    return Result.UNKNOWN_FAILURE;
                    return ContextHubTransaction.RESULT_FAILED_UNKNOWN;
                }
                }
            }
            }


@@ -310,10 +305,10 @@ import java.util.concurrent.atomic.AtomicInteger;
            @Override
            @Override
                /* package */ int onTransact() {
                /* package */ int onTransact() {
                try {
                try {
                    return mContextHubProxy.queryApps(contextHubId);
                    return mContextHubProxy.queryNanoapps(contextHubId);
                } catch (RemoteException e) {
                } catch (RemoteException e) {
                    Log.e(TAG, "RemoteException while trying to query for nanoapps", e);
                    Log.e(TAG, "RemoteException while trying to query for nanoapps", e);
                    return Result.UNKNOWN_FAILURE;
                    return ContextHubTransaction.RESULT_FAILED_UNKNOWN;
                }
                }
            }
            }


@@ -336,7 +331,7 @@ import java.util.concurrent.atomic.AtomicInteger;


    /**
    /**
     * Adds a new transaction to the queue.
     * Adds a new transaction to the queue.
     *
     * <p>
     * If there was no pending transaction at the time, the transaction that was added will be
     * If there was no pending transaction at the time, the transaction that was added will be
     * started in this method. If there were too many transactions in the queue, an exception will
     * started in this method. If there were too many transactions in the queue, an exception will
     * be thrown.
     * be thrown.
@@ -363,10 +358,10 @@ import java.util.concurrent.atomic.AtomicInteger;
     * Handles a transaction response from a Context Hub.
     * Handles a transaction response from a Context Hub.
     *
     *
     * @param transactionId the transaction ID of the response
     * @param transactionId the transaction ID of the response
     * @param result        the result of the transaction as defined by the HAL TransactionResult
     * @param success       true if the transaction succeeded
     */
     */
    /* package */
    /* package */
    synchronized void onTransactionResponse(int transactionId, int result) {
    synchronized void onTransactionResponse(int transactionId, boolean success) {
        ContextHubServiceTransaction transaction = mTransactionQueue.peek();
        ContextHubServiceTransaction transaction = mTransactionQueue.peek();
        if (transaction == null) {
        if (transaction == null) {
            Log.w(TAG, "Received unexpected transaction response (no transaction pending)");
            Log.w(TAG, "Received unexpected transaction response (no transaction pending)");
@@ -378,9 +373,7 @@ import java.util.concurrent.atomic.AtomicInteger;
            return;
            return;
        }
        }


        transaction.onTransactionComplete(
        transaction.onTransactionComplete(success ? ContextHubTransaction.RESULT_SUCCESS :
                (result == TransactionResult.SUCCESS) ?
                        ContextHubTransaction.RESULT_SUCCESS :
                        ContextHubTransaction.RESULT_FAILED_AT_HUB);
                        ContextHubTransaction.RESULT_FAILED_AT_HUB);
        removeTransactionAndStartNext();
        removeTransactionAndStartNext();
    }
    }
@@ -421,11 +414,11 @@ import java.util.concurrent.atomic.AtomicInteger;


    /**
    /**
     * Pops the front transaction from the queue and starts the next pending transaction request.
     * Pops the front transaction from the queue and starts the next pending transaction request.
     *
     * <p>
     * Removing elements from the transaction queue must only be done through this method. When a
     * Removing elements from the transaction queue must only be done through this method. When a
     * pending transaction is removed, the timeout timer is cancelled and the transaction is marked
     * pending transaction is removed, the timeout timer is cancelled and the transaction is marked
     * complete.
     * complete.
     *
     * <p>
     * It is assumed that the transaction queue is non-empty when this method is invoked, and that
     * It is assumed that the transaction queue is non-empty when this method is invoked, and that
     * the caller has obtained a lock on this ContextHubTransactionManager object.
     * the caller has obtained a lock on this ContextHubTransactionManager object.
     */
     */
@@ -442,21 +435,21 @@ import java.util.concurrent.atomic.AtomicInteger;


    /**
    /**
     * Starts the next pending transaction request.
     * Starts the next pending transaction request.
     *
     * <p>
     * Starting new transactions must only be done through this method. This method continues to
     * Starting new transactions must only be done through this method. This method continues to
     * process the transaction queue as long as there are pending requests, and no transaction is
     * process the transaction queue as long as there are pending requests, and no transaction is
     * pending.
     * pending.
     *
     * <p>
     * It is assumed that the caller has obtained a lock on this ContextHubTransactionManager
     * It is assumed that the caller has obtained a lock on this ContextHubTransactionManager
     * object.
     * object.
     */
     */
    private void startNextTransaction() {
    private void startNextTransaction() {
        int result = Result.UNKNOWN_FAILURE;
        int result = ContextHubTransaction.RESULT_FAILED_UNKNOWN;
        while (result != Result.OK && !mTransactionQueue.isEmpty()) {
        while (result != ContextHubTransaction.RESULT_SUCCESS && !mTransactionQueue.isEmpty()) {
            ContextHubServiceTransaction transaction = mTransactionQueue.peek();
            ContextHubServiceTransaction transaction = mTransactionQueue.peek();
            result = transaction.onTransact();
            result = transaction.onTransact();


            if (result == Result.OK) {
            if (result == ContextHubTransaction.RESULT_SUCCESS) {
                Runnable onTimeoutFunc = () -> {
                Runnable onTimeoutFunc = () -> {
                    synchronized (this) {
                    synchronized (this) {
                        if (!transaction.isComplete()) {
                        if (!transaction.isComplete()) {
+125 −24
Original line number Original line Diff line number Diff line
@@ -17,10 +17,14 @@ 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.NanoAppBinary;
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;
@@ -104,11 +108,6 @@ public abstract class IContextHubWrapper {
    public abstract void registerCallback(
    public abstract void registerCallback(
            int hubId, IContexthubCallback callback) throws RemoteException;
            int hubId, IContexthubCallback callback) throws RemoteException;


    /**
     * @return A valid instance of Contexthub HAL 1.0.
     */
    public abstract android.hardware.contexthub.V1_0.IContexthub getHub();

    /**
    /**
     * @return True if this version of the Contexthub HAL supports Location setting notifications.
     * @return True if this version of the Contexthub HAL supports Location setting notifications.
     */
     */
@@ -148,21 +147,133 @@ 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;

    /**
     * Loads a nanoapp on the Context Hub.
     *
     * @param contextHubId  The ID of the Context Hub to load the nanoapp to.
     * @param binary        The nanoapp binary to load.
     * @param transactionId The transaction ID of this load.
     * @return the result of this load transaction.
     */
    @ContextHubTransaction.Result
    public abstract int loadNanoapp(int contextHubId, NanoAppBinary binary,
            int transactionId) throws RemoteException;

    /**
     * Unloads a nanoapp on the Context Hub. Semantics are similar to loadNanoapp().
     */
    @ContextHubTransaction.Result
    public abstract int unloadNanoapp(int contextHubId, long nanoappId,
            int transactionId) throws RemoteException;

    /**
     * Enables a nanoapp on the Context Hub. Semantics are similar to loadNanoapp().
     */
    @ContextHubTransaction.Result
    public abstract int enableNanoapp(int contextHubId, long nanoappId,
            int transactionId) throws RemoteException;

    /**
     * Disables a nanoapp on the Context Hub. Semantics are similar to loadNanoapp().
     */
    @ContextHubTransaction.Result
    public abstract int disableNanoapp(int contextHubId, long nanoappId,
            int transactionId) throws RemoteException;

    /**
     * Queries a list of nanoapp from the Context hub.
     *
     * @param contextHubId The ID of the Context Hub to query.
     * @return the result of this query transaction.
     */
    @ContextHubTransaction.Result
    public abstract int queryNanoapps(int contextHubId) 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));
        }

        @ContextHubTransaction.Result
        public int loadNanoapp(int contextHubId, NanoAppBinary binary,
                int transactionId) throws RemoteException {
            android.hardware.contexthub.V1_0.NanoAppBinary hidlNanoAppBinary =
                    ContextHubServiceUtil.createHidlNanoAppBinary(binary);
            return ContextHubServiceUtil.toTransactionResult(mHub.loadNanoApp(
                    contextHubId, hidlNanoAppBinary, transactionId));
        }

        @ContextHubTransaction.Result
        public int unloadNanoapp(int contextHubId, long nanoappId, int transactionId)
                throws RemoteException {
            return ContextHubServiceUtil.toTransactionResult(mHub.unloadNanoApp(
                    contextHubId, nanoappId, transactionId));
        }

        @ContextHubTransaction.Result
        public int enableNanoapp(int contextHubId, long nanoappId, int transactionId)
                throws RemoteException {
            return ContextHubServiceUtil.toTransactionResult(mHub.enableNanoApp(
                    contextHubId, nanoappId, transactionId));
        }

        @ContextHubTransaction.Result
        public int disableNanoapp(int contextHubId, long nanoappId, int transactionId)
                throws RemoteException {
            return ContextHubServiceUtil.toTransactionResult(mHub.disableNanoApp(
                    contextHubId, nanoappId, transactionId));
        }

        @ContextHubTransaction.Result
        public int queryNanoapps(int contextHubId) throws RemoteException {
            return ContextHubServiceUtil.toTransactionResult(
                    mHub.queryApps(contextHubId));
        }
    }

    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;
        }
        }


@@ -179,10 +290,6 @@ public abstract class IContextHubWrapper {
            mHub.registerCallback(hubId, callback);
            mHub.registerCallback(hubId, callback);
        }
        }


        public android.hardware.contexthub.V1_0.IContexthub getHub() {
            return mHub;
        }

        public boolean supportsLocationSettingNotifications() {
        public boolean supportsLocationSettingNotifications() {
            return false;
            return false;
        }
        }
@@ -212,10 +319,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;
        }
        }


@@ -232,10 +340,6 @@ public abstract class IContextHubWrapper {
            mHub.registerCallback(hubId, callback);
            mHub.registerCallback(hubId, callback);
        }
        }


        public android.hardware.contexthub.V1_0.IContexthub getHub() {
            return mHub;
        }

        public boolean supportsLocationSettingNotifications() {
        public boolean supportsLocationSettingNotifications() {
            return true;
            return true;
        }
        }
@@ -271,7 +375,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 +383,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;
        }
        }


@@ -301,10 +406,6 @@ public abstract class IContextHubWrapper {
            mHub.registerCallback_1_2(hubId, callback);
            mHub.registerCallback_1_2(hubId, callback);
        }
        }


        public android.hardware.contexthub.V1_0.IContexthub getHub() {
            return mHub;
        }

        public boolean supportsLocationSettingNotifications() {
        public boolean supportsLocationSettingNotifications() {
            return true;
            return true;
        }
        }