From 8b95a1248945b8ed565d44dda2500fc5a1a0f6fb Mon Sep 17 00:00:00 2001 From: Tomasz Wasilczyk Date: Fri, 11 Aug 2023 18:43:23 +0000 Subject: [PATCH] Lock down String8|16.string() usage All users should migrate to .c_str() Bug: 295394788 Test: make checkbuild Change-Id: Ic6295848cf3377e0bf5334448d5ed7ea53fae7ae --- libutils/include/utils/String16.h | 9 ++++++++- libutils/include/utils/String8.h | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libutils/include/utils/String16.h b/libutils/include/utils/String16.h index 1fa3723b7..44a4fd785 100644 --- a/libutils/include/utils/String16.h +++ b/libutils/include/utils/String16.h @@ -59,7 +59,6 @@ public: ~String16(); inline const char16_t* c_str() const; - inline const char16_t* string() const; size_t size() const; inline bool empty() const; @@ -188,6 +187,14 @@ protected: template explicit constexpr String16(const StaticData& s) : mString(s.data) {} + +// These symbols are for potential backward compatibility with prebuilts. To be removed. +#ifdef ENABLE_STRING8_OBSOLETE_METHODS +public: +#else +private: +#endif + inline const char16_t* string() const; }; // String16 can be trivially moved using memcpy() because moving does not diff --git a/libutils/include/utils/String8.h b/libutils/include/utils/String8.h index 0b92f5b10..6d250723b 100644 --- a/libutils/include/utils/String8.h +++ b/libutils/include/utils/String8.h @@ -65,7 +65,6 @@ public: static String8 formatV(const char* fmt, va_list args); inline const char* c_str() const; - inline const char* string() const; inline size_t size() const; inline size_t bytes() const; @@ -155,6 +154,7 @@ public: #else private: #endif + inline const char* string() const; inline bool isEmpty() const; };