From 84f02c1346609cd2e123a4e27b137cc76d447cef Mon Sep 17 00:00:00 2001 From: Anthony Stange Date: Fri, 16 Dec 2022 17:43:40 +0000 Subject: [PATCH] Add APIs for Contexthub NAN support With current hardware limitations, WiFi chips are unable to support NAN session initialization without assistance of the WiFi framework. Update the Contexthub HAL APIs to allow Contexthubs to request the framework enable a NAN session on their behalf so they can make low power NAN requests to the initialized session without waking the main CPU. Bug: 229888878 Test: Update Contexthub HAL Change-Id: I47a6a1b0512099727c7343542c2aff814dc0d59a --- .../hardware/contexthub/IContextHub.aidl | 1 + .../contexthub/IContextHubCallback.aidl | 2 ++ .../hardware/contexthub/IContextHub.aidl | 13 ++++++++++++ .../contexthub/IContextHubCallback.aidl | 21 +++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/contexthub/aidl/aidl_api/android.hardware.contexthub/current/android/hardware/contexthub/IContextHub.aidl b/contexthub/aidl/aidl_api/android.hardware.contexthub/current/android/hardware/contexthub/IContextHub.aidl index 272d76823b..c1f4df868d 100644 --- a/contexthub/aidl/aidl_api/android.hardware.contexthub/current/android/hardware/contexthub/IContextHub.aidl +++ b/contexthub/aidl/aidl_api/android.hardware.contexthub/current/android/hardware/contexthub/IContextHub.aidl @@ -46,5 +46,6 @@ interface IContextHub { void onHostEndpointConnected(in android.hardware.contexthub.HostEndpointInfo hostEndpointInfo); void onHostEndpointDisconnected(char hostEndpointId); long[] getPreloadedNanoappIds(); + void onNanSessionStateChanged(in boolean state); const int EX_CONTEXT_HUB_UNSPECIFIED = -1; } diff --git a/contexthub/aidl/aidl_api/android.hardware.contexthub/current/android/hardware/contexthub/IContextHubCallback.aidl b/contexthub/aidl/aidl_api/android.hardware.contexthub/current/android/hardware/contexthub/IContextHubCallback.aidl index f81f7cfdee..e72ae73147 100644 --- a/contexthub/aidl/aidl_api/android.hardware.contexthub/current/android/hardware/contexthub/IContextHubCallback.aidl +++ b/contexthub/aidl/aidl_api/android.hardware.contexthub/current/android/hardware/contexthub/IContextHubCallback.aidl @@ -38,4 +38,6 @@ interface IContextHubCallback { void handleContextHubMessage(in android.hardware.contexthub.ContextHubMessage msg, in String[] msgContentPerms); void handleContextHubAsyncEvent(in android.hardware.contexthub.AsyncEventType evt); void handleTransactionResult(in int transactionId, in boolean success); + void handleNanSessionRequest(in boolean enable); + const int CONTEXTHUB_NAN_TRANSACTION_TIMEOUT_MS = 10000; } diff --git a/contexthub/aidl/android/hardware/contexthub/IContextHub.aidl b/contexthub/aidl/android/hardware/contexthub/IContextHub.aidl index 9fa67a5aa1..7f507306f3 100644 --- a/contexthub/aidl/android/hardware/contexthub/IContextHub.aidl +++ b/contexthub/aidl/android/hardware/contexthub/IContextHub.aidl @@ -203,6 +203,19 @@ interface IContextHub { */ long[] getPreloadedNanoappIds(); + /** + * Invoked when the state of the NAN session requested through handleNanSessionRequest() + * changes. This function may be invoked without a corresponding handleNanSessionRequest to + * indicate if a NAN session was terminated without a request due to resource limitations. + * + * If the state becomes disabled without an explicit request from the HAL, the HAL MUST + * explicitly invoke handleNanSessionRequest() at a later point in time to attempt to + * re-enable NAN. + * + * @param state True if the NAN session is currently enabled. + */ + void onNanSessionStateChanged(in boolean state); + /** * Error codes that are used as service specific errors with the AIDL return * value EX_SERVICE_SPECIFIC. diff --git a/contexthub/aidl/android/hardware/contexthub/IContextHubCallback.aidl b/contexthub/aidl/android/hardware/contexthub/IContextHubCallback.aidl index e385d48c55..cff18935c3 100644 --- a/contexthub/aidl/android/hardware/contexthub/IContextHubCallback.aidl +++ b/contexthub/aidl/android/hardware/contexthub/IContextHubCallback.aidl @@ -74,4 +74,25 @@ interface IContextHubCallback { * */ void handleTransactionResult(in int transactionId, in boolean success); + + /** + * This callback is passed by the Contexthub service to the HAL implementation to allow the HAL + * to request a WiFi NAN session is created to allow the Contexthub to be able to utilize NAN + * functionality. + * + * onNanSessionStateChanged() will be invoked asynchronously after the NAN session request has + * been completed. This must be done within CONTEXTHUB_NAN_TRANSACTION_TIMEOUT_MS. If the + * request times out, onNanSessionStateChanged() will be invoked with the state that the session + * was previously in. + * + * @param enable Whether the NAN session should be enabled or disabled depending on whether the + * Contexthub needs access to NAN. + */ + void handleNanSessionRequest(in boolean enable); + + /** + * Amount of time, in milliseconds, that a handleNanSessionRequest can be pending before the + * Contexthub service must respond. + */ + const int CONTEXTHUB_NAN_TRANSACTION_TIMEOUT_MS = 10000; }