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

Commit 622ebcb4 authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Stores ContextHubInfo in ContextHubClientBroker

This will be necessary when sending intents back to registered
PendingIntents.

Bug: 117612105
Test: Compile only
Change-Id: I24a4c5a83d6fcfd59c63dac6a4a23bff9c05b2eb
parent e767fa2e
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context;
import android.hardware.contexthub.V1_0.ContextHubMsg;
import android.hardware.contexthub.V1_0.IContexthub;
import android.hardware.contexthub.V1_0.Result;
import android.hardware.location.ContextHubInfo;
import android.hardware.location.ContextHubTransaction;
import android.hardware.location.IContextHubClient;
import android.hardware.location.IContextHubClientCallback;
@@ -57,9 +58,9 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
    private final ContextHubClientManager mClientManager;

    /*
     * The ID of the hub that this client is attached to.
     * The object describing the hub that this client is attached to.
     */
    private final int mAttachedContextHubId;
    private final ContextHubInfo mAttachedContextHubInfo;

    /*
     * The host end point ID of this client.
@@ -85,11 +86,12 @@ public class ContextHubClientBroker extends IContextHubClient.Stub

    /* package */ ContextHubClientBroker(
            Context context, IContexthub contextHubProxy, ContextHubClientManager clientManager,
            int contextHubId, short hostEndPointId, IContextHubClientCallback callback) {
            ContextHubInfo contextHubInfo, short hostEndPointId,
            IContextHubClientCallback callback) {
        mContext = context;
        mContextHubProxy = contextHubProxy;
        mClientManager = clientManager;
        mAttachedContextHubId = contextHubId;
        mAttachedContextHubInfo = contextHubInfo;
        mHostEndPointId = hostEndPointId;
        mCallbackInterface = callback;
    }
@@ -119,11 +121,12 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
            ContextHubMsg messageToNanoApp = ContextHubServiceUtil.createHidlContextHubMessage(
                    mHostEndPointId, message);

            int contextHubId = mAttachedContextHubInfo.getId();
            try {
                result = mContextHubProxy.sendMessageToHub(mAttachedContextHubId, messageToNanoApp);
                result = mContextHubProxy.sendMessageToHub(contextHubId, messageToNanoApp);
            } catch (RemoteException e) {
                Log.e(TAG, "RemoteException in sendMessageToNanoApp (target hub ID = "
                        + mAttachedContextHubId + ")", e);
                        + contextHubId + ")", e);
                result = Result.UNKNOWN_FAILURE;
            }
        } else {
@@ -156,7 +159,7 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
     * @return the ID of the context hub this client is attached to
     */
    /* package */ int getAttachedContextHubId() {
        return mAttachedContextHubId;
        return mAttachedContextHubInfo.getId();
    }

    /**
+10 −9
Original line number Diff line number Diff line
@@ -19,13 +19,13 @@ package com.android.server.location;
import android.content.Context;
import android.hardware.contexthub.V1_0.ContextHubMsg;
import android.hardware.contexthub.V1_0.IContexthub;
import android.hardware.location.ContextHubInfo;
import android.hardware.location.IContextHubClient;
import android.hardware.location.IContextHubClientCallback;
import android.hardware.location.NanoAppMessage;
import android.os.RemoteException;
import android.util.Log;

import java.util.NoSuchElementException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;

@@ -80,15 +80,15 @@ import java.util.function.Consumer;
     * Registers a new client with the service.
     *
     * @param clientCallback the callback interface of the client to register
     * @param contextHubId   the ID of the hub this client is attached to
     * @param contextHubInfo the object describing the hub this client is attached to
     *
     * @return the client interface
     *
     * @throws IllegalStateException if max number of clients have already registered
     */
    /* package */ IContextHubClient registerClient(
            IContextHubClientCallback clientCallback, int contextHubId) {
        ContextHubClientBroker broker = createNewClientBroker(clientCallback, contextHubId);
            IContextHubClientCallback clientCallback, ContextHubInfo contextHubInfo) {
        ContextHubClientBroker broker = createNewClientBroker(clientCallback, contextHubInfo);

        try {
            broker.attachDeathRecipient();
@@ -183,14 +183,14 @@ import java.util.function.Consumer;
     * manager.
     *
     * @param clientCallback the callback interface of the client to register
     * @param contextHubId   the ID of the hub this client is attached to
     * @param contextHubInfo the object describing the hub this client is attached to
     *
     * @return the ContextHubClientBroker object
     *
     * @throws IllegalStateException if max number of clients have already registered
     */
    private synchronized ContextHubClientBroker createNewClientBroker(
            IContextHubClientCallback clientCallback, int contextHubId) {
            IContextHubClientCallback clientCallback, ContextHubInfo contextHubInfo) {
        if (mHostEndPointIdToClientMap.size() == MAX_CLIENT_ID + 1) {
            throw new IllegalStateException("Could not register client - max limit exceeded");
        }
@@ -200,7 +200,8 @@ import java.util.function.Consumer;
        for (int i = 0; i <= MAX_CLIENT_ID; i++) {
            if (!mHostEndPointIdToClientMap.containsKey((short) id)) {
                broker = new ContextHubClientBroker(
                        mContext, mContextHubProxy, this, contextHubId, (short)id, clientCallback);
                        mContext, mContextHubProxy, this, contextHubInfo, (short) id,
                        clientCallback);
                mHostEndPointIdToClientMap.put((short) id, broker);
                mNextHostEndpointId = (id == MAX_CLIENT_ID) ? 0 : id + 1;
                break;
+4 −2
Original line number Diff line number Diff line
@@ -170,8 +170,9 @@ public class ContextHubService extends IContextHubService.Stub {

        HashMap<Integer, IContextHubClient> defaultClientMap = new HashMap<>();
        for (int contextHubId : mContextHubIdToInfoMap.keySet()) {
            ContextHubInfo contextHubInfo = mContextHubIdToInfoMap.get(contextHubId);
            IContextHubClient client = mClientManager.registerClient(
                    createDefaultClientCallback(contextHubId), contextHubId);
                    createDefaultClientCallback(contextHubId), contextHubInfo);
            defaultClientMap.put(contextHubId, client);

            try {
@@ -623,7 +624,8 @@ public class ContextHubService extends IContextHubService.Stub {
            throw new NullPointerException("Cannot register client with null callback");
        }

        return mClientManager.registerClient(clientCallback, contextHubId);
        ContextHubInfo contextHubInfo = mContextHubIdToInfoMap.get(contextHubId);
        return mClientManager.registerClient(clientCallback, contextHubInfo);
    }

    /**