blob: ff9cc1142cd7e09be9173ede30448006c92a30ee [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001//
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"
8#include "ResourceTable.h"
9#include "XMLNode.h"
10
Mathias Agopian3b4062e2009-05-31 19:13:00 -070011#include <utils/Log.h>
12#include <utils/threads.h>
13#include <utils/List.h>
14#include <utils/Errors.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080015
16#include <fcntl.h>
17#include <errno.h>
18
19using namespace android;
20
21/*
22 * Show version info. All the cool kids do it.
23 */
24int doVersion(Bundle* bundle)
25{
26 if (bundle->getFileSpecCount() != 0)
27 printf("(ignoring extra arguments)\n");
28 printf("Android Asset Packaging Tool, v0.2\n");
29
30 return 0;
31}
32
33
34/*
35 * Open the file read only. The call fails if the file doesn't exist.
36 *
37 * Returns NULL on failure.
38 */
39ZipFile* openReadOnly(const char* fileName)
40{
41 ZipFile* zip;
42 status_t result;
43
44 zip = new ZipFile;
45 result = zip->open(fileName, ZipFile::kOpenReadOnly);
46 if (result != NO_ERROR) {
47 if (result == NAME_NOT_FOUND)
48 fprintf(stderr, "ERROR: '%s' not found\n", fileName);
49 else if (result == PERMISSION_DENIED)
50 fprintf(stderr, "ERROR: '%s' access denied\n", fileName);
51 else
52 fprintf(stderr, "ERROR: failed opening '%s' as Zip file\n",
53 fileName);
54 delete zip;
55 return NULL;
56 }
57
58 return zip;
59}
60
61/*
62 * Open the file read-write. The file will be created if it doesn't
63 * already exist and "okayToCreate" is set.
64 *
65 * Returns NULL on failure.
66 */
67ZipFile* openReadWrite(const char* fileName, bool okayToCreate)
68{
69 ZipFile* zip = NULL;
70 status_t result;
71 int flags;
72
73 flags = ZipFile::kOpenReadWrite;
74 if (okayToCreate)
75 flags |= ZipFile::kOpenCreate;
76
77 zip = new ZipFile;
78 result = zip->open(fileName, flags);
79 if (result != NO_ERROR) {
80 delete zip;
81 zip = NULL;
82 goto bail;
83 }
84
85bail:
86 return zip;
87}
88
89
90/*
91 * Return a short string describing the compression method.
92 */
93const char* compressionName(int method)
94{
95 if (method == ZipEntry::kCompressStored)
96 return "Stored";
97 else if (method == ZipEntry::kCompressDeflated)
98 return "Deflated";
99 else
100 return "Unknown";
101}
102
103/*
104 * Return the percent reduction in size (0% == no compression).
105 */
106int calcPercent(long uncompressedLen, long compressedLen)
107{
108 if (!uncompressedLen)
109 return 0;
110 else
111 return (int) (100.0 - (compressedLen * 100.0) / uncompressedLen + 0.5);
112}
113
114/*
115 * Handle the "list" command, which can be a simple file dump or
116 * a verbose listing.
117 *
118 * The verbose listing closely matches the output of the Info-ZIP "unzip"
119 * command.
120 */
121int doList(Bundle* bundle)
122{
123 int result = 1;
124 ZipFile* zip = NULL;
125 const ZipEntry* entry;
126 long totalUncLen, totalCompLen;
127 const char* zipFileName;
128
129 if (bundle->getFileSpecCount() != 1) {
130 fprintf(stderr, "ERROR: specify zip file name (only)\n");
131 goto bail;
132 }
133 zipFileName = bundle->getFileSpecEntry(0);
134
135 zip = openReadOnly(zipFileName);
136 if (zip == NULL)
137 goto bail;
138
139 int count, i;
140
141 if (bundle->getVerbose()) {
142 printf("Archive: %s\n", zipFileName);
143 printf(
144 " Length Method Size Ratio Date Time CRC-32 Name\n");
145 printf(
146 "-------- ------ ------- ----- ---- ---- ------ ----\n");
147 }
148
149 totalUncLen = totalCompLen = 0;
150
151 count = zip->getNumEntries();
152 for (i = 0; i < count; i++) {
153 entry = zip->getEntryByIndex(i);
154 if (bundle->getVerbose()) {
155 char dateBuf[32];
156 time_t when;
157
158 when = entry->getModWhen();
159 strftime(dateBuf, sizeof(dateBuf), "%m-%d-%y %H:%M",
160 localtime(&when));
161
162 printf("%8ld %-7.7s %7ld %3d%% %s %08lx %s\n",
163 (long) entry->getUncompressedLen(),
164 compressionName(entry->getCompressionMethod()),
165 (long) entry->getCompressedLen(),
166 calcPercent(entry->getUncompressedLen(),
167 entry->getCompressedLen()),
168 dateBuf,
169 entry->getCRC32(),
170 entry->getFileName());
171 } else {
172 printf("%s\n", entry->getFileName());
173 }
174
175 totalUncLen += entry->getUncompressedLen();
176 totalCompLen += entry->getCompressedLen();
177 }
178
179 if (bundle->getVerbose()) {
180 printf(
181 "-------- ------- --- -------\n");
182 printf("%8ld %7ld %2d%% %d files\n",
183 totalUncLen,
184 totalCompLen,
185 calcPercent(totalUncLen, totalCompLen),
186 zip->getNumEntries());
187 }
188
189 if (bundle->getAndroidList()) {
190 AssetManager assets;
191 if (!assets.addAssetPath(String8(zipFileName), NULL)) {
192 fprintf(stderr, "ERROR: list -a failed because assets could not be loaded\n");
193 goto bail;
194 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 const ResTable& res = assets.getResources(false);
197 if (&res == NULL) {
198 printf("\nNo resource table found.\n");
199 } else {
200 printf("\nResource table:\n");
Dianne Hackborne17086b2009-06-19 15:13:28 -0700201 res.print(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 Asset* manifestAsset = assets.openNonAsset("AndroidManifest.xml",
205 Asset::ACCESS_BUFFER);
206 if (manifestAsset == NULL) {
207 printf("\nNo AndroidManifest.xml found.\n");
208 } else {
209 printf("\nAndroid manifest:\n");
210 ResXMLTree tree;
211 tree.setTo(manifestAsset->getBuffer(true),
212 manifestAsset->getLength());
213 printXMLBlock(&tree);
214 }
215 delete manifestAsset;
216 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 result = 0;
219
220bail:
221 delete zip;
222 return result;
223}
224
225static ssize_t indexOfAttribute(const ResXMLTree& tree, uint32_t attrRes)
226{
227 size_t N = tree.getAttributeCount();
228 for (size_t i=0; i<N; i++) {
229 if (tree.getAttributeNameResID(i) == attrRes) {
230 return (ssize_t)i;
231 }
232 }
233 return -1;
234}
235
Joe Onorato1553c822009-08-30 13:36:22 -0700236String8 getAttribute(const ResXMLTree& tree, const char* ns,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 const char* attr, String8* outError)
238{
239 ssize_t idx = tree.indexOfAttribute(ns, attr);
240 if (idx < 0) {
241 return String8();
242 }
243 Res_value value;
244 if (tree.getAttributeValue(idx, &value) != NO_ERROR) {
245 if (value.dataType != Res_value::TYPE_STRING) {
246 if (outError != NULL) *outError = "attribute is not a string value";
247 return String8();
248 }
249 }
250 size_t len;
251 const uint16_t* str = tree.getAttributeStringValue(idx, &len);
252 return str ? String8(str, len) : String8();
253}
254
255static String8 getAttribute(const ResXMLTree& tree, uint32_t attrRes, String8* outError)
256{
257 ssize_t idx = indexOfAttribute(tree, attrRes);
258 if (idx < 0) {
259 return String8();
260 }
261 Res_value value;
262 if (tree.getAttributeValue(idx, &value) != NO_ERROR) {
263 if (value.dataType != Res_value::TYPE_STRING) {
264 if (outError != NULL) *outError = "attribute is not a string value";
265 return String8();
266 }
267 }
268 size_t len;
269 const uint16_t* str = tree.getAttributeStringValue(idx, &len);
270 return str ? String8(str, len) : String8();
271}
272
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700273static int32_t getIntegerAttribute(const ResXMLTree& tree, uint32_t attrRes,
274 String8* outError, int32_t defValue = -1)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275{
276 ssize_t idx = indexOfAttribute(tree, attrRes);
277 if (idx < 0) {
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700278 return defValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 }
280 Res_value value;
281 if (tree.getAttributeValue(idx, &value) != NO_ERROR) {
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700282 if (value.dataType < Res_value::TYPE_FIRST_INT
283 || value.dataType > Res_value::TYPE_LAST_INT) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 if (outError != NULL) *outError = "attribute is not an integer value";
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700285 return defValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 }
287 }
288 return value.data;
289}
290
291static String8 getResolvedAttribute(const ResTable* resTable, const ResXMLTree& tree,
292 uint32_t attrRes, String8* outError)
293{
294 ssize_t idx = indexOfAttribute(tree, attrRes);
295 if (idx < 0) {
296 return String8();
297 }
298 Res_value value;
299 if (tree.getAttributeValue(idx, &value) != NO_ERROR) {
300 if (value.dataType == Res_value::TYPE_STRING) {
301 size_t len;
302 const uint16_t* str = tree.getAttributeStringValue(idx, &len);
303 return str ? String8(str, len) : String8();
304 }
305 resTable->resolveReference(&value, 0);
306 if (value.dataType != Res_value::TYPE_STRING) {
307 if (outError != NULL) *outError = "attribute is not a string value";
308 return String8();
309 }
310 }
311 size_t len;
312 const Res_value* value2 = &value;
313 const char16_t* str = const_cast<ResTable*>(resTable)->valueToString(value2, 0, NULL, &len);
314 return str ? String8(str, len) : String8();
315}
316
317// These are attribute resource constants for the platform, as found
318// in android.R.attr
319enum {
320 NAME_ATTR = 0x01010003,
321 VERSION_CODE_ATTR = 0x0101021b,
322 VERSION_NAME_ATTR = 0x0101021c,
323 LABEL_ATTR = 0x01010001,
324 ICON_ATTR = 0x01010002,
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700325 MIN_SDK_VERSION_ATTR = 0x0101020c,
Suchi Amalapurapu75c49842009-08-14 15:13:09 -0700326 MAX_SDK_VERSION_ATTR = 0x01010271,
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700327 REQ_TOUCH_SCREEN_ATTR = 0x01010227,
328 REQ_KEYBOARD_TYPE_ATTR = 0x01010228,
329 REQ_HARD_KEYBOARD_ATTR = 0x01010229,
330 REQ_NAVIGATION_ATTR = 0x0101022a,
331 REQ_FIVE_WAY_NAV_ATTR = 0x01010232,
332 TARGET_SDK_VERSION_ATTR = 0x01010270,
333 TEST_ONLY_ATTR = 0x01010272,
334 DENSITY_ATTR = 0x0101026c,
Dianne Hackborne5276a72009-08-27 16:28:44 -0700335 GL_ES_VERSION_ATTR = 0x01010281,
Dianne Hackborn723738c2009-06-25 19:48:04 -0700336 SMALL_SCREEN_ATTR = 0x01010284,
337 NORMAL_SCREEN_ATTR = 0x01010285,
338 LARGE_SCREEN_ATTR = 0x01010286,
Dianne Hackborne5276a72009-08-27 16:28:44 -0700339 REQUIRED_ATTR = 0x0101028e,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340};
341
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700342const char *getComponentName(String8 &pkgName, String8 &componentName) {
343 ssize_t idx = componentName.find(".");
344 String8 retStr(pkgName);
345 if (idx == 0) {
346 retStr += componentName;
347 } else if (idx < 0) {
348 retStr += ".";
349 retStr += componentName;
350 } else {
351 return componentName.string();
352 }
353 return retStr.string();
354}
355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356/*
357 * Handle the "dump" command, to extract select data from an archive.
358 */
359int doDump(Bundle* bundle)
360{
361 status_t result = UNKNOWN_ERROR;
362 Asset* asset = NULL;
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700363
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800364 if (bundle->getFileSpecCount() < 1) {
365 fprintf(stderr, "ERROR: no dump option specified\n");
366 return 1;
367 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 if (bundle->getFileSpecCount() < 2) {
370 fprintf(stderr, "ERROR: no dump file specified\n");
371 return 1;
372 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 const char* option = bundle->getFileSpecEntry(0);
375 const char* filename = bundle->getFileSpecEntry(1);
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 AssetManager assets;
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700378 void* assetsCookie;
379 if (!assets.addAssetPath(String8(filename), &assetsCookie)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 fprintf(stderr, "ERROR: dump failed because assets could not be loaded\n");
381 return 1;
382 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 const ResTable& res = assets.getResources(false);
385 if (&res == NULL) {
386 fprintf(stderr, "ERROR: dump failed because no resource table was found\n");
387 goto bail;
388 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 if (strcmp("resources", option) == 0) {
Dianne Hackborne17086b2009-06-19 15:13:28 -0700391 res.print(bundle->getValues());
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 } else if (strcmp("xmltree", option) == 0) {
394 if (bundle->getFileSpecCount() < 3) {
395 fprintf(stderr, "ERROR: no dump xmltree resource file specified\n");
396 goto bail;
397 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700398
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 for (int i=2; i<bundle->getFileSpecCount(); i++) {
400 const char* resname = bundle->getFileSpecEntry(i);
401 ResXMLTree tree;
402 asset = assets.openNonAsset(resname, Asset::ACCESS_BUFFER);
403 if (asset == NULL) {
404 fprintf(stderr, "ERROR: dump failed because resource %p found\n", resname);
405 goto bail;
406 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 if (tree.setTo(asset->getBuffer(true),
409 asset->getLength()) != NO_ERROR) {
410 fprintf(stderr, "ERROR: Resource %s is corrupt\n", resname);
411 goto bail;
412 }
413 tree.restart();
414 printXMLBlock(&tree);
Kenny Root19138462009-12-04 09:38:48 -0800415 tree.uninit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 delete asset;
417 asset = NULL;
418 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 } else if (strcmp("xmlstrings", option) == 0) {
421 if (bundle->getFileSpecCount() < 3) {
422 fprintf(stderr, "ERROR: no dump xmltree resource file specified\n");
423 goto bail;
424 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 for (int i=2; i<bundle->getFileSpecCount(); i++) {
427 const char* resname = bundle->getFileSpecEntry(i);
428 ResXMLTree tree;
429 asset = assets.openNonAsset(resname, Asset::ACCESS_BUFFER);
430 if (asset == NULL) {
431 fprintf(stderr, "ERROR: dump failed because resource %p found\n", resname);
432 goto bail;
433 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800435 if (tree.setTo(asset->getBuffer(true),
436 asset->getLength()) != NO_ERROR) {
437 fprintf(stderr, "ERROR: Resource %s is corrupt\n", resname);
438 goto bail;
439 }
440 printStringPool(&tree.getStrings());
441 delete asset;
442 asset = NULL;
443 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 } else {
446 ResXMLTree tree;
447 asset = assets.openNonAsset("AndroidManifest.xml",
448 Asset::ACCESS_BUFFER);
449 if (asset == NULL) {
450 fprintf(stderr, "ERROR: dump failed because no AndroidManifest.xml found\n");
451 goto bail;
452 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 if (tree.setTo(asset->getBuffer(true),
455 asset->getLength()) != NO_ERROR) {
456 fprintf(stderr, "ERROR: AndroidManifest.xml is corrupt\n");
457 goto bail;
458 }
459 tree.restart();
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 if (strcmp("permissions", option) == 0) {
462 size_t len;
463 ResXMLTree::event_code_t code;
464 int depth = 0;
465 while ((code=tree.next()) != ResXMLTree::END_DOCUMENT && code != ResXMLTree::BAD_DOCUMENT) {
466 if (code == ResXMLTree::END_TAG) {
467 depth--;
468 continue;
469 }
470 if (code != ResXMLTree::START_TAG) {
471 continue;
472 }
473 depth++;
474 String8 tag(tree.getElementName(&len));
475 //printf("Depth %d tag %s\n", depth, tag.string());
476 if (depth == 1) {
477 if (tag != "manifest") {
478 fprintf(stderr, "ERROR: manifest does not start with <manifest> tag\n");
479 goto bail;
480 }
481 String8 pkg = getAttribute(tree, NULL, "package", NULL);
482 printf("package: %s\n", pkg.string());
483 } else if (depth == 2 && tag == "permission") {
484 String8 error;
485 String8 name = getAttribute(tree, NAME_ATTR, &error);
486 if (error != "") {
487 fprintf(stderr, "ERROR: %s\n", error.string());
488 goto bail;
489 }
490 printf("permission: %s\n", name.string());
491 } else if (depth == 2 && tag == "uses-permission") {
492 String8 error;
493 String8 name = getAttribute(tree, NAME_ATTR, &error);
494 if (error != "") {
495 fprintf(stderr, "ERROR: %s\n", error.string());
496 goto bail;
497 }
498 printf("uses-permission: %s\n", name.string());
499 }
500 }
501 } else if (strcmp("badging", option) == 0) {
502 size_t len;
503 ResXMLTree::event_code_t code;
504 int depth = 0;
505 String8 error;
506 bool withinActivity = false;
507 bool isMainActivity = false;
508 bool isLauncherActivity = false;
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700509 bool isSearchable = false;
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700510 bool withinApplication = false;
511 bool withinReceiver = false;
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700512 bool withinService = false;
513 bool withinIntentFilter = false;
514 bool hasMainActivity = false;
515 bool hasOtherActivities = false;
516 bool hasOtherReceivers = false;
517 bool hasOtherServices = false;
518 bool hasWallpaperService = false;
519 bool hasImeService = false;
520 bool hasWidgetReceivers = false;
521 bool hasIntentFilter = false;
522 bool actMainActivity = false;
523 bool actWidgetReceivers = false;
524 bool actImeService = false;
525 bool actWallpaperService = false;
Dianne Hackborne5276a72009-08-27 16:28:44 -0700526 bool specCameraFeature = false;
527 bool hasCameraPermission = false;
Dianne Hackborn723738c2009-06-25 19:48:04 -0700528 int targetSdk = 0;
529 int smallScreen = 1;
530 int normalScreen = 1;
531 int largeScreen = 1;
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700532 String8 pkg;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 String8 activityName;
534 String8 activityLabel;
535 String8 activityIcon;
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700536 String8 receiverName;
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700537 String8 serviceName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 while ((code=tree.next()) != ResXMLTree::END_DOCUMENT && code != ResXMLTree::BAD_DOCUMENT) {
539 if (code == ResXMLTree::END_TAG) {
540 depth--;
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700541 if (depth < 2) {
542 withinApplication = false;
543 } else if (depth < 3) {
544 if (withinActivity && isMainActivity && isLauncherActivity) {
545 const char *aName = getComponentName(pkg, activityName);
546 if (aName != NULL) {
547 printf("launchable activity name='%s'", aName);
548 }
549 printf("label='%s' icon='%s'\n",
550 activityLabel.string(),
551 activityIcon.string());
552 }
553 if (!hasIntentFilter) {
554 hasOtherActivities |= withinActivity;
555 hasOtherReceivers |= withinReceiver;
556 hasOtherServices |= withinService;
557 }
558 withinActivity = false;
559 withinService = false;
560 withinReceiver = false;
561 hasIntentFilter = false;
562 isMainActivity = isLauncherActivity = false;
563 } else if (depth < 4) {
564 if (withinIntentFilter) {
565 if (withinActivity) {
566 hasMainActivity |= actMainActivity;
567 hasOtherActivities |= !actMainActivity;
568 } else if (withinReceiver) {
569 hasWidgetReceivers |= actWidgetReceivers;
570 hasOtherReceivers |= !actWidgetReceivers;
571 } else if (withinService) {
572 hasImeService |= actImeService;
573 hasWallpaperService |= actWallpaperService;
574 hasOtherServices |= (!actImeService && !actWallpaperService);
575 }
576 }
577 withinIntentFilter = false;
578 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 continue;
580 }
581 if (code != ResXMLTree::START_TAG) {
582 continue;
583 }
584 depth++;
585 String8 tag(tree.getElementName(&len));
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700586 //printf("Depth %d, %s\n", depth, tag.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 if (depth == 1) {
588 if (tag != "manifest") {
589 fprintf(stderr, "ERROR: manifest does not start with <manifest> tag\n");
590 goto bail;
591 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700592 pkg = getAttribute(tree, NULL, "package", NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 printf("package: name='%s' ", pkg.string());
594 int32_t versionCode = getIntegerAttribute(tree, VERSION_CODE_ATTR, &error);
595 if (error != "") {
596 fprintf(stderr, "ERROR getting 'android:versionCode' attribute: %s\n", error.string());
597 goto bail;
598 }
599 if (versionCode > 0) {
600 printf("versionCode='%d' ", versionCode);
601 } else {
602 printf("versionCode='' ");
603 }
604 String8 versionName = getAttribute(tree, VERSION_NAME_ATTR, &error);
605 if (error != "") {
606 fprintf(stderr, "ERROR getting 'android:versionName' attribute: %s\n", error.string());
607 goto bail;
608 }
609 printf("versionName='%s'\n", versionName.string());
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700610 } else if (depth == 2) {
611 withinApplication = false;
612 if (tag == "application") {
613 withinApplication = true;
614 String8 label = getResolvedAttribute(&res, tree, LABEL_ATTR, &error);
615 if (error != "") {
616 fprintf(stderr, "ERROR getting 'android:label' attribute: %s\n", error.string());
617 goto bail;
618 }
619 printf("application: label='%s' ", label.string());
620 String8 icon = getResolvedAttribute(&res, tree, ICON_ATTR, &error);
621 if (error != "") {
622 fprintf(stderr, "ERROR getting 'android:icon' attribute: %s\n", error.string());
623 goto bail;
624 }
625 printf("icon='%s'\n", icon.string());
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700626 int32_t testOnly = getIntegerAttribute(tree, TEST_ONLY_ATTR, &error, 0);
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700627 if (error != "") {
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700628 fprintf(stderr, "ERROR getting 'android:testOnly' attribute: %s\n", error.string());
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700629 goto bail;
630 }
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700631 if (testOnly != 0) {
632 printf("testOnly='%d'\n", testOnly);
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700633 }
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700634 } else if (tag == "uses-sdk") {
635 int32_t code = getIntegerAttribute(tree, MIN_SDK_VERSION_ATTR, &error);
636 if (error != "") {
637 error = "";
638 String8 name = getResolvedAttribute(&res, tree, MIN_SDK_VERSION_ATTR, &error);
639 if (error != "") {
640 fprintf(stderr, "ERROR getting 'android:minSdkVersion' attribute: %s\n",
641 error.string());
642 goto bail;
643 }
Dianne Hackborn723738c2009-06-25 19:48:04 -0700644 if (name == "Donut") targetSdk = 4;
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700645 printf("sdkVersion:'%s'\n", name.string());
646 } else if (code != -1) {
Dianne Hackborn723738c2009-06-25 19:48:04 -0700647 targetSdk = code;
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700648 printf("sdkVersion:'%d'\n", code);
649 }
Suchi Amalapurapu75c49842009-08-14 15:13:09 -0700650 code = getIntegerAttribute(tree, MAX_SDK_VERSION_ATTR, NULL, -1);
651 if (code != -1) {
652 printf("maxSdkVersion:'%d'\n", code);
653 }
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700654 code = getIntegerAttribute(tree, TARGET_SDK_VERSION_ATTR, &error);
655 if (error != "") {
656 error = "";
657 String8 name = getResolvedAttribute(&res, tree, TARGET_SDK_VERSION_ATTR, &error);
658 if (error != "") {
659 fprintf(stderr, "ERROR getting 'android:targetSdkVersion' attribute: %s\n",
660 error.string());
661 goto bail;
662 }
Dianne Hackborn723738c2009-06-25 19:48:04 -0700663 if (name == "Donut" && targetSdk < 4) targetSdk = 4;
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700664 printf("targetSdkVersion:'%s'\n", name.string());
665 } else if (code != -1) {
Dianne Hackborn723738c2009-06-25 19:48:04 -0700666 if (targetSdk < code) {
667 targetSdk = code;
668 }
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700669 printf("targetSdkVersion:'%d'\n", code);
670 }
671 } else if (tag == "uses-configuration") {
672 int32_t reqTouchScreen = getIntegerAttribute(tree,
673 REQ_TOUCH_SCREEN_ATTR, NULL, 0);
674 int32_t reqKeyboardType = getIntegerAttribute(tree,
675 REQ_KEYBOARD_TYPE_ATTR, NULL, 0);
676 int32_t reqHardKeyboard = getIntegerAttribute(tree,
677 REQ_HARD_KEYBOARD_ATTR, NULL, 0);
678 int32_t reqNavigation = getIntegerAttribute(tree,
679 REQ_NAVIGATION_ATTR, NULL, 0);
680 int32_t reqFiveWayNav = getIntegerAttribute(tree,
681 REQ_FIVE_WAY_NAV_ATTR, NULL, 0);
682 printf("uses-configuation:");
683 if (reqTouchScreen != 0) {
684 printf(" reqTouchScreen='%d'", reqTouchScreen);
685 }
686 if (reqKeyboardType != 0) {
687 printf(" reqKeyboardType='%d'", reqKeyboardType);
688 }
689 if (reqHardKeyboard != 0) {
690 printf(" reqHardKeyboard='%d'", reqHardKeyboard);
691 }
692 if (reqNavigation != 0) {
693 printf(" reqNavigation='%d'", reqNavigation);
694 }
695 if (reqFiveWayNav != 0) {
696 printf(" reqFiveWayNav='%d'", reqFiveWayNav);
697 }
698 printf("\n");
699 } else if (tag == "supports-density") {
700 int32_t dens = getIntegerAttribute(tree, DENSITY_ATTR, &error);
701 if (error != "") {
702 fprintf(stderr, "ERROR getting 'android:density' attribute: %s\n",
703 error.string());
704 goto bail;
705 }
706 printf("supports-density:'%d'\n", dens);
Dianne Hackborn723738c2009-06-25 19:48:04 -0700707 } else if (tag == "supports-screens") {
708 smallScreen = getIntegerAttribute(tree,
709 SMALL_SCREEN_ATTR, NULL, 1);
710 normalScreen = getIntegerAttribute(tree,
711 NORMAL_SCREEN_ATTR, NULL, 1);
712 largeScreen = getIntegerAttribute(tree,
713 LARGE_SCREEN_ATTR, NULL, 1);
Dianne Hackborne5276a72009-08-27 16:28:44 -0700714 } else if (tag == "uses-feature") {
715 String8 name = getAttribute(tree, NAME_ATTR, &error);
Suchi Amalapurapu40b94722009-09-20 13:39:37 -0700716
717 if (name != "" && error == "") {
Dianne Hackborne5276a72009-08-27 16:28:44 -0700718 int req = getIntegerAttribute(tree,
719 REQUIRED_ATTR, NULL, 1);
720 if (name == "android.hardware.camera") {
721 specCameraFeature = true;
722 }
723 printf("uses-feature%s:'%s'\n",
724 req ? "" : "-not-required", name.string());
725 } else {
726 int vers = getIntegerAttribute(tree,
727 GL_ES_VERSION_ATTR, &error);
728 if (error == "") {
729 printf("uses-gl-es:'0x%x'\n", vers);
730 }
731 }
732 } else if (tag == "uses-permission") {
733 String8 name = getAttribute(tree, NAME_ATTR, &error);
Suchi Amalapurapu40b94722009-09-20 13:39:37 -0700734 if (name != "" && error == "") {
Dianne Hackborne5276a72009-08-27 16:28:44 -0700735 if (name == "android.permission.CAMERA") {
736 hasCameraPermission = true;
737 }
738 printf("uses-permission:'%s'\n", name.string());
739 } else {
740 fprintf(stderr, "ERROR getting 'android:name' attribute: %s\n",
741 error.string());
742 goto bail;
743 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700745 } else if (depth == 3 && withinApplication) {
746 withinActivity = false;
747 withinReceiver = false;
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700748 withinService = false;
749 hasIntentFilter = false;
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700750 if(tag == "activity") {
751 withinActivity = true;
752 activityName = getAttribute(tree, NAME_ATTR, &error);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 if (error != "") {
754 fprintf(stderr, "ERROR getting 'android:name' attribute: %s\n", error.string());
755 goto bail;
756 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700757
758 activityLabel = getResolvedAttribute(&res, tree, LABEL_ATTR, &error);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 if (error != "") {
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700760 fprintf(stderr, "ERROR getting 'android:label' attribute: %s\n", error.string());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 goto bail;
762 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700763
764 activityIcon = getResolvedAttribute(&res, tree, ICON_ATTR, &error);
765 if (error != "") {
766 fprintf(stderr, "ERROR getting 'android:icon' attribute: %s\n", error.string());
767 goto bail;
768 }
769 } else if (tag == "uses-library") {
770 String8 libraryName = getAttribute(tree, NAME_ATTR, &error);
771 if (error != "") {
772 fprintf(stderr, "ERROR getting 'android:name' attribute for uses-library: %s\n", error.string());
773 goto bail;
774 }
Dianne Hackborn49237342009-08-27 20:08:01 -0700775 int req = getIntegerAttribute(tree,
776 REQUIRED_ATTR, NULL, 1);
777 printf("uses-library%s:'%s'\n",
778 req ? "" : "-not-required", libraryName.string());
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700779 } else if (tag == "receiver") {
780 withinReceiver = true;
781 receiverName = getAttribute(tree, NAME_ATTR, &error);
782
783 if (error != "") {
784 fprintf(stderr, "ERROR getting 'android:name' attribute for receiver: %s\n", error.string());
785 goto bail;
786 }
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700787 } else if (tag == "service") {
788 withinService = true;
789 serviceName = getAttribute(tree, NAME_ATTR, &error);
790
791 if (error != "") {
792 fprintf(stderr, "ERROR getting 'android:name' attribute for service: %s\n", error.string());
793 goto bail;
794 }
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700795 }
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700796 } else if ((depth == 4) && (tag == "intent-filter")) {
797 hasIntentFilter = true;
798 withinIntentFilter = true;
799 actMainActivity = actWidgetReceivers = actImeService = actWallpaperService = false;
800 } else if ((depth == 5) && withinIntentFilter){
801 String8 action;
802 if (tag == "action") {
803 action = getAttribute(tree, NAME_ATTR, &error);
804 if (error != "") {
805 fprintf(stderr, "ERROR getting 'android:name' attribute: %s\n", error.string());
806 goto bail;
807 }
808 if (withinActivity) {
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700809 if (action == "android.intent.action.MAIN") {
810 isMainActivity = true;
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700811 actMainActivity = true;
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700812 }
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700813 } else if (withinReceiver) {
814 if (action == "android.appwidget.action.APPWIDGET_UPDATE") {
815 actWidgetReceivers = true;
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700816 }
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700817 } else if (withinService) {
818 if (action == "android.view.InputMethod") {
819 actImeService = true;
820 } else if (action == "android.service.wallpaper.WallpaperService") {
821 actWallpaperService = true;
822 }
823 }
824 if (action == "android.intent.action.SEARCH") {
825 isSearchable = true;
826 }
827 }
828
829 if (tag == "category") {
830 String8 category = getAttribute(tree, NAME_ATTR, &error);
831 if (error != "") {
832 fprintf(stderr, "ERROR getting 'name' attribute: %s\n", error.string());
833 goto bail;
834 }
835 if (withinActivity) {
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700836 if (category == "android.intent.category.LAUNCHER") {
837 isLauncherActivity = true;
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700838 }
839 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 }
841 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 }
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700843
Dianne Hackborne5276a72009-08-27 16:28:44 -0700844 if (!specCameraFeature && hasCameraPermission) {
845 // For applications that have not explicitly stated their
846 // camera feature requirements, but have requested the camera
847 // permission, we are going to give them compatibility treatment
848 // of requiring the equivalent to original android devices.
849 printf("uses-feature:'android.hardware.camera'\n");
850 printf("uses-feature:'android.hardware.camera.autofocus'\n");
851 }
Doug Zongkerdbe7a682009-10-09 11:24:51 -0700852
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700853 if (hasMainActivity) {
854 printf("main\n");
855 }
856 if (hasWidgetReceivers) {
857 printf("app-widget\n");
858 }
859 if (hasImeService) {
860 printf("ime\n");
861 }
862 if (hasWallpaperService) {
863 printf("wallpaper\n");
864 }
865 if (hasOtherActivities) {
866 printf("other-activities\n");
867 }
868 if (isSearchable) {
869 printf("search\n");
870 }
871 if (hasOtherReceivers) {
872 printf("other-receivers\n");
873 }
874 if (hasOtherServices) {
875 printf("other-services\n");
876 }
877
Dianne Hackborn723738c2009-06-25 19:48:04 -0700878 // Determine default values for any unspecified screen sizes,
879 // based on the target SDK of the package. As of 4 (donut)
880 // the screen size support was introduced, so all default to
881 // enabled.
882 if (smallScreen > 0) {
883 smallScreen = targetSdk >= 4 ? -1 : 0;
884 }
885 if (normalScreen > 0) {
886 normalScreen = -1;
887 }
888 if (largeScreen > 0) {
889 largeScreen = targetSdk >= 4 ? -1 : 0;
890 }
891 printf("supports-screens:");
892 if (smallScreen != 0) printf(" 'small'");
893 if (normalScreen != 0) printf(" 'normal'");
894 if (largeScreen != 0) printf(" 'large'");
895 printf("\n");
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 printf("locales:");
898 Vector<String8> locales;
899 res.getLocales(&locales);
Dianne Hackborne17086b2009-06-19 15:13:28 -0700900 const size_t NL = locales.size();
901 for (size_t i=0; i<NL; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902 const char* localeStr = locales[i].string();
903 if (localeStr == NULL || strlen(localeStr) == 0) {
904 localeStr = "--_--";
905 }
906 printf(" '%s'", localeStr);
907 }
908 printf("\n");
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700909
Dianne Hackborne17086b2009-06-19 15:13:28 -0700910 Vector<ResTable_config> configs;
911 res.getConfigurations(&configs);
912 SortedVector<int> densities;
913 const size_t NC = configs.size();
914 for (size_t i=0; i<NC; i++) {
915 int dens = configs[i].density;
916 if (dens == 0) dens = 160;
917 densities.add(dens);
918 }
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700919
Dianne Hackborne17086b2009-06-19 15:13:28 -0700920 printf("densities:");
921 const size_t ND = densities.size();
922 for (size_t i=0; i<ND; i++) {
923 printf(" '%d'", densities[i]);
924 }
925 printf("\n");
Suchi Amalapurapu1b125982009-08-18 01:42:27 -0700926
Dianne Hackbornbb9ea302009-05-18 15:22:00 -0700927 AssetDir* dir = assets.openNonAssetDir(assetsCookie, "lib");
928 if (dir != NULL) {
929 if (dir->getFileCount() > 0) {
930 printf("native-code:");
931 for (size_t i=0; i<dir->getFileCount(); i++) {
932 printf(" '%s'", dir->getFileName(i).string());
933 }
934 printf("\n");
935 }
936 delete dir;
937 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 } else if (strcmp("configurations", option) == 0) {
939 Vector<ResTable_config> configs;
940 res.getConfigurations(&configs);
941 const size_t N = configs.size();
942 for (size_t i=0; i<N; i++) {
943 printf("%s\n", configs[i].toString().string());
944 }
945 } else {
946 fprintf(stderr, "ERROR: unknown dump option '%s'\n", option);
947 goto bail;
948 }
949 }
950
951 result = NO_ERROR;
Suchi Amalapurapu7ef189d2009-04-02 15:20:29 -0700952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953bail:
954 if (asset) {
955 delete asset;
956 }
957 return (result != NO_ERROR);
958}
959
960
961/*
962 * Handle the "add" command, which wants to add files to a new or
963 * pre-existing archive.
964 */
965int doAdd(Bundle* bundle)
966{
967 ZipFile* zip = NULL;
968 status_t result = UNKNOWN_ERROR;
969 const char* zipFileName;
970
971 if (bundle->getUpdate()) {
972 /* avoid confusion */
973 fprintf(stderr, "ERROR: can't use '-u' with add\n");
974 goto bail;
975 }
976
977 if (bundle->getFileSpecCount() < 1) {
978 fprintf(stderr, "ERROR: must specify zip file name\n");
979 goto bail;
980 }
981 zipFileName = bundle->getFileSpecEntry(0);
982
983 if (bundle->getFileSpecCount() < 2) {
984 fprintf(stderr, "NOTE: nothing to do\n");
985 goto bail;
986 }
987
988 zip = openReadWrite(zipFileName, true);
989 if (zip == NULL) {
990 fprintf(stderr, "ERROR: failed opening/creating '%s' as Zip file\n", zipFileName);
991 goto bail;
992 }
993
994 for (int i = 1; i < bundle->getFileSpecCount(); i++) {
995 const char* fileName = bundle->getFileSpecEntry(i);
996
997 if (strcasecmp(String8(fileName).getPathExtension().string(), ".gz") == 0) {
998 printf(" '%s'... (from gzip)\n", fileName);
999 result = zip->addGzip(fileName, String8(fileName).getBasePath().string(), NULL);
1000 } else {
Doug Zongkerdbe7a682009-10-09 11:24:51 -07001001 if (bundle->getJunkPath()) {
1002 String8 storageName = String8(fileName).getPathLeaf();
1003 printf(" '%s' as '%s'...\n", fileName, storageName.string());
1004 result = zip->add(fileName, storageName.string(),
1005 bundle->getCompressionMethod(), NULL);
1006 } else {
1007 printf(" '%s'...\n", fileName);
1008 result = zip->add(fileName, bundle->getCompressionMethod(), NULL);
1009 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 }
1011 if (result != NO_ERROR) {
1012 fprintf(stderr, "Unable to add '%s' to '%s'", bundle->getFileSpecEntry(i), zipFileName);
1013 if (result == NAME_NOT_FOUND)
1014 fprintf(stderr, ": file not found\n");
1015 else if (result == ALREADY_EXISTS)
1016 fprintf(stderr, ": already exists in archive\n");
1017 else
1018 fprintf(stderr, "\n");
1019 goto bail;
1020 }
1021 }
1022
1023 result = NO_ERROR;
1024
1025bail:
1026 delete zip;
1027 return (result != NO_ERROR);
1028}
1029
1030
1031/*
1032 * Delete files from an existing archive.
1033 */
1034int doRemove(Bundle* bundle)
1035{
1036 ZipFile* zip = NULL;
1037 status_t result = UNKNOWN_ERROR;
1038 const char* zipFileName;
1039
1040 if (bundle->getFileSpecCount() < 1) {
1041 fprintf(stderr, "ERROR: must specify zip file name\n");
1042 goto bail;
1043 }
1044 zipFileName = bundle->getFileSpecEntry(0);
1045
1046 if (bundle->getFileSpecCount() < 2) {
1047 fprintf(stderr, "NOTE: nothing to do\n");
1048 goto bail;
1049 }
1050
1051 zip = openReadWrite(zipFileName, false);
1052 if (zip == NULL) {
1053 fprintf(stderr, "ERROR: failed opening Zip archive '%s'\n",
1054 zipFileName);
1055 goto bail;
1056 }
1057
1058 for (int i = 1; i < bundle->getFileSpecCount(); i++) {
1059 const char* fileName = bundle->getFileSpecEntry(i);
1060 ZipEntry* entry;
1061
1062 entry = zip->getEntryByName(fileName);
1063 if (entry == NULL) {
1064 printf(" '%s' NOT FOUND\n", fileName);
1065 continue;
1066 }
1067
1068 result = zip->remove(entry);
1069
1070 if (result != NO_ERROR) {
1071 fprintf(stderr, "Unable to delete '%s' from '%s'\n",
1072 bundle->getFileSpecEntry(i), zipFileName);
1073 goto bail;
1074 }
1075 }
1076
1077 /* update the archive */
1078 zip->flush();
1079
1080bail:
1081 delete zip;
1082 return (result != NO_ERROR);
1083}
1084
1085
1086/*
1087 * Package up an asset directory and associated application files.
1088 */
1089int doPackage(Bundle* bundle)
1090{
1091 const char* outputAPKFile;
1092 int retVal = 1;
1093 status_t err;
1094 sp<AaptAssets> assets;
1095 int N;
1096
1097 // -c zz_ZZ means do pseudolocalization
1098 ResourceFilter filter;
1099 err = filter.parse(bundle->getConfigurations());
1100 if (err != NO_ERROR) {
1101 goto bail;
1102 }
1103 if (filter.containsPseudo()) {
1104 bundle->setPseudolocalize(true);
1105 }
1106
1107 N = bundle->getFileSpecCount();
1108 if (N < 1 && bundle->getResourceSourceDirs().size() == 0 && bundle->getJarFiles().size() == 0
1109 && bundle->getAndroidManifestFile() == NULL && bundle->getAssetSourceDir() == NULL) {
1110 fprintf(stderr, "ERROR: no input files\n");
1111 goto bail;
1112 }
1113
1114 outputAPKFile = bundle->getOutputAPKFile();
1115
1116 // Make sure the filenames provided exist and are of the appropriate type.
1117 if (outputAPKFile) {
1118 FileType type;
1119 type = getFileType(outputAPKFile);
1120 if (type != kFileTypeNonexistent && type != kFileTypeRegular) {
1121 fprintf(stderr,
1122 "ERROR: output file '%s' exists but is not regular file\n",
1123 outputAPKFile);
1124 goto bail;
1125 }
1126 }
1127
1128 // Load the assets.
1129 assets = new AaptAssets();
1130 err = assets->slurpFromArgs(bundle);
1131 if (err < 0) {
1132 goto bail;
1133 }
1134
1135 if (bundle->getVerbose()) {
1136 assets->print();
1137 }
1138
1139 // If they asked for any files that need to be compiled, do so.
1140 if (bundle->getResourceSourceDirs().size() || bundle->getAndroidManifestFile()) {
1141 err = buildResources(bundle, assets);
1142 if (err != 0) {
1143 goto bail;
1144 }
1145 }
1146
1147 // At this point we've read everything and processed everything. From here
1148 // on out it's just writing output files.
1149 if (SourcePos::hasErrors()) {
1150 goto bail;
1151 }
1152
1153 // Write out R.java constants
1154 if (assets->getPackage() == assets->getSymbolsPrivatePackage()) {
1155 err = writeResourceSymbols(bundle, assets, assets->getPackage(), true);
1156 if (err < 0) {
1157 goto bail;
1158 }
1159 } else {
1160 err = writeResourceSymbols(bundle, assets, assets->getPackage(), false);
1161 if (err < 0) {
1162 goto bail;
1163 }
1164 err = writeResourceSymbols(bundle, assets, assets->getSymbolsPrivatePackage(), true);
1165 if (err < 0) {
1166 goto bail;
1167 }
1168 }
1169
Joe Onorato1553c822009-08-30 13:36:22 -07001170 // Write out the ProGuard file
1171 err = writeProguardFile(bundle, assets);
1172 if (err < 0) {
1173 goto bail;
1174 }
1175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 // Write the apk
1177 if (outputAPKFile) {
1178 err = writeAPK(bundle, assets, String8(outputAPKFile));
1179 if (err != NO_ERROR) {
1180 fprintf(stderr, "ERROR: packaging of '%s' failed\n", outputAPKFile);
1181 goto bail;
1182 }
1183 }
1184
1185 retVal = 0;
1186bail:
1187 if (SourcePos::hasErrors()) {
1188 SourcePos::printErrors(stderr);
1189 }
1190 return retVal;
1191}