Adds additional host info exchanges in Context Hub HAL
Bug: 194287786 Test: Run VTS Change-Id: I5459e44f752cd04bc1bec3b5e99f398be9f4ce11
This commit is contained in:
parent
8824d6c08a
commit
065a9a5aac
7 changed files with 161 additions and 0 deletions
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
|
||||
// two cases:
|
||||
// 1). this is a frozen version file - do not edit this in any case.
|
||||
// 2). this is a 'current' file. If you make a backwards compatible change to
|
||||
// the interface (from the latest frozen version), the build system will
|
||||
// prompt you to update this file with `m <name>-update-api`.
|
||||
//
|
||||
// You must not make a backward incompatible change to any AIDL file built
|
||||
// with the aidl_interface module type with versions property set. The module
|
||||
// type is used to build AIDL files in a way that they can be used across
|
||||
// independently updatable components of the system. If a device is shipped
|
||||
// with such a backward incompatible change, it has a high risk of breaking
|
||||
// later when a module using the interface is updated, e.g., Mainline modules.
|
||||
|
||||
package android.hardware.contexthub;
|
||||
@VintfStability
|
||||
parcelable HostEndpointInfo {
|
||||
char hostEndpointId;
|
||||
android.hardware.contexthub.HostEndpointInfo.Type type;
|
||||
@nullable String[] packageName;
|
||||
@nullable String[] attributionTag;
|
||||
@Backing(type="int") @VintfStability
|
||||
enum Type {
|
||||
TYPE_FRAMEWORK = 1,
|
||||
TYPE_APP = 2,
|
||||
}
|
||||
}
|
|
@ -43,4 +43,6 @@ interface IContextHub {
|
|||
boolean queryNanoapps(in int contextHubId);
|
||||
boolean registerCallback(in int contextHubId, in android.hardware.contexthub.IContextHubCallback cb);
|
||||
boolean sendMessageToHub(in int contextHubId, in android.hardware.contexthub.ContextHubMessage message);
|
||||
void onHostEndpointConnected(in android.hardware.contexthub.HostEndpointInfo hostEndpointInfo);
|
||||
void onHostEndpointDisconnected(char hostEndpointId);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.hardware.contexthub;
|
||||
|
||||
/**
|
||||
* Stores metadata regarding a host endpoint that may communicate with the Context Hub.
|
||||
*/
|
||||
@VintfStability
|
||||
parcelable HostEndpointInfo {
|
||||
/** The ID of the host endpoint asscociated with this host. */
|
||||
char hostEndpointId;
|
||||
|
||||
/** The type of endpoint. */
|
||||
Type type;
|
||||
|
||||
/** The (optional) package name of the host. */
|
||||
@nullable String[] packageName;
|
||||
|
||||
/** The (optional) attribution tag associated with this host. */
|
||||
@nullable String[] attributionTag;
|
||||
|
||||
@VintfStability
|
||||
@Backing(type="int")
|
||||
enum Type {
|
||||
/**
|
||||
This endpoint is from the Android framework, where packageName and attributionTag may be
|
||||
empty.
|
||||
*/
|
||||
TYPE_FRAMEWORK = 1,
|
||||
|
||||
/** This endpoint is an Android app. */
|
||||
TYPE_APP = 2,
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ package android.hardware.contexthub;
|
|||
|
||||
import android.hardware.contexthub.ContextHubInfo;
|
||||
import android.hardware.contexthub.ContextHubMessage;
|
||||
import android.hardware.contexthub.HostEndpointInfo;
|
||||
import android.hardware.contexthub.IContextHubCallback;
|
||||
import android.hardware.contexthub.NanoappBinary;
|
||||
import android.hardware.contexthub.Setting;
|
||||
|
@ -151,4 +152,29 @@ interface IContextHub {
|
|||
* @return true on success
|
||||
*/
|
||||
boolean sendMessageToHub(in int contextHubId, in ContextHubMessage message);
|
||||
|
||||
/**
|
||||
* Invoked when a host endpoint has connected with the ContextHubService.
|
||||
*
|
||||
* The host associated with this invocation may initiate a communication channel with
|
||||
* the Context Hub using sendMessageToHub.
|
||||
*
|
||||
* @param hostEndpointInfo Metadata associated with this host endpoint.
|
||||
*/
|
||||
void onHostEndpointConnected(in HostEndpointInfo hostEndpointInfo);
|
||||
|
||||
/**
|
||||
* Invoked when a host endpoint has disconnected from the framework. This could be as a result
|
||||
* of an explicit connection closure, or unexpected restarts.
|
||||
*
|
||||
* Note that hostEndpointId is the same as the value in HostEndpointInfo. When this function is
|
||||
* called, the HAL is expected to clean up any resources attached to the messaging channel
|
||||
* associated with this host endpoint ID.
|
||||
*
|
||||
* @param hostEndPointId The ID of the host that has disconnected.
|
||||
*
|
||||
* @return Status::ok on success
|
||||
* EX_ILLEGAL_ARGUMENT if hostEndpointId is not associated with a connected host.
|
||||
*/
|
||||
void onHostEndpointDisconnected(char hostEndpointId);
|
||||
}
|
||||
|
|
|
@ -111,6 +111,21 @@ namespace contexthub {
|
|||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus ContextHub::onHostEndpointConnected(const HostEndpointInfo& in_info) {
|
||||
mConnectedHostEndpoints.insert(in_info.hostEndpointId);
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
::ndk::ScopedAStatus ContextHub::onHostEndpointDisconnected(char16_t in_hostEndpointId) {
|
||||
if (mConnectedHostEndpoints.count(in_hostEndpointId) > 0) {
|
||||
mConnectedHostEndpoints.erase(in_hostEndpointId);
|
||||
return ndk::ScopedAStatus::ok();
|
||||
} else {
|
||||
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace contexthub
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
#include <aidl/android/hardware/contexthub/BnContextHub.h>
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
|
@ -41,10 +43,15 @@ class ContextHub : public BnContextHub {
|
|||
::ndk::ScopedAStatus sendMessageToHub(int32_t in_contextHubId,
|
||||
const ContextHubMessage& in_message,
|
||||
bool* _aidl_return) override;
|
||||
::ndk::ScopedAStatus onHostEndpointConnected(const HostEndpointInfo& in_info) override;
|
||||
|
||||
::ndk::ScopedAStatus onHostEndpointDisconnected(char16_t in_hostEndpointId) override;
|
||||
|
||||
private:
|
||||
static constexpr uint32_t kMockHubId = 0;
|
||||
std::shared_ptr<IContextHubCallback> mCallback;
|
||||
|
||||
std::unordered_set<char16_t> mConnectedHostEndpoints;
|
||||
};
|
||||
|
||||
} // namespace contexthub
|
||||
|
|
|
@ -36,6 +36,7 @@ using ::android::binder::Status;
|
|||
using ::android::hardware::contexthub::AsyncEventType;
|
||||
using ::android::hardware::contexthub::ContextHubInfo;
|
||||
using ::android::hardware::contexthub::ContextHubMessage;
|
||||
using ::android::hardware::contexthub::HostEndpointInfo;
|
||||
using ::android::hardware::contexthub::IContextHub;
|
||||
using ::android::hardware::contexthub::IContextHubCallbackDefault;
|
||||
using ::android::hardware::contexthub::NanoappBinary;
|
||||
|
@ -330,6 +331,22 @@ std::vector<std::tuple<std::string, int32_t>> generateContextHubMapping() {
|
|||
return tuples;
|
||||
}
|
||||
|
||||
TEST_P(ContextHubAidl, TestHostConnection) {
|
||||
constexpr char16_t kHostEndpointId = 1;
|
||||
HostEndpointInfo hostEndpointInfo;
|
||||
hostEndpointInfo.hostEndpointId = kHostEndpointId;
|
||||
|
||||
ASSERT_TRUE(contextHub->onHostEndpointConnected(hostEndpointInfo).isOk());
|
||||
ASSERT_TRUE(contextHub->onHostEndpointDisconnected(kHostEndpointId).isOk());
|
||||
}
|
||||
|
||||
TEST_P(ContextHubAidl, TestInvalidHostConnection) {
|
||||
constexpr char16_t kHostEndpointId = 1;
|
||||
|
||||
Status status = contextHub->onHostEndpointDisconnected(kHostEndpointId);
|
||||
ASSERT_EQ(status.exceptionCode(), android::binder::Status::EX_ILLEGAL_ARGUMENT);
|
||||
}
|
||||
|
||||
std::string PrintGeneratedTest(const testing::TestParamInfo<ContextHubAidl::ParamType>& info) {
|
||||
return std::string("CONTEXT_HUB_ID_") + std::to_string(std::get<1>(info.param));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue