From c8ce4d5c33284092f035594b2819b2a1584854b6 Mon Sep 17 00:00:00 2001 From: Matthew Sedam Date: Mon, 9 Jan 2023 20:18:21 +0000 Subject: [PATCH] Add setTestMode to Context Hub AIDL definition Bug: 258074235 Test: make android.hardware.contexthub-update-api Test: atest VtsAidlHalContextHubTargetTest Test: m Change-Id: I276857a2a2254cdf41bc8767ab972436a9015418 --- .../hardware/contexthub/IContextHub.aidl | 3 ++- .../hardware/contexthub/NanoappBinary.aidl | 6 +++--- .../android/hardware/contexthub/Setting.aidl | 12 +++++------ .../hardware/contexthub/IContextHub.aidl | 16 +++++++++++++++ contexthub/aidl/default/ContextHub.cpp | 4 ++++ .../include/contexthub-impl/ContextHub.h | 1 + .../vts/VtsAidlHalContextHubTargetTest.cpp | 20 +++++++++++++++++++ 7 files changed, 52 insertions(+), 10 deletions(-) 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 c1f4df868d..d66e1ac4d5 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 @@ -47,5 +47,6 @@ interface IContextHub { void onHostEndpointDisconnected(char hostEndpointId); long[] getPreloadedNanoappIds(); void onNanSessionStateChanged(in boolean state); - const int EX_CONTEXT_HUB_UNSPECIFIED = -1; + void setTestMode(in boolean enable); + const int EX_CONTEXT_HUB_UNSPECIFIED = (-1); } diff --git a/contexthub/aidl/aidl_api/android.hardware.contexthub/current/android/hardware/contexthub/NanoappBinary.aidl b/contexthub/aidl/aidl_api/android.hardware.contexthub/current/android/hardware/contexthub/NanoappBinary.aidl index d53b28f943..741a9cf0c9 100644 --- a/contexthub/aidl/aidl_api/android.hardware.contexthub/current/android/hardware/contexthub/NanoappBinary.aidl +++ b/contexthub/aidl/aidl_api/android.hardware.contexthub/current/android/hardware/contexthub/NanoappBinary.aidl @@ -40,7 +40,7 @@ parcelable NanoappBinary { byte targetChreApiMajorVersion; byte targetChreApiMinorVersion; byte[] customBinary; - const int FLAG_SIGNED = 1; - const int FLAG_ENCRYPTED = 2; - const int FLAG_TCM_CAPABLE = 4; + const int FLAG_SIGNED = (1 << 0); + const int FLAG_ENCRYPTED = (1 << 1); + const int FLAG_TCM_CAPABLE = (1 << 2); } diff --git a/contexthub/aidl/aidl_api/android.hardware.contexthub/current/android/hardware/contexthub/Setting.aidl b/contexthub/aidl/aidl_api/android.hardware.contexthub/current/android/hardware/contexthub/Setting.aidl index d998478db6..aeb720b779 100644 --- a/contexthub/aidl/aidl_api/android.hardware.contexthub/current/android/hardware/contexthub/Setting.aidl +++ b/contexthub/aidl/aidl_api/android.hardware.contexthub/current/android/hardware/contexthub/Setting.aidl @@ -35,10 +35,10 @@ package android.hardware.contexthub; @Backing(type="byte") @VintfStability enum Setting { LOCATION = 1, - WIFI_MAIN = 2, - WIFI_SCANNING = 3, - AIRPLANE_MODE = 4, - MICROPHONE = 5, - BT_MAIN = 6, - BT_SCANNING = 7, + WIFI_MAIN, + WIFI_SCANNING, + AIRPLANE_MODE, + MICROPHONE, + BT_MAIN, + BT_SCANNING, } diff --git a/contexthub/aidl/android/hardware/contexthub/IContextHub.aidl b/contexthub/aidl/android/hardware/contexthub/IContextHub.aidl index 7f507306f3..f9838bdb19 100644 --- a/contexthub/aidl/android/hardware/contexthub/IContextHub.aidl +++ b/contexthub/aidl/android/hardware/contexthub/IContextHub.aidl @@ -216,6 +216,22 @@ interface IContextHub { */ void onNanSessionStateChanged(in boolean state); + /** + * Puts the context hub in and out of test mode. Test mode is a clean state + * where tests can be executed in the same environment. If enable is true, + * this will enable test mode by unloading all nanoapps. If enable is false, + * this will disable test mode and reverse the actions of enabling test mode + * by loading all preloaded nanoapps. This puts CHRE in a normal state. + * + * This should only be used for a test environment, either through a + * @TestApi or development tools. This should not be used in a production + * environment. + * + * @param enable If true, put the context hub in test mode. If false, disable + * test mode. + */ + void setTestMode(in boolean enable); + /** * Error codes that are used as service specific errors with the AIDL return * value EX_SERVICE_SPECIFIC. diff --git a/contexthub/aidl/default/ContextHub.cpp b/contexthub/aidl/default/ContextHub.cpp index 615ac5c258..b98bfb26bd 100644 --- a/contexthub/aidl/default/ContextHub.cpp +++ b/contexthub/aidl/default/ContextHub.cpp @@ -113,6 +113,10 @@ ScopedAStatus ContextHub::sendMessageToHub(int32_t in_contextHubId, } } +ScopedAStatus ContextHub::setTestMode(bool /* enable */) { + return ndk::ScopedAStatus::ok(); +} + ScopedAStatus ContextHub::onHostEndpointConnected(const HostEndpointInfo& in_info) { mConnectedHostEndpoints.insert(in_info.hostEndpointId); diff --git a/contexthub/aidl/default/include/contexthub-impl/ContextHub.h b/contexthub/aidl/default/include/contexthub-impl/ContextHub.h index b3998b917e..dc9aef0e01 100644 --- a/contexthub/aidl/default/include/contexthub-impl/ContextHub.h +++ b/contexthub/aidl/default/include/contexthub-impl/ContextHub.h @@ -44,6 +44,7 @@ class ContextHub : public BnContextHub { int32_t in_contextHubId, const std::shared_ptr& in_cb) override; ::ndk::ScopedAStatus sendMessageToHub(int32_t in_contextHubId, const ContextHubMessage& in_message) override; + ::ndk::ScopedAStatus setTestMode(bool enable) override; ::ndk::ScopedAStatus onHostEndpointConnected(const HostEndpointInfo& in_info) override; ::ndk::ScopedAStatus onHostEndpointDisconnected(char16_t in_hostEndpointId) override; diff --git a/contexthub/aidl/vts/VtsAidlHalContextHubTargetTest.cpp b/contexthub/aidl/vts/VtsAidlHalContextHubTargetTest.cpp index 4731648c27..f7ff73d477 100644 --- a/contexthub/aidl/vts/VtsAidlHalContextHubTargetTest.cpp +++ b/contexthub/aidl/vts/VtsAidlHalContextHubTargetTest.cpp @@ -84,6 +84,26 @@ TEST_P(ContextHubAidl, TestGetHubs) { } } +TEST_P(ContextHubAidl, TestEnableTestMode) { + Status status = contextHub->setTestMode(true); + if (status.exceptionCode() == Status::EX_UNSUPPORTED_OPERATION || + status.transactionError() == android::UNKNOWN_TRANSACTION) { + return; // not supported -> old API; or not implemented + } + + ASSERT_TRUE(status.isOk()); +} + +TEST_P(ContextHubAidl, TestDisableTestMode) { + Status status = contextHub->setTestMode(false); + if (status.exceptionCode() == Status::EX_UNSUPPORTED_OPERATION || + status.transactionError() == android::UNKNOWN_TRANSACTION) { + return; // not supported -> old API; or not implemented + } + + ASSERT_TRUE(status.isOk()); +} + class EmptyContextHubCallback : public android::hardware::contexthub::BnContextHubCallback { public: Status handleNanoappInfo(const std::vector& /* appInfo */) override {