From 835dfe50a73c6f6de581aaa143c333af79bcca4d Mon Sep 17 00:00:00 2001 From: Tomasz Wasilczyk Date: Thu, 17 Aug 2023 16:27:22 +0000 Subject: Don't depend on String8 cast to C string Bug: 295394788 Test: m checkbuild Change-Id: I6aa039b6b2a4944e3537ef133f8785890d957edd --- libs/androidfw/AssetManager.cpp | 12 ++++++------ libs/androidfw/AssetManager2.cpp | 2 +- libs/androidfw/ResourceTypes.cpp | 6 +++--- libs/protoutil/include/android/util/ProtoOutputStream.h | 2 +- libs/protoutil/src/ProtoOutputStream.cpp | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) (limited to 'libs') diff --git a/libs/androidfw/AssetManager.cpp b/libs/androidfw/AssetManager.cpp index fd6e18ee364a..68befffecf2f 100644 --- a/libs/androidfw/AssetManager.cpp +++ b/libs/androidfw/AssetManager.cpp @@ -812,10 +812,10 @@ Asset* AssetManager::openNonAssetInPathLocked(const char* fileName, AccessMode m /* check the appropriate Zip file */ ZipFileRO* pZip = getZipFileLocked(ap); if (pZip != NULL) { - ALOGV("GOT zip, checking NA '%s'", (const char*) path); + ALOGV("GOT zip, checking NA '%s'", path.c_str()); ZipEntryRO entry = pZip->findEntryByName(path.c_str()); if (entry != NULL) { - ALOGV("FOUND NA in Zip file for %s", (const char*) path); + ALOGV("FOUND NA in Zip file for %s", path.c_str()); pAsset = openAssetFromZipLocked(pZip, entry, mode, path); pZip->releaseEntry(entry); } @@ -1425,7 +1425,7 @@ AssetManager::SharedZip::SharedZip(const String8& path, time_t modWhen) mResourceTableAsset(NULL), mResourceTable(NULL) { if (kIsDebug) { - ALOGI("Creating SharedZip %p %s\n", this, (const char*)mPath); + ALOGI("Creating SharedZip %p %s\n", this, mPath.c_str()); } ALOGV("+++ opening zip '%s'\n", mPath.c_str()); mZipFile = ZipFileRO::open(mPath.c_str()); @@ -1439,7 +1439,7 @@ AssetManager::SharedZip::SharedZip(int fd, const String8& path) mResourceTableAsset(NULL), mResourceTable(NULL) { if (kIsDebug) { - ALOGI("Creating SharedZip %p fd=%d %s\n", this, fd, (const char*)mPath); + ALOGI("Creating SharedZip %p fd=%d %s\n", this, fd, mPath.c_str()); } ALOGV("+++ opening zip fd=%d '%s'\n", fd, mPath.c_str()); mZipFile = ZipFileRO::openFd(fd, mPath.c_str()); @@ -1453,7 +1453,7 @@ sp AssetManager::SharedZip::get(const String8& path, bool createIfNotPresent) { AutoMutex _l(gLock); - time_t modWhen = getFileModDate(path); + time_t modWhen = getFileModDate(path.c_str()); sp zip = gOpen.valueFor(path).promote(); if (zip != NULL && zip->mModWhen == modWhen) { return zip; @@ -1541,7 +1541,7 @@ bool AssetManager::SharedZip::getOverlay(size_t idx, asset_path* out) const AssetManager::SharedZip::~SharedZip() { if (kIsDebug) { - ALOGI("Destroying SharedZip %p %s\n", this, (const char*)mPath); + ALOGI("Destroying SharedZip %p %s\n", this, mPath.c_str()); } if (mResourceTable != NULL) { delete mResourceTable; diff --git a/libs/androidfw/AssetManager2.cpp b/libs/androidfw/AssetManager2.cpp index fc9dd145dc5d..dc2185ea2f6c 100644 --- a/libs/androidfw/AssetManager2.cpp +++ b/libs/androidfw/AssetManager2.cpp @@ -897,7 +897,7 @@ std::string AssetManager2::GetLastResourceResolution() const { log_stream << "\nBest matching is from " << (last_resolution_.best_config_name.empty() ? "default" - : last_resolution_.best_config_name) + : last_resolution_.best_config_name.c_str()) << " configuration of " << last_resolution_.best_package_name; return log_stream.str(); } diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp index cc380625d9be..11d153eb0d14 100644 --- a/libs/androidfw/ResourceTypes.cpp +++ b/libs/androidfw/ResourceTypes.cpp @@ -5214,19 +5214,19 @@ bool ResTable::expandResourceRef(const char16_t* refStr, size_t refLen, *outType = *defType; } *outName = String16(p, end-p); - if(**outPackage == 0) { + if(outPackage->empty()) { if(outErrorMsg) { *outErrorMsg = "Resource package cannot be an empty string"; } return false; } - if(**outType == 0) { + if(outType->empty()) { if(outErrorMsg) { *outErrorMsg = "Resource type cannot be an empty string"; } return false; } - if(**outName == 0) { + if(outName->empty()) { if(outErrorMsg) { *outErrorMsg = "Resource id cannot be an empty string"; } diff --git a/libs/protoutil/include/android/util/ProtoOutputStream.h b/libs/protoutil/include/android/util/ProtoOutputStream.h index f4a358de1c41..1bfb874729d7 100644 --- a/libs/protoutil/include/android/util/ProtoOutputStream.h +++ b/libs/protoutil/include/android/util/ProtoOutputStream.h @@ -102,7 +102,7 @@ public: bool write(uint64_t fieldId, long val); bool write(uint64_t fieldId, long long val); bool write(uint64_t fieldId, bool val); - bool write(uint64_t fieldId, std::string val); + bool write(uint64_t fieldId, std::string_view val); bool write(uint64_t fieldId, const char* val, size_t size); /** diff --git a/libs/protoutil/src/ProtoOutputStream.cpp b/libs/protoutil/src/ProtoOutputStream.cpp index fcf82eed4eb1..a44a1b210924 100644 --- a/libs/protoutil/src/ProtoOutputStream.cpp +++ b/libs/protoutil/src/ProtoOutputStream.cpp @@ -170,13 +170,13 @@ ProtoOutputStream::write(uint64_t fieldId, bool val) } bool -ProtoOutputStream::write(uint64_t fieldId, std::string val) +ProtoOutputStream::write(uint64_t fieldId, std::string_view val) { if (mCompact) return false; const uint32_t id = (uint32_t)fieldId; switch (fieldId & FIELD_TYPE_MASK) { case FIELD_TYPE_STRING: - writeUtf8StringImpl(id, val.c_str(), val.size()); + writeUtf8StringImpl(id, val.data(), val.size()); return true; default: ALOGW("Field type %" PRIu64 " is not supported when writing string val.", -- cgit v1.2.3-59-g8ed1b