From d2a698351d13901b95f836df09e9463344f6ab0e Mon Sep 17 00:00:00 2001 From: Tomasz Wasilczyk Date: Thu, 10 Aug 2023 23:54:44 +0000 Subject: Use String8/16 c_str [tools] Bug: 295394788 Test: make checkbuild Change-Id: I82d6899d8c15a10b15399c39177290012bb5f13b Merged-In: I82d6899d8c15a10b15399c39177290012bb5f13b --- tools/aapt/Command.cpp | 260 ++++++++++++++++++++++++------------------------- 1 file changed, 130 insertions(+), 130 deletions(-) (limited to 'tools/aapt/Command.cpp') diff --git a/tools/aapt/Command.cpp b/tools/aapt/Command.cpp index 51cf38bce64e..5a06b102592a 100644 --- a/tools/aapt/Command.cpp +++ b/tools/aapt/Command.cpp @@ -240,13 +240,13 @@ static void printResolvedResourceAttribute(const ResTable& resTable, const ResXM } if (value.dataType == Res_value::TYPE_STRING) { String8 result = AaptXml::getResolvedAttribute(resTable, tree, attrRes, outError); - printf("%s='%s'", attrLabel.string(), - ResTable::normalizeForOutput(result.string()).string()); + printf("%s='%s'", attrLabel.c_str(), + ResTable::normalizeForOutput(result.c_str()).c_str()); } else if (Res_value::TYPE_FIRST_INT <= value.dataType && value.dataType <= Res_value::TYPE_LAST_INT) { - printf("%s='%d'", attrLabel.string(), value.data); + printf("%s='%d'", attrLabel.c_str(), value.data); } else { - printf("%s='0x%x'", attrLabel.string(), (int)value.data); + printf("%s='0x%x'", attrLabel.c_str(), (int)value.data); } } @@ -355,21 +355,21 @@ static void printCompatibleScreens(ResXMLTree& tree, String8* outError) { static void printUsesPermission(const String8& name, bool optional=false, int maxSdkVersion=-1, const String8& requiredFeature = String8(), const String8& requiredNotFeature = String8()) { - printf("uses-permission: name='%s'", ResTable::normalizeForOutput(name.string()).string()); + printf("uses-permission: name='%s'", ResTable::normalizeForOutput(name.c_str()).c_str()); if (maxSdkVersion != -1) { printf(" maxSdkVersion='%d'", maxSdkVersion); } if (requiredFeature.length() > 0) { - printf(" requiredFeature='%s'", requiredFeature.string()); + printf(" requiredFeature='%s'", requiredFeature.c_str()); } if (requiredNotFeature.length() > 0) { - printf(" requiredNotFeature='%s'", requiredNotFeature.string()); + printf(" requiredNotFeature='%s'", requiredNotFeature.c_str()); } printf("\n"); if (optional) { printf("optional-permission: name='%s'", - ResTable::normalizeForOutput(name.string()).string()); + ResTable::normalizeForOutput(name.c_str()).c_str()); if (maxSdkVersion != -1) { printf(" maxSdkVersion='%d'", maxSdkVersion); } @@ -380,7 +380,7 @@ static void printUsesPermission(const String8& name, bool optional=false, int ma static void printUsesPermissionSdk23(const String8& name, int maxSdkVersion=-1) { printf("uses-permission-sdk-23: "); - printf("name='%s'", ResTable::normalizeForOutput(name.string()).string()); + printf("name='%s'", ResTable::normalizeForOutput(name.c_str()).c_str()); if (maxSdkVersion != -1) { printf(" maxSdkVersion='%d'", maxSdkVersion); } @@ -390,11 +390,11 @@ static void printUsesPermissionSdk23(const String8& name, int maxSdkVersion=-1) static void printUsesImpliedPermission(const String8& name, const String8& reason, const int32_t maxSdkVersion = -1) { printf("uses-implied-permission: name='%s'", - ResTable::normalizeForOutput(name.string()).string()); + ResTable::normalizeForOutput(name.c_str()).c_str()); if (maxSdkVersion != -1) { printf(" maxSdkVersion='%d'", maxSdkVersion); } - printf(" reason='%s'\n", ResTable::normalizeForOutput(reason.string()).string()); + printf(" reason='%s'\n", ResTable::normalizeForOutput(reason.c_str()).c_str()); } Vector getNfcAidCategories(AssetManager& assets, const String8& xmlPath, bool offHost, @@ -556,7 +556,7 @@ static void addImpliedFeature(KeyedVector* impliedFeatu static void printFeatureGroupImpl(const FeatureGroup& grp, const KeyedVector* impliedFeatures) { - printf("feature-group: label='%s'\n", grp.label.string()); + printf("feature-group: label='%s'\n", grp.label.c_str()); if (grp.openGLESVersion > 0) { printf(" uses-gl-es: '0x%x'\n", grp.openGLESVersion); @@ -570,7 +570,7 @@ static void printFeatureGroupImpl(const FeatureGroup& grp, const String8& featureName = grp.features.keyAt(i); printf(" uses-feature%s: name='%s'", (required ? "" : "-not-required"), - ResTable::normalizeForOutput(featureName.string()).string()); + ResTable::normalizeForOutput(featureName.c_str()).c_str()); if (version > 0) { printf(" version='%d'", version); @@ -589,15 +589,15 @@ static void printFeatureGroupImpl(const FeatureGroup& grp, } String8 printableFeatureName(ResTable::normalizeForOutput( - impliedFeature.name.string())); + impliedFeature.name.c_str())); const char* sdk23Suffix = impliedFeature.impliedBySdk23 ? "-sdk-23" : ""; - printf(" uses-feature%s: name='%s'\n", sdk23Suffix, printableFeatureName.string()); + printf(" uses-feature%s: name='%s'\n", sdk23Suffix, printableFeatureName.c_str()); printf(" uses-implied-feature%s: name='%s' reason='", sdk23Suffix, - printableFeatureName.string()); + printableFeatureName.c_str()); const size_t numReasons = impliedFeature.reasons.size(); for (size_t j = 0; j < numReasons; j++) { - printf("%s", impliedFeature.reasons[j].string()); + printf("%s", impliedFeature.reasons[j].c_str()); if (j + 2 < numReasons) { printf(", "); } else if (j + 1 < numReasons) { @@ -649,43 +649,43 @@ static void addImpliedFeaturesForPermission(const int targetSdk, const String8& bool impliedBySdk23Permission) { if (name == "android.permission.CAMERA") { addImpliedFeature(impliedFeatures, "android.hardware.camera", - String8::format("requested %s permission", name.string()), + String8::format("requested %s permission", name.c_str()), impliedBySdk23Permission); } else if (name == "android.permission.ACCESS_FINE_LOCATION") { if (targetSdk < SDK_LOLLIPOP) { addImpliedFeature(impliedFeatures, "android.hardware.location.gps", - String8::format("requested %s permission", name.string()), + String8::format("requested %s permission", name.c_str()), impliedBySdk23Permission); addImpliedFeature(impliedFeatures, "android.hardware.location.gps", String8::format("targetSdkVersion < %d", SDK_LOLLIPOP), impliedBySdk23Permission); } addImpliedFeature(impliedFeatures, "android.hardware.location", - String8::format("requested %s permission", name.string()), + String8::format("requested %s permission", name.c_str()), impliedBySdk23Permission); } else if (name == "android.permission.ACCESS_COARSE_LOCATION") { if (targetSdk < SDK_LOLLIPOP) { addImpliedFeature(impliedFeatures, "android.hardware.location.network", - String8::format("requested %s permission", name.string()), + String8::format("requested %s permission", name.c_str()), impliedBySdk23Permission); addImpliedFeature(impliedFeatures, "android.hardware.location.network", String8::format("targetSdkVersion < %d", SDK_LOLLIPOP), impliedBySdk23Permission); } addImpliedFeature(impliedFeatures, "android.hardware.location", - String8::format("requested %s permission", name.string()), + String8::format("requested %s permission", name.c_str()), impliedBySdk23Permission); } else if (name == "android.permission.ACCESS_MOCK_LOCATION" || name == "android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" || name == "android.permission.INSTALL_LOCATION_PROVIDER") { addImpliedFeature(impliedFeatures, "android.hardware.location", - String8::format("requested %s permission", name.string()), + String8::format("requested %s permission", name.c_str()), impliedBySdk23Permission); } else if (name == "android.permission.BLUETOOTH" || name == "android.permission.BLUETOOTH_ADMIN") { if (targetSdk > SDK_DONUT) { addImpliedFeature(impliedFeatures, "android.hardware.bluetooth", - String8::format("requested %s permission", name.string()), + String8::format("requested %s permission", name.c_str()), impliedBySdk23Permission); addImpliedFeature(impliedFeatures, "android.hardware.bluetooth", String8::format("targetSdkVersion > %d", SDK_DONUT), @@ -693,13 +693,13 @@ static void addImpliedFeaturesForPermission(const int targetSdk, const String8& } } else if (name == "android.permission.RECORD_AUDIO") { addImpliedFeature(impliedFeatures, "android.hardware.microphone", - String8::format("requested %s permission", name.string()), + String8::format("requested %s permission", name.c_str()), impliedBySdk23Permission); } else if (name == "android.permission.ACCESS_WIFI_STATE" || name == "android.permission.CHANGE_WIFI_STATE" || name == "android.permission.CHANGE_WIFI_MULTICAST_STATE") { addImpliedFeature(impliedFeatures, "android.hardware.wifi", - String8::format("requested %s permission", name.string()), + String8::format("requested %s permission", name.c_str()), impliedBySdk23Permission); } else if (name == "android.permission.CALL_PHONE" || name == "android.permission.CALL_PRIVILEGED" || @@ -746,7 +746,7 @@ int doDump(Bundle* bundle) for (size_t i = 0; i < bundle->getPackageIncludes().size(); i++) { const String8& assetPath = bundle->getPackageIncludes()[i]; if (!assets.addAssetPath(assetPath, NULL)) { - fprintf(stderr, "ERROR: included asset path %s could not be loaded\n", assetPath.string()); + fprintf(stderr, "ERROR: included asset path %s could not be loaded\n", assetPath.c_str()); return 1; } } @@ -890,7 +890,7 @@ int doDump(Bundle* bundle) goto bail; } String8 tag(ctag16); - //printf("Depth %d tag %s\n", depth, tag.string()); + //printf("Depth %d tag %s\n", depth, tag.c_str()); if (depth == 1) { if (tag != "manifest") { SourcePos(manifestFile, tree.getLineNumber()).error( @@ -898,14 +898,14 @@ int doDump(Bundle* bundle) goto bail; } String8 pkg = AaptXml::getAttribute(tree, NULL, "package", NULL); - printf("package: %s\n", ResTable::normalizeForOutput(pkg.string()).string()); + printf("package: %s\n", ResTable::normalizeForOutput(pkg.c_str()).c_str()); } else if (depth == 2) { if (tag == "permission") { String8 error; String8 name = AaptXml::getAttribute(tree, NAME_ATTR, &error); if (error != "") { SourcePos(manifestFile, tree.getLineNumber()).error( - "ERROR getting 'android:name': %s", error.string()); + "ERROR getting 'android:name': %s", error.c_str()); goto bail; } @@ -915,13 +915,13 @@ int doDump(Bundle* bundle) goto bail; } printf("permission: %s\n", - ResTable::normalizeForOutput(name.string()).string()); + ResTable::normalizeForOutput(name.c_str()).c_str()); } else if (tag == "uses-permission") { String8 error; String8 name = AaptXml::getAttribute(tree, NAME_ATTR, &error); if (error != "") { SourcePos(manifestFile, tree.getLineNumber()).error( - "ERROR getting 'android:name' attribute: %s", error.string()); + "ERROR getting 'android:name' attribute: %s", error.c_str()); goto bail; } @@ -938,7 +938,7 @@ int doDump(Bundle* bundle) String8 name = AaptXml::getAttribute(tree, NAME_ATTR, &error); if (error != "") { SourcePos(manifestFile, tree.getLineNumber()).error( - "ERROR getting 'android:name' attribute: %s", error.string()); + "ERROR getting 'android:name' attribute: %s", error.c_str()); goto bail; } @@ -1138,7 +1138,7 @@ int doDump(Bundle* bundle) const size_t N = supportedInput.size(); for (size_t i=0; i 0) { printf(" name='%s' ", - ResTable::normalizeForOutput(aName.string()).string()); + ResTable::normalizeForOutput(aName.c_str()).c_str()); } printf(" label='%s' icon='%s'\n", - ResTable::normalizeForOutput(activityLabel.string()) - .string(), - ResTable::normalizeForOutput(activityIcon.string()) - .string()); + ResTable::normalizeForOutput(activityLabel.c_str()) + .c_str(), + ResTable::normalizeForOutput(activityIcon.c_str()) + .c_str()); } if (isLeanbackLauncherActivity) { printf("leanback-launchable-activity:"); if (aName.length() > 0) { printf(" name='%s' ", - ResTable::normalizeForOutput(aName.string()).string()); + ResTable::normalizeForOutput(aName.c_str()).c_str()); } printf(" label='%s' icon='%s' banner='%s'\n", - ResTable::normalizeForOutput(activityLabel.string()) - .string(), - ResTable::normalizeForOutput(activityIcon.string()) - .string(), - ResTable::normalizeForOutput(activityBanner.string()) - .string()); + ResTable::normalizeForOutput(activityLabel.c_str()) + .c_str(), + ResTable::normalizeForOutput(activityIcon.c_str()) + .c_str(), + ResTable::normalizeForOutput(activityBanner.c_str()) + .c_str()); } } if (!hasIntentFilter) { @@ -1265,7 +1265,7 @@ int doDump(Bundle* bundle) goto bail; } String8 tag(ctag16); - //printf("Depth %d, %s\n", depth, tag.string()); + //printf("Depth %d, %s\n", depth, tag.c_str()); if (depth == 1) { if (tag != "manifest") { SourcePos(manifestFile, tree.getLineNumber()).error( @@ -1274,13 +1274,13 @@ int doDump(Bundle* bundle) } pkg = AaptXml::getAttribute(tree, NULL, "package", NULL); printf("package: name='%s' ", - ResTable::normalizeForOutput(pkg.string()).string()); + ResTable::normalizeForOutput(pkg.c_str()).c_str()); int32_t versionCode = AaptXml::getIntegerAttribute(tree, VERSION_CODE_ATTR, &error); if (error != "") { SourcePos(manifestFile, tree.getLineNumber()).error( "ERROR getting 'android:versionCode' attribute: %s", - error.string()); + error.c_str()); goto bail; } if (versionCode > 0) { @@ -1293,16 +1293,16 @@ int doDump(Bundle* bundle) if (error != "") { SourcePos(manifestFile, tree.getLineNumber()).error( "ERROR getting 'android:versionName' attribute: %s", - error.string()); + error.c_str()); goto bail; } printf("versionName='%s'", - ResTable::normalizeForOutput(versionName.string()).string()); + ResTable::normalizeForOutput(versionName.c_str()).c_str()); String8 splitName = AaptXml::getAttribute(tree, NULL, "split"); if (!splitName.isEmpty()) { printf(" split='%s'", ResTable::normalizeForOutput( - splitName.string()).string()); + splitName.c_str()).c_str()); } // For 'platformBuildVersionName', using both string and int type as a fallback @@ -1313,7 +1313,7 @@ int doDump(Bundle* bundle) AaptXml::getIntegerAttribute(tree, NULL, "platformBuildVersionName", 0, NULL); if (platformBuildVersionName != "") { - printf(" platformBuildVersionName='%s'", platformBuildVersionName.string()); + printf(" platformBuildVersionName='%s'", platformBuildVersionName.c_str()); } else if (platformBuildVersionNameInt > 0) { printf(" platformBuildVersionName='%d'", platformBuildVersionNameInt); } @@ -1326,7 +1326,7 @@ int doDump(Bundle* bundle) AaptXml::getIntegerAttribute(tree, NULL, "platformBuildVersionCode", 0, NULL); if (platformBuildVersionCode != "") { - printf(" platformBuildVersionCode='%s'", platformBuildVersionCode.string()); + printf(" platformBuildVersionCode='%s'", platformBuildVersionCode.c_str()); } else if (platformBuildVersionCodeInt > 0) { printf(" platformBuildVersionCode='%d'", platformBuildVersionCodeInt); } @@ -1336,7 +1336,7 @@ int doDump(Bundle* bundle) if (error != "") { SourcePos(manifestFile, tree.getLineNumber()).error( "ERROR getting 'android:compileSdkVersion' attribute: %s", - error.string()); + error.c_str()); goto bail; } if (compileSdkVersion > 0) { @@ -1347,7 +1347,7 @@ int doDump(Bundle* bundle) COMPILE_SDK_VERSION_CODENAME_ATTR, &error); if (compileSdkVersionCodename != "") { printf(" compileSdkVersionCodename='%s'", ResTable::normalizeForOutput( - compileSdkVersionCodename.string()).string()); + compileSdkVersionCodename.c_str()).c_str()); } printf("\n"); @@ -1357,7 +1357,7 @@ int doDump(Bundle* bundle) if (error != "") { SourcePos(manifestFile, tree.getLineNumber()).error( "ERROR getting 'android:installLocation' attribute: %s", - error.string()); + error.c_str()); goto bail; } @@ -1387,7 +1387,7 @@ int doDump(Bundle* bundle) String8 label; const size_t NL = locales.size(); for (size_t i=0; i architectures; for (size_t i=0; igetFileCount(); i++) { architectures.add(ResTable::normalizeForOutput( - dir->getFileName(i).string())); + dir->getFileName(i).c_str())); } bool outputAltNativeCode = false; @@ -2401,7 +2401,7 @@ int doDump(Bundle* bundle) } if (index >= 0) { - printf("native-code: '%s'\n", architectures[index].string()); + printf("native-code: '%s'\n", architectures[index].c_str()); architectures.removeAt(index); outputAltNativeCode = true; } @@ -2414,7 +2414,7 @@ int doDump(Bundle* bundle) } printf("native-code:"); for (size_t i = 0; i < archCount; i++) { - printf(" '%s'", architectures[i].string()); + printf(" '%s'", architectures[i].c_str()); } printf("\n"); } @@ -2428,7 +2428,7 @@ int doDump(Bundle* bundle) res.getConfigurations(&configs); const size_t N = configs.size(); for (size_t i=0; igetFileSpecCount(); i++) { const char* fileName = bundle->getFileSpecEntry(i); - if (strcasecmp(String8(fileName).getPathExtension().string(), ".gz") == 0) { + if (strcasecmp(String8(fileName).getPathExtension().c_str(), ".gz") == 0) { printf(" '%s'... (from gzip)\n", fileName); - result = zip->addGzip(fileName, String8(fileName).getBasePath().string(), NULL); + result = zip->addGzip(fileName, String8(fileName).getBasePath().c_str(), NULL); } else { if (bundle->getJunkPath()) { String8 storageName = String8(fileName).getPathLeaf(); printf(" '%s' as '%s'...\n", fileName, - ResTable::normalizeForOutput(storageName.string()).string()); - result = zip->add(fileName, storageName.string(), + ResTable::normalizeForOutput(storageName.c_str()).c_str()); + result = zip->add(fileName, storageName.c_str(), bundle->getCompressionMethod(), NULL); } else { printf(" '%s'...\n", fileName); @@ -2581,7 +2581,7 @@ static status_t addResourcesToBuilder(const sp& dir, const sp& subDir = dir->getDirs().valueAt(i); - const char* dirStr = subDir->getLeaf().string(); + const char* dirStr = subDir->getLeaf().c_str(); if (!ignore && strstr(dirStr, "mipmap") == dirStr) { ignore = true; } @@ -2604,7 +2604,7 @@ static status_t addResourcesToBuilder(const sp& dir, const spgetPath().string(), gp->getFiles()[j]->getPrintableSource().string()); + gp->getPath().c_str(), gp->getFiles()[j]->getPrintableSource().c_str()); return err; } } @@ -2620,13 +2620,13 @@ static String8 buildApkName(const String8& original, const sp& split) String8 ext(original.getPathExtension()); if (ext == String8(".apk")) { return String8::format("%s_%s%s", - original.getBasePath().string(), - split->getDirectorySafeName().string(), - ext.string()); + original.getBasePath().c_str(), + split->getDirectorySafeName().c_str(), + ext.c_str()); } - return String8::format("%s_%s", original.string(), - split->getDirectorySafeName().string()); + return String8::format("%s_%s", original.c_str(), + split->getDirectorySafeName().c_str()); } /* @@ -2712,7 +2712,7 @@ int doPackage(Bundle* bundle) for (size_t i = 0; i < numSplits; i++) { std::set configs; if (!AaptConfig::parseCommaSeparatedList(splitStrs[i], &configs)) { - fprintf(stderr, "ERROR: failed to parse split configuration '%s'\n", splitStrs[i].string()); + fprintf(stderr, "ERROR: failed to parse split configuration '%s'\n", splitStrs[i].c_str()); goto bail; } @@ -2835,7 +2835,7 @@ int doPackage(Bundle* bundle) String8 outputPath = buildApkName(String8(outputAPKFile), split); err = writeAPK(bundle, outputPath, split); if (err != NO_ERROR) { - fprintf(stderr, "ERROR: packaging of '%s' failed\n", outputPath.string()); + fprintf(stderr, "ERROR: packaging of '%s' failed\n", outputPath.c_str()); goto bail; } } -- cgit v1.2.3-59-g8ed1b