Combine libhidlbase/libhidltransport into one lib.
am: a46371d5b3
Change-Id: Id851f2f0de31ac26f89e3b058b4d412678f1c0e5
diff --git a/Android.bp b/Android.bp
index 084763c..ce4cc07 100644
--- a/Android.bp
+++ b/Android.bp
@@ -22,6 +22,14 @@
],
}
+phony {
+ name: "libhidl",
+ required: [
+ "libhidlbase",
+ "libhidltransport",
+ ],
+}
+
cc_test {
name: "libhidl_test",
defaults: ["libhidl-defaults"],
diff --git a/base/Status.cpp b/base/Status.cpp
index 90474a0..08631cc 100644
--- a/base/Status.cpp
+++ b/base/Status.cpp
@@ -149,19 +149,28 @@
}
namespace details {
- void return_status::assertOk() const {
+ void return_status::onValueRetrieval() const {
if (!isOk()) {
LOG(FATAL) << "Attempted to retrieve value from failed HIDL call: " << description();
}
}
+ void return_status::assertOk() const {
+ if (!isOk()) {
+ LOG(FATAL) << "Failed HIDL return status not checked. Usually this happens because of "
+ "a transport error (error parceling, binder driver, or from unparceling)"
+ ". If you see this in code calling into \"Bn\" classes in for a HAL "
+ "server process, then it is likely that the code there is returning "
+ "transport errors there (as opposed to errors defined within its "
+ "protocol). Error is: " << description();
+ }
+ }
+
return_status::~return_status() {
// mCheckedStatus must be checked before isOk since isOk modifies mCheckedStatus
if (mCheckedStatus) return;
- if (!isOk()) {
- LOG(FATAL) << "Failed HIDL return status not checked: " << description();
- }
+ assertOk();
if (gReturnRestriction == HidlReturnRestriction::NONE) {
return;
@@ -176,9 +185,10 @@
}
return_status& return_status::operator=(return_status&& other) noexcept {
- if (!mCheckedStatus && !isOk()) {
- LOG(FATAL) << "Failed HIDL return status not checked: " << description();
+ if (!mCheckedStatus) {
+ assertOk();
}
+
std::swap(mStatus, other.mStatus);
std::swap(mCheckedStatus, other.mCheckedStatus);
return *this;
diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h
index 93a6251..4c133c1 100644
--- a/base/include/hidl/HidlSupport.h
+++ b/base/include/hidl/HidlSupport.h
@@ -326,6 +326,8 @@
template<typename T>
struct hidl_vec {
+ using value_type = T;
+
hidl_vec() {
static_assert(hidl_vec<T>::kOffsetOfBuffer == 0, "wrong offset");
@@ -793,7 +795,7 @@
// An array of T's. Assumes that T::operator=(const T &) is defined.
template<typename T, size_t SIZE1>
struct hidl_array<T, SIZE1> {
-
+ using value_type = T;
using std_array_type = typename details::std_array<T, SIZE1>::type;
hidl_array() = default;
diff --git a/base/include/hidl/Status.h b/base/include/hidl/Status.h
index 817277f..07d352f 100644
--- a/base/include/hidl/Status.h
+++ b/base/include/hidl/Status.h
@@ -143,6 +143,8 @@
template <typename T, typename U>
friend Return<U> StatusOf(const Return<T> &other);
+ protected:
+ void onValueRetrieval() const;
public:
void assertOk() const;
return_status() {}
@@ -224,7 +226,7 @@
~Return() = default;
operator T() const {
- assertOk();
+ onValueRetrieval(); // assert okay
return mVal;
}
@@ -253,7 +255,7 @@
~Return() = default;
operator sp<T>() const {
- assertOk();
+ onValueRetrieval(); // assert okay
return mVal;
}
diff --git a/transport/HidlBinderSupport.cpp b/transport/HidlBinderSupport.cpp
index 352ed78..02d10d0 100644
--- a/transport/HidlBinderSupport.cpp
+++ b/transport/HidlBinderSupport.cpp
@@ -163,20 +163,6 @@
parentOffset + hidl_string::kOffsetOfBuffer);
}
-android::status_t writeToParcel(const hidl_version &version, android::hardware::Parcel& parcel) {
- return parcel.writeUint32(static_cast<uint32_t>(version.get_major()) << 16 | version.get_minor());
-}
-
-hidl_version* readFromParcel(const android::hardware::Parcel& parcel) {
- uint32_t version;
- android::status_t status = parcel.readUint32(&version);
- if (status != OK) {
- return nullptr;
- } else {
- return new hidl_version(version >> 16, version & 0xFFFF);
- }
-}
-
status_t readFromParcel(Status *s, const Parcel& parcel) {
int32_t exception;
status_t status = parcel.readInt32(&exception);
diff --git a/transport/ServiceManagement.cpp b/transport/ServiceManagement.cpp
index e7bec41..374470e 100644
--- a/transport/ServiceManagement.cpp
+++ b/transport/ServiceManagement.cpp
@@ -769,6 +769,13 @@
const char* env = std::getenv("TREBLE_TESTING_OVERRIDE");
const bool trebleTestingOverride = env && !strcmp(env, "true");
const bool vintfLegacy = (transport == Transport::EMPTY);
+
+ ALOGE("getService: Potential race detected. The VINTF manifest is not being enforced. If a HAL "
+ "server has a delay in starting and it is not in the manifest, it will not be retrieved. "
+ "Please make sure all HALs on this device are in the VINTF manifest and enable "
+ "PRODUCT_ENFORCE_VINTF_MANIFEST on this device (this is also enabled by "
+ "PRODUCT_FULL_TREBLE). PRODUCT_ENFORCE_VINTF_MANIFEST will ensure that no race condition "
+ "is possible here.");
#endif // ENFORCE_VINTF_MANIFEST
for (int tries = 0; !getStub && (vintfHwbinder || vintfLegacy); tries++) {
diff --git a/transport/allocator/1.0/Android.bp b/transport/allocator/1.0/Android.bp
index a3d885a..80364a7 100644
--- a/transport/allocator/1.0/Android.bp
+++ b/transport/allocator/1.0/Android.bp
@@ -14,4 +14,3 @@
],
gen_java: false,
}
-
diff --git a/transport/base/1.0/Android.bp b/transport/base/1.0/Android.bp
index cebb01b..f90831e 100644
--- a/transport/base/1.0/Android.bp
+++ b/transport/base/1.0/Android.bp
@@ -12,4 +12,3 @@
],
gen_java: true,
}
-
diff --git a/transport/include/hidl/HidlBinderSupport.h b/transport/include/hidl/HidlBinderSupport.h
index a098805..5dec5cd 100644
--- a/transport/include/hidl/HidlBinderSupport.h
+++ b/transport/include/hidl/HidlBinderSupport.h
@@ -28,7 +28,7 @@
#include <hwbinder/Parcel.h>
#include <log/log.h> // TODO(b/65843592): remove. Too many users depending on this transitively.
-// Defines functions for hidl_string, hidl_version, Status, hidl_vec, MQDescriptor,
+// Defines functions for hidl_string, Status, hidl_vec, MQDescriptor,
// etc. to interact with Parcel.
namespace android {
@@ -72,13 +72,6 @@
status_t writeEmbeddedToParcel(const hidl_string &string,
Parcel *parcel, size_t parentHandle, size_t parentOffset);
-// ---------------------- hidl_version
-
-status_t writeToParcel(const hidl_version &version, android::hardware::Parcel& parcel);
-
-// Caller is responsible for freeing the returned object.
-hidl_version* readFromParcel(const android::hardware::Parcel& parcel);
-
// ---------------------- Status
// Bear in mind that if the client or service is a Java endpoint, this
@@ -185,127 +178,6 @@
return _hidl_err;
}
-// ---------------------- pointers for HIDL
-
-template <typename T>
-static status_t readEmbeddedReferenceFromParcel(
- T const* * /* bufptr */,
- const Parcel & parcel,
- size_t parentHandle,
- size_t parentOffset,
- size_t *handle,
- bool *shouldResolveRefInBuffer
- ) {
- // *bufptr is ignored because, if I am embedded in some
- // other buffer, the kernel should have fixed me up already.
- bool isPreviouslyWritten;
- status_t result = parcel.readEmbeddedReference(
- nullptr, // ignored, not written to bufptr.
- handle,
- parentHandle,
- parentOffset,
- &isPreviouslyWritten);
- // tell caller to run T::readEmbeddedToParcel and
- // T::readEmbeddedReferenceToParcel if necessary.
- // It is not called here because we don't know if these two are valid methods.
- *shouldResolveRefInBuffer = !isPreviouslyWritten;
- return result;
-}
-
-template <typename T>
-static status_t writeEmbeddedReferenceToParcel(
- T const* buf,
- Parcel *parcel, size_t parentHandle, size_t parentOffset,
- size_t *handle,
- bool *shouldResolveRefInBuffer
- ) {
-
- if(buf == nullptr) {
- *shouldResolveRefInBuffer = false;
- return parcel->writeEmbeddedNullReference(handle, parentHandle, parentOffset);
- }
-
- // find whether the buffer exists
- size_t childHandle, childOffset;
- status_t result;
- bool found;
-
- result = parcel->findBuffer(buf, sizeof(T), &found, &childHandle, &childOffset);
-
- // tell caller to run T::writeEmbeddedToParcel and
- // T::writeEmbeddedReferenceToParcel if necessary.
- // It is not called here because we don't know if these two are valid methods.
- *shouldResolveRefInBuffer = !found;
-
- if(result != OK) {
- return result; // bad pointers and length given
- }
- if(!found) { // did not find it.
- return parcel->writeEmbeddedBuffer(buf, sizeof(T), handle,
- parentHandle, parentOffset);
- }
- // found the buffer. easy case.
- return parcel->writeEmbeddedReference(
- handle,
- childHandle,
- childOffset,
- parentHandle,
- parentOffset);
-}
-
-template <typename T>
-static status_t readReferenceFromParcel(
- T const* *bufptr,
- const Parcel & parcel,
- size_t *handle,
- bool *shouldResolveRefInBuffer
- ) {
- bool isPreviouslyWritten;
- status_t result = parcel.readReference(reinterpret_cast<void const* *>(bufptr),
- handle, &isPreviouslyWritten);
- // tell caller to run T::readEmbeddedToParcel and
- // T::readEmbeddedReferenceToParcel if necessary.
- // It is not called here because we don't know if these two are valid methods.
- *shouldResolveRefInBuffer = !isPreviouslyWritten;
- return result;
-}
-
-template <typename T>
-static status_t writeReferenceToParcel(
- T const *buf,
- Parcel * parcel,
- size_t *handle,
- bool *shouldResolveRefInBuffer
- ) {
-
- if(buf == nullptr) {
- *shouldResolveRefInBuffer = false;
- return parcel->writeNullReference(handle);
- }
-
- // find whether the buffer exists
- size_t childHandle, childOffset;
- status_t result;
- bool found;
-
- result = parcel->findBuffer(buf, sizeof(T), &found, &childHandle, &childOffset);
-
- // tell caller to run T::writeEmbeddedToParcel and
- // T::writeEmbeddedReferenceToParcel if necessary.
- // It is not called here because we don't know if these two are valid methods.
- *shouldResolveRefInBuffer = !found;
-
- if(result != OK) {
- return result; // bad pointers and length given
- }
- if(!found) { // did not find it.
- return parcel->writeBuffer(buf, sizeof(T), handle);
- }
- // found the buffer. easy case.
- return parcel->writeReference(handle,
- childHandle, childOffset);
-}
-
// ---------------------- support for casting interfaces
// Constructs a binder for this interface and caches it. If it has already been created
diff --git a/transport/include/hidl/LegacySupport.h b/transport/include/hidl/LegacySupport.h
index 1e983eb..0a9feee 100644
--- a/transport/include/hidl/LegacySupport.h
+++ b/transport/include/hidl/LegacySupport.h
@@ -91,6 +91,15 @@
return defaultPassthroughServiceImplementation<Interface>("default", maxThreads);
}
+// Make LazyServiceRegistrar static so that multiple calls to
+// registerLazyPassthroughServiceImplementation work as expected: each HAL is registered and the
+// process only exits once all HALs have 0 clients.
+static inline std::shared_ptr<LazyServiceRegistrar> getOrCreateLazyServiceRegistrar() {
+ using android::hardware::LazyServiceRegistrar;
+ static auto serviceCounter(std::make_shared<LazyServiceRegistrar>());
+ return serviceCounter;
+}
+
/**
* Registers a passthrough service implementation that exits when there are 0 clients.
*
@@ -102,15 +111,9 @@
template <class Interface>
__attribute__((warn_unused_result)) status_t registerLazyPassthroughServiceImplementation(
const std::string& name = "default") {
- // Make LazyServiceRegistrar static so that multiple calls to
- // registerLazyPassthroughServiceImplementation work as expected: each HAL is registered and the
- // process only exits once all HALs have 0 clients.
- using android::hardware::LazyServiceRegistrar;
- static auto serviceCounter(std::make_shared<LazyServiceRegistrar>());
-
return details::registerPassthroughServiceImplementation<Interface>(
[](const sp<Interface>& service, const std::string& name) {
- return serviceCounter->registerService(service, name);
+ return getOrCreateLazyServiceRegistrar()->registerService(service, name);
},
name);
}
diff --git a/transport/manager/1.0/Android.bp b/transport/manager/1.0/Android.bp
index 869c58e..c91dcd2 100644
--- a/transport/manager/1.0/Android.bp
+++ b/transport/manager/1.0/Android.bp
@@ -15,4 +15,3 @@
],
gen_java: true,
}
-
diff --git a/transport/manager/1.1/Android.bp b/transport/manager/1.1/Android.bp
index 407dfa3..82545e5 100644
--- a/transport/manager/1.1/Android.bp
+++ b/transport/manager/1.1/Android.bp
@@ -15,4 +15,3 @@
],
gen_java: true,
}
-
diff --git a/transport/manager/1.2/Android.bp b/transport/manager/1.2/Android.bp
index 3f02f78..e7ee143 100644
--- a/transport/manager/1.2/Android.bp
+++ b/transport/manager/1.2/Android.bp
@@ -17,4 +17,3 @@
],
gen_java: true,
}
-
diff --git a/transport/memory/1.0/Android.bp b/transport/memory/1.0/Android.bp
index eaa3037..dd76889 100644
--- a/transport/memory/1.0/Android.bp
+++ b/transport/memory/1.0/Android.bp
@@ -16,4 +16,3 @@
],
gen_java: false,
}
-
diff --git a/transport/safe_union/1.0/Android.bp b/transport/safe_union/1.0/Android.bp
index 88c7d5d..2760863 100644
--- a/transport/safe_union/1.0/Android.bp
+++ b/transport/safe_union/1.0/Android.bp
@@ -12,4 +12,3 @@
],
gen_java: true,
}
-
diff --git a/transport/token/1.0/Android.bp b/transport/token/1.0/Android.bp
index c0988cb..28f16f7 100644
--- a/transport/token/1.0/Android.bp
+++ b/transport/token/1.0/Android.bp
@@ -14,4 +14,3 @@
],
gen_java: true,
}
-