Add setTestMode to Context Hub AIDL definition

Bug: 258074235
Test: make android.hardware.contexthub-update-api
Test: atest VtsAidlHalContextHubTargetTest
Test: m
Change-Id: I276857a2a2254cdf41bc8767ab972436a9015418
This commit is contained in:
Matthew Sedam 2023-01-09 20:18:21 +00:00
parent 1cb36a537d
commit c8ce4d5c33
7 changed files with 52 additions and 10 deletions

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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,
}

View file

@ -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.

View file

@ -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);

View file

@ -44,6 +44,7 @@ class ContextHub : public BnContextHub {
int32_t in_contextHubId, const std::shared_ptr<IContextHubCallback>& 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;

View file

@ -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<NanoappInfo>& /* appInfo */) override {