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

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

Remove HIDL references in ContextHubTransactionManager

Bug: 194285834
Test: Presubmits, run CHQTS on device
Change-Id: I0913fafadd72cdcc4463e7576e4ee3f007892edd
parent ed470daf
Loading
Loading
Loading
Loading
+19 −17
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.
     *
     *
@@ -664,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) {
@@ -678,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);
    }
    }


    /**
    /**
@@ -1094,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(
@@ -1122,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()) {
+79 −17
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ 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.ContextHubTransaction;
import android.hardware.location.NanoAppBinary;
import android.hardware.location.NanoAppMessage;
import android.hardware.location.NanoAppMessage;
import android.os.RemoteException;
import android.os.RemoteException;
import android.util.Log;
import android.util.Log;
@@ -107,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.
     */
     */
@@ -174,6 +170,48 @@ public abstract class IContextHubWrapper {
            short hostEndpointId, int contextHubId, NanoAppMessage message)
            short hostEndpointId, int contextHubId, NanoAppMessage message)
            throws RemoteException;
            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.
     * An abstract call that defines methods common to all HIDL IContextHubWrappers.
     */
     */
@@ -193,6 +231,42 @@ public abstract class IContextHubWrapper {
            return ContextHubServiceUtil.toTransactionResult(
            return ContextHubServiceUtil.toTransactionResult(
                    mHub.sendMessageToHub(contextHubId, messageToNanoApp));
                    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 static class ContextHubWrapperV1_0 extends ContextHubWrapperHidl {
@@ -216,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;
        }
        }
@@ -270,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;
        }
        }
@@ -340,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;
        }
        }