Migrate String8/16 from .string() to c_str()
This will align usage with std::string.
Bug: 295394788
Test: make checkbuild
Change-Id: Ic5c215b011197950dcbcb0339f44cc68fefc65a1
diff --git a/fs_mgr/libfiemap/binder.cpp b/fs_mgr/libfiemap/binder.cpp
index 41e534a..439aac9 100644
--- a/fs_mgr/libfiemap/binder.cpp
+++ b/fs_mgr/libfiemap/binder.cpp
@@ -77,7 +77,7 @@
static FiemapStatus ToFiemapStatus(const char* func, const binder::Status& status) {
if (!status.isOk()) {
- LOG(ERROR) << func << " binder returned: " << status.toString8().string();
+ LOG(ERROR) << func << " binder returned: " << status.toString8().c_str();
if (status.serviceSpecificErrorCode() != 0) {
return FiemapStatus::FromErrorCode(status.serviceSpecificErrorCode());
} else {
@@ -106,7 +106,7 @@
auto status = manager_->deleteBackingImage(name);
if (!status.isOk()) {
LOG(ERROR) << __PRETTY_FUNCTION__
- << " binder returned: " << status.exceptionMessage().string();
+ << " binder returned: " << status.exceptionMessage().c_str();
return false;
}
return true;
@@ -122,7 +122,7 @@
auto status = manager_->mapImageDevice(name, timeout_ms_count, &map);
if (!status.isOk()) {
LOG(ERROR) << __PRETTY_FUNCTION__
- << " binder returned: " << status.exceptionMessage().string();
+ << " binder returned: " << status.exceptionMessage().c_str();
return false;
}
*path = map.path;
@@ -133,7 +133,7 @@
auto status = manager_->unmapImageDevice(name);
if (!status.isOk()) {
LOG(ERROR) << __PRETTY_FUNCTION__
- << " binder returned: " << status.exceptionMessage().string();
+ << " binder returned: " << status.exceptionMessage().c_str();
return false;
}
return true;
@@ -144,7 +144,7 @@
auto status = manager_->backingImageExists(name, &retval);
if (!status.isOk()) {
LOG(ERROR) << __PRETTY_FUNCTION__
- << " binder returned: " << status.exceptionMessage().string();
+ << " binder returned: " << status.exceptionMessage().c_str();
return false;
}
return retval;
@@ -155,7 +155,7 @@
auto status = manager_->isImageMapped(name, &retval);
if (!status.isOk()) {
LOG(ERROR) << __PRETTY_FUNCTION__
- << " binder returned: " << status.exceptionMessage().string();
+ << " binder returned: " << status.exceptionMessage().c_str();
return false;
}
return retval;
@@ -175,7 +175,7 @@
auto status = manager_->getAllBackingImages(&retval);
if (!status.isOk()) {
LOG(ERROR) << __PRETTY_FUNCTION__
- << " binder returned: " << status.exceptionMessage().string();
+ << " binder returned: " << status.exceptionMessage().c_str();
}
return retval;
}
@@ -189,7 +189,7 @@
auto status = manager_->removeAllImages();
if (!status.isOk()) {
LOG(ERROR) << __PRETTY_FUNCTION__
- << " binder returned: " << status.exceptionMessage().string();
+ << " binder returned: " << status.exceptionMessage().c_str();
return false;
}
return true;
@@ -199,7 +199,7 @@
auto status = manager_->disableImage(name);
if (!status.isOk()) {
LOG(ERROR) << __PRETTY_FUNCTION__
- << " binder returned: " << status.exceptionMessage().string();
+ << " binder returned: " << status.exceptionMessage().c_str();
return false;
}
return true;
@@ -209,7 +209,7 @@
auto status = manager_->removeDisabledImages();
if (!status.isOk()) {
LOG(ERROR) << __PRETTY_FUNCTION__
- << " binder returned: " << status.exceptionMessage().string();
+ << " binder returned: " << status.exceptionMessage().c_str();
return false;
}
return true;
@@ -219,7 +219,7 @@
auto status = manager_->getMappedImageDevice(name, device);
if (!status.isOk()) {
LOG(ERROR) << __PRETTY_FUNCTION__
- << " binder returned: " << status.exceptionMessage().string();
+ << " binder returned: " << status.exceptionMessage().c_str();
return false;
}
return !device->empty();
@@ -230,7 +230,7 @@
auto status = manager_->isImageDisabled(name, &retval);
if (!status.isOk()) {
LOG(ERROR) << __PRETTY_FUNCTION__
- << " binder returned: " << status.exceptionMessage().string();
+ << " binder returned: " << status.exceptionMessage().c_str();
return false;
}
return retval;
@@ -249,7 +249,7 @@
auto status = service->openImageService(dir, &manager);
if (!status.isOk() || !manager) {
- LOG(ERROR) << "Could not acquire IImageManager: " << status.exceptionMessage().string();
+ LOG(ERROR) << "Could not acquire IImageManager: " << status.exceptionMessage().c_str();
return nullptr;
}
return std::make_unique<ImageManagerBinder>(std::move(service), std::move(manager));
diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp
index bd7955a..15c30be 100644
--- a/healthd/BatteryMonitor.cpp
+++ b/healthd/BatteryMonitor.cpp
@@ -444,12 +444,10 @@
for (size_t i = 0; i < mChargerNames.size(); i++) {
String8 path;
- path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH,
- mChargerNames[i].string());
+ path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].c_str());
if (getIntField(path)) {
path.clear();
- path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH,
- mChargerNames[i].string());
+ path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].c_str());
switch(readPowerSupplyType(path)) {
case ANDROID_POWER_SUPPLY_TYPE_AC:
mHealthInfo->chargerAcOnline = true;
@@ -466,26 +464,24 @@
default:
path.clear();
path.appendFormat("%s/%s/is_dock", POWER_SUPPLY_SYSFS_PATH,
- mChargerNames[i].string());
- if (access(path.string(), R_OK) == 0)
+ mChargerNames[i].c_str());
+ if (access(path.c_str(), R_OK) == 0)
mHealthInfo->chargerDockOnline = true;
else
KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n",
- mChargerNames[i].string());
+ mChargerNames[i].c_str());
}
path.clear();
path.appendFormat("%s/%s/current_max", POWER_SUPPLY_SYSFS_PATH,
- mChargerNames[i].string());
- int ChargingCurrent =
- (access(path.string(), R_OK) == 0) ? getIntField(path) : 0;
+ mChargerNames[i].c_str());
+ int ChargingCurrent = (access(path.c_str(), R_OK) == 0) ? getIntField(path) : 0;
path.clear();
path.appendFormat("%s/%s/voltage_max", POWER_SUPPLY_SYSFS_PATH,
- mChargerNames[i].string());
+ mChargerNames[i].c_str());
int ChargingVoltage =
- (access(path.string(), R_OK) == 0) ? getIntField(path) :
- DEFAULT_VBUS_VOLTAGE;
+ (access(path.c_str(), R_OK) == 0) ? getIntField(path) : DEFAULT_VBUS_VOLTAGE;
double power = ((double)ChargingCurrent / MILLION) *
((double)ChargingVoltage / MILLION);
@@ -775,8 +771,7 @@
case ANDROID_POWER_SUPPLY_TYPE_DOCK:
path.clear();
path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name);
- if (access(path.string(), R_OK) == 0)
- mChargerNames.add(String8(name));
+ if (access(path.c_str(), R_OK) == 0) mChargerNames.add(String8(name));
break;
case ANDROID_POWER_SUPPLY_TYPE_BATTERY:
@@ -958,12 +953,10 @@
// Look for "is_dock" file
path.clear();
path.appendFormat("%s/%s/is_dock", POWER_SUPPLY_SYSFS_PATH, name);
- if (access(path.string(), R_OK) == 0) {
+ if (access(path.c_str(), R_OK) == 0) {
path.clear();
path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name);
- if (access(path.string(), R_OK) == 0)
- mChargerNames.add(String8(name));
-
+ if (access(path.c_str(), R_OK) == 0) mChargerNames.add(String8(name));
}
}
}
diff --git a/healthd/BatteryMonitor_v1.cpp b/healthd/BatteryMonitor_v1.cpp
index b87c493..b2d6518 100644
--- a/healthd/BatteryMonitor_v1.cpp
+++ b/healthd/BatteryMonitor_v1.cpp
@@ -358,12 +358,10 @@
for (size_t i = 0; i < mChargerNames.size(); i++) {
String8 path;
- path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH,
- mChargerNames[i].string());
+ path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].c_str());
if (getIntField(path)) {
path.clear();
- path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH,
- mChargerNames[i].string());
+ path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].c_str());
switch(readPowerSupplyType(path)) {
case ANDROID_POWER_SUPPLY_TYPE_AC:
mHealthInfo->chargerAcOnline = true;
@@ -380,26 +378,24 @@
default:
path.clear();
path.appendFormat("%s/%s/is_dock", POWER_SUPPLY_SYSFS_PATH,
- mChargerNames[i].string());
- if (access(path.string(), R_OK) == 0)
+ mChargerNames[i].c_str());
+ if (access(path.c_str(), R_OK) == 0)
mHealthInfo->chargerDockOnline = true;
else
KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n",
- mChargerNames[i].string());
+ mChargerNames[i].c_str());
}
path.clear();
path.appendFormat("%s/%s/current_max", POWER_SUPPLY_SYSFS_PATH,
- mChargerNames[i].string());
- int ChargingCurrent =
- (access(path.string(), R_OK) == 0) ? getIntField(path) : 0;
+ mChargerNames[i].c_str());
+ int ChargingCurrent = (access(path.c_str(), R_OK) == 0) ? getIntField(path) : 0;
path.clear();
path.appendFormat("%s/%s/voltage_max", POWER_SUPPLY_SYSFS_PATH,
- mChargerNames[i].string());
+ mChargerNames[i].c_str());
int ChargingVoltage =
- (access(path.string(), R_OK) == 0) ? getIntField(path) :
- DEFAULT_VBUS_VOLTAGE;
+ (access(path.c_str(), R_OK) == 0) ? getIntField(path) : DEFAULT_VBUS_VOLTAGE;
double power = ((double)ChargingCurrent / MILLION) *
((double)ChargingVoltage / MILLION);
@@ -628,8 +624,7 @@
case ANDROID_POWER_SUPPLY_TYPE_DOCK:
path.clear();
path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name);
- if (access(path.string(), R_OK) == 0)
- mChargerNames.add(String8(name));
+ if (access(path.c_str(), R_OK) == 0) mChargerNames.add(String8(name));
break;
case ANDROID_POWER_SUPPLY_TYPE_BATTERY:
@@ -767,12 +762,10 @@
// Look for "is_dock" file
path.clear();
path.appendFormat("%s/%s/is_dock", POWER_SUPPLY_SYSFS_PATH, name);
- if (access(path.string(), R_OK) == 0) {
+ if (access(path.c_str(), R_OK) == 0) {
path.clear();
path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name);
- if (access(path.string(), R_OK) == 0)
- mChargerNames.add(String8(name));
-
+ if (access(path.c_str(), R_OK) == 0) mChargerNames.add(String8(name));
}
}
}
diff --git a/libutils/ProcessCallStack.cpp b/libutils/ProcessCallStack.cpp
index f054de9..4b27bdd 100644
--- a/libutils/ProcessCallStack.cpp
+++ b/libutils/ProcessCallStack.cpp
@@ -205,8 +205,7 @@
}
void ProcessCallStack::printInternal(Printer& printer, Printer& csPrinter) const {
- dumpProcessHeader(printer, getpid(),
- getTimeString(mTimeUpdated).string());
+ dumpProcessHeader(printer, getpid(), getTimeString(mTimeUpdated).c_str());
for (size_t i = 0; i < mThreadMap.size(); ++i) {
pid_t tid = mThreadMap.keyAt(i);
@@ -214,7 +213,7 @@
const String8& threadName = threadInfo.threadName;
printer.printLine("");
- printer.printFormatLine("\"%s\" sysTid=%d", threadName.string(), tid);
+ printer.printFormatLine("\"%s\" sysTid=%d", threadName.c_str(), tid);
threadInfo.callStack.print(csPrinter);
}
diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp
index ab122c7..e0a2846 100644
--- a/libutils/RefBase.cpp
+++ b/libutils/RefBase.cpp
@@ -330,7 +330,7 @@
this);
int rc = open(name, O_RDWR | O_CREAT | O_APPEND, 0644);
if (rc >= 0) {
- (void)write(rc, text.string(), text.length());
+ (void)write(rc, text.c_str(), text.length());
close(rc);
ALOGI("STACK TRACE for %p saved in %s", this, name);
}
diff --git a/libutils/String16_fuzz.cpp b/libutils/String16_fuzz.cpp
index d7e5ec7..a271aee 100644
--- a/libutils/String16_fuzz.cpp
+++ b/libutils/String16_fuzz.cpp
@@ -25,7 +25,7 @@
// Bytes and size
([](FuzzedDataProvider&, android::String16 str1, android::String16) -> void {
- str1.string();
+ str1.c_str();
}),
([](FuzzedDataProvider&, android::String16 str1, android::String16) -> void {
str1.isStaticString();
@@ -39,7 +39,7 @@
str1.startsWith(str2);
}),
([](FuzzedDataProvider&, android::String16 str1, android::String16 str2) -> void {
- str1.contains(str2.string());
+ str1.contains(str2.c_str());
}),
([](FuzzedDataProvider&, android::String16 str1, android::String16 str2) -> void {
str1.compare(str2);
@@ -52,7 +52,7 @@
([](FuzzedDataProvider& dataProvider, android::String16 str1,
android::String16 str2) -> void {
int pos = dataProvider.ConsumeIntegralInRange<int>(0, str1.size());
- str1.insert(pos, str2.string());
+ str1.insert(pos, str2.c_str());
}),
// Find and replace operations
diff --git a/libutils/String8_test.cpp b/libutils/String8_test.cpp
index 35fd512..9c12cb1 100644
--- a/libutils/String8_test.cpp
+++ b/libutils/String8_test.cpp
@@ -36,7 +36,7 @@
TEST_F(String8Test, Cstr) {
String8 tmp("Hello, world!");
- EXPECT_STREQ(tmp.string(), "Hello, world!");
+ EXPECT_STREQ(tmp.c_str(), "Hello, world!");
}
TEST_F(String8Test, OperatorPlus) {
@@ -45,16 +45,16 @@
// Test adding String8 + const char*
const char* ccsrc2 = "world!";
String8 dst1 = src1 + ccsrc2;
- EXPECT_STREQ(dst1.string(), "Hello, world!");
- EXPECT_STREQ(src1.string(), "Hello, ");
+ EXPECT_STREQ(dst1.c_str(), "Hello, world!");
+ EXPECT_STREQ(src1.c_str(), "Hello, ");
EXPECT_STREQ(ccsrc2, "world!");
// Test adding String8 + String8
String8 ssrc2("world!");
String8 dst2 = src1 + ssrc2;
- EXPECT_STREQ(dst2.string(), "Hello, world!");
- EXPECT_STREQ(src1.string(), "Hello, ");
- EXPECT_STREQ(ssrc2.string(), "world!");
+ EXPECT_STREQ(dst2.c_str(), "Hello, world!");
+ EXPECT_STREQ(src1.c_str(), "Hello, ");
+ EXPECT_STREQ(ssrc2.c_str(), "world!");
}
TEST_F(String8Test, OperatorPlusEquals) {
@@ -63,14 +63,14 @@
// Testing String8 += String8
String8 src2(" is my passport.");
src1 += src2;
- EXPECT_STREQ(src1.string(), "My voice is my passport.");
- EXPECT_STREQ(src2.string(), " is my passport.");
+ EXPECT_STREQ(src1.c_str(), "My voice is my passport.");
+ EXPECT_STREQ(src2.c_str(), " is my passport.");
// Adding const char* to the previous string.
const char* src3 = " Verify me.";
src1 += src3;
- EXPECT_STREQ(src1.string(), "My voice is my passport. Verify me.");
- EXPECT_STREQ(src2.string(), " is my passport.");
+ EXPECT_STREQ(src1.c_str(), "My voice is my passport. Verify me.");
+ EXPECT_STREQ(src2.c_str(), " is my passport.");
EXPECT_STREQ(src3, " Verify me.");
}
diff --git a/libutils/Tokenizer.cpp b/libutils/Tokenizer.cpp
index c3ec165..9fc955c 100644
--- a/libutils/Tokenizer.cpp
+++ b/libutils/Tokenizer.cpp
@@ -50,15 +50,15 @@
*outTokenizer = nullptr;
int result = OK;
- int fd = ::open(filename.string(), O_RDONLY);
+ int fd = ::open(filename.c_str(), O_RDONLY);
if (fd < 0) {
result = -errno;
- ALOGE("Error opening file '%s': %s", filename.string(), strerror(errno));
+ ALOGE("Error opening file '%s': %s", filename.c_str(), strerror(errno));
} else {
struct stat stat;
if (fstat(fd, &stat)) {
result = -errno;
- ALOGE("Error getting size of file '%s': %s", filename.string(), strerror(errno));
+ ALOGE("Error getting size of file '%s': %s", filename.c_str(), strerror(errno));
} else {
size_t length = size_t(stat.st_size);
@@ -80,7 +80,7 @@
ssize_t nrd = read(fd, buffer, length);
if (nrd < 0) {
result = -errno;
- ALOGE("Error reading file '%s': %s", filename.string(), strerror(errno));
+ ALOGE("Error reading file '%s': %s", filename.c_str(), strerror(errno));
delete[] buffer;
buffer = nullptr;
} else {
@@ -106,7 +106,7 @@
String8 Tokenizer::getLocation() const {
String8 result;
- result.appendFormat("%s:%d", mFilename.string(), mLineNumber);
+ result.appendFormat("%s:%d", mFilename.c_str(), mLineNumber);
return result;
}