summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2021-03-30 01:59:19 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-03-30 01:59:19 +0000
commit681d0f0e34ca69e38fd195ff72803c525f2a623f (patch)
treeb2ee6796c081cb83f9fd185f82b9386a3dd3f9d1
parent413b305542d42de8bfcbb287022514e2fc779b3d (diff)
parent6e0d6b100bd494cdac55e6ade184f3eb325583ce (diff)
downloadlibhidl-681d0f0e34ca69e38fd195ff72803c525f2a623f.tar.gz
Snap for 7243396 from ee47ab21d540f11f6b5ff8abec8872b212429bf7 to sc-release am: 6e0d6b100b
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/libhidl/+/14022895 Change-Id: Ia410fe7e6335a2917d15fe9e74fa70ee43410765
-rw-r--r--base/HidlSupport.cpp8
-rw-r--r--test_main.cpp14
-rw-r--r--transport/include/hidl/ServiceManagement.h5
3 files changed, 26 insertions, 1 deletions
diff --git a/base/HidlSupport.cpp b/base/HidlSupport.cpp
index af805b9..78faa2f 100644
--- a/base/HidlSupport.cpp
+++ b/base/HidlSupport.cpp
@@ -217,6 +217,14 @@ void hidl_string::copyFrom(const char *data, size_t size) {
if (size >= UINT32_MAX) {
LOG(FATAL) << "string size can't exceed 2^32 bytes: " << size;
}
+
+ if (size == 0) {
+ mBuffer = kEmptyString;
+ mSize = 0;
+ mOwnsBuffer = false;
+ return;
+ }
+
char *buf = (char *)malloc(size + 1);
memcpy(buf, data, size);
buf[size] = '\0';
diff --git a/test_main.cpp b/test_main.cpp
index ea4dfd1..5c6c78e 100644
--- a/test_main.cpp
+++ b/test_main.cpp
@@ -175,6 +175,20 @@ TEST_F(LibHidlTest, StringTest) {
EXPECT_FALSE(hs2 <= hs1);
}
+// empty string optimization should apply for any constructor
+TEST_F(LibHidlTest, HidlStringEmptyLiteralAllocation) {
+ using android::hardware::hidl_string;
+
+ hidl_string empty1;
+ hidl_string empty2("");
+ hidl_string empty3("foo", 0);
+ hidl_string empty4((std::string()));
+
+ EXPECT_EQ(empty1.c_str(), empty2.c_str());
+ EXPECT_EQ(empty1.c_str(), empty3.c_str());
+ EXPECT_EQ(empty1.c_str(), empty4.c_str());
+}
+
TEST_F(LibHidlTest, MemoryTest) {
using android::hardware::hidl_memory;
diff --git a/transport/include/hidl/ServiceManagement.h b/transport/include/hidl/ServiceManagement.h
index c8e8f6c..886e816 100644
--- a/transport/include/hidl/ServiceManagement.h
+++ b/transport/include/hidl/ServiceManagement.h
@@ -54,7 +54,10 @@ void setTrebleTestingOverride(bool testingOverride);
void preloadPassthroughService(const std::string &descriptor);
// Returns a service with the following constraints:
-// - retry => service is waited for and returned if available in this process
+// - retry => service is waited for and returned if it is declared in the
+// manifest AND it is available in this process (if errors indicate an
+// sepolicy denial, then this will return - TODO(b/28321379) more precise
+// errors to handle more cases)
// - getStub => internal only. Forces to get the unwrapped (no BsFoo) if available.
// TODO(b/65843592)
// If the service is a remote service, this function returns BpBase. If the service is