diff options
author | 2021-01-08 02:13:00 +0000 | |
---|---|---|
committer | 2021-01-08 02:13:00 +0000 | |
commit | 0bda2d23eac71902ca802a2209396abcf77699e9 (patch) | |
tree | 4b15ebc8ce0a5318432b35c676da8ab65be6ac51 | |
parent | 048f1e93fd31849b1b9d9e9dc4293e630280caae (diff) |
libbinder: ParcelableHolder - avoid utf-8<->utf-16
Switching getParcelableDescriptor to String16:
- consistent w/ interfaces
- can use StaticString16 (no static dirty heap allocation)
- avoid converting these strings utf-8/utf-16
Bug: 170909836
Test: aidl_integration_test
Change-Id: I51f81fc89d95f2697524512b9d5cf3bd669dbb0e
-rw-r--r-- | libs/binder/ParcelableHolder.cpp | 2 | ||||
-rw-r--r-- | libs/binder/include/binder/ParcelableHolder.h | 9 |
2 files changed, 6 insertions, 5 deletions
diff --git a/libs/binder/ParcelableHolder.cpp b/libs/binder/ParcelableHolder.cpp index b2b86716d5..2e86b7415a 100644 --- a/libs/binder/ParcelableHolder.cpp +++ b/libs/binder/ParcelableHolder.cpp @@ -37,7 +37,7 @@ status_t ParcelableHolder::writeToParcel(Parcel* p) const { size_t sizePos = p->dataPosition(); RETURN_ON_FAILURE(p->writeInt32(0)); size_t dataStartPos = p->dataPosition(); - RETURN_ON_FAILURE(p->writeUtf8AsUtf16(this->mParcelableName)); + RETURN_ON_FAILURE(p->writeString16(this->mParcelableName)); this->mParcelable->writeToParcel(p); size_t dataSize = p->dataPosition() - dataStartPos; diff --git a/libs/binder/include/binder/ParcelableHolder.h b/libs/binder/include/binder/ParcelableHolder.h index ff0a6860f3..9e4475c947 100644 --- a/libs/binder/include/binder/ParcelableHolder.h +++ b/libs/binder/include/binder/ParcelableHolder.h @@ -18,6 +18,7 @@ #include <binder/Parcel.h> #include <binder/Parcelable.h> +#include <utils/String16.h> #include <mutex> #include <optional> #include <tuple> @@ -72,7 +73,7 @@ public: template <typename T> status_t getParcelable(std::shared_ptr<T>* ret) const { static_assert(std::is_base_of<Parcelable, T>::value, "T must be derived from Parcelable"); - const std::string& parcelableDesc = T::getParcelableDescriptor(); + const String16& parcelableDesc = T::getParcelableDescriptor(); if (!this->mParcelPtr) { if (!this->mParcelable || !this->mParcelableName) { ALOGD("empty ParcelableHolder"); @@ -80,7 +81,7 @@ public: return android::OK; } else if (parcelableDesc != *mParcelableName) { ALOGD("extension class name mismatch expected:%s actual:%s", - mParcelableName->c_str(), parcelableDesc.c_str()); + String8(*mParcelableName).c_str(), String8(parcelableDesc).c_str()); *ret = nullptr; return android::BAD_VALUE; } @@ -88,7 +89,7 @@ public: return android::OK; } this->mParcelPtr->setDataPosition(0); - status_t status = this->mParcelPtr->readUtf8FromUtf16(&this->mParcelableName); + status_t status = this->mParcelPtr->readString16(&this->mParcelableName); if (status != android::OK || parcelableDesc != this->mParcelableName) { this->mParcelableName = std::nullopt; *ret = nullptr; @@ -130,7 +131,7 @@ public: private: mutable std::shared_ptr<Parcelable> mParcelable; - mutable std::optional<std::string> mParcelableName; + mutable std::optional<String16> mParcelableName; mutable std::unique_ptr<Parcel> mParcelPtr; Stability mStability; }; |