X-Git-Url: https://git.saurik.com/android/aapt.git/blobdiff_plain/d25ea7e18ee381dd2e4107200c4cb18355276f81..deaaa0a632a1fccb8e09ec25b1227fc5f965c0c9:/Command.cpp diff --git a/Command.cpp b/Command.cpp index 223b1fa..daf53e0 100644 --- a/Command.cpp +++ b/Command.cpp @@ -291,6 +291,27 @@ static int32_t getIntegerAttribute(const ResXMLTree& tree, uint32_t attrRes, return value.data; } +static int32_t getResolvedIntegerAttribute(const ResTable* resTable, const ResXMLTree& tree, + uint32_t attrRes, String8* outError, int32_t defValue = -1) +{ + ssize_t idx = indexOfAttribute(tree, attrRes); + if (idx < 0) { + return defValue; + } + Res_value value; + if (tree.getAttributeValue(idx, &value) != NO_ERROR) { + if (value.dataType == Res_value::TYPE_REFERENCE) { + resTable->resolveReference(&value, 0); + } + if (value.dataType < Res_value::TYPE_FIRST_INT + || value.dataType > Res_value::TYPE_LAST_INT) { + if (outError != NULL) *outError = "attribute is not an integer value"; + return defValue; + } + } + return value.data; +} + static String8 getResolvedAttribute(const ResTable* resTable, const ResXMLTree& tree, uint32_t attrRes, String8* outError) { @@ -320,11 +341,12 @@ static String8 getResolvedAttribute(const ResTable* resTable, const ResXMLTree& // These are attribute resource constants for the platform, as found // in android.R.attr enum { + LABEL_ATTR = 0x01010001, + ICON_ATTR = 0x01010002, NAME_ATTR = 0x01010003, VERSION_CODE_ATTR = 0x0101021b, VERSION_NAME_ATTR = 0x0101021c, - LABEL_ATTR = 0x01010001, - ICON_ATTR = 0x01010002, + SCREEN_ORIENTATION_ATTR = 0x0101001e, MIN_SDK_VERSION_ATTR = 0x0101020c, MAX_SDK_VERSION_ATTR = 0x01010271, REQ_TOUCH_SCREEN_ATTR = 0x01010227, @@ -634,6 +656,8 @@ int doDump(Bundle* bundle) bool reqDistinctMultitouchFeature = false; bool specScreenPortraitFeature = false; bool specScreenLandscapeFeature = false; + bool reqScreenPortraitFeature = false; + bool reqScreenLandscapeFeature = false; // 2.2 also added some other features that apps can request, but that // have no corresponding permission, so we cannot implement any // back-compatibility heuristic for them. The below are thus unnecessary @@ -1022,6 +1046,18 @@ int doDump(Bundle* bundle) fprintf(stderr, "ERROR getting 'android:icon' attribute: %s\n", error.string()); goto bail; } + + int32_t orien = getResolvedIntegerAttribute(&res, tree, + SCREEN_ORIENTATION_ATTR, &error); + if (error == "") { + if (orien == 0 || orien == 6 || orien == 8) { + // Requests landscape, sensorLandscape, or reverseLandscape. + reqScreenLandscapeFeature = true; + } else if (orien == 1 || orien == 7 || orien == 9) { + // Requests portrait, sensorPortrait, or reversePortrait. + reqScreenPortraitFeature = true; + } + } } else if (tag == "uses-library") { String8 libraryName = getAttribute(tree, NAME_ATTR, &error); if (error != "") { @@ -1182,12 +1218,16 @@ int doDump(Bundle* bundle) } // Landscape/portrait-related compatibility logic - if (!specScreenLandscapeFeature && !specScreenPortraitFeature && (targetSdk < 13)) { - // If app has not specified whether it requires portrait or landscape - // and is targeting an API before Honeycomb MR2, then assume it requires - // both. - printf("uses-feature:'android.hardware.screen.portrait'\n"); - printf("uses-feature:'android.hardware.screen.landscape'\n"); + if (!specScreenLandscapeFeature && !specScreenPortraitFeature) { + // If the app has specified any activities in its manifest + // that request a specific orientation, then assume that + // orientation is required. + if (reqScreenLandscapeFeature) { + printf("uses-feature:'android.hardware.screen.landscape'\n"); + } + if (reqScreenPortraitFeature) { + printf("uses-feature:'android.hardware.screen.portrait'\n"); + } } if (hasMainActivity) { @@ -1468,6 +1508,8 @@ int doPackage(Bundle* bundle) status_t err; sp assets; int N; + FILE* fp; + String8 dependencyFile; // -c zz_ZZ means do pseudolocalization ResourceFilter filter; @@ -1502,6 +1544,16 @@ int doPackage(Bundle* bundle) // Load the assets. assets = new AaptAssets(); + + // Set up the resource gathering in assets if we're going to generate + // dependency files + if (bundle->getGenDependencies()) { + sp resPathStore = new FilePathStore; + assets->setFullResPaths(resPathStore); + sp assetPathStore = new FilePathStore; + assets->setFullAssetPaths(assetPathStore); + } + err = assets->slurpFromArgs(bundle); if (err < 0) { goto bail; @@ -1511,7 +1563,7 @@ int doPackage(Bundle* bundle) assets->print(); } - // If they asked for any files that need to be compiled, do so. + // If they asked for any fileAs that need to be compiled, do so. if (bundle->getResourceSourceDirs().size() || bundle->getAndroidManifestFile()) { err = buildResources(bundle, assets); if (err != 0) { @@ -1525,10 +1577,36 @@ int doPackage(Bundle* bundle) goto bail; } + if (bundle->getGenDependencies()) { + if (outputAPKFile) { + dependencyFile = String8(outputAPKFile); + // Strip the extension and add new one + dependencyFile = dependencyFile.getBasePath(); + dependencyFile.append(".d"); + } else { + dependencyFile = String8(bundle->getRClassDir()); + dependencyFile.appendPath("R.d"); + } + // Make sure we have a clean dependency file to start with + fp = fopen(dependencyFile, "w"); + fclose(fp); + } + // Write out R.java constants if (assets->getPackage() == assets->getSymbolsPrivatePackage()) { if (bundle->getCustomPackage() == NULL) { err = writeResourceSymbols(bundle, assets, assets->getPackage(), true); + // Copy R.java for libraries + if (bundle->getExtraPackages() != NULL) { + // Split on colon + String8 libs(bundle->getExtraPackages()); + char* packageString = strtok(libs.lockBuffer(libs.length()), ":"); + while (packageString != NULL) { + err = writeResourceSymbols(bundle, assets, String8(packageString), true); + packageString = strtok(NULL, ":"); + } + libs.unlockBuffer(); + } } else { const String8 customPkg(bundle->getCustomPackage()); err = writeResourceSymbols(bundle, assets, customPkg, true); @@ -1562,6 +1640,18 @@ int doPackage(Bundle* bundle) } } + if (bundle->getGenDependencies()) { + // Now that writeResourceSymbols or writeAPK has taken care of writing + // the targets to our dependency file, we'll write the prereqs + fp = fopen(dependencyFile, "a+"); + fprintf(fp, " : "); + bool includeRaw = (outputAPKFile != NULL); + err = writeDependencyPreReqs(bundle, assets, fp, includeRaw); + // Also manually add the AndroidManifeset since it's a non-asset + fprintf(fp, "%s \\\n", bundle->getAndroidManifestFile()); + fclose(fp); + } + retVal = 0; bail: if (SourcePos::hasErrors()) { @@ -1569,3 +1659,25 @@ bail: } return retVal; } + +/* + * Do PNG Crunching + * PRECONDITIONS + * -S flag points to a source directory containing drawable* folders + * -C flag points to destination directory. The folder structure in the + * source directory will be mirrored to the destination (cache) directory + * + * POSTCONDITIONS + * Destination directory will be updated to match the PNG files in + * the source directory. + */ +int doCrunch(Bundle* bundle) +{ + fprintf(stdout, "Crunching PNG Files in "); + fprintf(stdout, "source dir: %s\n", bundle->getResourceSourceDirs()[0]); + fprintf(stdout, "To destination dir: %s\n", bundle->getCrunchedOutputDir()); + + updatePreProcessedCache(bundle); + + return NO_ERROR; +}