The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2006 The Android Open Source Project |
| 3 | // |
| 4 | // Android Asset Packaging Tool main entry point. |
| 5 | // |
| 6 | #include "Main.h" |
| 7 | #include "Bundle.h" |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 8 | #include "ResourceFilter.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9 | #include "ResourceTable.h" |
| 10 | #include "XMLNode.h" |
| 11 | |
Mathias Agopian | 3b4062e | 2009-05-31 19:13:00 -0700 | [diff] [blame] | 12 | #include <utils/Log.h> |
| 13 | #include <utils/threads.h> |
| 14 | #include <utils/List.h> |
| 15 | #include <utils/Errors.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16 | |
| 17 | #include <fcntl.h> |
| 18 | #include <errno.h> |
| 19 | |
| 20 | using namespace android; |
| 21 | |
| 22 | /* |
| 23 | * Show version info. All the cool kids do it. |
| 24 | */ |
| 25 | int doVersion(Bundle* bundle) |
| 26 | { |
| 27 | if (bundle->getFileSpecCount() != 0) |
| 28 | printf("(ignoring extra arguments)\n"); |
| 29 | printf("Android Asset Packaging Tool, v0.2\n"); |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | |
| 35 | /* |
| 36 | * Open the file read only. The call fails if the file doesn't exist. |
| 37 | * |
| 38 | * Returns NULL on failure. |
| 39 | */ |
| 40 | ZipFile* openReadOnly(const char* fileName) |
| 41 | { |
| 42 | ZipFile* zip; |
| 43 | status_t result; |
| 44 | |
| 45 | zip = new ZipFile; |
| 46 | result = zip->open(fileName, ZipFile::kOpenReadOnly); |
| 47 | if (result != NO_ERROR) { |
| 48 | if (result == NAME_NOT_FOUND) |
| 49 | fprintf(stderr, "ERROR: '%s' not found\n", fileName); |
| 50 | else if (result == PERMISSION_DENIED) |
| 51 | fprintf(stderr, "ERROR: '%s' access denied\n", fileName); |
| 52 | else |
| 53 | fprintf(stderr, "ERROR: failed opening '%s' as Zip file\n", |
| 54 | fileName); |
| 55 | delete zip; |
| 56 | return NULL; |
| 57 | } |
| 58 | |
| 59 | return zip; |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * Open the file read-write. The file will be created if it doesn't |
| 64 | * already exist and "okayToCreate" is set. |
| 65 | * |
| 66 | * Returns NULL on failure. |
| 67 | */ |
| 68 | ZipFile* openReadWrite(const char* fileName, bool okayToCreate) |
| 69 | { |
| 70 | ZipFile* zip = NULL; |
| 71 | status_t result; |
| 72 | int flags; |
| 73 | |
| 74 | flags = ZipFile::kOpenReadWrite; |
| 75 | if (okayToCreate) |
| 76 | flags |= ZipFile::kOpenCreate; |
| 77 | |
| 78 | zip = new ZipFile; |
| 79 | result = zip->open(fileName, flags); |
| 80 | if (result != NO_ERROR) { |
| 81 | delete zip; |
| 82 | zip = NULL; |
| 83 | goto bail; |
| 84 | } |
| 85 | |
| 86 | bail: |
| 87 | return zip; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | /* |
| 92 | * Return a short string describing the compression method. |
| 93 | */ |
| 94 | const char* compressionName(int method) |
| 95 | { |
| 96 | if (method == ZipEntry::kCompressStored) |
| 97 | return "Stored"; |
| 98 | else if (method == ZipEntry::kCompressDeflated) |
| 99 | return "Deflated"; |
| 100 | else |
| 101 | return "Unknown"; |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | * Return the percent reduction in size (0% == no compression). |
| 106 | */ |
| 107 | int calcPercent(long uncompressedLen, long compressedLen) |
| 108 | { |
| 109 | if (!uncompressedLen) |
| 110 | return 0; |
| 111 | else |
| 112 | return (int) (100.0 - (compressedLen * 100.0) / uncompressedLen + 0.5); |
| 113 | } |
| 114 | |
| 115 | /* |
| 116 | * Handle the "list" command, which can be a simple file dump or |
| 117 | * a verbose listing. |
| 118 | * |
| 119 | * The verbose listing closely matches the output of the Info-ZIP "unzip" |
| 120 | * command. |
| 121 | */ |
| 122 | int doList(Bundle* bundle) |
| 123 | { |
| 124 | int result = 1; |
| 125 | ZipFile* zip = NULL; |
| 126 | const ZipEntry* entry; |
| 127 | long totalUncLen, totalCompLen; |
| 128 | const char* zipFileName; |
| 129 | |
| 130 | if (bundle->getFileSpecCount() != 1) { |
| 131 | fprintf(stderr, "ERROR: specify zip file name (only)\n"); |
| 132 | goto bail; |
| 133 | } |
| 134 | zipFileName = bundle->getFileSpecEntry(0); |
| 135 | |
| 136 | zip = openReadOnly(zipFileName); |
| 137 | if (zip == NULL) |
| 138 | goto bail; |
| 139 | |
| 140 | int count, i; |
| 141 | |
| 142 | if (bundle->getVerbose()) { |
| 143 | printf("Archive: %s\n", zipFileName); |
| 144 | printf( |
Kenny Root | fb2a946 | 2010-08-25 07:36:31 -0700 | [diff] [blame] | 145 | " Length Method Size Ratio Offset Date Time CRC-32 Name\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | printf( |
Kenny Root | fb2a946 | 2010-08-25 07:36:31 -0700 | [diff] [blame] | 147 | "-------- ------ ------- ----- ------- ---- ---- ------ ----\n"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | totalUncLen = totalCompLen = 0; |
| 151 | |
| 152 | count = zip->getNumEntries(); |
| 153 | for (i = 0; i < count; i++) { |
| 154 | entry = zip->getEntryByIndex(i); |
| 155 | if (bundle->getVerbose()) { |
| 156 | char dateBuf[32]; |
| 157 | time_t when; |
| 158 | |
| 159 | when = entry->getModWhen(); |
| 160 | strftime(dateBuf, sizeof(dateBuf), "%m-%d-%y %H:%M", |
| 161 | localtime(&when)); |
| 162 | |
Kenny Root | fb2a946 | 2010-08-25 07:36:31 -0700 | [diff] [blame] | 163 | printf("%8ld %-7.7s %7ld %3d%% %8zd %s %08lx %s\n", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | (long) entry->getUncompressedLen(), |
| 165 | compressionName(entry->getCompressionMethod()), |
| 166 | (long) entry->getCompressedLen(), |
| 167 | calcPercent(entry->getUncompressedLen(), |
| 168 | entry->getCompressedLen()), |
Kenny Root | fb2a946 | 2010-08-25 07:36:31 -0700 | [diff] [blame] | 169 | (size_t) entry->getLFHOffset(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | dateBuf, |
| 171 | entry->getCRC32(), |
| 172 | entry->getFileName()); |
| 173 | } else { |
| 174 | printf("%s\n", entry->getFileName()); |
| 175 | } |
| 176 | |
| 177 | totalUncLen += entry->getUncompressedLen(); |
| 178 | totalCompLen += entry->getCompressedLen(); |
| 179 | } |
| 180 | |
| 181 | if (bundle->getVerbose()) { |
| 182 | printf( |
| 183 | "-------- ------- --- -------\n"); |
| 184 | printf("%8ld %7ld %2d%% %d files\n", |
| 185 | totalUncLen, |
| 186 | totalCompLen, |
| 187 | calcPercent(totalUncLen, totalCompLen), |
| 188 | zip->getNumEntries()); |
| 189 | } |
| 190 | |
| 191 | if (bundle->getAndroidList()) { |
| 192 | AssetManager assets; |
| 193 | if (!assets.addAssetPath(String8(zipFileName), NULL)) { |
| 194 | fprintf(stderr, "ERROR: list -a failed because assets could not be loaded\n"); |
| 195 | goto bail; |
| 196 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 197 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | const ResTable& res = assets.getResources(false); |
| 199 | if (&res == NULL) { |
| 200 | printf("\nNo resource table found.\n"); |
| 201 | } else { |
Steve Block | f1ff21a | 2010-06-14 17:34:04 +0100 | [diff] [blame] | 202 | #ifndef HAVE_ANDROID_OS |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | printf("\nResource table:\n"); |
Dianne Hackborn | e17086b | 2009-06-19 15:13:28 -0700 | [diff] [blame] | 204 | res.print(false); |
Steve Block | f1ff21a | 2010-06-14 17:34:04 +0100 | [diff] [blame] | 205 | #endif |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | Asset* manifestAsset = assets.openNonAsset("AndroidManifest.xml", |
| 209 | Asset::ACCESS_BUFFER); |
| 210 | if (manifestAsset == NULL) { |
| 211 | printf("\nNo AndroidManifest.xml found.\n"); |
| 212 | } else { |
| 213 | printf("\nAndroid manifest:\n"); |
| 214 | ResXMLTree tree; |
| 215 | tree.setTo(manifestAsset->getBuffer(true), |
| 216 | manifestAsset->getLength()); |
| 217 | printXMLBlock(&tree); |
| 218 | } |
| 219 | delete manifestAsset; |
| 220 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | result = 0; |
| 223 | |
| 224 | bail: |
| 225 | delete zip; |
| 226 | return result; |
| 227 | } |
| 228 | |
| 229 | static ssize_t indexOfAttribute(const ResXMLTree& tree, uint32_t attrRes) |
| 230 | { |
| 231 | size_t N = tree.getAttributeCount(); |
| 232 | for (size_t i=0; i<N; i++) { |
| 233 | if (tree.getAttributeNameResID(i) == attrRes) { |
| 234 | return (ssize_t)i; |
| 235 | } |
| 236 | } |
| 237 | return -1; |
| 238 | } |
| 239 | |
Joe Onorato | 1553c82 | 2009-08-30 13:36:22 -0700 | [diff] [blame] | 240 | String8 getAttribute(const ResXMLTree& tree, const char* ns, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | const char* attr, String8* outError) |
| 242 | { |
| 243 | ssize_t idx = tree.indexOfAttribute(ns, attr); |
| 244 | if (idx < 0) { |
| 245 | return String8(); |
| 246 | } |
| 247 | Res_value value; |
| 248 | if (tree.getAttributeValue(idx, &value) != NO_ERROR) { |
| 249 | if (value.dataType != Res_value::TYPE_STRING) { |
| 250 | if (outError != NULL) *outError = "attribute is not a string value"; |
| 251 | return String8(); |
| 252 | } |
| 253 | } |
| 254 | size_t len; |
| 255 | const uint16_t* str = tree.getAttributeStringValue(idx, &len); |
| 256 | return str ? String8(str, len) : String8(); |
| 257 | } |
| 258 | |
| 259 | static String8 getAttribute(const ResXMLTree& tree, uint32_t attrRes, String8* outError) |
| 260 | { |
| 261 | ssize_t idx = indexOfAttribute(tree, attrRes); |
| 262 | if (idx < 0) { |
| 263 | return String8(); |
| 264 | } |
| 265 | Res_value value; |
| 266 | if (tree.getAttributeValue(idx, &value) != NO_ERROR) { |
| 267 | if (value.dataType != Res_value::TYPE_STRING) { |
| 268 | if (outError != NULL) *outError = "attribute is not a string value"; |
| 269 | return String8(); |
| 270 | } |
| 271 | } |
| 272 | size_t len; |
| 273 | const uint16_t* str = tree.getAttributeStringValue(idx, &len); |
| 274 | return str ? String8(str, len) : String8(); |
| 275 | } |
| 276 | |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 277 | static int32_t getIntegerAttribute(const ResXMLTree& tree, uint32_t attrRes, |
| 278 | String8* outError, int32_t defValue = -1) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | { |
| 280 | ssize_t idx = indexOfAttribute(tree, attrRes); |
| 281 | if (idx < 0) { |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 282 | return defValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | } |
| 284 | Res_value value; |
| 285 | if (tree.getAttributeValue(idx, &value) != NO_ERROR) { |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 286 | if (value.dataType < Res_value::TYPE_FIRST_INT |
| 287 | || value.dataType > Res_value::TYPE_LAST_INT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | if (outError != NULL) *outError = "attribute is not an integer value"; |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 289 | return defValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | return value.data; |
| 293 | } |
| 294 | |
Dianne Hackborn | f77ae6e | 2011-06-16 11:11:23 -0700 | [diff] [blame] | 295 | static int32_t getResolvedIntegerAttribute(const ResTable* resTable, const ResXMLTree& tree, |
| 296 | uint32_t attrRes, String8* outError, int32_t defValue = -1) |
| 297 | { |
| 298 | ssize_t idx = indexOfAttribute(tree, attrRes); |
| 299 | if (idx < 0) { |
| 300 | return defValue; |
| 301 | } |
| 302 | Res_value value; |
| 303 | if (tree.getAttributeValue(idx, &value) != NO_ERROR) { |
| 304 | if (value.dataType == Res_value::TYPE_REFERENCE) { |
| 305 | resTable->resolveReference(&value, 0); |
| 306 | } |
| 307 | if (value.dataType < Res_value::TYPE_FIRST_INT |
| 308 | || value.dataType > Res_value::TYPE_LAST_INT) { |
| 309 | if (outError != NULL) *outError = "attribute is not an integer value"; |
| 310 | return defValue; |
| 311 | } |
| 312 | } |
| 313 | return value.data; |
| 314 | } |
| 315 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | static String8 getResolvedAttribute(const ResTable* resTable, const ResXMLTree& tree, |
| 317 | uint32_t attrRes, String8* outError) |
| 318 | { |
| 319 | ssize_t idx = indexOfAttribute(tree, attrRes); |
| 320 | if (idx < 0) { |
| 321 | return String8(); |
| 322 | } |
| 323 | Res_value value; |
| 324 | if (tree.getAttributeValue(idx, &value) != NO_ERROR) { |
| 325 | if (value.dataType == Res_value::TYPE_STRING) { |
| 326 | size_t len; |
| 327 | const uint16_t* str = tree.getAttributeStringValue(idx, &len); |
| 328 | return str ? String8(str, len) : String8(); |
| 329 | } |
| 330 | resTable->resolveReference(&value, 0); |
| 331 | if (value.dataType != Res_value::TYPE_STRING) { |
| 332 | if (outError != NULL) *outError = "attribute is not a string value"; |
| 333 | return String8(); |
| 334 | } |
| 335 | } |
| 336 | size_t len; |
| 337 | const Res_value* value2 = &value; |
| 338 | const char16_t* str = const_cast<ResTable*>(resTable)->valueToString(value2, 0, NULL, &len); |
| 339 | return str ? String8(str, len) : String8(); |
| 340 | } |
| 341 | |
| 342 | // These are attribute resource constants for the platform, as found |
| 343 | // in android.R.attr |
| 344 | enum { |
Dianne Hackborn | f77ae6e | 2011-06-16 11:11:23 -0700 | [diff] [blame] | 345 | LABEL_ATTR = 0x01010001, |
| 346 | ICON_ATTR = 0x01010002, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | NAME_ATTR = 0x01010003, |
| 348 | VERSION_CODE_ATTR = 0x0101021b, |
| 349 | VERSION_NAME_ATTR = 0x0101021c, |
Dianne Hackborn | f77ae6e | 2011-06-16 11:11:23 -0700 | [diff] [blame] | 350 | SCREEN_ORIENTATION_ATTR = 0x0101001e, |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 351 | MIN_SDK_VERSION_ATTR = 0x0101020c, |
Suchi Amalapurapu | 75c4984 | 2009-08-14 15:13:09 -0700 | [diff] [blame] | 352 | MAX_SDK_VERSION_ATTR = 0x01010271, |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 353 | REQ_TOUCH_SCREEN_ATTR = 0x01010227, |
| 354 | REQ_KEYBOARD_TYPE_ATTR = 0x01010228, |
| 355 | REQ_HARD_KEYBOARD_ATTR = 0x01010229, |
| 356 | REQ_NAVIGATION_ATTR = 0x0101022a, |
| 357 | REQ_FIVE_WAY_NAV_ATTR = 0x01010232, |
| 358 | TARGET_SDK_VERSION_ATTR = 0x01010270, |
| 359 | TEST_ONLY_ATTR = 0x01010272, |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 360 | ANY_DENSITY_ATTR = 0x0101026c, |
Dianne Hackborn | e5276a7 | 2009-08-27 16:28:44 -0700 | [diff] [blame] | 361 | GL_ES_VERSION_ATTR = 0x01010281, |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 362 | SMALL_SCREEN_ATTR = 0x01010284, |
| 363 | NORMAL_SCREEN_ATTR = 0x01010285, |
| 364 | LARGE_SCREEN_ATTR = 0x01010286, |
Dianne Hackborn | f43489d | 2010-08-20 12:44:33 -0700 | [diff] [blame] | 365 | XLARGE_SCREEN_ATTR = 0x010102bf, |
Dianne Hackborn | e5276a7 | 2009-08-27 16:28:44 -0700 | [diff] [blame] | 366 | REQUIRED_ATTR = 0x0101028e, |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 367 | SCREEN_SIZE_ATTR = 0x010102ca, |
| 368 | SCREEN_DENSITY_ATTR = 0x010102cb, |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 369 | REQUIRES_SMALLEST_WIDTH_DP_ATTR = 0x01010364, |
| 370 | COMPATIBLE_WIDTH_LIMIT_DP_ATTR = 0x01010365, |
| 371 | LARGEST_WIDTH_LIMIT_DP_ATTR = 0x01010366, |
Kenny Root | 56088a55 | 2011-09-29 13:49:45 -0700 | [diff] [blame] | 372 | PUBLIC_KEY_ATTR = 0x010103a6, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | }; |
| 374 | |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 375 | const char *getComponentName(String8 &pkgName, String8 &componentName) { |
| 376 | ssize_t idx = componentName.find("."); |
| 377 | String8 retStr(pkgName); |
| 378 | if (idx == 0) { |
| 379 | retStr += componentName; |
| 380 | } else if (idx < 0) { |
| 381 | retStr += "."; |
| 382 | retStr += componentName; |
| 383 | } else { |
| 384 | return componentName.string(); |
| 385 | } |
| 386 | return retStr.string(); |
| 387 | } |
| 388 | |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 389 | static void printCompatibleScreens(ResXMLTree& tree) { |
| 390 | size_t len; |
| 391 | ResXMLTree::event_code_t code; |
| 392 | int depth = 0; |
| 393 | bool first = true; |
| 394 | printf("compatible-screens:"); |
| 395 | while ((code=tree.next()) != ResXMLTree::END_DOCUMENT && code != ResXMLTree::BAD_DOCUMENT) { |
| 396 | if (code == ResXMLTree::END_TAG) { |
| 397 | depth--; |
| 398 | if (depth < 0) { |
| 399 | break; |
| 400 | } |
| 401 | continue; |
| 402 | } |
| 403 | if (code != ResXMLTree::START_TAG) { |
| 404 | continue; |
| 405 | } |
| 406 | depth++; |
| 407 | String8 tag(tree.getElementName(&len)); |
| 408 | if (tag == "screen") { |
| 409 | int32_t screenSize = getIntegerAttribute(tree, |
| 410 | SCREEN_SIZE_ATTR, NULL, -1); |
| 411 | int32_t screenDensity = getIntegerAttribute(tree, |
| 412 | SCREEN_DENSITY_ATTR, NULL, -1); |
| 413 | if (screenSize > 0 && screenDensity > 0) { |
| 414 | if (!first) { |
| 415 | printf(","); |
| 416 | } |
| 417 | first = false; |
| 418 | printf("'%d/%d'", screenSize, screenDensity); |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | printf("\n"); |
| 423 | } |
| 424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | /* |
| 426 | * Handle the "dump" command, to extract select data from an archive. |
| 427 | */ |
| 428 | int doDump(Bundle* bundle) |
| 429 | { |
| 430 | status_t result = UNKNOWN_ERROR; |
| 431 | Asset* asset = NULL; |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | if (bundle->getFileSpecCount() < 1) { |
| 434 | fprintf(stderr, "ERROR: no dump option specified\n"); |
| 435 | return 1; |
| 436 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | if (bundle->getFileSpecCount() < 2) { |
| 439 | fprintf(stderr, "ERROR: no dump file specified\n"); |
| 440 | return 1; |
| 441 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 442 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | const char* option = bundle->getFileSpecEntry(0); |
| 444 | const char* filename = bundle->getFileSpecEntry(1); |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 445 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | AssetManager assets; |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 447 | void* assetsCookie; |
| 448 | if (!assets.addAssetPath(String8(filename), &assetsCookie)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | fprintf(stderr, "ERROR: dump failed because assets could not be loaded\n"); |
| 450 | return 1; |
| 451 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 452 | |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 453 | // Make a dummy config for retrieving resources... we need to supply |
| 454 | // non-default values for some configs so that we can retrieve resources |
| 455 | // in the app that don't have a default. The most important of these is |
| 456 | // the API version because key resources like icons will have an implicit |
| 457 | // version if they are using newer config types like density. |
| 458 | ResTable_config config; |
| 459 | config.language[0] = 'e'; |
| 460 | config.language[1] = 'n'; |
| 461 | config.country[0] = 'U'; |
| 462 | config.country[1] = 'S'; |
| 463 | config.orientation = ResTable_config::ORIENTATION_PORT; |
| 464 | config.density = ResTable_config::DENSITY_MEDIUM; |
| 465 | config.sdkVersion = 10000; // Very high. |
| 466 | config.screenWidthDp = 320; |
| 467 | config.screenHeightDp = 480; |
| 468 | config.smallestScreenWidthDp = 320; |
| 469 | assets.setConfiguration(config); |
| 470 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | const ResTable& res = assets.getResources(false); |
| 472 | if (&res == NULL) { |
| 473 | fprintf(stderr, "ERROR: dump failed because no resource table was found\n"); |
| 474 | goto bail; |
| 475 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 476 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | if (strcmp("resources", option) == 0) { |
Steve Block | f1ff21a | 2010-06-14 17:34:04 +0100 | [diff] [blame] | 478 | #ifndef HAVE_ANDROID_OS |
Dianne Hackborn | e17086b | 2009-06-19 15:13:28 -0700 | [diff] [blame] | 479 | res.print(bundle->getValues()); |
Steve Block | f1ff21a | 2010-06-14 17:34:04 +0100 | [diff] [blame] | 480 | #endif |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | } else if (strcmp("xmltree", option) == 0) { |
| 482 | if (bundle->getFileSpecCount() < 3) { |
| 483 | fprintf(stderr, "ERROR: no dump xmltree resource file specified\n"); |
| 484 | goto bail; |
| 485 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | for (int i=2; i<bundle->getFileSpecCount(); i++) { |
| 488 | const char* resname = bundle->getFileSpecEntry(i); |
| 489 | ResXMLTree tree; |
| 490 | asset = assets.openNonAsset(resname, Asset::ACCESS_BUFFER); |
| 491 | if (asset == NULL) { |
Kenny Root | 44b283d | 2009-09-01 19:03:11 -0500 | [diff] [blame] | 492 | fprintf(stderr, "ERROR: dump failed because resource %s found\n", resname); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | goto bail; |
| 494 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | if (tree.setTo(asset->getBuffer(true), |
| 497 | asset->getLength()) != NO_ERROR) { |
| 498 | fprintf(stderr, "ERROR: Resource %s is corrupt\n", resname); |
| 499 | goto bail; |
| 500 | } |
| 501 | tree.restart(); |
| 502 | printXMLBlock(&tree); |
Kenny Root | 1913846 | 2009-12-04 09:38:48 -0800 | [diff] [blame] | 503 | tree.uninit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | delete asset; |
| 505 | asset = NULL; |
| 506 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 507 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | } else if (strcmp("xmlstrings", option) == 0) { |
| 509 | if (bundle->getFileSpecCount() < 3) { |
| 510 | fprintf(stderr, "ERROR: no dump xmltree resource file specified\n"); |
| 511 | goto bail; |
| 512 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 513 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 514 | for (int i=2; i<bundle->getFileSpecCount(); i++) { |
| 515 | const char* resname = bundle->getFileSpecEntry(i); |
| 516 | ResXMLTree tree; |
| 517 | asset = assets.openNonAsset(resname, Asset::ACCESS_BUFFER); |
| 518 | if (asset == NULL) { |
Kenny Root | 44b283d | 2009-09-01 19:03:11 -0500 | [diff] [blame] | 519 | fprintf(stderr, "ERROR: dump failed because resource %s found\n", resname); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | goto bail; |
| 521 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 522 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | if (tree.setTo(asset->getBuffer(true), |
| 524 | asset->getLength()) != NO_ERROR) { |
| 525 | fprintf(stderr, "ERROR: Resource %s is corrupt\n", resname); |
| 526 | goto bail; |
| 527 | } |
| 528 | printStringPool(&tree.getStrings()); |
| 529 | delete asset; |
| 530 | asset = NULL; |
| 531 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 532 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | } else { |
| 534 | ResXMLTree tree; |
| 535 | asset = assets.openNonAsset("AndroidManifest.xml", |
| 536 | Asset::ACCESS_BUFFER); |
| 537 | if (asset == NULL) { |
| 538 | fprintf(stderr, "ERROR: dump failed because no AndroidManifest.xml found\n"); |
| 539 | goto bail; |
| 540 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 541 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 542 | if (tree.setTo(asset->getBuffer(true), |
| 543 | asset->getLength()) != NO_ERROR) { |
| 544 | fprintf(stderr, "ERROR: AndroidManifest.xml is corrupt\n"); |
| 545 | goto bail; |
| 546 | } |
| 547 | tree.restart(); |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 548 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 549 | if (strcmp("permissions", option) == 0) { |
| 550 | size_t len; |
| 551 | ResXMLTree::event_code_t code; |
| 552 | int depth = 0; |
| 553 | while ((code=tree.next()) != ResXMLTree::END_DOCUMENT && code != ResXMLTree::BAD_DOCUMENT) { |
| 554 | if (code == ResXMLTree::END_TAG) { |
| 555 | depth--; |
| 556 | continue; |
| 557 | } |
| 558 | if (code != ResXMLTree::START_TAG) { |
| 559 | continue; |
| 560 | } |
| 561 | depth++; |
| 562 | String8 tag(tree.getElementName(&len)); |
| 563 | //printf("Depth %d tag %s\n", depth, tag.string()); |
| 564 | if (depth == 1) { |
| 565 | if (tag != "manifest") { |
| 566 | fprintf(stderr, "ERROR: manifest does not start with <manifest> tag\n"); |
| 567 | goto bail; |
| 568 | } |
| 569 | String8 pkg = getAttribute(tree, NULL, "package", NULL); |
| 570 | printf("package: %s\n", pkg.string()); |
| 571 | } else if (depth == 2 && tag == "permission") { |
| 572 | String8 error; |
| 573 | String8 name = getAttribute(tree, NAME_ATTR, &error); |
| 574 | if (error != "") { |
| 575 | fprintf(stderr, "ERROR: %s\n", error.string()); |
| 576 | goto bail; |
| 577 | } |
| 578 | printf("permission: %s\n", name.string()); |
| 579 | } else if (depth == 2 && tag == "uses-permission") { |
| 580 | String8 error; |
| 581 | String8 name = getAttribute(tree, NAME_ATTR, &error); |
| 582 | if (error != "") { |
| 583 | fprintf(stderr, "ERROR: %s\n", error.string()); |
| 584 | goto bail; |
| 585 | } |
| 586 | printf("uses-permission: %s\n", name.string()); |
| 587 | } |
| 588 | } |
| 589 | } else if (strcmp("badging", option) == 0) { |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 590 | Vector<String8> locales; |
| 591 | res.getLocales(&locales); |
| 592 | |
| 593 | Vector<ResTable_config> configs; |
| 594 | res.getConfigurations(&configs); |
| 595 | SortedVector<int> densities; |
| 596 | const size_t NC = configs.size(); |
| 597 | for (size_t i=0; i<NC; i++) { |
| 598 | int dens = configs[i].density; |
| 599 | if (dens == 0) dens = 160; |
| 600 | densities.add(dens); |
| 601 | } |
| 602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | size_t len; |
| 604 | ResXMLTree::event_code_t code; |
| 605 | int depth = 0; |
| 606 | String8 error; |
| 607 | bool withinActivity = false; |
| 608 | bool isMainActivity = false; |
| 609 | bool isLauncherActivity = false; |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 610 | bool isSearchable = false; |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 611 | bool withinApplication = false; |
| 612 | bool withinReceiver = false; |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 613 | bool withinService = false; |
| 614 | bool withinIntentFilter = false; |
| 615 | bool hasMainActivity = false; |
| 616 | bool hasOtherActivities = false; |
| 617 | bool hasOtherReceivers = false; |
| 618 | bool hasOtherServices = false; |
| 619 | bool hasWallpaperService = false; |
| 620 | bool hasImeService = false; |
| 621 | bool hasWidgetReceivers = false; |
| 622 | bool hasIntentFilter = false; |
| 623 | bool actMainActivity = false; |
| 624 | bool actWidgetReceivers = false; |
| 625 | bool actImeService = false; |
| 626 | bool actWallpaperService = false; |
Dan Morrill | 89d97c1 | 2010-05-03 16:13:14 -0700 | [diff] [blame] | 627 | |
Kenny Root | 063a44e | 2011-12-08 08:46:03 -0800 | [diff] [blame^] | 628 | // These two implement the implicit permissions that are granted |
| 629 | // to pre-1.6 applications. |
| 630 | bool hasWriteExternalStoragePermission = false; |
| 631 | bool hasReadPhoneStatePermission = false; |
| 632 | |
Dan Morrill | 89d97c1 | 2010-05-03 16:13:14 -0700 | [diff] [blame] | 633 | // This next group of variables is used to implement a group of |
| 634 | // backward-compatibility heuristics necessitated by the addition of |
| 635 | // some new uses-feature constants in 2.1 and 2.2. In most cases, the |
| 636 | // heuristic is "if an app requests a permission but doesn't explicitly |
| 637 | // request the corresponding <uses-feature>, presume it's there anyway". |
| 638 | bool specCameraFeature = false; // camera-related |
| 639 | bool specCameraAutofocusFeature = false; |
| 640 | bool reqCameraAutofocusFeature = false; |
| 641 | bool reqCameraFlashFeature = false; |
Dianne Hackborn | e5276a7 | 2009-08-27 16:28:44 -0700 | [diff] [blame] | 642 | bool hasCameraPermission = false; |
Dan Morrill | 89d97c1 | 2010-05-03 16:13:14 -0700 | [diff] [blame] | 643 | bool specLocationFeature = false; // location-related |
| 644 | bool specNetworkLocFeature = false; |
| 645 | bool reqNetworkLocFeature = false; |
Dianne Hackborn | ef05e07 | 2010-03-01 17:43:39 -0800 | [diff] [blame] | 646 | bool specGpsFeature = false; |
Dan Morrill | 89d97c1 | 2010-05-03 16:13:14 -0700 | [diff] [blame] | 647 | bool reqGpsFeature = false; |
| 648 | bool hasMockLocPermission = false; |
| 649 | bool hasCoarseLocPermission = false; |
Dianne Hackborn | ef05e07 | 2010-03-01 17:43:39 -0800 | [diff] [blame] | 650 | bool hasGpsPermission = false; |
Dan Morrill | 89d97c1 | 2010-05-03 16:13:14 -0700 | [diff] [blame] | 651 | bool hasGeneralLocPermission = false; |
| 652 | bool specBluetoothFeature = false; // Bluetooth API-related |
| 653 | bool hasBluetoothPermission = false; |
| 654 | bool specMicrophoneFeature = false; // microphone-related |
| 655 | bool hasRecordAudioPermission = false; |
| 656 | bool specWiFiFeature = false; |
| 657 | bool hasWiFiPermission = false; |
| 658 | bool specTelephonyFeature = false; // telephony-related |
| 659 | bool reqTelephonySubFeature = false; |
| 660 | bool hasTelephonyPermission = false; |
| 661 | bool specTouchscreenFeature = false; // touchscreen-related |
| 662 | bool specMultitouchFeature = false; |
| 663 | bool reqDistinctMultitouchFeature = false; |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 664 | bool specScreenPortraitFeature = false; |
| 665 | bool specScreenLandscapeFeature = false; |
Dianne Hackborn | f77ae6e | 2011-06-16 11:11:23 -0700 | [diff] [blame] | 666 | bool reqScreenPortraitFeature = false; |
| 667 | bool reqScreenLandscapeFeature = false; |
Dan Morrill | 89d97c1 | 2010-05-03 16:13:14 -0700 | [diff] [blame] | 668 | // 2.2 also added some other features that apps can request, but that |
| 669 | // have no corresponding permission, so we cannot implement any |
| 670 | // back-compatibility heuristic for them. The below are thus unnecessary |
| 671 | // (but are retained here for documentary purposes.) |
| 672 | //bool specCompassFeature = false; |
| 673 | //bool specAccelerometerFeature = false; |
| 674 | //bool specProximityFeature = false; |
| 675 | //bool specAmbientLightFeature = false; |
| 676 | //bool specLiveWallpaperFeature = false; |
| 677 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 678 | int targetSdk = 0; |
| 679 | int smallScreen = 1; |
| 680 | int normalScreen = 1; |
| 681 | int largeScreen = 1; |
Dianne Hackborn | f43489d | 2010-08-20 12:44:33 -0700 | [diff] [blame] | 682 | int xlargeScreen = 1; |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 683 | int anyDensity = 1; |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 684 | int requiresSmallestWidthDp = 0; |
| 685 | int compatibleWidthLimitDp = 0; |
| 686 | int largestWidthLimitDp = 0; |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 687 | String8 pkg; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 688 | String8 activityName; |
| 689 | String8 activityLabel; |
| 690 | String8 activityIcon; |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 691 | String8 receiverName; |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 692 | String8 serviceName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 693 | while ((code=tree.next()) != ResXMLTree::END_DOCUMENT && code != ResXMLTree::BAD_DOCUMENT) { |
| 694 | if (code == ResXMLTree::END_TAG) { |
| 695 | depth--; |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 696 | if (depth < 2) { |
| 697 | withinApplication = false; |
| 698 | } else if (depth < 3) { |
| 699 | if (withinActivity && isMainActivity && isLauncherActivity) { |
| 700 | const char *aName = getComponentName(pkg, activityName); |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 701 | printf("launchable-activity:"); |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 702 | if (aName != NULL) { |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 703 | printf(" name='%s' ", aName); |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 704 | } |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 705 | printf(" label='%s' icon='%s'\n", |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 706 | activityLabel.string(), |
| 707 | activityIcon.string()); |
| 708 | } |
| 709 | if (!hasIntentFilter) { |
| 710 | hasOtherActivities |= withinActivity; |
| 711 | hasOtherReceivers |= withinReceiver; |
| 712 | hasOtherServices |= withinService; |
| 713 | } |
| 714 | withinActivity = false; |
| 715 | withinService = false; |
| 716 | withinReceiver = false; |
| 717 | hasIntentFilter = false; |
| 718 | isMainActivity = isLauncherActivity = false; |
| 719 | } else if (depth < 4) { |
| 720 | if (withinIntentFilter) { |
| 721 | if (withinActivity) { |
| 722 | hasMainActivity |= actMainActivity; |
| 723 | hasOtherActivities |= !actMainActivity; |
| 724 | } else if (withinReceiver) { |
| 725 | hasWidgetReceivers |= actWidgetReceivers; |
| 726 | hasOtherReceivers |= !actWidgetReceivers; |
| 727 | } else if (withinService) { |
| 728 | hasImeService |= actImeService; |
| 729 | hasWallpaperService |= actWallpaperService; |
| 730 | hasOtherServices |= (!actImeService && !actWallpaperService); |
| 731 | } |
| 732 | } |
| 733 | withinIntentFilter = false; |
| 734 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 735 | continue; |
| 736 | } |
| 737 | if (code != ResXMLTree::START_TAG) { |
| 738 | continue; |
| 739 | } |
| 740 | depth++; |
| 741 | String8 tag(tree.getElementName(&len)); |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 742 | //printf("Depth %d, %s\n", depth, tag.string()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 743 | if (depth == 1) { |
| 744 | if (tag != "manifest") { |
| 745 | fprintf(stderr, "ERROR: manifest does not start with <manifest> tag\n"); |
| 746 | goto bail; |
| 747 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 748 | pkg = getAttribute(tree, NULL, "package", NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | printf("package: name='%s' ", pkg.string()); |
| 750 | int32_t versionCode = getIntegerAttribute(tree, VERSION_CODE_ATTR, &error); |
| 751 | if (error != "") { |
| 752 | fprintf(stderr, "ERROR getting 'android:versionCode' attribute: %s\n", error.string()); |
| 753 | goto bail; |
| 754 | } |
| 755 | if (versionCode > 0) { |
| 756 | printf("versionCode='%d' ", versionCode); |
| 757 | } else { |
| 758 | printf("versionCode='' "); |
| 759 | } |
Dianne Hackborn | cf244ad | 2010-03-09 15:00:30 -0800 | [diff] [blame] | 760 | String8 versionName = getResolvedAttribute(&res, tree, VERSION_NAME_ATTR, &error); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 761 | if (error != "") { |
| 762 | fprintf(stderr, "ERROR getting 'android:versionName' attribute: %s\n", error.string()); |
| 763 | goto bail; |
| 764 | } |
| 765 | printf("versionName='%s'\n", versionName.string()); |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 766 | } else if (depth == 2) { |
| 767 | withinApplication = false; |
| 768 | if (tag == "application") { |
| 769 | withinApplication = true; |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 770 | |
| 771 | String8 label; |
| 772 | const size_t NL = locales.size(); |
| 773 | for (size_t i=0; i<NL; i++) { |
| 774 | const char* localeStr = locales[i].string(); |
| 775 | assets.setLocale(localeStr != NULL ? localeStr : ""); |
| 776 | String8 llabel = getResolvedAttribute(&res, tree, LABEL_ATTR, &error); |
| 777 | if (llabel != "") { |
| 778 | if (localeStr == NULL || strlen(localeStr) == 0) { |
| 779 | label = llabel; |
| 780 | printf("application-label:'%s'\n", llabel.string()); |
| 781 | } else { |
| 782 | if (label == "") { |
| 783 | label = llabel; |
| 784 | } |
| 785 | printf("application-label-%s:'%s'\n", localeStr, |
| 786 | llabel.string()); |
| 787 | } |
| 788 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 789 | } |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 790 | |
| 791 | ResTable_config tmpConfig = config; |
| 792 | const size_t ND = densities.size(); |
| 793 | for (size_t i=0; i<ND; i++) { |
| 794 | tmpConfig.density = densities[i]; |
| 795 | assets.setConfiguration(tmpConfig); |
| 796 | String8 icon = getResolvedAttribute(&res, tree, ICON_ATTR, &error); |
| 797 | if (icon != "") { |
| 798 | printf("application-icon-%d:'%s'\n", densities[i], icon.string()); |
| 799 | } |
| 800 | } |
| 801 | assets.setConfiguration(config); |
| 802 | |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 803 | String8 icon = getResolvedAttribute(&res, tree, ICON_ATTR, &error); |
| 804 | if (error != "") { |
| 805 | fprintf(stderr, "ERROR getting 'android:icon' attribute: %s\n", error.string()); |
| 806 | goto bail; |
| 807 | } |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 808 | int32_t testOnly = getIntegerAttribute(tree, TEST_ONLY_ATTR, &error, 0); |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 809 | if (error != "") { |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 810 | fprintf(stderr, "ERROR getting 'android:testOnly' attribute: %s\n", error.string()); |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 811 | goto bail; |
| 812 | } |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 813 | printf("application: label='%s' ", label.string()); |
| 814 | printf("icon='%s'\n", icon.string()); |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 815 | if (testOnly != 0) { |
| 816 | printf("testOnly='%d'\n", testOnly); |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 817 | } |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 818 | } else if (tag == "uses-sdk") { |
| 819 | int32_t code = getIntegerAttribute(tree, MIN_SDK_VERSION_ATTR, &error); |
| 820 | if (error != "") { |
| 821 | error = ""; |
| 822 | String8 name = getResolvedAttribute(&res, tree, MIN_SDK_VERSION_ATTR, &error); |
| 823 | if (error != "") { |
| 824 | fprintf(stderr, "ERROR getting 'android:minSdkVersion' attribute: %s\n", |
| 825 | error.string()); |
| 826 | goto bail; |
| 827 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 828 | if (name == "Donut") targetSdk = 4; |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 829 | printf("sdkVersion:'%s'\n", name.string()); |
| 830 | } else if (code != -1) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 831 | targetSdk = code; |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 832 | printf("sdkVersion:'%d'\n", code); |
| 833 | } |
Suchi Amalapurapu | 75c4984 | 2009-08-14 15:13:09 -0700 | [diff] [blame] | 834 | code = getIntegerAttribute(tree, MAX_SDK_VERSION_ATTR, NULL, -1); |
| 835 | if (code != -1) { |
| 836 | printf("maxSdkVersion:'%d'\n", code); |
| 837 | } |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 838 | code = getIntegerAttribute(tree, TARGET_SDK_VERSION_ATTR, &error); |
| 839 | if (error != "") { |
| 840 | error = ""; |
| 841 | String8 name = getResolvedAttribute(&res, tree, TARGET_SDK_VERSION_ATTR, &error); |
| 842 | if (error != "") { |
| 843 | fprintf(stderr, "ERROR getting 'android:targetSdkVersion' attribute: %s\n", |
| 844 | error.string()); |
| 845 | goto bail; |
| 846 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 847 | if (name == "Donut" && targetSdk < 4) targetSdk = 4; |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 848 | printf("targetSdkVersion:'%s'\n", name.string()); |
| 849 | } else if (code != -1) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 850 | if (targetSdk < code) { |
| 851 | targetSdk = code; |
| 852 | } |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 853 | printf("targetSdkVersion:'%d'\n", code); |
| 854 | } |
| 855 | } else if (tag == "uses-configuration") { |
| 856 | int32_t reqTouchScreen = getIntegerAttribute(tree, |
| 857 | REQ_TOUCH_SCREEN_ATTR, NULL, 0); |
| 858 | int32_t reqKeyboardType = getIntegerAttribute(tree, |
| 859 | REQ_KEYBOARD_TYPE_ATTR, NULL, 0); |
| 860 | int32_t reqHardKeyboard = getIntegerAttribute(tree, |
| 861 | REQ_HARD_KEYBOARD_ATTR, NULL, 0); |
| 862 | int32_t reqNavigation = getIntegerAttribute(tree, |
| 863 | REQ_NAVIGATION_ATTR, NULL, 0); |
| 864 | int32_t reqFiveWayNav = getIntegerAttribute(tree, |
| 865 | REQ_FIVE_WAY_NAV_ATTR, NULL, 0); |
Dianne Hackborn | cb2d50d | 2010-01-06 11:29:54 -0800 | [diff] [blame] | 866 | printf("uses-configuration:"); |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 867 | if (reqTouchScreen != 0) { |
| 868 | printf(" reqTouchScreen='%d'", reqTouchScreen); |
| 869 | } |
| 870 | if (reqKeyboardType != 0) { |
| 871 | printf(" reqKeyboardType='%d'", reqKeyboardType); |
| 872 | } |
| 873 | if (reqHardKeyboard != 0) { |
| 874 | printf(" reqHardKeyboard='%d'", reqHardKeyboard); |
| 875 | } |
| 876 | if (reqNavigation != 0) { |
| 877 | printf(" reqNavigation='%d'", reqNavigation); |
| 878 | } |
| 879 | if (reqFiveWayNav != 0) { |
| 880 | printf(" reqFiveWayNav='%d'", reqFiveWayNav); |
| 881 | } |
| 882 | printf("\n"); |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 883 | } else if (tag == "supports-screens") { |
| 884 | smallScreen = getIntegerAttribute(tree, |
| 885 | SMALL_SCREEN_ATTR, NULL, 1); |
| 886 | normalScreen = getIntegerAttribute(tree, |
| 887 | NORMAL_SCREEN_ATTR, NULL, 1); |
| 888 | largeScreen = getIntegerAttribute(tree, |
| 889 | LARGE_SCREEN_ATTR, NULL, 1); |
Dianne Hackborn | f43489d | 2010-08-20 12:44:33 -0700 | [diff] [blame] | 890 | xlargeScreen = getIntegerAttribute(tree, |
| 891 | XLARGE_SCREEN_ATTR, NULL, 1); |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 892 | anyDensity = getIntegerAttribute(tree, |
| 893 | ANY_DENSITY_ATTR, NULL, 1); |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 894 | requiresSmallestWidthDp = getIntegerAttribute(tree, |
| 895 | REQUIRES_SMALLEST_WIDTH_DP_ATTR, NULL, 0); |
| 896 | compatibleWidthLimitDp = getIntegerAttribute(tree, |
| 897 | COMPATIBLE_WIDTH_LIMIT_DP_ATTR, NULL, 0); |
| 898 | largestWidthLimitDp = getIntegerAttribute(tree, |
| 899 | LARGEST_WIDTH_LIMIT_DP_ATTR, NULL, 0); |
Dianne Hackborn | e5276a7 | 2009-08-27 16:28:44 -0700 | [diff] [blame] | 900 | } else if (tag == "uses-feature") { |
| 901 | String8 name = getAttribute(tree, NAME_ATTR, &error); |
Suchi Amalapurapu | 40b9472 | 2009-09-20 13:39:37 -0700 | [diff] [blame] | 902 | |
| 903 | if (name != "" && error == "") { |
Dianne Hackborn | e5276a7 | 2009-08-27 16:28:44 -0700 | [diff] [blame] | 904 | int req = getIntegerAttribute(tree, |
| 905 | REQUIRED_ATTR, NULL, 1); |
Dan Morrill | 89d97c1 | 2010-05-03 16:13:14 -0700 | [diff] [blame] | 906 | |
Dianne Hackborn | e5276a7 | 2009-08-27 16:28:44 -0700 | [diff] [blame] | 907 | if (name == "android.hardware.camera") { |
| 908 | specCameraFeature = true; |
Dan Morrill | 89d97c1 | 2010-05-03 16:13:14 -0700 | [diff] [blame] | 909 | } else if (name == "android.hardware.camera.autofocus") { |
| 910 | // these have no corresponding permission to check for, |
| 911 | // but should imply the foundational camera permission |
| 912 | reqCameraAutofocusFeature = reqCameraAutofocusFeature || req; |
| 913 | specCameraAutofocusFeature = true; |
| 914 | } else if (req && (name == "android.hardware.camera.flash")) { |
| 915 | // these have no corresponding permission to check for, |
| 916 | // but should imply the foundational camera permission |
| 917 | reqCameraFlashFeature = true; |
| 918 | } else if (name == "android.hardware.location") { |
| 919 | specLocationFeature = true; |
| 920 | } else if (name == "android.hardware.location.network") { |
| 921 | specNetworkLocFeature = true; |
| 922 | reqNetworkLocFeature = reqNetworkLocFeature || req; |
Dianne Hackborn | ef05e07 | 2010-03-01 17:43:39 -0800 | [diff] [blame] | 923 | } else if (name == "android.hardware.location.gps") { |
| 924 | specGpsFeature = true; |
Dan Morrill | 89d97c1 | 2010-05-03 16:13:14 -0700 | [diff] [blame] | 925 | reqGpsFeature = reqGpsFeature || req; |
| 926 | } else if (name == "android.hardware.bluetooth") { |
| 927 | specBluetoothFeature = true; |
| 928 | } else if (name == "android.hardware.touchscreen") { |
| 929 | specTouchscreenFeature = true; |
| 930 | } else if (name == "android.hardware.touchscreen.multitouch") { |
| 931 | specMultitouchFeature = true; |
| 932 | } else if (name == "android.hardware.touchscreen.multitouch.distinct") { |
| 933 | reqDistinctMultitouchFeature = reqDistinctMultitouchFeature || req; |
| 934 | } else if (name == "android.hardware.microphone") { |
| 935 | specMicrophoneFeature = true; |
| 936 | } else if (name == "android.hardware.wifi") { |
| 937 | specWiFiFeature = true; |
| 938 | } else if (name == "android.hardware.telephony") { |
| 939 | specTelephonyFeature = true; |
| 940 | } else if (req && (name == "android.hardware.telephony.gsm" || |
| 941 | name == "android.hardware.telephony.cdma")) { |
| 942 | // these have no corresponding permission to check for, |
| 943 | // but should imply the foundational telephony permission |
| 944 | reqTelephonySubFeature = true; |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 945 | } else if (name == "android.hardware.screen.portrait") { |
| 946 | specScreenPortraitFeature = true; |
| 947 | } else if (name == "android.hardware.screen.landscape") { |
| 948 | specScreenLandscapeFeature = true; |
Dianne Hackborn | e5276a7 | 2009-08-27 16:28:44 -0700 | [diff] [blame] | 949 | } |
| 950 | printf("uses-feature%s:'%s'\n", |
| 951 | req ? "" : "-not-required", name.string()); |
| 952 | } else { |
| 953 | int vers = getIntegerAttribute(tree, |
| 954 | GL_ES_VERSION_ATTR, &error); |
| 955 | if (error == "") { |
| 956 | printf("uses-gl-es:'0x%x'\n", vers); |
| 957 | } |
| 958 | } |
| 959 | } else if (tag == "uses-permission") { |
| 960 | String8 name = getAttribute(tree, NAME_ATTR, &error); |
Suchi Amalapurapu | 40b9472 | 2009-09-20 13:39:37 -0700 | [diff] [blame] | 961 | if (name != "" && error == "") { |
Dianne Hackborn | e5276a7 | 2009-08-27 16:28:44 -0700 | [diff] [blame] | 962 | if (name == "android.permission.CAMERA") { |
| 963 | hasCameraPermission = true; |
Dianne Hackborn | ef05e07 | 2010-03-01 17:43:39 -0800 | [diff] [blame] | 964 | } else if (name == "android.permission.ACCESS_FINE_LOCATION") { |
| 965 | hasGpsPermission = true; |
Dan Morrill | 89d97c1 | 2010-05-03 16:13:14 -0700 | [diff] [blame] | 966 | } else if (name == "android.permission.ACCESS_MOCK_LOCATION") { |
| 967 | hasMockLocPermission = true; |
| 968 | } else if (name == "android.permission.ACCESS_COARSE_LOCATION") { |
| 969 | hasCoarseLocPermission = true; |
| 970 | } else if (name == "android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" || |
| 971 | name == "android.permission.INSTALL_LOCATION_PROVIDER") { |
| 972 | hasGeneralLocPermission = true; |
| 973 | } else if (name == "android.permission.BLUETOOTH" || |
| 974 | name == "android.permission.BLUETOOTH_ADMIN") { |
| 975 | hasBluetoothPermission = true; |
| 976 | } else if (name == "android.permission.RECORD_AUDIO") { |
| 977 | hasRecordAudioPermission = true; |
| 978 | } else if (name == "android.permission.ACCESS_WIFI_STATE" || |
| 979 | name == "android.permission.CHANGE_WIFI_STATE" || |
| 980 | name == "android.permission.CHANGE_WIFI_MULTICAST_STATE") { |
| 981 | hasWiFiPermission = true; |
| 982 | } else if (name == "android.permission.CALL_PHONE" || |
| 983 | name == "android.permission.CALL_PRIVILEGED" || |
| 984 | name == "android.permission.MODIFY_PHONE_STATE" || |
| 985 | name == "android.permission.PROCESS_OUTGOING_CALLS" || |
| 986 | name == "android.permission.READ_SMS" || |
| 987 | name == "android.permission.RECEIVE_SMS" || |
| 988 | name == "android.permission.RECEIVE_MMS" || |
| 989 | name == "android.permission.RECEIVE_WAP_PUSH" || |
| 990 | name == "android.permission.SEND_SMS" || |
| 991 | name == "android.permission.WRITE_APN_SETTINGS" || |
| 992 | name == "android.permission.WRITE_SMS") { |
| 993 | hasTelephonyPermission = true; |
Kenny Root | 063a44e | 2011-12-08 08:46:03 -0800 | [diff] [blame^] | 994 | } else if (name == "android.permission.WRITE_EXTERNAL_STORAGE") { |
| 995 | hasWriteExternalStoragePermission = true; |
| 996 | } else if (name == "android.permission.READ_PHONE_STATE") { |
| 997 | hasReadPhoneStatePermission = true; |
Dianne Hackborn | e5276a7 | 2009-08-27 16:28:44 -0700 | [diff] [blame] | 998 | } |
| 999 | printf("uses-permission:'%s'\n", name.string()); |
| 1000 | } else { |
| 1001 | fprintf(stderr, "ERROR getting 'android:name' attribute: %s\n", |
| 1002 | error.string()); |
| 1003 | goto bail; |
| 1004 | } |
Dianne Hackborn | 43b6803 | 2010-09-02 17:14:41 -0700 | [diff] [blame] | 1005 | } else if (tag == "uses-package") { |
| 1006 | String8 name = getAttribute(tree, NAME_ATTR, &error); |
| 1007 | if (name != "" && error == "") { |
| 1008 | printf("uses-package:'%s'\n", name.string()); |
| 1009 | } else { |
| 1010 | fprintf(stderr, "ERROR getting 'android:name' attribute: %s\n", |
| 1011 | error.string()); |
| 1012 | goto bail; |
| 1013 | } |
Jeff Hamilton | e2c17f9 | 2010-02-12 13:45:16 -0600 | [diff] [blame] | 1014 | } else if (tag == "original-package") { |
| 1015 | String8 name = getAttribute(tree, NAME_ATTR, &error); |
| 1016 | if (name != "" && error == "") { |
| 1017 | printf("original-package:'%s'\n", name.string()); |
| 1018 | } else { |
| 1019 | fprintf(stderr, "ERROR getting 'android:name' attribute: %s\n", |
| 1020 | error.string()); |
| 1021 | goto bail; |
| 1022 | } |
Dan Morrill | 096b67f | 2010-12-13 16:25:54 -0800 | [diff] [blame] | 1023 | } else if (tag == "supports-gl-texture") { |
Dan Morrill | 6f51fc1 | 2010-10-13 14:33:43 -0700 | [diff] [blame] | 1024 | String8 name = getAttribute(tree, NAME_ATTR, &error); |
| 1025 | if (name != "" && error == "") { |
Dan Morrill | 096b67f | 2010-12-13 16:25:54 -0800 | [diff] [blame] | 1026 | printf("supports-gl-texture:'%s'\n", name.string()); |
Dan Morrill | 6f51fc1 | 2010-10-13 14:33:43 -0700 | [diff] [blame] | 1027 | } else { |
| 1028 | fprintf(stderr, "ERROR getting 'android:name' attribute: %s\n", |
| 1029 | error.string()); |
| 1030 | goto bail; |
| 1031 | } |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 1032 | } else if (tag == "compatible-screens") { |
| 1033 | printCompatibleScreens(tree); |
| 1034 | depth--; |
Kenny Root | 56088a55 | 2011-09-29 13:49:45 -0700 | [diff] [blame] | 1035 | } else if (tag == "package-verifier") { |
| 1036 | String8 name = getAttribute(tree, NAME_ATTR, &error); |
| 1037 | if (name != "" && error == "") { |
| 1038 | String8 publicKey = getAttribute(tree, PUBLIC_KEY_ATTR, &error); |
| 1039 | if (publicKey != "" && error == "") { |
| 1040 | printf("package-verifier: name='%s' publicKey='%s'\n", |
| 1041 | name.string(), publicKey.string()); |
| 1042 | } |
| 1043 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 1045 | } else if (depth == 3 && withinApplication) { |
| 1046 | withinActivity = false; |
| 1047 | withinReceiver = false; |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 1048 | withinService = false; |
| 1049 | hasIntentFilter = false; |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 1050 | if(tag == "activity") { |
| 1051 | withinActivity = true; |
| 1052 | activityName = getAttribute(tree, NAME_ATTR, &error); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1053 | if (error != "") { |
| 1054 | fprintf(stderr, "ERROR getting 'android:name' attribute: %s\n", error.string()); |
| 1055 | goto bail; |
| 1056 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 1057 | |
| 1058 | activityLabel = getResolvedAttribute(&res, tree, LABEL_ATTR, &error); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1059 | if (error != "") { |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 1060 | fprintf(stderr, "ERROR getting 'android:label' attribute: %s\n", error.string()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1061 | goto bail; |
| 1062 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 1063 | |
| 1064 | activityIcon = getResolvedAttribute(&res, tree, ICON_ATTR, &error); |
| 1065 | if (error != "") { |
| 1066 | fprintf(stderr, "ERROR getting 'android:icon' attribute: %s\n", error.string()); |
| 1067 | goto bail; |
| 1068 | } |
Dianne Hackborn | f77ae6e | 2011-06-16 11:11:23 -0700 | [diff] [blame] | 1069 | |
| 1070 | int32_t orien = getResolvedIntegerAttribute(&res, tree, |
| 1071 | SCREEN_ORIENTATION_ATTR, &error); |
| 1072 | if (error == "") { |
| 1073 | if (orien == 0 || orien == 6 || orien == 8) { |
| 1074 | // Requests landscape, sensorLandscape, or reverseLandscape. |
| 1075 | reqScreenLandscapeFeature = true; |
| 1076 | } else if (orien == 1 || orien == 7 || orien == 9) { |
| 1077 | // Requests portrait, sensorPortrait, or reversePortrait. |
| 1078 | reqScreenPortraitFeature = true; |
| 1079 | } |
| 1080 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 1081 | } else if (tag == "uses-library") { |
| 1082 | String8 libraryName = getAttribute(tree, NAME_ATTR, &error); |
| 1083 | if (error != "") { |
| 1084 | fprintf(stderr, "ERROR getting 'android:name' attribute for uses-library: %s\n", error.string()); |
| 1085 | goto bail; |
| 1086 | } |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 1087 | int req = getIntegerAttribute(tree, |
| 1088 | REQUIRED_ATTR, NULL, 1); |
| 1089 | printf("uses-library%s:'%s'\n", |
| 1090 | req ? "" : "-not-required", libraryName.string()); |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 1091 | } else if (tag == "receiver") { |
| 1092 | withinReceiver = true; |
| 1093 | receiverName = getAttribute(tree, NAME_ATTR, &error); |
| 1094 | |
| 1095 | if (error != "") { |
| 1096 | fprintf(stderr, "ERROR getting 'android:name' attribute for receiver: %s\n", error.string()); |
| 1097 | goto bail; |
| 1098 | } |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 1099 | } else if (tag == "service") { |
| 1100 | withinService = true; |
| 1101 | serviceName = getAttribute(tree, NAME_ATTR, &error); |
| 1102 | |
| 1103 | if (error != "") { |
| 1104 | fprintf(stderr, "ERROR getting 'android:name' attribute for service: %s\n", error.string()); |
| 1105 | goto bail; |
| 1106 | } |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 1107 | } |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 1108 | } else if ((depth == 4) && (tag == "intent-filter")) { |
| 1109 | hasIntentFilter = true; |
| 1110 | withinIntentFilter = true; |
| 1111 | actMainActivity = actWidgetReceivers = actImeService = actWallpaperService = false; |
| 1112 | } else if ((depth == 5) && withinIntentFilter){ |
| 1113 | String8 action; |
| 1114 | if (tag == "action") { |
| 1115 | action = getAttribute(tree, NAME_ATTR, &error); |
| 1116 | if (error != "") { |
| 1117 | fprintf(stderr, "ERROR getting 'android:name' attribute: %s\n", error.string()); |
| 1118 | goto bail; |
| 1119 | } |
| 1120 | if (withinActivity) { |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 1121 | if (action == "android.intent.action.MAIN") { |
| 1122 | isMainActivity = true; |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 1123 | actMainActivity = true; |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 1124 | } |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 1125 | } else if (withinReceiver) { |
| 1126 | if (action == "android.appwidget.action.APPWIDGET_UPDATE") { |
| 1127 | actWidgetReceivers = true; |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 1128 | } |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 1129 | } else if (withinService) { |
| 1130 | if (action == "android.view.InputMethod") { |
| 1131 | actImeService = true; |
| 1132 | } else if (action == "android.service.wallpaper.WallpaperService") { |
| 1133 | actWallpaperService = true; |
| 1134 | } |
| 1135 | } |
| 1136 | if (action == "android.intent.action.SEARCH") { |
| 1137 | isSearchable = true; |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | if (tag == "category") { |
| 1142 | String8 category = getAttribute(tree, NAME_ATTR, &error); |
| 1143 | if (error != "") { |
| 1144 | fprintf(stderr, "ERROR getting 'name' attribute: %s\n", error.string()); |
| 1145 | goto bail; |
| 1146 | } |
| 1147 | if (withinActivity) { |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 1148 | if (category == "android.intent.category.LAUNCHER") { |
| 1149 | isLauncherActivity = true; |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 1150 | } |
| 1151 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1152 | } |
| 1153 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | } |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 1155 | |
Kenny Root | 063a44e | 2011-12-08 08:46:03 -0800 | [diff] [blame^] | 1156 | // Pre-1.6 implicitly granted permission compatibility logic |
| 1157 | if (targetSdk < 4) { |
| 1158 | if (!hasWriteExternalStoragePermission) { |
| 1159 | printf("uses-permission:'android.permission.WRITE_EXTERNAL_STORAGE'\n"); |
| 1160 | } |
| 1161 | if (!hasReadPhoneStatePermission) { |
| 1162 | printf("uses-permission:'android.permission.READ_PHONE_STATE'\n"); |
| 1163 | } |
| 1164 | } |
| 1165 | |
Dan Morrill | 89d97c1 | 2010-05-03 16:13:14 -0700 | [diff] [blame] | 1166 | /* The following blocks handle printing "inferred" uses-features, based |
| 1167 | * on whether related features or permissions are used by the app. |
| 1168 | * Note that the various spec*Feature variables denote whether the |
| 1169 | * relevant tag was *present* in the AndroidManfest, not that it was |
| 1170 | * present and set to true. |
| 1171 | */ |
| 1172 | // Camera-related back-compatibility logic |
| 1173 | if (!specCameraFeature) { |
| 1174 | if (reqCameraFlashFeature || reqCameraAutofocusFeature) { |
| 1175 | // if app requested a sub-feature (autofocus or flash) and didn't |
| 1176 | // request the base camera feature, we infer that it meant to |
| 1177 | printf("uses-feature:'android.hardware.camera'\n"); |
| 1178 | } else if (hasCameraPermission) { |
| 1179 | // if app wants to use camera but didn't request the feature, we infer |
| 1180 | // that it meant to, and further that it wants autofocus |
| 1181 | // (which was the 1.0 - 1.5 behavior) |
| 1182 | printf("uses-feature:'android.hardware.camera'\n"); |
| 1183 | if (!specCameraAutofocusFeature) { |
| 1184 | printf("uses-feature:'android.hardware.camera.autofocus'\n"); |
| 1185 | } |
| 1186 | } |
Dianne Hackborn | e5276a7 | 2009-08-27 16:28:44 -0700 | [diff] [blame] | 1187 | } |
Doug Zongker | dbe7a68 | 2009-10-09 11:24:51 -0700 | [diff] [blame] | 1188 | |
Dan Morrill | 89d97c1 | 2010-05-03 16:13:14 -0700 | [diff] [blame] | 1189 | // Location-related back-compatibility logic |
| 1190 | if (!specLocationFeature && |
| 1191 | (hasMockLocPermission || hasCoarseLocPermission || hasGpsPermission || |
| 1192 | hasGeneralLocPermission || reqNetworkLocFeature || reqGpsFeature)) { |
| 1193 | // if app either takes a location-related permission or requests one of the |
| 1194 | // sub-features, we infer that it also meant to request the base location feature |
| 1195 | printf("uses-feature:'android.hardware.location'\n"); |
| 1196 | } |
Dianne Hackborn | ef05e07 | 2010-03-01 17:43:39 -0800 | [diff] [blame] | 1197 | if (!specGpsFeature && hasGpsPermission) { |
Dan Morrill | 89d97c1 | 2010-05-03 16:13:14 -0700 | [diff] [blame] | 1198 | // if app takes GPS (FINE location) perm but does not request the GPS |
| 1199 | // feature, we infer that it meant to |
Dianne Hackborn | ef05e07 | 2010-03-01 17:43:39 -0800 | [diff] [blame] | 1200 | printf("uses-feature:'android.hardware.location.gps'\n"); |
| 1201 | } |
Dan Morrill | 89d97c1 | 2010-05-03 16:13:14 -0700 | [diff] [blame] | 1202 | if (!specNetworkLocFeature && hasCoarseLocPermission) { |
| 1203 | // if app takes Network location (COARSE location) perm but does not request the |
| 1204 | // network location feature, we infer that it meant to |
| 1205 | printf("uses-feature:'android.hardware.location.network'\n"); |
| 1206 | } |
| 1207 | |
| 1208 | // Bluetooth-related compatibility logic |
Dan Morrill | 6b22d81 | 2010-06-15 21:41:42 -0700 | [diff] [blame] | 1209 | if (!specBluetoothFeature && hasBluetoothPermission && (targetSdk > 4)) { |
Dan Morrill | 89d97c1 | 2010-05-03 16:13:14 -0700 | [diff] [blame] | 1210 | // if app takes a Bluetooth permission but does not request the Bluetooth |
| 1211 | // feature, we infer that it meant to |
| 1212 | printf("uses-feature:'android.hardware.bluetooth'\n"); |
| 1213 | } |
| 1214 | |
| 1215 | // Microphone-related compatibility logic |
| 1216 | if (!specMicrophoneFeature && hasRecordAudioPermission) { |
| 1217 | // if app takes the record-audio permission but does not request the microphone |
| 1218 | // feature, we infer that it meant to |
| 1219 | printf("uses-feature:'android.hardware.microphone'\n"); |
| 1220 | } |
| 1221 | |
| 1222 | // WiFi-related compatibility logic |
| 1223 | if (!specWiFiFeature && hasWiFiPermission) { |
| 1224 | // if app takes one of the WiFi permissions but does not request the WiFi |
| 1225 | // feature, we infer that it meant to |
| 1226 | printf("uses-feature:'android.hardware.wifi'\n"); |
| 1227 | } |
| 1228 | |
| 1229 | // Telephony-related compatibility logic |
| 1230 | if (!specTelephonyFeature && (hasTelephonyPermission || reqTelephonySubFeature)) { |
| 1231 | // if app takes one of the telephony permissions or requests a sub-feature but |
| 1232 | // does not request the base telephony feature, we infer that it meant to |
| 1233 | printf("uses-feature:'android.hardware.telephony'\n"); |
| 1234 | } |
| 1235 | |
| 1236 | // Touchscreen-related back-compatibility logic |
| 1237 | if (!specTouchscreenFeature) { // not a typo! |
| 1238 | // all apps are presumed to require a touchscreen, unless they explicitly say |
| 1239 | // <uses-feature android:name="android.hardware.touchscreen" android:required="false"/> |
| 1240 | // Note that specTouchscreenFeature is true if the tag is present, regardless |
| 1241 | // of whether its value is true or false, so this is safe |
| 1242 | printf("uses-feature:'android.hardware.touchscreen'\n"); |
| 1243 | } |
| 1244 | if (!specMultitouchFeature && reqDistinctMultitouchFeature) { |
| 1245 | // if app takes one of the telephony permissions or requests a sub-feature but |
| 1246 | // does not request the base telephony feature, we infer that it meant to |
| 1247 | printf("uses-feature:'android.hardware.touchscreen.multitouch'\n"); |
| 1248 | } |
Dianne Hackborn | ef05e07 | 2010-03-01 17:43:39 -0800 | [diff] [blame] | 1249 | |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 1250 | // Landscape/portrait-related compatibility logic |
Dianne Hackborn | f77ae6e | 2011-06-16 11:11:23 -0700 | [diff] [blame] | 1251 | if (!specScreenLandscapeFeature && !specScreenPortraitFeature) { |
| 1252 | // If the app has specified any activities in its manifest |
| 1253 | // that request a specific orientation, then assume that |
| 1254 | // orientation is required. |
| 1255 | if (reqScreenLandscapeFeature) { |
| 1256 | printf("uses-feature:'android.hardware.screen.landscape'\n"); |
| 1257 | } |
| 1258 | if (reqScreenPortraitFeature) { |
| 1259 | printf("uses-feature:'android.hardware.screen.portrait'\n"); |
| 1260 | } |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 1263 | if (hasMainActivity) { |
| 1264 | printf("main\n"); |
| 1265 | } |
| 1266 | if (hasWidgetReceivers) { |
| 1267 | printf("app-widget\n"); |
| 1268 | } |
| 1269 | if (hasImeService) { |
| 1270 | printf("ime\n"); |
| 1271 | } |
| 1272 | if (hasWallpaperService) { |
| 1273 | printf("wallpaper\n"); |
| 1274 | } |
| 1275 | if (hasOtherActivities) { |
| 1276 | printf("other-activities\n"); |
| 1277 | } |
| 1278 | if (isSearchable) { |
| 1279 | printf("search\n"); |
| 1280 | } |
| 1281 | if (hasOtherReceivers) { |
| 1282 | printf("other-receivers\n"); |
| 1283 | } |
| 1284 | if (hasOtherServices) { |
| 1285 | printf("other-services\n"); |
| 1286 | } |
| 1287 | |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 1288 | // For modern apps, if screen size buckets haven't been specified |
| 1289 | // but the new width ranges have, then infer the buckets from them. |
| 1290 | if (smallScreen > 0 && normalScreen > 0 && largeScreen > 0 && xlargeScreen > 0 |
| 1291 | && requiresSmallestWidthDp > 0) { |
| 1292 | int compatWidth = compatibleWidthLimitDp; |
| 1293 | if (compatWidth <= 0) compatWidth = requiresSmallestWidthDp; |
| 1294 | if (requiresSmallestWidthDp <= 240 && compatWidth >= 240) { |
| 1295 | smallScreen = -1; |
| 1296 | } else { |
| 1297 | smallScreen = 0; |
| 1298 | } |
| 1299 | if (requiresSmallestWidthDp <= 320 && compatWidth >= 320) { |
| 1300 | normalScreen = -1; |
| 1301 | } else { |
| 1302 | normalScreen = 0; |
| 1303 | } |
| 1304 | if (requiresSmallestWidthDp <= 480 && compatWidth >= 480) { |
| 1305 | largeScreen = -1; |
| 1306 | } else { |
| 1307 | largeScreen = 0; |
| 1308 | } |
| 1309 | if (requiresSmallestWidthDp <= 720 && compatWidth >= 720) { |
| 1310 | xlargeScreen = -1; |
| 1311 | } else { |
| 1312 | xlargeScreen = 0; |
| 1313 | } |
| 1314 | } |
| 1315 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1316 | // Determine default values for any unspecified screen sizes, |
| 1317 | // based on the target SDK of the package. As of 4 (donut) |
| 1318 | // the screen size support was introduced, so all default to |
| 1319 | // enabled. |
| 1320 | if (smallScreen > 0) { |
| 1321 | smallScreen = targetSdk >= 4 ? -1 : 0; |
| 1322 | } |
| 1323 | if (normalScreen > 0) { |
| 1324 | normalScreen = -1; |
| 1325 | } |
| 1326 | if (largeScreen > 0) { |
| 1327 | largeScreen = targetSdk >= 4 ? -1 : 0; |
| 1328 | } |
Dianne Hackborn | f43489d | 2010-08-20 12:44:33 -0700 | [diff] [blame] | 1329 | if (xlargeScreen > 0) { |
Scott Main | d58fb97 | 2010-11-04 18:32:00 -0700 | [diff] [blame] | 1330 | // Introduced in Gingerbread. |
| 1331 | xlargeScreen = targetSdk >= 9 ? -1 : 0; |
Dianne Hackborn | f43489d | 2010-08-20 12:44:33 -0700 | [diff] [blame] | 1332 | } |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 1333 | if (anyDensity > 0) { |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 1334 | anyDensity = (targetSdk >= 4 || requiresSmallestWidthDp > 0 |
| 1335 | || compatibleWidthLimitDp > 0) ? -1 : 0; |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 1336 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1337 | printf("supports-screens:"); |
| 1338 | if (smallScreen != 0) printf(" 'small'"); |
| 1339 | if (normalScreen != 0) printf(" 'normal'"); |
| 1340 | if (largeScreen != 0) printf(" 'large'"); |
Dianne Hackborn | f43489d | 2010-08-20 12:44:33 -0700 | [diff] [blame] | 1341 | if (xlargeScreen != 0) printf(" 'xlarge'"); |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 1342 | printf("\n"); |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 1343 | printf("supports-any-density: '%s'\n", anyDensity ? "true" : "false"); |
Dianne Hackborn | e289bff | 2011-06-13 19:33:22 -0700 | [diff] [blame] | 1344 | if (requiresSmallestWidthDp > 0) { |
| 1345 | printf("requires-smallest-width:'%d'\n", requiresSmallestWidthDp); |
| 1346 | } |
| 1347 | if (compatibleWidthLimitDp > 0) { |
| 1348 | printf("compatible-width-limit:'%d'\n", compatibleWidthLimitDp); |
| 1349 | } |
| 1350 | if (largestWidthLimitDp > 0) { |
| 1351 | printf("largest-width-limit:'%d'\n", largestWidthLimitDp); |
| 1352 | } |
Dianne Hackborn | a0b46c9 | 2010-10-21 15:32:06 -0700 | [diff] [blame] | 1353 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1354 | printf("locales:"); |
Dianne Hackborn | e17086b | 2009-06-19 15:13:28 -0700 | [diff] [blame] | 1355 | const size_t NL = locales.size(); |
| 1356 | for (size_t i=0; i<NL; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1357 | const char* localeStr = locales[i].string(); |
| 1358 | if (localeStr == NULL || strlen(localeStr) == 0) { |
| 1359 | localeStr = "--_--"; |
| 1360 | } |
| 1361 | printf(" '%s'", localeStr); |
| 1362 | } |
| 1363 | printf("\n"); |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 1364 | |
Dianne Hackborn | e17086b | 2009-06-19 15:13:28 -0700 | [diff] [blame] | 1365 | printf("densities:"); |
| 1366 | const size_t ND = densities.size(); |
| 1367 | for (size_t i=0; i<ND; i++) { |
| 1368 | printf(" '%d'", densities[i]); |
| 1369 | } |
| 1370 | printf("\n"); |
Suchi Amalapurapu | 1b12598 | 2009-08-18 01:42:27 -0700 | [diff] [blame] | 1371 | |
Dianne Hackborn | bb9ea30 | 2009-05-18 15:22:00 -0700 | [diff] [blame] | 1372 | AssetDir* dir = assets.openNonAssetDir(assetsCookie, "lib"); |
| 1373 | if (dir != NULL) { |
| 1374 | if (dir->getFileCount() > 0) { |
| 1375 | printf("native-code:"); |
| 1376 | for (size_t i=0; i<dir->getFileCount(); i++) { |
| 1377 | printf(" '%s'", dir->getFileName(i).string()); |
| 1378 | } |
| 1379 | printf("\n"); |
| 1380 | } |
| 1381 | delete dir; |
| 1382 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1383 | } else if (strcmp("configurations", option) == 0) { |
| 1384 | Vector<ResTable_config> configs; |
| 1385 | res.getConfigurations(&configs); |
| 1386 | const size_t N = configs.size(); |
| 1387 | for (size_t i=0; i<N; i++) { |
| 1388 | printf("%s\n", configs[i].toString().string()); |
| 1389 | } |
| 1390 | } else { |
| 1391 | fprintf(stderr, "ERROR: unknown dump option '%s'\n", option); |
| 1392 | goto bail; |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | result = NO_ERROR; |
Suchi Amalapurapu | 7ef189d | 2009-04-02 15:20:29 -0700 | [diff] [blame] | 1397 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | bail: |
| 1399 | if (asset) { |
| 1400 | delete asset; |
| 1401 | } |
| 1402 | return (result != NO_ERROR); |
| 1403 | } |
| 1404 | |
| 1405 | |
| 1406 | /* |
| 1407 | * Handle the "add" command, which wants to add files to a new or |
| 1408 | * pre-existing archive. |
| 1409 | */ |
| 1410 | int doAdd(Bundle* bundle) |
| 1411 | { |
| 1412 | ZipFile* zip = NULL; |
| 1413 | status_t result = UNKNOWN_ERROR; |
| 1414 | const char* zipFileName; |
| 1415 | |
| 1416 | if (bundle->getUpdate()) { |
| 1417 | /* avoid confusion */ |
| 1418 | fprintf(stderr, "ERROR: can't use '-u' with add\n"); |
| 1419 | goto bail; |
| 1420 | } |
| 1421 | |
| 1422 | if (bundle->getFileSpecCount() < 1) { |
| 1423 | fprintf(stderr, "ERROR: must specify zip file name\n"); |
| 1424 | goto bail; |
| 1425 | } |
| 1426 | zipFileName = bundle->getFileSpecEntry(0); |
| 1427 | |
| 1428 | if (bundle->getFileSpecCount() < 2) { |
| 1429 | fprintf(stderr, "NOTE: nothing to do\n"); |
| 1430 | goto bail; |
| 1431 | } |
| 1432 | |
| 1433 | zip = openReadWrite(zipFileName, true); |
| 1434 | if (zip == NULL) { |
| 1435 | fprintf(stderr, "ERROR: failed opening/creating '%s' as Zip file\n", zipFileName); |
| 1436 | goto bail; |
| 1437 | } |
| 1438 | |
| 1439 | for (int i = 1; i < bundle->getFileSpecCount(); i++) { |
| 1440 | const char* fileName = bundle->getFileSpecEntry(i); |
| 1441 | |
| 1442 | if (strcasecmp(String8(fileName).getPathExtension().string(), ".gz") == 0) { |
| 1443 | printf(" '%s'... (from gzip)\n", fileName); |
| 1444 | result = zip->addGzip(fileName, String8(fileName).getBasePath().string(), NULL); |
| 1445 | } else { |
Doug Zongker | dbe7a68 | 2009-10-09 11:24:51 -0700 | [diff] [blame] | 1446 | if (bundle->getJunkPath()) { |
| 1447 | String8 storageName = String8(fileName).getPathLeaf(); |
| 1448 | printf(" '%s' as '%s'...\n", fileName, storageName.string()); |
| 1449 | result = zip->add(fileName, storageName.string(), |
| 1450 | bundle->getCompressionMethod(), NULL); |
| 1451 | } else { |
| 1452 | printf(" '%s'...\n", fileName); |
| 1453 | result = zip->add(fileName, bundle->getCompressionMethod(), NULL); |
| 1454 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1455 | } |
| 1456 | if (result != NO_ERROR) { |
| 1457 | fprintf(stderr, "Unable to add '%s' to '%s'", bundle->getFileSpecEntry(i), zipFileName); |
| 1458 | if (result == NAME_NOT_FOUND) |
| 1459 | fprintf(stderr, ": file not found\n"); |
| 1460 | else if (result == ALREADY_EXISTS) |
| 1461 | fprintf(stderr, ": already exists in archive\n"); |
| 1462 | else |
| 1463 | fprintf(stderr, "\n"); |
| 1464 | goto bail; |
| 1465 | } |
| 1466 | } |
| 1467 | |
| 1468 | result = NO_ERROR; |
| 1469 | |
| 1470 | bail: |
| 1471 | delete zip; |
| 1472 | return (result != NO_ERROR); |
| 1473 | } |
| 1474 | |
| 1475 | |
| 1476 | /* |
| 1477 | * Delete files from an existing archive. |
| 1478 | */ |
| 1479 | int doRemove(Bundle* bundle) |
| 1480 | { |
| 1481 | ZipFile* zip = NULL; |
| 1482 | status_t result = UNKNOWN_ERROR; |
| 1483 | const char* zipFileName; |
| 1484 | |
| 1485 | if (bundle->getFileSpecCount() < 1) { |
| 1486 | fprintf(stderr, "ERROR: must specify zip file name\n"); |
| 1487 | goto bail; |
| 1488 | } |
| 1489 | zipFileName = bundle->getFileSpecEntry(0); |
| 1490 | |
| 1491 | if (bundle->getFileSpecCount() < 2) { |
| 1492 | fprintf(stderr, "NOTE: nothing to do\n"); |
| 1493 | goto bail; |
| 1494 | } |
| 1495 | |
| 1496 | zip = openReadWrite(zipFileName, false); |
| 1497 | if (zip == NULL) { |
| 1498 | fprintf(stderr, "ERROR: failed opening Zip archive '%s'\n", |
| 1499 | zipFileName); |
| 1500 | goto bail; |
| 1501 | } |
| 1502 | |
| 1503 | for (int i = 1; i < bundle->getFileSpecCount(); i++) { |
| 1504 | const char* fileName = bundle->getFileSpecEntry(i); |
| 1505 | ZipEntry* entry; |
| 1506 | |
| 1507 | entry = zip->getEntryByName(fileName); |
| 1508 | if (entry == NULL) { |
| 1509 | printf(" '%s' NOT FOUND\n", fileName); |
| 1510 | continue; |
| 1511 | } |
| 1512 | |
| 1513 | result = zip->remove(entry); |
| 1514 | |
| 1515 | if (result != NO_ERROR) { |
| 1516 | fprintf(stderr, "Unable to delete '%s' from '%s'\n", |
| 1517 | bundle->getFileSpecEntry(i), zipFileName); |
| 1518 | goto bail; |
| 1519 | } |
| 1520 | } |
| 1521 | |
| 1522 | /* update the archive */ |
| 1523 | zip->flush(); |
| 1524 | |
| 1525 | bail: |
| 1526 | delete zip; |
| 1527 | return (result != NO_ERROR); |
| 1528 | } |
| 1529 | |
| 1530 | |
| 1531 | /* |
| 1532 | * Package up an asset directory and associated application files. |
| 1533 | */ |
| 1534 | int doPackage(Bundle* bundle) |
| 1535 | { |
| 1536 | const char* outputAPKFile; |
| 1537 | int retVal = 1; |
| 1538 | status_t err; |
| 1539 | sp<AaptAssets> assets; |
| 1540 | int N; |
Josiah Gaskin | 9bf34ca | 2011-06-14 13:57:09 -0700 | [diff] [blame] | 1541 | FILE* fp; |
| 1542 | String8 dependencyFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1543 | |
| 1544 | // -c zz_ZZ means do pseudolocalization |
| 1545 | ResourceFilter filter; |
| 1546 | err = filter.parse(bundle->getConfigurations()); |
| 1547 | if (err != NO_ERROR) { |
| 1548 | goto bail; |
| 1549 | } |
| 1550 | if (filter.containsPseudo()) { |
| 1551 | bundle->setPseudolocalize(true); |
| 1552 | } |
| 1553 | |
| 1554 | N = bundle->getFileSpecCount(); |
| 1555 | if (N < 1 && bundle->getResourceSourceDirs().size() == 0 && bundle->getJarFiles().size() == 0 |
| 1556 | && bundle->getAndroidManifestFile() == NULL && bundle->getAssetSourceDir() == NULL) { |
| 1557 | fprintf(stderr, "ERROR: no input files\n"); |
| 1558 | goto bail; |
| 1559 | } |
| 1560 | |
| 1561 | outputAPKFile = bundle->getOutputAPKFile(); |
| 1562 | |
| 1563 | // Make sure the filenames provided exist and are of the appropriate type. |
| 1564 | if (outputAPKFile) { |
| 1565 | FileType type; |
| 1566 | type = getFileType(outputAPKFile); |
| 1567 | if (type != kFileTypeNonexistent && type != kFileTypeRegular) { |
| 1568 | fprintf(stderr, |
| 1569 | "ERROR: output file '%s' exists but is not regular file\n", |
| 1570 | outputAPKFile); |
| 1571 | goto bail; |
| 1572 | } |
| 1573 | } |
| 1574 | |
| 1575 | // Load the assets. |
| 1576 | assets = new AaptAssets(); |
Josiah Gaskin | 9bf34ca | 2011-06-14 13:57:09 -0700 | [diff] [blame] | 1577 | |
Josiah Gaskin | 03589cc | 2011-06-27 16:26:02 -0700 | [diff] [blame] | 1578 | // Set up the resource gathering in assets if we're going to generate |
Josiah Gaskin | b711f3f | 2011-08-15 18:33:44 -0700 | [diff] [blame] | 1579 | // dependency files. Every time we encounter a resource while slurping |
| 1580 | // the tree, we'll add it to these stores so we have full resource paths |
| 1581 | // to write to a dependency file. |
Josiah Gaskin | 9bf34ca | 2011-06-14 13:57:09 -0700 | [diff] [blame] | 1582 | if (bundle->getGenDependencies()) { |
Josiah Gaskin | 03589cc | 2011-06-27 16:26:02 -0700 | [diff] [blame] | 1583 | sp<FilePathStore> resPathStore = new FilePathStore; |
| 1584 | assets->setFullResPaths(resPathStore); |
| 1585 | sp<FilePathStore> assetPathStore = new FilePathStore; |
| 1586 | assets->setFullAssetPaths(assetPathStore); |
Josiah Gaskin | 9bf34ca | 2011-06-14 13:57:09 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | err = assets->slurpFromArgs(bundle); |
| 1590 | if (err < 0) { |
| 1591 | goto bail; |
| 1592 | } |
| 1593 | |
| 1594 | if (bundle->getVerbose()) { |
Dianne Hackborn | e6b6803 | 2011-10-13 16:26:02 -0700 | [diff] [blame] | 1595 | assets->print(String8()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1596 | } |
| 1597 | |
Josiah Gaskin | 9bf34ca | 2011-06-14 13:57:09 -0700 | [diff] [blame] | 1598 | // If they asked for any fileAs that need to be compiled, do so. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1599 | if (bundle->getResourceSourceDirs().size() || bundle->getAndroidManifestFile()) { |
| 1600 | err = buildResources(bundle, assets); |
| 1601 | if (err != 0) { |
| 1602 | goto bail; |
| 1603 | } |
| 1604 | } |
| 1605 | |
| 1606 | // At this point we've read everything and processed everything. From here |
| 1607 | // on out it's just writing output files. |
| 1608 | if (SourcePos::hasErrors()) { |
| 1609 | goto bail; |
| 1610 | } |
| 1611 | |
Josiah Gaskin | b711f3f | 2011-08-15 18:33:44 -0700 | [diff] [blame] | 1612 | // If we've been asked to generate a dependency file, do that here |
Josiah Gaskin | 9bf34ca | 2011-06-14 13:57:09 -0700 | [diff] [blame] | 1613 | if (bundle->getGenDependencies()) { |
Josiah Gaskin | b711f3f | 2011-08-15 18:33:44 -0700 | [diff] [blame] | 1614 | // If this is the packaging step, generate the dependency file next to |
| 1615 | // the output apk (e.g. bin/resources.ap_.d) |
Josiah Gaskin | 03589cc | 2011-06-27 16:26:02 -0700 | [diff] [blame] | 1616 | if (outputAPKFile) { |
| 1617 | dependencyFile = String8(outputAPKFile); |
Josiah Gaskin | b711f3f | 2011-08-15 18:33:44 -0700 | [diff] [blame] | 1618 | // Add the .d extension to the dependency file. |
Josiah Gaskin | 03589cc | 2011-06-27 16:26:02 -0700 | [diff] [blame] | 1619 | dependencyFile.append(".d"); |
| 1620 | } else { |
Josiah Gaskin | b711f3f | 2011-08-15 18:33:44 -0700 | [diff] [blame] | 1621 | // Else if this is the R.java dependency generation step, |
| 1622 | // generate the dependency file in the R.java package subdirectory |
| 1623 | // e.g. gen/com/foo/app/R.java.d |
Josiah Gaskin | 03589cc | 2011-06-27 16:26:02 -0700 | [diff] [blame] | 1624 | dependencyFile = String8(bundle->getRClassDir()); |
Josiah Gaskin | b711f3f | 2011-08-15 18:33:44 -0700 | [diff] [blame] | 1625 | dependencyFile.appendPath("R.java.d"); |
Josiah Gaskin | 03589cc | 2011-06-27 16:26:02 -0700 | [diff] [blame] | 1626 | } |
Josiah Gaskin | 9bf34ca | 2011-06-14 13:57:09 -0700 | [diff] [blame] | 1627 | // Make sure we have a clean dependency file to start with |
Josiah Gaskin | 9bf34ca | 2011-06-14 13:57:09 -0700 | [diff] [blame] | 1628 | fp = fopen(dependencyFile, "w"); |
| 1629 | fclose(fp); |
| 1630 | } |
| 1631 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1632 | // Write out R.java constants |
| 1633 | if (assets->getPackage() == assets->getSymbolsPrivatePackage()) { |
Xavier Ducrohet | 63459ad | 2009-11-30 18:05:10 -0800 | [diff] [blame] | 1634 | if (bundle->getCustomPackage() == NULL) { |
Josiah Gaskin | b711f3f | 2011-08-15 18:33:44 -0700 | [diff] [blame] | 1635 | // Write the R.java file into the appropriate class directory |
| 1636 | // e.g. gen/com/foo/app/R.java |
Xavier Ducrohet | 63459ad | 2009-11-30 18:05:10 -0800 | [diff] [blame] | 1637 | err = writeResourceSymbols(bundle, assets, assets->getPackage(), true); |
Josiah Gaskin | b711f3f | 2011-08-15 18:33:44 -0700 | [diff] [blame] | 1638 | // If we have library files, we're going to write our R.java file into |
| 1639 | // the appropriate class directory for those libraries as well. |
| 1640 | // e.g. gen/com/foo/app/lib/R.java |
Josiah Gaskin | ce89f15 | 2011-06-08 19:31:40 -0700 | [diff] [blame] | 1641 | if (bundle->getExtraPackages() != NULL) { |
Josiah Gaskin | 9bf34ca | 2011-06-14 13:57:09 -0700 | [diff] [blame] | 1642 | // Split on colon |
Josiah Gaskin | ce89f15 | 2011-06-08 19:31:40 -0700 | [diff] [blame] | 1643 | String8 libs(bundle->getExtraPackages()); |
Josiah Gaskin | 9bf34ca | 2011-06-14 13:57:09 -0700 | [diff] [blame] | 1644 | char* packageString = strtok(libs.lockBuffer(libs.length()), ":"); |
Josiah Gaskin | ce89f15 | 2011-06-08 19:31:40 -0700 | [diff] [blame] | 1645 | while (packageString != NULL) { |
Josiah Gaskin | b711f3f | 2011-08-15 18:33:44 -0700 | [diff] [blame] | 1646 | // Write the R.java file out with the correct package name |
Josiah Gaskin | ce89f15 | 2011-06-08 19:31:40 -0700 | [diff] [blame] | 1647 | err = writeResourceSymbols(bundle, assets, String8(packageString), true); |
Josiah Gaskin | 9bf34ca | 2011-06-14 13:57:09 -0700 | [diff] [blame] | 1648 | packageString = strtok(NULL, ":"); |
Josiah Gaskin | ce89f15 | 2011-06-08 19:31:40 -0700 | [diff] [blame] | 1649 | } |
| 1650 | libs.unlockBuffer(); |
| 1651 | } |
Xavier Ducrohet | 63459ad | 2009-11-30 18:05:10 -0800 | [diff] [blame] | 1652 | } else { |
| 1653 | const String8 customPkg(bundle->getCustomPackage()); |
| 1654 | err = writeResourceSymbols(bundle, assets, customPkg, true); |
| 1655 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1656 | if (err < 0) { |
| 1657 | goto bail; |
| 1658 | } |
| 1659 | } else { |
| 1660 | err = writeResourceSymbols(bundle, assets, assets->getPackage(), false); |
| 1661 | if (err < 0) { |
| 1662 | goto bail; |
| 1663 | } |
| 1664 | err = writeResourceSymbols(bundle, assets, assets->getSymbolsPrivatePackage(), true); |
| 1665 | if (err < 0) { |
| 1666 | goto bail; |
| 1667 | } |
| 1668 | } |
| 1669 | |
Joe Onorato | 1553c82 | 2009-08-30 13:36:22 -0700 | [diff] [blame] | 1670 | // Write out the ProGuard file |
| 1671 | err = writeProguardFile(bundle, assets); |
| 1672 | if (err < 0) { |
| 1673 | goto bail; |
| 1674 | } |
| 1675 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1676 | // Write the apk |
| 1677 | if (outputAPKFile) { |
| 1678 | err = writeAPK(bundle, assets, String8(outputAPKFile)); |
| 1679 | if (err != NO_ERROR) { |
| 1680 | fprintf(stderr, "ERROR: packaging of '%s' failed\n", outputAPKFile); |
| 1681 | goto bail; |
| 1682 | } |
| 1683 | } |
| 1684 | |
Josiah Gaskin | b711f3f | 2011-08-15 18:33:44 -0700 | [diff] [blame] | 1685 | // If we've been asked to generate a dependency file, we need to finish up here. |
| 1686 | // the writeResourceSymbols and writeAPK functions have already written the target |
| 1687 | // half of the dependency file, now we need to write the prerequisites. (files that |
| 1688 | // the R.java file or .ap_ file depend on) |
Josiah Gaskin | 03589cc | 2011-06-27 16:26:02 -0700 | [diff] [blame] | 1689 | if (bundle->getGenDependencies()) { |
| 1690 | // Now that writeResourceSymbols or writeAPK has taken care of writing |
| 1691 | // the targets to our dependency file, we'll write the prereqs |
| 1692 | fp = fopen(dependencyFile, "a+"); |
| 1693 | fprintf(fp, " : "); |
| 1694 | bool includeRaw = (outputAPKFile != NULL); |
| 1695 | err = writeDependencyPreReqs(bundle, assets, fp, includeRaw); |
Josiah Gaskin | b711f3f | 2011-08-15 18:33:44 -0700 | [diff] [blame] | 1696 | // Also manually add the AndroidManifeset since it's not under res/ or assets/ |
| 1697 | // and therefore was not added to our pathstores during slurping |
Josiah Gaskin | 03589cc | 2011-06-27 16:26:02 -0700 | [diff] [blame] | 1698 | fprintf(fp, "%s \\\n", bundle->getAndroidManifestFile()); |
| 1699 | fclose(fp); |
| 1700 | } |
| 1701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1702 | retVal = 0; |
| 1703 | bail: |
| 1704 | if (SourcePos::hasErrors()) { |
| 1705 | SourcePos::printErrors(stderr); |
| 1706 | } |
| 1707 | return retVal; |
| 1708 | } |
Josiah Gaskin | 8a39da8 | 2011-06-06 17:00:35 -0700 | [diff] [blame] | 1709 | |
| 1710 | /* |
| 1711 | * Do PNG Crunching |
| 1712 | * PRECONDITIONS |
| 1713 | * -S flag points to a source directory containing drawable* folders |
| 1714 | * -C flag points to destination directory. The folder structure in the |
| 1715 | * source directory will be mirrored to the destination (cache) directory |
| 1716 | * |
| 1717 | * POSTCONDITIONS |
| 1718 | * Destination directory will be updated to match the PNG files in |
| 1719 | * the source directory. |
| 1720 | */ |
| 1721 | int doCrunch(Bundle* bundle) |
| 1722 | { |
| 1723 | fprintf(stdout, "Crunching PNG Files in "); |
| 1724 | fprintf(stdout, "source dir: %s\n", bundle->getResourceSourceDirs()[0]); |
| 1725 | fprintf(stdout, "To destination dir: %s\n", bundle->getCrunchedOutputDir()); |
| 1726 | |
| 1727 | updatePreProcessedCache(bundle); |
| 1728 | |
| 1729 | return NO_ERROR; |
| 1730 | } |