2 // Copyright 2006 The Android Open Source Project
4 // Android Asset Packaging Tool main entry point.
8 #include "ResourceTable.h"
11 #include <utils/Log.h>
12 #include <utils/threads.h>
13 #include <utils/List.h>
14 #include <utils/Errors.h>
19 using namespace android
;
22 * Show version info. All the cool kids do it.
24 int doVersion(Bundle
* bundle
)
26 if (bundle
->getFileSpecCount() != 0)
27 printf("(ignoring extra arguments)\n");
28 printf("Android Asset Packaging Tool, v0.2\n");
35 * Open the file read only. The call fails if the file doesn't exist.
37 * Returns NULL on failure.
39 ZipFile
* openReadOnly(const char* fileName
)
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
);
52 fprintf(stderr
, "ERROR: failed opening '%s' as Zip file\n",
62 * Open the file read-write. The file will be created if it doesn't
63 * already exist and "okayToCreate" is set.
65 * Returns NULL on failure.
67 ZipFile
* openReadWrite(const char* fileName
, bool okayToCreate
)
73 flags
= ZipFile::kOpenReadWrite
;
75 flags
|= ZipFile::kOpenCreate
;
78 result
= zip
->open(fileName
, flags
);
79 if (result
!= NO_ERROR
) {
91 * Return a short string describing the compression method.
93 const char* compressionName(int method
)
95 if (method
== ZipEntry::kCompressStored
)
97 else if (method
== ZipEntry::kCompressDeflated
)
104 * Return the percent reduction in size (0% == no compression).
106 int calcPercent(long uncompressedLen
, long compressedLen
)
108 if (!uncompressedLen
)
111 return (int) (100.0 - (compressedLen
* 100.0) / uncompressedLen
+ 0.5);
115 * Handle the "list" command, which can be a simple file dump or
118 * The verbose listing closely matches the output of the Info-ZIP "unzip"
121 int doList(Bundle
* bundle
)
125 const ZipEntry
* entry
;
126 long totalUncLen
, totalCompLen
;
127 const char* zipFileName
;
129 if (bundle
->getFileSpecCount() != 1) {
130 fprintf(stderr
, "ERROR: specify zip file name (only)\n");
133 zipFileName
= bundle
->getFileSpecEntry(0);
135 zip
= openReadOnly(zipFileName
);
141 if (bundle
->getVerbose()) {
142 printf("Archive: %s\n", zipFileName
);
144 " Length Method Size Ratio Offset Date Time CRC-32 Name\n");
146 "-------- ------ ------- ----- ------- ---- ---- ------ ----\n");
149 totalUncLen
= totalCompLen
= 0;
151 count
= zip
->getNumEntries();
152 for (i
= 0; i
< count
; i
++) {
153 entry
= zip
->getEntryByIndex(i
);
154 if (bundle
->getVerbose()) {
158 when
= entry
->getModWhen();
159 strftime(dateBuf
, sizeof(dateBuf
), "%m-%d-%y %H:%M",
162 printf("%8ld %-7.7s %7ld %3d%% %8zd %s %08lx %s\n",
163 (long) entry
->getUncompressedLen(),
164 compressionName(entry
->getCompressionMethod()),
165 (long) entry
->getCompressedLen(),
166 calcPercent(entry
->getUncompressedLen(),
167 entry
->getCompressedLen()),
168 (size_t) entry
->getLFHOffset(),
171 entry
->getFileName());
173 printf("%s\n", entry
->getFileName());
176 totalUncLen
+= entry
->getUncompressedLen();
177 totalCompLen
+= entry
->getCompressedLen();
180 if (bundle
->getVerbose()) {
182 "-------- ------- --- -------\n");
183 printf("%8ld %7ld %2d%% %d files\n",
186 calcPercent(totalUncLen
, totalCompLen
),
187 zip
->getNumEntries());
190 if (bundle
->getAndroidList()) {
192 if (!assets
.addAssetPath(String8(zipFileName
), NULL
)) {
193 fprintf(stderr
, "ERROR: list -a failed because assets could not be loaded\n");
197 const ResTable
& res
= assets
.getResources(false);
199 printf("\nNo resource table found.\n");
201 #ifndef HAVE_ANDROID_OS
202 printf("\nResource table:\n");
207 Asset
* manifestAsset
= assets
.openNonAsset("AndroidManifest.xml",
208 Asset::ACCESS_BUFFER
);
209 if (manifestAsset
== NULL
) {
210 printf("\nNo AndroidManifest.xml found.\n");
212 printf("\nAndroid manifest:\n");
214 tree
.setTo(manifestAsset
->getBuffer(true),
215 manifestAsset
->getLength());
216 printXMLBlock(&tree
);
218 delete manifestAsset
;
228 static ssize_t
indexOfAttribute(const ResXMLTree
& tree
, uint32_t attrRes
)
230 size_t N
= tree
.getAttributeCount();
231 for (size_t i
=0; i
<N
; i
++) {
232 if (tree
.getAttributeNameResID(i
) == attrRes
) {
239 String8
getAttribute(const ResXMLTree
& tree
, const char* ns
,
240 const char* attr
, String8
* outError
)
242 ssize_t idx
= tree
.indexOfAttribute(ns
, attr
);
247 if (tree
.getAttributeValue(idx
, &value
) != NO_ERROR
) {
248 if (value
.dataType
!= Res_value::TYPE_STRING
) {
249 if (outError
!= NULL
) *outError
= "attribute is not a string value";
254 const uint16_t* str
= tree
.getAttributeStringValue(idx
, &len
);
255 return str
? String8(str
, len
) : String8();
258 static String8
getAttribute(const ResXMLTree
& tree
, uint32_t attrRes
, String8
* outError
)
260 ssize_t idx
= indexOfAttribute(tree
, attrRes
);
265 if (tree
.getAttributeValue(idx
, &value
) != NO_ERROR
) {
266 if (value
.dataType
!= Res_value::TYPE_STRING
) {
267 if (outError
!= NULL
) *outError
= "attribute is not a string value";
272 const uint16_t* str
= tree
.getAttributeStringValue(idx
, &len
);
273 return str
? String8(str
, len
) : String8();
276 static int32_t getIntegerAttribute(const ResXMLTree
& tree
, uint32_t attrRes
,
277 String8
* outError
, int32_t defValue
= -1)
279 ssize_t idx
= indexOfAttribute(tree
, attrRes
);
284 if (tree
.getAttributeValue(idx
, &value
) != NO_ERROR
) {
285 if (value
.dataType
< Res_value::TYPE_FIRST_INT
286 || value
.dataType
> Res_value::TYPE_LAST_INT
) {
287 if (outError
!= NULL
) *outError
= "attribute is not an integer value";
294 static String8
getResolvedAttribute(const ResTable
* resTable
, const ResXMLTree
& tree
,
295 uint32_t attrRes
, String8
* outError
)
297 ssize_t idx
= indexOfAttribute(tree
, attrRes
);
302 if (tree
.getAttributeValue(idx
, &value
) != NO_ERROR
) {
303 if (value
.dataType
== Res_value::TYPE_STRING
) {
305 const uint16_t* str
= tree
.getAttributeStringValue(idx
, &len
);
306 return str
? String8(str
, len
) : String8();
308 resTable
->resolveReference(&value
, 0);
309 if (value
.dataType
!= Res_value::TYPE_STRING
) {
310 if (outError
!= NULL
) *outError
= "attribute is not a string value";
315 const Res_value
* value2
= &value
;
316 const char16_t* str
= const_cast<ResTable
*>(resTable
)->valueToString(value2
, 0, NULL
, &len
);
317 return str
? String8(str
, len
) : String8();
320 // These are attribute resource constants for the platform, as found
323 NAME_ATTR
= 0x01010003,
324 VERSION_CODE_ATTR
= 0x0101021b,
325 VERSION_NAME_ATTR
= 0x0101021c,
326 LABEL_ATTR
= 0x01010001,
327 ICON_ATTR
= 0x01010002,
328 MIN_SDK_VERSION_ATTR
= 0x0101020c,
329 MAX_SDK_VERSION_ATTR
= 0x01010271,
330 REQ_TOUCH_SCREEN_ATTR
= 0x01010227,
331 REQ_KEYBOARD_TYPE_ATTR
= 0x01010228,
332 REQ_HARD_KEYBOARD_ATTR
= 0x01010229,
333 REQ_NAVIGATION_ATTR
= 0x0101022a,
334 REQ_FIVE_WAY_NAV_ATTR
= 0x01010232,
335 TARGET_SDK_VERSION_ATTR
= 0x01010270,
336 TEST_ONLY_ATTR
= 0x01010272,
337 ANY_DENSITY_ATTR
= 0x0101026c,
338 GL_ES_VERSION_ATTR
= 0x01010281,
339 SMALL_SCREEN_ATTR
= 0x01010284,
340 NORMAL_SCREEN_ATTR
= 0x01010285,
341 LARGE_SCREEN_ATTR
= 0x01010286,
342 XLARGE_SCREEN_ATTR
= 0x010102bf,
343 REQUIRED_ATTR
= 0x0101028e,
344 SCREEN_SIZE_ATTR
= 0x010102ca,
345 SCREEN_DENSITY_ATTR
= 0x010102cb,
346 REQUIRES_SMALLEST_WIDTH_DP_ATTR
= 0x01010364,
347 COMPATIBLE_WIDTH_LIMIT_DP_ATTR
= 0x01010365,
348 LARGEST_WIDTH_LIMIT_DP_ATTR
= 0x01010366,
351 const char *getComponentName(String8
&pkgName
, String8
&componentName
) {
352 ssize_t idx
= componentName
.find(".");
353 String8
retStr(pkgName
);
355 retStr
+= componentName
;
356 } else if (idx
< 0) {
358 retStr
+= componentName
;
360 return componentName
.string();
362 return retStr
.string();
365 static void printCompatibleScreens(ResXMLTree
& tree
) {
367 ResXMLTree::event_code_t code
;
370 printf("compatible-screens:");
371 while ((code
=tree
.next()) != ResXMLTree::END_DOCUMENT
&& code
!= ResXMLTree::BAD_DOCUMENT
) {
372 if (code
== ResXMLTree::END_TAG
) {
379 if (code
!= ResXMLTree::START_TAG
) {
383 String8
tag(tree
.getElementName(&len
));
384 if (tag
== "screen") {
385 int32_t screenSize
= getIntegerAttribute(tree
,
386 SCREEN_SIZE_ATTR
, NULL
, -1);
387 int32_t screenDensity
= getIntegerAttribute(tree
,
388 SCREEN_DENSITY_ATTR
, NULL
, -1);
389 if (screenSize
> 0 && screenDensity
> 0) {
394 printf("'%d/%d'", screenSize
, screenDensity
);
402 * Handle the "dump" command, to extract select data from an archive.
404 int doDump(Bundle
* bundle
)
406 status_t result
= UNKNOWN_ERROR
;
409 if (bundle
->getFileSpecCount() < 1) {
410 fprintf(stderr
, "ERROR: no dump option specified\n");
414 if (bundle
->getFileSpecCount() < 2) {
415 fprintf(stderr
, "ERROR: no dump file specified\n");
419 const char* option
= bundle
->getFileSpecEntry(0);
420 const char* filename
= bundle
->getFileSpecEntry(1);
424 if (!assets
.addAssetPath(String8(filename
), &assetsCookie
)) {
425 fprintf(stderr
, "ERROR: dump failed because assets could not be loaded\n");
429 // Make a dummy config for retrieving resources... we need to supply
430 // non-default values for some configs so that we can retrieve resources
431 // in the app that don't have a default. The most important of these is
432 // the API version because key resources like icons will have an implicit
433 // version if they are using newer config types like density.
434 ResTable_config config
;
435 config
.language
[0] = 'e';
436 config
.language
[1] = 'n';
437 config
.country
[0] = 'U';
438 config
.country
[1] = 'S';
439 config
.orientation
= ResTable_config::ORIENTATION_PORT
;
440 config
.density
= ResTable_config::DENSITY_MEDIUM
;
441 config
.sdkVersion
= 10000; // Very high.
442 config
.screenWidthDp
= 320;
443 config
.screenHeightDp
= 480;
444 config
.smallestScreenWidthDp
= 320;
445 assets
.setConfiguration(config
);
447 const ResTable
& res
= assets
.getResources(false);
449 fprintf(stderr
, "ERROR: dump failed because no resource table was found\n");
453 if (strcmp("resources", option
) == 0) {
454 #ifndef HAVE_ANDROID_OS
455 res
.print(bundle
->getValues());
457 } else if (strcmp("xmltree", option
) == 0) {
458 if (bundle
->getFileSpecCount() < 3) {
459 fprintf(stderr
, "ERROR: no dump xmltree resource file specified\n");
463 for (int i
=2; i
<bundle
->getFileSpecCount(); i
++) {
464 const char* resname
= bundle
->getFileSpecEntry(i
);
466 asset
= assets
.openNonAsset(resname
, Asset::ACCESS_BUFFER
);
468 fprintf(stderr
, "ERROR: dump failed because resource %s found\n", resname
);
472 if (tree
.setTo(asset
->getBuffer(true),
473 asset
->getLength()) != NO_ERROR
) {
474 fprintf(stderr
, "ERROR: Resource %s is corrupt\n", resname
);
478 printXMLBlock(&tree
);
484 } else if (strcmp("xmlstrings", option
) == 0) {
485 if (bundle
->getFileSpecCount() < 3) {
486 fprintf(stderr
, "ERROR: no dump xmltree resource file specified\n");
490 for (int i
=2; i
<bundle
->getFileSpecCount(); i
++) {
491 const char* resname
= bundle
->getFileSpecEntry(i
);
493 asset
= assets
.openNonAsset(resname
, Asset::ACCESS_BUFFER
);
495 fprintf(stderr
, "ERROR: dump failed because resource %s found\n", resname
);
499 if (tree
.setTo(asset
->getBuffer(true),
500 asset
->getLength()) != NO_ERROR
) {
501 fprintf(stderr
, "ERROR: Resource %s is corrupt\n", resname
);
504 printStringPool(&tree
.getStrings());
511 asset
= assets
.openNonAsset("AndroidManifest.xml",
512 Asset::ACCESS_BUFFER
);
514 fprintf(stderr
, "ERROR: dump failed because no AndroidManifest.xml found\n");
518 if (tree
.setTo(asset
->getBuffer(true),
519 asset
->getLength()) != NO_ERROR
) {
520 fprintf(stderr
, "ERROR: AndroidManifest.xml is corrupt\n");
525 if (strcmp("permissions", option
) == 0) {
527 ResXMLTree::event_code_t code
;
529 while ((code
=tree
.next()) != ResXMLTree::END_DOCUMENT
&& code
!= ResXMLTree::BAD_DOCUMENT
) {
530 if (code
== ResXMLTree::END_TAG
) {
534 if (code
!= ResXMLTree::START_TAG
) {
538 String8
tag(tree
.getElementName(&len
));
539 //printf("Depth %d tag %s\n", depth, tag.string());
541 if (tag
!= "manifest") {
542 fprintf(stderr
, "ERROR: manifest does not start with <manifest> tag\n");
545 String8 pkg
= getAttribute(tree
, NULL
, "package", NULL
);
546 printf("package: %s\n", pkg
.string());
547 } else if (depth
== 2 && tag
== "permission") {
549 String8 name
= getAttribute(tree
, NAME_ATTR
, &error
);
551 fprintf(stderr
, "ERROR: %s\n", error
.string());
554 printf("permission: %s\n", name
.string());
555 } else if (depth
== 2 && tag
== "uses-permission") {
557 String8 name
= getAttribute(tree
, NAME_ATTR
, &error
);
559 fprintf(stderr
, "ERROR: %s\n", error
.string());
562 printf("uses-permission: %s\n", name
.string());
565 } else if (strcmp("badging", option
) == 0) {
566 Vector
<String8
> locales
;
567 res
.getLocales(&locales
);
569 Vector
<ResTable_config
> configs
;
570 res
.getConfigurations(&configs
);
571 SortedVector
<int> densities
;
572 const size_t NC
= configs
.size();
573 for (size_t i
=0; i
<NC
; i
++) {
574 int dens
= configs
[i
].density
;
575 if (dens
== 0) dens
= 160;
580 ResXMLTree::event_code_t code
;
583 bool withinActivity
= false;
584 bool isMainActivity
= false;
585 bool isLauncherActivity
= false;
586 bool isSearchable
= false;
587 bool withinApplication
= false;
588 bool withinReceiver
= false;
589 bool withinService
= false;
590 bool withinIntentFilter
= false;
591 bool hasMainActivity
= false;
592 bool hasOtherActivities
= false;
593 bool hasOtherReceivers
= false;
594 bool hasOtherServices
= false;
595 bool hasWallpaperService
= false;
596 bool hasImeService
= false;
597 bool hasWidgetReceivers
= false;
598 bool hasIntentFilter
= false;
599 bool actMainActivity
= false;
600 bool actWidgetReceivers
= false;
601 bool actImeService
= false;
602 bool actWallpaperService
= false;
604 // This next group of variables is used to implement a group of
605 // backward-compatibility heuristics necessitated by the addition of
606 // some new uses-feature constants in 2.1 and 2.2. In most cases, the
607 // heuristic is "if an app requests a permission but doesn't explicitly
608 // request the corresponding <uses-feature>, presume it's there anyway".
609 bool specCameraFeature
= false; // camera-related
610 bool specCameraAutofocusFeature
= false;
611 bool reqCameraAutofocusFeature
= false;
612 bool reqCameraFlashFeature
= false;
613 bool hasCameraPermission
= false;
614 bool specLocationFeature
= false; // location-related
615 bool specNetworkLocFeature
= false;
616 bool reqNetworkLocFeature
= false;
617 bool specGpsFeature
= false;
618 bool reqGpsFeature
= false;
619 bool hasMockLocPermission
= false;
620 bool hasCoarseLocPermission
= false;
621 bool hasGpsPermission
= false;
622 bool hasGeneralLocPermission
= false;
623 bool specBluetoothFeature
= false; // Bluetooth API-related
624 bool hasBluetoothPermission
= false;
625 bool specMicrophoneFeature
= false; // microphone-related
626 bool hasRecordAudioPermission
= false;
627 bool specWiFiFeature
= false;
628 bool hasWiFiPermission
= false;
629 bool specTelephonyFeature
= false; // telephony-related
630 bool reqTelephonySubFeature
= false;
631 bool hasTelephonyPermission
= false;
632 bool specTouchscreenFeature
= false; // touchscreen-related
633 bool specMultitouchFeature
= false;
634 bool reqDistinctMultitouchFeature
= false;
635 bool specScreenPortraitFeature
= false;
636 bool specScreenLandscapeFeature
= false;
637 // 2.2 also added some other features that apps can request, but that
638 // have no corresponding permission, so we cannot implement any
639 // back-compatibility heuristic for them. The below are thus unnecessary
640 // (but are retained here for documentary purposes.)
641 //bool specCompassFeature = false;
642 //bool specAccelerometerFeature = false;
643 //bool specProximityFeature = false;
644 //bool specAmbientLightFeature = false;
645 //bool specLiveWallpaperFeature = false;
649 int normalScreen
= 1;
651 int xlargeScreen
= 1;
653 int requiresSmallestWidthDp
= 0;
654 int compatibleWidthLimitDp
= 0;
655 int largestWidthLimitDp
= 0;
657 String8 activityName
;
658 String8 activityLabel
;
659 String8 activityIcon
;
660 String8 receiverName
;
662 while ((code
=tree
.next()) != ResXMLTree::END_DOCUMENT
&& code
!= ResXMLTree::BAD_DOCUMENT
) {
663 if (code
== ResXMLTree::END_TAG
) {
666 withinApplication
= false;
667 } else if (depth
< 3) {
668 if (withinActivity
&& isMainActivity
&& isLauncherActivity
) {
669 const char *aName
= getComponentName(pkg
, activityName
);
670 printf("launchable-activity:");
672 printf(" name='%s' ", aName
);
674 printf(" label='%s' icon='%s'\n",
675 activityLabel
.string(),
676 activityIcon
.string());
678 if (!hasIntentFilter
) {
679 hasOtherActivities
|= withinActivity
;
680 hasOtherReceivers
|= withinReceiver
;
681 hasOtherServices
|= withinService
;
683 withinActivity
= false;
684 withinService
= false;
685 withinReceiver
= false;
686 hasIntentFilter
= false;
687 isMainActivity
= isLauncherActivity
= false;
688 } else if (depth
< 4) {
689 if (withinIntentFilter
) {
690 if (withinActivity
) {
691 hasMainActivity
|= actMainActivity
;
692 hasOtherActivities
|= !actMainActivity
;
693 } else if (withinReceiver
) {
694 hasWidgetReceivers
|= actWidgetReceivers
;
695 hasOtherReceivers
|= !actWidgetReceivers
;
696 } else if (withinService
) {
697 hasImeService
|= actImeService
;
698 hasWallpaperService
|= actWallpaperService
;
699 hasOtherServices
|= (!actImeService
&& !actWallpaperService
);
702 withinIntentFilter
= false;
706 if (code
!= ResXMLTree::START_TAG
) {
710 String8
tag(tree
.getElementName(&len
));
711 //printf("Depth %d, %s\n", depth, tag.string());
713 if (tag
!= "manifest") {
714 fprintf(stderr
, "ERROR: manifest does not start with <manifest> tag\n");
717 pkg
= getAttribute(tree
, NULL
, "package", NULL
);
718 printf("package: name='%s' ", pkg
.string());
719 int32_t versionCode
= getIntegerAttribute(tree
, VERSION_CODE_ATTR
, &error
);
721 fprintf(stderr
, "ERROR getting 'android:versionCode' attribute: %s\n", error
.string());
724 if (versionCode
> 0) {
725 printf("versionCode='%d' ", versionCode
);
727 printf("versionCode='' ");
729 String8 versionName
= getResolvedAttribute(&res
, tree
, VERSION_NAME_ATTR
, &error
);
731 fprintf(stderr
, "ERROR getting 'android:versionName' attribute: %s\n", error
.string());
734 printf("versionName='%s'\n", versionName
.string());
735 } else if (depth
== 2) {
736 withinApplication
= false;
737 if (tag
== "application") {
738 withinApplication
= true;
741 const size_t NL
= locales
.size();
742 for (size_t i
=0; i
<NL
; i
++) {
743 const char* localeStr
= locales
[i
].string();
744 assets
.setLocale(localeStr
!= NULL
? localeStr
: "");
745 String8 llabel
= getResolvedAttribute(&res
, tree
, LABEL_ATTR
, &error
);
747 if (localeStr
== NULL
|| strlen(localeStr
) == 0) {
749 printf("application-label:'%s'\n", llabel
.string());
754 printf("application-label-%s:'%s'\n", localeStr
,
760 ResTable_config tmpConfig
= config
;
761 const size_t ND
= densities
.size();
762 for (size_t i
=0; i
<ND
; i
++) {
763 tmpConfig
.density
= densities
[i
];
764 assets
.setConfiguration(tmpConfig
);
765 String8 icon
= getResolvedAttribute(&res
, tree
, ICON_ATTR
, &error
);
767 printf("application-icon-%d:'%s'\n", densities
[i
], icon
.string());
770 assets
.setConfiguration(config
);
772 String8 icon
= getResolvedAttribute(&res
, tree
, ICON_ATTR
, &error
);
774 fprintf(stderr
, "ERROR getting 'android:icon' attribute: %s\n", error
.string());
777 int32_t testOnly
= getIntegerAttribute(tree
, TEST_ONLY_ATTR
, &error
, 0);
779 fprintf(stderr
, "ERROR getting 'android:testOnly' attribute: %s\n", error
.string());
782 printf("application: label='%s' ", label
.string());
783 printf("icon='%s'\n", icon
.string());
785 printf("testOnly='%d'\n", testOnly
);
787 } else if (tag
== "uses-sdk") {
788 int32_t code
= getIntegerAttribute(tree
, MIN_SDK_VERSION_ATTR
, &error
);
791 String8 name
= getResolvedAttribute(&res
, tree
, MIN_SDK_VERSION_ATTR
, &error
);
793 fprintf(stderr
, "ERROR getting 'android:minSdkVersion' attribute: %s\n",
797 if (name
== "Donut") targetSdk
= 4;
798 printf("sdkVersion:'%s'\n", name
.string());
799 } else if (code
!= -1) {
801 printf("sdkVersion:'%d'\n", code
);
803 code
= getIntegerAttribute(tree
, MAX_SDK_VERSION_ATTR
, NULL
, -1);
805 printf("maxSdkVersion:'%d'\n", code
);
807 code
= getIntegerAttribute(tree
, TARGET_SDK_VERSION_ATTR
, &error
);
810 String8 name
= getResolvedAttribute(&res
, tree
, TARGET_SDK_VERSION_ATTR
, &error
);
812 fprintf(stderr
, "ERROR getting 'android:targetSdkVersion' attribute: %s\n",
816 if (name
== "Donut" && targetSdk
< 4) targetSdk
= 4;
817 printf("targetSdkVersion:'%s'\n", name
.string());
818 } else if (code
!= -1) {
819 if (targetSdk
< code
) {
822 printf("targetSdkVersion:'%d'\n", code
);
824 } else if (tag
== "uses-configuration") {
825 int32_t reqTouchScreen
= getIntegerAttribute(tree
,
826 REQ_TOUCH_SCREEN_ATTR
, NULL
, 0);
827 int32_t reqKeyboardType
= getIntegerAttribute(tree
,
828 REQ_KEYBOARD_TYPE_ATTR
, NULL
, 0);
829 int32_t reqHardKeyboard
= getIntegerAttribute(tree
,
830 REQ_HARD_KEYBOARD_ATTR
, NULL
, 0);
831 int32_t reqNavigation
= getIntegerAttribute(tree
,
832 REQ_NAVIGATION_ATTR
, NULL
, 0);
833 int32_t reqFiveWayNav
= getIntegerAttribute(tree
,
834 REQ_FIVE_WAY_NAV_ATTR
, NULL
, 0);
835 printf("uses-configuration:");
836 if (reqTouchScreen
!= 0) {
837 printf(" reqTouchScreen='%d'", reqTouchScreen
);
839 if (reqKeyboardType
!= 0) {
840 printf(" reqKeyboardType='%d'", reqKeyboardType
);
842 if (reqHardKeyboard
!= 0) {
843 printf(" reqHardKeyboard='%d'", reqHardKeyboard
);
845 if (reqNavigation
!= 0) {
846 printf(" reqNavigation='%d'", reqNavigation
);
848 if (reqFiveWayNav
!= 0) {
849 printf(" reqFiveWayNav='%d'", reqFiveWayNav
);
852 } else if (tag
== "supports-screens") {
853 smallScreen
= getIntegerAttribute(tree
,
854 SMALL_SCREEN_ATTR
, NULL
, 1);
855 normalScreen
= getIntegerAttribute(tree
,
856 NORMAL_SCREEN_ATTR
, NULL
, 1);
857 largeScreen
= getIntegerAttribute(tree
,
858 LARGE_SCREEN_ATTR
, NULL
, 1);
859 xlargeScreen
= getIntegerAttribute(tree
,
860 XLARGE_SCREEN_ATTR
, NULL
, 1);
861 anyDensity
= getIntegerAttribute(tree
,
862 ANY_DENSITY_ATTR
, NULL
, 1);
863 requiresSmallestWidthDp
= getIntegerAttribute(tree
,
864 REQUIRES_SMALLEST_WIDTH_DP_ATTR
, NULL
, 0);
865 compatibleWidthLimitDp
= getIntegerAttribute(tree
,
866 COMPATIBLE_WIDTH_LIMIT_DP_ATTR
, NULL
, 0);
867 largestWidthLimitDp
= getIntegerAttribute(tree
,
868 LARGEST_WIDTH_LIMIT_DP_ATTR
, NULL
, 0);
869 } else if (tag
== "uses-feature") {
870 String8 name
= getAttribute(tree
, NAME_ATTR
, &error
);
872 if (name
!= "" && error
== "") {
873 int req
= getIntegerAttribute(tree
,
874 REQUIRED_ATTR
, NULL
, 1);
876 if (name
== "android.hardware.camera") {
877 specCameraFeature
= true;
878 } else if (name
== "android.hardware.camera.autofocus") {
879 // these have no corresponding permission to check for,
880 // but should imply the foundational camera permission
881 reqCameraAutofocusFeature
= reqCameraAutofocusFeature
|| req
;
882 specCameraAutofocusFeature
= true;
883 } else if (req
&& (name
== "android.hardware.camera.flash")) {
884 // these have no corresponding permission to check for,
885 // but should imply the foundational camera permission
886 reqCameraFlashFeature
= true;
887 } else if (name
== "android.hardware.location") {
888 specLocationFeature
= true;
889 } else if (name
== "android.hardware.location.network") {
890 specNetworkLocFeature
= true;
891 reqNetworkLocFeature
= reqNetworkLocFeature
|| req
;
892 } else if (name
== "android.hardware.location.gps") {
893 specGpsFeature
= true;
894 reqGpsFeature
= reqGpsFeature
|| req
;
895 } else if (name
== "android.hardware.bluetooth") {
896 specBluetoothFeature
= true;
897 } else if (name
== "android.hardware.touchscreen") {
898 specTouchscreenFeature
= true;
899 } else if (name
== "android.hardware.touchscreen.multitouch") {
900 specMultitouchFeature
= true;
901 } else if (name
== "android.hardware.touchscreen.multitouch.distinct") {
902 reqDistinctMultitouchFeature
= reqDistinctMultitouchFeature
|| req
;
903 } else if (name
== "android.hardware.microphone") {
904 specMicrophoneFeature
= true;
905 } else if (name
== "android.hardware.wifi") {
906 specWiFiFeature
= true;
907 } else if (name
== "android.hardware.telephony") {
908 specTelephonyFeature
= true;
909 } else if (req
&& (name
== "android.hardware.telephony.gsm" ||
910 name
== "android.hardware.telephony.cdma")) {
911 // these have no corresponding permission to check for,
912 // but should imply the foundational telephony permission
913 reqTelephonySubFeature
= true;
914 } else if (name
== "android.hardware.screen.portrait") {
915 specScreenPortraitFeature
= true;
916 } else if (name
== "android.hardware.screen.landscape") {
917 specScreenLandscapeFeature
= true;
919 printf("uses-feature%s:'%s'\n",
920 req
? "" : "-not-required", name
.string());
922 int vers
= getIntegerAttribute(tree
,
923 GL_ES_VERSION_ATTR
, &error
);
925 printf("uses-gl-es:'0x%x'\n", vers
);
928 } else if (tag
== "uses-permission") {
929 String8 name
= getAttribute(tree
, NAME_ATTR
, &error
);
930 if (name
!= "" && error
== "") {
931 if (name
== "android.permission.CAMERA") {
932 hasCameraPermission
= true;
933 } else if (name
== "android.permission.ACCESS_FINE_LOCATION") {
934 hasGpsPermission
= true;
935 } else if (name
== "android.permission.ACCESS_MOCK_LOCATION") {
936 hasMockLocPermission
= true;
937 } else if (name
== "android.permission.ACCESS_COARSE_LOCATION") {
938 hasCoarseLocPermission
= true;
939 } else if (name
== "android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" ||
940 name
== "android.permission.INSTALL_LOCATION_PROVIDER") {
941 hasGeneralLocPermission
= true;
942 } else if (name
== "android.permission.BLUETOOTH" ||
943 name
== "android.permission.BLUETOOTH_ADMIN") {
944 hasBluetoothPermission
= true;
945 } else if (name
== "android.permission.RECORD_AUDIO") {
946 hasRecordAudioPermission
= true;
947 } else if (name
== "android.permission.ACCESS_WIFI_STATE" ||
948 name
== "android.permission.CHANGE_WIFI_STATE" ||
949 name
== "android.permission.CHANGE_WIFI_MULTICAST_STATE") {
950 hasWiFiPermission
= true;
951 } else if (name
== "android.permission.CALL_PHONE" ||
952 name
== "android.permission.CALL_PRIVILEGED" ||
953 name
== "android.permission.MODIFY_PHONE_STATE" ||
954 name
== "android.permission.PROCESS_OUTGOING_CALLS" ||
955 name
== "android.permission.READ_SMS" ||
956 name
== "android.permission.RECEIVE_SMS" ||
957 name
== "android.permission.RECEIVE_MMS" ||
958 name
== "android.permission.RECEIVE_WAP_PUSH" ||
959 name
== "android.permission.SEND_SMS" ||
960 name
== "android.permission.WRITE_APN_SETTINGS" ||
961 name
== "android.permission.WRITE_SMS") {
962 hasTelephonyPermission
= true;
964 printf("uses-permission:'%s'\n", name
.string());
966 fprintf(stderr
, "ERROR getting 'android:name' attribute: %s\n",
970 } else if (tag
== "uses-package") {
971 String8 name
= getAttribute(tree
, NAME_ATTR
, &error
);
972 if (name
!= "" && error
== "") {
973 printf("uses-package:'%s'\n", name
.string());
975 fprintf(stderr
, "ERROR getting 'android:name' attribute: %s\n",
979 } else if (tag
== "original-package") {
980 String8 name
= getAttribute(tree
, NAME_ATTR
, &error
);
981 if (name
!= "" && error
== "") {
982 printf("original-package:'%s'\n", name
.string());
984 fprintf(stderr
, "ERROR getting 'android:name' attribute: %s\n",
988 } else if (tag
== "supports-gl-texture") {
989 String8 name
= getAttribute(tree
, NAME_ATTR
, &error
);
990 if (name
!= "" && error
== "") {
991 printf("supports-gl-texture:'%s'\n", name
.string());
993 fprintf(stderr
, "ERROR getting 'android:name' attribute: %s\n",
997 } else if (tag
== "compatible-screens") {
998 printCompatibleScreens(tree
);
1001 } else if (depth
== 3 && withinApplication
) {
1002 withinActivity
= false;
1003 withinReceiver
= false;
1004 withinService
= false;
1005 hasIntentFilter
= false;
1006 if(tag
== "activity") {
1007 withinActivity
= true;
1008 activityName
= getAttribute(tree
, NAME_ATTR
, &error
);
1010 fprintf(stderr
, "ERROR getting 'android:name' attribute: %s\n", error
.string());
1014 activityLabel
= getResolvedAttribute(&res
, tree
, LABEL_ATTR
, &error
);
1016 fprintf(stderr
, "ERROR getting 'android:label' attribute: %s\n", error
.string());
1020 activityIcon
= getResolvedAttribute(&res
, tree
, ICON_ATTR
, &error
);
1022 fprintf(stderr
, "ERROR getting 'android:icon' attribute: %s\n", error
.string());
1025 } else if (tag
== "uses-library") {
1026 String8 libraryName
= getAttribute(tree
, NAME_ATTR
, &error
);
1028 fprintf(stderr
, "ERROR getting 'android:name' attribute for uses-library: %s\n", error
.string());
1031 int req
= getIntegerAttribute(tree
,
1032 REQUIRED_ATTR
, NULL
, 1);
1033 printf("uses-library%s:'%s'\n",
1034 req
? "" : "-not-required", libraryName
.string());
1035 } else if (tag
== "receiver") {
1036 withinReceiver
= true;
1037 receiverName
= getAttribute(tree
, NAME_ATTR
, &error
);
1040 fprintf(stderr
, "ERROR getting 'android:name' attribute for receiver: %s\n", error
.string());
1043 } else if (tag
== "service") {
1044 withinService
= true;
1045 serviceName
= getAttribute(tree
, NAME_ATTR
, &error
);
1048 fprintf(stderr
, "ERROR getting 'android:name' attribute for service: %s\n", error
.string());
1052 } else if ((depth
== 4) && (tag
== "intent-filter")) {
1053 hasIntentFilter
= true;
1054 withinIntentFilter
= true;
1055 actMainActivity
= actWidgetReceivers
= actImeService
= actWallpaperService
= false;
1056 } else if ((depth
== 5) && withinIntentFilter
){
1058 if (tag
== "action") {
1059 action
= getAttribute(tree
, NAME_ATTR
, &error
);
1061 fprintf(stderr
, "ERROR getting 'android:name' attribute: %s\n", error
.string());
1064 if (withinActivity
) {
1065 if (action
== "android.intent.action.MAIN") {
1066 isMainActivity
= true;
1067 actMainActivity
= true;
1069 } else if (withinReceiver
) {
1070 if (action
== "android.appwidget.action.APPWIDGET_UPDATE") {
1071 actWidgetReceivers
= true;
1073 } else if (withinService
) {
1074 if (action
== "android.view.InputMethod") {
1075 actImeService
= true;
1076 } else if (action
== "android.service.wallpaper.WallpaperService") {
1077 actWallpaperService
= true;
1080 if (action
== "android.intent.action.SEARCH") {
1081 isSearchable
= true;
1085 if (tag
== "category") {
1086 String8 category
= getAttribute(tree
, NAME_ATTR
, &error
);
1088 fprintf(stderr
, "ERROR getting 'name' attribute: %s\n", error
.string());
1091 if (withinActivity
) {
1092 if (category
== "android.intent.category.LAUNCHER") {
1093 isLauncherActivity
= true;
1100 /* The following blocks handle printing "inferred" uses-features, based
1101 * on whether related features or permissions are used by the app.
1102 * Note that the various spec*Feature variables denote whether the
1103 * relevant tag was *present* in the AndroidManfest, not that it was
1104 * present and set to true.
1106 // Camera-related back-compatibility logic
1107 if (!specCameraFeature
) {
1108 if (reqCameraFlashFeature
|| reqCameraAutofocusFeature
) {
1109 // if app requested a sub-feature (autofocus or flash) and didn't
1110 // request the base camera feature, we infer that it meant to
1111 printf("uses-feature:'android.hardware.camera'\n");
1112 } else if (hasCameraPermission
) {
1113 // if app wants to use camera but didn't request the feature, we infer
1114 // that it meant to, and further that it wants autofocus
1115 // (which was the 1.0 - 1.5 behavior)
1116 printf("uses-feature:'android.hardware.camera'\n");
1117 if (!specCameraAutofocusFeature
) {
1118 printf("uses-feature:'android.hardware.camera.autofocus'\n");
1123 // Location-related back-compatibility logic
1124 if (!specLocationFeature
&&
1125 (hasMockLocPermission
|| hasCoarseLocPermission
|| hasGpsPermission
||
1126 hasGeneralLocPermission
|| reqNetworkLocFeature
|| reqGpsFeature
)) {
1127 // if app either takes a location-related permission or requests one of the
1128 // sub-features, we infer that it also meant to request the base location feature
1129 printf("uses-feature:'android.hardware.location'\n");
1131 if (!specGpsFeature
&& hasGpsPermission
) {
1132 // if app takes GPS (FINE location) perm but does not request the GPS
1133 // feature, we infer that it meant to
1134 printf("uses-feature:'android.hardware.location.gps'\n");
1136 if (!specNetworkLocFeature
&& hasCoarseLocPermission
) {
1137 // if app takes Network location (COARSE location) perm but does not request the
1138 // network location feature, we infer that it meant to
1139 printf("uses-feature:'android.hardware.location.network'\n");
1142 // Bluetooth-related compatibility logic
1143 if (!specBluetoothFeature
&& hasBluetoothPermission
&& (targetSdk
> 4)) {
1144 // if app takes a Bluetooth permission but does not request the Bluetooth
1145 // feature, we infer that it meant to
1146 printf("uses-feature:'android.hardware.bluetooth'\n");
1149 // Microphone-related compatibility logic
1150 if (!specMicrophoneFeature
&& hasRecordAudioPermission
) {
1151 // if app takes the record-audio permission but does not request the microphone
1152 // feature, we infer that it meant to
1153 printf("uses-feature:'android.hardware.microphone'\n");
1156 // WiFi-related compatibility logic
1157 if (!specWiFiFeature
&& hasWiFiPermission
) {
1158 // if app takes one of the WiFi permissions but does not request the WiFi
1159 // feature, we infer that it meant to
1160 printf("uses-feature:'android.hardware.wifi'\n");
1163 // Telephony-related compatibility logic
1164 if (!specTelephonyFeature
&& (hasTelephonyPermission
|| reqTelephonySubFeature
)) {
1165 // if app takes one of the telephony permissions or requests a sub-feature but
1166 // does not request the base telephony feature, we infer that it meant to
1167 printf("uses-feature:'android.hardware.telephony'\n");
1170 // Touchscreen-related back-compatibility logic
1171 if (!specTouchscreenFeature
) { // not a typo!
1172 // all apps are presumed to require a touchscreen, unless they explicitly say
1173 // <uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
1174 // Note that specTouchscreenFeature is true if the tag is present, regardless
1175 // of whether its value is true or false, so this is safe
1176 printf("uses-feature:'android.hardware.touchscreen'\n");
1178 if (!specMultitouchFeature
&& reqDistinctMultitouchFeature
) {
1179 // if app takes one of the telephony permissions or requests a sub-feature but
1180 // does not request the base telephony feature, we infer that it meant to
1181 printf("uses-feature:'android.hardware.touchscreen.multitouch'\n");
1184 // Landscape/portrait-related compatibility logic
1185 if (!specScreenLandscapeFeature
&& !specScreenPortraitFeature
&& (targetSdk
< 13)) {
1186 // If app has not specified whether it requires portrait or landscape
1187 // and is targeting an API before Honeycomb MR2, then assume it requires
1189 printf("uses-feature:'android.hardware.screen.portrait'\n");
1190 printf("uses-feature:'android.hardware.screen.landscape'\n");
1193 if (hasMainActivity
) {
1196 if (hasWidgetReceivers
) {
1197 printf("app-widget\n");
1199 if (hasImeService
) {
1202 if (hasWallpaperService
) {
1203 printf("wallpaper\n");
1205 if (hasOtherActivities
) {
1206 printf("other-activities\n");
1211 if (hasOtherReceivers
) {
1212 printf("other-receivers\n");
1214 if (hasOtherServices
) {
1215 printf("other-services\n");
1218 // For modern apps, if screen size buckets haven't been specified
1219 // but the new width ranges have, then infer the buckets from them.
1220 if (smallScreen
> 0 && normalScreen
> 0 && largeScreen
> 0 && xlargeScreen
> 0
1221 && requiresSmallestWidthDp
> 0) {
1222 int compatWidth
= compatibleWidthLimitDp
;
1223 if (compatWidth
<= 0) compatWidth
= requiresSmallestWidthDp
;
1224 if (requiresSmallestWidthDp
<= 240 && compatWidth
>= 240) {
1229 if (requiresSmallestWidthDp
<= 320 && compatWidth
>= 320) {
1234 if (requiresSmallestWidthDp
<= 480 && compatWidth
>= 480) {
1239 if (requiresSmallestWidthDp
<= 720 && compatWidth
>= 720) {
1246 // Determine default values for any unspecified screen sizes,
1247 // based on the target SDK of the package. As of 4 (donut)
1248 // the screen size support was introduced, so all default to
1250 if (smallScreen
> 0) {
1251 smallScreen
= targetSdk
>= 4 ? -1 : 0;
1253 if (normalScreen
> 0) {
1256 if (largeScreen
> 0) {
1257 largeScreen
= targetSdk
>= 4 ? -1 : 0;
1259 if (xlargeScreen
> 0) {
1260 // Introduced in Gingerbread.
1261 xlargeScreen
= targetSdk
>= 9 ? -1 : 0;
1263 if (anyDensity
> 0) {
1264 anyDensity
= (targetSdk
>= 4 || requiresSmallestWidthDp
> 0
1265 || compatibleWidthLimitDp
> 0) ? -1 : 0;
1267 printf("supports-screens:");
1268 if (smallScreen
!= 0) printf(" 'small'");
1269 if (normalScreen
!= 0) printf(" 'normal'");
1270 if (largeScreen
!= 0) printf(" 'large'");
1271 if (xlargeScreen
!= 0) printf(" 'xlarge'");
1273 printf("supports-any-density: '%s'\n", anyDensity
? "true" : "false");
1274 if (requiresSmallestWidthDp
> 0) {
1275 printf("requires-smallest-width:'%d'\n", requiresSmallestWidthDp
);
1277 if (compatibleWidthLimitDp
> 0) {
1278 printf("compatible-width-limit:'%d'\n", compatibleWidthLimitDp
);
1280 if (largestWidthLimitDp
> 0) {
1281 printf("largest-width-limit:'%d'\n", largestWidthLimitDp
);
1285 const size_t NL
= locales
.size();
1286 for (size_t i
=0; i
<NL
; i
++) {
1287 const char* localeStr
= locales
[i
].string();
1288 if (localeStr
== NULL
|| strlen(localeStr
) == 0) {
1289 localeStr
= "--_--";
1291 printf(" '%s'", localeStr
);
1295 printf("densities:");
1296 const size_t ND
= densities
.size();
1297 for (size_t i
=0; i
<ND
; i
++) {
1298 printf(" '%d'", densities
[i
]);
1302 AssetDir
* dir
= assets
.openNonAssetDir(assetsCookie
, "lib");
1304 if (dir
->getFileCount() > 0) {
1305 printf("native-code:");
1306 for (size_t i
=0; i
<dir
->getFileCount(); i
++) {
1307 printf(" '%s'", dir
->getFileName(i
).string());
1313 } else if (strcmp("configurations", option
) == 0) {
1314 Vector
<ResTable_config
> configs
;
1315 res
.getConfigurations(&configs
);
1316 const size_t N
= configs
.size();
1317 for (size_t i
=0; i
<N
; i
++) {
1318 printf("%s\n", configs
[i
].toString().string());
1321 fprintf(stderr
, "ERROR: unknown dump option '%s'\n", option
);
1332 return (result
!= NO_ERROR
);
1337 * Handle the "add" command, which wants to add files to a new or
1338 * pre-existing archive.
1340 int doAdd(Bundle
* bundle
)
1342 ZipFile
* zip
= NULL
;
1343 status_t result
= UNKNOWN_ERROR
;
1344 const char* zipFileName
;
1346 if (bundle
->getUpdate()) {
1347 /* avoid confusion */
1348 fprintf(stderr
, "ERROR: can't use '-u' with add\n");
1352 if (bundle
->getFileSpecCount() < 1) {
1353 fprintf(stderr
, "ERROR: must specify zip file name\n");
1356 zipFileName
= bundle
->getFileSpecEntry(0);
1358 if (bundle
->getFileSpecCount() < 2) {
1359 fprintf(stderr
, "NOTE: nothing to do\n");
1363 zip
= openReadWrite(zipFileName
, true);
1365 fprintf(stderr
, "ERROR: failed opening/creating '%s' as Zip file\n", zipFileName
);
1369 for (int i
= 1; i
< bundle
->getFileSpecCount(); i
++) {
1370 const char* fileName
= bundle
->getFileSpecEntry(i
);
1372 if (strcasecmp(String8(fileName
).getPathExtension().string(), ".gz") == 0) {
1373 printf(" '%s'... (from gzip)\n", fileName
);
1374 result
= zip
->addGzip(fileName
, String8(fileName
).getBasePath().string(), NULL
);
1376 if (bundle
->getJunkPath()) {
1377 String8 storageName
= String8(fileName
).getPathLeaf();
1378 printf(" '%s' as '%s'...\n", fileName
, storageName
.string());
1379 result
= zip
->add(fileName
, storageName
.string(),
1380 bundle
->getCompressionMethod(), NULL
);
1382 printf(" '%s'...\n", fileName
);
1383 result
= zip
->add(fileName
, bundle
->getCompressionMethod(), NULL
);
1386 if (result
!= NO_ERROR
) {
1387 fprintf(stderr
, "Unable to add '%s' to '%s'", bundle
->getFileSpecEntry(i
), zipFileName
);
1388 if (result
== NAME_NOT_FOUND
)
1389 fprintf(stderr
, ": file not found\n");
1390 else if (result
== ALREADY_EXISTS
)
1391 fprintf(stderr
, ": already exists in archive\n");
1393 fprintf(stderr
, "\n");
1402 return (result
!= NO_ERROR
);
1407 * Delete files from an existing archive.
1409 int doRemove(Bundle
* bundle
)
1411 ZipFile
* zip
= NULL
;
1412 status_t result
= UNKNOWN_ERROR
;
1413 const char* zipFileName
;
1415 if (bundle
->getFileSpecCount() < 1) {
1416 fprintf(stderr
, "ERROR: must specify zip file name\n");
1419 zipFileName
= bundle
->getFileSpecEntry(0);
1421 if (bundle
->getFileSpecCount() < 2) {
1422 fprintf(stderr
, "NOTE: nothing to do\n");
1426 zip
= openReadWrite(zipFileName
, false);
1428 fprintf(stderr
, "ERROR: failed opening Zip archive '%s'\n",
1433 for (int i
= 1; i
< bundle
->getFileSpecCount(); i
++) {
1434 const char* fileName
= bundle
->getFileSpecEntry(i
);
1437 entry
= zip
->getEntryByName(fileName
);
1438 if (entry
== NULL
) {
1439 printf(" '%s' NOT FOUND\n", fileName
);
1443 result
= zip
->remove(entry
);
1445 if (result
!= NO_ERROR
) {
1446 fprintf(stderr
, "Unable to delete '%s' from '%s'\n",
1447 bundle
->getFileSpecEntry(i
), zipFileName
);
1452 /* update the archive */
1457 return (result
!= NO_ERROR
);
1462 * Package up an asset directory and associated application files.
1464 int doPackage(Bundle
* bundle
)
1466 const char* outputAPKFile
;
1469 sp
<AaptAssets
> assets
;
1472 // -c zz_ZZ means do pseudolocalization
1473 ResourceFilter filter
;
1474 err
= filter
.parse(bundle
->getConfigurations());
1475 if (err
!= NO_ERROR
) {
1478 if (filter
.containsPseudo()) {
1479 bundle
->setPseudolocalize(true);
1482 N
= bundle
->getFileSpecCount();
1483 if (N
< 1 && bundle
->getResourceSourceDirs().size() == 0 && bundle
->getJarFiles().size() == 0
1484 && bundle
->getAndroidManifestFile() == NULL
&& bundle
->getAssetSourceDir() == NULL
) {
1485 fprintf(stderr
, "ERROR: no input files\n");
1489 outputAPKFile
= bundle
->getOutputAPKFile();
1491 // Make sure the filenames provided exist and are of the appropriate type.
1492 if (outputAPKFile
) {
1494 type
= getFileType(outputAPKFile
);
1495 if (type
!= kFileTypeNonexistent
&& type
!= kFileTypeRegular
) {
1497 "ERROR: output file '%s' exists but is not regular file\n",
1504 assets
= new AaptAssets();
1505 err
= assets
->slurpFromArgs(bundle
);
1510 if (bundle
->getVerbose()) {
1514 // If they asked for any files that need to be compiled, do so.
1515 if (bundle
->getResourceSourceDirs().size() || bundle
->getAndroidManifestFile()) {
1516 err
= buildResources(bundle
, assets
);
1522 // At this point we've read everything and processed everything. From here
1523 // on out it's just writing output files.
1524 if (SourcePos::hasErrors()) {
1528 // Write out R.java constants
1529 if (assets
->getPackage() == assets
->getSymbolsPrivatePackage()) {
1530 if (bundle
->getCustomPackage() == NULL
) {
1531 err
= writeResourceSymbols(bundle
, assets
, assets
->getPackage(), true);
1533 const String8
customPkg(bundle
->getCustomPackage());
1534 err
= writeResourceSymbols(bundle
, assets
, customPkg
, true);
1540 err
= writeResourceSymbols(bundle
, assets
, assets
->getPackage(), false);
1544 err
= writeResourceSymbols(bundle
, assets
, assets
->getSymbolsPrivatePackage(), true);
1550 // Write out the ProGuard file
1551 err
= writeProguardFile(bundle
, assets
);
1557 if (outputAPKFile
) {
1558 err
= writeAPK(bundle
, assets
, String8(outputAPKFile
));
1559 if (err
!= NO_ERROR
) {
1560 fprintf(stderr
, "ERROR: packaging of '%s' failed\n", outputAPKFile
);
1567 if (SourcePos::hasErrors()) {
1568 SourcePos::printErrors(stderr
);