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

Commit 551ada20 authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Removes HIDL references from ContextHubService

This CL fully encapsulates HIDL references in the IContextHubWrapper,
allowing the ContextHubService to operate independently regardless of
whether the HAL is HIDL/AIDL.

Bug: 194285834
Test: Presubmits, run CHQTS on device
Test: Manual testing of untested code path (e.g. Context Hub restart)
Change-Id: I56494a4bd5f508601b8a0f4e3ab1c74a858b81f2
parent 88cc919c
Loading
Loading
Loading
Loading
+45 −52
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


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


import android.annotation.IntDef;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityManager;
import android.app.PendingIntent;
import android.app.PendingIntent;
@@ -27,12 +28,6 @@ import android.content.pm.UserInfo;
import android.database.ContentObserver;
import android.database.ContentObserver;
import android.hardware.SensorPrivacyManager;
import android.hardware.SensorPrivacyManager;
import android.hardware.SensorPrivacyManagerInternal;
import android.hardware.SensorPrivacyManagerInternal;
import android.hardware.contexthub.V1_0.AsyncEventType;
import android.hardware.contexthub.V1_0.ContextHubMsg;
import android.hardware.contexthub.V1_0.Result;
import android.hardware.contexthub.V1_0.TransactionResult;
import android.hardware.contexthub.V1_2.HubAppInfo;
import android.hardware.contexthub.V1_2.IContexthubCallback;
import android.hardware.location.ContextHubInfo;
import android.hardware.location.ContextHubInfo;
import android.hardware.location.ContextHubMessage;
import android.hardware.location.ContextHubMessage;
import android.hardware.location.ContextHubTransaction;
import android.hardware.location.ContextHubTransaction;
@@ -66,6 +61,8 @@ import com.android.server.location.ContextHubServiceProto;


import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.nio.ByteBuffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.ArrayList;
@@ -96,6 +93,20 @@ public class ContextHubService extends IContextHubService.Stub {


    private static final int OS_APP_INSTANCE = -1;
    private static final int OS_APP_INSTANCE = -1;


    /**
     * Constants describing an async event from the Context Hub.
     * {@hide}
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = { "CONTEXT_HUB_EVENT_" }, value = {
            CONTEXT_HUB_EVENT_UNKNOWN,
            CONTEXT_HUB_EVENT_RESTARTED,
    })
    public @interface Type { }

    public static final int CONTEXT_HUB_EVENT_UNKNOWN = 0;
    public static final int CONTEXT_HUB_EVENT_RESTARTED = 1;

    /*
    /*
     * Local flag to enable debug logging.
     * Local flag to enable debug logging.
     */
     */
@@ -135,7 +146,7 @@ public class ContextHubService extends IContextHubService.Stub {
    /**
    /**
     * Class extending the callback to register with a Context Hub.
     * Class extending the callback to register with a Context Hub.
     */
     */
    private class ContextHubServiceCallback extends IContexthubCallback.Stub {
    private class ContextHubServiceCallback implements IContextHubWrapper.ICallback {
        private final int mContextHubId;
        private final int mContextHubId;


        ContextHubServiceCallback(int contextHubId) {
        ContextHubServiceCallback(int contextHubId) {
@@ -143,46 +154,31 @@ public class ContextHubService extends IContextHubService.Stub {
        }
        }


        @Override
        @Override
        public void handleClientMsg(ContextHubMsg message) {
        public void handleTransactionResult(int transactionId, boolean success) {
            handleClientMessageCallback(mContextHubId, message,
            handleTransactionResultCallback(mContextHubId, transactionId, success);
                    Collections.emptyList() /* nanoappPermissions */,
                    Collections.emptyList() /* messagePermissions */);
        }

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


        @Override
        @Override
        public void handleHubEvent(int eventType) {
        public void handleContextHubEvent(int eventType) {
            handleHubEventCallback(mContextHubId, eventType);
            handleHubEventCallback(mContextHubId, eventType);
        }
        }


        @Override
        @Override
        public void handleAppAbort(long nanoAppId, int abortCode) {
        public void handleNanoappAbort(long nanoappId, int abortCode) {
            handleAppAbortCallback(mContextHubId, nanoAppId, abortCode);
            handleAppAbortCallback(mContextHubId, nanoappId, abortCode);
        }
        }


        @Override
        @Override
        public void handleAppsInfo(
        public void handleNanoappInfo(List<NanoAppState> nanoappStateList) {
                ArrayList<android.hardware.contexthub.V1_0.HubAppInfo> nanoAppInfoList) {
            handleQueryAppsCallback(mContextHubId, nanoappStateList);
            handleQueryAppsCallback(mContextHubId,
                    ContextHubServiceUtil.toHubAppInfo_1_2(nanoAppInfoList));
        }
        }


        @Override
        @Override
        public void handleClientMsg_1_2(android.hardware.contexthub.V1_2.ContextHubMsg message,
        public void handleNanoappMessage(short hostEndpointId, NanoAppMessage message,
                ArrayList<String> messagePermissions) {
                List<String> nanoappPermissions, List<String> messagePermissions) {
            handleClientMessageCallback(mContextHubId, message.msg_1_0, message.permissions,
            handleClientMessageCallback(mContextHubId, hostEndpointId, message, nanoappPermissions,
                    messagePermissions);
                    messagePermissions);
        }
        }

        @Override
        public void handleAppsInfo_1_2(ArrayList<HubAppInfo> nanoAppInfoList) {
            handleQueryAppsCallback(mContextHubId, nanoAppInfoList);
        }
    }
    }


    public ContextHubService(Context context) {
    public ContextHubService(Context context) {
@@ -329,7 +325,7 @@ public class ContextHubService extends IContextHubService.Stub {


            @Override
            @Override
            public void onHubReset() {
            public void onHubReset() {
                byte[] data = {TransactionResult.SUCCESS};
                byte[] data = {android.hardware.contexthub.V1_0.TransactionResult.SUCCESS};
                onMessageReceiptOldApi(MSG_HUB_RESET, contextHubId, OS_APP_INSTANCE, data);
                onMessageReceiptOldApi(MSG_HUB_RESET, contextHubId, OS_APP_INSTANCE, data);
            }
            }


@@ -565,12 +561,12 @@ public class ContextHubService extends IContextHubService.Stub {
     * 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.
     *
     *
     * @param contextHubId the ID of the hub to do the query
     * @param contextHubId the ID of the hub to do the query
     * @return the result of the query
     * @return true if the query succeeded
     * @throws IllegalStateException if the transaction queue is full
     * @throws IllegalStateException if the transaction queue is full
     */
     */
    private int queryNanoAppsInternal(int contextHubId) {
    private boolean queryNanoAppsInternal(int contextHubId) {
        if (mContextHubWrapper == null) {
        if (mContextHubWrapper == null) {
            return Result.UNKNOWN_FAILURE;
            return false;
        }
        }


        IContextHubTransactionCallback onCompleteCallback =
        IContextHubTransactionCallback onCompleteCallback =
@@ -579,7 +575,7 @@ public class ContextHubService extends IContextHubService.Stub {
                contextHubId, onCompleteCallback, getCallingPackageName());
                contextHubId, onCompleteCallback, getCallingPackageName());


        mTransactionManager.addTransaction(transaction);
        mTransactionManager.addTransaction(transaction);
        return Result.OK;
        return true;
    }
    }


    @Override
    @Override
@@ -605,7 +601,7 @@ public class ContextHubService extends IContextHubService.Stub {
        boolean success = false;
        boolean success = false;
        if (nanoAppHandle == OS_APP_INSTANCE) {
        if (nanoAppHandle == OS_APP_INSTANCE) {
            if (msg.getMsgType() == MSG_QUERY_NANO_APPS) {
            if (msg.getMsgType() == MSG_QUERY_NANO_APPS) {
                success = (queryNanoAppsInternal(contextHubHandle) == Result.OK);
                success = queryNanoAppsInternal(contextHubHandle);
            } else {
            } else {
                Log.e(TAG, "Invalid OS message params of type " + msg.getMsgType());
                Log.e(TAG, "Invalid OS message params of type " + msg.getMsgType());
            }
            }
@@ -631,16 +627,16 @@ public class ContextHubService extends IContextHubService.Stub {
     * Handles a unicast or broadcast message from a nanoapp.
     * Handles a unicast or broadcast message from a nanoapp.
     *
     *
     * @param contextHubId   the ID of the hub the message came from
     * @param contextHubId   the ID of the hub the message came from
     * @param hostEndpointId the host endpoint ID of the client receiving this message
     * @param message        the message contents
     * @param message        the message contents
     * @param reqPermissions the permissions required to consume this message
     * @param reqPermissions the permissions required to consume this message
     */
     */
    private void handleClientMessageCallback(
    private void handleClientMessageCallback(
            int contextHubId, ContextHubMsg message, List<String> nanoappPermissions,
            int contextHubId, short hostEndpointId, NanoAppMessage message,
            List<String> nanoappPermissions,
            List<String> messagePermissions) {
            List<String> messagePermissions) {
        NanoAppMessage clientMessage = ContextHubServiceUtil.createNanoAppMessage(message);
        mClientManager.onMessageFromNanoApp(
        mClientManager.onMessageFromNanoApp(
                contextHubId, message.hostEndPoint, clientMessage, nanoappPermissions,
                contextHubId, hostEndpointId, message, nanoappPermissions, messagePermissions);
                messagePermissions);
    }
    }


    /**
    /**
@@ -690,10 +686,10 @@ public class ContextHubService extends IContextHubService.Stub {
     * Handles an asynchronous event from a Context Hub.
     * Handles an asynchronous event from a Context Hub.
     *
     *
     * @param contextHubId the ID of the hub the response came from
     * @param contextHubId the ID of the hub the response came from
     * @param eventType    the type of the event as defined in Context Hub HAL AsyncEventType
     * @param eventType    the type of the event as in CONTEXT_HUB_EVENT_*
     */
     */
    private void handleHubEventCallback(int contextHubId, int eventType) {
    private void handleHubEventCallback(int contextHubId, int eventType) {
        if (eventType == AsyncEventType.RESTARTED) {
        if (eventType == CONTEXT_HUB_EVENT_RESTARTED) {
            sendLocationSettingUpdate();
            sendLocationSettingUpdate();
            sendWifiSettingUpdate(true /* forceUpdate */);
            sendWifiSettingUpdate(true /* forceUpdate */);
            sendAirplaneModeSettingUpdate();
            sendAirplaneModeSettingUpdate();
@@ -724,14 +720,11 @@ public class ContextHubService extends IContextHubService.Stub {
     * Handles a query response from a Context Hub.
     * Handles a query response from a Context Hub.
     *
     *
     * @param contextHubId     the ID of the hub of the response
     * @param contextHubId     the ID of the hub of the response
     * @param nanoAppInfoList the list of loaded nanoapps
     * @param nanoappStateList the list of loaded nanoapps
     */
     */
    private void handleQueryAppsCallback(int contextHubId, List<HubAppInfo> nanoAppInfoList) {
    private void handleQueryAppsCallback(int contextHubId, List<NanoAppState> nanoappStateList) {
        List<NanoAppState> nanoAppStateList =
        mNanoAppStateManager.updateCache(contextHubId, nanoappStateList);
                ContextHubServiceUtil.createNanoAppStateList(nanoAppInfoList);
        mTransactionManager.onQueryResponse(nanoappStateList);

        mNanoAppStateManager.updateCache(contextHubId, nanoAppInfoList);
        mTransactionManager.onQueryResponse(nanoAppStateList);
    }
    }


    /**
    /**
+18 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.content.pm.PackageManager.PERMISSION_GRANTED;


import android.Manifest;
import android.Manifest;
import android.content.Context;
import android.content.Context;
import android.hardware.contexthub.V1_0.AsyncEventType;
import android.hardware.contexthub.V1_0.ContextHubMsg;
import android.hardware.contexthub.V1_0.ContextHubMsg;
import android.hardware.contexthub.V1_0.HostEndPoint;
import android.hardware.contexthub.V1_0.HostEndPoint;
import android.hardware.contexthub.V1_0.Result;
import android.hardware.contexthub.V1_0.Result;
@@ -256,4 +257,21 @@ import java.util.List;
        }
        }
        return newAppInfo;
        return newAppInfo;
    }
    }

    /**
     * Converts a HIDL AsyncEventType to the corresponding ContextHubService.CONTEXT_HUB_EVENT_*.
     *
     * @param hidlEventType The AsyncEventType value.
     * @return The converted event type.
     */
    /* package */
    static int toContextHubEvent(int hidlEventType) {
        switch (hidlEventType) {
            case AsyncEventType.RESTARTED:
                return ContextHubService.CONTEXT_HUB_EVENT_RESTARTED;
            default:
                Log.e(TAG, "toContextHubEvent: Unknown event type: " + hidlEventType);
                return ContextHubService.CONTEXT_HUB_EVENT_UNKNOWN;
        }
    }
}
}
+117 −21
Original line number Original line Diff line number Diff line
@@ -15,16 +15,20 @@
 */
 */
package com.android.server.location.contexthub;
package com.android.server.location.contexthub;


import android.annotation.NonNull;
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_0.ContextHubMsg;
import android.hardware.contexthub.V1_0.TransactionResult;
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.HubAppInfo;
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.NanoAppBinary;
import android.hardware.location.NanoAppMessage;
import android.hardware.location.NanoAppMessage;
import android.hardware.location.NanoAppState;
import android.os.RemoteException;
import android.os.RemoteException;
import android.util.Log;
import android.util.Log;
import android.util.Pair;
import android.util.Pair;
@@ -40,6 +44,45 @@ import java.util.NoSuchElementException;
public abstract class IContextHubWrapper {
public abstract class IContextHubWrapper {
    private static final String TAG = "IContextHubWrapper";
    private static final String TAG = "IContextHubWrapper";


    /**
     * The callback interface to use in registerCallback.
     */
    public interface ICallback {
        /**
         * @param transactionId The ID of the transaction that completed.
         * @param success       true if the transaction succeeded.
         */
        void handleTransactionResult(int transactionId, boolean success);

        /**
         * @param eventType The Context Hub event type defined by ContextHubService
         *                  .CONTEXT_HUB_EVENT_*.
         */
        void handleContextHubEvent(int eventType);

        /**
         * @param nanoappId The ID of the nanoapp that aborted.
         * @param abortCode The nanoapp-defined abort code.
         */
        void handleNanoappAbort(long nanoappId, int abortCode);

        /**
         * @param nanoappStateList The list of loaded nanoapps on the Context Hub.
         */
        void handleNanoappInfo(List<NanoAppState> nanoappStateList);

        /**
         * Handles a message from a nanoapp to a ContextHubClient.
         *
         * @param hostEndpointId     The host endpoint ID of the recipient.
         * @param message            The message from the nanoapp.
         * @param nanoappPermissions The list of permissions held by the nanoapp.
         * @param messagePermissions The list of permissions required to receive the message.
         */
        void handleNanoappMessage(short hostEndpointId, NanoAppMessage message,
                List<String> nanoappPermissions, List<String> messagePermissions);
    }

    /**
    /**
     * Attempts to connect to the Contexthub HAL 1.0 service, if it exists.
     * Attempts to connect to the Contexthub HAL 1.0 service, if it exists.
     *
     *
@@ -102,12 +145,6 @@ public abstract class IContextHubWrapper {
     */
     */
    public abstract Pair<List<ContextHubInfo>, List<String>> getHubs() throws RemoteException;
    public abstract Pair<List<ContextHubInfo>, List<String>> getHubs() throws RemoteException;


    /**
     * Calls the appropriate registerCallback function depending on the HAL version.
     */
    public abstract void registerCallback(
            int hubId, IContexthubCallback callback) throws RemoteException;

    /**
    /**
     * @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.
     */
     */
@@ -212,12 +249,76 @@ public abstract class IContextHubWrapper {
    @ContextHubTransaction.Result
    @ContextHubTransaction.Result
    public abstract int queryNanoapps(int contextHubId) throws RemoteException;
    public abstract int queryNanoapps(int contextHubId) throws RemoteException;


    /**
     * Registers a callback with the Context Hub.
     *
     * @param contextHubId The ID of the Context Hub to register the callback with.
     * @param callback     The callback to register.
     */
    public abstract void registerCallback(int contextHubId, @NonNull ICallback callback)
            throws RemoteException;

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


        protected ICallback mCallback = null;

        protected final ContextHubWrapperHidlCallback mHidlCallback =
                new ContextHubWrapperHidlCallback();

        protected class ContextHubWrapperHidlCallback extends IContexthubCallback.Stub {
            @Override
            public void handleClientMsg(ContextHubMsg message) {
                mCallback.handleNanoappMessage(
                        message.hostEndPoint,
                        ContextHubServiceUtil.createNanoAppMessage(message),
                        Collections.emptyList() /* nanoappPermissions */,
                        Collections.emptyList() /* messagePermissions */);
            }

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

            @Override
            public void handleHubEvent(int eventType) {
                mCallback.handleContextHubEvent(
                        ContextHubServiceUtil.toContextHubEvent(eventType));
            }

            @Override
            public void handleAppAbort(long nanoAppId, int abortCode) {
                mCallback.handleNanoappAbort(nanoAppId, abortCode);
            }

            @Override
            public void handleAppsInfo(
                    ArrayList<android.hardware.contexthub.V1_0.HubAppInfo> nanoAppInfoList) {
                handleAppsInfo_1_2(ContextHubServiceUtil.toHubAppInfo_1_2(nanoAppInfoList));
            }

            @Override
            public void handleClientMsg_1_2(android.hardware.contexthub.V1_2.ContextHubMsg message,
                    ArrayList<String> messagePermissions) {
                mCallback.handleNanoappMessage(
                        message.msg_1_0.hostEndPoint,
                        ContextHubServiceUtil.createNanoAppMessage(message.msg_1_0),
                        message.permissions, messagePermissions);
            }

            @Override
            public void handleAppsInfo_1_2(ArrayList<HubAppInfo> nanoAppInfoList) {
                List<NanoAppState> nanoAppStateList =
                        ContextHubServiceUtil.createNanoAppStateList(nanoAppInfoList);
                mCallback.handleNanoappInfo(nanoAppStateList);
            }
        }

        ContextHubWrapperHidl(android.hardware.contexthub.V1_0.IContexthub hub) {
        ContextHubWrapperHidl(android.hardware.contexthub.V1_0.IContexthub hub) {
            mHub = hub;
            mHub = hub;
        }
        }
@@ -267,6 +368,11 @@ public abstract class IContextHubWrapper {
            return ContextHubServiceUtil.toTransactionResult(
            return ContextHubServiceUtil.toTransactionResult(
                    mHub.queryApps(contextHubId));
                    mHub.queryApps(contextHubId));
        }
        }

        public void registerCallback(int contextHubId, ICallback callback) throws RemoteException {
            mCallback = callback;
            mHub.registerCallback(contextHubId, mHidlCallback);
        }
    }
    }


    private static class ContextHubWrapperV1_0 extends ContextHubWrapperHidl {
    private static class ContextHubWrapperV1_0 extends ContextHubWrapperHidl {
@@ -285,11 +391,6 @@ public abstract class IContextHubWrapper {
            return new Pair(hubInfoList, new ArrayList<String>());
            return new Pair(hubInfoList, new ArrayList<String>());
        }
        }


        public void registerCallback(
                int hubId, IContexthubCallback callback) throws RemoteException {
            mHub.registerCallback(hubId, callback);
        }

        public boolean supportsLocationSettingNotifications() {
        public boolean supportsLocationSettingNotifications() {
            return false;
            return false;
        }
        }
@@ -335,11 +436,6 @@ public abstract class IContextHubWrapper {
            return new Pair(hubInfoList, new ArrayList<String>());
            return new Pair(hubInfoList, new ArrayList<String>());
        }
        }


        public void registerCallback(
                int hubId, IContexthubCallback callback) throws RemoteException {
            mHub.registerCallback(hubId, callback);
        }

        public boolean supportsLocationSettingNotifications() {
        public boolean supportsLocationSettingNotifications() {
            return true;
            return true;
        }
        }
@@ -401,11 +497,6 @@ public abstract class IContextHubWrapper {
            return mHubInfo;
            return mHubInfo;
        }
        }


        public void registerCallback(
                int hubId, IContexthubCallback callback) throws RemoteException {
            mHub.registerCallback_1_2(hubId, callback);
        }

        public boolean supportsLocationSettingNotifications() {
        public boolean supportsLocationSettingNotifications() {
            return true;
            return true;
        }
        }
@@ -445,6 +536,11 @@ public abstract class IContextHubWrapper {
                    enabled ? SettingValue.DISABLED : SettingValue.ENABLED);
                    enabled ? SettingValue.DISABLED : SettingValue.ENABLED);
        }
        }


        public void registerCallback(int contextHubId, ICallback callback) throws RemoteException {
            mCallback = callback;
            mHub.registerCallback_1_2(contextHubId, mHidlCallback);
        }

        private void sendSettingChanged(byte setting, byte newValue) {
        private void sendSettingChanged(byte setting, byte newValue) {
            try {
            try {
                mHub.onSettingChanged_1_2(setting, newValue);
                mHub.onSettingChanged_1_2(setting, newValue);
+18 −16
Original line number Original line Diff line number Diff line
@@ -17,8 +17,8 @@
package com.android.server.location.contexthub;
package com.android.server.location.contexthub;


import android.annotation.Nullable;
import android.annotation.Nullable;
import android.hardware.contexthub.V1_2.HubAppInfo;
import android.hardware.location.NanoAppInstanceInfo;
import android.hardware.location.NanoAppInstanceInfo;
import android.hardware.location.NanoAppState;
import android.util.Log;
import android.util.Log;


import java.util.HashMap;
import java.util.HashMap;
@@ -31,8 +31,8 @@ import java.util.function.Consumer;
 * Manages the state of loaded nanoapps at the Context Hubs.
 * Manages the state of loaded nanoapps at the Context Hubs.
 *
 *
 * This class maintains a list of nanoapps that have been informed as loaded at the hubs. The state
 * This class maintains a list of nanoapps that have been informed as loaded at the hubs. The state
 * should be updated based on the hub callbacks (defined in IContexthubCallback.hal), as a result
 * should be updated based on the hub callbacks (defined in IContexthubCallback.hal), as a result of
 * of either loadNanoApp, unloadNanoApp, or queryApps.
 * either loadNanoApp, unloadNanoApp, or queryApps.
 *
 *
 * The state tracked by this manager is used by clients of ContextHubService that use the old APIs.
 * The state tracked by this manager is used by clients of ContextHubService that use the old APIs.
 *
 *
@@ -99,7 +99,7 @@ import java.util.function.Consumer;


    /**
    /**
     * Adds a nanoapp instance to the cache.
     * Adds a nanoapp instance to the cache.
     *
     * <p>
     * If the cache already contained the nanoapp, the entry is removed and a new nanoapp handle is
     * If the cache already contained the nanoapp, the entry is removed and a new nanoapp handle is
     * generated.
     * generated.
     *
     *
@@ -148,14 +148,16 @@ import java.util.function.Consumer;
     * Performs a batch update of the nanoapp cache given a nanoapp query response.
     * Performs a batch update of the nanoapp cache given a nanoapp query response.
     *
     *
     * @param contextHubId     the ID of the hub the response came from
     * @param contextHubId     the ID of the hub the response came from
     * @param nanoAppInfoList the list of loaded nanoapps
     * @param nanoappStateList the list of loaded nanoapps
     */
     */
    /* package */
    /* package */
    synchronized void updateCache(int contextHubId, List<HubAppInfo> nanoAppInfoList) {
    synchronized void updateCache(int contextHubId, List<NanoAppState> nanoappStateList) {
        HashSet<Long> nanoAppIdSet = new HashSet<>();
        HashSet<Long> nanoAppIdSet = new HashSet<>();
        for (HubAppInfo appInfo : nanoAppInfoList) {
        for (NanoAppState nanoappState : nanoappStateList) {
            handleQueryAppEntry(contextHubId, appInfo.info_1_0.appId, appInfo.info_1_0.version);
            handleQueryAppEntry(
            nanoAppIdSet.add(appInfo.info_1_0.appId);
                    contextHubId, nanoappState.getNanoAppId(),
                    (int) nanoappState.getNanoAppVersion());
            nanoAppIdSet.add(nanoappState.getNanoAppId());
        }
        }


        Iterator<NanoAppInstanceInfo> iterator = mNanoAppHash.values().iterator();
        Iterator<NanoAppInstanceInfo> iterator = mNanoAppHash.values().iterator();