Skip to content

Commit

Permalink
Use String8/16 c_str
Browse files Browse the repository at this point in the history
Bug: 295394788
Test: make checkbuild
Change-Id: I538720d4de2dcc038b417048209782ff605b7e30
  • Loading branch information
twasilczyk committed Aug 28, 2023
1 parent 6c8fb01 commit 3815d34
Show file tree
Hide file tree
Showing 48 changed files with 214 additions and 212 deletions.
10 changes: 5 additions & 5 deletions cmds/app_process/app_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ class AppRuntime : public AndroidRuntime
* executing boot class Java code and thereby deny ourselves access to
* non-boot classes.
*/
char* slashClassName = toSlashClassName(mClassName.string());
char* slashClassName = toSlashClassName(mClassName.c_str());
mClass = env->FindClass(slashClassName);
if (mClass == NULL) {
ALOGE("ERROR: could not find class '%s'\n", mClassName.string());
ALOGE("ERROR: could not find class '%s'\n", mClassName.c_str());
}
free(slashClassName);

Expand Down Expand Up @@ -179,7 +179,7 @@ int main(int argc, char* const argv[])
argv_String.append(argv[i]);
argv_String.append("\" ");
}
ALOGV("app_process main with argv: %s", argv_String.string());
ALOGV("app_process main with argv: %s", argv_String.c_str());
}

AppRuntime runtime(argv[0], computeArgBlockSize(argc, argv));
Expand Down Expand Up @@ -300,7 +300,7 @@ int main(int argc, char* const argv[])
restOfArgs.append(argv_new[k]);
restOfArgs.append("\" ");
}
ALOGV("Class name = %s, args = %s", className.string(), restOfArgs.string());
ALOGV("Class name = %s, args = %s", className.c_str(), restOfArgs.c_str());
}
} else {
// We're in zygote mode.
Expand Down Expand Up @@ -329,7 +329,7 @@ int main(int argc, char* const argv[])
}

if (!niceName.empty()) {
runtime.setArgv0(niceName.string(), true /* setProcName */);
runtime.setArgv0(niceName.c_str(), true /* setProcName */);
}

if (zygote) {
Expand Down
16 changes: 8 additions & 8 deletions cmds/bootanimation/BootAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ bool BootAnimation::parseAnimationDesc(Animation& animation) {
if (!readFile(animation.zip, "desc.txt", desString)) {
return false;
}
char const* s = desString.string();
char const* s = desString.c_str();
std::string dynamicColoringPartName = "";
bool postDynamicColoring = false;

Expand All @@ -1146,7 +1146,7 @@ bool BootAnimation::parseAnimationDesc(Animation& animation) {
const char* endl = strstr(s, "\n");
if (endl == nullptr) break;
String8 line(s, endl - s);
const char* l = line.string();
const char* l = line.c_str();
int fps = 0;
int width = 0;
int height = 0;
Expand Down Expand Up @@ -1330,15 +1330,15 @@ bool BootAnimation::preloadZip(Animation& animation) {

// If there is trimData present, override the positioning defaults.
for (Animation::Part& part : animation.parts) {
const char* trimDataStr = part.trimData.string();
const char* trimDataStr = part.trimData.c_str();
for (size_t frameIdx = 0; frameIdx < part.frames.size(); frameIdx++) {
const char* endl = strstr(trimDataStr, "\n");
// No more trimData for this part.
if (endl == nullptr) {
break;
}
String8 line(trimDataStr, endl - trimDataStr);
const char* lineStr = line.string();
const char* lineStr = line.c_str();
trimDataStr = ++endl;
int width = 0, height = 0, x = 0, y = 0;
if (sscanf(lineStr, "%dx%d+%d+%d", &width, &height, &x, &y) == 4) {
Expand Down Expand Up @@ -1566,7 +1566,7 @@ bool BootAnimation::playAnimation(const Animation& animation) {
1.0f);

ALOGD("Playing files = %s/%s, Requested repeat = %d, playUntilComplete = %s",
animation.fileName.string(), part.path.string(), part.count,
animation.fileName.c_str(), part.path.c_str(), part.count,
part.playUntilComplete ? "true" : "false");

// For the last animation, if we have progress indicator from
Expand Down Expand Up @@ -1787,17 +1787,17 @@ void BootAnimation::releaseAnimation(Animation* animation) const {
BootAnimation::Animation* BootAnimation::loadAnimation(const String8& fn) {
if (mLoadedFiles.indexOf(fn) >= 0) {
SLOGE("File \"%s\" is already loaded. Cyclic ref is not allowed",
fn.string());
fn.c_str());
return nullptr;
}
ZipFileRO *zip = ZipFileRO::open(fn);
if (zip == nullptr) {
SLOGE("Failed to open animation zip \"%s\": %s",
fn.string(), strerror(errno));
fn.c_str(), strerror(errno));
return nullptr;
}

ALOGD("%s is loaded successfully", fn.string());
ALOGD("%s is loaded successfully", fn.c_str());

Animation *animation = new Animation;
animation->fileName = fn;
Expand Down
10 changes: 5 additions & 5 deletions cmds/incident/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ StatusListener::onReportSectionStatus(int32_t section, int32_t status)
Status
StatusListener::onReportServiceStatus(const String16& service, int32_t status)
{
fprintf(stderr, "service '%s' status %d\n", String8(service).string(), status);
ALOGD("service '%s' status %d\n", String8(service).string(), status);
fprintf(stderr, "service '%s' status %d\n", String8(service).c_str(), status);
ALOGD("service '%s' status %d\n", String8(service).c_str(), status);
return Status::ok();
}

Expand Down Expand Up @@ -384,7 +384,7 @@ main(int argc, char** argv)
status = service->reportIncidentToStream(args, listener, std::move(writeEnd));

if (!status.isOk()) {
fprintf(stderr, "reportIncident returned \"%s\"\n", status.toString8().string());
fprintf(stderr, "reportIncident returned \"%s\"\n", status.toString8().c_str());
return 1;
}

Expand All @@ -396,14 +396,14 @@ main(int argc, char** argv)
sp<StatusListener> listener(new StatusListener());
status = service->reportIncidentToDumpstate(std::move(writeEnd), listener);
if (!status.isOk()) {
fprintf(stderr, "reportIncident returned \"%s\"\n", status.toString8().string());
fprintf(stderr, "reportIncident returned \"%s\"\n", status.toString8().c_str());
return 1;
}
return listener->getExitCodeOrElse(stream_output(fds[0], STDOUT_FILENO));
} else {
status = service->reportIncident(args);
if (!status.isOk()) {
fprintf(stderr, "reportIncident returned \"%s\"\n", status.toString8().string());
fprintf(stderr, "reportIncident returned \"%s\"\n", status.toString8().c_str());
return 1;
} else {
return 0;
Expand Down
8 changes: 4 additions & 4 deletions cmds/incident_helper/src/TextParserBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ status_t NoopParser::Parse(const int in, const int out) const
{
string content;
if (!ReadFdToString(in, &content)) {
fprintf(stderr, "[%s]Failed to read data from incidentd\n", this->name.string());
fprintf(stderr, "[%s]Failed to read data from incidentd\n", this->name.c_str());
return -1;
}
if (!WriteStringToFd(content, out)) {
fprintf(stderr, "[%s]Failed to write data to incidentd\n", this->name.string());
fprintf(stderr, "[%s]Failed to write data to incidentd\n", this->name.c_str());
return -1;
}
return NO_ERROR;
Expand All @@ -42,13 +42,13 @@ status_t ReverseParser::Parse(const int in, const int out) const
{
string content;
if (!ReadFdToString(in, &content)) {
fprintf(stderr, "[%s]Failed to read data from incidentd\n", this->name.string());
fprintf(stderr, "[%s]Failed to read data from incidentd\n", this->name.c_str());
return -1;
}
// reverse the content
reverse(content.begin(), content.end());
if (!WriteStringToFd(content, out)) {
fprintf(stderr, "[%s]Failed to write data to incidentd\n", this->name.string());
fprintf(stderr, "[%s]Failed to write data to incidentd\n", this->name.c_str());
return -1;
}
return NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion cmds/incident_helper/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int main(int argc, char** argv) {
fprintf(stderr, "Pasring section %d...\n", sectionID);
TextParserBase* parser = selectParser(sectionID);
if (parser != nullptr) {
fprintf(stderr, "Running parser: %s\n", parser->name.string());
fprintf(stderr, "Running parser: %s\n", parser->name.c_str());
status_t err = parser->Parse(STDIN_FILENO, STDOUT_FILENO);
if (err != NO_ERROR) {
fprintf(stderr, "Parse error in section %d: %s\n", sectionID, strerror(-err));
Expand Down
4 changes: 2 additions & 2 deletions cmds/incident_helper/src/parsers/BatteryTypeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ BatteryTypeParser::Parse(const int in, const int out) const
}

if (!proto.flush(out)) {
fprintf(stderr, "[%s]Error writing proto back\n", this->name.string());
fprintf(stderr, "[%s]Error writing proto back\n", this->name.c_str());
return -1;
}
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.string(), proto.size());
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.c_str(), proto.size());
return NO_ERROR;
}
4 changes: 2 additions & 2 deletions cmds/incident_helper/src/parsers/CpuFreqParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ CpuFreqParser::Parse(const int in, const int out) const
}

if (!proto.flush(out)) {
fprintf(stderr, "[%s]Error writing proto back\n", this->name.string());
fprintf(stderr, "[%s]Error writing proto back\n", this->name.c_str());
return -1;
}
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.string(), proto.size());
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.c_str(), proto.size());
return NO_ERROR;
}
10 changes: 5 additions & 5 deletions cmds/incident_helper/src/parsers/CpuInfoParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ CpuInfoParser::Parse(const int in, const int out) const
record = parseRecordByColumns(line, columnIndices);
diff = record.size() - header.size();
if (diff < 0) {
fprintf(stderr, "[%s]Line %d has %d missing fields\n%s\n", this->name.string(), nline, -diff, line.c_str());
fprintf(stderr, "[%s]Line %d has %d missing fields\n%s\n", this->name.c_str(), nline, -diff, line.c_str());
printRecord(record);
continue;
} else if (diff > 0) {
fprintf(stderr, "[%s]Line %d has %d extra fields\n%s\n", this->name.string(), nline, diff, line.c_str());
fprintf(stderr, "[%s]Line %d has %d extra fields\n%s\n", this->name.c_str(), nline, diff, line.c_str());
printRecord(record);
continue;
}
Expand All @@ -143,7 +143,7 @@ CpuInfoParser::Parse(const int in, const int out) const
for (int i=0; i<(int)record.size(); i++) {
if (!table.insertField(&proto, header[i], record[i])) {
fprintf(stderr, "[%s]Line %d fails to insert field %s with value %s\n",
this->name.string(), nline, header[i].c_str(), record[i].c_str());
this->name.c_str(), nline, header[i].c_str(), record[i].c_str());
}
}
proto.end(token);
Expand All @@ -155,9 +155,9 @@ CpuInfoParser::Parse(const int in, const int out) const
}

if (!proto.flush(out)) {
fprintf(stderr, "[%s]Error writing proto back\n", this->name.string());
fprintf(stderr, "[%s]Error writing proto back\n", this->name.c_str());
return -1;
}
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.string(), proto.size());
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.c_str(), proto.size());
return NO_ERROR;
}
4 changes: 2 additions & 2 deletions cmds/incident_helper/src/parsers/EventLogTagsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ EventLogTagsParser::Parse(const int in, const int out) const
}

if (!proto.flush(out)) {
fprintf(stderr, "[%s]Error writing proto back\n", this->name.string());
fprintf(stderr, "[%s]Error writing proto back\n", this->name.c_str());
return -1;
}
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.string(), proto.size());
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.c_str(), proto.size());
return NO_ERROR;
}
10 changes: 5 additions & 5 deletions cmds/incident_helper/src/parsers/KernelWakesParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ KernelWakesParser::Parse(const int in, const int out) const

if (record.size() < header.size()) {
// TODO: log this to incident report!
fprintf(stderr, "[%s]Line %d has missing fields\n%s\n", this->name.string(), nline, line.c_str());
fprintf(stderr, "[%s]Line %d has missing fields\n%s\n", this->name.c_str(), nline, line.c_str());
continue;
} else if (record.size() > header.size()) {
// TODO: log this to incident report!
fprintf(stderr, "[%s]Line %d has extra fields\n%s\n", this->name.string(), nline, line.c_str());
fprintf(stderr, "[%s]Line %d has extra fields\n%s\n", this->name.c_str(), nline, line.c_str());
continue;
}

uint64_t token = proto.start(KernelWakeSourcesProto::WAKEUP_SOURCES);
for (int i=0; i<(int)record.size(); i++) {
if (!table.insertField(&proto, header[i], record[i])) {
fprintf(stderr, "[%s]Line %d has bad value %s of %s\n",
this->name.string(), nline, header[i].c_str(), record[i].c_str());
this->name.c_str(), nline, header[i].c_str(), record[i].c_str());
}
}
proto.end(token);
Expand All @@ -75,9 +75,9 @@ KernelWakesParser::Parse(const int in, const int out) const
}

if (!proto.flush(out)) {
fprintf(stderr, "[%s]Error writing proto back\n", this->name.string());
fprintf(stderr, "[%s]Error writing proto back\n", this->name.c_str());
return -1;
}
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.string(), proto.size());
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.c_str(), proto.size());
return NO_ERROR;
}
4 changes: 2 additions & 2 deletions cmds/incident_helper/src/parsers/PageTypeInfoParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ PageTypeInfoParser::Parse(const int in, const int out) const
}

if (!proto.flush(out)) {
fprintf(stderr, "[%s]Error writing proto back\n", this->name.string());
fprintf(stderr, "[%s]Error writing proto back\n", this->name.c_str());
return -1;
}

fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.string(), proto.size());
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.c_str(), proto.size());
return NO_ERROR;
}
8 changes: 4 additions & 4 deletions cmds/incident_helper/src/parsers/ProcrankParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ProcrankParser::Parse(const int in, const int out) const
if (record[record.size() - 1] == "TOTAL") { // TOTAL record
total = line;
} else {
fprintf(stderr, "[%s]Line %d has missing fields\n%s\n", this->name.string(), nline,
fprintf(stderr, "[%s]Line %d has missing fields\n%s\n", this->name.c_str(), nline,
line.c_str());
}
continue;
Expand All @@ -70,7 +70,7 @@ ProcrankParser::Parse(const int in, const int out) const
for (int i=0; i<(int)record.size(); i++) {
if (!table.insertField(&proto, header[i], record[i])) {
fprintf(stderr, "[%s]Line %d has bad value %s of %s\n",
this->name.string(), nline, header[i].c_str(), record[i].c_str());
this->name.c_str(), nline, header[i].c_str(), record[i].c_str());
}
}
proto.end(token);
Expand Down Expand Up @@ -104,9 +104,9 @@ ProcrankParser::Parse(const int in, const int out) const
}

if (!proto.flush(out)) {
fprintf(stderr, "[%s]Error writing proto back\n", this->name.string());
fprintf(stderr, "[%s]Error writing proto back\n", this->name.c_str());
return -1;
}
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.string(), proto.size());
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.c_str(), proto.size());
return NO_ERROR;
}
10 changes: 5 additions & 5 deletions cmds/incident_helper/src/parsers/PsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ status_t PsParser::Parse(const int in, const int out) const {
diff = record.size() - header.size();
if (diff < 0) {
// TODO: log this to incident report!
fprintf(stderr, "[%s]Line %d has %d missing fields\n%s\n", this->name.string(), nline, -diff, line.c_str());
fprintf(stderr, "[%s]Line %d has %d missing fields\n%s\n", this->name.c_str(), nline, -diff, line.c_str());
printRecord(record);
continue;
} else if (diff > 0) {
// TODO: log this to incident report!
fprintf(stderr, "[%s]Line %d has %d extra fields\n%s\n", this->name.string(), nline, diff, line.c_str());
fprintf(stderr, "[%s]Line %d has %d extra fields\n%s\n", this->name.c_str(), nline, diff, line.c_str());
printRecord(record);
continue;
}
Expand All @@ -75,7 +75,7 @@ status_t PsParser::Parse(const int in, const int out) const {
for (int i=0; i<(int)record.size(); i++) {
if (!table.insertField(&proto, header[i], record[i])) {
fprintf(stderr, "[%s]Line %d has bad value %s of %s\n",
this->name.string(), nline, header[i].c_str(), record[i].c_str());
this->name.c_str(), nline, header[i].c_str(), record[i].c_str());
}
}
proto.end(token);
Expand All @@ -87,9 +87,9 @@ status_t PsParser::Parse(const int in, const int out) const {
}

if (!proto.flush(out)) {
fprintf(stderr, "[%s]Error writing proto back\n", this->name.string());
fprintf(stderr, "[%s]Error writing proto back\n", this->name.c_str());
return -1;
}
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.string(), proto.size());
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.c_str(), proto.size());
return NO_ERROR;
}
4 changes: 2 additions & 2 deletions cmds/incident_helper/src/parsers/SystemPropertiesParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ SystemPropertiesParser::Parse(const int in, const int out) const
}

if (!proto.flush(out)) {
fprintf(stderr, "[%s]Error writing proto back\n", this->name.string());
fprintf(stderr, "[%s]Error writing proto back\n", this->name.c_str());
return -1;
}
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.string(), proto.size());
fprintf(stderr, "[%s]Proto size: %zu bytes\n", this->name.c_str(), proto.size());
return NO_ERROR;
}
Loading

0 comments on commit 3815d34

Please sign in to comment.