summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Android.bp4
-rw-r--r--TEST_MAPPING3
-rw-r--r--base/include/hidl/HidlSupport.h5
-rw-r--r--libhidlmemory/Android.bp2
-rw-r--r--test_main.cpp18
-rw-r--r--transport/HidlLazyUtils.cpp65
-rw-r--r--transport/allocator/1.0/vts/functional/Android.bp3
-rw-r--r--transport/base/1.0/vts/functional/Android.bp4
-rw-r--r--transport/base/1.0/vts/functional/Android.mk22
9 files changed, 81 insertions, 45 deletions
diff --git a/Android.bp b/Android.bp
index da50c0a..8e5c345 100644
--- a/Android.bp
+++ b/Android.bp
@@ -75,6 +75,10 @@ cc_library {
"//apex_available:platform",
"com.android.neuralnetworks",
"test_com.android.neuralnetworks",
+ "com.android.bluetooth.updatable",
+ "com.android.media",
+ "com.android.media.swcodec",
+ "com.android.tethering",
],
vndk: {
enabled: true,
diff --git a/TEST_MAPPING b/TEST_MAPPING
index 01179d5..22c9d36 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -8,6 +8,9 @@
},
{
"name": "hal_implementation_test"
+ },
+ {
+ "name": "hidl_lazy_test"
}
]
}
diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h
index 1b91c26..0a0beeb 100644
--- a/base/include/hidl/HidlSupport.h
+++ b/base/include/hidl/HidlSupport.h
@@ -412,7 +412,7 @@ struct hidl_vec {
}
T *releaseData() {
- if (!mOwnsBuffer && mSize > 0) {
+ if (!mOwnsBuffer && mBuffer != nullptr) {
resize(mSize);
}
mOwnsBuffer = false;
@@ -1044,6 +1044,9 @@ constexpr hidl_invalid_type<T> hidl_enum_values;
*/
template <typename T, typename = std::enable_if_t<std::is_enum<T>::value>>
struct hidl_enum_range {
+ // Container-like associated type.
+ using value_type = T;
+
constexpr auto begin() const { return std::begin(details::hidl_enum_values<T>); }
constexpr auto cbegin() const { return begin(); }
constexpr auto rbegin() const { return std::rbegin(details::hidl_enum_values<T>); }
diff --git a/libhidlmemory/Android.bp b/libhidlmemory/Android.bp
index e6b6b50..3ba408f 100644
--- a/libhidlmemory/Android.bp
+++ b/libhidlmemory/Android.bp
@@ -23,6 +23,8 @@ cc_library {
"//apex_available:platform",
"com.android.neuralnetworks",
"test_com.android.neuralnetworks",
+ "com.android.media",
+ "com.android.media.swcodec",
],
defaults: ["libhidl-defaults"],
shared_libs: [
diff --git a/test_main.cpp b/test_main.cpp
index e4cdd29..0a1e97b 100644
--- a/test_main.cpp
+++ b/test_main.cpp
@@ -222,6 +222,24 @@ TEST_F(LibHidlTest, VecInitTest) {
EXPECT_ARRAYEQ(v3, array, v3.size());
}
+TEST_F(LibHidlTest, VecReleaseTest) {
+ // this test indicates an inconsistency of behaviors which is undesirable.
+ // Perhaps hidl-vec should always allocate an empty vector whenever it
+ // exposes its data. Alternatively, perhaps it should always free/reject
+ // empty vectors and always return nullptr for this state. While this second
+ // alternative is faster, it makes client code harder to write, and it would
+ // break existing client code.
+ using android::hardware::hidl_vec;
+
+ hidl_vec<int32_t> empty;
+ EXPECT_EQ(nullptr, empty.releaseData());
+
+ empty.resize(0);
+ int32_t* data = empty.releaseData();
+ EXPECT_NE(nullptr, data);
+ delete data;
+}
+
TEST_F(LibHidlTest, VecIterTest) {
int32_t array[] = {5, 6, 7};
android::hardware::hidl_vec<int32_t> hv1 = std::vector<int32_t>(array, array + 3);
diff --git a/transport/HidlLazyUtils.cpp b/transport/HidlLazyUtils.cpp
index 08ed676..b943c99 100644
--- a/transport/HidlLazyUtils.cpp
+++ b/transport/HidlLazyUtils.cpp
@@ -29,15 +29,27 @@ namespace details {
using ::android::hidl::base::V1_0::IBase;
class ClientCounterCallback : public ::android::hidl::manager::V1_2::IClientCallback {
- public:
- ClientCounterCallback() : mNumConnectedServices(0) {}
+ public:
+ ClientCounterCallback() {}
bool addRegisteredService(const sp<IBase>& service, const std::string& name);
- protected:
+ protected:
Return<void> onClients(const sp<IBase>& service, bool clients) override;
- private:
+ private:
+ struct Service {
+ sp<IBase> service;
+ std::string name;
+ bool clients = false;
+ };
+
+ /**
+ * Looks up service that is guaranteed to be registered (service from
+ * onClients).
+ */
+ Service& assertRegisteredService(const sp<IBase>& service);
+
/**
* Registers or re-registers services. Returns whether successful.
*/
@@ -50,28 +62,19 @@ class ClientCounterCallback : public ::android::hidl::manager::V1_2::IClientCall
void tryShutdown();
/**
- * Counter of the number of services that currently have at least one client.
- */
- size_t mNumConnectedServices;
-
- struct Service {
- sp<IBase> service;
- std::string name;
- };
- /**
* Number of services that have been registered.
*/
std::vector<Service> mRegisteredServices;
};
class LazyServiceRegistrarImpl {
- public:
+ public:
LazyServiceRegistrarImpl() : mClientCallback(new ClientCounterCallback) {}
status_t registerService(const sp<::android::hidl::base::V1_0::IBase>& service,
const std::string& name);
- private:
+ private:
sp<ClientCounterCallback> mClientCallback;
};
@@ -86,6 +89,17 @@ bool ClientCounterCallback::addRegisteredService(const sp<IBase>& service,
return success;
}
+ClientCounterCallback::Service& ClientCounterCallback::assertRegisteredService(
+ const sp<IBase>& service) {
+ for (Service& registered : mRegisteredServices) {
+ if (registered.service != service) continue;
+ return registered;
+ }
+ LOG(FATAL) << "Got callback on service " << getDescriptor(service.get())
+ << " which we did not register.";
+ __builtin_unreachable();
+}
+
bool ClientCounterCallback::registerService(const sp<IBase>& service, const std::string& name) {
auto manager = hardware::defaultServiceManager1_2();
@@ -114,17 +128,24 @@ bool ClientCounterCallback::registerService(const sp<IBase>& service, const std:
*/
Return<void> ClientCounterCallback::onClients(const sp<::android::hidl::base::V1_0::IBase>& service,
bool clients) {
- if (clients) {
- mNumConnectedServices++;
- } else {
- mNumConnectedServices--;
+ Service& registered = assertRegisteredService(service);
+ if (registered.clients == clients) {
+ LOG(FATAL) << "Process already thought " << getDescriptor(service.get()) << "/"
+ << registered.name << " had clients: " << registered.clients
+ << " but hwservicemanager has notified has clients: " << clients;
+ }
+ registered.clients = clients;
+
+ size_t numWithClients = 0;
+ for (const Service& registered : mRegisteredServices) {
+ if (registered.clients) numWithClients++;
}
- LOG(INFO) << "Process has " << mNumConnectedServices << " (of " << mRegisteredServices.size()
+ LOG(INFO) << "Process has " << numWithClients << " (of " << mRegisteredServices.size()
<< " available) client(s) in use after notification " << getDescriptor(service.get())
- << " has clients: " << clients;
+ << "/" << registered.name << " has clients: " << clients;
- if (mNumConnectedServices == 0) {
+ if (numWithClients == 0) {
tryShutdown();
}
diff --git a/transport/allocator/1.0/vts/functional/Android.bp b/transport/allocator/1.0/vts/functional/Android.bp
index 31d9821..ba7aa70 100644
--- a/transport/allocator/1.0/vts/functional/Android.bp
+++ b/transport/allocator/1.0/vts/functional/Android.bp
@@ -27,3 +27,6 @@ cc_test {
test_suites: ["general-tests", "vts"],
}
+vts_config {
+ name: "VtsHidlAllocatorV1_0Target",
+}
diff --git a/transport/base/1.0/vts/functional/Android.bp b/transport/base/1.0/vts/functional/Android.bp
index 0c814ae..1c6e7ad 100644
--- a/transport/base/1.0/vts/functional/Android.bp
+++ b/transport/base/1.0/vts/functional/Android.bp
@@ -40,3 +40,7 @@ cc_test {
require_root: true,
auto_gen_config: true,
}
+
+vts_config {
+ name: "VtsHalBaseV1_0TargetTest",
+}
diff --git a/transport/base/1.0/vts/functional/Android.mk b/transport/base/1.0/vts/functional/Android.mk
deleted file mode 100644
index 61c6e31..0000000
--- a/transport/base/1.0/vts/functional/Android.mk
+++ /dev/null
@@ -1,22 +0,0 @@
-#
-# Copyright (C) 2017 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.
-#
-
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := VtsHalBaseV1_0TargetTest
--include test/vts/tools/build/Android.host_config.mk