Merge "Updated to better distinguish between options and operands"
diff --git a/buildspec.mk.default b/buildspec.mk.default
index 861bb0d..6303efc 100644
--- a/buildspec.mk.default
+++ b/buildspec.mk.default
@@ -21,6 +21,30 @@
# "buildspec.mk" should never be checked in to source control.
######################################################################
+# Choose a product to build for. Look in the products directory for ones
+# that work.
+ifndef TARGET_PRODUCT
+#TARGET_PRODUCT:=generic
+endif
+
+# Choose a variant to build. If you don't pick one, the default is eng.
+# User is what we ship. Userdebug is that, with a few flags turned on
+# for debugging. Eng has lots of extra tools for development.
+ifndef TARGET_BUILD_VARIANT
+#TARGET_BUILD_VARIANT:=user
+#TARGET_BUILD_VARIANT:=userdebug
+#TARGET_BUILD_VARIANT:=eng
+endif
+
+# Choose additional targets to always install, even when building
+# minimal targets like "make droid". This takes simple target names
+# like "Browser" or "MyApp", the names used by LOCAL_MODULE or
+# LOCAL_PACKAGE_NAME. Modules listed here will always be installed in
+# /system, even if they'd usually go in /data.
+ifndef CUSTOM_MODULES
+#CUSTOM_MODULES:=
+endif
+
# Uncomment this if you want the simulator, otherwise, build for arm
ifndef TARGET_SIMULATOR
#TARGET_SIMULATOR:=true
@@ -44,27 +68,15 @@
# will be added to LOCAL_CFLAGS when building the module.
#DEBUG_MODULE_ModuleName:=true
+# Specify an alternative tool chain prefix if needed.
+#TARGET_TOOLS_PREFIX:=
+
# Specify the extra CFLAGS to use when building a module whose
# DEBUG_MODULE_ variable is set. Host and device flags are handled
# separately.
#HOST_CUSTOM_DEBUG_CFLAGS:=
#TARGET_CUSTOM_DEBUG_CFLAGS:=
-# Choose a product to build for. Look in the products directory for ones
-# that work.
-ifndef TARGET_PRODUCT
-#TARGET_PRODUCT:=generic
-endif
-
-# Choose additional targets to always install, even when building
-# minimal targets like "make droid". This takes simple target names
-# like "Browser" or "MyApp", the names used by LOCAL_MODULE or
-# LOCAL_PACKAGE_NAME. Modules listed here will always be installed in
-# /system, even if they'd usually go in /data.
-ifndef CUSTOM_MODULES
-#CUSTOM_MODULES:=
-endif
-
# Choose additional locales, like "en_US" or "it_IT", to add to any
# built product. Any locales that appear in CUSTOM_LOCALES but not in
# the locale list for the selected product will be added to the end
@@ -88,10 +100,16 @@
#NO_FALLBACK_FONT:=true
endif
-# To enabled instrumentation in webcore based apps like gmail and
+# To enable instrumentation in webcore based apps like gmail and
# the browser, define WEBCORE_INSTRUMENTATION:=true
+ifndef WEBCORE_INSTRUMENTATION
#WEBCORE_INSTRUMENTATION:=true
-#endif
+endif
+
+# To enable SVG in webcore define ENABLE_SVG:=true
+ifndef ENABLE_SVG
+#ENABLE_SVG:=true
+endif
# when the build system changes such that this file must be updated, this
# variable will be changed. After you have modified this file with the new
diff --git a/cleanspec.mk b/cleanspec.mk
index c244c46..b40b5f2 100644
--- a/cleanspec.mk
+++ b/cleanspec.mk
@@ -18,7 +18,7 @@
# WHEN DOING SO, DELETE ANY "add-clean-step" ENTRIES THAT HAVE PILED UP.
# **********************************************************************
#
-INTERNAL_CLEAN_BUILD_VERSION := 2
+INTERNAL_CLEAN_BUILD_VERSION := 4
#
# ***********************************************************************
# Do not touch INTERNAL_CLEAN_BUILD_VERSION if you've added a clean step!
@@ -31,7 +31,7 @@
#
# E.g.:
# $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
-# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/external/zlib/)
+# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
#
# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
# files that are missing or have been moved.
@@ -55,37 +55,6 @@
#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
-$(call add-clean-step, rm -f $(PRODUCT_OUT)/system/etc/NOTICE.html)
-# Remove generated java files after CL 126153
-$(call add-clean-step, find $(OUT_DIR) -type f -name "*.java" -print0 | xargs -0 rm -f)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/product/sapphire/obj/SHARED_LIBRARIES/libhardware_legacy_intermediates/led)
-$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/bin/mountd)
-$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/etc/mountd.conf)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/Browser_intermediates)
-$(call add-clean-step, rm -f vendor/google/apps/Talk/res/drawable/%*)
-$(call add-clean-step, rm -rf $(OUT_DIR)/product/*/obj/SHARED_LIBRARIES/libandroid_runtime_intermediates/android_os_NetStat.o)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/product/*/obj/SHARED_LIBRARIES/libjni_andpyime_intermediates)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/product/*/obj/SHARED_LIBRARIES/share)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/product/*/obj/SHARED_LIBRARIES/libwebcore_intermediates)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/PinyinIME_intermediates)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/com.android.inputmethod.pinyin.lib_intermediates)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/PinyinIMEGoogleService_intermediates)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/com.android.inputmethod.pinyin.lib_intermediates)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/PinyinIMEGoogleService_intermediates)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/telephony)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/product/*/obj)
-$(call add-clean-step, rm -f $(PRODUCT_OUT)/system/bin/tcpdump)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/location)
-
-$(call add-clean-step, rm -rf $(OUT_DIR)/product/*/obj/SHARED_LIBRARIES/lib?camera_intermediates)
-$(call add-clean-step, rm -rf $(OUT_DIR)/product/*/obj/STATIC_LIBRARIES/lib?camera_intermediates)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/product/*/obj/SHARED_LIBRARIES/libwebcore_intermediates)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates)
-$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/media/audio/ringtones/Silence.ogg)
-$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/media/audio/ringtones/notifications/Silence.ogg)
# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************
diff --git a/core/Makefile b/core/Makefile
index 9247c75..46f5311 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -118,6 +118,7 @@
PRODUCT_BRAND="$(PRODUCT_BRAND)" \
PRODUCT_DEFAULT_LANGUAGE="$(call default-locale-language,$(PRODUCT_LOCALES))" \
PRODUCT_DEFAULT_REGION="$(call default-locale-region,$(PRODUCT_LOCALES))" \
+ PRODUCT_DEFAULT_WIFI_CHANNELS="$(PRODUCT_DEFAULT_WIFI_CHANNELS)" \
PRODUCT_MODEL="$(PRODUCT_MODEL)" \
PRODUCT_MANUFACTURER="$(PRODUCT_MANUFACTURER)" \
PRIVATE_BUILD_DESC="$(PRIVATE_BUILD_DESC)" \
@@ -132,6 +133,7 @@
BUILD_FINGERPRINT="$(BUILD_FINGERPRINT)" \
TARGET_BOARD_PLATFORM="$(TARGET_BOARD_PLATFORM)" \
TARGET_CPU_ABI="$(TARGET_CPU_ABI)" \
+ TARGET_CPU_ABI2="$(TARGET_CPU_ABI2)" \
bash $(BUILDINFO_SH) > $@
$(hide) if [ -f $(TARGET_DEVICE_DIR)/system.prop ]; then \
cat $(TARGET_DEVICE_DIR)/system.prop >> $@; \
@@ -299,7 +301,7 @@
$(INSTALLED_BOOTIMAGE_TARGET): $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_FILES)
$(call pretty,"Target boot image: $@")
$(hide) $(MKBOOTIMG) $(INTERNAL_BOOTIMAGE_ARGS) --output $@
- $(hide) $(call assert-max-file-size,$@,$(BOARD_BOOTIMAGE_MAX_SIZE))
+ $(hide) $(call assert-max-image-size,$@,$(BOARD_BOOTIMAGE_PARTITION_SIZE),raw)
endif # TARGET_BOOTIMAGE_USE_EXT2
else # TARGET_NO_KERNEL
@@ -501,7 +503,7 @@
# Recovery image
# If neither TARGET_NO_KERNEL nor TARGET_NO_RECOVERY are true
-ifeq (,$(filter true, $(TARGET_NO_KERNEL) $(TARGET_NO_RECOVERY)))
+ifeq (,$(filter true, $(TARGET_NO_KERNEL) $(TARGET_NO_RECOVERY) $(BUILD_TINY_ANDROID)))
INSTALLED_RECOVERYIMAGE_TARGET := $(PRODUCT_OUT)/recovery.img
@@ -577,7 +579,7 @@
$(MKBOOTFS) $(TARGET_RECOVERY_ROOT_OUT) | $(MINIGZIP) > $(recovery_ramdisk)
$(MKBOOTIMG) $(INTERNAL_RECOVERYIMAGE_ARGS) --output $@
@echo ----- Made recovery image -------- $@
- $(hide) $(call assert-max-file-size,$@,$(BOARD_RECOVERYIMAGE_MAX_SIZE))
+ $(hide) $(call assert-max-image-size,$@,$(BOARD_RECOVERYIMAGE_PARTITION_SIZE),raw)
else
INSTALLED_RECOVERYIMAGE_TARGET :=
@@ -662,7 +664,7 @@
$(INSTALLED_SYSTEMIMAGE): $(BUILT_SYSTEMIMAGE) $(RECOVERY_FROM_BOOT_PATCH) | $(ACP)
@echo "Install system fs image: $@"
$(copy-file-to-target)
- $(hide) $(call assert-max-file-size,$@ $(RECOVERY_FROM_BOOT_PATCH),$(BOARD_SYSTEMIMAGE_MAX_SIZE))
+ $(hide) $(call assert-max-image-size,$@ $(RECOVERY_FROM_BOOT_PATCH),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE),yaffs)
systemimage: $(INSTALLED_SYSTEMIMAGE)
@@ -671,7 +673,7 @@
| $(INTERNAL_MKUSERFS)
@echo "make $@: ignoring dependencies"
$(call build-systemimage-target,$(INSTALLED_SYSTEMIMAGE))
- $(hide) $(call assert-max-file-size,$(INSTALLED_SYSTEMIMAGE),$(BOARD_SYSTEMIMAGE_MAX_SIZE))
+ $(hide) $(call assert-max-image-size,$(INSTALLED_SYSTEMIMAGE),$(BOARD_SYSTEMIMAGE_PARTITION_SIZE),yaffs)
#######
## system tarball
@@ -708,7 +710,7 @@
$(call pretty,"Target userdata fs image: $(INSTALLED_USERDATAIMAGE_TARGET)")
@mkdir -p $(TARGET_OUT_DATA)
$(call build-userimage-ext2-target,$(TARGET_OUT_DATA),$(INSTALLED_USERDATAIMAGE_TARGET),userdata,)
- $(hide) $(call assert-max-file-size,$(INSTALLED_USERDATAIMAGE_TARGET),$(BOARD_USERDATAIMAGE_MAX_SIZE))
+ $(hide) $(call assert-max-image-size,$(INSTALLED_USERDATAIMAGE_TARGET),$(BOARD_USERDATAIMAGE_PARTITION_SIZE),yaffs)
endef
else # TARGET_USERIMAGES_USE_EXT2 != true
@@ -718,7 +720,7 @@
$(call pretty,"Target userdata fs image: $(INSTALLED_USERDATAIMAGE_TARGET)")
@mkdir -p $(TARGET_OUT_DATA)
$(hide) $(MKYAFFS2) -f $(TARGET_OUT_DATA) $(INSTALLED_USERDATAIMAGE_TARGET)
- $(hide) $(call assert-max-file-size,$(INSTALLED_USERDATAIMAGE_TARGET),$(BOARD_USERDATAIMAGE_MAX_SIZE))
+ $(hide) $(call assert-max-image-size,$(INSTALLED_USERDATAIMAGE_TARGET),$(BOARD_USERDATAIMAGE_PARTITION_SIZE),yaffs)
endef
endif # TARGET_USERIMAGES_USE_EXT2
@@ -813,6 +815,13 @@
$(BUILT_TARGET_FILES_PACKAGE): PRIVATE_RECOVERY_API_VERSION := $(RECOVERY_API_VERSION)
+ifeq ($(TARGET_RELEASETOOLS_EXTENSIONS),)
+# default to common dir for device vendor
+$(BUILT_TARGET_FILES_PACKAGE): tool_extensions := $(TARGET_DEVICE_DIR)/../common
+else
+$(BUILT_TARGET_FILES_PACKAGE): tool_extensions := $(TARGET_RELEASETOOLS_EXTENSIONS)
+endif
+
# Depending on the various images guarantees that the underlying
# directories are up-to-date.
$(BUILT_TARGET_FILES_PACKAGE): \
@@ -842,6 +851,9 @@
ifdef BOARD_KERNEL_CMDLINE
$(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/RECOVERY/cmdline
endif
+ifdef BOARD_KERNEL_BASE
+ $(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/RECOVERY/base
+endif
@# Components of the boot image
$(hide) mkdir -p $(zip_root)/BOOT
$(hide) $(call package_files-copy-root, \
@@ -856,11 +868,12 @@
ifdef BOARD_KERNEL_CMDLINE
$(hide) echo "$(BOARD_KERNEL_CMDLINE)" > $(zip_root)/BOOT/cmdline
endif
-ifdef INSTALLED_RADIOIMAGE_TARGET
- @# The radio image
- $(hide) mkdir -p $(zip_root)/RADIO
- $(hide) $(ACP) $(INSTALLED_RADIOIMAGE_TARGET) $(zip_root)/RADIO/image
+ifdef BOARD_KERNEL_BASE
+ $(hide) echo "$(BOARD_KERNEL_BASE)" > $(zip_root)/BOOT/base
endif
+ $(hide) $(foreach t,$(INSTALLED_RADIOIMAGE_TARGET),\
+ mkdir -p $(zip_root)/RADIO; \
+ $(ACP) $(t) $(zip_root)/RADIO/$(notdir $(t));)
@# Contents of the system image
$(hide) $(call package_files-copy-root, \
$(SYSTEMIMAGE_SOURCE_DIR),$(zip_root)/SYSTEM)
@@ -878,10 +891,11 @@
$(hide) echo "$(PRODUCT_OTA_PUBLIC_KEYS)" > $(zip_root)/META/otakeys.txt
$(hide) echo "$(PRIVATE_RECOVERY_API_VERSION)" > $(zip_root)/META/recovery-api-version.txt
$(hide) echo "blocksize $(BOARD_FLASH_BLOCK_SIZE)" > $(zip_root)/META/imagesizes.txt
- $(hide) echo "boot $(BOARD_BOOTIMAGE_MAX_SIZE)" >> $(zip_root)/META/imagesizes.txt
- $(hide) echo "recovery $(BOARD_RECOVERYIMAGE_MAX_SIZE)" >> $(zip_root)/META/imagesizes.txt
- $(hide) echo "system $(BOARD_SYSTEMIMAGE_MAX_SIZE)" >> $(zip_root)/META/imagesizes.txt
- $(hide) echo "userdata $(BOARD_USERDATAIMAGE_MAX_SIZE)" >> $(zip_root)/META/imagesizes.txt
+ $(hide) echo "boot $(call image-size-from-data-size,$(BOARD_BOOTIMAGE_PARTITION_SIZE))" >> $(zip_root)/META/imagesizes.txt
+ $(hide) echo "recovery $(call image-size-from-data-size,$(BOARD_RECOVERYIMAGE_PARTITION_SIZE))" >> $(zip_root)/META/imagesizes.txt
+ $(hide) echo "system $(call image-size-from-data-size,$(BOARD_SYSTEMIMAGE_PARTITION_SIZE))" >> $(zip_root)/META/imagesizes.txt
+ $(hide) echo "userdata $(call image-size-from-data-size,$(BOARD_USERDATAIMAGE_PARTITION_SIZE))" >> $(zip_root)/META/imagesizes.txt
+ $(hide) echo "$(tool_extensions)" > $(zip_root)/META/tool-extensions.txt
@# Zip everything up, preserving symlinks
$(hide) (cd $(zip_root) && zip -qry ../$(notdir $@) .)
@@ -893,6 +907,7 @@
ifneq ($(TARGET_SIMULATOR),true)
ifneq ($(TARGET_PRODUCT),sdk)
ifneq ($(TARGET_PRODUCT),generic)
+ifneq ($(TARGET_PRODUCT),aosp_emulator_us)
name := $(TARGET_PRODUCT)
ifeq ($(TARGET_BUILD_TYPE),debug)
@@ -904,9 +919,17 @@
$(INTERNAL_OTA_PACKAGE_TARGET): KEY_CERT_PAIR := $(DEFAULT_KEY_CERT_PAIR)
+ifeq ($(TARGET_OTA_SCRIPT_MODE),)
+# default to "auto"
+$(INTERNAL_OTA_PACKAGE_TARGET): scriptmode := auto
+else
+$(INTERNAL_OTA_PACKAGE_TARGET): scriptmode := $(TARGET_OTA_SCRIPT_MODE)
+endif
+
$(INTERNAL_OTA_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) otatools
@echo "Package OTA: $@"
$(hide) ./build/tools/releasetools/ota_from_target_files \
+ -m $(scriptmode) \
-p $(HOST_OUT) \
-k $(KEY_CERT_PAIR) \
$(BUILT_TARGET_FILES_PACKAGE) $@
@@ -914,6 +937,7 @@
.PHONY: otapackage
otapackage: $(INTERNAL_OTA_PACKAGE_TARGET)
+endif # TARGET_PRODUCT != aosp_emulator_us
endif # TARGET_PRODUCT != generic
endif # TARGET_PRODUCT != sdk
endif # TARGET_SIMULATOR != true
@@ -1030,9 +1054,17 @@
INTERNAL_UPDATE_PACKAGE_TARGET := $(PRODUCT_OUT)/$(name).zip
+ifeq ($(TARGET_RELEASETOOLS_EXTENSIONS),)
+# default to common dir for device vendor
+$(INTERNAL_UPDATE_PACKAGE_TARGET): extensions := $(TARGET_DEVICE_DIR)/../common
+else
+$(INTERNAL_UPDATE_PACKAGE_TARGET): extensions := $(TARGET_RELEASETOOLS_EXTENSIONS)
+endif
+
$(INTERNAL_UPDATE_PACKAGE_TARGET): $(BUILT_TARGET_FILES_PACKAGE) otatools
@echo "Package: $@"
$(hide) ./build/tools/releasetools/img_from_target_files \
+ -s $(extensions) \
-p $(HOST_OUT) \
$(BUILT_TARGET_FILES_PACKAGE) $@
@@ -1168,7 +1200,7 @@
$(PRIVATE_DIR)/platforms/android-$(PLATFORM_VERSION)/images/NOTICE.txt && \
cp -f $(tools_notice_file_txt) $(PRIVATE_DIR)/tools/NOTICE.txt && \
HOST_OUT_EXECUTABLES=$(HOST_OUT_EXECUTABLES) HOST_OS=$(HOST_OS) \
- development/tools/scripts/sdk_clean.sh $(PRIVATE_DIR) && \
+ development/build/tools/sdk_clean.sh $(PRIVATE_DIR) && \
chmod -R ug+rwX $(PRIVATE_DIR) && \
cd $(dir $@) && zip -rq $(notdir $@) $(PRIVATE_NAME) \
) || ( rm -rf $(PRIVATE_DIR) $@ && exit 44 )
diff --git a/core/base_rules.mk b/core/base_rules.mk
index a6bf504..64b74e7 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -272,8 +272,10 @@
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAVA_SOURCES := $(all_java_sources)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_JAVA_OBJECTS := $(patsubst %.java,%.class,$(LOCAL_SRC_FILES))
ifeq ($(my_prefix),TARGET_)
+ifeq ($(LOCAL_SDK_VERSION),)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_BOOTCLASSPATH := -bootclasspath $(call java-lib-files,core)
endif
+endif
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RESOURCE_DIR := $(LOCAL_RESOURCE_DIR)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EXTRA_JAR_ARGS := $(extra_jar_args)
$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASSET_DIR := $(LOCAL_ASSET_DIR)
@@ -350,7 +352,6 @@
$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_POST_PROCESS_COMMAND:= $(LOCAL_POST_PROCESS_COMMAND)
$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_AAPT_FLAGS:= $(LOCAL_AAPT_FLAGS)
$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_JAVA_LIBRARIES:= $(LOCAL_JAVA_LIBRARIES)
-#TODO: add this: $(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_ADDITIONAL_DEPENDENCIES:= $(LOCAL_ADDITIONAL_DEPENDENCIES)
$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_ALL_JAVA_LIBRARIES:= $(full_java_libs)
$(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_IS_HOST_MODULE := $(LOCAL_IS_HOST_MODULE)
diff --git a/core/binary.mk b/core/binary.mk
index ddcdc6f..4413d47 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -87,7 +87,7 @@
ifneq ($(strip $(yacc_cpps)),)
$(yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
$(TOPDIR)$(LOCAL_PATH)/%.y \
- $(lex_cpps) $(PRIVATE_ADDITIONAL_DEPENDENCIES)
+ $(lex_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
$(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION))
$(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
@@ -115,7 +115,7 @@
$(lex_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
$(lex_objects): $(intermediates)/%.o: \
$(intermediates)/%$(LOCAL_CPP_EXTENSION) \
- $(PRIVATE_ADDITIONAL_DEPENDENCIES) \
+ $(LOCAL_ADDITIONAL_DEPENDENCIES) \
$(yacc_headers)
$(transform-$(PRIVATE_HOST)cpp-to-o)
endif
@@ -142,7 +142,7 @@
ifneq ($(strip $(cpp_objects)),)
$(cpp_objects): $(intermediates)/%.o: \
$(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \
- $(yacc_cpps) $(PRIVATE_ADDITIONAL_DEPENDENCIES)
+ $(yacc_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
$(transform-$(PRIVATE_HOST)cpp-to-o)
-include $(cpp_objects:%.o=%.P)
endif
@@ -159,7 +159,7 @@
# TODO: support compiling certain generated files as arm.
$(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
$(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
-$(gen_cpp_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) $(PRIVATE_ADDITIONAL_DEPENDENCIES)
+$(gen_cpp_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
$(transform-$(PRIVATE_HOST)cpp-to-o)
-include $(gen_cpp_objects:%.o=%.P)
endif
@@ -172,7 +172,7 @@
gen_S_objects := $(gen_S_sources:%.S=%.o)
ifneq ($(strip $(gen_S_sources)),)
-$(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S $(PRIVATE_ADDITIONAL_DEPENDENCIES)
+$(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S $(LOCAL_ADDITIONAL_DEPENDENCIES)
$(transform-$(PRIVATE_HOST)s-to-o)
-include $(gen_S_objects:%.o=%.P)
endif
@@ -181,7 +181,7 @@
gen_s_objects := $(gen_s_sources:%.s=%.o)
ifneq ($(strip $(gen_s_objects)),)
-$(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s $(PRIVATE_ADDITIONAL_DEPENDENCIES)
+$(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s $(LOCAL_ADDITIONAL_DEPENDENCIES)
$(transform-$(PRIVATE_HOST)s-to-o-no-deps)
-include $(gen_s_objects:%.o=%.P)
endif
@@ -206,12 +206,29 @@
c_objects := $(c_arm_objects) $(c_normal_objects)
ifneq ($(strip $(c_objects)),)
-$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(PRIVATE_ADDITIONAL_DEPENDENCIES)
+$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
$(transform-$(PRIVATE_HOST)c-to-o)
-include $(c_objects:%.o=%.P)
endif
###########################################################
+## C: Compile generated .c files to .o.
+###########################################################
+
+gen_c_sources := $(filter %.c,$(LOCAL_GENERATED_SOURCES))
+gen_c_objects := $(gen_c_sources:%.c=%.o)
+
+ifneq ($(strip $(gen_c_objects)),)
+# Compile all generated files as thumb.
+# TODO: support compiling certain generated files as arm.
+$(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
+$(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
+$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
+ $(transform-$(PRIVATE_HOST)c-to-o)
+-include $(gen_c_objects:%.o=%.P)
+endif
+
+###########################################################
## ObjC: Compile .m files to .o
###########################################################
@@ -232,7 +249,7 @@
asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o))
ifneq ($(strip $(asm_objects_S)),)
-$(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S $(PRIVATE_ADDITIONAL_DEPENDENCIES)
+$(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S $(LOCAL_ADDITIONAL_DEPENDENCIES)
$(transform-$(PRIVATE_HOST)s-to-o)
-include $(asm_objects_S:%.o=%.P)
endif
@@ -241,7 +258,7 @@
asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o))
ifneq ($(strip $(asm_objects_s)),)
-$(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s $(PRIVATE_ADDITIONAL_DEPENDENCIES)
+$(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s $(LOCAL_ADDITIONAL_DEPENDENCIES)
$(transform-$(PRIVATE_HOST)s-to-o-no-deps)
-include $(asm_objects_s:%.o=%.P)
endif
@@ -261,6 +278,7 @@
$(gen_cpp_objects) \
$(gen_asm_objects) \
$(c_objects) \
+ $(gen_c_objects) \
$(yacc_objects) \
$(lex_objects) \
$(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES))
diff --git a/core/build_id.mk b/core/build_id.mk
index 060c9b5..4661aea 100644
--- a/core/build_id.mk
+++ b/core/build_id.mk
@@ -23,7 +23,7 @@
# (like "TC1-RC5"). It must be a single word, and is
# capitalized by convention.
#
-BUILD_ID := Donut
+BUILD_ID := ECLAIR
# DISPLAY_BUILD_NUMBER should only be set for development branches,
# If set, the BUILD_NUMBER (cl) is appended to the BUILD_ID for
diff --git a/core/clear_vars.mk b/core/clear_vars.mk
index 031bc0b..a7eba3f 100644
--- a/core/clear_vars.mk
+++ b/core/clear_vars.mk
@@ -47,6 +47,7 @@
LOCAL_PREBUILT_EXECUTABLES:=
LOCAL_PREBUILT_JAVA_LIBRARIES:=
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES:=
+LOCAL_PREBUILT_STRIP_COMMENTS:=
LOCAL_INTERMEDIATE_SOURCES:=
LOCAL_JAVA_LIBRARIES:=
LOCAL_NO_STANDARD_LIBRARIES:=
@@ -86,6 +87,8 @@
LOCAL_SDK_VERSION:=
LOCAL_NO_EMMA_INSTRUMENT:=
LOCAL_NO_EMMA_COMPILE:=
+LOCAL_PROGUARD_ENABLED:= # '',optonly,full,custom
+LOCAL_PROGUARD_FLAGS:=
# Trim MAKEFILE_LIST so that $(call my-dir) doesn't need to
# iterate over thousands of entries every time.
diff --git a/core/combo/arch/arm/armv4t.mk b/core/combo/arch/arm/armv4t.mk
new file mode 100644
index 0000000..abc8fa2
--- /dev/null
+++ b/core/combo/arch/arm/armv4t.mk
@@ -0,0 +1,23 @@
+# Configuration for Linux on ARM.
+# Generating binaries for the ARMv4T architecture and higher
+#
+# Supporting armv4 (without thumb) does not make much sense since
+# it's mostly an obsoleted instruction set architecture (only available
+# in StrongArm and arm8). Supporting armv4 will require a lot of conditional
+# code in assembler source since the bx (branch and exchange) instruction is
+# not supported.
+#
+$(warning ARMv4t support is currently a work in progress. It does not work right now!)
+ARCH_ARM_HAVE_THUMB_SUPPORT := false
+ARCH_ARM_HAVE_THUMB_INTERWORKING := false
+ARCH_ARM_HAVE_64BIT_DATA := false
+ARCH_ARM_HAVE_HALFWORD_MULTIPLY := false
+ARCH_ARM_HAVE_CLZ := false
+ARCH_ARM_HAVE_FFS := false
+
+DEFAULT_TARGET_CPU := arm920t
+
+# Note: Hard coding the 'tune' value here is probably not ideal,
+# and a better solution should be found in the future.
+#
+arch_variant_cflags := -march=armv4t -mtune=arm920t -D__ARM_ARCH_4T__
diff --git a/core/combo/arch/arm/armv5te-vfp.mk b/core/combo/arch/arm/armv5te-vfp.mk
new file mode 100644
index 0000000..75299ac
--- /dev/null
+++ b/core/combo/arch/arm/armv5te-vfp.mk
@@ -0,0 +1,7 @@
+# At the moment, use the same settings than the one
+# for armv5te, since TARGET_ARCH_VARIANT := armv5te-vfp
+# will only be used to select an optimized VFP-capable assembly
+# interpreter loop for Dalvik.
+#
+include $(BUILD_COMBOS)/arch/arm/armv5te.mk
+
diff --git a/core/combo/arch/arm/armv5te.mk b/core/combo/arch/arm/armv5te.mk
new file mode 100644
index 0000000..29aada6
--- /dev/null
+++ b/core/combo/arch/arm/armv5te.mk
@@ -0,0 +1,21 @@
+# Configuration for Linux on ARM.
+# Generating binaries for the ARMv5TE architecture and higher
+#
+ARCH_ARM_HAVE_THUMB_SUPPORT := true
+ARCH_ARM_HAVE_FAST_INTERWORKING := true
+ARCH_ARM_HAVE_64BIT_DATA := true
+ARCH_ARM_HAVE_HALFWORD_MULTIPLY := true
+ARCH_ARM_HAVE_CLZ := true
+ARCH_ARM_HAVE_FFS := true
+
+# Note: Hard coding the 'tune' value here is probably not ideal,
+# and a better solution should be found in the future.
+#
+arch_variant_cflags := \
+ -march=armv5te \
+ -mtune=xscale \
+ -D__ARM_ARCH_5__ \
+ -D__ARM_ARCH_5T__ \
+ -D__ARM_ARCH_5E__ \
+ -D__ARM_ARCH_5TE__
+
diff --git a/core/combo/arch/arm/armv7-a.mk b/core/combo/arch/arm/armv7-a.mk
new file mode 100644
index 0000000..7a3ecc4
--- /dev/null
+++ b/core/combo/arch/arm/armv7-a.mk
@@ -0,0 +1,22 @@
+# Configuration for Linux on ARM.
+# Generating binaries for the ARMv7-a architecture and higher
+#
+ARCH_ARM_HAVE_THUMB_SUPPORT := true
+ARCH_ARM_HAVE_FAST_INTERWORKING := true
+ARCH_ARM_HAVE_64BIT_DATA := true
+ARCH_ARM_HAVE_HALFWORD_MULTIPLY := true
+ARCH_ARM_HAVE_CLZ := true
+ARCH_ARM_HAVE_FFS := true
+ARCH_ARM_HAVE_VFP := true
+ARCH_ARM_HAVE_NEON := true
+
+# Note: Hard coding the 'tune' value here is probably not ideal,
+# and a better solution should be found in the future.
+#
+arch_variant_cflags := \
+ -march=armv7-a \
+ -mfloat-abi=softfp \
+ -mfpu=neon
+
+arch_variant_ldflags := \
+ -Wl,--fix-cortex-a8
\ No newline at end of file
diff --git a/core/combo/linux-arm.mk b/core/combo/linux-arm.mk
index 11a8ac7..6011351 100644
--- a/core/combo/linux-arm.mk
+++ b/core/combo/linux-arm.mk
@@ -1,68 +1,44 @@
# Configuration for Linux on ARM.
# Included by combo/select.make
-# You can set TARGET_ARCH_VERSION to use an arch version other
-# than ARMv5TE
-ifeq ($(strip $(TARGET_ARCH_VERSION)),)
-TARGET_ARCH_VERSION := armv5te
-endif
-
-# This set of if blocks sets makefile variables similar to preprocesser
+# You can set TARGET_ARCH_VARIANT to use an arch version other
+# than ARMv5TE. Each value should correspond to a file named
+# $(BUILD_COMBOS)/arch/<name>.mk which must contain
+# makefile variable definitions similar to the preprocessor
# defines in system/core/include/arch/<combo>/AndroidConfig.h. Their
-# purpose is to allow module Android.mk files to selctively compile
-# different versions of code based upon the funtionality and
+# purpose is to allow module Android.mk files to selectively compile
+# different versions of code based upon the funtionality and
# instructions available in a given architecture version.
#
-# The blocks also define specific arch_version_cflags, which
+# The blocks also define specific arch_variant_cflags, which
# include defines, and compiler settings for the given architecture
# version.
#
-# Note: Hard coding the 'tune' value here is probably not ideal,
-# and a better solution should be found in the future.
-#
-# With two or three different versions this if block approach is
-# fine. If/when this becomes large, please change this to include
-# architecture versions specific Makefiles which define these
-# variables.
-#
-# Supporting armv4 (without thumb) does not make much sense since
-# it's mostly an obsoleted instruction set architecture (only available
-# in StrongArm and arm8). Supporting armv4 will require a lot of conditional
-# code in assembler source since the bx (branch and exchange) instruction is
-# not supported.
-#
-ifeq ($(TARGET_ARCH_VERSION),armv5te)
-ARCH_ARM_HAVE_THUMB_SUPPORT := true
-ARCH_ARM_HAVE_FAST_INTERWORKING := true
-ARCH_ARM_HAVE_64BIT_DATA := true
-ARCH_ARM_HAVE_HALFWORD_MULTIPLY := true
-ARCH_ARM_HAVE_CLZ := true
-ARCH_ARM_HAVE_FFS := true
-
-arch_version_cflags := -march=armv5te -mtune=xscale -D__ARM_ARCH_5__ \
- -D__ARM_ARCH_5T__ -D__ARM_ARCH_5TE__
-else
-ifeq ($(TARGET_ARCH_VERSION),armv4t)
-$(warning ARMv4t support is currently a work in progress. It does not work right now!)
-ARCH_ARM_HAVE_THUMB_SUPPORT := false
-ARCH_ARM_HAVE_THUMB_INTERWORKING := false
-ARCH_ARM_HAVE_64BIT_DATA := false
-ARCH_ARM_HAVE_HALFWORD_MULTIPLY := false
-ARCH_ARM_HAVE_CLZ := false
-ARCH_ARM_HAVE_FFS := false
-
-DEFAULT_TARGET_CPU := arm920t
-
-arch_version_cflags := -march=armv4t -mtune=arm920t -D__ARM_ARCH_4T__
-else
-$(error Unknown ARM architecture version: $(TARGET_ARCH_VERSION))
+ifeq ($(strip $(TARGET_ARCH_VARIANT)),)
+TARGET_ARCH_VARIANT := armv5te
endif
+
+# TARGET_ARCH_VARIANT used to be called TARGET_ARCH_VERSION
+# to avoid any weirdness, issue an error message if the latter
+# is defined.
+#
+ifneq ($(strip $(TARGET_ARCH_VERSION)),)
+$(info Definition for TARGET_ARCH_VERSION encountered !)
+$(info This variable has been renamed TARGET_ARCH_VARIANT, please update your build files !!)
+$(error Aborting the build.)
endif
+TARGET_ARCH_SPECIFIC_MAKEFILE := $(BUILD_COMBOS)/arch/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT).mk
+ifeq ($(strip $(wildcard $(TARGET_ARCH_SPECIFIC_MAKEFILE))),)
+$(error Unknown ARM architecture version: $(TARGET_ARCH_VARIANT))
+endif
+
+include $(TARGET_ARCH_SPECIFIC_MAKEFILE)
+
# You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
ifeq ($(strip $($(combo_target)TOOLS_PREFIX)),)
$(combo_target)TOOLS_PREFIX := \
- prebuilt/$(HOST_PREBUILT_TAG)/toolchain/arm-eabi-4.2.1/bin/arm-eabi-
+ prebuilt/$(HOST_PREBUILT_TAG)/toolchain/arm-eabi-4.4.0/bin/arm-eabi-
endif
$(combo_target)CC := $($(combo_target)TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)
@@ -79,7 +55,7 @@
-funswitch-loops \
-finline-limit=300
-# Modules can choose to compile some source as thumb. As
+# Modules can choose to compile some source as thumb. As
# non-thumb enabled targets are supported, this is treated
# as a 'hint'. If thumb is not enabled, these files are just
# compiled as ARM.
@@ -103,7 +79,7 @@
# with -mlong-calls. When built at -O0, those libraries are
# too big for a thumb "BL <label>" to go from one end to the other.
ifeq ($(FORCE_ARM_DEBUGGING),true)
- TARGET_arm_CFLAGS += -fno-omit-frame-pointer
+ TARGET_arm_CFLAGS += -fno-omit-frame-pointer -fno-strict-aliasing
TARGET_thumb_CFLAGS += -marm -fno-omit-frame-pointer
endif
@@ -116,10 +92,13 @@
-funwind-tables \
-fstack-protector \
-fno-short-enums \
- $(arch_version_cflags) \
+ $(arch_variant_cflags) \
-include $(android_config_h) \
-I $(arch_include_dir)
+$(combo_target)GLOBAL_LDFLAGS += \
+ $(arch_variant_ldflags)
+
# We only need thumb interworking in cases where thumb support
# is available in the architecture, and just to be sure, (and
# since sometimes thumb-interwork appears to be default), we
@@ -150,7 +129,7 @@
## on some hosts, the target cross-compiler is not available so do not run this command
ifneq ($(wildcard $($(combo_target)CC)),)
-# We compile with the global cflags to ensure that
+# We compile with the global cflags to ensure that
# any flags which affect libgcc are correctly taken
# into account.
$(combo_target)LIBGCC := $(shell $($(combo_target)CC) $($(combo_target)GLOBAL_CFLAGS) -print-libgcc-file-name)
@@ -201,6 +180,7 @@
$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
-o $@ \
$(PRIVATE_LDFLAGS) \
+ $(TARGET_GLOBAL_LDFLAGS) \
$(TARGET_LIBGCC)
endef
@@ -217,6 +197,7 @@
$(PRIVATE_ALL_OBJECTS) \
$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
$(PRIVATE_LDFLAGS) \
+ $(TARGET_GLOBAL_LDFLAGS) \
$(TARGET_LIBGCC) \
$(TARGET_CRTEND_O)
endef
@@ -228,6 +209,7 @@
$(TARGET_GLOBAL_LD_DIRS) \
$(TARGET_CRTBEGIN_STATIC_O) \
$(PRIVATE_LDFLAGS) \
+ $(TARGET_GLOBAL_LDFLAGS) \
$(PRIVATE_ALL_OBJECTS) \
$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
$(TARGET_LIBGCC) \
diff --git a/core/combo/linux-sh.mk b/core/combo/linux-sh.mk
new file mode 100644
index 0000000..79cf49d
--- /dev/null
+++ b/core/combo/linux-sh.mk
@@ -0,0 +1,148 @@
+# Configuration for Linux on SuperH.
+# Included by combo/select.make
+
+# You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
+ifeq ($(strip $($(combo_target)TOOLS_PREFIX)),)
+$(combo_target)TOOLS_PREFIX := \
+ prebuilt/$(HOST_PREBUILT_TAG)/toolchain/sh-4.3.3/bin/sh-linux-gnu-
+endif
+
+$(combo_target)CC := $($(combo_target)TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)
+$(combo_target)CXX := $($(combo_target)TOOLS_PREFIX)c++$(HOST_EXECUTABLE_SUFFIX)
+$(combo_target)AR := $($(combo_target)TOOLS_PREFIX)ar$(HOST_EXECUTABLE_SUFFIX)
+$(combo_target)OBJCOPY := $($(combo_target)TOOLS_PREFIX)objcopy$(HOST_EXECUTABLE_SUFFIX)
+$(combo_target)LD := $($(combo_target)TOOLS_PREFIX)ld$(HOST_EXECUTABLE_SUFFIX)
+
+$(combo_target)NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
+
+TARGET_sh_release_CFLAGS := -O2 \
+ -fomit-frame-pointer \
+ -fstrict-aliasing \
+ -funswitch-loops \
+ -finline-limit=300
+
+# When building for debug, compile everything as superh.
+TARGET_sh_debug_CFLAGS := $(TARGET_sh_release_CFLAGS) -fno-omit-frame-pointer -fno-strict-aliasing
+
+$(combo_target)GLOBAL_CFLAGS += \
+ -fpic \
+ -ffunction-sections \
+ -funwind-tables \
+ -fstack-protector \
+ -include $(call select-android-config-h,linux-sh)
+
+$(combo_target)GLOBAL_CPPFLAGS += \
+ -fno-use-cxa-atexit \
+ -fvisibility-inlines-hidden
+
+$(combo_target)RELEASE_CFLAGS := \
+ -DSK_RELEASE -DNDEBUG \
+ -O2 -g \
+ -Wstrict-aliasing=2 \
+ -finline-functions \
+ -fno-inline-functions-called-once \
+ -fgcse-after-reload \
+ -frerun-cse-after-loop \
+ -frename-registers \
+ -fno-builtin
+
+libc_root := bionic/libc
+libm_root := bionic/libm
+libstdc++_root := bionic/libstdc++
+libthread_db_root := bionic/libthread_db
+
+
+## on some hosts, the target cross-compiler is not available so do not run this command
+ifneq ($(wildcard $($(combo_target)CC)),)
+# We compile with the global cflags to ensure that
+# any flags which affect libgcc are correctly taken
+# into account.
+LIBGCC_FILENAME := $(shell $($(combo_target)CC) $($(combo_target)GLOBAL_CFLAGS) -print-libgcc-file-name)
+LIBGCC_EH_FILENAME := $(subst libgcc,libgcc_eh,$(LIBGCC_FILENAME))
+$(combo_target)LIBGCC := $(LIBGCC_EH_FILENAME) $(LIBGCC_FILENAME)
+endif
+
+# unless CUSTOM_KERNEL_HEADERS is defined, we're going to use
+# symlinks located in out/ to point to the appropriate kernel
+# headers. see 'config/kernel_headers.make' for more details
+#
+ifneq ($(CUSTOM_KERNEL_HEADERS),)
+ KERNEL_HEADERS_COMMON := $(CUSTOM_KERNEL_HEADERS)
+ KERNEL_HEADERS_ARCH := $(CUSTOM_KERNEL_HEADERS)
+else
+ KERNEL_HEADERS_COMMON := $(libc_root)/kernel/common
+ KERNEL_HEADERS_ARCH := $(libc_root)/kernel/arch-$(TARGET_ARCH)
+endif
+KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH)
+
+$(combo_target)C_INCLUDES := \
+ $(libc_root)/arch-sh/include \
+ $(libc_root)/include \
+ $(libstdc++_root)/include \
+ $(KERNEL_HEADERS) \
+ $(libm_root)/include \
+ $(libm_root)/include/arch/sh \
+ $(libthread_db_root)/include
+
+TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_static.o
+TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtbegin_dynamic.o
+TARGET_CRTEND_O := $(TARGET_OUT_STATIC_LIBRARIES)/crtend_android.o
+TARGET_SOBEGIN := $(TARGET_OUT_STATIC_LIBRARIES)/sobegin.o
+TARGET_SOEND := $(TARGET_OUT_STATIC_LIBRARIES)/soend.o
+
+TARGET_STRIP_MODULE:=false
+
+$(combo_target)DEFAULT_SYSTEM_SHARED_LIBRARIES := libc libstdc++ libm
+
+$(combo_target)CUSTOM_LD_COMMAND := true
+define transform-o-to-shared-lib-inner
+$(TARGET_CXX) \
+ -nostdlib -Wl,-soname,$(notdir $@) -Wl,-T,$(BUILD_SYSTEM)/shlelf.xsc \
+ -Wl,--gc-sections -Wl,-z,norelro \
+ -Wl,-shared,-Bsymbolic \
+ $(TARGET_GLOBAL_LD_DIRS) \
+ $(TARGET_SOBEGIN) \
+ $(PRIVATE_ALL_OBJECTS) \
+ -Wl,--whole-archive \
+ $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
+ -Wl,--no-whole-archive \
+ $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
+ $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
+ -o $@ \
+ $(PRIVATE_LDFLAGS) \
+ $(subst -lrt,, $(subst -lpthread,,$(PRIVATE_LDLIBS))) \
+ $(TARGET_LIBGCC) \
+ $(TARGET_SOEND)
+endef
+
+define transform-o-to-executable-inner
+$(TARGET_CXX) -nostdlib -Bdynamic -Wl,-T,$(BUILD_SYSTEM)/shlelf.x \
+ -Wl,-dynamic-linker,/system/bin/linker \
+ -Wl,--gc-sections -Wl,-z,norelro \
+ -Wl,-z,nocopyreloc \
+ -o $@ \
+ $(TARGET_GLOBAL_LD_DIRS) \
+ -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
+ $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
+ $(TARGET_CRTBEGIN_DYNAMIC_O) \
+ $(PRIVATE_ALL_OBJECTS) \
+ $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
+ $(PRIVATE_LDFLAGS) \
+ $(TARGET_LIBGCC) \
+ $(subst -lrt,, $(subst -lpthread,,$(PRIVATE_LDLIBS))) \
+ $(TARGET_CRTEND_O)
+endef
+
+define transform-o-to-static-executable-inner
+$(TARGET_CXX) -nostdlib -Bstatic -Wl,-T,$(BUILD_SYSTEM)/shlelf.x \
+ -Wl,--gc-sections -Wl,-z,norelro \
+ -o $@ \
+ $(TARGET_GLOBAL_LD_DIRS) \
+ $(TARGET_CRTBEGIN_STATIC_O) \
+ $(PRIVATE_LDFLAGS) \
+ $(PRIVATE_ALL_OBJECTS) \
+ $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
+ $(TARGET_LIBGCC) \
+ $(subst -lrt,, $(subst -lpthread,,$(PRIVATE_LDLIBS))) \
+ $(TARGET_CRTEND_O)
+endef
diff --git a/core/combo/select.mk b/core/combo/select.mk
index 273b660..793b0a9 100644
--- a/core/combo/select.mk
+++ b/core/combo/select.mk
@@ -39,6 +39,7 @@
# These flags might (will) be overridden by the target makefiles
$(combo_target)GLOBAL_CFLAGS := -fno-exceptions -Wno-multichar
$(combo_target)RELEASE_CFLAGS := -O2 -g -fno-strict-aliasing
+$(combo_target)GLOBAL_LDFLAGS :=
$(combo_target)GLOBAL_ARFLAGS := crs
$(combo_target)EXECUTABLE_SUFFIX :=
diff --git a/core/config.mk b/core/config.mk
index b705de5..4662a38 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -75,11 +75,11 @@
# ###############################################################
# These can be changed to modify both host and device modules.
-COMMON_GLOBAL_CFLAGS:= -DANDROID -fmessage-length=0 -W -Wall -Wno-unused
+COMMON_GLOBAL_CFLAGS:= -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-arith
COMMON_RELEASE_CFLAGS:= -DNDEBUG -UDEBUG
-COMMON_GLOBAL_CPPFLAGS:= -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -Wnon-virtual-dtor
-COMMON_RELEASE_CPPFLAGS:= -DNDEBUG -UDEBUG
+COMMON_GLOBAL_CPPFLAGS:= $(COMMON_GLOBAL_CFLAGS) -Wsign-promo
+COMMON_RELEASE_CPPFLAGS:= $(COMMON_RELEASE_CFLAGS)
# Set the extensions used for various packages
COMMON_PACKAGE_SUFFIX := .zip
@@ -87,7 +87,13 @@
COMMON_ANDROID_PACKAGE_SUFFIX := .apk
# list of flags to turn specific warnings in to errors
-TARGET_ERROR_FLAGS := -Werror=return-type
+TARGET_ERROR_FLAGS := -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point
+
+# TODO: do symbol compression
+TARGET_COMPRESS_MODULE_SYMBOLS := false
+
+# Default is to prelink modules.
+TARGET_PRELINK_MODULE := true
# ###############################################################
# Include sub-configuration files
@@ -105,6 +111,34 @@
# are specific to the user's build configuration.
include $(BUILD_SYSTEM)/envsetup.mk
+# Boards may be defined under $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)
+# or under vendor/*/$(TARGET_DEVICE). Search in both places, but
+# make sure only one exists.
+# Real boards should always be associated with an OEM vendor.
+board_config_mk := \
+ $(strip $(wildcard \
+ $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)/BoardConfig.mk \
+ device/*/$(TARGET_DEVICE)/BoardConfig.mk \
+ vendor/*/$(TARGET_DEVICE)/BoardConfig.mk \
+ ))
+ifeq ($(board_config_mk),)
+ $(error No config file found for TARGET_DEVICE $(TARGET_DEVICE))
+endif
+ifneq ($(words $(board_config_mk)),1)
+ $(error Multiple board config files for TARGET_DEVICE $(TARGET_DEVICE): $(board_config_mk))
+endif
+include $(board_config_mk)
+TARGET_DEVICE_DIR := $(patsubst %/,%,$(dir $(board_config_mk)))
+board_config_mk :=
+
+# Clean up/verify variables defined by the board config file.
+TARGET_BOOTLOADER_BOARD_NAME := $(strip $(TARGET_BOOTLOADER_BOARD_NAME))
+TARGET_CPU_ABI := $(strip $(TARGET_CPU_ABI))
+ifeq ($(TARGET_CPU_ABI),)
+ $(error No TARGET_CPU_ABI defined by board config: $(board_config_mk))
+endif
+TARGET_CPU_ABI2 := $(strip $(TARGET_CPU_ABI2))
+
# $(1): os/arch
define select-android-config-h
system/core/include/arch/$(1)/AndroidConfig.h
@@ -167,6 +201,7 @@
TUNE2FS := tune2fs
E2FSCK := e2fsck
JARJAR := java -jar $(HOST_OUT_JAVA_LIBRARIES)/jarjar.jar
+PROGUARD := external/proguard/bin/proguard.sh
# dx is java behind a shell script; no .exe necessary.
DX := $(HOST_OUT_EXECUTABLES)/dx
@@ -259,10 +294,6 @@
TARGET_GLOBAL_CFLAGS += $(TARGET_RELEASE_CFLAGS)
TARGET_GLOBAL_CPPFLAGS += $(TARGET_RELEASE_CPPFLAGS)
-# TODO: do symbol compression
-TARGET_COMPRESS_MODULE_SYMBOLS := false
-TARGET_PRELINK_MODULE := true
-
PREBUILT_IS_PRESENT := $(if $(wildcard prebuilt/Android.mk),true)
diff --git a/core/definitions.mk b/core/definitions.mk
index c84cbd8..27e38d3 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -109,7 +109,14 @@
# Figure out where we are.
define my-dir
-$(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST),$(MAKEFILE_LIST))))
+$(strip \
+ $(eval md_file_ := $$(lastword $$(MAKEFILE_LIST))) \
+ $(if $(filter $(CLEAR_VARS),$(md_file_)), \
+ $(error LOCAL_PATH must be set before including $$(CLEAR_VARS)) \
+ , \
+ $(patsubst %/,%,$(dir $(md_file_))) \
+ ) \
+ )
endef
###########################################################
@@ -128,7 +135,8 @@
# $(1): directory to search under
# Ignores $(1)/Android.mk
define first-makefiles-under
-$(shell build/tools/findleaves.sh --mindepth=2 $(1) Android.mk)
+$(shell build/tools/findleaves.py --prune=out --prune=.repo --prune=.git \
+ --mindepth=2 $(1) Android.mk)
endef
###########################################################
@@ -1166,6 +1174,7 @@
$(addprefix -S , $(PRIVATE_RESOURCE_DIR)) \
$(addprefix -A , $(PRIVATE_ASSET_DIR)) \
$(addprefix -I , $(PRIVATE_AAPT_INCLUDES)) \
+ $(addprefix -G , $(PRIVATE_PROGUARD_OPTIONS_FILE)) \
$(addprefix --min-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
$(addprefix --target-sdk-version , $(DEFAULT_APP_TARGET_SDK)) \
$(addprefix --version-code , $(PLATFORM_SDK_VERSION)) \
@@ -1264,11 +1273,12 @@
#TODO: use a smaller -Xmx value for most libraries;
# only core.jar and framework.jar need a heap this big.
+# Avoid the memory arguments on Windows, dx fails to load for some reason with them.
define transform-classes.jar-to-dex
@echo "target Dex: $(PRIVATE_MODULE)"
@mkdir -p $(dir $@)
-$(hide) $(DX) -JXms16M \
- -JXmx1536M \
+$(hide) $(DX) \
+ $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx1536M) \
--dex --output=$@ \
$(if $(NO_OPTIMIZE_DX), \
--no-optimize) \
@@ -1314,21 +1324,17 @@
-F $@
endef
-#TODO: Allow library directory to be specified based on the target
-# CPU and ABI instead of being hard coded as armeabi.
define add-jni-shared-libs-to-package
$(hide) rm -rf $(dir $@)lib
-$(hide) mkdir -p $(dir $@)lib/armeabi
-$(hide) cp $(PRIVATE_JNI_SHARED_LIBRARIES) $(dir $@)lib/armeabi
+$(hide) mkdir -p $(dir $@)lib/$(TARGET_CPU_ABI)
+$(hide) cp $(PRIVATE_JNI_SHARED_LIBRARIES) $(dir $@)lib/$(TARGET_CPU_ABI)
$(hide) (cd $(dir $@) && zip -r $(notdir $@) lib)
$(hide) rm -rf $(dir $@)lib
endef
-#TODO: use aapt instead of zip, once it supports junking the path
-# (so adding "xxx/yyy/classes.dex" appears as "classes.dex")
#TODO: update the manifest to point to the dex file
define add-dex-to-package
-$(hide) zip -qj $@ $(PRIVATE_DEX_FILE)
+$(hide) $(AAPT) add -k $@ $(PRIVATE_DEX_FILE)
endef
define add-java-resources-to-package
@@ -1469,6 +1475,19 @@
$(hide) cp -fp $< $@
endef
+# The same as copy-file-to-target, but use the zipalign tool to do so.
+define copy-file-to-target-with-zipalign
+@mkdir -p $(dir $@)
+$(hide) $(ZIPALIGN) -f 4 $< $@
+endef
+
+# The same as copy-file-to-target, but strip out "# comment"-style
+# comments (for config files and such).
+define copy-file-to-target-strip-comments
+@mkdir -p $(dir $@)
+$(hide) sed -e 's/#.*$$//' -e 's/[ \t]*$$//' -e '/^$$/d' < $< > $@
+endef
+
# The same as copy-file-to-target, but don't preserve
# the old modification time.
define copy-file-to-new-target
@@ -1489,6 +1508,18 @@
$(copy-file-to-target)
endef
+# Copy a prebuilt file to a target location, using zipalign on it.
+define transform-prebuilt-to-target-with-zipalign
+@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt APK: $(PRIVATE_MODULE) ($@)"
+$(copy-file-to-target-with-zipalign)
+endef
+
+# Copy a prebuilt file to a target location, stripping "# comment" comments.
+define transform-prebuilt-to-target-strip-comments
+@echo "$(if $(PRIVATE_IS_HOST_MODULE),host,target) Prebuilt: $(PRIVATE_MODULE) ($@)"
+$(copy-file-to-target-strip-comments)
+endef
+
###########################################################
## On some platforms (MacOS), after copying a static
@@ -1547,6 +1578,7 @@
# $(1): The file(s) to check (often $@)
# $(2): The maximum total image size, in decimal bytes
+# $(3): the type of filesystem "yaffs" or "raw"
#
# If $(2) is empty, evaluates to "true"
#
@@ -1560,9 +1592,15 @@
printname=$$(echo -n "$(1)" | tr " " +); \
echo "$$printname total size is $$total"; \
img_blocksize=$(call image-size-from-data-size,$(BOARD_FLASH_BLOCK_SIZE)); \
+ if [ "$(3)" == "yaffs" ]; then \
+ reservedblocks=8; \
+ else \
+ reservedblocks=0; \
+ fi; \
twoblocks=$$((img_blocksize * 2)); \
onepct=$$((((($(2) / 100) - 1) / img_blocksize + 1) * img_blocksize)); \
- reserve=$$((twoblocks > onepct ? twoblocks : onepct)); \
+ reserve=$$(((twoblocks > onepct ? twoblocks : onepct) + \
+ reservedblocks * img_blocksize)); \
maxsize=$$(($(2) - reserve)); \
if [ "$$total" -gt "$$maxsize" ]; then \
echo "error: $$printname too large ($$total > [$(2) - $$reserve])"; \
@@ -1575,6 +1613,37 @@
)
endef
+# Like assert-max-file-size, but the second argument is a partition
+# size, which we'll convert to a max image size before checking it
+# against the files.
+#
+# $(1): The file(s) to check (often $@)
+# $(2): The partition size.
+define assert-max-image-size
+$(if $(2), \
+ $(call assert-max-file-size,$(1),$(call image-size-from-data-size,$(2))), \
+ true)
+endef
+
+
+###########################################################
+## Define device-specific radio files
+###########################################################
+
+# Copy a radio image file to the output location, and add it to
+# INSTALLED_RADIOIMAGE_TARGET.
+# $(1): filename
+define add-radio-file
+ $(eval $(call add-radio-file-internal,$(1)))
+endef
+define add-radio-file-internal
+INSTALLED_RADIOIMAGE_TARGET += $$(PRODUCT_OUT)/$(1)
+ALL_PREBUILT += $$(PRODUCT_OUT)/$(1)
+$$(PRODUCT_OUT)/$(1) : $$(LOCAL_PATH)/$(1) | $$(ACP)
+ $$(transform-prebuilt-to-target)
+endef
+
+
###########################################################
## Other includes
###########################################################
diff --git a/core/envsetup.mk b/core/envsetup.mk
index 31901e9..6d14753 100644
--- a/core/envsetup.mk
+++ b/core/envsetup.mk
@@ -173,7 +173,7 @@
# under product/) are actually host-dependent.
# But, the debug type is controlled by TARGET_BUILD_TYPE and not
# HOST_BUILD_TYPE.
- TARGET_PRODUCT_OUT_ROOT := $(HOST_OUT_$(TARGET_BUILD_TYPE))/product
+ TARGET_PRODUCT_OUT_ROOT := $(HOST_OUT_$(TARGET_BUILD_TYPE))/pr
else
TARGET_PRODUCT_OUT_ROOT := $(TARGET_OUT_ROOT)/product
endif
@@ -270,7 +270,7 @@
ABP:=$(ABP):$(TARGET_OUT_EXECUTABLES)
else
# this should be copied to HOST_OUT_EXECUTABLES instead
- ABP:=$(ABP):$(PWD)/prebuilt/$(HOST_PREBUILT_TAG)/toolchain/arm-eabi-4.2.1/bin
+ ABP:=$(ABP):$(PWD)/prebuilt/$(HOST_PREBUILT_TAG)/toolchain/arm-eabi-4.4.0/bin
endif
ANDROID_BUILD_PATHS := $(ABP)
ANDROID_PREBUILTS := prebuilt/$(HOST_PREBUILT_TAG)
@@ -335,5 +335,3 @@
$(info BUILD_ID=$(BUILD_ID))
$(info ============================================)
endif
-
-
diff --git a/core/java.mk b/core/java.mk
index 658b173..ddb8737 100644
--- a/core/java.mk
+++ b/core/java.mk
@@ -28,6 +28,7 @@
LOCAL_JAVA_LIBRARIES := core ext framework $(LOCAL_JAVA_LIBRARIES)
endif
endif
+LOCAL_JAVA_LIBRARIES := $(sort $(LOCAL_JAVA_LIBRARIES))
LOCAL_BUILT_MODULE_STEM := $(strip $(LOCAL_BUILT_MODULE_STEM))
ifeq ($(LOCAL_BUILT_MODULE_STEM),)
@@ -68,7 +69,8 @@
# the emma tool
full_classes_emma_jar := $(emma_intermediates_dir)/lib/$(full_classes_compiled_jar_leaf)
full_classes_stubs_jar := $(intermediates.COMMON)/stubs.jar
-full_classes_jarjar_jar := $(full_classes_jar)
+full_classes_jarjar_jar := $(intermediates.COMMON)/classes-jarjar.jar
+full_classes_proguard_jar := $(full_classes_jar)
built_dex := $(intermediates.COMMON)/classes.dex
LOCAL_INTERMEDIATE_TARGETS += \
@@ -174,15 +176,14 @@
$(PRIVATE_EMMA_COVERAGE_FILE): $(full_classes_emma_jar)
else
$(full_classes_emma_jar): $(full_classes_compiled_jar) | $(ACP)
- @echo Copying $<
+ @echo Copying: $<
$(copy-file-to-target)
endif
-# Run jarjar if necessary, otherwise just copy the file. This is the last
-# part of this step, so the output of this command is full_classes_jar.
+# Run jarjar if necessary, otherwise just copy the file.
ifneq ($(strip $(LOCAL_JARJAR_RULES)),)
$(full_classes_jarjar_jar): PRIVATE_JARJAR_RULES := $(LOCAL_JARJAR_RULES)
-$(full_classes_jarjar_jar): $(full_classes_emma_jar) | jarjar
+$(full_classes_jarjar_jar): $(full_classes_emma_jar) | $(JARJAR)
@echo JarJar: $@
$(hide) $(JARJAR) process $(PRIVATE_JARJAR_RULES) $< $@
else
@@ -191,6 +192,40 @@
$(hide) $(ACP) $< $@
endif
+# Run proguard if necessary, otherwise just copy the file. This is the last
+# part of this step, so the output of this command is full_classes_jar.
+ifneq ($(strip $(LOCAL_PROGUARD_ENABLED)),)
+proguard_dictionary := $(intermediates.COMMON)/proguard_dictionary
+proguard_flags := $(addprefix -libraryjars ,$(full_java_libs)) \
+ -include $(BUILD_SYSTEM)/proguard.flags \
+ -forceprocessing \
+ -printmapping $(proguard_dictionary)
+ifeq ($(strip $(LOCAL_PROGUARD_ENABLED)),full)
+ # full
+else
+ifeq ($(strip $(LOCAL_PROGUARD_ENABLED)),optonly)
+ # optonly
+ proguard_flags += -dontobfuscate
+else
+ifeq ($(strip $(LOCAL_PROGUARD_ENABLED)),custom)
+ # custom
+else
+ $(warning while processing: $(LOCAL_MODULE))
+ $(error invalid value for LOCAL_PROGUARD_ENABLED: $(LOCAL_PROGUARD_ENABLED))
+endif
+endif
+endif
+
+$(full_classes_proguard_jar): PRIVATE_PROGUARD_FLAGS := $(proguard_flags) $(LOCAL_PROGUARD_FLAGS)
+$(full_classes_proguard_jar): $(full_classes_emma_jar) | $(PROGUARD)
+ @echo Proguard: $@
+ $(hide) $(PROGUARD) -injars $< -outjars $@ $(PRIVATE_PROGUARD_FLAGS)
+else
+$(full_classes_proguard_jar): $(full_classes_emma_jar) | $(ACP)
+ @echo Copying: $@
+ $(hide) $(ACP) $< $@
+endif
+
# Override PRIVATE_INTERMEDIATES_DIR so that install-dex-debug
# will work even when intermediates != intermediates.COMMON.
$(built_dex): PRIVATE_INTERMEDIATES_DIR := $(intermediates.COMMON)
diff --git a/core/main.mk b/core/main.mk
index 71bbc08..5cb160b 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -30,7 +30,7 @@
$(warning ********************************************************************************)
$(warning * You are using version $(MAKE_VERSION) of make.)
$(warning * You must upgrade to version 3.81 or greater.)
-$(warning * see file://$(shell pwd)/docs/development-environment/machine-setup.html)
+$(warning * see http://source.android.com/download)
$(warning ********************************************************************************)
$(error stopping)
endif
@@ -54,6 +54,12 @@
# be generated correctly
include $(BUILD_SYSTEM)/cleanbuild.mk
+VERSION_CHECK_SEQUENCE_NUMBER := 1
+-include $(OUT_DIR)/versions_checked.mk
+ifneq ($(VERSION_CHECK_SEQUENCE_NUMBER),$(VERSIONS_CHECKED))
+
+$(info Checking build tools versions...)
+
ifneq ($(HOST_OS),windows)
ifneq ($(HOST_OS)-$(HOST_ARCH),darwin-ppc)
# check for a case sensitive file system
@@ -123,6 +129,10 @@
endif # windows
+$(shell echo 'VERSIONS_CHECKED := $(VERSION_CHECK_SEQUENCE_NUMBER)' \
+ > $(OUT_DIR)/versions_checked.mk)
+endif
+
# These are the modifier targets that don't do anything themselves, but
# change the behavior of the build.
# (must be defined before including definitions.make)
@@ -220,7 +230,8 @@
tags_to_install := user debug eng
# Don't require the setup wizard on eng builds
ADDITIONAL_BUILD_PROPERTIES := $(filter-out ro.setupwizard.mode=%,\
- $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES)))
+ $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))) \
+ ro.setupwizard.mode=OPTIONAL
endif
## tests ##
@@ -241,8 +252,16 @@
ADDITIONAL_BUILD_PROPERTIES += xmpp.auto-presence=true
ADDITIONAL_BUILD_PROPERTIES += ro.config.nocheckin=yes
else # !sdk
-# Enable sync for non-sdk builds only (sdk builds lack SubscribedFeedsProvider).
-ADDITIONAL_BUILD_PROPERTIES += ro.config.sync=yes
+endif
+
+## precise GC ##
+
+ifneq ($(filter dalvik.gc.type-precise,$(PRODUCT_TAGS)),)
+ # Enabling type-precise GC results in larger optimized DEX files. The
+ # additional storage requirements for ".odex" files can cause /system
+ # to overflow on some devices, so this is configured separately for
+ # each product.
+ ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.dexopt-flags=m=y
endif
# Install an apns-conf.xml file if one's not already being installed.
@@ -253,18 +272,10 @@
$(warning implicitly installing apns-conf_sdk.xml)
endif
endif
-# Install a vold.conf file is one's not already being installed.
-ifeq (,$(filter %:system/etc/vold.conf, $(PRODUCT_COPY_FILES)))
- PRODUCT_COPY_FILES += \
- development/data/etc/vold.conf:system/etc/vold.conf
- ifeq ($(filter eng tests,$(TARGET_BUILD_VARIANT)),)
- $(warning implicitly installing vold.conf)
- endif
-endif
# If we're on an eng or tests build, but not on the sdk, and we have
# a better one, use that instead.
ifneq ($(filter eng tests,$(TARGET_BUILD_VARIANT)),)
- ifdef is_sdk_build
+ ifndef is_sdk_build
apns_to_use := $(wildcard vendor/google/etc/apns-conf.xml)
ifneq ($(strip $(apns_to_use)),)
PRODUCT_COPY_FILES := \
@@ -275,6 +286,7 @@
endif
ADDITIONAL_BUILD_PROPERTIES += net.bt.name=Android
+ADDITIONAL_BUILD_PROPERTIES += ro.config.sync=yes
# enable vm tracing in files for now to help track
# the cause of ANRs in the content process
@@ -325,35 +337,42 @@
# Bring in all modules that need to be built.
ifneq ($(dont_bother),true)
-subdir_makefiles :=
+ifeq ($(HOST_OS)-$(HOST_ARCH),darwin-ppc)
+SDK_ONLY := true
+$(info Building the SDK under darwin-ppc is actually obsolete and unsupported.)
+$(error stop)
+endif
ifeq ($(HOST_OS),windows)
SDK_ONLY := true
endif
-ifeq ($(HOST_OS)-$(HOST_ARCH),darwin-ppc)
-SDK_ONLY := true
-endif
ifeq ($(SDK_ONLY),true)
+# ----- SDK for Windows ------
+# These configure the build targets that are available for the SDK under Windows.
+# The first section defines all the C/C++ tools that can be compiled in C/C++,
+# the second section defines all the Java ones (assuming javac is available.)
+
subdirs := \
prebuilt \
build/libs/host \
+ build/tools/zipalign \
dalvik/dexdump \
dalvik/libdex \
dalvik/tools/dmtracedump \
dalvik/tools/hprof-conv \
- development/emulator/mksdcard \
development/tools/line_endings \
+ development/tools/etc1tool \
+ sdk/emulator/mksdcard \
+ sdk/sdklauncher \
development/host \
external/expat \
external/libpng \
external/qemu \
external/sqlite/dist \
external/zlib \
- frameworks/base/libs/utils \
- frameworks/base/tools/aapt \
- frameworks/base/tools/aidl \
+ frameworks/base \
system/core/adb \
system/core/fastboot \
system/core/libcutils \
@@ -363,28 +382,26 @@
# The following can only be built if "javac" is available.
# This check is used when building parts of the SDK under Cygwin.
ifneq (,$(shell which javac 2>/dev/null))
-$(warning sdk-only: javac available.)
subdirs += \
build/tools/signapk \
- build/tools/zipalign \
dalvik/dx \
dalvik/libcore \
+ sdk/archquery \
+ sdk/androidprefs \
+ sdk/apkbuilder \
+ sdk/jarutils \
+ sdk/layoutlib_api \
+ sdk/layoutlib_utils \
+ sdk/ninepatch \
+ sdk/sdkstats \
+ sdk/sdkmanager \
+ sdk/layoutopt \
development/apps \
- development/tools/archquery \
- development/tools/androidprefs \
- development/tools/apkbuilder \
- development/tools/jarutils \
- development/tools/layoutlib_utils \
- development/tools/ninepatch \
- development/tools/sdkstats \
- development/tools/sdkmanager \
development/tools/mkstubs \
- frameworks/base \
- frameworks/base/tools/layoutlib \
external/googleclient \
packages
else
-$(warning sdk-only: javac not available.)
+$(warning SDK_ONLY: javac not available.)
endif
# Exclude tools/acp when cross-compiling windows under linux
@@ -398,8 +415,6 @@
# TINY_ANDROID is a super-minimal build configuration, handy for board
# bringup and very low level debugging
-INTERNAL_DEFAULT_DOCS_TARGETS :=
-
subdirs := \
bionic \
system/core \
@@ -418,7 +433,6 @@
#
# Typical build; include any Android.mk files we can find.
#
-INTERNAL_DEFAULT_DOCS_TARGETS := offline-sdk-docs
subdirs := $(TOP)
FULL_BUILD := true
@@ -427,41 +441,6 @@
endif # !SDK_ONLY
-# Can't use first-makefiles-under here because
-# --mindepth=2 makes the prunes not work.
-subdir_makefiles += \
- $(shell build/tools/findleaves.sh --prune="./out" $(subdirs) Android.mk)
-
-# Boards may be defined under $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)
-# or under vendor/*/$(TARGET_DEVICE). Search in both places, but
-# make sure only one exists.
-# Real boards should always be associated with an OEM vendor.
-board_config_mk := \
- $(strip $(wildcard \
- $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)/BoardConfig.mk \
- vendor/*/$(TARGET_DEVICE)/BoardConfig.mk \
- ))
-ifeq ($(board_config_mk),)
- $(error No config file found for TARGET_DEVICE $(TARGET_DEVICE))
-endif
-ifneq ($(words $(board_config_mk)),1)
- $(error Multiple board config files for TARGET_DEVICE $(TARGET_DEVICE): $(board_config_mk))
-endif
-include $(board_config_mk)
-TARGET_DEVICE_DIR := $(patsubst %/,%,$(dir $(board_config_mk)))
-board_config_mk :=
-
-# Clean up/verify variables defined by the board config file.
-TARGET_BOOTLOADER_BOARD_NAME := $(strip $(TARGET_BOOTLOADER_BOARD_NAME))
-TARGET_CPU_ABI := $(strip $(TARGET_CPU_ABI))
-ifeq ($(TARGET_CPU_ABI),)
- $(error No TARGET_CPU_ABI defined by board config: $(board_config_mk))
-endif
-
-#
-# Include all of the makefiles in the system
-#
-
ifneq ($(ONE_SHOT_MAKEFILE),)
# We've probably been invoked by the "mm" shell function
# with a subdirectory's makefile.
@@ -473,14 +452,25 @@
# would have been with a normal make.
CUSTOM_MODULES := $(sort $(call get-tagged-modules,$(ALL_MODULE_TAGS),))
FULL_BUILD :=
-INTERNAL_DEFAULT_DOCS_TARGETS :=
# Stub out the notice targets, which probably aren't defined
# when using ONE_SHOT_MAKEFILE.
NOTICE-HOST-%: ;
NOTICE-TARGET-%: ;
-else
+
+else # ONE_SHOT_MAKEFILE
+
+#
+# Include all of the makefiles in the system
+#
+
+# Can't use first-makefiles-under here because
+# --mindepth=2 makes the prunes not work.
+subdir_makefiles := \
+ $(shell build/tools/findleaves.py --prune=out --prune=.repo --prune=.git $(subdirs) Android.mk)
+
include $(subdir_makefiles)
-endif
+endif # ONE_SHOT_MAKEFILE
+
# -------------------------------------------------------------------
# All module makefiles have been included at this point.
# -------------------------------------------------------------------
@@ -681,7 +671,6 @@
$(INSTALLED_BOOTIMAGE_TARGET) \
$(INSTALLED_RECOVERYIMAGE_TARGET) \
$(INSTALLED_USERDATAIMAGE_TARGET) \
- $(INTERNAL_DEFAULT_DOCS_TARGETS) \
$(INSTALLED_FILES_FILE)
# The actual files built by the droidcore target changes depending
diff --git a/core/notice_files.mk b/core/notice_files.mk
index 24295c7..fd76d51 100644
--- a/core/notice_files.mk
+++ b/core/notice_files.mk
@@ -20,12 +20,19 @@
# We can't use xxx_OUT_STATIC_LIBRARIES because it points into
# device-obj or host-obj.
module_installed_filename := \
- $(patsubst $(PRODUCT_OUT)%,%,$($(my_prefix)OUT_SHARED_LIBRARIES))/$(notdir $(LOCAL_BUILT_MODULE))
+ $(patsubst $(PRODUCT_OUT)%,%,$($(my_prefix)OUT_SHARED_LIBRARIES))/$(notdir $(LOCAL_BUILT_MODULE))
else
ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
# Stick the static java libraries with the regular java libraries.
+ module_leaf := $(notdir $(LOCAL_BUILT_MODULE))
+ # javalib.jar is the default name for the build module (and isn't meaningful)
+ # If that's what we have, substitute the module name instead. These files
+ # aren't included on the device, so this name is synthetic anyway.
+ ifeq ($(module_leaf),javalib.jar)
+ module_leaf := $(LOCAL_MODULE).jar
+ endif
module_installed_filename := \
- $(patsubst $(PRODUCT_OUT)%,%,$($(my_prefix)OUT_JAVA_LIBRARIES))/$(notdir $(LOCAL_BUILT_MODULE))
+ $(patsubst $(PRODUCT_OUT)%,%,$($(my_prefix)OUT_JAVA_LIBRARIES))/$(module_leaf)
else
$(error Cannot determine where to install NOTICE file for $(LOCAL_MODULE))
endif # JAVA_LIBRARIES
diff --git a/core/package.mk b/core/package.mk
index 6b09bda..d92a8b8 100644
--- a/core/package.mk
+++ b/core/package.mk
@@ -92,6 +92,7 @@
all_res_assets := $(strip $(all_assets) $(all_resources))
+package_expected_intermediates_COMMON := $(call local-intermediates-dir,COMMON)
# If no assets or resources were found, clear the directory variables so
# we don't try to build them.
ifeq (,$(all_assets))
@@ -104,13 +105,17 @@
# Make sure that R_file_stamp inherits the proper PRIVATE vars.
# If R.stamp moves, be sure to update the framework makefile,
# which has intimate knowledge of its location.
-package_expected_intermediates_COMMON := $(call local-intermediates-dir,COMMON)
R_file_stamp := $(package_expected_intermediates_COMMON)/src/R.stamp
LOCAL_INTERMEDIATE_TARGETS += $(R_file_stamp)
endif
LOCAL_BUILT_MODULE_STEM := package.apk
+proguard_options_file := $(package_expected_intermediates_COMMON)/proguard_options
+ifneq ($(strip $(LOCAL_PROGUARD_ENABLED)),custom)
+ LOCAL_PROGUARD_FLAGS := -include $(proguard_options_file) $(LOCAL_PROGUARD_FLAGS)
+endif
+
# The dex files go in the package, so we don't
# want to install them separately for this module.
old_DONT_INSTALL_DEX_FILES := $(DONT_INSTALL_DEX_FILES)
@@ -143,6 +148,7 @@
$(R_file_stamp): PRIVATE_RESOURCE_PUBLICS_OUTPUT := \
$(intermediates.COMMON)/public_resources.xml
+$(R_file_stamp): PRIVATE_PROGUARD_OPTIONS_FILE := $(proguard_options_file)
$(R_file_stamp): $(all_res_assets) $(full_android_manifest) $(AAPT) | $(ACP)
@echo "target R.java/Manifest.java: $(PRIVATE_MODULE) ($@)"
@rm -f $@
@@ -164,6 +170,8 @@
$(ACP) -fpt $$GENERATED_R_FILE $@ || exit 32; \
done; \
+$(proguard_options_file): $(R_file_stamp)
+
ifdef LOCAL_EXPORT_PACKAGE_RESOURCES
# Put this module's resources into a PRODUCT-agnositc package that
# other packages can use to build their own PRODUCT-agnostic R.java (etc.)
diff --git a/core/pathmap.mk b/core/pathmap.mk
index e281b9d..1ae663d 100644
--- a/core/pathmap.mk
+++ b/core/pathmap.mk
@@ -28,8 +28,8 @@
#
pathmap_INCL := \
bluedroid:system/bluetooth/bluedroid/include \
- bluez-libs:external/bluez/libs/include \
- bluez-utils:external/bluez/utils \
+ bluez:external/bluetooth/bluez \
+ glib:external/bluetooth/glib \
bootloader:bootable/bootloader/legacy/include \
corecg:external/skia/include/core \
dbus:external/dbus \
@@ -76,7 +76,6 @@
$(addsuffix /java, \
core \
graphics \
- im \
location \
media \
opengl \
diff --git a/core/prebuilt.mk b/core/prebuilt.mk
index 2d93162..b2bb07c 100644
--- a/core/prebuilt.mk
+++ b/core/prebuilt.mk
@@ -3,7 +3,7 @@
##
## Additional inputs from base_rules.make:
## None.
-##
+##
###########################################################
ifneq ($(LOCAL_PREBUILT_LIBS),)
@@ -26,8 +26,37 @@
prebuilt_module_is_a_library :=
endif
+PACKAGES.$(LOCAL_MODULE).OVERRIDES := $(strip $(LOCAL_OVERRIDES_PACKAGES))
+
+# Ensure that prebuilt .apks have been aligned.
+ifneq ($(filter APPS,$(LOCAL_MODULE_CLASS)),)
+$(LOCAL_BUILT_MODULE) : $(LOCAL_PATH)/$(LOCAL_SRC_FILES) | $(ZIPALIGN)
+ $(transform-prebuilt-to-target-with-zipalign)
+else
+ifneq ($(LOCAL_PREBUILT_STRIP_COMMENTS),)
+$(LOCAL_BUILT_MODULE) : $(LOCAL_PATH)/$(LOCAL_SRC_FILES)
+ $(transform-prebuilt-to-target-strip-comments)
+else
$(LOCAL_BUILT_MODULE) : $(LOCAL_PATH)/$(LOCAL_SRC_FILES) | $(ACP)
$(transform-prebuilt-to-target)
+endif
+endif
+
+ifeq ($(LOCAL_CERTIFICATE),)
+ # can't re-sign this package, so predexopt is not available.
+else
+
+# If this is not an absolute certificate, assign it to a generic one.
+ifeq ($(dir $(strip $(LOCAL_CERTIFICATE))),./)
+ LOCAL_CERTIFICATE := $(SRC_TARGET_DIR)/product/security/$(LOCAL_CERTIFICATE)
+endif
+
+PACKAGES.$(LOCAL_MODULE).PRIVATE_KEY := $(LOCAL_CERTIFICATE).pk8
+PACKAGES.$(LOCAL_MODULE).CERTIFICATE := $(LOCAL_CERTIFICATE).x509.pem
+PACKAGES := $(PACKAGES) $(LOCAL_MODULE)
+
+endif
+
ifneq ($(prebuilt_module_is_a_library),)
ifneq ($(LOCAL_IS_HOST_MODULE),)
$(transform-host-ranlib-copy-hack)
diff --git a/core/prelink-linux-arm.map b/core/prelink-linux-arm.map
index c8e0db5..64149bc 100644
--- a/core/prelink-linux-arm.map
+++ b/core/prelink-linux-arm.map
@@ -27,7 +27,7 @@
liba2dp.so 0xAEE00000
audio.so 0xAED00000
input.so 0xAEC00000
-libhcid.so 0xAEB00000
+libbluetoothd.so 0xAEB00000
libbluedroid.so 0xAEA00000
libbluetooth.so 0xAE900000
libdbus.so 0xAE800000
@@ -50,8 +50,10 @@
# graphics
libpixelflinger.so 0xACF00000
+# libcorecg is for backward-compatibility with donut
libcorecg.so 0xACE00000
libsurfaceflinger.so 0xACD00000
+libGLES_android.so 0xACC80000
libagl.so 0xACC00000
libGLESv1_CM.so 0xACB00000
@@ -64,13 +66,21 @@
libexif.so 0xAC500000
libui.so 0xAC400000
-libsgl.so 0xAC000000
+# libsgl is for backward-compatibility with donut
+libsgl.so 0xAC200000
+libskia.so 0xAC000000
+librs_jni.so 0xABF00000
+libRS.so 0xAB900000
+
# audio
-libspeech.so 0xAB800000
+libFLAC.so 0xAB8A0000
+libaudiopolicy.so 0xAB880000
+libaudiopolicygeneric.so 0xAB800000
+libsoundpool.so 0xAB780000
libaudio.so 0xAB700000
-libsonivox.so 0xAB600000
-libsoundpool.so 0xAB500000
+libspeech.so 0xAB600000
+libsonivox.so 0xAB500000
libvorbisidec.so 0xAB400000
libmedia_jni.so 0xAB300000
libmediaplayerservice.so 0xAB280000
@@ -82,6 +92,7 @@
libsqlite.so 0xAAC00000
libexpat.so 0xAAB00000
libwebcore.so 0xAA000000
+libbinder.so 0xA9D80000
libutils.so 0xA9D00000
libcameraservice.so 0xA9C80000
libhardware.so 0xA9C70000
@@ -91,13 +102,29 @@
libime.so 0xA9800000
libgps.so 0xA9700000
libcamera.so 0xA9680000
-libqcamera.so 0xA9400000
+liboemcamera.so 0xA9400000
-# pv opencore libraries
-libopencore_author.so 0xA7B00000
-libopencore_player.so 0xA7800000
-libopencore_common.so 0xA7300000
-libopencore_2way.so 0xA7000000
+# pv libraries
+libpvasf.so 0xA7C26000
+libpvasfreg.so 0xA7C00000
+libomx_sharedlibrary.so 0xA7BA0000
+libopencore_download.so 0xA7B40000
+libopencore_downloadreg.so 0xA7B00000
+libopencore_net_support.so 0xA7A00000
+libopencore_rtsp.so 0xA7900000
+libopencore_rtspreg.so 0xA7890000
+libopencore_author.so 0xA7800000
+libomx_aacdec_sharedlibrary.so 0xA7700000
+libomx_amrdec_sharedlibrary.so 0xA76A0000
+libomx_amrenc_sharedlibrary.so 0xA7680000
+libomx_avcdec_sharedlibrary.so 0xA7660000
+libomx_avcenc_sharedlibrary.so 0xA7610000
+libomx_m4vdec_sharedlibrary.so 0xA75C0000
+libomx_m4venc_sharedlibrary.so 0xA7590000
+libomx_mp3dec_sharedlibrary.so 0xA7450000
+libopencore_mp4local.so 0xA7400000
+libopencore_mp4localreg.so 0xA7300000
+libopencore_player.so 0xA7000000
# opencore hardware support
libmm-adspsvc.so 0xA6FFD000
@@ -136,3 +163,4 @@
libtrace_test.so 0x9A300000
libsrec_jni.so 0x9A200000
libcerttool_jni.so 0x9A100000
+
diff --git a/core/product.mk b/core/product.mk
index adc81c3..5417242 100644
--- a/core/product.mk
+++ b/core/product.mk
@@ -23,7 +23,8 @@
# $(call ) isn't necessary.
#
define _find-android-products-files
-$(shell test -d vendor && find vendor -maxdepth 6 -name AndroidProducts.mk) \
+$(shell test -d device && find device -maxdepth 6 -name AndroidProducts.mk) \
+ $(shell test -d vendor && find vendor -maxdepth 6 -name AndroidProducts.mk) \
$(SRC_TARGET_DIR)/product/AndroidProducts.mk
endef
@@ -68,7 +69,8 @@
PRODUCT_SDK_ADDON_NAME \
PRODUCT_SDK_ADDON_COPY_FILES \
PRODUCT_SDK_ADDON_COPY_MODULES \
- PRODUCT_SDK_ADDON_DOC_MODULE
+ PRODUCT_SDK_ADDON_DOC_MODULE \
+ PRODUCT_DEFAULT_WIFI_CHANNELS
define dump-product
$(info ==== $(1) ====)\
diff --git a/core/product_config.mk b/core/product_config.mk
index 7cfa5f4..ffb8d27 100644
--- a/core/product_config.mk
+++ b/core/product_config.mk
@@ -193,6 +193,15 @@
extra_locales :=
endif
+# Default to medium-density assets.
+# (Can be overridden in the device config, e.g.: PRODUCT_LOCALES += hdpi)
+PRODUCT_LOCALES := $(strip \
+ $(PRODUCT_LOCALES) \
+ $(if $(filter %dpi,$(PRODUCT_LOCALES)),,mdpi))
+
+# Everyone gets nodpi assets which are density-independent.
+PRODUCT_LOCALES += nodpi
+
# Assemble the list of options.
PRODUCT_AAPT_CONFIG := $(PRODUCT_LOCALES)
@@ -214,6 +223,9 @@
PRODUCT_MANUFACTURER := unknown
endif
+PRODUCT_DEFAULT_WIFI_CHANNELS := \
+ $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_DEFAULT_WIFI_CHANNELS))
+
# Which policy should this product use
PRODUCT_POLICY := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_POLICY))
diff --git a/core/proguard.flags b/core/proguard.flags
new file mode 100644
index 0000000..afd1548
--- /dev/null
+++ b/core/proguard.flags
@@ -0,0 +1,7 @@
+# see http://sourceforge.net/tracker/?func=detail&aid=2787465&group_id=54750&atid=474707
+-optimizations !code/simplification/arithmetic
+-allowaccessmodification
+
+# Some classes in the libraries extend package private classes to chare common functionality
+# that isn't explicitly part of the API
+-dontskipnonpubliclibraryclasses
diff --git a/core/tasks/cts.mk b/core/tasks/cts.mk
index 42ad42a..917c5dc 100644
--- a/core/tasks/cts.mk
+++ b/core/tasks/cts.mk
@@ -26,6 +26,7 @@
CTS_HOST_JAR := $(HOST_OUT_JAVA_LIBRARIES)/cts.jar
junit_host_jar := $(HOST_OUT_JAVA_LIBRARIES)/junit.jar
+HOSTTESTLIB_JAR := $(HOST_OUT_JAVA_LIBRARIES)/hosttestlib.jar
CTS_CORE_CASE_LIST := android.core.tests.annotation \
android.core.tests.archive \
@@ -49,20 +50,40 @@
android.core.tests.xnet \
android.core.tests.runner
+CTS_SECURITY_APPS_LIST := \
+ CtsAppAccessData \
+ CtsAppWithData \
+ CtsInstrumentationAppDiffCert \
+ CtsPermissionDeclareApp \
+ CtsSharedUidInstall \
+ CtsSharedUidInstallDiffCert \
+ CtsSimpleAppInstall \
+ CtsSimpleAppInstallDiffCert \
+ CtsTargetInstrumentationApp \
+ CtsUsePermissionDiffCert
+
CTS_CASE_LIST := \
- DeviceInfoCollector \
+ TestDeviceSetup \
CtsTestStubs \
+ CtsAccountManagerTestCases \
CtsAppTestCases \
+ CtsBluetoothTestCases \
CtsContentTestCases \
CtsDatabaseTestCases \
+ CtsDpiTestCases \
+ CtsDpiTestCases2 \
+ CtsExampleTestCases \
+ CtsGestureTestCases \
CtsGraphicsTestCases \
CtsHardwareTestCases \
+ CtsJniTestCases \
CtsLocationTestCases \
CtsMediaTestCases \
CtsOsTestCases \
CtsPermissionTestCases \
CtsPermission2TestCases \
CtsProviderTestCases \
+ CtsSpeechTestCases \
CtsTelephonyTestCases \
CtsTextTestCases \
CtsUtilTestCases \
@@ -78,13 +99,14 @@
CtsPerformance5TestCases \
ApiDemos \
ApiDemosReferenceTest \
- $(CTS_CORE_CASE_LIST)
+ $(CTS_CORE_CASE_LIST) \
+ $(CTS_SECURITY_APPS_LIST)
DEFAULT_TEST_PLAN := $(PRIVATE_DIR)/resource/plans
$(cts_dir)/all_cts_files_stamp: PRIVATE_JUNIT_HOST_JAR := $(junit_host_jar)
-$(cts_dir)/all_cts_files_stamp: $(CTS_CASE_LIST) $(junit_host_jar) $(ACP)
+$(cts_dir)/all_cts_files_stamp: $(CTS_CASE_LIST) $(junit_host_jar) $(HOSTTESTLIB_JAR) $(ACP)
# Make necessary directory for CTS
@rm -rf $(PRIVATE_CTS_DIR)
@mkdir -p $(TMP_DIR)
@@ -97,6 +119,8 @@
$(hide) $(ACP) -fp $(CTS_EXECUTABLE_PATH) $(PRIVATE_DIR)/tools
# Copy junit jar
$(hide) $(ACP) -fp $(PRIVATE_JUNIT_HOST_JAR) $(PRIVATE_DIR)/tools
+# Copy hosttestlib jar
+ $(hide) $(ACP) -fp $(HOSTTESTLIB_JAR) $(PRIVATE_DIR)/tools
# Change mode of the executables
$(hide) chmod ug+rwX $(PRIVATE_DIR)/tools/$(notdir $(CTS_EXECUTABLE_PATH))
$(foreach apk,$(CTS_CASE_LIST), \
@@ -106,13 +130,17 @@
$(hide) touch $@
# Generate the test descriptions for the core-tests
-
+# Parameters:
+# $1 : The output file where the description should be written (without the '.xml' extension)
+# $2 : The AndroidManifest.xml corresponding to the test package
+# $3 : The name of the TestSuite generator class to use
+# $4 : The Android.mk corresponding to the test package (required for host-side tests only)
define generate-core-test-description
@echo "Generate core-test description ("$(notdir $(1))")"
$(hide) java $(PRIVATE_JAVAOPTS) \
-classpath $(PRIVATE_CLASSPATH) \
$(PRIVATE_PARAMS) CollectAllTests $(1) \
- $(2) $(3)
+ $(2) $(3) $(4)
endef
CORE_INTERMEDIATES :=$(call intermediates-dir-for,JAVA_LIBRARIES,core,,COMMON)
@@ -214,10 +242,17 @@
dot.junit.AllJunitHostTests, cts/tools/vm-tests/Android.mk)
$(ACP) -fv $(VMTESTS_INTERMEDIATES)/android.core.vm-tests.jar $(PRIVATE_DIR)/repository/testcases/android.core.vm-tests.jar
+# Move app security host-side tests to the repository
+APP_SECURITY_LIB := $(cts_dir)/$(cts_name)/repository/testcases/CtsAppSecurityTests.jar
+
+$(APP_SECURITY_LIB): $(HOST_OUT_JAVA_LIBRARIES)/CtsAppSecurityTests.jar $(cts_dir)/all_cts_files_stamp $(ACP)
+ $(ACP) -fv $(HOST_OUT_JAVA_LIBRARIES)/CtsAppSecurityTests.jar $(APP_SECURITY_LIB)
+
# Generate the default test plan for User.
-$(DEFAULT_TEST_PLAN): $(cts_dir)/all_cts_files_stamp $(cts_dir)/all_cts_core_files_stamp $(cts_tools_src_dir)/utils/genDefaultTestPlan.sh $(CORE_VM_TEST_DESC)
- $(hide) bash $(cts_tools_src_dir)/utils/genDefaultTestPlan.sh cts/tests/tests/ \
- $(PRIVATE_DIR) $(TMP_DIR) $(TOP) $(TARGET_COMMON_OUT_ROOT) $(OUT_DIR)
+# Usage: buildCts.py <testRoot> <ctsOutputDir> <tempDir> <androidRootDir> <docletPath>
+$(DEFAULT_TEST_PLAN): $(cts_dir)/all_cts_files_stamp $(cts_dir)/all_cts_core_files_stamp $(cts_tools_src_dir)/utils/buildCts.py $(CORE_VM_TEST_DESC) $(APP_SECURITY_LIB) $(HOST_OUT_JAVA_LIBRARIES)/descGen.jar
+ $(hide) $(cts_tools_src_dir)/utils/buildCts.py cts/tests/tests/ $(PRIVATE_DIR) $(TMP_DIR) \
+ $(TOP) $(HOST_OUT_JAVA_LIBRARIES)/descGen.jar
# Package CTS and clean up.
#
diff --git a/core/tasks/product-graph.mk b/core/tasks/product-graph.mk
index ead1406..6442252 100644
--- a/core/tasks/product-graph.mk
+++ b/core/tasks/product-graph.mk
@@ -15,21 +15,34 @@
#
products_pdf := $(OUT_DIR)/products.pdf
+products_graph := $(products_pdf:%.pdf=%.dot)
-# This rule doens't include any nodes that don't inherit from
+$(products_graph):
+ @echo Product graph DOT: $@
+ $(hide) ( \
+ echo 'digraph {'; \
+ echo 'graph [ ratio=.5 ];'; \
+ $(foreach p,$(ALL_PRODUCTS), \
+ $(foreach d,$(PRODUCTS.$(strip $(p)).INHERITS_FROM), \
+ echo \"$(d)\" -\> \"$(p)\";)) \
+ $(foreach prod, \
+ $(sort $(foreach p,$(ALL_PRODUCTS), \
+ $(foreach d,$(PRODUCTS.$(strip $(p)).INHERITS_FROM), \
+ $(d))) \
+ $(foreach p,$(ALL_PRODUCTS),$(p))), \
+ echo \"$(prod)\" [ label=\"$(dir $(prod))\\n$(notdir $(prod))\"];) \
+ echo '}' \
+ ) > $@
+
+# This rule doesn't include any nodes that don't inherit from
# anything or don't have anything inherit from them, to make the
# graph more readable. To add that, add this line to the rule
# below:
# $(foreach p,$(ALL_PRODUCTS), echo \"$(p)\";) \
-$(products_pdf):
- $(hide) ( \
- echo 'digraph {'; \
- $(foreach p,$(ALL_PRODUCTS), \
- $(foreach d,$(PRODUCTS.$(strip $(p)).INHERITS_FROM), \
- echo \"$(d)\" -\> \"$(p)\";)) \
- echo '}' \
- ) | dot -Tpdf -Nshape=box -o $@
+$(products_pdf): $(products_graph)
+ @echo Product graph PDF: $@
+ dot -Tpdf -Nshape=box -o $@ $<
product-graph: $(products_pdf)
diff --git a/core/version_defaults.mk b/core/version_defaults.mk
index ca8487f..9cc49c4 100644
--- a/core/version_defaults.mk
+++ b/core/version_defaults.mk
@@ -41,7 +41,7 @@
# which is the version that we reveal to the end user.
# Update this value when the platform version changes (rather
# than overriding it somewhere else). Can be an arbitrary string.
- PLATFORM_VERSION := Donut
+ PLATFORM_VERSION := 2.1-update1
endif
ifeq "" "$(PLATFORM_SDK_VERSION)"
@@ -53,13 +53,13 @@
# intermediate builds). During development, this number remains at the
# SDK version the branch is based on and PLATFORM_VERSION_CODENAME holds
# the code-name of the new development work.
- PLATFORM_SDK_VERSION := 3
+ PLATFORM_SDK_VERSION := 7
endif
ifeq "" "$(PLATFORM_VERSION_CODENAME)"
- # If the build is not a final release build, then this is the current
- # development code-name. If this is a final release build, it is simply "REL".
- PLATFORM_VERSION_CODENAME := Donut
+ # This is the current development code-name, if the build is not a final
+ # release build. If this is a final release build, it is simply "REL".
+ PLATFORM_VERSION_CODENAME := REL
endif
ifeq "" "$(DEFAULT_APP_TARGET_SDK)"
diff --git a/envsetup.sh b/envsetup.sh
index 6325c3d..4eede33 100644
--- a/envsetup.sh
+++ b/envsetup.sh
@@ -102,7 +102,7 @@
# and in with the new
CODE_REVIEWS=
prebuiltdir=$(getprebuilt)
- export ANDROID_EABI_TOOLCHAIN=$prebuiltdir/toolchain/arm-eabi-4.2.1/bin
+ export ANDROID_EABI_TOOLCHAIN=$prebuiltdir/toolchain/arm-eabi-4.4.0/bin
export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
export ANDROID_QTOOLS=$T/development/emulator/qtools
export ANDROID_BUILD_PATHS=:$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ANDROID_EABI_TOOLCHAIN$CODE_REVIEWS
@@ -537,7 +537,10 @@
echo $TOP
else
if [ -f $TOPFILE ] ; then
- echo $PWD
+ # The following circumlocution (repeated below as well) ensures
+ # that we record the true directory name and not one that is
+ # faked up with symlink names.
+ PWD= /bin/pwd
else
# We redirect cd to /dev/null in case it's aliased to
# a command that prints something as a side-effect
@@ -546,7 +549,7 @@
T=
while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
cd .. > /dev/null
- T=$PWD
+ T=`PWD= /bin/pwd`
done
cd $HERE > /dev/null
if [ -f "$T/$TOPFILE" ]; then
@@ -596,6 +599,8 @@
# Find the closest Android.mk file.
T=$(gettop)
local M=$(findmakefile)
+ # Remove the path to top as the makefilepath needs to be relative
+ local M=`echo $M|sed 's:'$T'/::'`
if [ ! "$T" ]; then
echo "Couldn't locate the top of the tree. Try setting TOP."
elif [ ! "$M" ]; then
@@ -634,6 +639,7 @@
ARGS="$ARGS showcommands"
else
echo "No Android.mk in $DIR."
+ return 1
fi
fi
done
@@ -653,6 +659,26 @@
fi
}
+function cproj()
+{
+ TOPFILE=build/core/envsetup.mk
+ # We redirect cd to /dev/null in case it's aliased to
+ # a command that prints something as a side-effect
+ # (like pushd)
+ local HERE=$PWD
+ T=
+ while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
+ T=$PWD
+ if [ -f "$T/Android.mk" ]; then
+ cd $T
+ return
+ fi
+ cd .. > /dev/null
+ done
+ cd $HERE > /dev/null
+ echo "can't find Android.mk"
+}
+
function pid()
{
local EXE="$1"
@@ -664,6 +690,13 @@
fi
}
+# systemstack - dump the current stack trace of all threads in the system process
+# to the usual ANR traces file
+function systemstack()
+{
+ adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
+}
+
function gdbclient()
{
local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
@@ -944,14 +977,7 @@
echo "Couldn't locate the top of the tree. Try setting TOP." >&2
return
fi
- (cd "$T" && development/testrunner/runtest.py $@)
-}
-
-# TODO: Remove this some time after 1 June 2009
-function runtest_py()
-{
- echo "runtest_py is obsolete; use runtest instead" >&2
- return 1
+ ("$T"/development/testrunner/runtest.py $@)
}
function godir () {
diff --git a/target/board/Android.mk b/target/board/Android.mk
index 64e3a74..ac8cb44 100644
--- a/target/board/Android.mk
+++ b/target/board/Android.mk
@@ -20,11 +20,8 @@
INSTALLED_KERNEL_TARGET :=
endif
-ifneq ($(strip $(TARGET_NO_RADIOIMAGE)),true)
- INSTALLED_RADIOIMAGE_TARGET := $(PRODUCT_OUT)/radio.img
-else
- INSTALLED_RADIOIMAGE_TARGET :=
-endif
+# Use the add-radio-file function to add values to this variable.
+INSTALLED_RADIOIMAGE_TARGET :=
ifeq (,$(wildcard $(TARGET_DEVICE_DIR)/AndroidBoard.mk))
ifeq (,$(wildcard $(TARGET_DEVICE_DIR)/Android.mk))
@@ -48,7 +45,8 @@
board_info_txt := $(wildcard $(TARGET_DEVICE_DIR)/board-info.txt)
$(INSTALLED_ANDROID_INFO_TXT_TARGET): $(board_info_txt)
$(call pretty,"Generated: ($@)")
- $(hide) echo "board=$(TARGET_BOOTLOADER_BOARD_NAME)" > $@
ifdef board_info_txt
- $(hide) cat $< >> $@
+ $(hide) cat $< > $@
+else
+ $(hide) echo "board=$(TARGET_BOOTLOADER_BOARD_NAME)" > $@
endif
diff --git a/target/board/generic/BoardConfig.mk b/target/board/generic/BoardConfig.mk
index 6ec2de3..2b72d01 100644
--- a/target/board/generic/BoardConfig.mk
+++ b/target/board/generic/BoardConfig.mk
@@ -1,12 +1,11 @@
# config.mk
-#
+#
# Product-specific compile-time definitions.
#
# The generic product target doesn't have any hardware-specific pieces.
TARGET_NO_BOOTLOADER := true
TARGET_NO_KERNEL := true
-TARGET_NO_RADIOIMAGE := true
TARGET_CPU_ABI := armeabi
HAVE_HTC_AUDIO_DRIVER := true
BOARD_USES_GENERIC_AUDIO := true
diff --git a/target/board/generic_x86/AndroidBoard.mk b/target/board/generic_x86/AndroidBoard.mk
new file mode 100644
index 0000000..ff46149
--- /dev/null
+++ b/target/board/generic_x86/AndroidBoard.mk
@@ -0,0 +1,17 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := init.rc
+LOCAL_SRC_FILES := init.rc
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
+include $(BUILD_PREBUILT)
+
+ifeq ($(TARGET_PREBUILT_KERNEL),)
+LOCAL_KERNEL := prebuilt/android-x86/kernel/kernel
+else
+LOCAL_KERNEL := $(TARGET_PREBUILT_KERNEL)
+endif
+
+PRODUCT_COPY_FILES += \
+ $(LOCAL_KERNEL):kernel
diff --git a/target/board/generic_x86/BoardConfig.mk b/target/board/generic_x86/BoardConfig.mk
new file mode 100644
index 0000000..be8aeb7
--- /dev/null
+++ b/target/board/generic_x86/BoardConfig.mk
@@ -0,0 +1,18 @@
+TARGET_COMPRESS_MODULE_SYMBOLS := false
+TARGET_PRELINK_MODULE := false
+TARGET_NO_RECOVERY := true
+TARGET_HARDWARE_3D := false
+BOARD_USES_GENERIC_AUDIO := true
+USE_CAMERA_STUB := true
+TARGET_PROVIDES_INIT_RC := true
+USE_CUSTOM_RUNTIME_HEAP_MAX := "32M"
+TARGET_CPU_ABI := x86
+TARGET_USERIMAGES_USE_EXT2 := true
+TARGET_BOOTIMAGE_USE_EXT2 := true
+
+BOARD_KERNEL_CMDLINE := init=/init console=tty0 androidboot.hardware=generic_x86 vga=788
+TARGET_USE_DISKINSTALLER := true
+TARGET_DISK_LAYOUT_CONFIG := build/target/board/generic_x86/disk_layout.conf
+BOARD_BOOTIMAGE_MAX_SIZE := 8388608
+BOARD_SYSLOADER_MAX_SIZE := 7340032
+BOARD_FLASH_BLOCK_SIZE := 512
diff --git a/target/board/generic_x86/README.txt b/target/board/generic_x86/README.txt
new file mode 100644
index 0000000..97e2d5b
--- /dev/null
+++ b/target/board/generic_x86/README.txt
@@ -0,0 +1,33 @@
+The generic_x86 board target provides basic services on very basic
+hardware (really for an emulation). To build with generic_x86, you will
+need an appropriate kernel for your emulation (or device).
+
+A1. Create a new top level directory and pull the AOSP repository
+ mkdir $HOME/AOSP
+ cd $HOME/AOSP
+ repo init -u git://android.git.kernel.org/platform/manifest.git
+ repo sync
+
+A2. Copy in the buildspeck.mk
+ cd $HOME/AOSP
+ cp build/target/board/generic_x86/buildspec-generic_x86.mk buildspec.mk
+
+A3. Copy in the kernel
+ cd $HOME/AOSP
+ cp ~/bzImage.your_device $HOME/AOSP/prebuilt/android-x86/kernel/kernel
+
+A4. Build
+ cd $HOME/AOSP
+ source build/envsetup.sh
+ lunch generic_x86-eng
+ make -j8
+
+The build will generate some image files whose format may or may not be correct for your
+device. You can build an installer image disk for the VirtualBox emulator using the command:
+
+A5. Build a VirtualBox installer image
+ cd $HOME/AOSP
+ source build/envsetup.sh
+ lunch generic_x86-eng
+ make -j8 installer_vdi
+
diff --git a/target/board/generic_x86/buildspec-generic_x86.mk b/target/board/generic_x86/buildspec-generic_x86.mk
new file mode 100644
index 0000000..5c4e6a5
--- /dev/null
+++ b/target/board/generic_x86/buildspec-generic_x86.mk
@@ -0,0 +1,3 @@
+BUILD_ENV_SEQUENCE_NUMBER := 9
+DISABLE_DEXPREOPT := true
+TARGET_ARCH := x86
diff --git a/target/board/generic_x86/disk_layout.conf b/target/board/generic_x86/disk_layout.conf
new file mode 100644
index 0000000..7b073ee
--- /dev/null
+++ b/target/board/generic_x86/disk_layout.conf
@@ -0,0 +1,54 @@
+device {
+ path /dev/block/sda
+
+ scheme mbr
+
+ # bytes in a disk sector (== 1 LBA), must be a power of 2!
+ sector_size 512
+
+ # What LBA should the partitions start at?
+ start_lba 2048
+
+ # Autodetect disk size if == 0
+ num_lba 0
+
+ partitions {
+ sysloader {
+ active y
+ type linux
+ len 7M
+ }
+
+ recovery {
+ active y
+ type linux
+ len 16M
+ }
+
+ boot {
+ active y
+ type linux
+ len 8M
+ }
+
+ cache {
+ type linux
+ len 512M
+ }
+
+ system {
+ type linux
+ len 512M
+ }
+
+ third_party {
+ type linux
+ len 512M
+ }
+
+ data {
+ type linux
+ len -1
+ }
+ }
+}
diff --git a/target/board/generic_x86/init.rc b/target/board/generic_x86/init.rc
new file mode 100644
index 0000000..2a6f665
--- /dev/null
+++ b/target/board/generic_x86/init.rc
@@ -0,0 +1,243 @@
+
+on init
+
+sysclktz 0
+
+loglevel 3
+
+# setup the global environment
+ export PATH /sbin:/system/sbin:/system/bin:/system/xbin
+ export LD_LIBRARY_PATH /system/lib
+ export ANDROID_BOOTLOGO 1
+ export ANDROID_ROOT /system
+ export ANDROID_ASSETS /system/app
+ export ANDROID_DATA /data
+ export EXTERNAL_STORAGE /sdcard
+ export BOOTCLASSPATH /system/framework/core.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar
+
+# Backward compatibility
+ symlink /system/etc /etc
+
+# create mountpoints and mount tmpfs on sqlite_stmt_journals and debugfs on d
+ mkdir /d
+ mkdir /sdcard 0000 system system
+ mkdir /system
+ mkdir /data 0771 system system
+ mkdir /cache 0770 system cache
+ mkdir /sqlite_stmt_journals 01777 root root
+ mount tmpfs tmpfs /sqlite_stmt_journals
+ mount debugfs debugfs /d
+
+ mount rootfs rootfs / rw remount
+
+ write /proc/sys/kernel/panic_on_oops 1
+ write /proc/sys/kernel/hung_task_timeout_secs 0
+ write /proc/cpu/alignment 4
+ write /proc/sys/kernel/sched_latency_ns 10000000
+ write /proc/sys/kernel/sched_wakeup_granularity_ns 2000000
+
+# mount mtd partitions
+ # Hack...
+ # We'll attempt to mount both as sdcard and harddisk...
+ # Only one or the other will actually work... this way, we can
+ # use the same init.rc for both
+ mount ext3 /dev/block/mmcblk0p6 /system
+ mount ext3 /dev/block/mmcblk0p6 /system rw remount
+ mount ext3 /dev/block/mmcblk0p2 /data nosuid nodev
+ mount ext3 /dev/block/mmcblk0p7 /cache nosuid nodev
+ mount ext3 /dev/block/sda6 /system
+ mount ext3 /dev/block/sda6 /system rw remount
+ mount ext3 /dev/block/sda8 /data
+
+ # We chown/chmod /data again so because mount is run as root + defaults
+ chown system system /data
+ chmod 0771 /data
+
+ # Same reason as /data above
+ chown system cache /cache
+ chmod 0770 /cache
+
+ # This may have been created by the recovery system with odd permissions
+ chown system system /cache/recovery
+ chmod 0770 /cache/recovery
+
+# create basic filesystem structure
+ mkdir /data/misc 01771 system misc
+ mkdir /data/misc/hcid 0770 bluetooth bluetooth
+ mkdir /data/local 0771 shell shell
+ mkdir /data/local/tmp 0771 shell shell
+ mkdir /data/data 0771 system system
+ mkdir /data/app-private 0771 system system
+ mkdir /data/app 0771 system system
+ mkdir /data/property 0700 root root
+
+ # create dalvik-cache and double-check the perms
+ mkdir /data/dalvik-cache 0771 system system
+ chown system system /data/dalvik-cache
+ chmod 0771 /data/dalvik-cache
+
+ # create the lost+found directories, so as to enforce our permissions
+ mkdir /system/lost+found 0770
+ mkdir /data/lost+found 0770
+ mkdir /cache/lost+found 0770
+
+ # double check the perms, in case lost+found already exists, and set owner
+ chown root root /data/lost+found
+ chmod 0770 /data/lost+found
+ chown root root /cache/lost+found
+ chmod 0770 /cache/lost+found
+
+on boot
+
+### Load some modules
+
+# basic network init
+ ifup lo
+ hostname localhost
+ domainname localdomain
+
+
+# set RLIMIT_NICE to allow priorities from 19 to -20
+ setrlimit 13 40 40
+ mkdir /data/core 0777
+ write /proc/sys/kernel/core_pattern /data/core/%e.%p
+ setrlimit 4 -1 -1
+
+# Define the oom_adj values for the classes of processes that can be
+# killed by the kernel. These are used in ActivityManagerService.
+ setprop ro.FOREGROUND_APP_ADJ 0
+ setprop ro.VISIBLE_APP_ADJ 1
+ setprop ro.SECONDARY_SERVER_ADJ 2
+ setprop ro.HIDDEN_APP_MIN_ADJ 7
+ setprop ro.CONTENT_PROVIDER_ADJ 14
+ setprop ro.EMPTY_APP_ADJ 15
+ setprop ro.BACKUP_APP_ADJ 2
+ setprop ro.HOME_APP_ADJ 4
+
+
+# Define the memory thresholds at which the above process classes will
+# be killed. These numbers are in pages (4k).
+ setprop ro.FOREGROUND_APP_MEM 1536
+ setprop ro.VISIBLE_APP_MEM 2048
+ setprop ro.SECONDARY_SERVER_MEM 4096
+ setprop ro.BACKUP_APP_MEM 4096
+ setprop ro.HOME_APP_MEM 4096
+ setprop ro.HIDDEN_APP_MEM 5120
+ setprop ro.CONTENT_PROVIDER_MEM 5632
+ setprop ro.EMPTY_APP_MEM 6144
+
+
+# Write value must be consistent with the above properties.
+ write /sys/module/lowmemorykiller/parameters/adj 0,1,2,7,14,15
+
+ write /proc/sys/vm/overcommit_memory 1
+ write /sys/module/lowmemorykiller/parameters/minfree 1536,2048,4096,8192,16384
+
+ # Set init its forked children's oom_adj.
+ write /proc/1/oom_adj -16
+
+ # Permissions for System Server and daemons.
+ chown radio system /sys/android_power/state
+ chown radio system /sys/android_power/request_state
+ chown radio system /sys/android_power/acquire_full_wake_lock
+ chown radio system /sys/android_power/acquire_partial_wake_lock
+ chown radio system /sys/android_power/release_wake_lock
+ chown radio system /sys/power/state
+ chown radio system /sys/power/wake_lock
+ chown radio system /sys/power/wake_unlock
+ chmod 0660 /sys/power/state
+ chmod 0660 /sys/power/wake_lock
+ chmod 0660 /sys/power/wake_unlock
+
+ chown system system /sys/class/timed_output/vibrator/enable
+ chown system system /sys/class/leds/keyboard-backlight/brightness
+ chown system system /sys/class/leds/lcd-backlight/brightness
+ chown system system /sys/class/leds/button-backlight/brightness
+ chown system system /sys/class/leds/red/brightness
+ chown system system /sys/class/leds/green/brightness
+ chown system system /sys/class/leds/blue/brightness
+ chown system system /sys/class/leds/red/device/grpfreq
+ chown system system /sys/class/leds/red/device/grppwm
+ chown system system /sys/class/leds/red/device/blink
+ chown system system /sys/class/leds/red/brightness
+ chown system system /sys/class/leds/green/brightness
+ chown system system /sys/class/leds/blue/brightness
+ chown system system /sys/class/leds/red/device/grpfreq
+ chown system system /sys/class/leds/red/device/grppwm
+ chown system system /sys/class/leds/red/device/blink
+ chown system system /sys/class/timed_output/vibrator/enable
+ chown bluetooth bluetooth /sys/module/board_trout/parameters/bluetooth_power_on
+ chown system system /sys/module/sco/parameters/disable_esco
+ chmod 0660 /sys/module/board_trout/parameters/bluetooth_power_on
+ chown radio audio /system/etc/AudioPara4.csv
+ chown system system /sys/kernel/ipv4/tcp_wmem_min
+ chown system system /sys/kernel/ipv4/tcp_wmem_def
+ chown system system /sys/kernel/ipv4/tcp_wmem_max
+ chown system system /sys/kernel/ipv4/tcp_rmem_min
+ chown system system /sys/kernel/ipv4/tcp_rmem_def
+ chown system system /sys/kernel/ipv4/tcp_rmem_max
+ chown root radio /proc/cmdline
+
+# Enable audio based on existing /dev/dsp
+ chmod 0666 /dev/snd/dsp
+
+# Define TCP buffer sizes for various networks
+# ReadMin, ReadInitial, ReadMax, WriteMin, WriteInitial, WriteMax,
+ setprop net.tcp.buffersize.default 4096,87380,110208,4096,16384,110208
+ setprop net.tcp.buffersize.wifi 4095,87380,110208,4096,16384,110208
+ setprop net.tcp.buffersize.umts 4094,87380,110208,4096,16384,110208
+ setprop net.tcp.buffersize.edge 4093,26280,35040,4096,16384,35040
+ setprop net.tcp.buffersize.gprs 4092,8760,11680,4096,8760,11680
+
+ class_start default
+
+## Daemon processes to be run by init.
+##
+service console /system/bin/sh
+ console
+
+# adbd is controlled by the persist.service.adb.enable system property
+service adbd /sbin/adbd
+# disabled
+
+# adbd on at boot in emulator
+on property:ro.kernel.qemu=1
+ start adbd
+
+# adbd on at boot in insecure builds
+on property:ro.secure=0
+ start adbd
+
+on property:persist.service.adb.enable=1
+ start adbd
+
+on property:persist.service.adb.enable=0
+ stop adbd
+
+service servicemanager /system/bin/servicemanager
+ user system
+ critical
+ onrestart restart zygote
+ onrestart restart media
+
+service vold /system/bin/vold
+ socket vold stream 0660 root mount
+
+service zygote /system/bin/app_process -Xzygote -Xint:fast /system/bin --zygote --start-system-server
+ socket zygote stream 666
+ onrestart write /sys/android_power/request_state wake
+
+service media /system/bin/mediaserver
+ user media
+ group system audio camera graphics inet net_bt net_bt_admin
+
+service dbus /system/bin/dbus-daemon --system --nofork
+ socket dbus stream 660 bluetooth bluetooth
+ user bluetooth
+ group bluetooth net_bt_admin
+
+service brick /system/bin/wipe nuke
+ disabled
+
+service installd /system/bin/installd
+ socket installd stream 600 system system
diff --git a/target/product/AndroidProducts.mk b/target/product/AndroidProducts.mk
index 1bf3c3f..e241cde 100644
--- a/target/product/AndroidProducts.mk
+++ b/target/product/AndroidProducts.mk
@@ -30,4 +30,5 @@
$(LOCAL_DIR)/min_dev.mk \
$(LOCAL_DIR)/sdk.mk \
$(LOCAL_DIR)/sim.mk \
+ $(LOCAL_DIR)/generic_x86.mk \
$(LOCAL_DIR)/generic_with_google.mk
diff --git a/target/product/core.mk b/target/product/core.mk
index 204345e..a93ba7c 100644
--- a/target/product/core.mk
+++ b/target/product/core.mk
@@ -3,7 +3,8 @@
PRODUCT_DEVICE :=
PRODUCT_POLICY := android.policy_phone
PRODUCT_PROPERTY_OVERRIDES := \
- ro.config.notification_sound=F1_New_SMS.ogg
+ ro.config.notification_sound=OnTheHunt.ogg \
+ ro.config.alarm_alert=Alarm_Classic.ogg
PRODUCT_PACKAGES := \
framework-res \
@@ -24,6 +25,4 @@
VpnServices \
UserDictionaryProvider \
PackageInstaller \
- WebSearchProvider \
Bugreport
-
diff --git a/target/product/generic.mk b/target/product/generic.mk
index b9bc070..8c85ca6 100644
--- a/target/product/generic.mk
+++ b/target/product/generic.mk
@@ -3,19 +3,25 @@
# you should derive from generic_with_google.mk
PRODUCT_PACKAGES := \
+ AccountAndSyncSettings \
AlarmClock \
AlarmProvider \
+ Bluetooth \
+ Calculator \
Calendar \
Camera \
+ CertInstaller \
DrmProvider \
+ Email \
+ Gallery \
LatinIME \
Mms \
Music \
+ Provision \
Settings \
Sync \
Updater \
CalendarProvider \
- SubscribedFeedsProvider \
SyncProvider
$(call inherit-product, $(SRC_TARGET_DIR)/product/core.mk)
diff --git a/target/product/generic_with_google.mk b/target/product/generic_with_google.mk
index dddbbb7..ba30f15 100644
--- a/target/product/generic_with_google.mk
+++ b/target/product/generic_with_google.mk
@@ -4,13 +4,16 @@
# from generic.mk
PRODUCT_PACKAGES := \
- GoogleContactsProvider \
+ ContactsProvider \
+ GoogleContactsSyncAdapter \
GoogleSubscribedFeedsProvider \
com.google.android.gtalkservice \
+ com.google.android.datamessaging \
com.google.android.maps
PRODUCT_COPY_FILES := \
vendor/google/frameworks/maps/com.google.android.maps.xml:system/etc/permissions/com.google.android.maps.xml \
+ vendor/google/frameworks/datamessaging/com.google.android.datamessaging.xml:system/etc/permissions/com.google.android.datamessaging.xml \
vendor/google/apps/GTalkService/com.google.android.gtalkservice.xml:system/etc/permissions/com.google.android.gtalkservice.xml
diff --git a/target/product/generic_x86.mk b/target/product/generic_x86.mk
new file mode 100644
index 0000000..00f2822
--- /dev/null
+++ b/target/product/generic_x86.mk
@@ -0,0 +1,27 @@
+# This is a generic product that isn't specialized for a specific device.
+# It includes the base Android platform. If you need Google-specific features,
+# you should derive from generic_with_google.mk
+
+PRODUCT_PACKAGES := \
+ AlarmClock \
+ AlarmProvider \
+ Calendar \
+ Camera \
+ DrmProvider \
+ LatinIME \
+ Mms \
+ Music \
+ Settings \
+ Sync \
+ Updater \
+ CalendarProvider \
+ SubscribedFeedsProvider \
+ SyncProvider
+
+$(call inherit-product, $(SRC_TARGET_DIR)/product/core.mk)
+
+# Overrides
+PRODUCT_BRAND := generic_x86
+PRODUCT_DEVICE := generic_x86
+PRODUCT_NAME := generic_x86
+PRODUCT_POLICY := android.policy_phone
diff --git a/target/product/min_dev.mk b/target/product/min_dev.mk
index 005af70..92ba973 100644
--- a/target/product/min_dev.mk
+++ b/target/product/min_dev.mk
@@ -1,7 +1,8 @@
PRODUCT_POLICY := android.policy_phone
PRODUCT_PROPERTY_OVERRIDES := \
- ro.config.notification_sound=F1_New_SMS.ogg
+ ro.config.notification_sound=OnTheHunt.ogg \
+ ro.config.alarm_alert=Alarm_Classic.ogg
PRODUCT_BRAND := generic
PRODUCT_NAME := min_dev
PRODUCT_DEVICE := generic
@@ -12,7 +13,6 @@
MediaProvider \
SettingsProvider \
PackageInstaller \
- WebSearchProvider \
Bugreport \
Launcher \
Settings \
diff --git a/target/product/sdk.mk b/target/product/sdk.mk
index d847377..e571f9e 100644
--- a/target/product/sdk.mk
+++ b/target/product/sdk.mk
@@ -1,6 +1,7 @@
PRODUCT_PROPERTY_OVERRIDES :=
PRODUCT_PACKAGES := \
+ AccountAndSyncSettings \
AlarmClock \
Camera \
Calculator \
@@ -8,6 +9,7 @@
DrmProvider \
Email \
Fallback \
+ Gallery \
GPSEnable \
Launcher \
Music \
@@ -23,12 +25,18 @@
libWnnEngDic \
libWnnJpnDic \
libwnndict \
+ CertInstaller \
+ LiveWallpapersPicker \
ApiDemos \
GestureBuilder \
- SoftKeyboard
+ SoftKeyboard \
+ CubeLiveWallpapers
+
+PRODUCT_PACKAGE_OVERLAYS := development/sdk_overlay
PRODUCT_COPY_FILES := \
- development/data/etc/vold.conf:system/etc/vold.conf
+ development/data/etc/vold.conf:system/etc/vold.conf \
+ frameworks/base/data/etc/android.hardware.camera.autofocus.xml:system/etc/permissions/android.hardware.camera.autofocus.xml
$(call inherit-product, $(SRC_TARGET_DIR)/product/core.mk)
@@ -37,6 +45,9 @@
PRODUCT_NAME := sdk
PRODUCT_DEVICE := generic
PRODUCT_LOCALES := \
+ ldpi \
+ hdpi \
+ mdpi \
en_US \
en_GB \
en_CA \
@@ -64,3 +75,10 @@
ru_RU \
ko_KR
+# include available languages for TTS in the system image
+include external/svox/pico/lang/PicoLangDeDeInSystem.mk
+include external/svox/pico/lang/PicoLangEnGBInSystem.mk
+include external/svox/pico/lang/PicoLangEnUsInSystem.mk
+include external/svox/pico/lang/PicoLangEsEsInSystem.mk
+include external/svox/pico/lang/PicoLangFrFrInSystem.mk
+include external/svox/pico/lang/PicoLangItItInSystem.mk
diff --git a/target/product/sim.mk b/target/product/sim.mk
index 7b27495..4403e46 100644
--- a/target/product/sim.mk
+++ b/target/product/sim.mk
@@ -1,7 +1,7 @@
PRODUCT_PACKAGES := \
IM
-$(call inherit-product, $(SRC_TARGET_DIR)/product/generic_with_google.mk)
+$(call inherit-product, $(SRC_TARGET_DIR)/product/generic.mk)
# Overrides
PRODUCT_NAME := sim
diff --git a/tools/adbs b/tools/adbs
new file mode 100755
index 0000000..8b1fac6
--- /dev/null
+++ b/tools/adbs
@@ -0,0 +1,222 @@
+#!/usr/bin/env python
+
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the 'License');
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an 'AS IS' BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import re
+import string
+import sys
+
+###############################################################################
+# match "#00 pc 0003f52e /system/lib/libdvm.so" for example
+###############################################################################
+trace_line = re.compile("(.*)(\#[0-9]+) (..) ([0-9a-f]{8}) ([^\r\n \t]*)")
+
+# returns a list containing the function name and the file/lineno
+def CallAddr2Line(lib, addr):
+ global symbols_dir
+ global addr2line_cmd
+ global cppfilt_cmd
+
+ if lib != "":
+ cmd = addr2line_cmd + \
+ " -f -e " + symbols_dir + lib + " 0x" + addr
+ stream = os.popen(cmd)
+ lines = stream.readlines()
+ list = map(string.strip, lines)
+ else:
+ list = []
+ if list != []:
+ # Name like "move_forward_type<JavaVMOption>" causes troubles
+ mangled_name = re.sub('<', '\<', list[0]);
+ mangled_name = re.sub('>', '\>', mangled_name);
+ cmd = cppfilt_cmd + " " + mangled_name
+ stream = os.popen(cmd)
+ list[0] = stream.readline()
+ stream.close()
+ list = map(string.strip, list)
+ else:
+ list = [ "(unknown)", "(unknown)" ]
+ return list
+
+
+###############################################################################
+# similar to CallAddr2Line, but using objdump to find out the name of the
+# containing function of the specified address
+###############################################################################
+def CallObjdump(lib, addr):
+ global objdump_cmd
+ global symbols_dir
+
+ unknown = "(unknown)"
+ uname = os.uname()[0]
+ if uname == "Darwin":
+ proc = os.uname()[-1]
+ if proc == "i386":
+ uname = "darwin-x86"
+ else:
+ uname = "darwin-ppc"
+ elif uname == "Linux":
+ uname = "linux-x86"
+ if lib != "":
+ next_addr = string.atoi(addr, 16) + 1
+ cmd = objdump_cmd \
+ + " -C -d --start-address=0x" + addr + " --stop-address=" \
+ + str(next_addr) \
+ + " " + symbols_dir + lib
+ stream = os.popen(cmd)
+ lines = stream.readlines()
+ map(string.strip, lines)
+ stream.close()
+ else:
+ return unknown
+
+ # output looks like
+ #
+ # file format elf32-littlearm
+ #
+ # Disassembly of section .text:
+ #
+ # 0000833c <func+0x4>:
+ # 833c: 701a strb r2, [r3, #0]
+ #
+ # we want to extract the "func" part
+ num_lines = len(lines)
+ if num_lines < 2:
+ return unknown
+ func_name = lines[num_lines-2]
+ func_regexp = re.compile("(^.*\<)(.*)(\+.*\>:$)")
+ components = func_regexp.match(func_name)
+ if components is None:
+ return unknown
+ return components.group(2)
+
+###############################################################################
+# determine the symbols directory in the local build
+###############################################################################
+def FindSymbolsDir():
+ global symbols_dir
+
+ try:
+ path = os.environ['ANDROID_PRODUCT_OUT'] + "/symbols"
+ except:
+ cmd = "CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core " \
+ + "SRC_TARGET_DIR=build/target make -f build/core/envsetup.mk " \
+ + "dumpvar-abs-TARGET_OUT_UNSTRIPPED"
+ stream = os.popen(cmd)
+ str = stream.read()
+ stream.close()
+ path = str.strip()
+
+ if (not os.path.exists(path)):
+ print path + " not found!"
+ sys.exit(1)
+
+ symbols_dir = path
+
+###############################################################################
+# determine the path of binutils
+###############################################################################
+def SetupToolsPath():
+ global addr2line_cmd
+ global objdump_cmd
+ global cppfilt_cmd
+ global symbols_dir
+
+ uname = os.uname()[0]
+ if uname == "Darwin":
+ proc = os.uname()[-1]
+ if proc == "i386":
+ uname = "darwin-x86"
+ else:
+ uname = "darwin-ppc"
+ elif uname == "Linux":
+ uname = "linux-x86"
+ prefix = "./prebuilt/" + uname + "/toolchain/arm-eabi-4.4.0/bin/"
+ addr2line_cmd = prefix + "arm-eabi-addr2line"
+
+ if (not os.path.exists(addr2line_cmd)):
+ try:
+ prefix = os.environ['ANDROID_BUILD_TOP'] + "/prebuilt/" + uname + \
+ "/toolchain/arm-eabi-4.4.0/bin/"
+ except:
+ prefix = "";
+
+ addr2line_cmd = prefix + "arm-eabi-addr2line"
+ if (not os.path.exists(addr2line_cmd)):
+ print addr2line_cmd + " not found!"
+ sys.exit(1)
+
+ objdump_cmd = prefix + "arm-eabi-objdump"
+ cppfilt_cmd = prefix + "arm-eabi-c++filt"
+
+###############################################################################
+# look up the function and file/line number for a raw stack trace line
+# groups[0]: log tag
+# groups[1]: stack level
+# groups[2]: "pc"
+# groups[3]: code address
+# groups[4]: library name
+###############################################################################
+def SymbolTranslation(groups):
+ lib_name = groups[4]
+ code_addr = groups[3]
+ caller = CallObjdump(lib_name, code_addr)
+ func_line_pair = CallAddr2Line(lib_name, code_addr)
+
+ # If a callee is inlined to the caller, objdump will see the caller's
+ # address but addr2line will report the callee's address. So the printed
+ # format is desgined to be "caller<-callee file:line"
+ if (func_line_pair[0] != caller):
+ print groups[0] + groups[1] + " " + caller + "<-" + \
+ ' '.join(func_line_pair[:]) + " "
+ else:
+ print groups[0] + groups[1] + " " + ' '.join(func_line_pair[:]) + " "
+
+###############################################################################
+
+if __name__ == '__main__':
+ # pass the options to adb
+ adb_cmd = "adb " + ' '.join(sys.argv[1:])
+
+ # setup addr2line_cmd and objdump_cmd
+ SetupToolsPath()
+
+ # setup the symbols directory
+ FindSymbolsDir()
+
+ # invoke the adb command and filter its output
+ stream = os.popen(adb_cmd)
+ while (True):
+ line = stream.readline()
+
+ # EOF reached
+ if (line == ''):
+ break
+
+ # remove the trailing \n
+ line = line.strip()
+
+ # see if this is a stack trace line
+ match = trace_line.match(line)
+ if (match):
+ groups = match.groups()
+ # translate raw address into symbols
+ SymbolTranslation(groups)
+ else:
+ print line
+
+ # adb itself aborts
+ stream.close()
diff --git a/tools/apicheck/src/com/android/apicheck/ApiCheck.java b/tools/apicheck/src/com/android/apicheck/ApiCheck.java
index 20a98ce..c8272dd 100644
--- a/tools/apicheck/src/com/android/apicheck/ApiCheck.java
+++ b/tools/apicheck/src/com/android/apicheck/ApiCheck.java
@@ -127,7 +127,7 @@
}
private static class MakeHandler extends DefaultHandler {
-
+
private ApiInfo mApi;
private PackageInfo mCurrentPackage;
private ClassInfo mCurrentClass;
@@ -139,8 +139,9 @@
super();
mApi = new ApiInfo();
}
-
- public void startElement(String uri, String localName, String qName,
+
+ @Override
+ public void startElement(String uri, String localName, String qName,
Attributes attributes) {
if (qName.equals("package")) {
mCurrentPackage = new PackageInfo(attributes.getValue("name"),
@@ -150,25 +151,25 @@
// push the old outer scope for later recovery, then set
// up the new current class object
mClassScope.push(mCurrentClass);
- mCurrentClass = new ClassInfo(attributes.getValue("name"),
+ mCurrentClass = new ClassInfo(attributes.getValue("name"),
mCurrentPackage,
attributes.getValue("extends") ,
- qName.equals("interface"),
+ qName.equals("interface"),
Boolean.valueOf(
attributes.getValue("abstract")),
Boolean.valueOf(
attributes.getValue("static")),
Boolean.valueOf(
attributes.getValue("final")),
- attributes.getValue("deprecated"),
+ attributes.getValue("deprecated"),
attributes.getValue("visibility"),
SourcePositionInfo.fromXml(attributes.getValue("source")),
mCurrentClass);
} else if (qName.equals("method")) {
- mCurrentMethod = new MethodInfo(attributes.getValue("name"),
+ mCurrentMethod = new MethodInfo(attributes.getValue("name"),
attributes.getValue("return") ,
Boolean.valueOf(
- attributes.getValue("abstract")),
+ attributes.getValue("abstract")),
Boolean.valueOf(
attributes.getValue("native")),
Boolean.valueOf(
@@ -178,11 +179,11 @@
Boolean.valueOf(
attributes.getValue("final")),
attributes.getValue("deprecated"),
- attributes.getValue("visibility"),
+ attributes.getValue("visibility"),
SourcePositionInfo.fromXml(attributes.getValue("source")),
mCurrentClass);
} else if (qName.equals("constructor")) {
- mCurrentMethod = new ConstructorInfo(attributes.getValue("name"),
+ mCurrentMethod = new ConstructorInfo(attributes.getValue("name"),
attributes.getValue("type") ,
Boolean.valueOf(
attributes.getValue("static")),
@@ -193,7 +194,7 @@
SourcePositionInfo.fromXml(attributes.getValue("source")),
mCurrentClass);
} else if (qName.equals("field")) {
- FieldInfo fInfo = new FieldInfo(attributes.getValue("name"),
+ FieldInfo fInfo = new FieldInfo(attributes.getValue("name"),
attributes.getValue("type") ,
Boolean.valueOf(
attributes.getValue("transient")),
@@ -218,6 +219,8 @@
mCurrentClass.addInterface(attributes.getValue("name"));
}
}
+
+ @Override
public void endElement(String uri, String localName, String qName) {
if (qName.equals("method")) {
mCurrentClass.addMethod((MethodInfo) mCurrentMethod);
diff --git a/tools/apicheck/src/com/android/apicheck/Errors.java b/tools/apicheck/src/com/android/apicheck/Errors.java
index d7013e3..b0b620e 100644
--- a/tools/apicheck/src/com/android/apicheck/Errors.java
+++ b/tools/apicheck/src/com/android/apicheck/Errors.java
@@ -41,6 +41,7 @@
return this.msg.compareTo(that.msg);
}
+ @Override
public String toString() {
return this.pos.toString() + this.msg;
}
@@ -115,7 +116,7 @@
public static Error CHANGED_CLASS = new Error(23, WARNING);
public static Error CHANGED_DEPRECATED = new Error(24, WARNING);
public static Error CHANGED_SYNCHRONIZED = new Error(25, ERROR);
-
+
public static Error[] ERRORS = {
PARSE_ERROR,
ADDED_PACKAGE,
diff --git a/tools/apicheck/src/com/android/apicheck/SourcePositionInfo.java b/tools/apicheck/src/com/android/apicheck/SourcePositionInfo.java
index 477c1d3..276771b 100644
--- a/tools/apicheck/src/com/android/apicheck/SourcePositionInfo.java
+++ b/tools/apicheck/src/com/android/apicheck/SourcePositionInfo.java
@@ -80,6 +80,7 @@
return new SourcePositionInfo(that.file, line, 0);
}
+ @Override
public String toString()
{
if (this.file == null) {
diff --git a/tools/applypatch/Android.mk b/tools/applypatch/Android.mk
index 5796cef..f09223e 100644
--- a/tools/applypatch/Android.mk
+++ b/tools/applypatch/Android.mk
@@ -14,10 +14,11 @@
ifneq ($(TARGET_SIMULATOR),true)
+ifeq ($(TARGET_ARCH),arm)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := applypatch.c bsdiff.c freecache.c imgpatch.c utils.c
+LOCAL_SRC_FILES := applypatch.c bspatch.c freecache.c imgpatch.c utils.c
LOCAL_MODULE := libapplypatch
LOCAL_MODULE_TAGS := eng
LOCAL_C_INCLUDES += external/bzip2 external/zlib bootable/recovery
@@ -47,13 +48,14 @@
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := imgdiff.c utils.c
+LOCAL_SRC_FILES := imgdiff.c utils.c bsdiff.c
LOCAL_MODULE := imgdiff
LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE_TAGS := eng
-LOCAL_C_INCLUDES += external/zlib
-LOCAL_STATIC_LIBRARIES += libz
+LOCAL_C_INCLUDES += external/zlib external/bzip2
+LOCAL_STATIC_LIBRARIES += libz libbz
include $(BUILD_HOST_EXECUTABLE)
+endif # TARGET_ARCH == arm
endif # !TARGET_SIMULATOR
diff --git a/tools/applypatch/applypatch.c b/tools/applypatch/applypatch.c
index 394c584..e69a2fb 100644
--- a/tools/applypatch/applypatch.c
+++ b/tools/applypatch/applypatch.c
@@ -21,6 +21,8 @@
#include <string.h>
#include <sys/stat.h>
#include <sys/statfs.h>
+#include <sys/types.h>
+#include <fcntl.h>
#include <unistd.h>
#include "mincrypt/sha.h"
@@ -30,6 +32,7 @@
int SaveFileContents(const char* filename, FileContents file);
int LoadMTDContents(const char* filename, FileContents* file);
int ParseSha1(const char* str, uint8_t* digest);
+size_t FileSink(unsigned char* data, size_t len, void* token);
static int mtd_partitions_scanned = 0;
@@ -45,7 +48,7 @@
}
if (stat(filename, &file->st) != 0) {
- fprintf(stderr, "failed to stat \"%s\": %s\n", filename, strerror(errno));
+ printf("failed to stat \"%s\": %s\n", filename, strerror(errno));
return -1;
}
@@ -54,7 +57,7 @@
FILE* f = fopen(filename, "rb");
if (f == NULL) {
- fprintf(stderr, "failed to open \"%s\": %s\n", filename, strerror(errno));
+ printf("failed to open \"%s\": %s\n", filename, strerror(errno));
free(file->data);
file->data = NULL;
return -1;
@@ -62,7 +65,7 @@
size_t bytes_read = fread(file->data, 1, file->size, f);
if (bytes_read != file->size) {
- fprintf(stderr, "short read of \"%s\" (%d bytes of %d)\n",
+ printf("short read of \"%s\" (%d bytes of %d)\n",
filename, bytes_read, file->size);
free(file->data);
file->data = NULL;
@@ -108,7 +111,7 @@
char* copy = strdup(filename);
const char* magic = strtok(copy, ":");
if (strcmp(magic, "MTD") != 0) {
- fprintf(stderr, "LoadMTDContents called with bad filename (%s)\n",
+ printf("LoadMTDContents called with bad filename (%s)\n",
filename);
return -1;
}
@@ -122,7 +125,7 @@
}
}
if (colons < 3 || colons%2 == 0) {
- fprintf(stderr, "LoadMTDContents called with bad filename (%s)\n",
+ printf("LoadMTDContents called with bad filename (%s)\n",
filename);
}
@@ -135,7 +138,7 @@
const char* size_str = strtok(NULL, ":");
size[i] = strtol(size_str, NULL, 10);
if (size[i] == 0) {
- fprintf(stderr, "LoadMTDContents called with bad size (%s)\n", filename);
+ printf("LoadMTDContents called with bad size (%s)\n", filename);
return -1;
}
sha1sum[i] = strtok(NULL, ":");
@@ -154,14 +157,14 @@
const MtdPartition* mtd = mtd_find_partition_by_name(partition);
if (mtd == NULL) {
- fprintf(stderr, "mtd partition \"%s\" not found (loading %s)\n",
+ printf("mtd partition \"%s\" not found (loading %s)\n",
partition, filename);
return -1;
}
MtdReadContext* ctx = mtd_read_partition(mtd);
if (ctx == NULL) {
- fprintf(stderr, "failed to initialize read of mtd partition \"%s\"\n",
+ printf("failed to initialize read of mtd partition \"%s\"\n",
partition);
return -1;
}
@@ -184,7 +187,7 @@
if (next > 0) {
read = mtd_read_data(ctx, p, next);
if (next != read) {
- fprintf(stderr, "short read (%d bytes of %d) for partition \"%s\"\n",
+ printf("short read (%d bytes of %d) for partition \"%s\"\n",
read, next, partition);
free(file->data);
file->data = NULL;
@@ -201,7 +204,7 @@
const uint8_t* sha_so_far = SHA_final(&temp_ctx);
if (ParseSha1(sha1sum[index[i]], parsed_sha) != 0) {
- fprintf(stderr, "failed to parse sha1 %s in %s\n",
+ printf("failed to parse sha1 %s in %s\n",
sha1sum[index[i]], filename);
free(file->data);
file->data = NULL;
@@ -224,7 +227,7 @@
if (i == pairs) {
// Ran off the end of the list of (size,sha1) pairs without
// finding a match.
- fprintf(stderr, "contents of MTD partition \"%s\" didn't match %s\n",
+ printf("contents of MTD partition \"%s\" didn't match %s\n",
partition, filename);
free(file->data);
file->data = NULL;
@@ -253,29 +256,29 @@
// Save the contents of the given FileContents object under the given
// filename. Return 0 on success.
int SaveFileContents(const char* filename, FileContents file) {
- FILE* f = fopen(filename, "wb");
- if (f == NULL) {
- fprintf(stderr, "failed to open \"%s\" for write: %s\n",
+ int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC);
+ if (fd < 0) {
+ printf("failed to open \"%s\" for write: %s\n",
filename, strerror(errno));
return -1;
}
- size_t bytes_written = fwrite(file.data, 1, file.size, f);
+ size_t bytes_written = FileSink(file.data, file.size, &fd);
if (bytes_written != file.size) {
- fprintf(stderr, "short write of \"%s\" (%d bytes of %d)\n",
- filename, bytes_written, file.size);
+ printf("short write of \"%s\" (%d bytes of %d) (%s)\n",
+ filename, bytes_written, file.size, strerror(errno));
+ close(fd);
return -1;
}
- fflush(f);
- fsync(fileno(f));
- fclose(f);
+ fsync(fd);
+ close(fd);
if (chmod(filename, file.st.st_mode) != 0) {
- fprintf(stderr, "chmod of \"%s\" failed: %s\n", filename, strerror(errno));
+ printf("chmod of \"%s\" failed: %s\n", filename, strerror(errno));
return -1;
}
if (chown(filename, file.st.st_uid, file.st.st_gid) != 0) {
- fprintf(stderr, "chown of \"%s\" failed: %s\n", filename, strerror(errno));
+ printf("chown of \"%s\" failed: %s\n", filename, strerror(errno));
return -1;
}
@@ -288,7 +291,7 @@
const char* target_mtd) {
char* partition = strchr(target_mtd, ':');
if (partition == NULL) {
- fprintf(stderr, "bad MTD target name \"%s\"\n", target_mtd);
+ printf("bad MTD target name \"%s\"\n", target_mtd);
return -1;
}
++partition;
@@ -306,33 +309,33 @@
const MtdPartition* mtd = mtd_find_partition_by_name(partition);
if (mtd == NULL) {
- fprintf(stderr, "mtd partition \"%s\" not found for writing\n", partition);
+ printf("mtd partition \"%s\" not found for writing\n", partition);
return -1;
}
MtdWriteContext* ctx = mtd_write_partition(mtd);
if (ctx == NULL) {
- fprintf(stderr, "failed to init mtd partition \"%s\" for writing\n",
+ printf("failed to init mtd partition \"%s\" for writing\n",
partition);
return -1;
}
size_t written = mtd_write_data(ctx, (char*)data, len);
if (written != len) {
- fprintf(stderr, "only wrote %d of %d bytes to MTD %s\n",
+ printf("only wrote %d of %d bytes to MTD %s\n",
written, len, partition);
mtd_write_close(ctx);
return -1;
}
if (mtd_erase_blocks(ctx, -1) < 0) {
- fprintf(stderr, "error finishing mtd write of %s\n", partition);
+ printf("error finishing mtd write of %s\n", partition);
mtd_write_close(ctx);
return -1;
}
if (mtd_write_close(ctx)) {
- fprintf(stderr, "error closing mtd write of %s\n", partition);
+ printf("error closing mtd write of %s\n", partition);
return -1;
}
@@ -381,7 +384,7 @@
int i;
for (i = 0; i < *num_patches; ++i) {
if (ParseSha1(argv[i], (*patches)[i].sha1) != 0) {
- fprintf(stderr, "failed to parse sha1 \"%s\"\n", argv[i]);
+ printf("failed to parse sha1 \"%s\"\n", argv[i]);
return -1;
}
if (argv[i][SHA_DIGEST_SIZE*2] == '\0') {
@@ -389,7 +392,7 @@
} else if (argv[i][SHA_DIGEST_SIZE*2] == ':') {
(*patches)[i].patch_filename = argv[i] + (SHA_DIGEST_SIZE*2+1);
} else {
- fprintf(stderr, "failed to parse filename \"%s\"\n", argv[i]);
+ printf("failed to parse filename \"%s\"\n", argv[i]);
return -1;
}
}
@@ -414,7 +417,7 @@
// nonzero otherwise.
int CheckMode(int argc, char** argv) {
if (argc < 3) {
- fprintf(stderr, "no filename given\n");
+ printf("no filename given\n");
return 2;
}
@@ -432,7 +435,7 @@
if (LoadFileContents(argv[2], &file) != 0 ||
(num_patches > 0 &&
FindMatchingPatch(file.sha1, patches, num_patches) == NULL)) {
- fprintf(stderr, "file \"%s\" doesn't have any of expected "
+ printf("file \"%s\" doesn't have any of expected "
"sha1 sums; checking cache\n", argv[2]);
free(file.data);
@@ -444,12 +447,12 @@
// passes.
if (LoadFileContents(CACHE_TEMP_SOURCE, &file) != 0) {
- fprintf(stderr, "failed to load cache file\n");
+ printf("failed to load cache file\n");
return 1;
}
if (FindMatchingPatch(file.sha1, patches, num_patches) == NULL) {
- fprintf(stderr, "cache bits don't match any sha1 for \"%s\"\n",
+ printf("cache bits don't match any sha1 for \"%s\"\n",
argv[2]);
return 1;
}
@@ -465,7 +468,19 @@
}
size_t FileSink(unsigned char* data, size_t len, void* token) {
- return fwrite(data, 1, len, (FILE*)token);
+ int fd = *(int *)token;
+ ssize_t done = 0;
+ ssize_t wrote;
+ while (done < (ssize_t) len) {
+ wrote = write(fd, data+done, len-done);
+ if (wrote <= 0) {
+ printf("error writing %d bytes: %s\n", (int)(len-done), strerror(errno));
+ return done;
+ }
+ done += wrote;
+ }
+ printf("wrote %d bytes to output\n", (int)done);
+ return done;
}
typedef struct {
@@ -489,7 +504,7 @@
size_t FreeSpaceForFile(const char* filename) {
struct statfs sf;
if (statfs(filename, &sf) != 0) {
- fprintf(stderr, "failed to statfs %s: %s\n", filename, strerror(errno));
+ printf("failed to statfs %s: %s\n", filename, strerror(errno));
return -1;
}
return sf.f_bsize * sf.f_bfree;
@@ -583,8 +598,10 @@
target_filename = source_filename;
}
- if (ParseSha1(argv[3], target_sha1) != 0) {
- fprintf(stderr, "failed to parse tgt-sha1 \"%s\"\n", argv[3]);
+ printf("\napplying patch to %s\n", source_filename);
+
+ if (ParseSha1(argv[3], target_sha1) != 0) {
+ printf("failed to parse tgt-sha1 \"%s\"\n", argv[3]);
return 1;
}
@@ -605,7 +622,7 @@
if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
// The early-exit case: the patch was already applied, this file
// has the desired hash, nothing for us to do.
- fprintf(stderr, "\"%s\" is already target; no patch needed\n",
+ printf("\"%s\" is already target; no patch needed\n",
target_filename);
return 0;
}
@@ -630,11 +647,11 @@
if (source_patch_filename == NULL) {
free(source_file.data);
- fprintf(stderr, "source file is bad; trying copy\n");
+ printf("source file is bad; trying copy\n");
if (LoadFileContents(CACHE_TEMP_SOURCE, ©_file) < 0) {
// fail.
- fprintf(stderr, "failed to read copy file\n");
+ printf("failed to read copy file\n");
return 1;
}
@@ -646,179 +663,205 @@
if (copy_patch_filename == NULL) {
// fail.
- fprintf(stderr, "copy file doesn't match source SHA-1s either\n");
+ printf("copy file doesn't match source SHA-1s either\n");
return 1;
}
}
- // Is there enough room in the target filesystem to hold the patched
- // file?
+ int retry = 1;
+ SHA_CTX ctx;
+ int output;
+ MemorySinkInfo msi;
+ FileContents* source_to_use;
+ char* outname;
- if (strncmp(target_filename, "MTD:", 4) == 0) {
- // If the target is an MTD partition, we're actually going to
- // write the output to /tmp and then copy it to the partition.
- // statfs() always returns 0 blocks free for /tmp, so instead
- // we'll just assume that /tmp has enough space to hold the file.
-
- // We still write the original source to cache, in case the MTD
- // write is interrupted.
- if (MakeFreeSpaceOnCache(source_file.size) < 0) {
- fprintf(stderr, "not enough free space on /cache\n");
- return 1;
- }
- if (SaveFileContents(CACHE_TEMP_SOURCE, source_file) < 0) {
- fprintf(stderr, "failed to back up source file\n");
- return 1;
- }
- made_copy = 1;
+ // assume that target_filename (eg "/system/app/Foo.apk") is located
+ // on the same filesystem as its top-level directory ("/system").
+ // We need something that exists for calling statfs().
+ char target_fs[strlen(target_filename)+1];
+ char* slash = strchr(target_filename+1, '/');
+ if (slash != NULL) {
+ int count = slash - target_filename;
+ strncpy(target_fs, target_filename, count);
+ target_fs[count] = '\0';
} else {
- // assume that target_filename (eg "/system/app/Foo.apk") is located
- // on the same filesystem as its top-level directory ("/system").
- // We need something that exists for calling statfs().
- char* target_fs = strdup(target_filename);
- char* slash = strchr(target_fs+1, '/');
- if (slash != NULL) {
- *slash = '\0';
- }
+ strcpy(target_fs, target_filename);
+ }
- size_t free_space = FreeSpaceForFile(target_fs);
- int enough_space =
- free_space > (target_size * 3 / 2); // 50% margin of error
- printf("target %ld bytes; free space %ld bytes; enough %d\n",
- (long)target_size, (long)free_space, enough_space);
+ do {
+ // Is there enough room in the target filesystem to hold the patched
+ // file?
- if (!enough_space && source_patch_filename != NULL) {
- // Using the original source, but not enough free space. First
- // copy the source file to cache, then delete it from the original
- // location.
+ if (strncmp(target_filename, "MTD:", 4) == 0) {
+ // If the target is an MTD partition, we're actually going to
+ // write the output to /tmp and then copy it to the partition.
+ // statfs() always returns 0 blocks free for /tmp, so instead
+ // we'll just assume that /tmp has enough space to hold the file.
- if (strncmp(source_filename, "MTD:", 4) == 0) {
- // It's impossible to free space on the target filesystem by
- // deleting the source if the source is an MTD partition. If
- // we're ever in a state where we need to do this, fail.
- fprintf(stderr, "not enough free space for target but source is MTD\n");
- return 1;
- }
-
+ // We still write the original source to cache, in case the MTD
+ // write is interrupted.
if (MakeFreeSpaceOnCache(source_file.size) < 0) {
- fprintf(stderr, "not enough free space on /cache\n");
+ printf("not enough free space on /cache\n");
return 1;
}
-
if (SaveFileContents(CACHE_TEMP_SOURCE, source_file) < 0) {
- fprintf(stderr, "failed to back up source file\n");
+ printf("failed to back up source file\n");
return 1;
}
made_copy = 1;
- unlink(source_filename);
+ retry = 0;
+ } else {
+ int enough_space = 0;
+ if (retry > 0) {
+ size_t free_space = FreeSpaceForFile(target_fs);
+ int enough_space =
+ (free_space > (target_size * 3 / 2)); // 50% margin of error
+ printf("target %ld bytes; free space %ld bytes; retry %d; enough %d\n",
+ (long)target_size, (long)free_space, retry, enough_space);
+ }
- size_t free_space = FreeSpaceForFile(target_fs);
- printf("(now %ld bytes free for target)\n", (long)free_space);
+ if (!enough_space) {
+ retry = 0;
+ }
+
+ if (!enough_space && source_patch_filename != NULL) {
+ // Using the original source, but not enough free space. First
+ // copy the source file to cache, then delete it from the original
+ // location.
+
+ if (strncmp(source_filename, "MTD:", 4) == 0) {
+ // It's impossible to free space on the target filesystem by
+ // deleting the source if the source is an MTD partition. If
+ // we're ever in a state where we need to do this, fail.
+ printf("not enough free space for target but source is MTD\n");
+ return 1;
+ }
+
+ if (MakeFreeSpaceOnCache(source_file.size) < 0) {
+ printf("not enough free space on /cache\n");
+ return 1;
+ }
+
+ if (SaveFileContents(CACHE_TEMP_SOURCE, source_file) < 0) {
+ printf("failed to back up source file\n");
+ return 1;
+ }
+ made_copy = 1;
+ unlink(source_filename);
+
+ size_t free_space = FreeSpaceForFile(target_fs);
+ printf("(now %ld bytes free for target)\n", (long)free_space);
+ }
}
- }
- FileContents* source_to_use;
- const char* patch_filename;
- if (source_patch_filename != NULL) {
- source_to_use = &source_file;
- patch_filename = source_patch_filename;
- } else {
- source_to_use = ©_file;
- patch_filename = copy_patch_filename;
- }
-
- char* outname = NULL;
- FILE* output = NULL;
- MemorySinkInfo msi;
- SinkFn sink = NULL;
- void* token = NULL;
- if (strncmp(target_filename, "MTD:", 4) == 0) {
- // We store the decoded output in memory.
- msi.buffer = malloc(target_size);
- if (msi.buffer == NULL) {
- fprintf(stderr, "failed to alloc %ld bytes for output\n",
- (long)target_size);
- return 1;
+ const char* patch_filename;
+ if (source_patch_filename != NULL) {
+ source_to_use = &source_file;
+ patch_filename = source_patch_filename;
+ } else {
+ source_to_use = ©_file;
+ patch_filename = copy_patch_filename;
}
- msi.pos = 0;
- msi.size = target_size;
- sink = MemorySink;
- token = &msi;
- } else {
- // We write the decoded output to "<tgt-file>.patch".
- outname = (char*)malloc(strlen(target_filename) + 10);
- strcpy(outname, target_filename);
- strcat(outname, ".patch");
- output = fopen(outname, "wb");
- if (output == NULL) {
- fprintf(stderr, "failed to open output file %s: %s\n",
- outname, strerror(errno));
- return 1;
+ SinkFn sink = NULL;
+ void* token = NULL;
+ output = -1;
+ outname = NULL;
+ if (strncmp(target_filename, "MTD:", 4) == 0) {
+ // We store the decoded output in memory.
+ msi.buffer = malloc(target_size);
+ if (msi.buffer == NULL) {
+ printf("failed to alloc %ld bytes for output\n",
+ (long)target_size);
+ return 1;
+ }
+ msi.pos = 0;
+ msi.size = target_size;
+ sink = MemorySink;
+ token = &msi;
+ } else {
+ // We write the decoded output to "<tgt-file>.patch".
+ outname = (char*)malloc(strlen(target_filename) + 10);
+ strcpy(outname, target_filename);
+ strcat(outname, ".patch");
+
+ output = open(outname, O_WRONLY | O_CREAT | O_TRUNC);
+ if (output < 0) {
+ printf("failed to open output file %s: %s\n",
+ outname, strerror(errno));
+ return 1;
+ }
+ sink = FileSink;
+ token = &output;
}
- sink = FileSink;
- token = output;
- }
#define MAX_HEADER_LENGTH 8
- unsigned char header[MAX_HEADER_LENGTH];
- FILE* patchf = fopen(patch_filename, "rb");
- if (patchf == NULL) {
- fprintf(stderr, "failed to open patch file %s: %s\n",
- patch_filename, strerror(errno));
- return 1;
- }
- int header_bytes_read = fread(header, 1, MAX_HEADER_LENGTH, patchf);
- fclose(patchf);
-
- SHA_CTX ctx;
- SHA_init(&ctx);
-
- if (header_bytes_read >= 4 &&
- header[0] == 0xd6 && header[1] == 0xc3 &&
- header[2] == 0xc4 && header[3] == 0) {
- // xdelta3 patches begin "VCD" (with the high bits set) followed
- // by a zero byte (the version number).
- fprintf(stderr, "error: xdelta3 patches no longer supported\n");
- return 1;
- } else if (header_bytes_read >= 8 &&
- memcmp(header, "BSDIFF40", 8) == 0) {
- int result = ApplyBSDiffPatch(source_to_use->data, source_to_use->size,
- patch_filename, 0, sink, token, &ctx);
- if (result != 0) {
- fprintf(stderr, "ApplyBSDiffPatch failed\n");
- return result;
+ unsigned char header[MAX_HEADER_LENGTH];
+ FILE* patchf = fopen(patch_filename, "rb");
+ if (patchf == NULL) {
+ printf("failed to open patch file %s: %s\n",
+ patch_filename, strerror(errno));
+ return 1;
}
- } else if (header_bytes_read >= 8 &&
- memcmp(header, "IMGDIFF", 7) == 0 &&
- (header[7] == '1' || header[7] == '2')) {
- int result = ApplyImagePatch(source_to_use->data, source_to_use->size,
- patch_filename, sink, token, &ctx);
- if (result != 0) {
- fprintf(stderr, "ApplyImagePatch failed\n");
- return result;
- }
- } else {
- fprintf(stderr, "Unknown patch file format\n");
- return 1;
- }
+ int header_bytes_read = fread(header, 1, MAX_HEADER_LENGTH, patchf);
+ fclose(patchf);
- if (output != NULL) {
- fflush(output);
- fsync(fileno(output));
- fclose(output);
- }
+ SHA_init(&ctx);
+
+ int result;
+
+ if (header_bytes_read >= 4 &&
+ header[0] == 0xd6 && header[1] == 0xc3 &&
+ header[2] == 0xc4 && header[3] == 0) {
+ // xdelta3 patches begin "VCD" (with the high bits set) followed
+ // by a zero byte (the version number).
+ printf("error: xdelta3 patches no longer supported\n");
+ return 1;
+ } else if (header_bytes_read >= 8 &&
+ memcmp(header, "BSDIFF40", 8) == 0) {
+ result = ApplyBSDiffPatch(source_to_use->data, source_to_use->size,
+ patch_filename, 0, sink, token, &ctx);
+ } else if (header_bytes_read >= 8 &&
+ memcmp(header, "IMGDIFF", 7) == 0 &&
+ (header[7] == '1' || header[7] == '2')) {
+ result = ApplyImagePatch(source_to_use->data, source_to_use->size,
+ patch_filename, sink, token, &ctx);
+ } else {
+ printf("Unknown patch file format\n");
+ return 1;
+ }
+
+ if (output >= 0) {
+ fsync(output);
+ close(output);
+ }
+
+ if (result != 0) {
+ if (retry == 0) {
+ printf("applying patch failed\n");
+ return result;
+ } else {
+ printf("applying patch failed; retrying\n");
+ }
+ if (outname != NULL) {
+ unlink(outname);
+ }
+ } else {
+ // succeeded; no need to retry
+ break;
+ }
+ } while (retry-- > 0);
const uint8_t* current_target_sha1 = SHA_final(&ctx);
if (memcmp(current_target_sha1, target_sha1, SHA_DIGEST_SIZE) != 0) {
- fprintf(stderr, "patch did not produce expected sha1\n");
+ printf("patch did not produce expected sha1\n");
return 1;
}
- if (output == NULL) {
+ if (output < 0) {
// Copy the temp file to the MTD partition.
if (WriteToMTDPartition(msi.buffer, msi.pos, target_filename) != 0) {
- fprintf(stderr, "write of patched data to %s failed\n", target_filename);
+ printf("write of patched data to %s failed\n", target_filename);
return 1;
}
free(msi.buffer);
@@ -826,18 +869,18 @@
// Give the .patch file the same owner, group, and mode of the
// original source file.
if (chmod(outname, source_to_use->st.st_mode) != 0) {
- fprintf(stderr, "chmod of \"%s\" failed: %s\n", outname, strerror(errno));
+ printf("chmod of \"%s\" failed: %s\n", outname, strerror(errno));
return 1;
}
if (chown(outname, source_to_use->st.st_uid,
source_to_use->st.st_gid) != 0) {
- fprintf(stderr, "chown of \"%s\" failed: %s\n", outname, strerror(errno));
+ printf("chown of \"%s\" failed: %s\n", outname, strerror(errno));
return 1;
}
// Finally, rename the .patch file to replace the target file.
if (rename(outname, target_filename) != 0) {
- fprintf(stderr, "rename of .patch to \"%s\" failed: %s\n",
+ printf("rename of .patch to \"%s\" failed: %s\n",
target_filename, strerror(errno));
return 1;
}
diff --git a/tools/applypatch/bsdiff.c b/tools/applypatch/bsdiff.c
index d5cd617..b6d342b 100644
--- a/tools/applypatch/bsdiff.c
+++ b/tools/applypatch/bsdiff.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,239 +14,397 @@
* limitations under the License.
*/
-// This file is a nearly line-for-line copy of bspatch.c from the
-// bsdiff-4.3 distribution; the primary differences being how the
-// input and output data are read and the error handling. Running
-// applypatch with the -l option will display the bsdiff license
-// notice.
+/*
+ * Most of this code comes from bsdiff.c from the bsdiff-4.3
+ * distribution, which is:
+ */
-#include <stdio.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
+/*-
+ * Copyright 2003-2005 Colin Percival
+ * All rights reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted providing that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
#include <bzlib.h>
+#include <err.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
-#include "mincrypt/sha.h"
-#include "applypatch.h"
+#define MIN(x,y) (((x)<(y)) ? (x) : (y))
-void ShowBSDiffLicense() {
- puts("The bsdiff library used herein is:\n"
- "\n"
- "Copyright 2003-2005 Colin Percival\n"
- "All rights reserved\n"
- "\n"
- "Redistribution and use in source and binary forms, with or without\n"
- "modification, are permitted providing that the following conditions\n"
- "are met:\n"
- "1. Redistributions of source code must retain the above copyright\n"
- " notice, this list of conditions and the following disclaimer.\n"
- "2. Redistributions in binary form must reproduce the above copyright\n"
- " notice, this list of conditions and the following disclaimer in the\n"
- " documentation and/or other materials provided with the distribution.\n"
- "\n"
- "THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n"
- "IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n"
- "WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n"
- "ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\n"
- "DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n"
- "DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n"
- "OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n"
- "HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n"
- "STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\n"
- "IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n"
- "POSSIBILITY OF SUCH DAMAGE.\n"
- "\n------------------\n\n"
- "This program uses Julian R Seward's \"libbzip2\" library, available\n"
- "from http://www.bzip.org/.\n"
- );
-}
-
-static off_t offtin(u_char *buf)
+static void split(off_t *I,off_t *V,off_t start,off_t len,off_t h)
{
- off_t y;
+ off_t i,j,k,x,tmp,jj,kk;
- y=buf[7]&0x7F;
- y=y*256;y+=buf[6];
- y=y*256;y+=buf[5];
- y=y*256;y+=buf[4];
- y=y*256;y+=buf[3];
- y=y*256;y+=buf[2];
- y=y*256;y+=buf[1];
- y=y*256;y+=buf[0];
+ if(len<16) {
+ for(k=start;k<start+len;k+=j) {
+ j=1;x=V[I[k]+h];
+ for(i=1;k+i<start+len;i++) {
+ if(V[I[k+i]+h]<x) {
+ x=V[I[k+i]+h];
+ j=0;
+ };
+ if(V[I[k+i]+h]==x) {
+ tmp=I[k+j];I[k+j]=I[k+i];I[k+i]=tmp;
+ j++;
+ };
+ };
+ for(i=0;i<j;i++) V[I[k+i]]=k+j-1;
+ if(j==1) I[k]=-1;
+ };
+ return;
+ };
- if(buf[7]&0x80) y=-y;
+ x=V[I[start+len/2]+h];
+ jj=0;kk=0;
+ for(i=start;i<start+len;i++) {
+ if(V[I[i]+h]<x) jj++;
+ if(V[I[i]+h]==x) kk++;
+ };
+ jj+=start;kk+=jj;
- return y;
+ i=start;j=0;k=0;
+ while(i<jj) {
+ if(V[I[i]+h]<x) {
+ i++;
+ } else if(V[I[i]+h]==x) {
+ tmp=I[i];I[i]=I[jj+j];I[jj+j]=tmp;
+ j++;
+ } else {
+ tmp=I[i];I[i]=I[kk+k];I[kk+k]=tmp;
+ k++;
+ };
+ };
+
+ while(jj+j<kk) {
+ if(V[I[jj+j]+h]==x) {
+ j++;
+ } else {
+ tmp=I[jj+j];I[jj+j]=I[kk+k];I[kk+k]=tmp;
+ k++;
+ };
+ };
+
+ if(jj>start) split(I,V,start,jj-start,h);
+
+ for(i=0;i<kk-jj;i++) V[I[jj+i]]=kk-1;
+ if(jj==kk-1) I[jj]=-1;
+
+ if(start+len>kk) split(I,V,kk,start+len-kk,h);
}
+static void qsufsort(off_t *I,off_t *V,u_char *old,off_t oldsize)
+{
+ off_t buckets[256];
+ off_t i,h,len;
-int ApplyBSDiffPatch(const unsigned char* old_data, ssize_t old_size,
- const char* patch_filename, ssize_t patch_offset,
- SinkFn sink, void* token, SHA_CTX* ctx) {
+ for(i=0;i<256;i++) buckets[i]=0;
+ for(i=0;i<oldsize;i++) buckets[old[i]]++;
+ for(i=1;i<256;i++) buckets[i]+=buckets[i-1];
+ for(i=255;i>0;i--) buckets[i]=buckets[i-1];
+ buckets[0]=0;
- unsigned char* new_data;
- ssize_t new_size;
- if (ApplyBSDiffPatchMem(old_data, old_size, patch_filename, patch_offset,
- &new_data, &new_size) != 0) {
- return -1;
- }
+ for(i=0;i<oldsize;i++) I[++buckets[old[i]]]=i;
+ I[0]=oldsize;
+ for(i=0;i<oldsize;i++) V[i]=buckets[old[i]];
+ V[oldsize]=0;
+ for(i=1;i<256;i++) if(buckets[i]==buckets[i-1]+1) I[buckets[i]]=-1;
+ I[0]=-1;
- if (sink(new_data, new_size, token) < new_size) {
- fprintf(stderr, "short write of output: %d (%s)\n", errno, strerror(errno));
- return 1;
- }
- if (ctx) {
- SHA_update(ctx, new_data, new_size);
- }
- free(new_data);
+ for(h=1;I[0]!=-(oldsize+1);h+=h) {
+ len=0;
+ for(i=0;i<oldsize+1;) {
+ if(I[i]<0) {
+ len-=I[i];
+ i-=I[i];
+ } else {
+ if(len) I[i-len]=-len;
+ len=V[I[i]]+1-i;
+ split(I,V,i,len,h);
+ i+=len;
+ len=0;
+ };
+ };
+ if(len) I[i-len]=-len;
+ };
- return 0;
+ for(i=0;i<oldsize+1;i++) I[V[i]]=i;
}
-int ApplyBSDiffPatchMem(const unsigned char* old_data, ssize_t old_size,
- const char* patch_filename, ssize_t patch_offset,
- unsigned char** new_data, ssize_t* new_size) {
+static off_t matchlen(u_char *old,off_t oldsize,u_char *new,off_t newsize)
+{
+ off_t i;
- FILE* f;
- if ((f = fopen(patch_filename, "rb")) == NULL) {
- fprintf(stderr, "failed to open patch file\n");
- return 1;
- }
+ for(i=0;(i<oldsize)&&(i<newsize);i++)
+ if(old[i]!=new[i]) break;
- // File format:
- // 0 8 "BSDIFF40"
- // 8 8 X
- // 16 8 Y
- // 24 8 sizeof(newfile)
- // 32 X bzip2(control block)
- // 32+X Y bzip2(diff block)
- // 32+X+Y ??? bzip2(extra block)
- // with control block a set of triples (x,y,z) meaning "add x bytes
- // from oldfile to x bytes from the diff block; copy y bytes from the
- // extra block; seek forwards in oldfile by z bytes".
+ return i;
+}
- fseek(f, patch_offset, SEEK_SET);
+static off_t search(off_t *I,u_char *old,off_t oldsize,
+ u_char *new,off_t newsize,off_t st,off_t en,off_t *pos)
+{
+ off_t x,y;
- unsigned char header[32];
- if (fread(header, 1, 32, f) < 32) {
- fprintf(stderr, "failed to read patch file header\n");
- return 1;
- }
+ if(en-st<2) {
+ x=matchlen(old+I[st],oldsize-I[st],new,newsize);
+ y=matchlen(old+I[en],oldsize-I[en],new,newsize);
- if (memcmp(header, "BSDIFF40", 8) != 0) {
- fprintf(stderr, "corrupt bsdiff patch file header (magic number)\n");
- return 1;
- }
+ if(x>y) {
+ *pos=I[st];
+ return x;
+ } else {
+ *pos=I[en];
+ return y;
+ }
+ };
- ssize_t ctrl_len, data_len;
- ctrl_len = offtin(header+8);
- data_len = offtin(header+16);
- *new_size = offtin(header+24);
+ x=st+(en-st)/2;
+ if(memcmp(old+I[x],new,MIN(oldsize-I[x],newsize))<0) {
+ return search(I,old,oldsize,new,newsize,x,en,pos);
+ } else {
+ return search(I,old,oldsize,new,newsize,st,x,pos);
+ };
+}
- if (ctrl_len < 0 || data_len < 0 || *new_size < 0) {
- fprintf(stderr, "corrupt patch file header (data lengths)\n");
- return 1;
- }
+static void offtout(off_t x,u_char *buf)
+{
+ off_t y;
- fclose(f);
+ if(x<0) y=-x; else y=x;
- int bzerr;
+ buf[0]=y%256;y-=buf[0];
+ y=y/256;buf[1]=y%256;y-=buf[1];
+ y=y/256;buf[2]=y%256;y-=buf[2];
+ y=y/256;buf[3]=y%256;y-=buf[3];
+ y=y/256;buf[4]=y%256;y-=buf[4];
+ y=y/256;buf[5]=y%256;y-=buf[5];
+ y=y/256;buf[6]=y%256;y-=buf[6];
+ y=y/256;buf[7]=y%256;
-#define OPEN_AT(f, bzf, offset) \
- FILE* f; \
- BZFILE* bzf; \
- if ((f = fopen(patch_filename, "rb")) == NULL) { \
- fprintf(stderr, "failed to open patch file\n"); \
- return 1; \
- } \
- if (fseeko(f, offset+patch_offset, SEEK_SET)) { \
- fprintf(stderr, "failed to seek in patch file\n"); \
- return 1; \
- } \
- if ((bzf = BZ2_bzReadOpen(&bzerr, f, 0, 0, NULL, 0)) == NULL) { \
- fprintf(stderr, "failed to bzReadOpen in patch file (%d)\n", bzerr); \
- return 1; \
- }
+ if(x<0) buf[7]|=0x80;
+}
- OPEN_AT(cpf, cpfbz2, 32);
- OPEN_AT(dpf, dpfbz2, 32+ctrl_len);
- OPEN_AT(epf, epfbz2, 32+ctrl_len+data_len);
+// This is main() from bsdiff.c, with the following changes:
+//
+// - old, oldsize, new, newsize are arguments; we don't load this
+// data from files. old and new are owned by the caller; we
+// don't free them at the end.
+//
+// - the "I" block of memory is owned by the caller, who passes a
+// pointer to *I, which can be NULL. This way if we call
+// bsdiff() multiple times with the same 'old' data, we only do
+// the qsufsort() step the first time.
+//
+int bsdiff(u_char* old, off_t oldsize, off_t** IP, u_char* new, off_t newsize,
+ const char* patch_filename)
+{
+ int fd;
+ off_t *I;
+ off_t scan,pos,len;
+ off_t lastscan,lastpos,lastoffset;
+ off_t oldscore,scsc;
+ off_t s,Sf,lenf,Sb,lenb;
+ off_t overlap,Ss,lens;
+ off_t i;
+ off_t dblen,eblen;
+ u_char *db,*eb;
+ u_char buf[8];
+ u_char header[32];
+ FILE * pf;
+ BZFILE * pfbz2;
+ int bz2err;
-#undef OPEN_AT
+ if (*IP == NULL) {
+ off_t* V;
+ *IP = malloc((oldsize+1) * sizeof(off_t));
+ V = malloc((oldsize+1) * sizeof(off_t));
+ qsufsort(*IP, V, old, oldsize);
+ free(V);
+ }
+ I = *IP;
- *new_data = malloc(*new_size);
- if (*new_data == NULL) {
- fprintf(stderr, "failed to allocate %d bytes of memory for output file\n",
- (int)*new_size);
- return 1;
- }
+ if(((db=malloc(newsize+1))==NULL) ||
+ ((eb=malloc(newsize+1))==NULL)) err(1,NULL);
+ dblen=0;
+ eblen=0;
- off_t oldpos = 0, newpos = 0;
- off_t ctrl[3];
- off_t len_read;
- int i;
- unsigned char buf[8];
- while (newpos < *new_size) {
- // Read control data
- for (i = 0; i < 3; ++i) {
- len_read = BZ2_bzRead(&bzerr, cpfbz2, buf, 8);
- if (len_read < 8 || !(bzerr == BZ_OK || bzerr == BZ_STREAM_END)) {
- fprintf(stderr, "corrupt patch (read control)\n");
- return 1;
- }
- ctrl[i] = offtin(buf);
- }
+ /* Create the patch file */
+ if ((pf = fopen(patch_filename, "w")) == NULL)
+ err(1, "%s", patch_filename);
- // Sanity check
- if (newpos + ctrl[0] > *new_size) {
- fprintf(stderr, "corrupt patch (new file overrun)\n");
- return 1;
- }
+ /* Header is
+ 0 8 "BSDIFF40"
+ 8 8 length of bzip2ed ctrl block
+ 16 8 length of bzip2ed diff block
+ 24 8 length of new file */
+ /* File is
+ 0 32 Header
+ 32 ?? Bzip2ed ctrl block
+ ?? ?? Bzip2ed diff block
+ ?? ?? Bzip2ed extra block */
+ memcpy(header,"BSDIFF40",8);
+ offtout(0, header + 8);
+ offtout(0, header + 16);
+ offtout(newsize, header + 24);
+ if (fwrite(header, 32, 1, pf) != 1)
+ err(1, "fwrite(%s)", patch_filename);
- // Read diff string
- len_read = BZ2_bzRead(&bzerr, dpfbz2, *new_data + newpos, ctrl[0]);
- if (len_read < ctrl[0] || !(bzerr == BZ_OK || bzerr == BZ_STREAM_END)) {
- fprintf(stderr, "corrupt patch (read diff)\n");
- return 1;
- }
+ /* Compute the differences, writing ctrl as we go */
+ if ((pfbz2 = BZ2_bzWriteOpen(&bz2err, pf, 9, 0, 0)) == NULL)
+ errx(1, "BZ2_bzWriteOpen, bz2err = %d", bz2err);
+ scan=0;len=0;
+ lastscan=0;lastpos=0;lastoffset=0;
+ while(scan<newsize) {
+ oldscore=0;
- // Add old data to diff string
- for (i = 0; i < ctrl[0]; ++i) {
- if ((oldpos+i >= 0) && (oldpos+i < old_size)) {
- (*new_data)[newpos+i] += old_data[oldpos+i];
- }
- }
+ for(scsc=scan+=len;scan<newsize;scan++) {
+ len=search(I,old,oldsize,new+scan,newsize-scan,
+ 0,oldsize,&pos);
- // Adjust pointers
- newpos += ctrl[0];
- oldpos += ctrl[0];
+ for(;scsc<scan+len;scsc++)
+ if((scsc+lastoffset<oldsize) &&
+ (old[scsc+lastoffset] == new[scsc]))
+ oldscore++;
- // Sanity check
- if (newpos + ctrl[1] > *new_size) {
- fprintf(stderr, "corrupt patch (new file overrun)\n");
- return 1;
- }
+ if(((len==oldscore) && (len!=0)) ||
+ (len>oldscore+8)) break;
- // Read extra string
- len_read = BZ2_bzRead(&bzerr, epfbz2, *new_data + newpos, ctrl[1]);
- if (len_read < ctrl[1] || !(bzerr == BZ_OK || bzerr == BZ_STREAM_END)) {
- fprintf(stderr, "corrupt patch (read extra)\n");
- return 1;
- }
+ if((scan+lastoffset<oldsize) &&
+ (old[scan+lastoffset] == new[scan]))
+ oldscore--;
+ };
- // Adjust pointers
- newpos += ctrl[1];
- oldpos += ctrl[2];
- }
+ if((len!=oldscore) || (scan==newsize)) {
+ s=0;Sf=0;lenf=0;
+ for(i=0;(lastscan+i<scan)&&(lastpos+i<oldsize);) {
+ if(old[lastpos+i]==new[lastscan+i]) s++;
+ i++;
+ if(s*2-i>Sf*2-lenf) { Sf=s; lenf=i; };
+ };
- BZ2_bzReadClose(&bzerr, cpfbz2);
- BZ2_bzReadClose(&bzerr, dpfbz2);
- BZ2_bzReadClose(&bzerr, epfbz2);
- fclose(cpf);
- fclose(dpf);
- fclose(epf);
+ lenb=0;
+ if(scan<newsize) {
+ s=0;Sb=0;
+ for(i=1;(scan>=lastscan+i)&&(pos>=i);i++) {
+ if(old[pos-i]==new[scan-i]) s++;
+ if(s*2-i>Sb*2-lenb) { Sb=s; lenb=i; };
+ };
+ };
- return 0;
+ if(lastscan+lenf>scan-lenb) {
+ overlap=(lastscan+lenf)-(scan-lenb);
+ s=0;Ss=0;lens=0;
+ for(i=0;i<overlap;i++) {
+ if(new[lastscan+lenf-overlap+i]==
+ old[lastpos+lenf-overlap+i]) s++;
+ if(new[scan-lenb+i]==
+ old[pos-lenb+i]) s--;
+ if(s>Ss) { Ss=s; lens=i+1; };
+ };
+
+ lenf+=lens-overlap;
+ lenb-=lens;
+ };
+
+ for(i=0;i<lenf;i++)
+ db[dblen+i]=new[lastscan+i]-old[lastpos+i];
+ for(i=0;i<(scan-lenb)-(lastscan+lenf);i++)
+ eb[eblen+i]=new[lastscan+lenf+i];
+
+ dblen+=lenf;
+ eblen+=(scan-lenb)-(lastscan+lenf);
+
+ offtout(lenf,buf);
+ BZ2_bzWrite(&bz2err, pfbz2, buf, 8);
+ if (bz2err != BZ_OK)
+ errx(1, "BZ2_bzWrite, bz2err = %d", bz2err);
+
+ offtout((scan-lenb)-(lastscan+lenf),buf);
+ BZ2_bzWrite(&bz2err, pfbz2, buf, 8);
+ if (bz2err != BZ_OK)
+ errx(1, "BZ2_bzWrite, bz2err = %d", bz2err);
+
+ offtout((pos-lenb)-(lastpos+lenf),buf);
+ BZ2_bzWrite(&bz2err, pfbz2, buf, 8);
+ if (bz2err != BZ_OK)
+ errx(1, "BZ2_bzWrite, bz2err = %d", bz2err);
+
+ lastscan=scan-lenb;
+ lastpos=pos-lenb;
+ lastoffset=pos-scan;
+ };
+ };
+ BZ2_bzWriteClose(&bz2err, pfbz2, 0, NULL, NULL);
+ if (bz2err != BZ_OK)
+ errx(1, "BZ2_bzWriteClose, bz2err = %d", bz2err);
+
+ /* Compute size of compressed ctrl data */
+ if ((len = ftello(pf)) == -1)
+ err(1, "ftello");
+ offtout(len-32, header + 8);
+
+ /* Write compressed diff data */
+ if ((pfbz2 = BZ2_bzWriteOpen(&bz2err, pf, 9, 0, 0)) == NULL)
+ errx(1, "BZ2_bzWriteOpen, bz2err = %d", bz2err);
+ BZ2_bzWrite(&bz2err, pfbz2, db, dblen);
+ if (bz2err != BZ_OK)
+ errx(1, "BZ2_bzWrite, bz2err = %d", bz2err);
+ BZ2_bzWriteClose(&bz2err, pfbz2, 0, NULL, NULL);
+ if (bz2err != BZ_OK)
+ errx(1, "BZ2_bzWriteClose, bz2err = %d", bz2err);
+
+ /* Compute size of compressed diff data */
+ if ((newsize = ftello(pf)) == -1)
+ err(1, "ftello");
+ offtout(newsize - len, header + 16);
+
+ /* Write compressed extra data */
+ if ((pfbz2 = BZ2_bzWriteOpen(&bz2err, pf, 9, 0, 0)) == NULL)
+ errx(1, "BZ2_bzWriteOpen, bz2err = %d", bz2err);
+ BZ2_bzWrite(&bz2err, pfbz2, eb, eblen);
+ if (bz2err != BZ_OK)
+ errx(1, "BZ2_bzWrite, bz2err = %d", bz2err);
+ BZ2_bzWriteClose(&bz2err, pfbz2, 0, NULL, NULL);
+ if (bz2err != BZ_OK)
+ errx(1, "BZ2_bzWriteClose, bz2err = %d", bz2err);
+
+ /* Seek to the beginning, write the header, and close the file */
+ if (fseeko(pf, 0, SEEK_SET))
+ err(1, "fseeko");
+ if (fwrite(header, 32, 1, pf) != 1)
+ err(1, "fwrite(%s)", patch_filename);
+ if (fclose(pf))
+ err(1, "fclose");
+
+ /* Free the memory we used */
+ free(db);
+ free(eb);
+
+ return 0;
}
diff --git a/tools/applypatch/bspatch.c b/tools/applypatch/bspatch.c
new file mode 100644
index 0000000..d5cd617
--- /dev/null
+++ b/tools/applypatch/bspatch.c
@@ -0,0 +1,252 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// This file is a nearly line-for-line copy of bspatch.c from the
+// bsdiff-4.3 distribution; the primary differences being how the
+// input and output data are read and the error handling. Running
+// applypatch with the -l option will display the bsdiff license
+// notice.
+
+#include <stdio.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <bzlib.h>
+
+#include "mincrypt/sha.h"
+#include "applypatch.h"
+
+void ShowBSDiffLicense() {
+ puts("The bsdiff library used herein is:\n"
+ "\n"
+ "Copyright 2003-2005 Colin Percival\n"
+ "All rights reserved\n"
+ "\n"
+ "Redistribution and use in source and binary forms, with or without\n"
+ "modification, are permitted providing that the following conditions\n"
+ "are met:\n"
+ "1. Redistributions of source code must retain the above copyright\n"
+ " notice, this list of conditions and the following disclaimer.\n"
+ "2. Redistributions in binary form must reproduce the above copyright\n"
+ " notice, this list of conditions and the following disclaimer in the\n"
+ " documentation and/or other materials provided with the distribution.\n"
+ "\n"
+ "THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n"
+ "IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n"
+ "WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n"
+ "ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\n"
+ "DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n"
+ "DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n"
+ "OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n"
+ "HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n"
+ "STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\n"
+ "IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n"
+ "POSSIBILITY OF SUCH DAMAGE.\n"
+ "\n------------------\n\n"
+ "This program uses Julian R Seward's \"libbzip2\" library, available\n"
+ "from http://www.bzip.org/.\n"
+ );
+}
+
+static off_t offtin(u_char *buf)
+{
+ off_t y;
+
+ y=buf[7]&0x7F;
+ y=y*256;y+=buf[6];
+ y=y*256;y+=buf[5];
+ y=y*256;y+=buf[4];
+ y=y*256;y+=buf[3];
+ y=y*256;y+=buf[2];
+ y=y*256;y+=buf[1];
+ y=y*256;y+=buf[0];
+
+ if(buf[7]&0x80) y=-y;
+
+ return y;
+}
+
+
+int ApplyBSDiffPatch(const unsigned char* old_data, ssize_t old_size,
+ const char* patch_filename, ssize_t patch_offset,
+ SinkFn sink, void* token, SHA_CTX* ctx) {
+
+ unsigned char* new_data;
+ ssize_t new_size;
+ if (ApplyBSDiffPatchMem(old_data, old_size, patch_filename, patch_offset,
+ &new_data, &new_size) != 0) {
+ return -1;
+ }
+
+ if (sink(new_data, new_size, token) < new_size) {
+ fprintf(stderr, "short write of output: %d (%s)\n", errno, strerror(errno));
+ return 1;
+ }
+ if (ctx) {
+ SHA_update(ctx, new_data, new_size);
+ }
+ free(new_data);
+
+ return 0;
+}
+
+int ApplyBSDiffPatchMem(const unsigned char* old_data, ssize_t old_size,
+ const char* patch_filename, ssize_t patch_offset,
+ unsigned char** new_data, ssize_t* new_size) {
+
+ FILE* f;
+ if ((f = fopen(patch_filename, "rb")) == NULL) {
+ fprintf(stderr, "failed to open patch file\n");
+ return 1;
+ }
+
+ // File format:
+ // 0 8 "BSDIFF40"
+ // 8 8 X
+ // 16 8 Y
+ // 24 8 sizeof(newfile)
+ // 32 X bzip2(control block)
+ // 32+X Y bzip2(diff block)
+ // 32+X+Y ??? bzip2(extra block)
+ // with control block a set of triples (x,y,z) meaning "add x bytes
+ // from oldfile to x bytes from the diff block; copy y bytes from the
+ // extra block; seek forwards in oldfile by z bytes".
+
+ fseek(f, patch_offset, SEEK_SET);
+
+ unsigned char header[32];
+ if (fread(header, 1, 32, f) < 32) {
+ fprintf(stderr, "failed to read patch file header\n");
+ return 1;
+ }
+
+ if (memcmp(header, "BSDIFF40", 8) != 0) {
+ fprintf(stderr, "corrupt bsdiff patch file header (magic number)\n");
+ return 1;
+ }
+
+ ssize_t ctrl_len, data_len;
+ ctrl_len = offtin(header+8);
+ data_len = offtin(header+16);
+ *new_size = offtin(header+24);
+
+ if (ctrl_len < 0 || data_len < 0 || *new_size < 0) {
+ fprintf(stderr, "corrupt patch file header (data lengths)\n");
+ return 1;
+ }
+
+ fclose(f);
+
+ int bzerr;
+
+#define OPEN_AT(f, bzf, offset) \
+ FILE* f; \
+ BZFILE* bzf; \
+ if ((f = fopen(patch_filename, "rb")) == NULL) { \
+ fprintf(stderr, "failed to open patch file\n"); \
+ return 1; \
+ } \
+ if (fseeko(f, offset+patch_offset, SEEK_SET)) { \
+ fprintf(stderr, "failed to seek in patch file\n"); \
+ return 1; \
+ } \
+ if ((bzf = BZ2_bzReadOpen(&bzerr, f, 0, 0, NULL, 0)) == NULL) { \
+ fprintf(stderr, "failed to bzReadOpen in patch file (%d)\n", bzerr); \
+ return 1; \
+ }
+
+ OPEN_AT(cpf, cpfbz2, 32);
+ OPEN_AT(dpf, dpfbz2, 32+ctrl_len);
+ OPEN_AT(epf, epfbz2, 32+ctrl_len+data_len);
+
+#undef OPEN_AT
+
+ *new_data = malloc(*new_size);
+ if (*new_data == NULL) {
+ fprintf(stderr, "failed to allocate %d bytes of memory for output file\n",
+ (int)*new_size);
+ return 1;
+ }
+
+ off_t oldpos = 0, newpos = 0;
+ off_t ctrl[3];
+ off_t len_read;
+ int i;
+ unsigned char buf[8];
+ while (newpos < *new_size) {
+ // Read control data
+ for (i = 0; i < 3; ++i) {
+ len_read = BZ2_bzRead(&bzerr, cpfbz2, buf, 8);
+ if (len_read < 8 || !(bzerr == BZ_OK || bzerr == BZ_STREAM_END)) {
+ fprintf(stderr, "corrupt patch (read control)\n");
+ return 1;
+ }
+ ctrl[i] = offtin(buf);
+ }
+
+ // Sanity check
+ if (newpos + ctrl[0] > *new_size) {
+ fprintf(stderr, "corrupt patch (new file overrun)\n");
+ return 1;
+ }
+
+ // Read diff string
+ len_read = BZ2_bzRead(&bzerr, dpfbz2, *new_data + newpos, ctrl[0]);
+ if (len_read < ctrl[0] || !(bzerr == BZ_OK || bzerr == BZ_STREAM_END)) {
+ fprintf(stderr, "corrupt patch (read diff)\n");
+ return 1;
+ }
+
+ // Add old data to diff string
+ for (i = 0; i < ctrl[0]; ++i) {
+ if ((oldpos+i >= 0) && (oldpos+i < old_size)) {
+ (*new_data)[newpos+i] += old_data[oldpos+i];
+ }
+ }
+
+ // Adjust pointers
+ newpos += ctrl[0];
+ oldpos += ctrl[0];
+
+ // Sanity check
+ if (newpos + ctrl[1] > *new_size) {
+ fprintf(stderr, "corrupt patch (new file overrun)\n");
+ return 1;
+ }
+
+ // Read extra string
+ len_read = BZ2_bzRead(&bzerr, epfbz2, *new_data + newpos, ctrl[1]);
+ if (len_read < ctrl[1] || !(bzerr == BZ_OK || bzerr == BZ_STREAM_END)) {
+ fprintf(stderr, "corrupt patch (read extra)\n");
+ return 1;
+ }
+
+ // Adjust pointers
+ newpos += ctrl[1];
+ oldpos += ctrl[2];
+ }
+
+ BZ2_bzReadClose(&bzerr, cpfbz2);
+ BZ2_bzReadClose(&bzerr, dpfbz2);
+ BZ2_bzReadClose(&bzerr, epfbz2);
+ fclose(cpf);
+ fclose(dpf);
+ fclose(epf);
+
+ return 0;
+}
diff --git a/tools/applypatch/freecache.c b/tools/applypatch/freecache.c
index ab71b81..9827fda 100644
--- a/tools/applypatch/freecache.c
+++ b/tools/applypatch/freecache.c
@@ -16,7 +16,7 @@
struct dirent* de;
d = opendir("/proc");
if (d == NULL) {
- fprintf(stderr, "error opening /proc: %s\n", strerror(errno));
+ printf("error opening /proc: %s\n", strerror(errno));
return -1;
}
while ((de = readdir(d)) != 0) {
@@ -35,7 +35,7 @@
struct dirent* fdde;
fdd = opendir(path);
if (fdd == NULL) {
- fprintf(stderr, "error opening %s: %s\n", path, strerror(errno));
+ printf("error opening %s: %s\n", path, strerror(errno));
continue;
}
while ((fdde = readdir(fdd)) != 0) {
@@ -88,7 +88,7 @@
for (i = 0; i < sizeof(dirs)/sizeof(dirs[0]); ++i) {
d = opendir(dirs[i]);
if (d == NULL) {
- fprintf(stderr, "error opening %s: %s\n", dirs[i], strerror(errno));
+ printf("error opening %s: %s\n", dirs[i], strerror(errno));
continue;
}
@@ -143,7 +143,7 @@
if (entries == 0) {
// nothing we can delete to free up space!
- fprintf(stderr, "no files can be deleted to free space on /cache\n");
+ printf("no files can be deleted to free space on /cache\n");
return -1;
}
diff --git a/tools/applypatch/imgdiff.c b/tools/applypatch/imgdiff.c
index 51835b4..6b9ebee 100644
--- a/tools/applypatch/imgdiff.c
+++ b/tools/applypatch/imgdiff.c
@@ -119,6 +119,7 @@
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <sys/types.h>
#include "zlib.h"
#include "imgdiff.h"
@@ -134,6 +135,8 @@
size_t source_start;
size_t source_len;
+ off_t* I; // used by bsdiff
+
// --- for CHUNK_DEFLATE chunks only: ---
// original (compressed) deflate data
@@ -167,19 +170,23 @@
}
}
+// from bsdiff.c
+int bsdiff(u_char* old, off_t oldsize, off_t** IP, u_char* new, off_t newsize,
+ const char* patch_filename);
+
unsigned char* ReadZip(const char* filename,
int* num_chunks, ImageChunk** chunks,
int include_pseudo_chunk) {
struct stat st;
if (stat(filename, &st) != 0) {
- fprintf(stderr, "failed to stat \"%s\": %s\n", filename, strerror(errno));
+ printf("failed to stat \"%s\": %s\n", filename, strerror(errno));
return NULL;
}
unsigned char* img = malloc(st.st_size);
FILE* f = fopen(filename, "rb");
if (fread(img, 1, st.st_size, f) != st.st_size) {
- fprintf(stderr, "failed to read \"%s\" %s\n", filename, strerror(errno));
+ printf("failed to read \"%s\" %s\n", filename, strerror(errno));
fclose(f);
return NULL;
}
@@ -196,7 +203,7 @@
}
// double-check: this archive consists of a single "disk"
if (!(img[i+4] == 0 && img[i+5] == 0 && img[i+6] == 0 && img[i+7] == 0)) {
- fprintf(stderr, "can't process multi-disk archive\n");
+ printf("can't process multi-disk archive\n");
return NULL;
}
@@ -209,7 +216,7 @@
unsigned char* cd = img+cdoffset;
for (i = 0; i < cdcount; ++i) {
if (!(cd[0] == 0x50 && cd[1] == 0x4b && cd[2] == 0x01 && cd[3] == 0x02)) {
- fprintf(stderr, "bad central directory entry %d\n", i);
+ printf("bad central directory entry %d\n", i);
return NULL;
}
@@ -236,12 +243,12 @@
unsigned char* lh = img + hoffset;
if (!(lh[0] == 0x50 && lh[1] == 0x4b && lh[2] == 0x03 && lh[3] == 0x04)) {
- fprintf(stderr, "bad local file header entry %d\n", i);
+ printf("bad local file header entry %d\n", i);
return NULL;
}
if (Read2(lh+26) != nlen || memcmp(lh+30, filename, nlen) != 0) {
- fprintf(stderr, "central dir filename doesn't match local header\n");
+ printf("central dir filename doesn't match local header\n");
return NULL;
}
@@ -278,6 +285,7 @@
curr->len = st.st_size;
curr->data = img;
curr->filename = NULL;
+ curr->I = NULL;
++curr;
++*num_chunks;
}
@@ -292,6 +300,7 @@
curr->deflate_len = temp_entries[nextentry].deflate_len;
curr->deflate_data = img + pos;
curr->filename = temp_entries[nextentry].filename;
+ curr->I = NULL;
curr->len = temp_entries[nextentry].uncomp_len;
curr->data = malloc(curr->len);
@@ -311,7 +320,7 @@
strm.next_out = curr->data;
ret = inflate(&strm, Z_NO_FLUSH);
if (ret != Z_STREAM_END) {
- fprintf(stderr, "failed to inflate \"%s\"; %d\n", curr->filename, ret);
+ printf("failed to inflate \"%s\"; %d\n", curr->filename, ret);
return NULL;
}
@@ -336,6 +345,7 @@
}
curr->data = img + pos;
curr->filename = NULL;
+ curr->I = NULL;
pos += curr->len;
++*num_chunks;
@@ -359,14 +369,14 @@
int* num_chunks, ImageChunk** chunks) {
struct stat st;
if (stat(filename, &st) != 0) {
- fprintf(stderr, "failed to stat \"%s\": %s\n", filename, strerror(errno));
+ printf("failed to stat \"%s\": %s\n", filename, strerror(errno));
return NULL;
}
unsigned char* img = malloc(st.st_size + 4);
FILE* f = fopen(filename, "rb");
if (fread(img, 1, st.st_size, f) != st.st_size) {
- fprintf(stderr, "failed to read \"%s\" %s\n", filename, strerror(errno));
+ printf("failed to read \"%s\" %s\n", filename, strerror(errno));
fclose(f);
return NULL;
}
@@ -400,6 +410,7 @@
curr->type = CHUNK_NORMAL;
curr->len = GZIP_HEADER_LEN;
curr->data = p;
+ curr->I = NULL;
pos += curr->len;
p += curr->len;
@@ -407,6 +418,7 @@
curr->type = CHUNK_DEFLATE;
curr->filename = NULL;
+ curr->I = NULL;
// We must decompress this chunk in order to discover where it
// ends, and so we can put the uncompressed data and its length
@@ -452,6 +464,7 @@
curr->start = pos;
curr->len = GZIP_FOOTER_LEN;
curr->data = img+pos;
+ curr->I = NULL;
pos += curr->len;
p += curr->len;
@@ -463,7 +476,7 @@
// the decompression.
size_t footer_size = Read4(p-4);
if (footer_size != curr[-2].len) {
- fprintf(stderr, "Error: footer size %d != decompressed size %d\n",
+ printf("Error: footer size %d != decompressed size %d\n",
footer_size, curr[-2].len);
free(img);
return NULL;
@@ -475,6 +488,7 @@
*chunks = realloc(*chunks, *num_chunks * sizeof(ImageChunk));
ImageChunk* curr = *chunks + (*num_chunks-1);
curr->start = pos;
+ curr->I = NULL;
// 'pos' is not the offset of the start of a gzip chunk, so scan
// forward until we find a gzip header.
@@ -508,7 +522,7 @@
size_t p = 0;
#if 0
- fprintf(stderr, "trying %d %d %d %d %d\n",
+ printf("trying %d %d %d %d %d\n",
chunk->level, chunk->method, chunk->windowBits,
chunk->memLevel, chunk->strategy);
#endif
@@ -551,7 +565,7 @@
*/
int ReconstructDeflateChunk(ImageChunk* chunk) {
if (chunk->type != CHUNK_DEFLATE) {
- fprintf(stderr, "attempt to reconstruct non-deflate chunk\n");
+ printf("attempt to reconstruct non-deflate chunk\n");
return -1;
}
@@ -591,49 +605,18 @@
}
}
- char stemp[] = "/tmp/imgdiff-src-XXXXXX";
- char ttemp[] = "/tmp/imgdiff-tgt-XXXXXX";
char ptemp[] = "/tmp/imgdiff-patch-XXXXXX";
- mkstemp(stemp);
- mkstemp(ttemp);
mkstemp(ptemp);
- FILE* f = fopen(stemp, "wb");
- if (f == NULL) {
- fprintf(stderr, "failed to open src chunk %s: %s\n",
- stemp, strerror(errno));
- return NULL;
- }
- if (fwrite(src->data, 1, src->len, f) != src->len) {
- fprintf(stderr, "failed to write src chunk to %s: %s\n",
- stemp, strerror(errno));
- return NULL;
- }
- fclose(f);
-
- f = fopen(ttemp, "wb");
- if (f == NULL) {
- fprintf(stderr, "failed to open tgt chunk %s: %s\n",
- ttemp, strerror(errno));
- return NULL;
- }
- if (fwrite(tgt->data, 1, tgt->len, f) != tgt->len) {
- fprintf(stderr, "failed to write tgt chunk to %s: %s\n",
- ttemp, strerror(errno));
- return NULL;
- }
- fclose(f);
-
- char cmd[200];
- sprintf(cmd, "bsdiff %s %s %s", stemp, ttemp, ptemp);
- if (system(cmd) != 0) {
- fprintf(stderr, "failed to run bsdiff: %s\n", strerror(errno));
+ int r = bsdiff(src->data, src->len, &(src->I), tgt->data, tgt->len, ptemp);
+ if (r != 0) {
+ printf("bsdiff() failed: %d\n", r);
return NULL;
}
struct stat st;
if (stat(ptemp, &st) != 0) {
- fprintf(stderr, "failed to stat patch file %s: %s\n",
+ printf("failed to stat patch file %s: %s\n",
ptemp, strerror(errno));
return NULL;
}
@@ -641,8 +624,6 @@
unsigned char* data = malloc(st.st_size);
if (tgt->type == CHUNK_NORMAL && tgt->len <= st.st_size) {
- unlink(stemp);
- unlink(ttemp);
unlink(ptemp);
tgt->type = CHUNK_RAW;
@@ -652,19 +633,17 @@
*size = st.st_size;
- f = fopen(ptemp, "rb");
+ FILE* f = fopen(ptemp, "rb");
if (f == NULL) {
- fprintf(stderr, "failed to open patch %s: %s\n", ptemp, strerror(errno));
+ printf("failed to open patch %s: %s\n", ptemp, strerror(errno));
return NULL;
}
if (fread(data, 1, st.st_size, f) != st.st_size) {
- fprintf(stderr, "failed to read patch %s: %s\n", ptemp, strerror(errno));
+ printf("failed to read patch %s: %s\n", ptemp, strerror(errno));
return NULL;
}
fclose(f);
- unlink(stemp);
- unlink(ttemp);
unlink(ptemp);
tgt->source_start = src->start;
@@ -712,7 +691,7 @@
memcmp(a->deflate_data, b->deflate_data, a->deflate_len) == 0;
default:
- fprintf(stderr, "unknown chunk type %d\n", a->type);
+ printf("unknown chunk type %d\n", a->type);
return 0;
}
}
@@ -784,10 +763,18 @@
return NULL;
}
+void DumpChunks(ImageChunk* chunks, int num_chunks) {
+ int i;
+ for (i = 0; i < num_chunks; ++i) {
+ printf("chunk %d: type %d start %d len %d\n",
+ i, chunks[i].type, chunks[i].start, chunks[i].len);
+ }
+}
+
int main(int argc, char** argv) {
if (argc != 4 && argc != 5) {
usage:
- fprintf(stderr, "usage: %s [-z] <src-img> <tgt-img> <patch-file>\n",
+ printf("usage: %s [-z] <src-img> <tgt-img> <patch-file>\n",
argv[0]);
return 2;
}
@@ -809,34 +796,49 @@
if (zip_mode) {
if (ReadZip(argv[1], &num_src_chunks, &src_chunks, 1) == NULL) {
- fprintf(stderr, "failed to break apart source zip file\n");
+ printf("failed to break apart source zip file\n");
return 1;
}
if (ReadZip(argv[2], &num_tgt_chunks, &tgt_chunks, 0) == NULL) {
- fprintf(stderr, "failed to break apart target zip file\n");
+ printf("failed to break apart target zip file\n");
return 1;
}
} else {
if (ReadImage(argv[1], &num_src_chunks, &src_chunks) == NULL) {
- fprintf(stderr, "failed to break apart source image\n");
+ printf("failed to break apart source image\n");
return 1;
}
if (ReadImage(argv[2], &num_tgt_chunks, &tgt_chunks) == NULL) {
- fprintf(stderr, "failed to break apart target image\n");
+ printf("failed to break apart target image\n");
return 1;
}
// Verify that the source and target images have the same chunk
// structure (ie, the same sequence of deflate and normal chunks).
+ if (!zip_mode) {
+ // Merge the gzip header and footer in with any adjacent
+ // normal chunks.
+ MergeAdjacentNormalChunks(tgt_chunks, &num_tgt_chunks);
+ MergeAdjacentNormalChunks(src_chunks, &num_src_chunks);
+ }
+
if (num_src_chunks != num_tgt_chunks) {
- fprintf(stderr, "source and target don't have same number of chunks!\n");
+ printf("source and target don't have same number of chunks!\n");
+ printf("source chunks:\n");
+ DumpChunks(src_chunks, num_src_chunks);
+ printf("target chunks:\n");
+ DumpChunks(tgt_chunks, num_tgt_chunks);
return 1;
}
for (i = 0; i < num_src_chunks; ++i) {
if (src_chunks[i].type != tgt_chunks[i].type) {
- fprintf(stderr, "source and target don't have same chunk "
+ printf("source and target don't have same chunk "
"structure! (chunk %d)\n", i);
+ printf("source chunks:\n");
+ DumpChunks(src_chunks, num_src_chunks);
+ printf("target chunks:\n");
+ DumpChunks(tgt_chunks, num_tgt_chunks);
return 1;
}
}
@@ -899,7 +901,7 @@
MergeAdjacentNormalChunks(src_chunks, &num_src_chunks);
if (num_src_chunks != num_tgt_chunks) {
// This shouldn't happen.
- fprintf(stderr, "merging normal chunks went awry\n");
+ printf("merging normal chunks went awry\n");
return 1;
}
}
diff --git a/tools/applypatch/imgpatch.c b/tools/applypatch/imgpatch.c
index 74b041f..5322817 100644
--- a/tools/applypatch/imgpatch.c
+++ b/tools/applypatch/imgpatch.c
@@ -40,13 +40,13 @@
SinkFn sink, void* token, SHA_CTX* ctx) {
FILE* f;
if ((f = fopen(patch_filename, "rb")) == NULL) {
- fprintf(stderr, "failed to open patch file\n");
+ printf("failed to open patch file\n");
return -1;
}
unsigned char header[12];
if (fread(header, 1, 12, f) != 12) {
- fprintf(stderr, "failed to read patch file header\n");
+ printf("failed to read patch file header\n");
return -1;
}
@@ -54,7 +54,7 @@
// IMGDIFF2 uses CHUNK_NORMAL, CHUNK_DEFLATE, and CHUNK_RAW.
if (memcmp(header, "IMGDIFF", 7) != 0 ||
(header[7] != '1' && header[7] != '2')) {
- fprintf(stderr, "corrupt patch file header (magic number)\n");
+ printf("corrupt patch file header (magic number)\n");
return -1;
}
@@ -65,7 +65,7 @@
// each chunk's header record starts with 4 bytes.
unsigned char chunk[4];
if (fread(chunk, 1, 4, f) != 4) {
- fprintf(stderr, "failed to read chunk %d record\n", i);
+ printf("failed to read chunk %d record\n", i);
return -1;
}
@@ -74,7 +74,7 @@
if (type == CHUNK_NORMAL) {
unsigned char normal_header[24];
if (fread(normal_header, 1, 24, f) != 24) {
- fprintf(stderr, "failed to read chunk %d normal header data\n", i);
+ printf("failed to read chunk %d normal header data\n", i);
return -1;
}
@@ -82,7 +82,7 @@
size_t src_len = Read8(normal_header+8);
size_t patch_offset = Read8(normal_header+16);
- fprintf(stderr, "CHUNK %d: normal patch offset %d\n", i, patch_offset);
+ printf("CHUNK %d: normal patch offset %d\n", i, patch_offset);
ApplyBSDiffPatch(old_data + src_start, src_len,
patch_filename, patch_offset,
@@ -98,14 +98,14 @@
// in their chunk header.
unsigned char* gzip = malloc(64);
if (fread(gzip, 1, 64, f) != 64) {
- fprintf(stderr, "failed to read chunk %d initial gzip header data\n",
+ printf("failed to read chunk %d initial gzip header data\n",
i);
return -1;
}
size_t gzip_header_len = Read4(gzip+60);
gzip = realloc(gzip, 64 + gzip_header_len + 8);
if (fread(gzip+64, 1, gzip_header_len+8, f) != gzip_header_len+8) {
- fprintf(stderr, "failed to read chunk %d remaining gzip header data\n",
+ printf("failed to read chunk %d remaining gzip header data\n",
i);
return -1;
}
@@ -122,14 +122,14 @@
int gz_memLevel = Read4(gzip+52);
int gz_strategy = Read4(gzip+56);
- fprintf(stderr, "CHUNK %d: gzip patch offset %d\n", i, patch_offset);
+ printf("CHUNK %d: gzip patch offset %d\n", i, patch_offset);
// Decompress the source data; the chunk header tells us exactly
// how big we expect it to be when decompressed.
unsigned char* expanded_source = malloc(expanded_len);
if (expanded_source == NULL) {
- fprintf(stderr, "failed to allocate %d bytes for expanded_source\n",
+ printf("failed to allocate %d bytes for expanded_source\n",
expanded_len);
return -1;
}
@@ -146,7 +146,7 @@
int ret;
ret = inflateInit2(&strm, -15);
if (ret != Z_OK) {
- fprintf(stderr, "failed to init source inflation: %d\n", ret);
+ printf("failed to init source inflation: %d\n", ret);
return -1;
}
@@ -154,12 +154,12 @@
// data, we expect one call to inflate() to suffice.
ret = inflate(&strm, Z_SYNC_FLUSH);
if (ret != Z_STREAM_END) {
- fprintf(stderr, "source inflation returned %d\n", ret);
+ printf("source inflation returned %d\n", ret);
return -1;
}
// We should have filled the output buffer exactly.
if (strm.avail_out != 0) {
- fprintf(stderr, "source inflation short by %d bytes\n", strm.avail_out);
+ printf("source inflation short by %d bytes\n", strm.avail_out);
return -1;
}
inflateEnd(&strm);
@@ -208,7 +208,7 @@
size_t have = temp_size - strm.avail_out;
if (sink(temp_data, have, token) != have) {
- fprintf(stderr, "failed to write %d compressed bytes to output\n",
+ printf("failed to write %d compressed bytes to output\n",
have);
return -1;
}
@@ -226,29 +226,29 @@
} else if (type == CHUNK_RAW) {
unsigned char raw_header[4];
if (fread(raw_header, 1, 4, f) != 4) {
- fprintf(stderr, "failed to read chunk %d raw header data\n", i);
+ printf("failed to read chunk %d raw header data\n", i);
return -1;
}
size_t data_len = Read4(raw_header);
- fprintf(stderr, "CHUNK %d: raw data %d\n", i, data_len);
+ printf("CHUNK %d: raw data %d\n", i, data_len);
unsigned char* temp = malloc(data_len);
if (fread(temp, 1, data_len, f) != data_len) {
- fprintf(stderr, "failed to read chunk %d raw data\n", i);
+ printf("failed to read chunk %d raw data\n", i);
return -1;
}
SHA_update(ctx, temp, data_len);
if (sink(temp, data_len, token) != data_len) {
- fprintf(stderr, "failed to write chunk %d raw data\n", i);
+ printf("failed to write chunk %d raw data\n", i);
return -1;
}
} else if (type == CHUNK_DEFLATE) {
// deflate chunks have an additional 60 bytes in their chunk header.
unsigned char deflate_header[60];
if (fread(deflate_header, 1, 60, f) != 60) {
- fprintf(stderr, "failed to read chunk %d deflate header data\n", i);
+ printf("failed to read chunk %d deflate header data\n", i);
return -1;
}
@@ -263,14 +263,14 @@
int memLevel = Read4(deflate_header+52);
int strategy = Read4(deflate_header+56);
- fprintf(stderr, "CHUNK %d: deflate patch offset %d\n", i, patch_offset);
+ printf("CHUNK %d: deflate patch offset %d\n", i, patch_offset);
// Decompress the source data; the chunk header tells us exactly
// how big we expect it to be when decompressed.
unsigned char* expanded_source = malloc(expanded_len);
if (expanded_source == NULL) {
- fprintf(stderr, "failed to allocate %d bytes for expanded_source\n",
+ printf("failed to allocate %d bytes for expanded_source\n",
expanded_len);
return -1;
}
@@ -287,7 +287,7 @@
int ret;
ret = inflateInit2(&strm, -15);
if (ret != Z_OK) {
- fprintf(stderr, "failed to init source inflation: %d\n", ret);
+ printf("failed to init source inflation: %d\n", ret);
return -1;
}
@@ -295,12 +295,12 @@
// data, we expect one call to inflate() to suffice.
ret = inflate(&strm, Z_SYNC_FLUSH);
if (ret != Z_STREAM_END) {
- fprintf(stderr, "source inflation returned %d\n", ret);
+ printf("source inflation returned %d\n", ret);
return -1;
}
// We should have filled the output buffer exactly.
if (strm.avail_out != 0) {
- fprintf(stderr, "source inflation short by %d bytes\n", strm.avail_out);
+ printf("source inflation short by %d bytes\n", strm.avail_out);
return -1;
}
inflateEnd(&strm);
@@ -344,7 +344,7 @@
size_t have = temp_size - strm.avail_out;
if (sink(temp_data, have, token) != have) {
- fprintf(stderr, "failed to write %d compressed bytes to output\n",
+ printf("failed to write %d compressed bytes to output\n",
have);
return -1;
}
@@ -355,7 +355,7 @@
free(temp_data);
free(uncompressed_target_data);
} else {
- fprintf(stderr, "patch chunk %d is unknown type %d\n", i, type);
+ printf("patch chunk %d is unknown type %d\n", i, type);
return -1;
}
}
diff --git a/tools/applypatch/main.c b/tools/applypatch/main.c
index e25c730..e08f5c1 100644
--- a/tools/applypatch/main.c
+++ b/tools/applypatch/main.c
@@ -44,7 +44,7 @@
int main(int argc, char** argv) {
int result = applypatch(argc, argv);
if (result == 2) {
- fprintf(stderr,
+ printf(
"usage: %s <src-file> <tgt-file> <tgt-sha1> <tgt-size> "
"[<src-sha1>:<patch> ...]\n"
" or %s -c <file> [<sha1> ...]\n"
diff --git a/tools/apriori/prelinkmap.c b/tools/apriori/prelinkmap.c
index 739c181..9fb00e4 100644
--- a/tools/apriori/prelinkmap.c
+++ b/tools/apriori/prelinkmap.c
@@ -7,11 +7,14 @@
typedef struct mapentry mapentry;
+#define MAX_ALIASES 10
+
struct mapentry
{
mapentry *next;
unsigned base;
- char name[0];
+ char *names[MAX_ALIASES];
+ int num_names;
};
static mapentry *maplist = 0;
@@ -22,14 +25,13 @@
*/
#define PRELINK_MIN 0x90000000
-#define PRELINK_MAX 0xB0000000
+#define PRELINK_MAX 0xBFFFFFFF
void pm_init(const char *file)
{
unsigned line = 0;
char buf[256];
char *x;
- unsigned n;
FILE *fp;
mapentry *me;
unsigned last = -1UL;
@@ -65,26 +67,52 @@
continue;
}
- n = strtoul(x, 0, 16);
- /* Note that this is not the only bounds check. If a library's size
- exceeds its slot as defined in the prelink map, the prelinker will
- exit with an error. See pm_report_library_size_in_memory().
- */
- FAILIF((n < PRELINK_MIN) || (n > PRELINK_MAX),
- "%s:%d base 0x%08x out of range.\n",
- file, line, n);
-
- me = malloc(sizeof(mapentry) + strlen(buf) + 1);
- FAILIF(me == NULL, "Out of memory parsing %s\n", file);
+ if (isalpha(*x)) {
+ /* Assume that this is an alias, and look through the list of
+ already-installed libraries.
+ */
+ me = maplist;
+ while(me) {
+ /* The strlen() call ignores the newline at the end of x */
+ if (!strncmp(me->names[0], x, strlen(me->names[0]))) {
+ PRINT("Aliasing library %s to %s at %08x\n",
+ buf, x, me->base);
+ break;
+ }
+ me = me->next;
+ }
+ FAILIF(!me, "Nonexistent alias %s -> %s\n", buf, x);
+ }
+ else {
+ unsigned n = strtoul(x, 0, 16);
+ /* Note that this is not the only bounds check. If a library's
+ size exceeds its slot as defined in the prelink map, the
+ prelinker will exit with an error. See
+ pm_report_library_size_in_memory().
+ */
+ FAILIF((n < PRELINK_MIN) || (n > PRELINK_MAX),
+ "%s:%d base 0x%08x out of range.\n",
+ file, line, n);
- FAILIF(last <= n, "The prelink map is not in descending order "
- "at entry %s (%08x)!\n", buf, n);
- last = n;
-
- me->base = n;
- strcpy(me->name, buf);
- me->next = maplist;
- maplist = me;
+ me = malloc(sizeof(mapentry));
+ FAILIF(me == NULL, "Out of memory parsing %s\n", file);
+
+ FAILIF(last <= n, "The prelink map is not in descending order "
+ "at entry %s (%08x)!\n", buf, n);
+ last = n;
+
+ me->base = n;
+ me->next = maplist;
+ me->num_names = 0;
+ maplist = me;
+ }
+
+ FAILIF(me->num_names >= MAX_ALIASES,
+ "Too many aliases for library %s, maximum is %d.\n",
+ me->names[0],
+ MAX_ALIASES);
+ me->names[me->num_names] = strdup(buf);
+ me->num_names++;
}
fclose(fp);
@@ -99,41 +127,44 @@
{
char *x;
mapentry *me;
+ int n;
x = strrchr(name,'/');
if(x) name = x+1;
for(me = maplist; me; me = me->next){
- if(!strcmp(name, me->name)) {
- off_t slot = me->next ? me->next->base : PRELINK_MAX;
- slot -= me->base;
- FAILIF(fsize > slot,
- "prelink map error: library %s@0x%08x is too big "
- "at %lld bytes, it runs %lld bytes into "
- "library %s@0x%08x!\n",
- me->name, me->base, fsize, fsize - slot,
- me->next->name, me->next->base);
- break;
+ for (n = 0; n < me->num_names; n++) {
+ if(!strcmp(name, me->names[n])) {
+ off_t slot = me->next ? me->next->base : PRELINK_MAX;
+ slot -= me->base;
+ FAILIF(fsize > slot,
+ "prelink map error: library %s@0x%08x is too big "
+ "at %lld bytes, it runs %lld bytes into "
+ "library %s@0x%08x!\n",
+ me->names[0], me->base, fsize, fsize - slot,
+ me->next->names[0], me->next->base);
+ return;
+ }
}
}
- FAILIF(!me,"library '%s' not in prelink map\n", name);
+ FAILIF(1, "library '%s' not in prelink map\n", name);
}
unsigned pm_get_next_link_address(const char *lookup_name)
{
char *x;
mapentry *me;
+ int n;
x = strrchr(lookup_name,'/');
if(x) lookup_name = x+1;
- for(me = maplist; me; me = me->next){
- if(!strcmp(lookup_name, me->name)) {
- return me->base;
- }
- }
-
- FAILIF(1==1,"library '%s' not in prelink map\n", lookup_name);
+ for(me = maplist; me; me = me->next)
+ for (n = 0; n < me->num_names; n++)
+ if(!strcmp(lookup_name, me->names[n]))
+ return me->base;
+
+ FAILIF(1, "library '%s' not in prelink map\n", lookup_name);
return 0;
}
diff --git a/tools/atree/fs.cpp b/tools/atree/fs.cpp
index 00f44c2..9971879 100644
--- a/tools/atree/fs.cpp
+++ b/tools/atree/fs.cpp
@@ -108,6 +108,10 @@
{
int err;
size_t pos = 0;
+ // For absolute pathnames, that starts with leading '/'
+ // use appropriate initial value.
+ if (path.length() != 0 and path[0] == '/') pos++;
+
while (true) {
pos = path.find('/', pos);
string p = path.substr(0, pos);
diff --git a/tools/buildinfo.sh b/tools/buildinfo.sh
index 5c738a2..6c85149 100755
--- a/tools/buildinfo.sh
+++ b/tools/buildinfo.sh
@@ -21,9 +21,13 @@
echo "ro.product.device=$TARGET_DEVICE"
echo "ro.product.board=$TARGET_BOOTLOADER_BOARD_NAME"
echo "ro.product.cpu.abi=$TARGET_CPU_ABI"
+if [ -n "$TARGET_CPU_ABI2" ] ; then
+ echo "ro.product.cpu.abi2=$TARGET_CPU_ABI2"
+fi
echo "ro.product.manufacturer=$PRODUCT_MANUFACTURER"
echo "ro.product.locale.language=$PRODUCT_DEFAULT_LANGUAGE"
echo "ro.product.locale.region=$PRODUCT_DEFAULT_REGION"
+echo "ro.wifi.channels=$PRODUCT_DEFAULT_WIFI_CHANNELS"
echo "ro.board.platform=$TARGET_BOARD_PLATFORM"
echo "# ro.build.product is obsolete; use ro.product.device"
diff --git a/tools/dexpreopt/Config.mk b/tools/dexpreopt/Config.mk
index c6639b2..443b8c9 100644
--- a/tools/dexpreopt/Config.mk
+++ b/tools/dexpreopt/Config.mk
@@ -77,6 +77,13 @@
$(shell echo "$(p) $(PACKAGES.$(p).CERTIFICATE) $(PACKAGES.$(p).PRIVATE_KEY)" >> $(dexpreopt_package_certs_file)))
endif
+# The kernel used for ARMv7 system images is different
+ifeq ($(TARGET_ARCH_VARIANT),armv7-a)
+BUILD_DEXPREOPT_KERNEL := prebuilt/android-arm/kernel/kernel-qemu-armv7
+else
+BUILD_DEXPREOPT_KERNEL := prebuilt/android-arm/kernel/kernel-qemu
+endif
+
# Build an optimized image from the unoptimized image
BUILT_DEXPREOPT_SYSTEMIMAGE := $(intermediates)/system.img
$(BUILT_DEXPREOPT_SYSTEMIMAGE): $(BUILT_SYSTEMIMAGE_UNOPT)
@@ -99,7 +106,7 @@
$(hide) \
PATH=$(HOST_OUT_EXECUTABLES):$$PATH \
$(DEXPREOPT) \
- --kernel prebuilt/android-arm/kernel/kernel-qemu \
+ --kernel $(BUILD_DEXPREOPT_KERNEL) \
--ramdisk $(BUILT_DEXPREOPT_RAMDISK) \
--image $(BUILT_SYSTEMIMAGE_UNOPT) \
--system $(PRODUCT_OUT) \
diff --git a/tools/droiddoc/src/AnnotationInstanceInfo.java b/tools/droiddoc/src/AnnotationInstanceInfo.java
index 07d4aa3..c4abc7e 100644
--- a/tools/droiddoc/src/AnnotationInstanceInfo.java
+++ b/tools/droiddoc/src/AnnotationInstanceInfo.java
@@ -35,6 +35,7 @@
return mElementValues;
}
+ @Override
public String toString()
{
StringBuilder str = new StringBuilder();
diff --git a/tools/droiddoc/src/AttrTagInfo.java b/tools/droiddoc/src/AttrTagInfo.java
index abc5452..7f1b4d9 100644
--- a/tools/droiddoc/src/AttrTagInfo.java
+++ b/tools/droiddoc/src/AttrTagInfo.java
@@ -98,7 +98,8 @@
public FieldInfo reference() {
return REF_COMMAND.equals(mCommand) ? mRefField : null;
}
-
+
+ @Override
public String name() {
return NAME_COMMAND.equals(mCommand) ? mAttrName : null;
}
@@ -107,6 +108,7 @@
return DESCRIPTION_COMMAND.equals(mCommand) ? mDescrComment : null;
}
+ @Override
public void makeHDF(HDF data, String base)
{
super.makeHDF(data, base);
diff --git a/tools/droiddoc/src/ClassInfo.java b/tools/droiddoc/src/ClassInfo.java
index 869142e..f3f11de 100644
--- a/tools/droiddoc/src/ClassInfo.java
+++ b/tools/droiddoc/src/ClassInfo.java
@@ -101,7 +101,7 @@
mSelfFields = null;
mSelfAttributes = null;
mDeprecatedKnown = false;
-
+
Arrays.sort(mEnumConstants, FieldInfo.comparator);
Arrays.sort(mInnerClasses, ClassInfo.comparator);
}
@@ -111,16 +111,16 @@
// objects
selfAttributes();
}
-
+
public void init3(TypeInfo[] types, ClassInfo[] realInnerClasses){
mTypeParameters = types;
mRealInnerClasses = realInnerClasses;
}
-
+
public ClassInfo[] getRealInnerClasses(){
return mRealInnerClasses;
}
-
+
public TypeInfo[] getTypeParameters(){
return mTypeParameters;
}
@@ -146,6 +146,7 @@
}
}
+ @Override
public ContainerInfo parent()
{
return this;
@@ -351,7 +352,7 @@
{
return comment().briefTags();
}
-
+
public boolean isDeprecated() {
boolean deprecated = false;
if (!mDeprecatedKnown) {
@@ -551,7 +552,7 @@
public MethodInfo[] allSelfMethods() {
return mAllSelfMethods;
}
-
+
public void addMethod(MethodInfo method) {
MethodInfo[] methods = new MethodInfo[mAllSelfMethods.length + 1];
int i = 0;
@@ -596,7 +597,7 @@
}
}
}
-
+
//constructors too
for (MethodInfo m: constructors()) {
for (AttrTagInfo tag: m.comment().attrTags()) {
@@ -863,6 +864,7 @@
data.setValue(base + ".kind", this.kind());
TagInfo.makeHDF(data, base + ".shortDescr", this.firstSentenceTags());
TagInfo.makeHDF(data, base + ".deprecated", deprecatedTags());
+ data.setValue(base + ".since", getSince());
}
/**
@@ -1135,7 +1137,11 @@
if (kind != null) {
data.setValue(base + ".kind", kind);
}
-
+
+ if (cl.mIsIncluded) {
+ data.setValue(base + ".included", "true");
+ }
+
// xml attributes
i=0;
for (AttributeInfo attr: cl.selfAttributes()) {
@@ -1169,6 +1175,7 @@
}
}
+ @Override
public boolean isHidden()
{
int val = mHidden;
@@ -1300,7 +1307,7 @@
return f;
}
}
-
+
// then look at our enum constants (these are really fields, maybe
// they should be mixed into fields(). not sure)
for (FieldInfo f: enumConstants()) {
@@ -1345,11 +1352,11 @@
return false;
}
}
-
+
public void setNonWrittenConstructors(MethodInfo[] nonWritten) {
mNonWrittenConstructors = nonWritten;
}
-
+
public MethodInfo[] getNonWrittenConstructors() {
return mNonWrittenConstructors;
}
@@ -1376,23 +1383,24 @@
}
return null;
}
-
+
public void setHiddenMethods(MethodInfo[] mInfo){
mHiddenMethods = mInfo;
}
public MethodInfo[] getHiddenMethods(){
return mHiddenMethods;
}
+ @Override
public String toString(){
return this.qualifiedName();
}
-
+
public void setReasonIncluded(String reason) {
mReasonIncluded = reason;
}
-
+
public String getReasonIncluded() {
- return mReasonIncluded;
+ return mReasonIncluded;
}
private ClassDoc mClass;
diff --git a/tools/droiddoc/src/Comment.java b/tools/droiddoc/src/Comment.java
index 3f1bf6c..553cdf2 100644
--- a/tools/droiddoc/src/Comment.java
+++ b/tools/droiddoc/src/Comment.java
@@ -157,7 +157,7 @@
else if (name.equals("@literal")) {
mInlineTagsList.add(new LiteralTagInfo(name, name, text, pos));
}
- else if (name.equals("@hide") || name.equals("@doconly")) {
+ else if (name.equals("@hide") || name.equals("@pending") || name.equals("@doconly")) {
// nothing
}
else if (name.equals("@attr")) {
@@ -206,7 +206,7 @@
for (int i=0; i<N; i++) {
if (mInlineTagsList.get(i).name().equals("@more")) {
more = i;
- }
+ }
}
if (more >= 0) {
for (int i=0; i<more; i++) {
@@ -225,7 +225,7 @@
}
}
mBriefTagsList.add(t);
-
+
}
}
}
@@ -307,12 +307,12 @@
mHidden = 0;
return false;
}
- boolean b = mText.indexOf("@hide") >= 0;
+ boolean b = mText.indexOf("@hide") >= 0 || mText.indexOf("@pending") >= 0;
mHidden = b ? 1 : 0;
return b;
}
}
-
+
public boolean isDocOnly() {
if (mDocOnly >= 0) {
return mDocOnly != 0;
@@ -391,5 +391,5 @@
ArrayList<TagInfo> mUndeprecateTagsList = new ArrayList<TagInfo>();
ArrayList<AttrTagInfo> mAttrTagsList = new ArrayList<AttrTagInfo>();
-
+
}
diff --git a/tools/droiddoc/src/Converter.java b/tools/droiddoc/src/Converter.java
index 4014f7f..ee911f4 100644
--- a/tools/droiddoc/src/Converter.java
+++ b/tools/droiddoc/src/Converter.java
@@ -238,6 +238,7 @@
}
private static Cache mClasses = new Cache()
{
+ @Override
protected Object make(Object o)
{
ClassDoc c = (ClassDoc)o;
@@ -268,19 +269,21 @@
}
return cl;
}
+ @Override
protected void made(Object o, Object r)
{
if (mClassesNeedingInit == null) {
initClass((ClassDoc)o, (ClassInfo)r);
((ClassInfo)r).init2();
}
- }
+ }
+ @Override
ClassInfo[] all()
{
return (ClassInfo[])mCache.values().toArray(new ClassInfo[mCache.size()]);
}
};
-
+
private static MethodInfo[] getHiddenMethods(MethodDoc[] methods){
if (methods == null) return null;
ArrayList<MethodInfo> out = new ArrayList<MethodInfo>();
@@ -342,7 +345,7 @@
}
return out.toArray(new MethodInfo[out.size()]);
}
-
+
private static MethodInfo[] convertNonWrittenConstructors(ConstructorDoc[] methods)
{
if (methods == null) return null;
@@ -367,6 +370,7 @@
}
private static Cache mMethods = new Cache()
{
+ @Override
protected Object make(Object o)
{
if (o instanceof AnnotationTypeElementDoc) {
@@ -374,7 +378,7 @@
MethodInfo result = new MethodInfo(
m.getRawCommentText(),
Converter.convertTypes(m.typeParameters()),
- m.name(), m.signature(),
+ m.name(), m.signature(),
Converter.obtainClass(m.containingClass()),
Converter.obtainClass(m.containingClass()),
m.isPublic(), m.isProtected(),
@@ -399,7 +403,7 @@
MethodInfo result = new MethodInfo(
m.getRawCommentText(),
Converter.convertTypes(m.typeParameters()),
- m.name(), m.signature(),
+ m.name(), m.signature(),
Converter.obtainClass(m.containingClass()),
Converter.obtainClass(m.containingClass()),
m.isPublic(), m.isProtected(),
@@ -424,7 +428,7 @@
MethodInfo result = new MethodInfo(
m.getRawCommentText(),
Converter.convertTypes(m.typeParameters()),
- m.name(), m.signature(),
+ m.name(), m.signature(),
Converter.obtainClass(m.containingClass()),
Converter.obtainClass(m.containingClass()),
m.isPublic(), m.isProtected(),
@@ -472,6 +476,7 @@
}
private static Cache mFields = new Cache()
{
+ @Override
protected Object make(Object o)
{
FieldDoc f = (FieldDoc)o;
@@ -496,6 +501,7 @@
}
private static Cache mPackagees = new Cache()
{
+ @Override
protected Object make(Object o)
{
PackageDoc p = (PackageDoc)o;
@@ -510,7 +516,8 @@
}
private static Cache mTypes = new Cache()
{
- protected Object make(Object o)
+ @Override
+ protected Object make(Object o)
{
Type t = (Type)o;
String simpleTypeName;
@@ -524,6 +531,7 @@
Converter.obtainClass(t.asClassDoc()));
return ti;
}
+ @Override
protected void made(Object o, Object r)
{
Type t = (Type)o;
@@ -545,8 +553,9 @@
Converter.convertTypes(t.asWildcardType().extendsBounds()));
}
}
+ @Override
protected Object keyFor(Object o)
- {
+ {
Type t = (Type)o;
String keyString = o.getClass().getName() + "/" + o.toString() + "/";
if (t.asParameterizedType() != null){
@@ -584,13 +593,13 @@
}else{
keyString += "NoWildCardType//";
}
-
-
-
+
+
+
return keyString;
}
};
-
+
private static MemberInfo obtainMember(MemberDoc o)
@@ -599,6 +608,7 @@
}
private static Cache mMembers = new Cache()
{
+ @Override
protected Object make(Object o)
{
if (o instanceof MethodDoc) {
@@ -633,6 +643,7 @@
}
private static Cache mAnnotationInstances = new Cache()
{
+ @Override
protected Object make(Object o)
{
AnnotationDesc a = (AnnotationDesc)o;
diff --git a/tools/droiddoc/src/DocFile.java b/tools/droiddoc/src/DocFile.java
index 9901330..cc7a8cf 100644
--- a/tools/droiddoc/src/DocFile.java
+++ b/tools/droiddoc/src/DocFile.java
@@ -137,6 +137,9 @@
} else if (outfile.indexOf("guide/") != -1) {
hdf.setValue("guide", "true");
ClearPage.write(hdf, "docpage.cs", outfile);
+ } else if (outfile.indexOf("resources/") != -1) {
+ hdf.setValue("resources", "true");
+ ClearPage.write(hdf, "docpage.cs", outfile);
} else {
ClearPage.write(hdf, "nosidenavpage.cs", outfile);
}
diff --git a/tools/droiddoc/src/DroidDoc.java b/tools/droiddoc/src/DroidDoc.java
index a8b9c73..4e9d6b1 100644
--- a/tools/droiddoc/src/DroidDoc.java
+++ b/tools/droiddoc/src/DroidDoc.java
@@ -33,6 +33,7 @@
private static final String SDK_CONSTANT_TYPE_BROADCAST_ACTION = "android.annotation.SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION";
private static final String SDK_CONSTANT_TYPE_SERVICE_ACTION = "android.annotation.SdkConstant.SdkConstantType.SERVICE_INTENT_ACTION";
private static final String SDK_CONSTANT_TYPE_CATEGORY = "android.annotation.SdkConstant.SdkConstantType.INTENT_CATEGORY";
+ private static final String SDK_CONSTANT_TYPE_FEATURE = "android.annotation.SdkConstant.SdkConstantType.FEATURE";
private static final String SDK_WIDGET_ANNOTATION = "android.annotation.Widget";
private static final String SDK_LAYOUT_ANNOTATION = "android.annotation.Layout";
@@ -40,7 +41,7 @@
private static final int TYPE_WIDGET = 1;
private static final int TYPE_LAYOUT = 2;
private static final int TYPE_LAYOUT_PARAM = 3;
-
+
public static final int SHOW_PUBLIC = 0x00000001;
public static final int SHOW_PROTECTED = 0x00000003;
public static final int SHOW_PACKAGE = 0x00000007;
@@ -56,6 +57,7 @@
public static ArrayList<String[]> mHDFData = new ArrayList<String[]>();
public static Map<Character,String> escapeChars = new HashMap<Character,String>();
public static String title = "";
+ public static SinceTagger sinceTagger = new SinceTagger();
public static boolean checkLevel(int level)
{
@@ -83,7 +85,7 @@
}
return false;
}
-
+
public static boolean start(RootDoc r)
{
String keepListFile = null;
@@ -94,10 +96,11 @@
String stubsDir = null;
//Create the dependency graph for the stubs directory
boolean apiXML = false;
+ boolean noDocs = false;
+ boolean offlineMode = false;
String apiFile = null;
String debugStubsFile = "";
HashSet<String> stubPackages = null;
- SinceTagger sinceTagger = new SinceTagger();
root = r;
@@ -187,9 +190,15 @@
apiXML = true;
apiFile = a[1];
}
+ else if (a[0].equals("-nodocs")) {
+ noDocs = true;
+ }
else if (a[0].equals("-since")) {
sinceTagger.addVersion(a[1], a[2]);
}
+ else if (a[0].equals("-offlinemode")) {
+ offlineMode = true;
+ }
}
// read some prefs from the template
@@ -200,62 +209,70 @@
// Set up the data structures
Converter.makeInfo(r);
- // Files for proofreading
- if (proofreadFile != null) {
- Proofread.initProofread(proofreadFile);
+ if (!noDocs) {
+ long startTime = System.nanoTime();
+
+ // Apply @since tags from the XML file
+ sinceTagger.tagAll(Converter.rootClasses());
+
+ // Files for proofreading
+ if (proofreadFile != null) {
+ Proofread.initProofread(proofreadFile);
+ }
+ if (todoFile != null) {
+ TodoFile.writeTodoFile(todoFile);
+ }
+
+ // HTML Pages
+ if (ClearPage.htmlDir != null) {
+ writeHTMLPages();
+ }
+
+ // Navigation tree
+ NavTree.writeNavTree(javadocDir);
+
+ // Packages Pages
+ writePackages(javadocDir
+ + (ClearPage.htmlDir!=null
+ ? "packages" + htmlExtension
+ : "index" + htmlExtension));
+
+ // Classes
+ writeClassLists();
+ writeClasses();
+ writeHierarchy();
+ // writeKeywords();
+
+ // Lists for JavaScript
+ writeLists();
+ if (keepListFile != null) {
+ writeKeepList(keepListFile);
+ }
+
+ // Sample Code
+ for (SampleCode sc: sampleCodes) {
+ sc.write(offlineMode);
+ }
+
+ // Index page
+ writeIndex();
+
+ Proofread.finishProofread(proofreadFile);
+
+ if (sdkValuePath != null) {
+ writeSdkValues(sdkValuePath);
+ }
+
+ long time = System.nanoTime() - startTime;
+ System.out.println("DroidDoc took " + (time / 1000000000) + " sec. to write docs to "
+ + ClearPage.outputDir);
}
- if (todoFile != null) {
- TodoFile.writeTodoFile(todoFile);
- }
-
- // Apply @since tags from the XML file
- sinceTagger.tagAll(Converter.rootClasses());
-
- // HTML Pages
- if (ClearPage.htmlDir != null) {
- writeHTMLPages();
- }
-
- // Navigation tree
- NavTree.writeNavTree(javadocDir);
-
- // Packages Pages
- writePackages(javadocDir
- + (ClearPage.htmlDir!=null
- ? "packages" + htmlExtension
- : "index" + htmlExtension));
-
- // Classes
- writeClassLists();
- writeClasses();
- writeHierarchy();
- // writeKeywords();
-
- // Lists for JavaScript
- writeLists();
- if (keepListFile != null) {
- writeKeepList(keepListFile);
- }
-
- // Sample Code
- for (SampleCode sc: sampleCodes) {
- sc.write();
- }
-
- // Index page
- writeIndex();
-
- Proofread.finishProofread(proofreadFile);
// Stubs
if (stubsDir != null) {
Stubs.writeStubs(stubsDir, apiXML, apiFile, stubPackages);
}
- if (sdkValuePath != null) {
- writeSdkValues(sdkValuePath);
- }
-
Errors.printErrors();
return !Errors.hadError;
}
@@ -401,9 +418,15 @@
if (option.equals("-apixml")) {
return 2;
}
+ if (option.equals("-nodocs")) {
+ return 1;
+ }
if (option.equals("-since")) {
return 3;
}
+ if (option.equals("-offlinemode")) {
+ return 1;
+ }
return 0;
}
@@ -518,6 +541,7 @@
i++;
}
+ sinceTagger.writeVersionNames(data);
return data;
}
@@ -776,7 +800,7 @@
data.setValue("package.since", pkg.getSince());
data.setValue("package.descr", "...description...");
- makeClassListHDF(data, "package.interfaces",
+ makeClassListHDF(data, "package.interfaces",
ClassInfo.sortByName(pkg.interfaces()));
makeClassListHDF(data, "package.classes",
ClassInfo.sortByName(pkg.ordinaryClasses()));
@@ -870,7 +894,7 @@
HDF data = makeHDF();
Collections.sort(keywords);
-
+
int i=0;
for (KeywordEntry entry: keywords) {
String base = "keywords." + entry.firstChar() + "." + i;
@@ -963,10 +987,11 @@
}
/**
- * Returns true if the given element has an @hide annotation.
+ * Returns true if the given element has an @hide or @pending annotation.
*/
private static boolean hasHideAnnotation(Doc doc) {
- return doc.getRawCommentText().indexOf("@hide") != -1;
+ String comment = doc.getRawCommentText();
+ return comment.indexOf("@hide") != -1 || comment.indexOf("@pending") != -1;
}
/**
@@ -1058,7 +1083,7 @@
if (methodName.equals("getRawCommentText")) {
return filterComment((String) method.invoke(target, args));
}
-
+
// escape "&" in disjunctive types.
if (proxy instanceof Type && methodName.equals("toString")) {
return ((String) method.invoke(target, args))
@@ -1113,7 +1138,7 @@
throw new RuntimeException("invalid scope for object " + scoped);
}
}
-
+
/**
* Collect the values used by the Dev tools and write them in files packaged with the SDK
* @param output the ouput directory for the files.
@@ -1123,16 +1148,17 @@
ArrayList<String> broadcastActions = new ArrayList<String>();
ArrayList<String> serviceActions = new ArrayList<String>();
ArrayList<String> categories = new ArrayList<String>();
-
+ ArrayList<String> features = new ArrayList<String>();
+
ArrayList<ClassInfo> layouts = new ArrayList<ClassInfo>();
ArrayList<ClassInfo> widgets = new ArrayList<ClassInfo>();
ArrayList<ClassInfo> layoutParams = new ArrayList<ClassInfo>();
-
+
ClassInfo[] classes = Converter.allClasses();
// Go through all the fields of all the classes, looking SDK stuff.
for (ClassInfo clazz : classes) {
-
+
// first check constant fields for the SdkConstant annotation.
FieldInfo[] fields = clazz.allSelfFields();
for (FieldInfo field : fields) {
@@ -1153,6 +1179,8 @@
serviceActions.add(cValue.toString());
} else if (SDK_CONSTANT_TYPE_CATEGORY.equals(type)) {
categories.add(cValue.toString());
+ } else if (SDK_CONSTANT_TYPE_FEATURE.equals(type)) {
+ features.add(cValue.toString());
}
}
break;
@@ -1161,7 +1189,7 @@
}
}
}
-
+
// Now check the class for @Widget or if its in the android.widget package
// (unless the class is hidden or abstract, or non public)
if (clazz.isHidden() == false && clazz.isPublic() && clazz.isAbstract() == false) {
@@ -1180,7 +1208,7 @@
}
}
}
-
+
if (annotated == false) {
// lets check if this is inside android.widget
PackageInfo pckg = clazz.containingPackage();
@@ -1220,7 +1248,10 @@
Collections.sort(categories);
writeValues(output + "/categories.txt", categories);
-
+
+ Collections.sort(features);
+ writeValues(output + "/features.txt", features);
+
// before writing the list of classes, we do some checks, to make sure the layout params
// are enclosed by a layout class (and not one that has been declared as a widget)
for (int i = 0 ; i < layoutParams.size();) {
@@ -1232,10 +1263,10 @@
i++;
}
}
-
+
writeClasses(output + "/widgets.txt", widgets, layouts, layoutParams);
}
-
+
/**
* Writes a list of values into a text files.
* @param pathname the absolute os path of the output file.
@@ -1247,7 +1278,7 @@
try {
fw = new FileWriter(pathname, false);
bw = new BufferedWriter(fw);
-
+
for (String value : values) {
bw.append(value).append('\n');
}
@@ -1281,7 +1312,7 @@
try {
fw = new FileWriter(pathname, false);
bw = new BufferedWriter(fw);
-
+
// write the 3 types of classes.
for (ClassInfo clazz : widgets) {
writeClass(bw, clazz, 'W');
@@ -1324,7 +1355,7 @@
}
writer.append('\n');
}
-
+
/**
* Checks the inheritance of {@link ClassInfo} objects. This method return
* <ul>
@@ -1332,7 +1363,7 @@
* <li>{@link #TYPE_WIDGET}: if the class extends <code>android.view.View</code></li>
* <li>{@link #TYPE_LAYOUT_PARAM}: if the class extends <code>android.view.ViewGroup$LayoutParams</code></li>
* <li>{@link #TYPE_NONE}: in all other cases</li>
- * </ul>
+ * </ul>
* @param clazz the {@link ClassInfo} to check.
*/
private static int checkInheritance(ClassInfo clazz) {
@@ -1343,12 +1374,12 @@
} else if ("android.view.ViewGroup.LayoutParams".equals(clazz.qualifiedName())) {
return TYPE_LAYOUT_PARAM;
}
-
+
ClassInfo parent = clazz.superclass();
if (parent != null) {
return checkInheritance(parent);
}
-
+
return TYPE_NONE;
}
}
diff --git a/tools/droiddoc/src/Errors.java b/tools/droiddoc/src/Errors.java
index 95439f1..77852f8 100644
--- a/tools/droiddoc/src/Errors.java
+++ b/tools/droiddoc/src/Errors.java
@@ -41,6 +41,7 @@
return this.msg.compareTo(that.msg);
}
+ @Override
public String toString() {
String whereText = this.pos == null ? "unknown: " : this.pos.toString() + ':';
return whereText + this.msg;
diff --git a/tools/droiddoc/src/FieldInfo.java b/tools/droiddoc/src/FieldInfo.java
index 1c975e4..d9371e8 100644
--- a/tools/droiddoc/src/FieldInfo.java
+++ b/tools/droiddoc/src/FieldInfo.java
@@ -26,7 +26,7 @@
return a.name().compareTo(b.name());
}
};
-
+
public FieldInfo(String name, ClassInfo containingClass, ClassInfo realContainingClass,
boolean isPublic, boolean isProtected,
boolean isPackagePrivate, boolean isPrivate,
@@ -92,7 +92,7 @@
{
return constantLiteralValue(mConstantValue);
}
-
+
public boolean isDeprecated() {
boolean deprecated = false;
if (!mDeprecatedKnown) {
@@ -124,7 +124,7 @@
if (val instanceof Boolean
|| val instanceof Byte
|| val instanceof Short
- || val instanceof Integer)
+ || val instanceof Integer)
{
str = val.toString();
}
@@ -291,6 +291,7 @@
}
}
+ @Override
public boolean isExecutable()
{
return false;
diff --git a/tools/droiddoc/src/MemberInfo.java b/tools/droiddoc/src/MemberInfo.java
index 2a2572a..05da583 100644
--- a/tools/droiddoc/src/MemberInfo.java
+++ b/tools/droiddoc/src/MemberInfo.java
@@ -115,6 +115,7 @@
return mIsSynthetic;
}
+ @Override
public ContainerInfo parent()
{
return mContainingClass;
@@ -130,7 +131,7 @@
{
return mKind;
}
-
+
public AnnotationInstanceInfo[] annotations()
{
return mAnnotations;
diff --git a/tools/droiddoc/src/MethodInfo.java b/tools/droiddoc/src/MethodInfo.java
index bded88b..3211038 100644
--- a/tools/droiddoc/src/MethodInfo.java
+++ b/tools/droiddoc/src/MethodInfo.java
@@ -25,9 +25,9 @@
return a.name().compareTo(b.name());
}
};
-
+
private class InlineTags implements InheritedTags
- {
+ {
public TagInfo[] tags()
{
return comment().tags();
@@ -42,7 +42,7 @@
}
}
}
-
+
private static void addInterfaces(ClassInfo[] ifaces, ArrayList<ClassInfo> queue)
{
for (ClassInfo i: ifaces) {
@@ -79,7 +79,7 @@
}
return null;
}
-
+
private static void addRealInterfaces(ClassInfo[] ifaces, ArrayList<ClassInfo> queue)
{
for (ClassInfo i: ifaces) {
@@ -92,7 +92,7 @@
addInterfaces(i.realInterfaces(), queue);
}
}
-
+
public MethodInfo findRealOverriddenMethod(String name, String signature, HashSet notStrippable) {
if (mReturnType == null) {
// ctor
@@ -103,7 +103,7 @@
}
ArrayList<ClassInfo> queue = new ArrayList<ClassInfo>();
- if (containingClass().realSuperclass() != null &&
+ if (containingClass().realSuperclass() != null &&
containingClass().realSuperclass().isAbstract()) {
queue.add(containingClass());
}
@@ -121,7 +121,7 @@
}
return null;
}
-
+
public MethodInfo findSuperclassImplementation(HashSet notStrippable) {
if (mReturnType == null) {
// ctor
@@ -138,7 +138,7 @@
}
ArrayList<ClassInfo> queue = new ArrayList<ClassInfo>();
- if (containingClass().realSuperclass() != null &&
+ if (containingClass().realSuperclass() != null &&
containingClass().realSuperclass().isAbstract()) {
queue.add(containingClass());
}
@@ -154,7 +154,7 @@
}
return null;
}
-
+
public ClassInfo findRealOverriddenClass(String name, String signature) {
if (mReturnType == null) {
// ctor
@@ -165,7 +165,7 @@
}
ArrayList<ClassInfo> queue = new ArrayList<ClassInfo>();
- if (containingClass().realSuperclass() != null &&
+ if (containingClass().realSuperclass() != null &&
containingClass().realSuperclass().isAbstract()) {
queue.add(containingClass());
}
@@ -199,7 +199,7 @@
}
}
}
-
+
private class ReturnTags implements InheritedTags {
public TagInfo[] tags() {
return comment().returnTags();
@@ -213,7 +213,7 @@
}
}
}
-
+
public boolean isDeprecated() {
boolean deprecated = false;
if (!mDeprecatedKnown) {
@@ -237,7 +237,7 @@
}
return mIsDeprecated;
}
-
+
public TypeInfo[] getTypeParameters(){
return mTypeParameters;
}
@@ -274,7 +274,7 @@
// The underlying MethodDoc for an interface's declared methods winds up being marked
// non-abstract. Correct that here by looking at the immediate-parent class, and marking
- // this method abstract if it is an unimplemented interface method.
+ // this method abstract if it is an unimplemented interface method.
if (containingClass.isInterface()) {
isAbstract = true;
}
@@ -448,7 +448,7 @@
+ tag.parameterName() + "'");
}
}
-
+
// get our parent's tags to fill in the blanks
MethodInfo overridden = this.findOverriddenMethod(name(), signature());
if (overridden != null) {
@@ -508,7 +508,7 @@
{
return mParameters;
}
-
+
public boolean matchesParams(String[] params, String[] dimensions)
{
@@ -589,6 +589,7 @@
return result;
}
+ @Override
public boolean isExecutable()
{
return true;
@@ -617,21 +618,23 @@
{
return mDefaultAnnotationElementValue;
}
-
+
public void setVarargs(boolean set){
mIsVarargs = set;
}
public boolean isVarArgs(){
return mIsVarargs;
}
+
+ @Override
public String toString(){
return this.name();
}
-
+
public void setReason(String reason) {
mReasonOpened = reason;
}
-
+
public String getReason() {
return mReasonOpened;
}
diff --git a/tools/droiddoc/src/NavTree.java b/tools/droiddoc/src/NavTree.java
index 9eef0ce..0469fdc 100644
--- a/tools/droiddoc/src/NavTree.java
+++ b/tools/droiddoc/src/NavTree.java
@@ -25,7 +25,7 @@
for (PackageInfo pkg: DroidDoc.choosePackages()) {
children.add(makePackageNode(pkg));
}
- Node node = new Node("Reference", dir + "packages.html", children);
+ Node node = new Node("Reference", dir + "packages.html", children, null);
StringBuilder buf = new StringBuilder();
if (false) {
@@ -46,7 +46,7 @@
private static Node makePackageNode(PackageInfo pkg) {
ArrayList<Node> children = new ArrayList();
- children.add(new Node("Description", pkg.fullDescriptionHtmlPage(), null));
+ children.add(new Node("Description", pkg.fullDescriptionHtmlPage(), null, null));
addClassNodes(children, "Interfaces", pkg.interfaces());
addClassNodes(children, "Classes", pkg.ordinaryClasses());
@@ -54,7 +54,7 @@
addClassNodes(children, "Exceptions", pkg.exceptions());
addClassNodes(children, "Errors", pkg.errors());
- return new Node(pkg.name(), pkg.htmlPage(), children);
+ return new Node(pkg.name(), pkg.htmlPage(), children, pkg.getSince());
}
private static void addClassNodes(ArrayList<Node> parent, String label, ClassInfo[] classes) {
@@ -62,12 +62,12 @@
for (ClassInfo cl: classes) {
if (cl.checkLevel()) {
- children.add(new Node(cl.name(), cl.htmlPage(), null));
+ children.add(new Node(cl.name(), cl.htmlPage(), null, cl.getSince()));
}
}
if (children.size() > 0) {
- parent.add(new Node(label, null, children));
+ parent.add(new Node(label, null, children, null));
}
}
@@ -75,11 +75,13 @@
private String mLabel;
private String mLink;
ArrayList<Node> mChildren;
+ private String mSince;
- Node(String label, String link, ArrayList<Node> children) {
+ Node(String label, String link, ArrayList<Node> children, String since) {
mLabel = label;
mLink = link;
mChildren = children;
+ mSince = since;
}
static void renderString(StringBuilder buf, String s) {
@@ -136,6 +138,8 @@
renderString(buf, mLink);
buf.append(", ");
renderChildren(buf);
+ buf.append(", ");
+ renderString(buf, mSince);
buf.append(" ]");
}
}
diff --git a/tools/droiddoc/src/PackageInfo.java b/tools/droiddoc/src/PackageInfo.java
index bcf3cf3..17ad1b7 100644
--- a/tools/droiddoc/src/PackageInfo.java
+++ b/tools/droiddoc/src/PackageInfo.java
@@ -57,11 +57,13 @@
return s;
}
+ @Override
public ContainerInfo parent()
{
return null;
}
+ @Override
public boolean isHidden()
{
return comment().isHidden();
@@ -123,6 +125,7 @@
ClassInfo.makeLinkListHDF(data, base + ".enums", enums());
ClassInfo.makeLinkListHDF(data, base + ".exceptions", exceptions());
ClassInfo.makeLinkListHDF(data, base + ".errors", errors());
+ data.setValue(base + ".since", getSince());
}
public ClassInfo[] interfaces()
diff --git a/tools/droiddoc/src/ParamTagInfo.java b/tools/droiddoc/src/ParamTagInfo.java
index c21ecd5..d6f2b6b 100644
--- a/tools/droiddoc/src/ParamTagInfo.java
+++ b/tools/droiddoc/src/ParamTagInfo.java
@@ -76,6 +76,7 @@
return mParameterName;
}
+ @Override
public void makeHDF(HDF data, String base)
{
data.setValue(base + ".name", parameterName());
diff --git a/tools/droiddoc/src/SampleCode.java b/tools/droiddoc/src/SampleCode.java
index e2283bd..bf54445 100644
--- a/tools/droiddoc/src/SampleCode.java
+++ b/tools/droiddoc/src/SampleCode.java
@@ -38,13 +38,14 @@
}
}
- public void write() {
+ public void write(boolean offlineMode) {
File f = new File(mSource);
if (!f.isDirectory()) {
System.out.println("-samplecode not a directory: " + mSource);
return;
}
- writeDirectory(f, mDest);
+ if (offlineMode) writeIndexOnly(f, mDest, offlineMode);
+ else writeDirectory(f, mDest);
}
public static String convertExtension(String s, String ext) {
@@ -99,10 +100,8 @@
// write the index page
int i;
- HDF hdf = DroidDoc.makeHDF();
- hdf.setValue("page.title", dir.getName() + " - " + mTitle);
- hdf.setValue("projectTitle", mTitle);
+ HDF hdf = writeIndex(dir);
hdf.setValue("subdir", subdir);
i=0;
for (String d: dirs) {
@@ -115,15 +114,33 @@
hdf.setValue("files." + i + ".href", convertExtension(f, ".html"));
i++;
}
+
+ ClearPage.write(hdf, "sampleindex.cs", relative + "/index" + DroidDoc.htmlExtension);
+ }
+
+ public void writeIndexOnly(File dir, String relative, Boolean offline) {
+ HDF hdf = writeIndex(dir);
+ if (!offline) relative = "/" + relative;
+ ClearPage.write(hdf, "sampleindex.cs", relative + "index" +
+ DroidDoc.htmlExtension);
+ }
+
+ public HDF writeIndex(File dir) {
+ HDF hdf = DroidDoc.makeHDF();
+
+ hdf.setValue("page.title", dir.getName() + " - " + mTitle);
+ hdf.setValue("projectTitle", mTitle);
+
String filename = dir.getPath() + "/_index.html";
- String summary = SampleTagInfo.readFile(new SourcePositionInfo(filename, -1,-1), filename,
- "sample code", true, false, true);
+ String summary = SampleTagInfo.readFile(new SourcePositionInfo(filename,
+ -1,-1), filename, "sample code", true, false, true);
+
if (summary == null) {
summary = "";
}
hdf.setValue("summary", summary);
-
- ClearPage.write(hdf, "sampleindex.cs", relative + "/index" + DroidDoc.htmlExtension);
+
+ return hdf;
}
public void writePage(File f, String out, String subdir) {
diff --git a/tools/droiddoc/src/SampleTagInfo.java b/tools/droiddoc/src/SampleTagInfo.java
index c80083b..c7ad1cc 100644
--- a/tools/droiddoc/src/SampleTagInfo.java
+++ b/tools/droiddoc/src/SampleTagInfo.java
@@ -36,7 +36,7 @@
* Both tags accept either a filename and an id or just a filename. If no id
* is provided, the entire file is copied. If an id is provided, the lines
* in the given file between the first two lines containing BEGIN_INCLUDE(id)
- * and END_INCLUDE(id), for the given id, are copied. The id may be only
+ * and END_INCLUDE(id), for the given id, are copied. The id may be only
* letters, numbers and underscore (_).
*
* Four examples:
@@ -274,6 +274,7 @@
return result.substring(0);
}
+ @Override
public void makeHDF(HDF data, String base)
{
data.setValue(base + ".name", name());
diff --git a/tools/droiddoc/src/SeeTagInfo.java b/tools/droiddoc/src/SeeTagInfo.java
index 94863b5..8420ed3 100644
--- a/tools/droiddoc/src/SeeTagInfo.java
+++ b/tools/droiddoc/src/SeeTagInfo.java
@@ -45,6 +45,7 @@
return linkReference().label;
}
+ @Override
public void makeHDF(HDF data, String base)
{
LinkReference linkRef = linkReference();
diff --git a/tools/droiddoc/src/SinceTagger.java b/tools/droiddoc/src/SinceTagger.java
index a34814c..fb69c04 100644
--- a/tools/droiddoc/src/SinceTagger.java
+++ b/tools/droiddoc/src/SinceTagger.java
@@ -4,6 +4,8 @@
import java.util.*;
+import org.clearsilver.HDF;
+
/**
* Applies version information to the DroidDoc class model from apicheck XML
* files. Sample usage:
@@ -46,6 +48,17 @@
}
/**
+ * Writes an index of the version names to {@code data}.
+ */
+ public void writeVersionNames(HDF data) {
+ int index = 1;
+ for (String version : xmlToName.values()) {
+ data.setValue("since." + index + ".name", version);
+ index++;
+ }
+ }
+
+ /**
* Applies the version information to {@code classDocs} where not already
* present.
*
diff --git a/tools/droiddoc/src/SourcePositionInfo.java b/tools/droiddoc/src/SourcePositionInfo.java
index 6244803..ac605ec 100644
--- a/tools/droiddoc/src/SourcePositionInfo.java
+++ b/tools/droiddoc/src/SourcePositionInfo.java
@@ -76,6 +76,7 @@
return new SourcePositionInfo(that.file, line, 0);
}
+ @Override
public String toString()
{
return file + ':' + line;
diff --git a/tools/droiddoc/src/TypeInfo.java b/tools/droiddoc/src/TypeInfo.java
index 5196c13..45e9db9 100644
--- a/tools/droiddoc/src/TypeInfo.java
+++ b/tools/droiddoc/src/TypeInfo.java
@@ -249,6 +249,7 @@
}
}
+ @Override
public String toString(){
String returnString = "";
returnString += "Primitive?: " + mIsPrimitive + " TypeVariable?: " +
diff --git a/tools/droiddoc/templates-pdk/customization.cs b/tools/droiddoc/templates-pdk/customization.cs
index 315b81b..dfebb12 100644
--- a/tools/droiddoc/templates-pdk/customization.cs
+++ b/tools/droiddoc/templates-pdk/customization.cs
@@ -1,24 +1,27 @@
<?cs # This file defines custom definitions for the masthead (logo, searchbox, tabs, etc) and
-left nav (toc) that gets placed on all pages. ?>
+left nav (toc) that gets placed on all pages, for the open source site?>
<?cs
def:custom_masthead() ?>
<div id="header">
<div id="headerLeft">
- <a href="<?cs var:toroot ?>guide/index.html" tabindex="-1"><img
+ <a href="http://source.android.com" tabindex="-1"><img
src="<?cs var:toroot ?>assets/images/open_source.png" alt="Open Source Project: Platform Development Kit" /></a>
<ul class="<?cs
- if:reference ?> <?cs
- elif:guide ?> <?cs
- elif:sdk ?> <?cs
- elif:home ?> <?cs
- elif:community ?> <?cs
- elif:publish ?> <?cs
- elif:about ?> <?cs /if ?>">
- <!--<li id="guide-link"><a href="<?cs var:toroot ?>guide/index.html"
- onClick="return loadLast('guide)'"><span>Dev Guide</span></a></li>
- <li id="opensource-link"><a href="http://source.android.com/"
- onClick="return loadLast('open')"><span>Open Source</span></a></li>-->
+ if:releases ?> releases<?cs
+ elif:guide ?> guide<?cs
+ elif:licenses ?>licenses <?cs
+ elif:home ?>home <?cs
+ elif:community ?>community <?cs /if ?>">
+ <li id="home-link"><a href="<?cs var:toroot ?>index.html"><span>Home</span></a></li>
+ <li id="guide-link"><a href="<?cs var:toroot ?>guide/index.html"
+ onClick="return loadLast('guide)'"><span>Guide</span></a></li>
+ <li id="releases-ink"><a href="<?cs var:toroot ?>releases/index.html"
+ onClick="return loadLast('releases)'"><span>Releases</span></a></li>
+ <li id="licenses-link"><a href="<?cs var:toroot ?>licenses/index.html"
+ onClick="return loadLast('licenses)'"><span>Licenses</span></a></li>
+ <li id="community-link"><a href="<?cs var:toroot ?>community/index.html"
+ onClick="return loadLast('community)'"><span>Community</span></a></li>
</ul>
</div>
<div id="headerRight">
@@ -49,9 +52,45 @@
</script>
<?cs /def ?>
+<?cs
+def:licenses_nav() ?>
+ <div class="g-section g-tpl-240" id="body-content">
+ <div class="g-unit g-first side-nav-resizable" id="side-nav">
+ <div id="devdoc-nav"><?cs
+ include:"../../../../development/pdk/docs/licenses/licenses_toc.cs" ?>
+ </div>
+ </div> <!-- end side-nav -->
+ <script>
+ addLoadEvent(function() {
+ scrollIntoView("devdoc-nav");
+ });
+ </script>
+<?cs /def ?>
+
+<?cs
+def:releases_nav() ?>
+ <div class="g-section g-tpl-240" id="body-content">
+ <div class="g-unit g-first side-nav-resizable" id="side-nav">
+ <div id="devdoc-nav"><?cs
+ include:"../../../../development/pdk/docs/releases/releases_toc.cs" ?>
+ </div>
+ </div> <!-- end side-nav -->
+ <script>
+ addLoadEvent(function() {
+ scrollIntoView("devdoc-nav");
+ });
+ </script>
+<?cs /def ?>
+
<?cs
-def:custom_left_nav() ?><?cs
- call:guide_nav() ?><?cs
+def:custom_left_nav() ?><?cs
+ if:doc.type == "guide" ?><?cs
+ call:guide_nav() ?><?cs
+ elif:doc.type == "licenses" ?><?cs
+ call:licenses_nav() ?><?cs
+ elif:doc.type == "releases" ?><?cs
+ call:releases_nav() ?><?cs
+ /if ?><?cs
/def ?>
<?cs # appears at the bottom of every page ?><?cs
diff --git a/tools/droiddoc/templates-sdk/customization.cs b/tools/droiddoc/templates-sdk/customization.cs
index 79fc282..34f5595 100644
--- a/tools/droiddoc/templates-sdk/customization.cs
+++ b/tools/droiddoc/templates-sdk/customization.cs
@@ -47,34 +47,52 @@
<div id="headerRight">
<div id="headerLinks">
<?cs if:template.showLanguageMenu ?>
- <img src="<?cs var:toroot ?>assets/images/icon_world.jpg" alt="" />
- <span id="language">
+ <img src="<?cs var:toroot ?>assets/images/icon_world.jpg" alt="Language:" />
+ <span id="language">
<select name="language" onChange="changeLangPref(this.value, true)">
- <option value="en">English </option>
- <option value="ja">日本語</option>
- <?cs #
- <option value="de">Deutsch</option>
- <option value="es">Español</option>
- <option value="fr">Français</option>
- <option value="it">Italiano</option>
- <option value="zh-CN">中文 (简体)</option>
- <option value="zh-TW">中文 (繁體)</option>
- ?>
+ <option value="en">English </option>
+ <option value="ja">日本語</option>
+ <?cs #
+ <option value="de">Deutsch</option>
+ <option value="es">Español</option>
+ <option value="fr">Français</option>
+ <option value="it">Italiano</option>
+ <option value="zh-CN">中文 (简体)</option>
+ <option value="zh-TW">中文 (繁體)</option>
+ ?>
</select>
<script type="text/javascript">
<!--
loadLangPref();
//-->
</script>
- </span>
+ </span>
<?cs /if ?>
<a href="http://www.android.com">Android.com</a>
</div><?cs
- call:default_search_box() ?>
+ call:default_search_box() ?><?cs
+ if:reference ?>
+ <div id="api-level-toggle">
+ <input type="checkbox" id="apiLevelCheckbox" onclick="toggleApiLevelSelector(this)" />
+ <label for="apiLevelCheckbox" class="disabled">Filter by API Level: </label>
+ <select id="apiLevelSelector">
+ <!-- option elements added by buildApiLevelSelector() -->
+ </select>
+ </div>
+ <script>
+ var SINCE_DATA = [ <?cs
+ each:since = since ?>'<?cs
+ var:since.name ?>'<?cs
+ if:!last(since) ?>, <?cs /if ?><?cs
+ /each
+ ?> ];
+ buildApiLevelSelector();
+ </script><?cs
+ /if ?>
</div><!-- headerRight -->
<script type="text/javascript">
<!--
- changeTabLang(getLangPref());
+ changeTabLang(getLangPref());
//-->
</script>
</div><!-- header --><?cs
@@ -91,6 +109,21 @@
<?cs /def ?>
<?cs
+def:resources_tab_nav() ?>
+ <div class="g-section g-tpl-240" id="body-content">
+ <div class="g-unit g-first side-nav-resizable" id="side-nav">
+ <div id="devdoc-nav"><?cs
+ include:"../../../../frameworks/base/docs/html/resources/resources_toc.cs" ?>
+ </div>
+ </div> <!-- end side-nav -->
+ <script>
+ addLoadEvent(function() {
+ scrollIntoView("devdoc-nav");
+ });
+ </script>
+<?cs /def ?>
+
+<?cs
def:guide_nav() ?>
<div class="g-section g-tpl-240" id="body-content">
<div class="g-unit g-first side-nav-resizable" id="side-nav">
@@ -178,6 +211,8 @@
def:custom_left_nav() ?><?cs
if:guide ?><?cs
call:guide_nav() ?><?cs
+ elif:resources ?><?cs
+ call:resources_tab_nav() ?><?cs
elif:sdk ?><?cs
call:sdk_nav() ?><?cs
else ?><?cs
diff --git a/tools/droiddoc/templates-sdk/devdoc-nav.cs b/tools/droiddoc/templates-sdk/devdoc-nav.cs
deleted file mode 100644
index a69c175..0000000
--- a/tools/droiddoc/templates-sdk/devdoc-nav.cs
+++ /dev/null
@@ -1,66 +0,0 @@
-<ul>
- <li><div><a href="<?cs var:toroot ?>index.html">Home</a></div></li>
- <li><div><a href="<?cs var:toroot ?>what-is-android.html">What is Android?</a></div></li>
- <li><div><a href="<?cs var:toroot ?>intro/index.html">Getting Started</a></div>
- <ul>
- <li><div><a href="<?cs var:toroot ?>intro/installing.html">Installing the SDK</a></div></li>
- <li><div><a href="<?cs var:toroot ?>intro/upgrading.html">Upgrading the SDK</a></div></li>
- <li><div><a href="<?cs var:toroot ?>intro/develop-and-debug.html">Developing/Debugging</a></div></li>
- <li><div><a href="<?cs var:toroot ?>intro/hello-android.html">Hello Android</a></div></li>
- <li><div><a href="<?cs var:toroot ?>intro/anatomy.html">Anatomy of an App</a></div></li>
- <li><div><a href="<?cs var:toroot ?>intro/tutorial.html">Notepad Tutorial</a></div></li>
- <li><div><a href="<?cs var:toroot ?>intro/tools.html">Development Tools</a></div></li>
- <li><div><a href="<?cs var:toroot ?>intro/appmodel.html">Application Model</a></div></li>
- <li><div><a href="<?cs var:toroot ?>intro/lifecycle.html">Application Life Cycle</a></div></li>
- </ul>
- </li>
- <li><div><div><a href="<?cs var:toroot ?>devel/index.html">Developing Applications</a></div>
- <ul>
- <li><div><a href="<?cs var:toroot ?>devel/implementing-ui.html">Implementing a UI</a></div></li>
- <li><div><a href="<?cs var:toroot ?>devel/building-blocks.html">Building Blocks</a></div></li>
- <li><div><a href="<?cs var:toroot ?>devel/data.html">Data Storage and Retrieval</a></div></li>
- <li><div><a href="<?cs var:toroot ?>devel/security.html">Security Model</a></div></li>
- <li><div><a href="<?cs var:toroot ?>devel/resources-i18n.html">Resources and i18n</a></div></li>
- </ul>
- </li>
- <li><div><a href="<?cs var:toroot ?>toolbox/index.html">Developer Toolbox</a></div>
- <ul>
- <li><div><a href="<?cs var:toroot ?>toolbox/philosophy.html">Design Philosophy</a></div></li>
- <li><div><a href="<?cs var:toroot ?>toolbox/custom-components.html">Building Custom Components</a></div></li>
- <li><div><a href="<?cs var:toroot ?>toolbox/optional-apis.html">Optional APIs</a></div></li>
- </ul>
- </li>
- <li><div><a href="<?cs var:toroot ?>samples/index.html">Sample Code</a></div>
- <ul>
- <li><div><a href="<?cs var:toroot ?>samples/ApiDemos/index.html">API Demos</a></div></li>
- <li><div><a href="<?cs var:toroot ?>samples/LunarLander/index.html">Lunar Lander</a></div></li>
- <li><div><a href="<?cs var:toroot ?>samples/NotePad/index.html">Note Pad</a></div></li>
- </ul>
- </li>
- <li> <a href="<?cs var:toroot ?>reference/index.html"><strong>Reference Information</strong></a>
- <ul>
- <li><a href="<?cs var:toroot ?>reference/packages.html">Package Index</a></li>
- <li><a href="<?cs var:toroot ?>reference/classes.html">Class Index</a></li>
- <li><a href="<?cs var:toroot ?>reference/hierarchy.html">Class Hierarchy</a></li>
- <li><a href="<?cs var:toroot ?>reference/view-gallery.html">List of Views</a></li>
- <li><a href="<?cs var:toroot ?>reference/available-intents.html">List of Intents</a></li>
- <li><a href="<?cs var:toroot ?>reference/android/Manifest.permission.html">List of Permissions</a></li>
- <li><a href="<?cs var:toroot ?>reference/available-resources.html">List of Resource Types</a></li>
- <li><a href="<?cs var:toroot ?>reference/aidl.html">Android IDL</a></li>
- <li><a href="<?cs var:toroot ?>reference/glossary.html">Glossary</a></li>
- <li><a href="<?cs var:toroot ?>reference/keywords.html">Index</a></li>
- </ul>
- </li>
- <li><div><a href="<?cs var:toroot ?>kb/index.html">FAQs</a></div>
- <ul>
- <li><div><a href="<?cs var:toroot ?>kb/general.html">General</a></div></li>
- <li><div><a href="<?cs var:toroot ?>kb/commontasks.html">Common Tasks</a></div></li>
- <li><div><a href="<?cs var:toroot ?>kb/troubleshooting.html">Troubleshooting</a></div></li>
- <li><div><a href="<?cs var:toroot ?>kb/licensingandoss.html">Open Source Licensing</a></div></li>
- <li><div><a href="<?cs var:toroot ?>kb/framework.html">Application Framework</a></div></li>
- <li><div><a href="<?cs var:toroot ?>kb/security.html">Security</a></div></li>
- </ul>
- </li>
- <li><div><a href="<?cs var:toroot ?>roadmap.html">Roadmap</a></div></li>
- <li><div><a href="<?cs var:toroot ?>goodies/index.html">Goodies</a></div></li>
-</ul>
\ No newline at end of file
diff --git a/tools/droiddoc/templates-sdk/header_tabs.cs b/tools/droiddoc/templates-sdk/header_tabs.cs
index 02fc8bf..496f276 100644
--- a/tools/droiddoc/templates-sdk/header_tabs.cs
+++ b/tools/droiddoc/templates-sdk/header_tabs.cs
@@ -3,75 +3,87 @@
elif:guide ?>guide<?cs
elif:sdk ?>sdk<?cs
elif:home ?>home<?cs
- elif:community ?>community<?cs
+ elif:resources ?>resources<?cs
elif:videos ?>videos<?cs /if ?>">
-
- <li id="home-link"><a href="<?cs var:toroot ?><?cs if:android.whichdoc != "online" ?>offline.html<?cs else ?>index.html<?cs /if ?>">
+
+ <li id="home-link"><a href="<?cs var:toroot ?><?cs
+ if:android.whichdoc != "online" ?>offline.html<?cs
+ else ?>index.html<?cs /if ?>">
<?cs if:!sdk.redirect ?>
<span class="en">Home</span>
- <span class="de">Startseite</span>
- <span class="es"></span>
- <span class="fr"></span>
- <span class="it"></span>
- <span class="ja">ホーム</span>
- <span class="zh-CN">主页</span>
- <span class="zh-TW">首頁</span>
+ <span style="display:none" class="de">Startseite</span>
+ <span style="display:none" class="es"></span>
+ <span style="display:none" class="fr"></span>
+ <span style="display:none" class="it"></span>
+ <span style="display:none" class="ja">ホーム</span>
+ <span style="display:none" class="zh-CN">主页</span>
+ <span style="display:none" class="zh-TW">首頁</span>
<?cs /if ?>
</a></li>
- <li id="sdk-link"><a href="<?cs var:toroot ?>sdk/<?cs var:sdk.current ?>/index.html">
+ <li id="sdk-link"><a href="<?cs var:toroot ?>sdk/index.html">
<span class="en">SDK</span>
</a></li>
<li id="guide-link"><a href="<?cs var:toroot ?>guide/index.html" onClick="return loadLast('guide')">
<?cs if:!sdk.redirect ?>
<span class="en">Dev Guide</span>
- <span class="de">Handbuch</span>
- <span class="es">Guía</span>
- <span class="fr">Guide</span>
- <span class="it">Guida</span>
- <span class="ja">開発ガイド</span>
- <span class="zh-CN">开发人员指南</span>
- <span class="zh-TW">開發指南</span>
+ <span style="display:none" class="de">Handbuch</span>
+ <span style="display:none" class="es">Guía</span>
+ <span style="display:none" class="fr">Guide</span>
+ <span style="display:none" class="it">Guida</span>
+ <span style="display:none" class="ja">開発ガイド</span>
+ <span style="display:none" class="zh-CN">开发人员指南</span>
+ <span style="display:none" class="zh-TW">開發指南</span>
<?cs /if ?>
</a></li>
<li id="reference-link"><a href="<?cs var:toroot ?>reference/packages.html" onClick="return loadLast('reference')">
<?cs if:!sdk.redirect ?>
<span class="en">Reference</span>
- <span class="de">Referenz</span>
- <span class="es">Referencia</span>
- <span class="fr">Référence</span>
- <span class="it">Riferimento</span>
- <span class="ja">リファレンス</span>
- <span class="zh-CN">参考</span>
- <span class="zh-TW">參考資料</span>
+ <span style="display:none" class="de">Referenz</span>
+ <span style="display:none" class="es">Referencia</span>
+ <span style="display:none" class="fr">Référence</span>
+ <span style="display:none" class="it">Riferimento</span>
+ <span style="display:none" class="ja">リファレンス</span>
+ <span style="display:none" class="zh-CN">参考</span>
+ <span style="display:none" class="zh-TW">參考資料</span>
+ <?cs /if ?>
+ </a></li>
+ <li id="resources-link"><a href="<?cs var:toroot ?>resources/index.html" onClick="return loadLast('resources')">
+ <?cs if:!sdk.redirect ?>
+ <span class="en">Resources</span>
+ <span style="display:none" class="de"></span>
+ <span style="display:none" class="es"></span>
+ <span style="display:none" class="fr"></span>
+ <span style="display:none" class="it"></span>
+ <span style="display:none" class="ja"></span>
+ <span style="display:none" class="zh-CN"></span>
+ <span style="display:none" class="zh-TW"></span>
+ <?cs /if ?>
+ </a></li>
+ <li id="videos-link"><a href="<?cs var:toroot ?>videos/index.html" onClick="return loadLast('videos')">
+ <?cs if:!sdk.redirect ?>
+ <span class="en">Videos</span>
+ <span style="display:none" class="de"></span>
+ <span style="display:none" class="es"></span>
+ <span style="display:none" class="fr"></span>
+ <span style="display:none" class="it"></span>
+ <span style="display:none" class="ja">ビデオ</span>
+ <span style="display:none" class="zh-CN"></span>
+ <span style="display:none" class="zh-TW"></span>
<?cs /if ?>
</a></li>
<li><a href="http://android-developers.blogspot.com" onClick="return requestAppendHL(this.href)">
<?cs if:!sdk.redirect ?>
<span class="en">Blog</span>
- <span class="de"></span>
- <span class="es"></span>
- <span class="fr"></span>
- <span class="it"></span>
- <span class="ja">ブログ</span>
- <span class="zh-CN">博客</span>
- <span class="zh-TW">網誌</span>
+ <span style="display:none" class="de"></span>
+ <span style="display:none" class="es"></span>
+ <span style="display:none" class="fr"></span>
+ <span style="display:none" class="it"></span>
+ <span style="display:none" class="ja">ブログ</span>
+ <span style="display:none" class="zh-CN">博客</span>
+ <span style="display:none" class="zh-TW">網誌</span>
<?cs /if ?>
</a></li>
- <li id="videos-link"><a href="<?cs var:toroot ?>videos/index.html" onClick="return loadLast('videos')">
- <span class="en">Videos</span>
- <span class="ja">ビデオ</span>
- </a></li>
- <li id="community-link"><a href="<?cs var:toroot ?>community/index.html">
- <?cs if:!sdk.redirect ?>
- <span class="en">Community</span>
- <span class="de"></span>
- <span class="es">Comunidad</span>
- <span class="fr">Communauté</span>
- <span class="it"></span>
- <span class="ja">コミュニティ</span>
- <span class="zh-CN">社区</span>
- <span class="zh-TW">社群</span>
- <?cs /if ?>
- </a></li>
+
+
</ul>
diff --git a/tools/droiddoc/templates-sdk/sdkpage.cs b/tools/droiddoc/templates-sdk/sdkpage.cs
index d5c9ffc..604b5ee 100644
--- a/tools/droiddoc/templates-sdk/sdkpage.cs
+++ b/tools/droiddoc/templates-sdk/sdkpage.cs
@@ -5,8 +5,8 @@
<head>
<title>Redirecting...</title>
<meta http-equiv="refresh" content="0;url=<?cs var:toroot ?>sdk/<?cs
- if:sdk.redirect.path ?><?cs var:sdk.redirect.path ?>"<?cs
- else ?><?cs var:sdk.current ?>/index.html<?cs /if ?>"
+ if:sdk.redirect.path ?><?cs var:sdk.redirect.path ?><?cs
+ else ?><?cs var:sdk.current ?>/index.html<?cs /if ?>">
<link href="<?cs var:toroot ?>assets/android-developer-docs.css" rel="stylesheet" type="text/css" />
</head>
<?cs else ?>
@@ -24,35 +24,38 @@
<div id="jd-content">
<p>Redirecting to
<a href="<?cs var:toroot ?>sdk/<?cs
- if:sdk.redirect.path ?><?cs var:sdk.redirect.path ?>">/sdk/<?cs var:sdk.redirect.path ?><?cs
- else ?><?cs var:sdk.current ?>/index.html">/sdk/<?cs var:sdk.current ?>/index.html<?cs /if ?>
+ if:sdk.redirect.path ?><?cs var:sdk.redirect.path ?><?cs
+ else ?><?cs var:sdk.current ?>/index.html<?cs /if ?>">sdk/<?cs
+ if:sdk.redirect.path ?><?cs var:sdk.redirect.path ?><?cs
+ else ?><?cs var:sdk.current ?>/index.html<?cs /if ?>
</a> ...</p>
<?cs else ?>
<div class="g-unit" id="doc-content" >
<div id="jd-header" class="guide-header" >
<span class="crumb"> </span>
- <h1><?cs if:android.whichdoc == "online" ?>Download <?cs /if ?><?cs var:page.title ?></h1>
+ <h1><?cs if:android.whichdoc == "online" ?>Download the <?cs /if ?><?cs var:page.title ?></h1>
</div>
<div id="jd-content">
- <p><em><?cs
- if:ndk ?><?cs
- var:ndk.date ?><?cs
+ <?cs
+ if:ndk ?><p><em><?cs
+ var:ndk.date ?></em></p><?cs
else ?><?cs
- var:sdk.date ?><?cs
- /if ?></em>
- </p>
+ if:android.whichdoc == "online" ?><p><em><?cs
+ var:sdk.date ?></em></p><?cs
+ /if ?><?cs
+ /if ?>
<?cs if:sdk.not_latest_version ?>
<div class="special">
<p><strong>This is NOT the current Android SDK release.</strong></p>
- <p><a href="/sdk/<?cs var:sdk.current ?>/index.html">Download the current Android SDK</a></p>
+ <p><a href="/sdk/index.html">Download the current Android SDK</a></p>
</div>
<?cs /if ?>
-<?cs if:android.whichdoc != "online" ?>
+<?cs if:android.whichdoc != "online" && !android.preview ?>
-<p>The sections below provide an overview of the SDK package. </p>
+<!-- <p>The sections below provide an overview of how to install the SDK package. </p> -->
<?cs else ?>
<?cs if:ndk ?>
@@ -60,10 +63,10 @@
<p>The Android NDK is a companion tool to the Android SDK that lets Android
application developers build performance-critical portions of their apps in
native code. It is designed for use <em>only</em> in conjunction with the
-Android SDK, so if you have not already installed the Android 1.5 SDK, please do
-so before downloading the NDK. Also, please read <a href="#overview">What is the
-Android NDK?</a> to get an understanding of what the NDK offers and whether it
-will be useful to you.</p>
+Android SDK, so if you have not already installed the latest Android SDK, please
+do so before downloading the NDK. Also, please read <a href="#overview">What is
+the Android NDK?</a> to get an understanding of what the NDK offers and whether
+it will be useful to you.</p>
<p>Select the download package that is appropriate for your development
computer. </p>
@@ -101,11 +104,53 @@
</tr>
</table>
- <?cs else ?>
-<p>Before downloading, please read the <a href="requirements.html">
-System Requirements</a> document. As you start the download, you will also need to review and agree to
-the Terms and Conditions that govern the use of the Android SDK. </p>
-
+ <?cs else ?><?cs if:android.whichdoc == "online" ?>
+
+ <?cs if:sdk.preview ?>
+ <p>Welcome developers! The next release of the Android platform will be
+ Android 1.6 and we are pleased to announce the availability of an early look
+ SDK to give you a head-start on developing applications for it. </p>
+
+ <p>The Android <?cs var:sdk.preview.version ?> platform includes a variety of
+ improvements and new features for users and developers. Additionally, the SDK
+ itself introduces several new capabilities that enable you to develop
+ applications more efficiently. See the <a href="features.html">Android <?cs
+ var:sdk.preview.version ?> Platform Highlights</a> document for a list of
+ highlights.</p>
+<?cs /if ?>
+<?cs # end if NDK ... the following is for the SDK ?>
+
+ <div class="toggle-content special">
+ <p>The Android SDK has changed! If you've worked with the Android SDK before,
+ you will notice several important differences:</p>
+
+ <div class="toggle-content-toggleme" style="display:none">
+ <ul style="padding-bottom:.0;">
+ <li style="margin-top:.5em">The SDK downloadable package includes <em>only</em>
+ the latest version of the Android SDK Tools.</li>
+ <li>Once you've installed the SDK, you now use the Android SDK and AVD Manager
+ to download all of the SDK components that you need, such as Android platforms,
+ SDK add-ons, tools, and documentation. </li>
+ <li>The new approach is modular — you can install only the components you
+ need and update any or all components without affecting other parts of your
+ development environment.</li>
+ <li>In short, once you've installed the new SDK, you will not need to download
+ an SDK package again. Instead, you will use the Android SDK and AVD Manager to
+ keep your development environment up-to-date. </li>
+ </ul>
+ <p style="margin-top:0">If you are currently using the Android 1.6 SDK, you
+ do not need to install the new SDK, because your existing SDK already
+ includes the Android SDK and AVD Manager tool. To develop against Android
+ 2.0.1, for example, you can just download the Android 2.0.1 platform (and
+ updated SDK Tools) into your existing SDK. Refer to <a
+ href="adding-components.html">Adding SDK Components</a>.</p>
+ </div>
+
+ <a href='#' class='toggle-content-button show' onclick="toggleContent(this);return false;">
+ <span>show more</span><span style='display:none'>show less</span>
+ </a>
+ </div>
+
<table class="download">
<tr>
<th>Platform</th>
@@ -137,9 +182,32 @@
<td><?cs var:sdk.linux_bytes ?> bytes</td>
<td><?cs var:sdk.linux_checksum ?></td>
</tr>
+ <?cs if:adt.zip_download ?>
+ <tr class="alt-color">
+ <td>ADT Plugin for Eclipse <?cs var:adt.zip_version ?></td>
+ <td>
+ <a href="http://dl.google.com/android/<?cs var:adt.zip_download ?>"><?cs var:adt.zip_download ?></a>
+ </td>
+ <td><?cs var:adt.zip_bytes ?> bytes</td>
+ <td><?cs var:adt.zip_checksum ?></td>
+ </tr>
+ <?cs /if ?>
</table>
-<?cs /if ?>
+ <?cs /if ?>
+ <?cs /if ?>
+<?cs /if ?>
+
+<?cs if:android.whichdoc != "online" && sdk.preview ?>
+ <p>Welcome developers! The next release of the Android platform will be
+ Android 1.6 and we are pleased to announce the availability of an early look SDK
+ to give you a head-start on developing applications for it. </p>
+
+ <p>The Android 1.6 platform includes a variety of improvements and new features
+ for users and developers. Additionally, the SDK itself introduces several new
+ capabilities that enable you to develop applications more efficiently.
+ See the <a href="http://developer.android.com/sdk/preview/features.html">
+ Android 1.6 Highlights</a> document for a list of highlights.</p>
<?cs /if ?>
<?cs call:tag_list(root.descr) ?>
diff --git a/tools/droiddoc/templates/assets/android-developer-core.css b/tools/droiddoc/templates/assets/android-developer-core.css
index 3bd7060..2d1708a 100644
--- a/tools/droiddoc/templates/assets/android-developer-core.css
+++ b/tools/droiddoc/templates/assets/android-developer-core.css
@@ -34,8 +34,7 @@
a, a code {
color:#006699;
-}
-
+}
a:active,
a:active code {
@@ -48,9 +47,12 @@
}
input, select,
-textarea, option {
+textarea, option, label {
+ font-family:inherit;
+ font-size:inherit;
padding:0;
margin:0;
+ vertical-align:middle;
}
option {
@@ -79,6 +81,7 @@
padding:10px;
margin:0 0 1em 1em;
overflow:auto;
+ line-height:inherit; /* fixes vertical scrolling in webkit */
}
h1,h2,h3,h4,h5 {
@@ -131,13 +134,17 @@
}
li ul,
-li ol {
- margin:.5em 0 0 0;
+li ol,
+dd ul,
+dd ol {
+ margin:0;
padding: 0 0 0 2em;
}
-dl li {
- padding:.5em 0 0 0;
+li li,
+dd li {
+ margin:0;
+ padding:.5em 0 0;
}
dl dl,
@@ -175,8 +182,16 @@
margin:20px 0 10px;
}
+blockquote {
+ margin: 0 0 1em 1em;
+ padding: 0 4em 0 1em;
+ border-left:2px solid #eee;
+}
/* LAYOUT */
+
#body-content {
+ /* "Preliminary" watermark for preview releases and interim builds.
+ background:transparent url(images/preliminary.png) repeat scroll 0 0; */
margin:0;
position:relative;
width:100%;
@@ -186,7 +201,7 @@
height: 114px;
position:relative;
z-index:100;
- min-width:576px;
+ min-width:675px; /* min width for the tabs, before they wrap */
padding:0 10px;
border-bottom:3px solid #94b922;
}
@@ -208,6 +223,7 @@
}
/* Tabs in the header */
+
#header ul {
list-style: none;
margin: 7px 0 0;
@@ -251,12 +267,13 @@
display:none;
}
-/* TAB HIGHLIGHTING */
+/* tab highlighting */
+
.home #home-link a,
.guide #guide-link a,
.reference #reference-link a,
.sdk #sdk-link a,
-.community #community-link a,
+.resources #resources-link a,
.videos #videos-link a {
background-image: url(images/bg_images_sprite.png);
background-position: 0 0;
@@ -270,7 +287,7 @@
.guide #guide-link a:hover,
.reference #reference-link a:hover,
.sdk #sdk-link a:hover,
-.community #community-link a:hover,
+.resources #resources-link a:hover,
.videos #videos-link a:hover {
background-image: url(images/bg_images_sprite.png);
background-position: 0 0;
@@ -300,7 +317,7 @@
margin:15px 10px 0 0;
}
-/* main */
+/* MAIN BODY */
#mainBodyFluid {
margin: 20px 10px;
@@ -425,7 +442,8 @@
clear: both;
}
-/* Footer */
+/* FOOTER */
+
#footer {
float: left;
width:90%;
@@ -453,99 +471,8 @@
color:#006699;
}
-#homeBottom td {
- border:0px solid #666;
- padding: 8px 18px 8px 18px;
-}
-
-#homeBottom table {
- width: 100%;
-}
-
-
-#homeBottom {
- padding: 0px 0px 0px 0px;
- float: left;
- width: 585px;
- height: 165px;
- background-image:url(images/home/bg_home_bottom.jpg);
- background-repeat: no-repeat;
-}
-
-.groupTable {
- width: 100%;
-}
-
-.groupTable th {
- padding: 10px;
- color: #ffffff;
- background-color: #6D8293;
- border: 2px solid #fff;
-}
-
-.groupTable td {
- padding: 10px;
- color: #333333;
- background-color: #d9d9d9;
- border: 2px solid #fff;
-}
-
-.groupTable .evenRow td {
- background-color: #ededed;
-}
-
-span.BigBlue {
- color:#336666;
- font-size:1.25em;
- margin: 0em 0em 0em 0em;
- padding-bottom:.5em;
- font-weight: bold;
-}
-
-span.emBlue {
- color: #336666;
- font-style:italic;
-}
-
-.pageTable {
- width: 95%;
- border: none;
-}
-
-.pageTable img {
-vertical-align: bottom;
-}
-
-.pageTable td {
- border: none;
-}
-
-.pageTable td.leftNav {
- width: 100px;
-}
-
-.greenBox {
- margin: 10px 30px 10px 30px;
- padding: 10px 20px 10px 20px;
- background-color: #EBF3DB;
- width: 75%;
-}
-
-.blueBox {
- margin: 10px 30px 10px 30px;
- padding: 10px 20px 10px 20px;
- background-color: #DDF0F2;
- width: 75%;
-}
-
-.blueHR {
- margin: 10px 30px 10px 30px;
- height: 5px;
- background-color: #DDF0F2;
- width: 75%;
-}
-
/* SEARCH FILTER */
+
#search_autocomplete {
color:#aaa;
}
@@ -732,7 +659,7 @@
padding: 0px 0px 0px 0px;
float: left;
width: 584px;
- height: 580px;
+ height: 627px;
position:relative;
}
@@ -777,7 +704,7 @@
}
#carouselMain {
- background: url('/assets/images/home/bg_home_carousel_board.png') 0 0 no-repeat;
+ background: url(images/home/bg_home_carousel_board.png) 0 0 no-repeat;
height:auto;
padding: 25px 21px 0;
overflow:hidden;
@@ -800,7 +727,7 @@
}
#carouselWheel {
- background: url('/assets/images/home/bg_home_carousel_wheel.png') 0 0 no-repeat;
+ background: url(images/home/bg_home_carousel_wheel.png) 0 0 no-repeat;
padding-top:40px;
height:150px;
}
@@ -1154,12 +1081,12 @@
ul.videoPreviews span.more {
padding:0 0 0 12px;
- background:url('/assets/images/arrow_bluelink_down.png') 0 2px no-repeat;
+ background:url(images/arrow_bluelink_down.png) 0 2px no-repeat;
}
ul.videoPreviews span.less {
padding:0 0 0 12px;
- background:url('/assets/images/arrow_bluelink_up.png') 0 2px no-repeat;
+ background:url(images/arrow_bluelink_up.png) 0 2px no-repeat;
display:none;
}
@@ -1227,3 +1154,30 @@
#mainBodyRight ul.videoPreviews img {
margin-top:5px;
}
+
+/* Pretty printing styles. Used with prettify.js. */
+
+.str { color: #080; }
+.kwd { color: #008; }
+.com { color: #800; }
+.typ { color: #606; }
+.lit { color: #066; }
+.pun { color: #660; }
+.pln { color: #000; }
+.tag { color: #008; }
+.atn { color: #606; }
+.atv { color: #080; }
+.dec { color: #606; }
+
+@media print {
+ .str { color: #060; }
+ .kwd { color: #006; font-weight: bold; }
+ .com { color: #600; font-style: italic; }
+ .typ { color: #404; font-weight: bold; }
+ .lit { color: #044; }
+ .pun { color: #440; }
+ .pln { color: #000; }
+ .tag { color: #006; font-weight: bold; }
+ .atn { color: #404; }
+ .atv { color: #060; }
+}
diff --git a/tools/droiddoc/templates/assets/android-developer-docs.css b/tools/droiddoc/templates/assets/android-developer-docs.css
index e5489e6..0ab7aab 100644
--- a/tools/droiddoc/templates/assets/android-developer-docs.css
+++ b/tools/droiddoc/templates/assets/android-developer-docs.css
@@ -276,9 +276,9 @@
/* summary tables for reference pages */
.jd-sumtable {
-margin: .5em 1em 1em 1em;
-width:99%;
-font-size:.9em;
+ margin: .5em 1em 1em 1em;
+ width:95%; /* consistent table widths; within IE's quirks */
+ font-size:.9em;
}
.jd-sumtable a {
@@ -330,8 +330,7 @@
links to summary tables) */
#api-info-block {
font-size:.8em;
- margin:0;
- padding:6px;
+ padding:6px 10px;
font-weight:normal;
float:right;
text-align:right;
@@ -340,26 +339,65 @@
}
#api-level-toggle {
- float:right;
padding:0 10px;
font-size:11px;
+ float:right;
+}
+
+#api-level-toggle label.disabled {
color:#999;
}
-h4.jd-details-title .api-level,
-div#jd-header .api-level {
- font-size:12px;
+div.api-level {
+ font-size:.8em;
font-weight:normal;
color:#999;
- position:absolute;
- top:5px;
- right:5px;
+ float:right;
+ padding:0 7px 0;
+ margin-top:-25px;
}
-div#jd-header .api-level {
- position:relative;
- float:right;
- margin-top:-1.7em;
+#api-info-block div.api-level {
+ font-size:1.3em;
+ font-weight:bold;
+ float:none;
+ color:#444;
+ padding:0;
+ margin:0;
+}
+
+/* Force link colors for IE6 */
+div.api-level a {
+ color:#999;
+}
+#api-info-block div.api-level a:link {
+ color:#444;
+}
+#api-level-toggle a {
+ color:#999;
+}
+
+div#naMessage {
+ display:none;
+ width:555px;
+ height:0;
+ margin:0 auto;
+}
+
+div#naMessage div {
+ width:450px;
+ position:fixed;
+ margin:50px 0;
+ padding:4em 4em 3em;
+ background:#FFF;
+ background:rgba(255,255,255,0.7);
+ border:1px solid #dddd00;
+}
+/* IE6 can't position fixed */
+* html div#naMessage div { position:absolute; }
+
+div#naMessage strong {
+ font-size:1.1em;
}
.absent,
@@ -367,25 +405,53 @@
.absent a:visited,
.absent a:hover,
.absent * {
- color:#aaa !important;
- background-color:#f6f6f6 !important;
+ color:#bbb !important;
cursor:default !important;
text-decoration:none !important;
}
-#side-nav li.absent,
-#side-nav li.absent * {
- background-color:#fff !important;
+#api-level-toggle a,
+.api-level a {
+ color:inherit;
+ text-decoration:none;
+}
+
+#api-level-toggle a:hover,
+.api-level a:hover {
+ color:inherit;
+ text-decoration:underline !important;
+ cursor:pointer !important;
}
#side-nav li.absent.selected,
-#side-nav li.absent.selected * {
- background-color:#eee !important;
+#side-nav li.absent.selected *,
+#side-nav div.label.absent.selected,
+#side-nav div.label.absent.selected * {
+ background-color:#eaeaea !important;
}
+/* IE6 quirk (won't chain classes, so just keep background blue) */
+* html #side-nav li.selected,
+* html #side-nav li.selected *,
+* html #side-nav div.label.selected,
+* html #side-nav div.label.selected * {
+ background-color: #435a6e !important;
+}
+
+
+.absent h4.jd-details-title,
+.absent h4.jd-details-title * {
+ background-color:#f6f6f6 !important;
+}
+
+.absent img {
+ opacity: .3;
+ filter: alpha(opacity=30);
+ -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";
+}
+
/* applies to a div containing links to summary tables */
.sum-details-links {
- margin:0 .5em;
padding:0;
font-weight:normal;
}
@@ -554,8 +620,7 @@
font-size:1.15em;
background-color: #E2E2E2;
margin:1.5em 0 .6em;
- padding:3px;
- position:relative; /* so the api level can be absolute */
+ padding:3px 95px 3px 3px; /* room for api-level */
}
h4.jd-tagtitle {
@@ -598,7 +663,27 @@
div.special {
padding: .5em 1em 1em 1em;
margin: 0 0 1em;
- background-color: #ddf0f2;
+ background-color: #DAF3FC;
+ border:1px solid #d3ecf5;
+ border-radius:5px;
+ -moz-border-radius:5px;
+ -webkit-border-radius:5px;
+}
+
+.toggle-content-toggleme {
+ display:none;
+}
+
+.toggle-content-button {
+ font-size:.9em;
+ line-height:.9em;
+ text-decoration:none;
+ position:relative;
+ top:5px;
+}
+
+.toggle-content-button:hover {
+ text-decoration:underline;
}
div.special p {
@@ -673,7 +758,7 @@
.listhead li {
font-weight: bold;
}
-
+
.listhead li *, /*ie*/.listhead li li {
font-weight: normal;
}
@@ -689,6 +774,8 @@
font-weight: bold;
color: red;
text-decoration: none;
+ vertical-align:top;
+ line-height:.9em;
}
pre.classic {
@@ -697,6 +784,16 @@
padding:0;
}
+div.figure {
+ float:right;
+ padding:0 0 20px 20px;
+ /* width must be defined w/ an inline style matching the image width */
+}
+
+#jd-content div.figure img {
+ display:block;
+ margin:0 0 10px 0;
+}
/* BEGIN quickview sidebar element styles */
@@ -1122,21 +1219,16 @@
padding:0;
}
- #headerLeft .guide {
- display:none;
- }
-
- #headerRight {
+ #header-tabs,
+ #headerRight,
+ #side-nav,
+ #api-info-block {
display:none;
}
#body-content {
position:inherit;
}
-
- #side-nav {
- display:none;
- }
#doc-content {
margin-left:0 !important;
@@ -1181,10 +1273,4 @@
table, img {
page-break-inside: avoid;
}
-
-/* #qv,
- #qv-wrapper {
- display:none;
- }
-*/
}
diff --git a/tools/droiddoc/templates/assets/android-developer-docs.js b/tools/droiddoc/templates/assets/android-developer-docs.js
index 2edf39d..dfe8fa1 100644
--- a/tools/droiddoc/templates/assets/android-developer-docs.js
+++ b/tools/droiddoc/templates/assets/android-developer-docs.js
@@ -10,7 +10,9 @@
var nav_pref;
var toRoot;
var isMobile = false; // true if mobile, so we can adjust some layout
+var isIE6 = false; // true if IE6
+// TODO: use $(document).ready instead
function addLoadEvent(newfun) {
var current = window.onload;
if (typeof window.onload != 'function') {
@@ -23,25 +25,26 @@
}
}
-var agent = navigator['userAgent'];
-if ((agent.indexOf("Mobile") != -1) ||
- (agent.indexOf("BlackBerry") != -1) ||
- (agent.indexOf("Mini") != -1)) {
+var agent = navigator['userAgent'].toLowerCase();
+// If a mobile phone, set flag and do mobile setup
+if ((agent.indexOf("mobile") != -1) || // android, iphone, ipod
+ (agent.indexOf("blackberry") != -1) ||
+ (agent.indexOf("webos") != -1) ||
+ (agent.indexOf("mini") != -1)) { // opera mini browsers
isMobile = true;
addLoadEvent(mobileSetup);
+// If not a mobile browser, set the onresize event for IE6, and others
+} else if (agent.indexOf("msie 6") != -1) {
+ isIE6 = true;
+ addLoadEvent(function() {
+ window.onresize = resizeAll;
+ });
+} else {
+ addLoadEvent(function() {
+ window.onresize = resizeHeight;
+ });
}
-/* loads the lists.js file to the page.
-Loading this in the head was slowing page load time */
-addLoadEvent( function() {
- var lists = document.createElement("script");
- lists.setAttribute("type","text/javascript");
- lists.setAttribute("src", toRoot+"reference/lists.js");
- $("head").append($(lists));
-} );
-
-window.onresize = resizeAll;
-
function mobileSetup() {
$("body").css({'overflow':'auto'});
$("html").css({'overflow':'auto'});
@@ -51,6 +54,20 @@
$("#nav-tree").css({'overflow-y': 'auto'});
}
+/* loads the lists.js file to the page.
+Loading this in the head was slowing page load time */
+addLoadEvent( function() {
+ var lists = document.createElement("script");
+ lists.setAttribute("type","text/javascript");
+ lists.setAttribute("src", toRoot+"reference/lists.js");
+ document.getElementsByTagName("head")[0].appendChild(lists);
+} );
+
+addLoadEvent( function() {
+ $("pre:not(.no-pretty-print)").addClass("prettyprint");
+ prettyPrint();
+} );
+
function setToRoot(root) {
toRoot = root;
// note: toRoot also used by carousel.js
@@ -58,8 +75,12 @@
function restoreWidth(navWidth) {
var windowWidth = $(window).width() + "px";
- content.css({marginLeft:parseInt(navWidth) + 6 + "px", //account for 6px-wide handle-bar
- width:parseInt(windowWidth) - parseInt(navWidth) - 6 + "px"});
+ content.css({marginLeft:parseInt(navWidth) + 6 + "px"}); //account for 6px-wide handle-bar
+
+ if (isIE6) {
+ content.css({width:parseInt(windowWidth) - parseInt(navWidth) - 6 + "px"}); // necessary in order for scrollbars to be visible
+ }
+
sidenav.css({width:navWidth});
resizePackagesNav.css({width:navWidth});
classesNav.css({width:navWidth});
@@ -97,14 +118,14 @@
}
function writeCookie(cookie, val, section, expiration) {
- if (!val) return;
+ if (val==undefined) return;
section = section == null ? "_" : "_"+section+"_";
if (expiration == null) {
var date = new Date();
date.setTime(date.getTime()+(10*365*24*60*60*1000)); // default expiration is one week
expiration = date.toGMTString();
}
- document.cookie = cookie_namespace+section+cookie+"="+val+"; expires="+expiration+"; path=/";
+ document.cookie = cookie_namespace + section + cookie + "=" + val + "; expires=" + expiration+"; path=/";
}
function init() {
@@ -115,14 +136,17 @@
sidenav = $("#side-nav");
devdocNav = $("#devdoc-nav");
+ var cookiePath = "";
if (location.href.indexOf("/reference/") != -1) {
- var cookiePath = "reference_";
+ cookiePath = "reference_";
} else if (location.href.indexOf("/guide/") != -1) {
- var cookiePath = "guide_";
+ cookiePath = "guide_";
+ } else if (location.href.indexOf("/resources/") != -1) {
+ cookiePath = "resources_";
}
if (!isMobile) {
- $("#resize-packages-nav").resizable({handles: "s", resize: function(e, ui) { resizeHeight(); } });
+ $("#resize-packages-nav").resizable({handles: "s", resize: function(e, ui) { resizePackagesHeight(); } });
$(".side-nav-resizable").resizable({handles: "e", resize: function(e, ui) { resizeWidth(); } });
var cookieWidth = readCookie(cookiePath+'width');
var cookieHeight = readCookie(cookiePath+'height');
@@ -145,17 +169,22 @@
function highlightNav(fullPageName) {
var lastSlashPos = fullPageName.lastIndexOf("/");
- var firstSlashPos = (fullPageName.indexOf("/guide/") != -1) ?
- fullPageName.indexOf("/guide/") :
- fullPageName.indexOf("/sdk/"); // first slash after /guide or /sdk
+ var firstSlashPos;
+ if (fullPageName.indexOf("/guide/") != -1) {
+ firstSlashPos = fullPageName.indexOf("/guide/");
+ } else if (fullPageName.indexOf("/sdk/") != -1) {
+ firstSlashPos = fullPageName.indexOf("/sdk/");
+ } else {
+ firstSlashPos = fullPageName.indexOf("/resources/");
+ }
if (lastSlashPos == (fullPageName.length - 1)) { // if the url ends in slash (add 'index.html')
fullPageName = fullPageName + "index.html";
}
var htmlPos = fullPageName.lastIndexOf(".html", fullPageName.length);
var pathPageName = fullPageName.slice(firstSlashPos, htmlPos + 5);
var link = $("#devdoc-nav a[href$='"+ pathPageName+"']");
- if ((link.length == 0) && ((fullPageName.indexOf("/guide/") != -1) || (fullPageName.indexOf("/sdk/") != -1))) {
-// if there's no match, then let's backstep through the directory until we find an index.html page that matches our ancestor directories (only for dev guide and sdk)
+ if ((link.length == 0) && ((fullPageName.indexOf("/guide/") != -1) || (fullPageName.indexOf("/resources/") != -1))) {
+// if there's no match, then let's backstep through the directory until we find an index.html page that matches our ancestor directories (only for dev guide)
lastBackstep = pathPageName.lastIndexOf("/");
while (link.length == 0) {
backstepDirectory = pathPageName.lastIndexOf("/", lastBackstep);
@@ -172,23 +201,57 @@
}
}
-function resizeHeight() {
+/* Resize the height of the nav panels in the reference,
+ * and save the new size to a cookie */
+function resizePackagesHeight() {
var windowHeight = ($(window).height() - HEADER_HEIGHT);
- var swapperHeight = windowHeight - 13;
- $("#swapper").css({height:swapperHeight + "px"});
- sidenav.css({height:windowHeight + "px"});
- content.css({height:windowHeight + "px"});
+ var swapperHeight = windowHeight - 13; // move 13px for swapper link at the bottom
resizePackagesNav.css({maxHeight:swapperHeight + "px"});
classesNav.css({height:swapperHeight - parseInt(resizePackagesNav.css("height")) + "px"});
+
+ $("#swapper").css({height:swapperHeight + "px"});
$("#packages-nav").css({height:parseInt(resizePackagesNav.css("height")) - 6 + "px"}); //move 6px for handle
- devdocNav.css({height:sidenav.css("height")});
- $("#nav-tree").css({height:swapperHeight + "px"});
-
+
var basePath = getBaseUri(location.pathname);
var section = basePath.substring(1,basePath.indexOf("/",1));
writeCookie("height", resizePackagesNav.css("height"), section, null);
}
+/* Resize the height of the side-nav and doc-content divs,
+ * which creates the frame effect */
+function resizeHeight() {
+ var docContent = $("#doc-content");
+
+ // Get the window height and always resize the doc-content and side-nav divs
+ var windowHeight = ($(window).height() - HEADER_HEIGHT);
+ docContent.css({height:windowHeight + "px"});
+ $("#side-nav").css({height:windowHeight + "px"});
+
+ var href = location.href;
+ // If in the reference docs, also resize the "swapper", "classes-nav", and "nav-tree" divs
+ if (href.indexOf("/reference/") != -1) {
+ var swapperHeight = windowHeight - 13;
+ $("#swapper").css({height:swapperHeight + "px"});
+ $("#classes-nav").css({height:swapperHeight - parseInt(resizePackagesNav.css("height")) + "px"});
+ $("#nav-tree").css({height:swapperHeight + "px"});
+
+ // If in the dev guide docs, also resize the "devdoc-nav" div
+ } else if (href.indexOf("/guide/") != -1) {
+ $("#devdoc-nav").css({height:sidenav.css("height")});
+ } else if (href.indexOf("/resources/") != -1) {
+ $("#devdoc-nav").css({height:sidenav.css("height")});
+ }
+
+ // Hide the "Go to top" link if there's no vertical scroll
+ if ( parseInt($("#jd-content").css("height")) <= parseInt(docContent.css("height")) ) {
+ $("a[href='#top']").css({'display':'none'});
+ } else {
+ $("a[href='#top']").css({'display':'inline'});
+ }
+}
+
+/* Resize the width of the "side-nav" and the left margin of the "doc-content" div,
+ * which creates the resizable side bar */
function resizeWidth() {
var windowWidth = $(window).width() + "px";
if (sidenav.length) {
@@ -196,24 +259,29 @@
} else {
var sidenavWidth = 0;
}
- content.css({marginLeft:parseInt(sidenavWidth) + 6 + "px", //account for 6px-wide handle-bar
- width:parseInt(windowWidth) - parseInt(sidenavWidth) - 6 + "px"});
+ content.css({marginLeft:parseInt(sidenavWidth) + 6 + "px"}); //account for 6px-wide handle-bar
+
+ if (isIE6) {
+ content.css({width:parseInt(windowWidth) - parseInt(sidenavWidth) - 6 + "px"}); // necessary in order to for scrollbars to be visible
+ }
+
resizePackagesNav.css({width:sidenavWidth});
classesNav.css({width:sidenavWidth});
$("#packages-nav").css({width:sidenavWidth});
-
- var basePath = getBaseUri(location.pathname);
- var section = basePath.substring(1,basePath.indexOf("/",1));
- writeCookie("width", sidenavWidth, section, null);
+
+ if ($(".side-nav-resizable").length) { // Must check if the nav is resizable because IE6 calls resizeWidth() from resizeAll() for all pages
+ var basePath = getBaseUri(location.pathname);
+ var section = basePath.substring(1,basePath.indexOf("/",1));
+ writeCookie("width", sidenavWidth, section, null);
+ }
}
+/* For IE6 only,
+ * because it can't properly perform auto width for "doc-content" div,
+ * avoiding this for all browsers provides better performance */
function resizeAll() {
- if (!isMobile) {
- resizeHeight();
- if ($(".side-nav-resizable").length) {
- resizeWidth();
- }
- }
+ resizeHeight();
+ resizeWidth();
}
function getBaseUri(uri) {
@@ -261,6 +329,8 @@
writeCookie("lastpage", path, "reference", null);
} else if (path.indexOf("/guide/") != -1) {
writeCookie("lastpage", path, "guide", null);
+ } else if (path.indexOf("/resources/") != -1) {
+ writeCookie("lastpage", path, "resources", null);
}
});
@@ -446,3 +516,18 @@
}
return (lang != 0) ? lang : 'en';
}
+
+
+function toggleContent(obj) {
+ var button = $(obj);
+ var div = $(obj.parentNode);
+ var toggleMe = $(".toggle-content-toggleme",div);
+ if (button.hasClass("show")) {
+ toggleMe.slideDown();
+ button.removeClass("show").addClass("hide");
+ } else {
+ toggleMe.slideUp();
+ button.removeClass("hide").addClass("show");
+ }
+ $("span", button).toggle();
+}
diff --git a/tools/droiddoc/templates/assets/android-developer-reference.js b/tools/droiddoc/templates/assets/android-developer-reference.js
new file mode 100644
index 0000000..6299596
--- /dev/null
+++ b/tools/droiddoc/templates/assets/android-developer-reference.js
@@ -0,0 +1,296 @@
+
+/* API LEVEL TOGGLE */
+addLoadEvent(changeApiLevel);
+
+var API_LEVEL_ENABLED_COOKIE = "api_level_enabled";
+var API_LEVEL_COOKIE = "api_level";
+var minLevel = 1;
+
+function toggleApiLevelSelector(checkbox) {
+ var date = new Date();
+ date.setTime(date.getTime()+(10*365*24*60*60*1000)); // keep this for 10 years
+ var expiration = date.toGMTString();
+ if (checkbox.checked) {
+ $("#apiLevelSelector").removeAttr("disabled");
+ $("#api-level-toggle label").removeClass("disabled");
+ writeCookie(API_LEVEL_ENABLED_COOKIE, 1, null, expiration);
+ } else {
+ $("#apiLevelSelector").attr("disabled","disabled");
+ $("#api-level-toggle label").addClass("disabled");
+ writeCookie(API_LEVEL_ENABLED_COOKIE, 0, null, expiration);
+ }
+ changeApiLevel();
+}
+
+function buildApiLevelSelector() {
+ var maxLevel = SINCE_DATA.length;
+ var userApiLevelEnabled = readCookie(API_LEVEL_ENABLED_COOKIE);
+ var userApiLevel = readCookie(API_LEVEL_COOKIE);
+ userApiLevel = userApiLevel == 0 ? maxLevel : userApiLevel; // If there's no cookie (zero), use the max by default
+
+ if (userApiLevelEnabled == 0) {
+ $("#apiLevelSelector").attr("disabled","disabled");
+ } else {
+ $("#apiLevelCheckbox").attr("checked","checked");
+ $("#api-level-toggle label").removeClass("disabled");
+ }
+
+ minLevel = $("body").attr("class");
+ var select = $("#apiLevelSelector").html("").change(changeApiLevel);
+ for (var i = maxLevel-1; i >= 0; i--) {
+ var option = $("<option />").attr("value",""+SINCE_DATA[i]).append(""+SINCE_DATA[i]);
+ // if (SINCE_DATA[i] < minLevel) option.addClass("absent"); // always false for strings (codenames)
+ select.append(option);
+ }
+
+ // get the DOM element and use setAttribute cuz IE6 fails when using jquery .attr('selected',true)
+ var selectedLevelItem = $("#apiLevelSelector option[value='"+userApiLevel+"']").get(0);
+ selectedLevelItem.setAttribute('selected',true);
+}
+
+function changeApiLevel() {
+ var maxLevel = SINCE_DATA.length;
+ var userApiLevelEnabled = readCookie(API_LEVEL_ENABLED_COOKIE);
+ var selectedLevel = maxLevel;
+
+ if (userApiLevelEnabled == 0) {
+ toggleVisisbleApis(selectedLevel, "body");
+ } else {
+ selectedLevel = $("#apiLevelSelector option:selected").val();
+ toggleVisisbleApis(selectedLevel, "body");
+
+ var date = new Date();
+ date.setTime(date.getTime()+(10*365*24*60*60*1000)); // keep this for 10 years
+ var expiration = date.toGMTString();
+ writeCookie(API_LEVEL_COOKIE, selectedLevel, null, expiration);
+ }
+
+ if (selectedLevel < minLevel) {
+ var thing = ($("#jd-header").html().indexOf("package") != -1) ? "package" : "class";
+ $("#naMessage").show().html("<div><p><strong>This " + thing + " is not available with API Level " + selectedLevel + ".</strong></p>"
+ + "<p>To use this " + thing + ", your application must specify API Level " + minLevel + " or higher in its manifest "
+ + "and be compiled against a version of the Android library that supports an equal or higher API Level. To reveal this "
+ + "document, change the value of the API Level filter above.</p>"
+ + "<p><a href='" +toRoot+ "guide/appendix/api-levels.html'>What is the API Level?</a></p></div>");
+ } else {
+ $("#naMessage").hide();
+ }
+}
+
+function toggleVisisbleApis(selectedLevel, context) {
+ var apis = $(".api",context);
+ apis.each(function(i) {
+ var obj = $(this);
+ var className = obj.attr("class");
+ var apiLevelIndex = className.lastIndexOf("-")+1;
+ var apiLevelEndIndex = className.indexOf(" ", apiLevelIndex);
+ apiLevelEndIndex = apiLevelEndIndex != -1 ? apiLevelEndIndex : className.length;
+ var apiLevel = className.substring(apiLevelIndex, apiLevelEndIndex);
+ if (apiLevel > selectedLevel) obj.addClass("absent").attr("title","Requires API Level "+apiLevel+" or higher");
+ else obj.removeClass("absent").removeAttr("title");
+ });
+}
+
+/* NAVTREE */
+
+function new_node(me, mom, text, link, children_data, api_level)
+{
+ var node = new Object();
+ node.children = Array();
+ node.children_data = children_data;
+ node.depth = mom.depth + 1;
+
+ node.li = document.createElement("li");
+ mom.get_children_ul().appendChild(node.li);
+
+ node.label_div = document.createElement("div");
+ node.label_div.className = "label";
+ if (api_level != null) {
+ $(node.label_div).addClass("api");
+ $(node.label_div).addClass("api-level-"+api_level);
+ }
+ node.li.appendChild(node.label_div);
+ node.label_div.style.paddingLeft = 10*node.depth + "px";
+
+ if (children_data == null) {
+ // 12 is the width of the triangle and padding extra space
+ node.label_div.style.paddingLeft = ((10*node.depth)+12) + "px";
+ } else {
+ node.label_div.style.paddingLeft = 10*node.depth + "px";
+ node.expand_toggle = document.createElement("a");
+ node.expand_toggle.href = "javascript:void(0)";
+ node.expand_toggle.onclick = function() {
+ if (node.expanded) {
+ $(node.get_children_ul()).slideUp("fast");
+ node.plus_img.src = me.toroot + "assets/images/triangle-closed-small.png";
+ node.expanded = false;
+ } else {
+ expand_node(me, node);
+ }
+ };
+ node.label_div.appendChild(node.expand_toggle);
+
+ node.plus_img = document.createElement("img");
+ node.plus_img.src = me.toroot + "assets/images/triangle-closed-small.png";
+ node.plus_img.className = "plus";
+ node.plus_img.border = "0";
+ node.expand_toggle.appendChild(node.plus_img);
+
+ node.expanded = false;
+ }
+
+ var a = document.createElement("a");
+ node.label_div.appendChild(a);
+ node.label = document.createTextNode(text);
+ a.appendChild(node.label);
+ if (link) {
+ a.href = me.toroot + link;
+ } else {
+ if (children_data != null) {
+ a.className = "nolink";
+ a.href = "javascript:void(0)";
+ a.onclick = node.expand_toggle.onclick;
+ // This next line shouldn't be necessary. I'll buy a beer for the first
+ // person who figures out how to remove this line and have the link
+ // toggle shut on the first try. --joeo@android.com
+ node.expanded = false;
+ }
+ }
+
+
+ node.children_ul = null;
+ node.get_children_ul = function() {
+ if (!node.children_ul) {
+ node.children_ul = document.createElement("ul");
+ node.children_ul.className = "children_ul";
+ node.children_ul.style.display = "none";
+ node.li.appendChild(node.children_ul);
+ }
+ return node.children_ul;
+ };
+
+ return node;
+}
+
+function expand_node(me, node)
+{
+ if (node.children_data && !node.expanded) {
+ if (node.children_visited) {
+ $(node.get_children_ul()).slideDown("fast");
+ } else {
+ get_node(me, node);
+ if ($(node.label_div).hasClass("absent")) $(node.get_children_ul()).addClass("absent");
+ $(node.get_children_ul()).slideDown("fast");
+ }
+ node.plus_img.src = me.toroot + "assets/images/triangle-opened-small.png";
+ node.expanded = true;
+
+ // perform api level toggling because new nodes are new to the DOM
+ var selectedLevel = $("#apiLevelSelector option:selected").val();
+ toggleVisisbleApis(selectedLevel, "#side-nav");
+ }
+}
+
+function get_node(me, mom)
+{
+ mom.children_visited = true;
+ for (var i in mom.children_data) {
+ var node_data = mom.children_data[i];
+ mom.children[i] = new_node(me, mom, node_data[0], node_data[1],
+ node_data[2], node_data[3]);
+ }
+}
+
+function this_page_relative(toroot)
+{
+ var full = document.location.pathname;
+ var file = "";
+ if (toroot.substr(0, 1) == "/") {
+ if (full.substr(0, toroot.length) == toroot) {
+ return full.substr(toroot.length);
+ } else {
+ // the file isn't under toroot. Fail.
+ return null;
+ }
+ } else {
+ if (toroot != "./") {
+ toroot = "./" + toroot;
+ }
+ do {
+ if (toroot.substr(toroot.length-3, 3) == "../" || toroot == "./") {
+ var pos = full.lastIndexOf("/");
+ file = full.substr(pos) + file;
+ full = full.substr(0, pos);
+ toroot = toroot.substr(0, toroot.length-3);
+ }
+ } while (toroot != "" && toroot != "/");
+ return file.substr(1);
+ }
+}
+
+function find_page(url, data)
+{
+ var nodes = data;
+ var result = null;
+ for (var i in nodes) {
+ var d = nodes[i];
+ if (d[1] == url) {
+ return new Array(i);
+ }
+ else if (d[2] != null) {
+ result = find_page(url, d[2]);
+ if (result != null) {
+ return (new Array(i).concat(result));
+ }
+ }
+ }
+ return null;
+}
+
+function load_navtree_data(toroot) {
+ var navtreeData = document.createElement("script");
+ navtreeData.setAttribute("type","text/javascript");
+ navtreeData.setAttribute("src", toroot+"navtree_data.js");
+ $("head").append($(navtreeData));
+}
+
+function init_default_navtree(toroot) {
+ init_navtree("nav-tree", toroot, NAVTREE_DATA);
+
+ // perform api level toggling because because the whole tree is new to the DOM
+ var selectedLevel = $("#apiLevelSelector option:selected").val();
+ toggleVisisbleApis(selectedLevel, "#side-nav");
+}
+
+function init_navtree(navtree_id, toroot, root_nodes)
+{
+ var me = new Object();
+ me.toroot = toroot;
+ me.node = new Object();
+
+ me.node.li = document.getElementById(navtree_id);
+ me.node.children_data = root_nodes;
+ me.node.children = new Array();
+ me.node.children_ul = document.createElement("ul");
+ me.node.get_children_ul = function() { return me.node.children_ul; };
+ //me.node.children_ul.className = "children_ul";
+ me.node.li.appendChild(me.node.children_ul);
+ me.node.depth = 0;
+
+ get_node(me, me.node);
+
+ me.this_page = this_page_relative(toroot);
+ me.breadcrumbs = find_page(me.this_page, root_nodes);
+ if (me.breadcrumbs != null && me.breadcrumbs.length != 0) {
+ var mom = me.node;
+ for (var i in me.breadcrumbs) {
+ var j = me.breadcrumbs[i];
+ mom = mom.children[j];
+ expand_node(me, mom);
+ }
+ mom.label_div.className = mom.label_div.className + " selected";
+ addLoadEvent(function() {
+ scrollIntoView("nav-tree");
+ });
+ }
+}
diff --git a/tools/droiddoc/templates/assets/carousel.js b/tools/droiddoc/templates/assets/carousel.js
index 57eaff7..9512f8f 100644
--- a/tools/droiddoc/templates/assets/carousel.js
+++ b/tools/droiddoc/templates/assets/carousel.js
@@ -83,7 +83,7 @@
/* add the bulletins */
- var layout = droid.layout;
+ var layout = droid.layout;
var div = document.createElement("div");
var imgDiv = document.createElement("div");
var descDiv = document.createElement("div");
@@ -112,9 +112,6 @@
$("#carouselMain").append(div);
}
-
-
-
}
// -- * slider * -- //
diff --git a/tools/droiddoc/templates/assets/images/home/Android_Dev_Lab_l.png b/tools/droiddoc/templates/assets/images/home/Android_Dev_Lab_l.png
new file mode 100644
index 0000000..3c04f24
--- /dev/null
+++ b/tools/droiddoc/templates/assets/images/home/Android_Dev_Lab_l.png
Binary files differ
diff --git a/tools/droiddoc/templates/assets/images/home/adc2_l.png b/tools/droiddoc/templates/assets/images/home/adc2_l.png
new file mode 100644
index 0000000..0b101a4
--- /dev/null
+++ b/tools/droiddoc/templates/assets/images/home/adc2_l.png
Binary files differ
diff --git a/tools/droiddoc/templates/assets/images/home/adc2_s.png b/tools/droiddoc/templates/assets/images/home/adc2_s.png
new file mode 100644
index 0000000..0d36bdb
--- /dev/null
+++ b/tools/droiddoc/templates/assets/images/home/adc2_s.png
Binary files differ
diff --git a/tools/droiddoc/templates/assets/images/home/devphone-large.png b/tools/droiddoc/templates/assets/images/home/devphone-large.png
old mode 100755
new mode 100644
index cbf94c8..6221e0a
--- a/tools/droiddoc/templates/assets/images/home/devphone-large.png
+++ b/tools/droiddoc/templates/assets/images/home/devphone-large.png
Binary files differ
diff --git a/tools/droiddoc/templates/assets/images/home/donut-android.png b/tools/droiddoc/templates/assets/images/home/donut-android.png
new file mode 100755
index 0000000..6aba06b
--- /dev/null
+++ b/tools/droiddoc/templates/assets/images/home/donut-android.png
Binary files differ
diff --git a/tools/droiddoc/templates/assets/images/home/eclair-android.png b/tools/droiddoc/templates/assets/images/home/eclair-android.png
new file mode 100644
index 0000000..d476ce9
--- /dev/null
+++ b/tools/droiddoc/templates/assets/images/home/eclair-android.png
Binary files differ
diff --git a/tools/droiddoc/templates/assets/images/preliminary.png b/tools/droiddoc/templates/assets/images/preliminary.png
old mode 100755
new mode 100644
index aad1644..fe0da3d
--- a/tools/droiddoc/templates/assets/images/preliminary.png
+++ b/tools/droiddoc/templates/assets/images/preliminary.png
Binary files differ
diff --git a/tools/droiddoc/templates/assets/navtree.js b/tools/droiddoc/templates/assets/navtree.js
deleted file mode 100644
index 33a4f81..0000000
--- a/tools/droiddoc/templates/assets/navtree.js
+++ /dev/null
@@ -1,192 +0,0 @@
-
-function new_node(me, mom, text, link, children_data)
-{
- var node = new Object();
- node.children = Array();
- node.children_data = children_data;
- node.depth = mom.depth + 1;
-
- node.li = document.createElement("li");
- mom.get_children_ul().appendChild(node.li);
-
- node.label_div = document.createElement("div");
- node.li.appendChild(node.label_div);
- node.label_div.style.paddingLeft = 10*node.depth + "px";
- node.label_div.className = "label";
-
- if (children_data == null) {
- // 12 is the width of the triangle and padding extra space
- node.label_div.style.paddingLeft = ((10*node.depth)+12) + "px";
- } else {
- node.label_div.style.paddingLeft = 10*node.depth + "px";
- node.expand_toggle = document.createElement("a");
- node.expand_toggle.href = "javascript:void(0)";
- node.expand_toggle.onclick = function() {
- if (node.expanded) {
- $(node.get_children_ul()).slideUp("fast");
- node.plus_img.src = me.toroot + "assets/images/triangle-closed-small.png";
- node.expanded = false;
- } else {
- expand_node(me, node);
- }
- };
- node.label_div.appendChild(node.expand_toggle);
-
- node.plus_img = document.createElement("img");
- node.plus_img.src = me.toroot + "assets/images/triangle-closed-small.png";
- node.plus_img.className = "plus";
- node.plus_img.border = "0";
- node.expand_toggle.appendChild(node.plus_img);
-
- node.expanded = false;
- }
-
- var a = document.createElement("a");
- node.label_div.appendChild(a);
- node.label = document.createTextNode(text);
- a.appendChild(node.label);
- if (link) {
- a.href = me.toroot + link;
- } else {
- if (children_data != null) {
- a.className = "nolink";
- a.href = "javascript:void(0)";
- a.onclick = node.expand_toggle.onclick;
- // This next line shouldn't be necessary. I'll buy a beer for the first
- // person who figures out how to remove this line and have the link
- // toggle shut on the first try. --joeo@android.com
- node.expanded = false;
- }
- }
-
-
- node.children_ul = null;
- node.get_children_ul = function() {
- if (!node.children_ul) {
- node.children_ul = document.createElement("ul");
- node.children_ul.className = "children_ul";
- node.children_ul.style.display = "none";
- node.li.appendChild(node.children_ul);
- }
- return node.children_ul;
- };
-
- return node;
-}
-
-function expand_node(me, node)
-{
- if (node.children_data && !node.expanded) {
- if (node.children_visited) {
- $(node.get_children_ul()).slideDown("fast");
- } else {
- get_node(me, node);
- $(node.get_children_ul()).slideDown("fast");
- }
- node.plus_img.src = me.toroot + "assets/images/triangle-opened-small.png";
- node.expanded = true;
- }
-}
-
-function get_node(me, mom)
-{
- mom.children_visited = true;
- for (var i in mom.children_data) {
- var node_data = mom.children_data[i];
- mom.children[i] = new_node(me, mom, node_data[0], node_data[1],
- node_data[2]);
- }
-}
-
-function this_page_relative(toroot)
-{
- var full = document.location.pathname;
- var file = "";
- if (toroot.substr(0, 1) == "/") {
- if (full.substr(0, toroot.length) == toroot) {
- var basePath = getBaseUri(full);
- return basePath.substring(toroot.length);
- } else {
- // the file isn't under toroot. Fail.
- return null;
- }
- } else {
- if (toroot != "./") {
- toroot = "./" + toroot;
- }
- do {
- if (toroot.substr(toroot.length-3, 3) == "../" || toroot == "./") {
- var pos = full.lastIndexOf("/");
- file = full.substr(pos) + file;
- full = full.substr(0, pos);
- toroot = toroot.substr(0, toroot.length-3);
- }
- } while (toroot != "" && toroot != "/");
- return file.substr(1);
- }
-}
-
-function find_page(url, data)
-{
- var nodes = data;
- var result = null;
- for (var i in nodes) {
- var d = nodes[i];
- if (d[1] == url) {
- return new Array(i);
- }
- else if (d[2] != null) {
- result = find_page(url, d[2]);
- if (result != null) {
- return (new Array(i).concat(result));
- }
- }
- }
- return null;
-}
-
-function load_navtree_data(toroot) {
- var navtreeData = document.createElement("script");
- navtreeData.setAttribute("type","text/javascript");
- navtreeData.setAttribute("src", toroot+"navtree_data.js");
- $("head").append($(navtreeData));
-}
-
-function init_default_navtree(toroot) {
- load_navtree_data(toroot);
- init_navtree("nav-tree", toroot, NAVTREE_DATA);
-}
-
-function init_navtree(navtree_id, toroot, root_nodes)
-{
- var me = new Object();
- me.toroot = toroot;
- me.node = new Object();
-
- me.node.li = document.getElementById(navtree_id);
- me.node.children_data = root_nodes;
- me.node.children = new Array();
- me.node.children_ul = document.createElement("ul");
- me.node.get_children_ul = function() { return me.node.children_ul; };
- //me.node.children_ul.className = "children_ul";
- me.node.li.appendChild(me.node.children_ul);
- me.node.depth = 0;
-
- get_node(me, me.node);
-
- me.this_page = this_page_relative(toroot);
- me.breadcrumbs = find_page(me.this_page, root_nodes);
- if (me.breadcrumbs != null && me.breadcrumbs.length != 0) {
- var mom = me.node;
- for (var i in me.breadcrumbs) {
- var j = me.breadcrumbs[i];
- mom = mom.children[j];
- expand_node(me, mom);
- }
- mom.label_div.className = mom.label_div.className + " selected";
- addLoadEvent(function() {
- scrollIntoView("nav-tree");
- });
- }
-}
-
diff --git a/tools/droiddoc/templates/assets/prettify.js b/tools/droiddoc/templates/assets/prettify.js
new file mode 100644
index 0000000..076f9d0
--- /dev/null
+++ b/tools/droiddoc/templates/assets/prettify.js
@@ -0,0 +1,33 @@
+(function(){
+var o=true,r=null,z=false;window.PR_SHOULD_USE_CONTINUATION=o;window.PR_TAB_WIDTH=8;window.PR_normalizedHtml=window.PR=window.prettyPrintOne=window.prettyPrint=void 0;window._pr_isIE6=function(){var N=navigator&&navigator.userAgent&&/\bMSIE 6\./.test(navigator.userAgent);window._pr_isIE6=function(){return N};return N};
+var aa="!",ba="!=",ca="!==",F="#",da="%",ea="%=",G="&",fa="&&",ja="&&=",ka="&=",H="(",la="*",ma="*=",na="+=",oa=",",pa="-=",qa="->",ra="/",sa="/=",ta=":",ua="::",va=";",I="<",wa="<<",xa="<<=",ya="<=",za="=",Aa="==",Ba="===",J=">",Ca=">=",Da=">>",Ea=">>=",Fa=">>>",Ga=">>>=",Ha="?",Ia="@",L="[",M="^",Ta="^=",Ua="^^",Va="^^=",Wa="{",O="|",Xa="|=",Ya="||",Za="||=",$a="~",ab="break",bb="case",cb="continue",db="delete",eb="do",fb="else",gb="finally",hb="instanceof",ib="return",jb="throw",kb="try",lb="typeof",
+mb="(?:^^|[+-]",nb="\\$1",ob=")\\s*",pb="&",qb="<",rb=">",sb=""",tb="&#",ub="x",vb="'",wb='"',xb=" ",yb="XMP",zb="</",Ab='="',P="",Q="\\",Bb="b",Cb="t",Db="n",Eb="v",Fb="f",Gb="r",Hb="u",Ib="0",Jb="1",Kb="2",Lb="3",Mb="4",Nb="5",Ob="6",Pb="7",Qb="\\x0",Rb="\\x",Sb="-",Tb="]",Ub="\\\\u[0-9A-Fa-f]{4}|\\\\x[0-9A-Fa-f]{2}|\\\\[0-3][0-7]{0,2}|\\\\[0-7]{1,2}|\\\\[\\s\\S]|-|[^-\\\\]",R="g",Vb="\\B",Wb="\\b",Xb="\\D",Yb="\\d",Zb="\\S",$b="\\s",ac="\\W",bc="\\w",cc="(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)",
+dc="(?:",ec=")",fc="gi",gc="PRE",hc='<!DOCTYPE foo PUBLIC "foo bar">\n<foo />',ic="\t",jc="\n",kc="[^<]+|<!--[\\s\\S]*?--\>|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>|</?[a-zA-Z][^>]*>|<",lc="nocode",mc=' $1="$2$3$4"',S="pln",nc="string",T="lang-",oc="src",U="str",pc="'\"",qc="'\"`",rc="\"'",V="com",sc="lang-regex",tc="(/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/)",uc="kwd",vc="^(?:",wc=")\\b",xc=" \r\n\t\u00a0",yc="lit",zc="typ",Ac="0123456789",Y="pun",Bc="break continue do else for if return while auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile catch class delete false import new operator private protected public this throw true try alignof align_union asm axiom bool concept concept_map const_cast constexpr decltype dynamic_cast explicit export friend inline late_check mutable namespace nullptr reinterpret_cast static_assert static_cast template typeid typename typeof using virtual wchar_t where break continue do else for if return while auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile catch class delete false import new operator private protected public this throw true try boolean byte extends final finally implements import instanceof null native package strictfp super synchronized throws transient as base by checked decimal delegate descending event fixed foreach from group implicit in interface internal into is lock object out override orderby params partial readonly ref sbyte sealed stackalloc string select uint ulong unchecked unsafe ushort var break continue do else for if return while auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile catch class delete false import new operator private protected public this throw true try debugger eval export function get null set undefined var with Infinity NaN caller delete die do dump elsif eval exit foreach for goto if import last local my next no our print package redo require sub undef unless until use wantarray while BEGIN END break continue do else for if return while and as assert class def del elif except exec finally from global import in is lambda nonlocal not or pass print raise try with yield False True None break continue do else for if return while alias and begin case class def defined elsif end ensure false in module next nil not or redo rescue retry self super then true undef unless until when yield BEGIN END break continue do else for if return while case done elif esac eval fi function in local set then until ",
+Cc="</span>",Dc='<span class="',Ec='">',Fc="$1 ",Gc=" <br />",Hc="<br />",Ic="console",Jc="cannot override language handler %s",Kc="default-markup",Lc="default-code",Mc="dec",Z="lang-js",$="lang-css",Nc="lang-in.tag",Oc="htm",Pc="html",Qc="mxml",Rc="xhtml",Sc="xml",Tc="xsl",Uc=" \t\r\n",Vc="atv",Wc="tag",Xc="atn",Yc="lang-uq.val",Zc="in.tag",$c="uq.val",ad="break continue do else for if return while auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile catch class delete false import new operator private protected public this throw true try alignof align_union asm axiom bool concept concept_map const_cast constexpr decltype dynamic_cast explicit export friend inline late_check mutable namespace nullptr reinterpret_cast static_assert static_cast template typeid typename typeof using virtual wchar_t where ",
+bd="c",cd="cc",dd="cpp",ed="cxx",fd="cyc",gd="m",hd="null true false",id="json",jd="break continue do else for if return while auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile catch class delete false import new operator private protected public this throw true try boolean byte extends final finally implements import instanceof null native package strictfp super synchronized throws transient as base by checked decimal delegate descending event fixed foreach from group implicit in interface internal into is lock object out override orderby params partial readonly ref sbyte sealed stackalloc string select uint ulong unchecked unsafe ushort var ",
+kd="cs",ld="break continue do else for if return while auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile catch class delete false import new operator private protected public this throw true try boolean byte extends final finally implements import instanceof null native package strictfp super synchronized throws transient ",md="java",nd="break continue do else for if return while case done elif esac eval fi function in local set then until ",
+od="bsh",pd="csh",qd="sh",rd="break continue do else for if return while and as assert class def del elif except exec finally from global import in is lambda nonlocal not or pass print raise try with yield False True None ",sd="cv",td="py",ud="caller delete die do dump elsif eval exit foreach for goto if import last local my next no our print package redo require sub undef unless until use wantarray while BEGIN END ",vd="perl",wd="pl",xd="pm",yd="break continue do else for if return while alias and begin case class def defined elsif end ensure false in module next nil not or redo rescue retry self super then true undef unless until when yield BEGIN END ",
+zd="rb",Ad="break continue do else for if return while auto case char const default double enum extern float goto int long register short signed sizeof static struct switch typedef union unsigned void volatile catch class delete false import new operator private protected public this throw true try debugger eval export function get null set undefined var with Infinity NaN ",Bd="js",Cd="regex",Dd="pre",Ed="code",Fd="xmp",Gd="prettyprint",Hd="class",Id="br",Jd="\r";
+(function(){var N=function(){for(var a=[aa,ba,ca,F,da,ea,G,fa,ja,ka,H,la,ma,na,oa,pa,qa,ra,sa,ta,ua,va,I,wa,xa,ya,za,Aa,Ba,J,Ca,Da,Ea,Fa,Ga,Ha,Ia,L,M,Ta,Ua,Va,Wa,O,Xa,Ya,Za,$a,ab,bb,cb,db,eb,fb,gb,hb,ib,jb,kb,lb],b=mb,c=0;c<a.length;++c)b+=O+a[c].replace(/([^=<>:&a-z])/g,nb);b+=ob;return b}(),Ja=/&/g,Ka=/</g,La=/>/g,Kd=/\"/g;function Ld(a){return a.replace(Ja,pb).replace(Ka,qb).replace(La,rb).replace(Kd,sb)}function ga(a){return a.replace(Ja,pb).replace(Ka,qb).replace(La,rb)}var Md=/</g,Nd=/>/g,
+Od=/'/g,Pd=/"/g,Qd=/&/g,Rd=/ /g;function Sd(a){var b=a.indexOf(G);if(b<0)return a;for(--b;(b=a.indexOf(tb,b+1))>=0;){var c=a.indexOf(va,b);if(c>=0){var d=a.substring(b+3,c),g=10;if(d&&d.charAt(0)===ub){d=d.substring(1);g=16}var i=parseInt(d,g);isNaN(i)||(a=a.substring(0,b)+String.fromCharCode(i)+a.substring(c+1))}}return a.replace(Md,I).replace(Nd,J).replace(Od,vb).replace(Pd,wb).replace(Qd,G).replace(Rd,xb)}function Ma(a){return yb===a.tagName}function W(a,b){switch(a.nodeType){case 1:var c=
+a.tagName.toLowerCase();b.push(I,c);for(var d=0;d<a.attributes.length;++d){var g=a.attributes[d];if(g.specified){b.push(xb);W(g,b)}}b.push(J);for(var i=a.firstChild;i;i=i.nextSibling)W(i,b);if(a.firstChild||!/^(?:br|link|img)$/.test(c))b.push(zb,c,J);break;case 2:b.push(a.name.toLowerCase(),Ab,Ld(a.value),wb);break;case 3:case 4:b.push(ga(a.nodeValue));break}}function Na(a){for(var b=0,c=z,d=z,g=0,i=a.length;g<i;++g){var m=a[g];if(m.ignoreCase)d=o;else if(/[a-z]/i.test(m.source.replace(/\\u[0-9a-f]{4}|\\x[0-9a-f]{2}|\\[^ux]/gi,
+P))){c=o;d=z;break}}function l(j){if(j.charAt(0)!==Q)return j.charCodeAt(0);switch(j.charAt(1)){case Bb:return 8;case Cb:return 9;case Db:return 10;case Eb:return 11;case Fb:return 12;case Gb:return 13;case Hb:case ub:return parseInt(j.substring(2),16)||j.charCodeAt(1);case Ib:case Jb:case Kb:case Lb:case Mb:case Nb:case Ob:case Pb:return parseInt(j.substring(1),8);default:return j.charCodeAt(1)}}function n(j){if(j<32)return(j<16?Qb:Rb)+j.toString(16);var f=String.fromCharCode(j);if(f===Q||f===Sb||
+f===L||f===Tb)f=Q+f;return f}function q(j){for(var f=j.substring(1,j.length-1).match(new RegExp(Ub,R)),s=[],k=[],h=f[0]===M,e=h?1:0,p=f.length;e<p;++e){var t=f[e];switch(t){case Vb:case Wb:case Xb:case Yb:case Zb:case $b:case ac:case bc:s.push(t);continue}var u=l(t),x;if(e+2<p&&Sb===f[e+1]){x=l(f[e+2]);e+=2}else x=u;k.push([u,x]);if(!(x<65||u>122)){x<65||u>90||k.push([Math.max(65,u)|32,Math.min(x,90)|32]);x<97||u>122||k.push([Math.max(97,u)&-33,Math.min(x,122)&-33])}}k.sort(function(Oa,Pa){return Oa[0]-
+Pa[0]||Pa[1]-Oa[1]});var B=[],E=[NaN,NaN];for(e=0;e<k.length;++e){var A=k[e];if(A[0]<=E[1]+1)E[1]=Math.max(E[1],A[1]);else B.push(E=A)}var D=[L];h&&D.push(M);D.push.apply(D,s);for(e=0;e<B.length;++e){A=B[e];D.push(n(A[0]));if(A[1]>A[0]){A[1]+1>A[0]&&D.push(Sb);D.push(n(A[1]))}}D.push(Tb);return D.join(P)}function v(j){var f=j.source.match(new RegExp(cc,R)),s=f.length,k=[],h,e=0;for(h=0;e<s;++e){var p=f[e];if(p===H)++h;else if(Q===p.charAt(0)){var t=+p.substring(1);if(t&&t<=h)k[t]=-1}}for(e=1;e<k.length;++e)if(-1===
+k[e])k[e]=++b;for(h=e=0;e<s;++e){p=f[e];if(p===H){++h;if(k[h]===undefined)f[e]=dc}else if(Q===p.charAt(0))if((t=+p.substring(1))&&t<=h)f[e]=Q+k[h]}for(h=e=0;e<s;++e)if(M===f[e]&&M!==f[e+1])f[e]=P;if(j.ignoreCase&&c)for(e=0;e<s;++e){p=f[e];var u=p.charAt(0);if(p.length>=2&&u===L)f[e]=q(p);else if(u!==Q)f[e]=p.replace(/[a-zA-Z]/g,function(x){var B=x.charCodeAt(0);return L+String.fromCharCode(B&-33,B|32)+Tb})}return f.join(P)}var w=[];g=0;for(i=a.length;g<i;++g){m=a[g];if(m.global||m.multiline)throw new Error(P+
+m);w.push(dc+v(m)+ec)}return new RegExp(w.join(O),d?fc:R)}var ha=r;function Td(a){if(r===ha){var b=document.createElement(gc);b.appendChild(document.createTextNode(hc));ha=!/</.test(b.innerHTML)}if(ha){var c=a.innerHTML;if(Ma(a))c=ga(c);return c}for(var d=[],g=a.firstChild;g;g=g.nextSibling)W(g,d);return d.join(P)}function Ud(a){var b=0;return function(c){for(var d=r,g=0,i=0,m=c.length;i<m;++i){var l=c.charAt(i);switch(l){case ic:d||(d=[]);d.push(c.substring(g,i));var n=a-b%a;for(b+=n;n>=0;n-=" ".length)d.push(" ".substring(0,
+n));g=i+1;break;case jc:b=0;break;default:++b}}if(!d)return c;d.push(c.substring(g));return d.join(P)}}var Vd=new RegExp(kc,R),Wd=/^<\!--/,Xd=/^<\[CDATA\[/,Yd=/^<br\b/i,Qa=/^<(\/?)([a-zA-Z]+)/;function Zd(a){var b=a.match(Vd),c=[],d=0,g=[];if(b)for(var i=0,m=b.length;i<m;++i){var l=b[i];if(l.length>1&&l.charAt(0)===I){if(!Wd.test(l))if(Xd.test(l)){c.push(l.substring(9,l.length-3));d+=l.length-12}else if(Yd.test(l)){c.push(jc);++d}else if(l.indexOf(lc)>=0&&$d(l)){var n=l.match(Qa)[2],q=1,v;v=i+1;a:for(;v<
+m;++v){var w=b[v].match(Qa);if(w&&w[2]===n)if(w[1]===ra){if(--q===0)break a}else++q}if(v<m){g.push(d,b.slice(i,v+1).join(P));i=v}else g.push(d,l)}else g.push(d,l)}else{var j=Sd(l);c.push(j);d+=j.length}}return{source:c.join(P),tags:g}}function $d(a){return!!a.replace(/\s(\w+)\s*=\s*(?:\"([^\"]*)\"|'([^\']*)'|(\S+))/g,mc).match(/[cC][lL][aA][sS][sS]=\"[^\"]*\bnocode\b/)}function ia(a,b,c,d){if(b){var g={source:b,b:a};c(g);d.push.apply(d,g.c)}}function K(a,b){var c={},d;(function(){for(var m=a.concat(b),
+l=[],n={},q=0,v=m.length;q<v;++q){var w=m[q],j=w[3];if(j)for(var f=j.length;--f>=0;)c[j.charAt(f)]=w;var s=w[1],k=P+s;if(!n.hasOwnProperty(k)){l.push(s);n[k]=r}}l.push(/[\0-\uffff]/);d=Na(l)})();var g=b.length,i=function(m){for(var l=m.source,n=m.b,q=[n,S],v=0,w=l.match(d)||[],j={},f=0,s=w.length;f<s;++f){var k=w[f],h=j[k],e,p;if(typeof h===nc)p=z;else{var t=c[k.charAt(0)];if(t){e=k.match(t[1]);h=t[0]}else{for(var u=0;u<g;++u){t=b[u];if(e=k.match(t[1])){h=t[0];break}}e||(h=S)}if((p=h.length>=5&&T===
+h.substring(0,5))&&!(e&&e[1])){p=z;h=oc}p||(j[k]=h)}var x=v;v+=k.length;if(p){var B=e[1],E=k.indexOf(B),A=E+B.length,D=h.substring(5);ia(n+x,k.substring(0,E),i,q);ia(n+x+E,B,Ra(D,B),q);ia(n+x+A,k.substring(A),i,q)}else q.push(n+x,h)}m.c=q};return i}function C(a){var b=[],c=[];if(a.tripleQuotedStrings)b.push([U,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,r,pc]);
+else a.multiLineStrings?b.push([U,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,r,qc]):b.push([U,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,r,rc]);if(a.hashComments)a.cStyleComments?b.push([V,/^#(?:[^\r\n\/]|\/(?!\*)|\/\*[^\r\n]*?\*\/)*/,r,F]):b.push([V,/^#[^\r\n]*/,r,F]);if(a.cStyleComments){c.push([V,/^\/\/[^\r\n]*/,r]);c.push([V,/^\/\*[\s\S]*?(?:\*\/|$)/,r])}a.regexLiterals&&c.push([sc,new RegExp(M+N+tc)]);var d=
+a.keywords.replace(/^\s+|\s+$/g,P);d.length&&c.push([uc,new RegExp(vc+d.replace(/\s+/g,O)+wc),r]);b.push([S,/^\s+/,r,xc]);c.push([yc,/^@[a-z_$][a-z_$@0-9]*/i,r,Ia],[zc,/^@?[A-Z]+[a-z][A-Za-z_$@0-9]*/,r],[S,/^[a-z_$][a-z_$@0-9]*/i,r],[yc,/^(?:0x[a-f0-9]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+\-]?\d+)?)[a-z]*/i,r,Ac],[Y,/^.[^\s\w\.$@\'\"\`\/\#]*/,r]);return K(b,c)}var ae=C({keywords:Bc,hashComments:o,cStyleComments:o,multiLineStrings:o,regexLiterals:o});function be(a){var b=a.source,c=a.f,d=a.c,
+g=[],i=0,m=r,l=r,n=0,q=0,v=Ud(window.PR_TAB_WIDTH),w=/([\r\n ]) /g,j=/(^| ) /gm,f=/\r\n?|\n/g,s=/[ \r\n]$/,k=o;function h(p){if(p>i){if(m&&m!==l){g.push(Cc);m=r}if(!m&&l){m=l;g.push(Dc,m,Ec)}var t=ga(v(b.substring(i,p))).replace(k?j:w,Fc);k=s.test(t);var u=window._pr_isIE6()?Gc:Hc;g.push(t.replace(f,u));i=p}}for(;1;){var e;if(e=n<c.length?q<d.length?c[n]<=d[q]:o:z){h(c[n]);if(m){g.push(Cc);m=r}g.push(c[n+1]);n+=2}else if(q<d.length){h(d[q]);l=d[q+1];q+=2}else break}h(b.length);m&&g.push(Cc);a.a=g.join(P)}
+var X={};function y(a,b){for(var c=b.length;--c>=0;){var d=b[c];if(X.hasOwnProperty(d))Ic in window&&console.i(Jc,d);else X[d]=a}}function Ra(a,b){a&&X.hasOwnProperty(a)||(a=/^\s*</.test(b)?Kc:Lc);return X[a]}y(ae,[Lc]);y(K([],[[S,/^[^<?]+/],[Mc,/^<!\w[^>]*(?:>|$)/],[V,/^<\!--[\s\S]*?(?:-\->|$)/],[T,/^<\?([\s\S]+?)(?:\?>|$)/],[T,/^<%([\s\S]+?)(?:%>|$)/],[Y,/^(?:<[%?]|[%?]>)/],[T,/^<xmp\b[^>]*>([\s\S]+?)<\/xmp\b[^>]*>/i],[Z,/^<script\b[^>]*>([\s\S]+?)<\/script\b[^>]*>/i],[$,/^<style\b[^>]*>([\s\S]+?)<\/style\b[^>]*>/i],
+[Nc,/^(<\/?[a-z][^<>]*>)/i]]),[Kc,Oc,Pc,Qc,Rc,Sc,Tc]);y(K([[S,/^[\s]+/,r,Uc],[Vc,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,r,rc]],[[Wc,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[Xc,/^(?!style\b|on)[a-z](?:[\w:-]*\w)?/],[Yc,/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[Y,/^[=<>\/]+/],[Z,/^on\w+\s*=\s*\"([^\"]+)\"/i],[Z,/^on\w+\s*=\s*\'([^\']+)\'/i],[Z,/^on\w+\s*=\s*([^\"\'>\s]+)/i],[$,/^sty\w+\s*=\s*\"([^\"]+)\"/i],[$,/^sty\w+\s*=\s*\'([^\']+)\'/i],[$,/^sty\w+\s*=\s*([^\"\'>\s]+)/i]]),[Zc]);y(K([],[[Vc,/^[\s\S]+/]]),
+[$c]);y(C({keywords:ad,hashComments:o,cStyleComments:o}),[bd,cd,dd,ed,fd,gd]);y(C({keywords:hd}),[id]);y(C({keywords:jd,hashComments:o,cStyleComments:o}),[kd]);y(C({keywords:ld,cStyleComments:o}),[md]);y(C({keywords:nd,hashComments:o,multiLineStrings:o}),[od,pd,qd]);y(C({keywords:rd,hashComments:o,multiLineStrings:o,tripleQuotedStrings:o}),[sd,td]);y(C({keywords:ud,hashComments:o,multiLineStrings:o,regexLiterals:o}),[vd,wd,xd]);y(C({keywords:yd,hashComments:o,multiLineStrings:o,regexLiterals:o}),
+[zd]);y(C({keywords:Ad,cStyleComments:o,regexLiterals:o}),[Bd]);y(K([],[[U,/^[\s\S]+/]]),[Cd]);function Sa(a){var b=a.e,c=a.d;a.a=b;try{var d=Zd(b),g=d.source;a.source=g;a.b=0;a.f=d.tags;Ra(c,g)(a);be(a)}catch(i){if(Ic in window){console.log(i);console.h()}}}function ce(a,b){var c={e:a,d:b};Sa(c);return c.a}function de(a){for(var b=window._pr_isIE6(),c=[document.getElementsByTagName(Dd),document.getElementsByTagName(Ed),document.getElementsByTagName(Fd)],d=[],g=0;g<c.length;++g)for(var i=0,m=c[g].length;i<
+m;++i)d.push(c[g][i]);c=r;var l=Date;l.now||(l={now:function(){return(new Date).getTime()}});var n=0,q;function v(){for(var j=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;n<d.length&&l.now()<j;n++){var f=d[n];if(f.className&&f.className.indexOf(Gd)>=0){var s=f.className.match(/\blang-(\w+)\b/);if(s)s=s[1];for(var k=z,h=f.parentNode;h;h=h.parentNode)if((h.tagName===Dd||h.tagName===Ed||h.tagName===Fd)&&h.className&&h.className.indexOf(Gd)>=0){k=o;break}if(!k){var e=Td(f);e=e.replace(/(?:\r\n?|\n)$/,
+P);q={e:e,d:s,g:f};Sa(q);w()}}}if(n<d.length)setTimeout(v,250);else a&&a()}function w(){var j=q.a;if(j){var f=q.g;if(Ma(f)){for(var s=document.createElement(gc),k=0;k<f.attributes.length;++k){var h=f.attributes[k];if(h.specified){var e=h.name.toLowerCase();if(e===Hd)s.className=h.value;else s.setAttribute(h.name,h.value)}}s.innerHTML=j;f.parentNode.replaceChild(s,f);f=s}else f.innerHTML=j;if(b&&f.tagName===gc)for(var p=f.getElementsByTagName(Id),t=p.length;--t>=0;){var u=p[t];u.parentNode.replaceChild(document.createTextNode(Jd),
+u)}}}v()}window.PR_normalizedHtml=W;window.prettyPrintOne=ce;window.prettyPrint=de;window.PR={combinePrefixPatterns:Na,createSimpleLexer:K,registerLangHandler:y,sourceDecorator:C,PR_ATTRIB_NAME:Xc,PR_ATTRIB_VALUE:Vc,PR_COMMENT:V,PR_DECLARATION:Mc,PR_KEYWORD:uc,PR_LITERAL:yc,PR_NOCODE:lc,PR_PLAIN:S,PR_PUNCTUATION:Y,PR_SOURCE:oc,PR_STRING:U,PR_TAG:Wc,PR_TYPE:zc}})();
+})()
diff --git a/tools/droiddoc/templates/assets/search_autocomplete.js b/tools/droiddoc/templates/assets/search_autocomplete.js
index 929751f..4fa47a5 100644
--- a/tools/droiddoc/templates/assets/search_autocomplete.js
+++ b/tools/droiddoc/templates/assets/search_autocomplete.js
@@ -107,11 +107,13 @@
var text = search.value;
// 13 = enter
- if (!kd && (e.keyCode == 13)) {
+ if (e.keyCode == 13) {
document.getElementById("search_filtered_div").className = "no-display";
- if (gSelectedIndex >= 0) {
+ if (kd && gSelectedIndex >= 0) {
window.location = toroot + gMatches[gSelectedIndex].link;
return false;
+ } else if (gSelectedIndex < 0) {
+ return true;
}
}
// 38 -- arrow up
@@ -168,6 +170,6 @@
function submit_search() {
var query = document.getElementById('search_autocomplete').value;
- document.location = toRoot + 'search.html#q=' + query; // toRoot is initialized in android-developer-docs.js
+ document.location = toRoot + 'search.html#q=' + query + '&t=0';
return false;
}
diff --git a/tools/droiddoc/templates/class.cs b/tools/droiddoc/templates/class.cs
index 90e1472..89eb927 100644
--- a/tools/droiddoc/templates/class.cs
+++ b/tools/droiddoc/templates/class.cs
@@ -2,7 +2,7 @@
<?cs include:"macros.cs" ?>
<html>
<?cs include:"head_tag.cs" ?>
-<body>
+<body class="<?cs var:class.since ?>">
<script type="text/javascript">
function toggleInherited(linkObj, expand) {
var base = linkObj.getAttribute("id");
@@ -26,7 +26,6 @@
return false;
}
</script>
-
<?cs include:"header.cs" ?>
<div class="g-unit" id="doc-content">
@@ -106,7 +105,9 @@
| <a href="#" onclick="return toggleAllSummaryInherited(this)">[Expand All]</a>
<?cs /if ?>
</div><!-- end sum-details-links -->
-
+<div class="api-level">
+ <?cs call:since_tags(class) ?>
+</div>
</div><!-- end api-info-block -->
<?cs # this next line must be exactly like this to be parsed by eclipse ?>
@@ -134,12 +135,11 @@
<?cs set:colspan = colspan-1 ?>
<?cs /each ?>
-<div class="api-level"><?cs call:since_tags(class) ?></div>
-
</div><!-- end header -->
+<div id="naMessage"></div>
-<div id="jd-content" class="apilevel-<?cs var:class.since ?>">
+<div id="jd-content" class="api apilevel-<?cs var:class.since ?>">
<table class="jd-inheritance-table">
<?cs set:colspan = subcount(class.inheritance) ?>
<?cs each:supr = class.inheritance ?>
@@ -188,7 +188,7 @@
<?cs # summary macros ?>
-<?cs def:write_method_summary(methods) ?>
+<?cs def:write_method_summary(methods, included) ?>
<?cs set:count = #1 ?>
<?cs each:method = methods ?>
<?cs # The apilevel-N class MUST BE LAST in the sequence of class names ?>
@@ -202,8 +202,7 @@
<?cs call:type_link(method.returnType) ?></nobr>
</td>
<td class="jd-linkcol" width="100%"><nobr>
- <span class="sympad"><a href="<?cs var:toroot ?><?cs var:method.href ?>">
- <?cs var:method.name ?></a></span>(<?cs call:parameter_list(method.params) ?>)</nobr>
+ <span class="sympad"><?cs call:cond_link(method.name, toroot, method.href, included) ?></span>(<?cs call:parameter_list(method.params) ?>)</nobr>
<?cs if:subcount(method.shortDescr) || subcount(method.deprecated) ?>
<div class="jd-descrdiv"><?cs call:short_descr(method) ?></div>
<?cs /if ?>
@@ -212,35 +211,35 @@
<?cs /each ?>
<?cs /def ?>
-<?cs def:write_field_summary(fields) ?>
+<?cs def:write_field_summary(fields, included) ?>
<?cs set:count = #1 ?>
<?cs each:field=fields ?>
- <tr <?cs if:count % #2 ?>class="alt-color"<?cs /if ?> >
+ <tr class="<?cs if:count % #2 ?>alt-color<?cs /if ?> api apilevel-<?cs var:field.since ?>" >
<td class="jd-typecol"><nobr>
<?cs var:field.scope ?>
<?cs var:field.static ?>
<?cs var:field.final ?>
<?cs call:type_link(field.type) ?></nobr></td>
- <td class="jd-linkcol"><a href="<?cs var:toroot ?><?cs var:field.href ?>"><?cs var:field.name ?></a></td>
+ <td class="jd-linkcol"><?cs call:cond_link(field.name, toroot, field.href, included) ?></td>
<td class="jd-descrcol" width="100%"><?cs call:short_descr(field) ?></td>
</tr>
<?cs set:count = count + #1 ?>
<?cs /each ?>
<?cs /def ?>
-<?cs def:write_constant_summary(fields) ?>
+<?cs def:write_constant_summary(fields, included) ?>
<?cs set:count = #1 ?>
<?cs each:field=fields ?>
- <tr <?cs if:count % #2 ?>class="alt-color"<?cs /if ?> >
+ <tr class="<?cs if:count % #2 ?>alt-color<?cs /if ?> api apilevel-<?cs var:field.since ?>" >
<td class="jd-typecol"><?cs call:type_link(field.type) ?></td>
- <td class="jd-linkcol"><a href="<?cs var:toroot ?><?cs var:field.href ?>"><?cs var:field.name ?></a></td>
+ <td class="jd-linkcol"><?cs call:cond_link(field.name, toroot, field.href, included) ?></td>
<td class="jd-descrcol" width="100%"><?cs call:short_descr(field) ?></td>
</tr>
<?cs set:count = count + #1 ?>
<?cs /each ?>
<?cs /def ?>
-<?cs def:write_attr_summary(attrs) ?>
+<?cs def:write_attr_summary(attrs, included) ?>
<?cs set:count = #1 ?>
<tr>
<td><nobr><em>Attribute Name</em></nobr></td>
@@ -248,10 +247,10 @@
<td><nobr><em>Description</em></nobr></td>
</tr>
<?cs each:attr=attrs ?>
- <tr <?cs if:count % #2 ?>class="alt-color"<?cs /if ?> >
- <td class="jd-linkcol"><a href="<?cs var:toroot ?><?cs var:attr.href ?>"><?cs var:attr.name ?></a></td>
+ <tr class="<?cs if:count % #2 ?>alt-color<?cs /if ?> api apilevel-<?cs var:attr.since ?>" >
+ <td class="jd-linkcol"><?cs if:included ?><a href="<?cs var:toroot ?><?cs var:attr.href ?>"><?cs /if ?><?cs var:attr.name ?><?cs if:included ?></a><?cs /if ?></td>
<td class="jd-linkcol"><?cs each:m=attr.methods ?>
- <a href="<?cs var:toroot ?><?cs var:m.href ?>"><?cs var:m.name ?></a>
+ <?cs call:cond_link(m.name, toroot, m.href, included) ?>
<?cs /each ?>
</td>
<td class="jd-descrcol" width="100%"><?cs call:short_descr(attr) ?> </td>
@@ -263,13 +262,13 @@
<?cs def:write_inners_summary(classes) ?>
<?cs set:count = #1 ?>
<?cs each:cl=class.inners ?>
- <tr <?cs if:count % #2 ?>class="alt-color"<?cs /if ?> >
+ <tr class="<?cs if:count % #2 ?>alt-color<?cs /if ?> api apilevel-<?cs var:cl.since ?>" >
<td class="jd-typecol"><nobr>
- <?cs var:class.scope ?>
- <?cs var:class.static ?>
- <?cs var:class.final ?>
- <?cs var:class.abstract ?>
- <?cs var:class.kind ?></nobr></td>
+ <?cs var:cl.scope ?>
+ <?cs var:cl.static ?>
+ <?cs var:cl.final ?>
+ <?cs var:cl.abstract ?>
+ <?cs var:cl.kind ?></nobr></td>
<td class="jd-linkcol"><?cs call:type_link(cl.type) ?></td>
<td class="jd-descrcol" width="100%"><?cs call:short_descr(cl) ?> </td>
</tr>
@@ -293,7 +292,7 @@
<?cs if:subcount(class.attrs) ?>
<!-- =========== FIELD SUMMARY =========== -->
<table id="lattrs" class="jd-sumtable"><tr><th colspan="12">XML Attributes</th></tr>
-<?cs call:write_attr_summary(class.attrs) ?>
+<?cs call:write_attr_summary(class.attrs, 1) ?>
<?cs /if ?>
<?cs # if there are inherited attrs, write the table ?>
@@ -305,16 +304,17 @@
<div style="clear:left;">Inherited XML Attributes</div></th></tr>
<?cs each:cl=class.inherited ?>
<?cs if:subcount(cl.attrs) ?>
-<tr><td colspan="12">
+<tr class="api apilevel-<?cs var:cl.since ?>" >
+<td colspan="12">
<?cs call:expando_trigger("inherited-attrs-"+cl.qualified, "closed") ?>From <?cs var:cl.kind ?>
-<a href="<?cs var:toroot ?><?cs var:cl.link ?>"><?cs var:cl.qualified ?></a>
+<?cs call:cond_link(cl.qualified, toroot, cl.link, cl.included) ?>
<div id="inherited-attrs-<?cs var:cl.qualified ?>">
<div id="inherited-attrs-<?cs var:cl.qualified ?>-list"
class="jd-inheritedlinks">
</div>
<div id="inherited-attrs-<?cs var:cl.qualified ?>-summary" style="display: none;">
<table class="jd-sumtable-expando">
- <?cs call:write_attr_summary(cl.attrs) ?></table>
+ <?cs call:write_attr_summary(cl.attrs, cl.included) ?></table>
</div>
</div>
</td></tr>
@@ -329,9 +329,9 @@
<table id="enumconstants" class="jd-sumtable"><tr><th colspan="12">Enum Values</th></tr>
<?cs set:count = #1 ?>
<?cs each:field=class.enumConstants ?>
- <tr <?cs if:count % #2 ?>class="alt-color"<?cs /if ?> >
+ <tr class="<?cs if:count % #2 ?>alt-color<?cs /if ?> api apilevel-<?cs var:field.since ?>" >
<td class="jd-descrcol"><?cs call:type_link(field.type) ?> </td>
- <td class="jd-linkcol"><a href="<?cs var:toroot ?><?cs var:field.href ?>"><?cs var:field.name ?></a> </td>
+ <td class="jd-linkcol"><?cs call:cond_link(field.name, toroot, field.href, cl.included) ?> </td>
<td class="jd-descrcol" width="100%"><?cs call:short_descr(field) ?> </td>
</tr>
<?cs set:count = count + #1 ?>
@@ -342,7 +342,7 @@
<?cs # this next line must be exactly like this to be parsed by eclipse ?>
<!-- =========== ENUM CONSTANT SUMMARY =========== -->
<table id="constants" class="jd-sumtable"><tr><th colspan="12">Constants</th></tr>
-<?cs call:write_constant_summary(class.constants) ?>
+<?cs call:write_constant_summary(class.constants, 1) ?>
</table>
<?cs /if ?>
@@ -355,16 +355,17 @@
<div style="clear:left;">Inherited Constants</div></th></tr>
<?cs each:cl=class.inherited ?>
<?cs if:subcount(cl.constants) ?>
-<tr><td colspan="12">
+<tr class="api apilevel-<?cs var:cl.since ?>" >
+<td colspan="12">
<?cs call:expando_trigger("inherited-constants-"+cl.qualified, "closed") ?>From <?cs var:cl.kind ?>
-<a href="<?cs var:toroot ?><?cs var:cl.link ?>"><?cs var:cl.qualified ?></a>
+<?cs call:cond_link(cl.qualified, toroot, cl.link, cl.included) ?>
<div id="inherited-constants-<?cs var:cl.qualified ?>">
<div id="inherited-constants-<?cs var:cl.qualified ?>-list"
class="jd-inheritedlinks">
</div>
<div id="inherited-constants-<?cs var:cl.qualified ?>-summary" style="display: none;">
<table class="jd-sumtable-expando">
- <?cs call:write_constant_summary(cl.constants) ?></table>
+ <?cs call:write_constant_summary(cl.constants, cl.included) ?></table>
</div>
</div>
</td></tr>
@@ -377,7 +378,7 @@
<?cs # this next line must be exactly like this to be parsed by eclipse ?>
<!-- =========== FIELD SUMMARY =========== -->
<table id="lfields" class="jd-sumtable"><tr><th colspan="12">Fields</th></tr>
-<?cs call:write_field_summary(class.fields) ?>
+<?cs call:write_field_summary(class.fields, 1) ?>
</table>
<?cs /if ?>
@@ -390,16 +391,17 @@
<div style="clear:left;">Inherited Fields</div></th></tr>
<?cs each:cl=class.inherited ?>
<?cs if:subcount(cl.fields) ?>
-<tr><td colspan="12">
+<tr class="api apilevel-<?cs var:cl.since ?>" >
+<td colspan="12">
<?cs call:expando_trigger("inherited-fields-"+cl.qualified, "closed") ?>From <?cs var:cl.kind ?>
-<a href="<?cs var:toroot ?><?cs var:cl.link ?>"><?cs var:cl.qualified ?></a>
+<?cs call:cond_link(cl.qualified, toroot, cl.link, cl.included) ?>
<div id="inherited-fields-<?cs var:cl.qualified ?>">
<div id="inherited-fields-<?cs var:cl.qualified ?>-list"
class="jd-inheritedlinks">
</div>
<div id="inherited-fields-<?cs var:cl.qualified ?>-summary" style="display: none;">
<table class="jd-sumtable-expando">
- <?cs call:write_field_summary(cl.fields) ?></table>
+ <?cs call:write_field_summary(cl.fields, cl.included) ?></table>
</div>
</div>
</td></tr>
@@ -412,7 +414,7 @@
<?cs # this next line must be exactly like this to be parsed by eclipse ?>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<table id="pubctors" class="jd-sumtable"><tr><th colspan="12">Public Constructors</th></tr>
-<?cs call:write_method_summary(class.ctors.public) ?>
+<?cs call:write_method_summary(class.ctors.public, 1) ?>
</table>
<?cs /if ?>
@@ -420,7 +422,7 @@
<?cs # this next line must be exactly like this to be parsed by eclipse ?>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<table id="proctors" class="jd-sumtable"><tr><th colspan="12">Protected Constructors</th></tr>
-<?cs call:write_method_summary(class.ctors.protected) ?>
+<?cs call:write_method_summary(class.ctors.protected, 1) ?>
</table>
<?cs /if ?>
@@ -428,7 +430,7 @@
<?cs # this next line must be exactly like this to be parsed by eclipse ?>
<!-- ========== METHOD SUMMARY =========== -->
<table id="pubmethods" class="jd-sumtable"><tr><th colspan="12">Public Methods</th></tr>
-<?cs call:write_method_summary(class.methods.public) ?>
+<?cs call:write_method_summary(class.methods.public, 1) ?>
</table>
<?cs /if ?>
@@ -436,7 +438,7 @@
<?cs # this next line must be exactly like this to be parsed by eclipse ?>
<!-- ========== METHOD SUMMARY =========== -->
<table id="promethods" class="jd-sumtable"><tr><th colspan="12">Protected Methods</th></tr>
-<?cs call:write_method_summary(class.methods.protected) ?>
+<?cs call:write_method_summary(class.methods.protected, 1) ?>
</table>
<?cs /if ?>
@@ -449,15 +451,16 @@
<div style="clear:left;">Inherited Methods</div></th></tr>
<?cs each:cl=class.inherited ?>
<?cs if:subcount(cl.methods) ?>
-<tr><td colspan="12"><?cs call:expando_trigger("inherited-methods-"+cl.qualified, "closed") ?>
-From <?cs var:cl.kind ?> <a href="<?cs var:toroot ?><?cs var:cl.link ?>"><?cs var:cl.qualified ?></a>
+<tr class="api apilevel-<?cs var:cl.since ?>" >
+<td colspan="12"><?cs call:expando_trigger("inherited-methods-"+cl.qualified, "closed") ?>
+From <?cs var:cl.kind ?> <?cs call:cond_link(cl.qualified, toroot, cl.link, cl.included) ?>
<div id="inherited-methods-<?cs var:cl.qualified ?>">
<div id="inherited-methods-<?cs var:cl.qualified ?>-list"
class="jd-inheritedlinks">
</div>
<div id="inherited-methods-<?cs var:cl.qualified ?>-summary" style="display: none;">
<table class="jd-sumtable-expando">
- <?cs call:write_method_summary(cl.methods) ?></table>
+ <?cs call:write_method_summary(cl.methods, cl.included) ?></table>
</div>
</div>
</td></tr>
@@ -485,11 +488,12 @@
<?cs call:type_link(field.type) ?>
</span>
<?cs var:field.name ?>
- <span class="api-level">
- <?cs call:since_tags(field) ?>
- </span>
</h4>
- <div class="jd-details-descr"><?cs call:description(field) ?>
+ <div class="api-level">
+ <?cs call:since_tags(field) ?>
+ </div>
+ <div class="jd-details-descr">
+ <?cs call:description(field) ?>
<?cs if:subcount(field.constantValue) ?>
<div class="jd-tagdata">
<span class="jd-tagtitle">Constant Value: </span>
@@ -525,11 +529,13 @@
</span>
<span class="sympad"><?cs var:method.name ?></span>
<span class="normal">(<?cs call:parameter_list(method.params) ?>)</span>
- <span class="api-level">
- <?cs call:since_tags(method) ?>
- </span>
</h4>
- <div class="jd-details-descr"><?cs call:description(method) ?></div>
+ <div class="api-level">
+ <?cs call:since_tags(method) ?>
+ </div>
+ <div class="jd-details-descr">
+ <?cs call:description(method) ?>
+ </div>
</div>
<?cs /each ?>
<?cs /def ?>
@@ -541,10 +547,10 @@
<?cs # The apilevel-N class MUST BE LAST in the sequence of class names ?>
<div class="jd-details api apilevel-<?cs var:attr.since ?>">
<h4 class="jd-details-title"><?cs var:attr.name ?>
- <span class="api-level">
- <?cs call:since_tags(attr) ?>
- </span>
</h4>
+ <div class="api-level">
+ <?cs call:since_tags(attr) ?>
+ </div>
<div class="jd-details-descr">
<?cs call:description(attr) ?>
diff --git a/tools/droiddoc/templates/classes.cs b/tools/droiddoc/templates/classes.cs
index abe8e4e..5a8315f 100644
--- a/tools/droiddoc/templates/classes.cs
+++ b/tools/droiddoc/templates/classes.cs
@@ -22,7 +22,7 @@
<table class="jd-sumtable">
<?cs set:cur_row = #0 ?>
<?cs each:cl = letter ?>
- <tr <?cs if:count % #2 ?>class="alt-color"<?cs /if ?> >
+ <tr class="<?cs if:count % #2 ?>alt-color<?cs /if ?> api apilevel-<?cs var:cl.since ?>" >
<td class="jd-linkcol"><?cs call:type_link(cl.type) ?></td>
<td class="jd-descrcol" width="100%"><?cs call:short_descr(cl) ?> </td>
</tr>
diff --git a/tools/droiddoc/templates/customization.cs b/tools/droiddoc/templates/customization.cs
index 1988a89..f6a5c1a 100644
--- a/tools/droiddoc/templates/customization.cs
+++ b/tools/droiddoc/templates/customization.cs
@@ -27,4 +27,5 @@
<?cs def:custom_buildinfo() ?>Build <?cs var:page.build ?> - <?cs var:page.now ?><?cs /def ?>
<?cs # appears on the side of the page ?>
-<?cs def:custom_left_nav() ?><?cs call:default_left_nav() ?><?cs /def ?>
\ No newline at end of file
+<?cs def:custom_left_nav() ?><?cs call:default_left_nav() ?><?cs /def ?>
+
diff --git a/tools/droiddoc/templates/docpage.cs b/tools/droiddoc/templates/docpage.cs
index 06b3f35..9d85c6f 100644
--- a/tools/droiddoc/templates/docpage.cs
+++ b/tools/droiddoc/templates/docpage.cs
@@ -19,7 +19,6 @@
<div id="jd-content">
-
<div class="jd-descr">
<?cs call:tag_list(root.descr) ?>
</div>
diff --git a/tools/droiddoc/templates/doctype.cs b/tools/droiddoc/templates/doctype.cs
index 643f992..763b073 100644
--- a/tools/droiddoc/templates/doctype.cs
+++ b/tools/droiddoc/templates/doctype.cs
@@ -1 +1 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
\ No newline at end of file
+<!DOCTYPE html>
\ No newline at end of file
diff --git a/tools/droiddoc/templates/head_tag.cs b/tools/droiddoc/templates/head_tag.cs
index f721403..5a7fd40 100644
--- a/tools/droiddoc/templates/head_tag.cs
+++ b/tools/droiddoc/templates/head_tag.cs
@@ -5,7 +5,7 @@
if:page.title ?><?cs
var:page.title ?> | <?cs
/if ?>Android Developers</title><?cs
-if:guide||sdk ?>
+if:guide||sdk||resources ?>
<link href="<?cs var:toroot ?>assets/android-developer-docs-devguide.css" rel="stylesheet" type="text/css" /><?cs
else ?>
<link href="<?cs var:toroot ?>assets/android-developer-docs.css" rel="stylesheet" type="text/css" /><?cs
@@ -13,11 +13,13 @@
<script src="<?cs var:toroot ?>assets/search_autocomplete.js" type="text/javascript"></script>
<script src="<?cs var:toroot ?>assets/jquery-resizable.min.js" type="text/javascript"></script>
<script src="<?cs var:toroot ?>assets/android-developer-docs.js" type="text/javascript"></script>
+<script src="<?cs var:toroot ?>assets/prettify.js" type="text/javascript"></script>
<script type="text/javascript">
setToRoot("<?cs var:toroot ?>");
</script><?cs
if:reference ?>
-<script src="<?cs var:toroot ?>assets/navtree.js" type="text/javascript"></script><?cs
+<script src="<?cs var:toroot ?>assets/android-developer-reference.js" type="text/javascript"></script>
+<script src="<?cs var:toroot ?>navtree_data.js" type="text/javascript"></script><?cs
/if ?>
<noscript>
<style type="text/css">
diff --git a/tools/droiddoc/templates/macros.cs b/tools/droiddoc/templates/macros.cs
index 9f0e5ac..b5fd3f2 100644
--- a/tools/droiddoc/templates/macros.cs
+++ b/tools/droiddoc/templates/macros.cs
@@ -39,6 +39,15 @@
<?cs def:class_name(type) ?><?cs call:type_link_impl(type, "false") ?><?cs /def ?>
<?cs def:type_link(type) ?><?cs call:type_link_impl(type, "true") ?><?cs /def ?>
+<?cs # a conditional link.
+ if the "condition" parameter evals to true then the link is displayed
+ otherwise only the text is displayed
+?><?cs
+def:cond_link(text, root, path, condition) ?><?cs
+ if:condition ?><a href="<?cs var:root ?><?cs var:path ?>"><?cs /if ?><?cs var:text ?><?cs if:condition ?></a><?cs /if ?><?cs
+/def ?>
+
+
<?cs # A comma separated parameter list ?><?cs
def:parameter_list(params) ?><?cs
each:param = params ?><?cs
@@ -53,17 +62,26 @@
each:tag = tags ?><?cs
if:tag.name == "Text" ?><?cs var:tag.text?><?cs
elif:tag.kind == "@more" ?><p><?cs
- elif:tag.kind == "@see" ?><a href="<?cs var:toroot ?><?cs var:tag.href ?>"><?cs var:tag.label ?></a><?cs
+ elif:tag.kind == "@see" ?><code><a href="<?cs var:toroot ?><?cs var:tag.href ?>"><?cs var:tag.label ?></a></code><?cs
elif:tag.kind == "@seeHref" ?><a href="<?cs var:tag.href ?>"><?cs var:tag.label ?></a><?cs
elif:tag.kind == "@seeJustLabel" ?><?cs var:tag.label ?><?cs
- elif:tag.kind == "@code" ?><code class="Code prettyprint"><?cs var:tag.text ?></code><?cs
- elif:tag.kind == "@samplecode" ?><pre class="Code prettyprint"><?cs var:tag.text ?></pre><?cs
- elif:tag.name == "@sample" ?><pre class="Code prettyprint"><?cs var:tag.text ?></pre><?cs
+ elif:tag.kind == "@code" ?><code><?cs var:tag.text ?></code><?cs
+ elif:tag.kind == "@samplecode" ?><pre><?cs var:tag.text ?></pre><?cs
+ elif:tag.name == "@sample" ?><pre><?cs var:tag.text ?></pre><?cs
elif:tag.name == "@include" ?><?cs var:tag.text ?><?cs
elif:tag.kind == "@docRoot" ?><?cs var:toroot ?><?cs
elif:tag.kind == "@sdkCurrent" ?><?cs var:sdk.current ?><?cs
elif:tag.kind == "@sdkCurrentVersion" ?><?cs var:sdk.version ?><?cs
elif:tag.kind == "@sdkCurrentRelId" ?><?cs var:sdk.rel.id ?><?cs
+ elif:tag.kind == "@sdkPlatformVersion" ?><?cs var:sdk.platform.version ?><?cs
+ elif:tag.kind == "@sdkPlatformApiLevel" ?><?cs var:sdk.platform.apiLevel ?><?cs
+ elif:tag.kind == "@sdkPlatformMajorMinor" ?><?cs var:sdk.platform.majorMinor ?><?cs
+ elif:tag.kind == "@sdkPlatformReleaseDate" ?><?cs var:sdk.platform.releaseDate ?><?cs
+ elif:tag.kind == "@sdkPlatformDeployableDate" ?><?cs var:sdk.platform.deployableDate ?><?cs
+ elif:tag.kind == "@adtZipVersion" ?><?cs var:adt.zip.version ?><?cs
+ elif:tag.kind == "@adtZipDownload" ?><?cs var:adt.zip.download ?><?cs
+ elif:tag.kind == "@adtZipBytes" ?><?cs var:adt.zip.bytes ?><?cs
+ elif:tag.kind == "@adtZipChecksum" ?><?cs var:adt.zip.checksum ?><?cs
elif:tag.kind == "@inheritDoc" ?><?cs # This is the case when @inheritDoc is in something
that doesn't inherit from anything?><?cs
elif:tag.kind == "@attr" ?><?cs
@@ -89,8 +107,8 @@
<?cs # Show the red box with the deprecated warning ?><?cs
def:deprecated_warning(obj) ?><?cs
if:subcount(obj.deprecated) ?><p>
- <p class="warning jd-deprecated-warning">
- <strong><?cs call:deprecated_text(obj.kind) ?></strong><?cs
+ <p class="caution">
+ <strong><?cs call:deprecated_text(obj.kind) ?></strong><br/> <?cs
call:tag_list(obj.deprecated) ?>
</p><?cs
/if ?><?cs
@@ -103,8 +121,8 @@
<h5 class="jd-tagtitle">See Also</h5>
<ul class="nolist"><?cs
each:tag=also ?><li><?cs
- if:tag.kind == "@see" ?><a href="<?cs var:toroot ?><?cs var:tag.href ?>"><?cs
- var:tag.label ?></a><?cs
+ if:tag.kind == "@see" ?><code><a href="<?cs var:toroot ?><?cs var:tag.href ?>"><?cs
+ var:tag.label ?></a></code><?cs
elif:tag.kind == "@seeHref" ?><a href="<?cs var:tag.href ?>"><?cs var:tag.label ?></a><?cs
elif:tag.kind == "@seeJustLabel" ?><?cs var:tag.label ?><?cs
else ?>[ERROR: Unknown @see kind]<?cs
@@ -117,7 +135,7 @@
<?cs # print the API Level ?><?cs
def:since_tags(obj) ?>
- Since: API Level <?cs var:obj.since ?>
+ Since: <a href="<?cs var:toroot ?>guide/appendix/api-levels.html#level<?cs var:obj.since ?>">API Level <?cs var:obj.since ?></a>
<?cs /def ?>
<?cs # Print the long-form description for something.
@@ -203,7 +221,7 @@
<li><h2><?cs var:label ?></h2>
<ul><?cs
each:cl=classes ?>
- <li class="<?cs if:class.name == cl.label?>selected<?cs /if ?> api apilevel-<?cs var:cl.since ?>"><?cs call:type_link(cl) ?></li><?cs
+ <li class="<?cs if:class.name == cl.label?>selected <?cs /if ?>api apilevel-<?cs var:cl.since ?>"><?cs call:type_link(cl) ?></li><?cs
/each ?>
</ul>
</li><?cs
@@ -213,7 +231,7 @@
<?cs # A list of links to packages, for use in the side navigation of packages (panel nav) ?><?cs
def:package_link_list(packages) ?><?cs
each:pkg=packages ?>
- <li class="<?cs if:(class.package.name == pkg.name) || (package.name == pkg.name)?>selected<?cs /if ?> api apilevel-<?cs var:pkg.since ?>"><?cs call:package_link(pkg) ?></li><?cs
+ <li class="<?cs if:(class.package.name == pkg.name) || (package.name == pkg.name)?>selected <?cs /if ?>api apilevel-<?cs var:pkg.since ?>"><?cs call:package_link(pkg) ?></li><?cs
/each ?><?cs
/def ?>
diff --git a/tools/droiddoc/templates/package-descr.cs b/tools/droiddoc/templates/package-descr.cs
index 112db4b..08fee18 100644
--- a/tools/droiddoc/templates/package-descr.cs
+++ b/tools/droiddoc/templates/package-descr.cs
@@ -2,26 +2,31 @@
<?cs include:"macros.cs" ?>
<html>
<?cs include:"head_tag.cs" ?>
+<body class="<?cs var:package.since ?>">
<?cs include:"header.cs" ?>
<div class="g-unit" id="doc-content">
+<div id="api-info-block">
+<div class="api-level">
+ <?cs call:since_tags(package) ?>
+</div>
+</div>
+
<div id="jd-header">
- <strong>
- <div class="jd-page_title-prefix">package</div>
- </strong>
+ package
<h1><?cs var:package.name ?></b></h1>
<div class="jd-nav">
- <a class="jd-navlink" href="package-summary.html">Classes</a> |
- Description
+ <a class="jd-navlink" href="package-summary.html">Classes</a> | Description
</div>
</div><!-- end header -->
-<div id="jd-content">
+<div id="naMessage"></div>
+
+<div id="jd-content" class="api apilevel-<?cs var:package.since ?>">
<div class="jd-descr">
<p><?cs call:tag_list(package.descr) ?></p>
</div>
-<?cs call:since_tags(package) ?>
<?cs include:"footer.cs" ?>
</div><!-- end jd-content -->
diff --git a/tools/droiddoc/templates/package.cs b/tools/droiddoc/templates/package.cs
index 5ef3e0c..b29bc77 100644
--- a/tools/droiddoc/templates/package.cs
+++ b/tools/droiddoc/templates/package.cs
@@ -2,25 +2,30 @@
<?cs include:"macros.cs" ?>
<html>
<?cs include:"head_tag.cs" ?>
+<body class="<?cs var:package.since ?>">
<?cs include:"header.cs" ?>
<div class="g-unit" id="doc-content">
+<div id="api-info-block">
+<div class="api-level">
+ <?cs call:since_tags(package) ?>
+</div>
+</div>
+
<div id="jd-header">
package
<h1><?cs var:package.name ?></h1>
<div class="jd-nav">
<?cs if:subcount(package.shortDescr) ?>
- Classes |
- <a class="jd-navlink" href="package-descr.html">Description</a>
+ Classes | <a class="jd-navlink" href="package-descr.html">Description</a>
<?cs /if ?>
</div>
- <span class="api-level">
- <?cs call:since_tags(package) ?>
- </span>
-</div>
+</div><!-- end header -->
-<div id="jd-content">
+<div id="naMessage"></div>
+
+<div id="jd-content" class="api apilevel-<?cs var:package.since ?>">
<?cs if:subcount(package.shortDescr) ?>
<div class="jd-descr">
diff --git a/tools/droiddoc/templates/packages.cs b/tools/droiddoc/templates/packages.cs
index a358dca..c2d8c75 100644
--- a/tools/droiddoc/templates/packages.cs
+++ b/tools/droiddoc/templates/packages.cs
@@ -20,7 +20,7 @@
<?cs set:count = #1 ?>
<table class="jd-sumtable">
<?cs each:pkg = docs.packages ?>
- <tr <?cs if:count % #2 ?>class="alt-color"<?cs /if ?> >
+ <tr class="<?cs if:count % #2 ?>alt-color<?cs /if ?> api apilevel-<?cs var:pkg.since ?>" >
<td class="jd-linkcol"><?cs call:package_link(pkg) ?></td>
<td class="jd-descrcol" width="100%"><?cs call:tag_list(pkg.shortDescr) ?> </td>
</tr>
diff --git a/tools/droiddoc/templates/sample.cs b/tools/droiddoc/templates/sample.cs
index e919111..7979b2a 100644
--- a/tools/droiddoc/templates/sample.cs
+++ b/tools/droiddoc/templates/sample.cs
@@ -1,27 +1,25 @@
<?cs include:"doctype.cs" ?>
<?cs include:"macros.cs" ?>
-<?cs set:guide="true" ?>
+<?cs set:resources="true" ?>
<html>
<?cs include:"head_tag.cs" ?>
<?cs include:"header.cs" ?>
+<body class="gc-documentation">
-<div class="g-unit" id="doc-content"><a name="top"></a>
-<div id="jd-header" class="guide-header">
-
- <span class="crumb">
- <a href="<?cs var:toroot ?>guide/samples/index.html">Sample Code ></a>
-
- </span>
-<h1><?cs var:page.title ?></h1>
-</div>
+<a name="top"></a>
+<div class="g-unit" id="doc-content">
+ <div id="jd-header" class="guide-header">
+ <span class="crumb"> </span>
+ <h1><?cs var:page.title ?></h1>
+ </div>
<div id="jd-content">
<p>The file containing the source code shown below is located in the corresponding directory in <code><sdk>/platforms/android-<version>/samples/...</code></p>
<!-- begin file contents -->
-<pre class="Code prettyprint"><?cs var:fileContents ?></pre>
+<pre><?cs var:fileContents ?></pre>
<!-- end file contents -->
<?cs include:"footer.cs" ?>
diff --git a/tools/droiddoc/templates/sampleindex.cs b/tools/droiddoc/templates/sampleindex.cs
index 6e57cfd..8a75298 100644
--- a/tools/droiddoc/templates/sampleindex.cs
+++ b/tools/droiddoc/templates/sampleindex.cs
@@ -1,45 +1,61 @@
<?cs include:"doctype.cs" ?>
<?cs include:"macros.cs" ?>
-<?cs set:guide="true" ?>
+<?cs set:resources="true" ?>
<html>
<?cs include:"head_tag.cs" ?>
<?cs include:"header.cs" ?>
+<body class="gc-documentation">
-<div class="g-unit" id="doc-content"><a name="top"></a>
-<div id="jd-header" class="guide-header">
-
- <span class="crumb">
- <a href="<?cs var:toroot ?>guide/samples/index.html">Sample Code ></a>
-
- </span>
-<h1><?cs var:page.title ?></h1>
-</div>
+<a name="top"></a>
+<div class="g-unit" id="doc-content">
+ <div id="jd-header" class="guide-header">
+ <span class="crumb"> </span>
+ <h1><?cs var:page.title ?></h1>
+ </div>
<div id="jd-content">
<?cs var:summary ?>
-<?cs if:subcount(subdirs) ?>
- <h2>Subdirectories</h2>
- <ul class="nolist">
- <?cs each:dir=subdirs ?>
- <li><a href="<?cs var:dir.name ?>/index.html"><?cs var:dir.name ?>/</a></li>
- <?cs /each ?>
- </ul>
-<?cs /if ?>
+<?cs if:android.whichdoc == "online" ?><?cs
+ # If this is the online docs, build the src code navigation links ?>
-<?cs if:subcount(files) ?>
- <h2>Files</h2>
- <ul class="nolist">
- <?cs each:file=files ?>
- <li><a href="<?cs var:file.href ?>"><?cs var:file.name ?></a></li>
- <?cs /each ?>
- </ul>
-<?cs /if ?>
+ <?cs if:subcount(subdirs) ?>
+ <h2>Subdirectories</h2>
+ <ul class="nolist">
+ <?cs each:dir=subdirs ?>
+ <li><a href="<?cs var:dir.name ?>/index.html"><?cs
+ var:dir.name ?>/</a></li>
+ <?cs /each ?>
+ </ul>
+ <?cs /if ?>
+
+ <?cs if:subcount(files) ?>
+ <h2>Files</h2>
+ <ul class="nolist">
+ <?cs each:file=files ?>
+ <li><a href="<?cs var:file.href ?>"><?cs
+ var:file.name ?></a></li>
+ <?cs /each ?>
+ </ul>
+ <?cs /if ?>
+
+<?cs else ?><?cs
+ # else, this means it's offline docs,
+ so don't show src links (we don't have the pages!) ?>
+
+<p>You can find the source code for this sample in your SDK at:</p>
+<p style="margin-left:2em">
+<code><em><sdk></em>/platforms/android-<em><version></em>/samples/</code>
+</p>
+
+<?cs /if ?><?cs # end if/else online docs ?>
+
+</div><!-- end jd-content -->
<?cs include:"footer.cs" ?>
-</div><!-- end jd-content -->
+
</div><!-- end doc-content -->
<?cs include:"trailer.cs" ?>
diff --git a/tools/dump-package-stats b/tools/dump-package-stats
index 589bab5..d11e727 100755
--- a/tools/dump-package-stats
+++ b/tools/dump-package-stats
@@ -102,7 +102,7 @@
$1 != "Length" ||
$2 != "Method" ||
$3 != "Size" ||
- $4 != "Ratio" ||
+ ($4 != "Ratio" && $4 != "Cmpr") ||
$5 != "Date" ||
$6 != "Time" ||
$7 != "CRC-32" ||
diff --git a/tools/findleaves.py b/tools/findleaves.py
new file mode 100755
index 0000000..0adf188
--- /dev/null
+++ b/tools/findleaves.py
@@ -0,0 +1,98 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#
+# Finds files with the specified name under a particular directory, stopping
+# the search in a given subdirectory when the file is found.
+#
+
+import os
+import sys
+
+def perform_find(mindepth, prune, dirlist, filename):
+ result = []
+ pruneleaves = set(map(lambda x: os.path.split(x)[1], prune))
+ for rootdir in dirlist:
+ rootdepth = rootdir.count("/")
+ for root, dirs, files in os.walk(rootdir):
+ # prune
+ check_prune = False
+ for d in dirs:
+ if d in pruneleaves:
+ check_prune = True
+ break
+ if check_prune:
+ i = 0
+ while i < len(dirs):
+ if dirs[i] in prune:
+ del dirs[i]
+ else:
+ i += 1
+ # mindepth
+ if mindepth > 0:
+ depth = 1 + root.count("/") - rootdepth
+ if depth < mindepth:
+ continue
+ # match
+ if filename in files:
+ result.append(os.path.join(root, filename))
+ del dirs[:]
+ return result
+
+def usage():
+ sys.stderr.write("""Usage: %(progName)s [<options>] <dirlist> <filename>
+Options:
+ --mindepth=<mindepth>
+ Both behave in the same way as their find(1) equivalents.
+ --prune=<dirname>
+ Avoids returning results from inside any directory called <dirname>
+ (e.g., "*/out/*"). May be used multiple times.
+""" % {
+ "progName": os.path.split(sys.argv[0])[1],
+ })
+ sys.exit(1)
+
+def main(argv):
+ mindepth = -1
+ prune = []
+ i=1
+ while i<len(argv) and len(argv[i])>2 and argv[i][0:2] == "--":
+ arg = argv[i]
+ if arg.startswith("--mindepth="):
+ try:
+ mindepth = int(arg[len("--mindepth="):])
+ except ValueError:
+ usage()
+ elif arg.startswith("--prune="):
+ p = arg[len("--prune="):]
+ if len(p) == 0:
+ usage()
+ prune.append(p)
+ else:
+ usage()
+ i += 1
+ if len(argv)-i < 2: # need both <dirlist> and <filename>
+ usage()
+ dirlist = argv[i:-1]
+ filename = argv[-1]
+ results = perform_find(mindepth, prune, dirlist, filename)
+ results.sort()
+ for r in set(results):
+ print r
+
+if __name__ == "__main__":
+ main(sys.argv)
diff --git a/tools/findleaves.sh b/tools/findleaves.sh
deleted file mode 100755
index 74bfd24..0000000
--- a/tools/findleaves.sh
+++ /dev/null
@@ -1,109 +0,0 @@
-#!/bin/bash
-#
-# Copyright (C) 2008 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-#
-# Finds files with the specified name under a particular directory, stopping
-# the search in a given subdirectory when the file is found.
-#
-
-set -o nounset # fail when dereferencing unset variables
-set -o errexit # fail if any subcommand fails
-
-progName=`basename $0`
-
-function warn() {
- echo "$progName: $@" >&2
-}
-
-function trace() {
- echo "$progName: $@"
-}
-
-function usage() {
- if [[ $# > 0 ]]
- then
- warn $@
- fi
- cat <<-EOF
-Usage: $progName [<options>] <dirlist> <filename>
-Options:
- --mindepth=<mindepth>
- --maxdepth=<maxdepth>
- Both behave in the same way as their find(1) equivalents.
- --prune=<glob>
- Avoids returning results from any path matching the given glob-style
- pattern (e.g., "*/out/*"). May be used multiple times.
-EOF
- exit 1
-}
-
-function fail() {
- warn $@
- exit 1
-}
-
-if [ $# -lt 2 ]
-then
- usage
-fi
-
-findargs=""
-while [[ "${1:0:2}" == "--" ]]
-do
- arg=${1:2}
- name=${arg%%=*}
- value=${arg##*=}
- if [[ "$name" == "mindepth" || "$name" == "maxdepth" ]]
- then
- # Add to beginning of findargs; these must come before the expression.
- findargs="-$name $value $findargs"
- elif [[ "$name" == "prune" ]]
- then
- # Add to end of findargs; these are part of the expression.
- findargs="$findargs -path $value -prune -or"
- fi
- shift
-done
-
-nargs=$#
-# The filename is the last argument
-filename="${!nargs}"
-
-# Print out all files that match, as long as the path isn't explicitly
-# pruned. This will print out extraneous results from directories whose
-# parents have a match. These are filtered out by the awk script below.
-find -L "${@:1:$nargs-1}" $findargs -type f -name "$filename" -print 2>/dev/null |
-
-# Only pass along the directory of each match.
-sed -e 's/\/[^\/]*$/\//' |
-
-# Sort the output, so directories appear immediately before their contents.
-# If there are any duplicates, the awk script will implicitly ignore them.
-# The LC_ALL=C forces sort(1) to use bytewise ordering instead of listening
-# to the locale, which may do case-insensitive and/or alphanumeric-only
-# sorting.
-LC_ALL=C sort |
-
-# Always print the first line, which can't possibly be covered by a
-# parent directory match. After that, only print lines where the last
-# line printed isn't a prefix.
-awk -v "filename=$filename" '
- (NR == 1) || (index($0, last) != 1) {
- last = $0;
- printf("%s%s\n", $0, filename);
- }
-'
diff --git a/tools/kcm/kcm.cpp b/tools/kcm/kcm.cpp
index 3e6320b..23ac377 100644
--- a/tools/kcm/kcm.cpp
+++ b/tools/kcm/kcm.cpp
@@ -198,7 +198,7 @@
return 1;
}
- int out = open(outfilename, O_RDWR|O_CREAT|O_TRUNC, 0660);
+ int out = open(outfilename, O_RDWR|O_CREAT|O_TRUNC, 0664);
if (out == -1) {
fprintf(stderr, "kcm: error opening file for write: %s\n", outfilename);
return 1;
diff --git a/tools/releasetools/amend_generator.py b/tools/releasetools/amend_generator.py
index 3e8af13..f8f4344 100644
--- a/tools/releasetools/amend_generator.py
+++ b/tools/releasetools/amend_generator.py
@@ -87,6 +87,10 @@
'dur' seconds."""
self.script.append("show_progress %f %d" % (frac, int(dur)))
+ def SetProgress(self, frac):
+ """Not implemented in amend."""
+ pass
+
def PatchCheck(self, filename, *sha1):
"""Check that the given file (or MTD reference) has one of the
given *sha1 hashes."""
@@ -180,6 +184,7 @@
def MakeSymlinks(self, symlink_list):
"""Create symlinks, given a list of (dest, link) pairs."""
+ self.DeleteFiles([i[1] for i in symlink_list])
self.script.extend(["symlink %s %s" % (i[0], self._FileRoot(i[1]))
for i in sorted(symlink_list)])
diff --git a/tools/releasetools/check_target_files_signatures b/tools/releasetools/check_target_files_signatures
new file mode 100755
index 0000000..b91f3d4
--- /dev/null
+++ b/tools/releasetools/check_target_files_signatures
@@ -0,0 +1,428 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""
+Check the signatures of all APKs in a target_files .zip file. With
+-c, compare the signatures of each package to the ones in a separate
+target_files (usually a previously distributed build for the same
+device) and flag any changes.
+
+Usage: check_target_file_signatures [flags] target_files
+
+ -c (--compare_with) <other_target_files>
+ Look for compatibility problems between the two sets of target
+ files (eg., packages whose keys have changed).
+
+ -l (--local_cert_dirs) <dir,dir,...>
+ Comma-separated list of top-level directories to scan for
+ .x509.pem files. Defaults to "vendor,build". Where cert files
+ can be found that match APK signatures, the filename will be
+ printed as the cert name, otherwise a hash of the cert plus its
+ subject string will be printed instead.
+
+ -t (--text)
+ Dump the certificate information for both packages in comparison
+ mode (this output is normally suppressed).
+
+"""
+
+import sys
+
+if sys.hexversion < 0x02040000:
+ print >> sys.stderr, "Python 2.4 or newer is required."
+ sys.exit(1)
+
+import os
+import re
+import sha
+import shutil
+import subprocess
+import tempfile
+import zipfile
+
+import common
+
+# Work around a bug in python's zipfile module that prevents opening
+# of zipfiles if any entry has an extra field of between 1 and 3 bytes
+# (which is common with zipaligned APKs). This overrides the
+# ZipInfo._decodeExtra() method (which contains the bug) with an empty
+# version (since we don't need to decode the extra field anyway).
+class MyZipInfo(zipfile.ZipInfo):
+ def _decodeExtra(self):
+ pass
+zipfile.ZipInfo = MyZipInfo
+
+OPTIONS = common.OPTIONS
+
+OPTIONS.text = False
+OPTIONS.compare_with = None
+OPTIONS.local_cert_dirs = ("vendor", "build")
+
+PROBLEMS = []
+PROBLEM_PREFIX = []
+
+def AddProblem(msg):
+ PROBLEMS.append(" ".join(PROBLEM_PREFIX) + " " + msg)
+def Push(msg):
+ PROBLEM_PREFIX.append(msg)
+def Pop():
+ PROBLEM_PREFIX.pop()
+
+
+def Banner(msg):
+ print "-" * 70
+ print " ", msg
+ print "-" * 70
+
+
+def GetCertSubject(cert):
+ p = common.Run(["openssl", "x509", "-inform", "DER", "-text"],
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE)
+ out, err = p.communicate(cert)
+ if err and not err.strip():
+ return "(error reading cert subject)"
+ for line in out.split("\n"):
+ line = line.strip()
+ if line.startswith("Subject:"):
+ return line[8:].strip()
+ return "(unknown cert subject)"
+
+
+class CertDB(object):
+ def __init__(self):
+ self.certs = {}
+
+ def Add(self, cert, name=None):
+ if cert in self.certs:
+ if name:
+ self.certs[cert] = self.certs[cert] + "," + name
+ else:
+ if name is None:
+ name = "unknown cert %s (%s)" % (sha.sha(cert).hexdigest()[:12],
+ GetCertSubject(cert))
+ self.certs[cert] = name
+
+ def Get(self, cert):
+ """Return the name for a given cert."""
+ return self.certs.get(cert, None)
+
+ def FindLocalCerts(self):
+ to_load = []
+ for top in OPTIONS.local_cert_dirs:
+ for dirpath, dirnames, filenames in os.walk(top):
+ certs = [os.path.join(dirpath, i)
+ for i in filenames if i.endswith(".x509.pem")]
+ if certs:
+ to_load.extend(certs)
+
+ for i in to_load:
+ f = open(i)
+ cert = ParseCertificate(f.read())
+ f.close()
+ name, _ = os.path.splitext(i)
+ name, _ = os.path.splitext(name)
+ self.Add(cert, name)
+
+ALL_CERTS = CertDB()
+
+
+def ParseCertificate(data):
+ """Parse a PEM-format certificate."""
+ cert = []
+ save = False
+ for line in data.split("\n"):
+ if "--END CERTIFICATE--" in line:
+ break
+ if save:
+ cert.append(line)
+ if "--BEGIN CERTIFICATE--" in line:
+ save = True
+ cert = "".join(cert).decode('base64')
+ return cert
+
+
+def CertFromPKCS7(data, filename):
+ """Read the cert out of a PKCS#7-format file (which is what is
+ stored in a signed .apk)."""
+ Push(filename + ":")
+ try:
+ p = common.Run(["openssl", "pkcs7",
+ "-inform", "DER",
+ "-outform", "PEM",
+ "-print_certs"],
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE)
+ out, err = p.communicate(data)
+ if err and not err.strip():
+ AddProblem("error reading cert:\n" + err)
+ return None
+
+ cert = ParseCertificate(out)
+ if not cert:
+ AddProblem("error parsing cert output")
+ return None
+ return cert
+ finally:
+ Pop()
+
+
+class APK(object):
+ def __init__(self, full_filename, filename):
+ self.filename = filename
+ self.cert = None
+ Push(filename+":")
+ try:
+ self.RecordCert(full_filename)
+ self.ReadManifest(full_filename)
+ finally:
+ Pop()
+
+ def RecordCert(self, full_filename):
+ try:
+ f = open(full_filename)
+ apk = zipfile.ZipFile(f, "r")
+ pkcs7 = None
+ for info in apk.infolist():
+ if info.filename.startswith("META-INF/") and \
+ (info.filename.endswith(".DSA") or info.filename.endswith(".RSA")):
+ if pkcs7 is not None:
+ AddProblem("multiple certs")
+ pkcs7 = apk.read(info.filename)
+ self.cert = CertFromPKCS7(pkcs7, info.filename)
+ ALL_CERTS.Add(self.cert)
+ if not pkcs7:
+ AddProblem("no signature")
+ finally:
+ f.close()
+
+ def ReadManifest(self, full_filename):
+ p = common.Run(["aapt", "dump", "xmltree", full_filename,
+ "AndroidManifest.xml"],
+ stdout=subprocess.PIPE)
+ manifest, err = p.communicate()
+ if err:
+ AddProblem("failed to read manifest")
+ return
+
+ self.shared_uid = None
+ self.package = None
+
+ for line in manifest.split("\n"):
+ line = line.strip()
+ m = re.search('A: (\S*?)(?:\(0x[0-9a-f]+\))?="(.*?)" \(Raw', line)
+ if m:
+ name = m.group(1)
+ if name == "android:sharedUserId":
+ if self.shared_uid is not None:
+ AddProblem("multiple sharedUserId declarations")
+ self.shared_uid = m.group(2)
+ elif name == "package":
+ if self.package is not None:
+ AddProblem("multiple package declarations")
+ self.package = m.group(2)
+
+ if self.package is None:
+ AddProblem("no package declaration")
+
+
+class TargetFiles(object):
+ def __init__(self):
+ self.max_pkg_len = 30
+ self.max_fn_len = 20
+
+ def LoadZipFile(self, filename):
+ d = common.UnzipTemp(filename, '*.apk')
+ try:
+ self.apks = {}
+ for dirpath, dirnames, filenames in os.walk(d):
+ for fn in filenames:
+ if fn.endswith(".apk"):
+ fullname = os.path.join(dirpath, fn)
+ displayname = fullname[len(d)+1:]
+ apk = APK(fullname, displayname)
+ self.apks[apk.package] = apk
+
+ self.max_pkg_len = max(self.max_pkg_len, len(apk.package))
+ self.max_fn_len = max(self.max_fn_len, len(apk.filename))
+ finally:
+ shutil.rmtree(d)
+
+ def CheckSharedUids(self):
+ """Look for any instances where packages signed with different
+ certs request the same sharedUserId."""
+ apks_by_uid = {}
+ for apk in self.apks.itervalues():
+ if apk.shared_uid:
+ apks_by_uid.setdefault(apk.shared_uid, []).append(apk)
+
+ for uid in sorted(apks_by_uid.keys()):
+ apks = apks_by_uid[uid]
+ for apk in apks[1:]:
+ if apk.cert != apks[0].cert:
+ break
+ else:
+ # all the certs are the same; this uid is fine
+ continue
+
+ AddProblem("uid %s shared across multiple certs" % (uid,))
+
+ print "uid %s is shared by packages with different certs:" % (uid,)
+ x = [(i.cert, i.package, i) for i in apks]
+ x.sort()
+ lastcert = None
+ for cert, _, apk in x:
+ if cert != lastcert:
+ lastcert = cert
+ print " %s:" % (ALL_CERTS.Get(cert),)
+ print " %-*s [%s]" % (self.max_pkg_len,
+ apk.package, apk.filename)
+ print
+
+ def PrintCerts(self):
+ """Display a table of packages grouped by cert."""
+ by_cert = {}
+ for apk in self.apks.itervalues():
+ by_cert.setdefault(apk.cert, []).append((apk.package, apk))
+
+ order = [(-len(v), k) for (k, v) in by_cert.iteritems()]
+ order.sort()
+
+ for _, cert in order:
+ print "%s:" % (ALL_CERTS.Get(cert),)
+ apks = by_cert[cert]
+ apks.sort()
+ for _, apk in apks:
+ if apk.shared_uid:
+ print " %-*s %-*s [%s]" % (self.max_fn_len, apk.filename,
+ self.max_pkg_len, apk.package,
+ apk.shared_uid)
+ else:
+ print " %-*s %-*s" % (self.max_fn_len, apk.filename,
+ self.max_pkg_len, apk.package)
+ print
+
+ def CompareWith(self, other):
+ """Look for instances where a given package that exists in both
+ self and other have different certs."""
+
+ all = set(self.apks.keys())
+ all.update(other.apks.keys())
+
+ max_pkg_len = max(self.max_pkg_len, other.max_pkg_len)
+
+ by_certpair = {}
+
+ for i in all:
+ if i in self.apks:
+ if i in other.apks:
+ # in both; should have the same cert
+ if self.apks[i].cert != other.apks[i].cert:
+ by_certpair.setdefault((other.apks[i].cert,
+ self.apks[i].cert), []).append(i)
+ else:
+ print "%s [%s]: new APK (not in comparison target_files)" % (
+ i, self.apks[i].filename)
+ else:
+ if i in other.apks:
+ print "%s [%s]: removed APK (only in comparison target_files)" % (
+ i, other.apks[i].filename)
+
+ if by_certpair:
+ AddProblem("some APKs changed certs")
+ Banner("APK signing differences")
+ for (old, new), packages in sorted(by_certpair.items()):
+ print "was", ALL_CERTS.Get(old)
+ print "now", ALL_CERTS.Get(new)
+ for i in sorted(packages):
+ old_fn = other.apks[i].filename
+ new_fn = self.apks[i].filename
+ if old_fn == new_fn:
+ print " %-*s [%s]" % (max_pkg_len, i, old_fn)
+ else:
+ print " %-*s [was: %s; now: %s]" % (max_pkg_len, i,
+ old_fn, new_fn)
+ print
+
+
+def main(argv):
+ def option_handler(o, a):
+ if o in ("-c", "--compare_with"):
+ OPTIONS.compare_with = a
+ elif o in ("-l", "--local_cert_dirs"):
+ OPTIONS.local_cert_dirs = [i.strip() for i in a.split(",")]
+ elif o in ("-t", "--text"):
+ OPTIONS.text = True
+ else:
+ return False
+ return True
+
+ args = common.ParseOptions(argv, __doc__,
+ extra_opts="c:l:t",
+ extra_long_opts=["compare_with=",
+ "local_cert_dirs="],
+ extra_option_handler=option_handler)
+
+ if len(args) != 1:
+ common.Usage(__doc__)
+ sys.exit(1)
+
+ ALL_CERTS.FindLocalCerts()
+
+ Push("input target_files:")
+ try:
+ target_files = TargetFiles()
+ target_files.LoadZipFile(args[0])
+ finally:
+ Pop()
+
+ compare_files = None
+ if OPTIONS.compare_with:
+ Push("comparison target_files:")
+ try:
+ compare_files = TargetFiles()
+ compare_files.LoadZipFile(OPTIONS.compare_with)
+ finally:
+ Pop()
+
+ if OPTIONS.text or not compare_files:
+ Banner("target files")
+ target_files.PrintCerts()
+ target_files.CheckSharedUids()
+ if compare_files:
+ if OPTIONS.text:
+ Banner("comparison files")
+ compare_files.PrintCerts()
+ target_files.CompareWith(compare_files)
+
+ if PROBLEMS:
+ print "%d problem(s) found:\n" % (len(PROBLEMS),)
+ for p in PROBLEMS:
+ print p
+ return 1
+
+ return 0
+
+
+if __name__ == '__main__':
+ try:
+ r = main(sys.argv[1:])
+ sys.exit(r)
+ except common.ExternalError, e:
+ print
+ print " ERROR: %s" % (e,)
+ print
+ sys.exit(1)
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index a07ff7c..0e17a5f 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -15,6 +15,7 @@
import errno
import getopt
import getpass
+import imp
import os
import re
import shutil
@@ -33,7 +34,8 @@
OPTIONS.max_image_size = {}
OPTIONS.verbose = False
OPTIONS.tempfiles = []
-
+OPTIONS.device_specific = None
+OPTIONS.extras = {}
class ExternalError(RuntimeError): pass
@@ -46,18 +48,20 @@
return subprocess.Popen(args, **kwargs)
-def LoadBoardConfig(fn):
- """Parse a board_config.mk file looking for lines that specify the
- maximum size of various images, and parse them into the
- OPTIONS.max_image_size dict."""
+def LoadMaxSizes():
+ """Load the maximum allowable images sizes from the input
+ target_files size."""
OPTIONS.max_image_size = {}
- for line in open(fn):
- line = line.strip()
- m = re.match(r"BOARD_(BOOT|RECOVERY|SYSTEM|USERDATA)IMAGE_MAX_SIZE"
- r"\s*:=\s*(\d+)", line)
- if not m: continue
-
- OPTIONS.max_image_size[m.group(1).lower() + ".img"] = int(m.group(2))
+ try:
+ for line in open(os.path.join(OPTIONS.input_tmp, "META", "imagesizes.txt")):
+ pieces = line.split()
+ if len(pieces) != 2: continue
+ image = pieces[0]
+ size = int(pieces[1])
+ OPTIONS.max_image_size[image + ".img"] = size
+ except IOError, e:
+ if e.errno == errno.ENOENT:
+ pass
def BuildAndAddBootableImage(sourcedir, targetname, output_zip):
@@ -137,12 +141,15 @@
BuildAndAddBootableImage(os.path.join(OPTIONS.input_tmp, "BOOT"),
"boot.img", output_zip)
-def UnzipTemp(filename):
+def UnzipTemp(filename, pattern=None):
"""Unzip the given archive into a temporary directory and return the name."""
tmp = tempfile.mkdtemp(prefix="targetfiles-")
OPTIONS.tempfiles.append(tmp)
- p = Run(["unzip", "-q", filename, "-d", tmp], stdout=subprocess.PIPE)
+ cmd = ["unzip", "-o", "-q", filename, "-d", tmp]
+ if pattern is not None:
+ cmd.append(pattern)
+ p = Run(cmd, stdout=subprocess.PIPE)
p.communicate()
if p.returncode != 0:
raise ExternalError("failed to unzip input target-files \"%s\"" %
@@ -182,14 +189,20 @@
return key_passwords
-def SignFile(input_name, output_name, key, password, align=None):
+def SignFile(input_name, output_name, key, password, align=None,
+ whole_file=False):
"""Sign the input_name zip/jar/apk, producing output_name. Use the
given key and password (the latter may be None if the key does not
have a password.
If align is an integer > 1, zipalign is run to align stored files in
the output zip on 'align'-byte boundaries.
+
+ If whole_file is true, use the "-w" option to SignApk to embed a
+ signature that covers the whole file in the archive comment of the
+ zip file.
"""
+
if align == 0 or align == 1:
align = None
@@ -199,13 +212,14 @@
else:
sign_name = output_name
- p = Run(["java", "-jar",
- os.path.join(OPTIONS.search_path, "framework", "signapk.jar"),
- key + ".x509.pem",
- key + ".pk8",
- input_name, sign_name],
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE)
+ cmd = ["java", "-Xmx512m", "-jar",
+ os.path.join(OPTIONS.search_path, "framework", "signapk.jar")]
+ if whole_file:
+ cmd.append("-w")
+ cmd.extend([key + ".x509.pem", key + ".pk8",
+ input_name, sign_name])
+
+ p = Run(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
if password is not None:
password += "\n"
p.communicate(password)
@@ -245,6 +259,14 @@
Prepend <dir>/bin to the list of places to search for binaries
run by this script, and expect to find jars in <dir>/framework.
+ -s (--device_specific) <file>
+ Path to the python module containing device-specific
+ releasetools code.
+
+ -x (--extra) <key=value>
+ Add a key/value pair to the 'extras' dict, which device-specific
+ extension code may look at.
+
-v (--verbose)
Show command lines being executed.
@@ -269,8 +291,9 @@
try:
opts, args = getopt.getopt(
- argv, "hvp:" + extra_opts,
- ["help", "verbose", "path="] + list(extra_long_opts))
+ argv, "hvp:s:x:" + extra_opts,
+ ["help", "verbose", "path=", "device_specific=", "extra="] +
+ list(extra_long_opts))
except getopt.GetoptError, err:
Usage(docstring)
print "**", str(err), "**"
@@ -286,6 +309,11 @@
OPTIONS.verbose = True
elif o in ("-p", "--path"):
OPTIONS.search_path = a
+ elif o in ("-s", "--device_specific"):
+ OPTIONS.device_specific = a
+ elif o in ("-x", "--extra"):
+ key, value = a.split("=", 1)
+ OPTIONS.extras[key] = value
else:
if extra_option_handler is None or not extra_option_handler(o, a):
assert False, "unknown option \"%s\"" % (o,)
@@ -410,3 +438,69 @@
zinfo.compress_type = zip.compression
zinfo.external_attr = perms << 16
zip.writestr(zinfo, data)
+
+
+class DeviceSpecificParams(object):
+ module = None
+ def __init__(self, **kwargs):
+ """Keyword arguments to the constructor become attributes of this
+ object, which is passed to all functions in the device-specific
+ module."""
+ for k, v in kwargs.iteritems():
+ setattr(self, k, v)
+ self.extras = OPTIONS.extras
+
+ if self.module is None:
+ path = OPTIONS.device_specific
+ if not path: return
+ try:
+ if os.path.isdir(path):
+ info = imp.find_module("releasetools", [path])
+ else:
+ d, f = os.path.split(path)
+ b, x = os.path.splitext(f)
+ if x == ".py":
+ f = b
+ info = imp.find_module(f, [d])
+ self.module = imp.load_module("device_specific", *info)
+ except ImportError:
+ print "unable to load device-specific module; assuming none"
+
+ def _DoCall(self, function_name, *args, **kwargs):
+ """Call the named function in the device-specific module, passing
+ the given args and kwargs. The first argument to the call will be
+ the DeviceSpecific object itself. If there is no module, or the
+ module does not define the function, return the value of the
+ 'default' kwarg (which itself defaults to None)."""
+ if self.module is None or not hasattr(self.module, function_name):
+ return kwargs.get("default", None)
+ return getattr(self.module, function_name)(*((self,) + args), **kwargs)
+
+ def FullOTA_Assertions(self):
+ """Called after emitting the block of assertions at the top of a
+ full OTA package. Implementations can add whatever additional
+ assertions they like."""
+ return self._DoCall("FullOTA_Assertions")
+
+ def FullOTA_InstallEnd(self):
+ """Called at the end of full OTA installation; typically this is
+ used to install the image for the device's baseband processor."""
+ return self._DoCall("FullOTA_InstallEnd")
+
+ def IncrementalOTA_Assertions(self):
+ """Called after emitting the block of assertions at the top of an
+ incremental OTA package. Implementations can add whatever
+ additional assertions they like."""
+ return self._DoCall("IncrementalOTA_Assertions")
+
+ def IncrementalOTA_VerifyEnd(self):
+ """Called at the end of the verification phase of incremental OTA
+ installation; additional checks can be placed here to abort the
+ script before any changes are made."""
+ return self._DoCall("IncrementalOTA_VerifyEnd")
+
+ def IncrementalOTA_InstallEnd(self):
+ """Called at the end of incremental OTA installation; typically
+ this is used to install the image for the device's baseband
+ processor."""
+ return self._DoCall("IncrementalOTA_InstallEnd")
diff --git a/tools/releasetools/edify_generator.py b/tools/releasetools/edify_generator.py
index e7a15cd..d1902e1 100644
--- a/tools/releasetools/edify_generator.py
+++ b/tools/releasetools/edify_generator.py
@@ -100,9 +100,16 @@
def ShowProgress(self, frac, dur):
"""Update the progress bar, advancing it over 'frac' over the next
- 'dur' seconds."""
+ 'dur' seconds. 'dur' may be zero to advance it via SetProgress
+ commands instead of by time."""
self.script.append("show_progress(%f, %d);" % (frac, int(dur)))
+ def SetProgress(self, frac):
+ """Set the position of the progress bar within the chunk defined
+ by the most recent ShowProgress call. 'frac' should be in
+ [0,1]."""
+ self.script.append("set_progress(%f);" % (frac,))
+
def PatchCheck(self, filename, *sha1):
"""Check that the given file (or MTD reference) has one of the
given *sha1 hashes."""
diff --git a/tools/releasetools/img_from_target_files b/tools/releasetools/img_from_target_files
index 1d154b9..d157dca 100755
--- a/tools/releasetools/img_from_target_files
+++ b/tools/releasetools/img_from_target_files
@@ -21,8 +21,7 @@
Usage: img_from_target_files [flags] input_target_files output_image_zip
-b (--board_config) <file>
- Specifies a BoardConfig.mk file containing image max sizes
- against which the generated image files are checked.
+ Deprecated.
"""
@@ -32,6 +31,7 @@
print >> sys.stderr, "Python 2.4 or newer is required."
sys.exit(1)
+import errno
import os
import re
import shutil
@@ -83,8 +83,16 @@
# The name of the directory it is making an image out of matters to
# mkyaffs2image. It wants "system" but we have a directory named
# "SYSTEM", so create a symlink.
- os.symlink(os.path.join(OPTIONS.input_tmp, "SYSTEM"),
- os.path.join(OPTIONS.input_tmp, "system"))
+ try:
+ os.symlink(os.path.join(OPTIONS.input_tmp, "SYSTEM"),
+ os.path.join(OPTIONS.input_tmp, "system"))
+ except OSError, e:
+ # bogus error on my mac version?
+ # File "./build/tools/releasetools/img_from_target_files", line 86, in AddSystem
+ # os.path.join(OPTIONS.input_tmp, "system"))
+ # OSError: [Errno 17] File exists
+ if (e.errno == errno.EEXIST):
+ pass
p = common.Run(["mkyaffs2image", "-f",
os.path.join(OPTIONS.input_tmp, "system"), img.name])
@@ -109,10 +117,10 @@
def option_handler(o, a):
if o in ("-b", "--board_config"):
- common.LoadBoardConfig(a)
- return True
+ pass # deprecated
else:
return False
+ return True
args = common.ParseOptions(argv, __doc__,
extra_opts="b:",
@@ -123,15 +131,15 @@
common.Usage(__doc__)
sys.exit(1)
+ OPTIONS.input_tmp = common.UnzipTemp(args[0])
+
+ common.LoadMaxSizes()
if not OPTIONS.max_image_size:
print
- print " WARNING: No board config specified; will not check image"
- print " sizes against limits. Use -b to make sure the generated"
- print " images don't exceed partition sizes."
+ print " WARNING: Failed to load max image sizes; will not enforce"
+ print " image size limits."
print
- OPTIONS.input_tmp = common.UnzipTemp(args[0])
-
output_zip = zipfile.ZipFile(args[1], "w", compression=zipfile.ZIP_DEFLATED)
common.AddBoot(output_zip)
diff --git a/tools/releasetools/ota_from_target_files b/tools/releasetools/ota_from_target_files
index 4cda44a..f129da1 100755
--- a/tools/releasetools/ota_from_target_files
+++ b/tools/releasetools/ota_from_target_files
@@ -22,8 +22,7 @@
Usage: ota_from_target_files [flags] input_target_files output_ota_package
-b (--board_config) <file>
- Specifies a BoardConfig.mk file containing image max sizes
- against which the generated image files are checked.
+ Deprecated.
-k (--package_key) <key>
Key to use to sign the package (default is
@@ -58,11 +57,13 @@
sys.exit(1)
import copy
+import errno
import os
import re
import sha
import subprocess
import tempfile
+import threading
import time
import zipfile
@@ -81,6 +82,7 @@
OPTIONS.omit_prereq = False
OPTIONS.extra_script = None
OPTIONS.script_mode = 'auto'
+OPTIONS.worker_threads = 3
def MostPopularKey(d, default):
"""Given a dict, return the key corresponding to the largest
@@ -274,19 +276,14 @@
key_passwords = common.GetKeyPasswords([OPTIONS.package_key])
pw = key_passwords[OPTIONS.package_key]
- common.SignFile(temp_zip_name, output_zip_name, OPTIONS.package_key, pw)
+ common.SignFile(temp_zip_name, output_zip_name, OPTIONS.package_key, pw,
+ whole_file=True)
def AppendAssertions(script, input_zip):
device = GetBuildProp("ro.product.device", input_zip)
script.AssertDevice(device)
- info = input_zip.read("OTA/android-info.txt")
- m = re.search(r"require\s+version-bootloader\s*=\s*(\S+)", info)
- if m:
- bootloaders = m.group(1).split("|")
- script.AssertSomeBootloader(*bootloaders)
-
def MakeRecoveryPatch(output_zip, recovery_img, boot_img):
"""Generate a binary patch that creates the recovery image starting
@@ -303,8 +300,9 @@
executable.
"""
- patch = Difference(recovery_img, boot_img, "imgdiff")
- common.ZipWriteStr(output_zip, "system/recovery-from-boot.p", patch)
+ d = Difference(recovery_img, boot_img)
+ _, _, patch = d.ComputePatch()
+ common.ZipWriteStr(output_zip, "recovery/recovery-from-boot.p", patch)
Item.Get("system/recovery-from-boot.p", dir=False)
# Images with different content will have a different first page, so
@@ -325,7 +323,7 @@
'header_sha1': header_sha1,
'recovery_size': recovery_img.size,
'recovery_sha1': recovery_img.sha1 }
- common.ZipWriteStr(output_zip, "system/etc/install-recovery.sh", sh)
+ common.ZipWriteStr(output_zip, "recovery/etc/install-recovery.sh", sh)
return Item.Get("system/etc/install-recovery.sh", dir=False)
@@ -340,19 +338,18 @@
# change very often.
script = edify_generator.EdifyGenerator(2)
+ device_specific = common.DeviceSpecificParams(
+ input_zip=input_zip,
+ output_zip=output_zip,
+ script=script,
+ input_tmp=OPTIONS.input_tmp)
+
if not OPTIONS.omit_prereq:
ts = GetBuildProp("ro.build.date.utc", input_zip)
script.AssertOlderBuild(ts)
AppendAssertions(script, input_zip)
-
- script.ShowProgress(0.1, 0)
-
- try:
- common.ZipWriteStr(output_zip, "radio.img", input_zip.read("RADIO/image"))
- script.WriteFirmwareImage("radio", "radio.img")
- except KeyError:
- print "warning: no radio image in input target_files; not flashing radio"
+ device_specific.FullOTA_Assertions()
script.ShowProgress(0.5, 0)
@@ -361,6 +358,7 @@
script.FormatPartition("system")
script.Mount("MTD", "system", "/system")
+ script.UnpackPackageDir("recovery", "/system")
script.UnpackPackageDir("system", "/system")
symlinks = CopySystemFiles(input_zip, output_zip)
@@ -386,8 +384,11 @@
common.ZipWriteStr(output_zip, "boot.img", boot_img.data)
script.ShowProgress(0.2, 0)
- script.WriteRawImage("boot", "boot.img")
script.ShowProgress(0.2, 10)
+ script.WriteRawImage("boot", "boot.img")
+
+ script.ShowProgress(0.1, 0)
+ device_specific.FullOTA_InstallEnd()
if OPTIONS.extra_script is not None:
script.AppendExtra(OPTIONS.extra_script)
@@ -424,38 +425,111 @@
return out
-def Difference(tf, sf, diff_program):
- """Return the patch (as a string of data) needed to turn sf into tf.
- diff_program is the name of an external program (or list, if
- additional arguments are desired) to run to generate the diff.
- """
+DIFF_PROGRAM_BY_EXT = {
+ ".gz" : "imgdiff",
+ ".zip" : ["imgdiff", "-z"],
+ ".jar" : ["imgdiff", "-z"],
+ ".apk" : ["imgdiff", "-z"],
+ ".img" : "imgdiff",
+ }
- ttemp = tf.WriteToTemp()
- stemp = sf.WriteToTemp()
- ext = os.path.splitext(tf.name)[1]
+class Difference(object):
+ def __init__(self, tf, sf):
+ self.tf = tf
+ self.sf = sf
+ self.patch = None
- try:
- ptemp = tempfile.NamedTemporaryFile()
- if isinstance(diff_program, list):
- cmd = copy.copy(diff_program)
- else:
- cmd = [diff_program]
- cmd.append(stemp.name)
- cmd.append(ttemp.name)
- cmd.append(ptemp.name)
- p = common.Run(cmd)
- _, err = p.communicate()
- if err or p.returncode != 0:
- print "WARNING: failure running %s:\n%s\n" % (diff_program, err)
- return None
- diff = ptemp.read()
- finally:
- ptemp.close()
- stemp.close()
- ttemp.close()
+ def ComputePatch(self):
+ """Compute the patch (as a string of data) needed to turn sf into
+ tf. Returns the same tuple as GetPatch()."""
- return diff
+ tf = self.tf
+ sf = self.sf
+
+ ext = os.path.splitext(tf.name)[1]
+ diff_program = DIFF_PROGRAM_BY_EXT.get(ext, "bsdiff")
+
+ ttemp = tf.WriteToTemp()
+ stemp = sf.WriteToTemp()
+
+ ext = os.path.splitext(tf.name)[1]
+
+ try:
+ ptemp = tempfile.NamedTemporaryFile()
+ if isinstance(diff_program, list):
+ cmd = copy.copy(diff_program)
+ else:
+ cmd = [diff_program]
+ cmd.append(stemp.name)
+ cmd.append(ttemp.name)
+ cmd.append(ptemp.name)
+ p = common.Run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ _, err = p.communicate()
+ if err or p.returncode != 0:
+ print "WARNING: failure running %s:\n%s\n" % (diff_program, err)
+ return None
+ diff = ptemp.read()
+ finally:
+ ptemp.close()
+ stemp.close()
+ ttemp.close()
+
+ self.patch = diff
+ return self.tf, self.sf, self.patch
+
+
+ def GetPatch(self):
+ """Return a tuple (target_file, source_file, patch_data).
+ patch_data may be None if ComputePatch hasn't been called, or if
+ computing the patch failed."""
+ return self.tf, self.sf, self.patch
+
+
+def ComputeDifferences(diffs):
+ """Call ComputePatch on all the Difference objects in 'diffs'."""
+ print len(diffs), "diffs to compute"
+
+ # Do the largest files first, to try and reduce the long-pole effect.
+ by_size = [(i.tf.size, i) for i in diffs]
+ by_size.sort(reverse=True)
+ by_size = [i[1] for i in by_size]
+
+ lock = threading.Lock()
+ diff_iter = iter(by_size) # accessed under lock
+
+ def worker():
+ try:
+ lock.acquire()
+ for d in diff_iter:
+ lock.release()
+ start = time.time()
+ d.ComputePatch()
+ dur = time.time() - start
+ lock.acquire()
+
+ tf, sf, patch = d.GetPatch()
+ if sf.name == tf.name:
+ name = tf.name
+ else:
+ name = "%s (%s)" % (tf.name, sf.name)
+ if patch is None:
+ print "patching failed! %s" % (name,)
+ else:
+ print "%8.2f sec %8d / %8d bytes (%6.2f%%) %s" % (
+ dur, len(patch), tf.size, 100.0 * len(patch) / tf.size, name)
+ lock.release()
+ except Exception, e:
+ print e
+ raise
+
+ # start worker threads; wait for them all to finish.
+ threads = [threading.Thread(target=worker)
+ for i in range(OPTIONS.worker_threads)]
+ for th in threads:
+ th.start()
+ while threads:
+ threads.pop().join()
def GetBuildProp(property, z):
@@ -485,6 +559,7 @@
except KeyError:
return 0
+
def WriteIncrementalOTAPackage(target_zip, source_zip, output_zip):
source_version = GetRecoveryAPIVersion(source_zip)
@@ -503,6 +578,12 @@
else:
raise ValueError('unknown script mode "%s"' % (OPTIONS.script_mode,))
+ device_specific = common.DeviceSpecificParams(
+ source_zip=source_zip,
+ target_zip=target_zip,
+ output_zip=output_zip,
+ script=script)
+
print "Loading target..."
target_data = LoadSystemFiles(target_zip)
print "Loading source..."
@@ -510,9 +591,11 @@
verbatim_targets = []
patch_list = []
+ diffs = []
largest_source_size = 0
for fn in sorted(target_data.keys()):
tf = target_data[fn]
+ assert fn == tf.name
sf = source_data.get(fn, None)
if sf is None or fn in OPTIONS.require_verbatim:
@@ -524,26 +607,23 @@
verbatim_targets.append((fn, tf.size))
elif tf.sha1 != sf.sha1:
# File is different; consider sending as a patch
- diff_method = "bsdiff"
- if tf.name.endswith(".gz"):
- diff_method = "imgdiff"
- d = Difference(tf, sf, diff_method)
- if d is not None:
- print fn, tf.size, len(d), (float(len(d)) / tf.size)
- if d is None or len(d) > tf.size * OPTIONS.patch_threshold:
- # patch is almost as big as the file; don't bother patching
- tf.AddToZip(output_zip)
- verbatim_targets.append((fn, tf.size))
- else:
- common.ZipWriteStr(output_zip, "patch/" + fn + ".p", d)
- patch_list.append((fn, tf, sf, tf.size))
- largest_source_size = max(largest_source_size, sf.size)
+ diffs.append(Difference(tf, sf))
else:
# Target file identical to source.
pass
- total_verbatim_size = sum([i[1] for i in verbatim_targets])
- total_patched_size = sum([i[3] for i in patch_list])
+ ComputeDifferences(diffs)
+
+ for diff in diffs:
+ tf, sf, d = diff.GetPatch()
+ if d is None or len(d) > tf.size * OPTIONS.patch_threshold:
+ # patch is almost as big as the file; don't bother patching
+ tf.AddToZip(output_zip)
+ verbatim_targets.append((tf.name, tf.size))
+ else:
+ common.ZipWriteStr(output_zip, "patch/" + tf.name + ".p", d)
+ patch_list.append((tf.name, tf, sf, tf.size))
+ largest_source_size = max(largest_source_size, sf.size)
source_fp = GetBuildProp("ro.build.fingerprint", source_zip)
target_fp = GetBuildProp("ro.build.fingerprint", target_zip)
@@ -567,35 +647,31 @@
os.path.join(OPTIONS.target_tmp, "RECOVERY")))
updating_recovery = (source_recovery.data != target_recovery.data)
- source_radio = source_zip.read("RADIO/image")
- target_radio = target_zip.read("RADIO/image")
- updating_radio = (source_radio != target_radio)
-
- # The last 0.1 is reserved for creating symlinks, fixing
- # permissions, and writing the boot image (if necessary).
- progress_bar_total = 1.0
- if updating_boot:
- progress_bar_total -= 0.1
- if updating_radio:
- progress_bar_total -= 0.3
+ # Here's how we divide up the progress bar:
+ # 0.1 for verifying the start state (PatchCheck calls)
+ # 0.8 for applying patches (ApplyPatch calls)
+ # 0.1 for unpacking verbatim files, symlinking, and doing the
+ # device-specific commands.
AppendAssertions(script, target_zip)
+ device_specific.IncrementalOTA_Assertions()
script.Print("Verifying current system...")
- pb_verify = progress_bar_total * 0.3 * \
- (total_patched_size /
- float(total_patched_size+total_verbatim_size+1))
+ script.ShowProgress(0.1, 0)
+ total_verify_size = float(sum([i[2].size for i in patch_list]) + 1)
+ if updating_boot:
+ total_verify_size += source_boot.size
+ so_far = 0
- for i, (fn, tf, sf, size) in enumerate(patch_list):
- if i % 5 == 0:
- next_sizes = sum([i[3] for i in patch_list[i:i+5]])
- script.ShowProgress(next_sizes * pb_verify / (total_patched_size+1), 1)
-
+ for fn, tf, sf, size in patch_list:
script.PatchCheck("/"+fn, tf.sha1, sf.sha1)
+ so_far += sf.size
+ script.SetProgress(so_far / total_verify_size)
if updating_boot:
- d = Difference(target_boot, source_boot, "imgdiff")
+ d = Difference(target_boot, source_boot)
+ _, _, d = d.ComputePatch()
print "boot target: %d source: %d diff: %d" % (
target_boot.size, source_boot.size, len(d))
@@ -604,12 +680,16 @@
script.PatchCheck("MTD:boot:%d:%s:%d:%s" %
(source_boot.size, source_boot.sha1,
target_boot.size, target_boot.sha1))
+ so_far += source_boot.size
+ script.SetProgress(so_far / total_verify_size)
if patch_list or updating_recovery or updating_boot:
script.CacheFreeSpaceCheck(largest_source_size)
script.Print("Unpacking patches...")
script.UnpackPackageDir("patch", "/tmp/patchtmp")
+ device_specific.IncrementalOTA_VerifyEnd()
+
script.Comment("---- start making changes here ----")
if OPTIONS.wipe_user_data:
@@ -619,7 +699,21 @@
script.Print("Removing unneeded files...")
script.DeleteFiles(["/"+i[0] for i in verbatim_targets] +
["/"+i for i in sorted(source_data)
- if i not in target_data])
+ if i not in target_data] +
+ ["/system/recovery.img"])
+
+ script.ShowProgress(0.8, 0)
+ total_patch_size = float(sum([i[1].size for i in patch_list]) + 1)
+ if updating_boot:
+ total_patch_size += target_boot.size
+ so_far = 0
+
+ script.Print("Patching system files...")
+ for fn, tf, sf, size in patch_list:
+ script.ApplyPatch("/"+fn, "-", tf.size, tf.sha1,
+ sf.sha1, "/tmp/patchtmp/"+fn+".p")
+ so_far += tf.size
+ script.SetProgress(so_far / total_patch_size)
if updating_boot:
# Produce the boot image by applying a patch to the current
@@ -632,6 +726,8 @@
"-",
target_boot.size, target_boot.sha1,
source_boot.sha1, "/tmp/patchtmp/boot.img.p")
+ so_far += target_boot.size
+ script.SetProgress(so_far / total_patch_size)
print "boot image changed; including."
else:
print "boot image unchanged; skipping."
@@ -650,29 +746,12 @@
# as fodder for constructing the recovery image.
recovery_sh_item = MakeRecoveryPatch(output_zip,
target_recovery, target_boot)
+ script.UnpackPackageDir("recovery", "/system")
print "recovery image changed; including as patch from boot."
else:
print "recovery image unchanged; skipping."
- if updating_radio:
- script.ShowProgress(0.3, 10)
- script.Print("Writing radio image...")
- script.WriteFirmwareImage("radio", "radio.img")
- common.ZipWriteStr(output_zip, "radio.img", target_radio)
- print "radio image changed; including."
- else:
- print "radio image unchanged; skipping."
-
- script.Print("Patching system files...")
- pb_apply = progress_bar_total * 0.7 * \
- (total_patched_size /
- float(total_patched_size+total_verbatim_size+1))
- for i, (fn, tf, sf, size) in enumerate(patch_list):
- if i % 5 == 0:
- next_sizes = sum([i[3] for i in patch_list[i:i+5]])
- script.ShowProgress(next_sizes * pb_apply / (total_patched_size+1), 1)
- script.ApplyPatch("/"+fn, "-", tf.size, tf.sha1,
- sf.sha1, "/tmp/patchtmp/"+fn+".p")
+ script.ShowProgress(0.1, 10)
target_symlinks = CopySystemFiles(target_zip, None)
@@ -700,14 +779,10 @@
script.DeleteFiles(to_delete)
if verbatim_targets:
- pb_verbatim = progress_bar_total * \
- (total_verbatim_size /
- float(total_patched_size+total_verbatim_size+1))
- script.ShowProgress(pb_verbatim, 5)
script.Print("Unpacking new files...")
script.UnpackPackageDir("system", "/system")
- script.Print("Finishing up...")
+ script.Print("Symlinks and permissions...")
# Create all the symlinks that don't already exist, or point to
# somewhere different than what we want. Delete each symlink before
@@ -726,6 +801,9 @@
# permissions.
script.AppendScript(temp_script)
+ # Do device-specific installation (eg, write radio image).
+ device_specific.IncrementalOTA_InstallEnd()
+
if OPTIONS.extra_script is not None:
scirpt.AppendExtra(OPTIONS.extra_script)
@@ -736,7 +814,7 @@
def option_handler(o, a):
if o in ("-b", "--board_config"):
- common.LoadBoardConfig(a)
+ pass # deprecated
elif o in ("-k", "--package_key"):
OPTIONS.package_key = a
elif o in ("-i", "--incremental_from"):
@@ -749,6 +827,8 @@
OPTIONS.extra_script = a
elif o in ("-m", "--script_mode"):
OPTIONS.script_mode = a
+ elif o in ("--worker_threads"):
+ OPTIONS.worker_threads = int(a)
else:
return False
return True
@@ -761,20 +841,14 @@
"wipe_user_data",
"no_prereq",
"extra_script=",
- "script_mode="],
+ "script_mode=",
+ "worker_threads="],
extra_option_handler=option_handler)
if len(args) != 2:
common.Usage(__doc__)
sys.exit(1)
- if not OPTIONS.max_image_size:
- print
- print " WARNING: No board config specified; will not check image"
- print " sizes against limits. Use -b to make sure the generated"
- print " images don't exceed partition sizes."
- print
-
if OPTIONS.script_mode not in ("amend", "edify", "auto"):
raise ValueError('unknown script mode "%s"' % (OPTIONS.script_mode,))
@@ -783,6 +857,31 @@
print "unzipping target target-files..."
OPTIONS.input_tmp = common.UnzipTemp(args[0])
+
+ if OPTIONS.device_specific is None:
+ # look for the device-specific tools extension location in the input
+ try:
+ f = open(os.path.join(OPTIONS.input_tmp, "META", "tool-extensions.txt"))
+ ds = f.read().strip()
+ f.close()
+ if ds:
+ ds = os.path.normpath(ds)
+ print "using device-specific extensions in", ds
+ OPTIONS.device_specific = ds
+ except IOError, e:
+ if e.errno == errno.ENOENT:
+ # nothing specified in the file
+ pass
+ else:
+ raise
+
+ common.LoadMaxSizes()
+ if not OPTIONS.max_image_size:
+ print
+ print " WARNING: Failed to load max image sizes; will not enforce"
+ print " image size limits."
+ print
+
OPTIONS.target_tmp = OPTIONS.input_tmp
input_zip = zipfile.ZipFile(args[0], "r")
if OPTIONS.package_key:
diff --git a/tools/releasetools/sign_target_files_apks b/tools/releasetools/sign_target_files_apks
index 6dd8ede..9d296d8 100755
--- a/tools/releasetools/sign_target_files_apks
+++ b/tools/releasetools/sign_target_files_apks
@@ -20,10 +20,6 @@
Usage: sign_target_files_apks [flags] input_target_files output_target_files
- -s (--signapk_jar) <path>
- Path of the signapks.jar file used to sign an individual APK
- file.
-
-e (--extra_apks) <name,name,...=key>
Add extra APK name/key pairs as though they appeared in
apkcerts.txt (so mappings specified by -k and -d are applied).
@@ -59,7 +55,7 @@
the last component of the build fingerprint). Prefix each with
'+' or '-' to indicate whether that tag should be added or
removed. Changes are processed in the order they appear.
- Default value is "-test-keys,+ota-rel-keys,+release-keys".
+ Default value is "-test-keys,+release-keys".
"""
@@ -84,7 +80,7 @@
OPTIONS.extra_apks = {}
OPTIONS.key_map = {}
OPTIONS.replace_ota_keys = False
-OPTIONS.tag_changes = ("-test-keys", "+ota-rel-keys", "+release-keys")
+OPTIONS.tag_changes = ("-test-keys", "+release-keys")
def GetApkCerts(tf_zip):
certmap = {}
@@ -272,8 +268,13 @@
k = m.group(1)
mapped_keys.append(OPTIONS.key_map.get(k, k) + ".x509.pem")
- print "using:\n ", "\n ".join(mapped_keys)
- print "for OTA package verification"
+ if mapped_keys:
+ print "using:\n ", "\n ".join(mapped_keys)
+ print "for OTA package verification"
+ else:
+ mapped_keys.append(
+ OPTIONS.key_map["build/target/product/security/testkey"] + ".x509.pem")
+ print "META/otakeys.txt has no keys; using", mapped_keys[0]
# recovery uses a version of the key that has been slightly
# predigested (by DumpPublicKey.java) and put in res/keys.
@@ -302,9 +303,7 @@
def main(argv):
def option_handler(o, a):
- if o in ("-s", "--signapk_jar"):
- OPTIONS.signapk_jar = a
- elif o in ("-e", "--extra_apks"):
+ if o in ("-e", "--extra_apks"):
names, key = a.split("=")
names = names.split(",")
for n in names:
@@ -334,9 +333,8 @@
return True
args = common.ParseOptions(argv, __doc__,
- extra_opts="s:e:d:k:ot:",
- extra_long_opts=["signapk_jar=",
- "extra_apks=",
+ extra_opts="e:d:k:ot:",
+ extra_long_opts=["extra_apks=",
"default_key_mappings=",
"key_mapping=",
"replace_ota_keys",
diff --git a/tools/signapk/SignApk.java b/tools/signapk/SignApk.java
index caf7935..3244a49 100644
--- a/tools/signapk/SignApk.java
+++ b/tools/signapk/SignApk.java
@@ -247,7 +247,7 @@
}
}
- /** Write a .SF file with a digest the specified manifest. */
+ /** Write a .SF file with a digest of the specified manifest. */
private static void writeSignatureFile(Manifest manifest, OutputStream out)
throws IOException, GeneralSecurityException {
Manifest sf = new Manifest();
@@ -304,6 +304,75 @@
pkcs7.encodeSignedData(out);
}
+ private static void signWholeOutputFile(byte[] zipData,
+ OutputStream outputStream,
+ X509Certificate publicKey,
+ PrivateKey privateKey)
+ throws IOException, GeneralSecurityException {
+
+ // For a zip with no archive comment, the
+ // end-of-central-directory record will be 22 bytes long, so
+ // we expect to find the EOCD marker 22 bytes from the end.
+ if (zipData[zipData.length-22] != 0x50 ||
+ zipData[zipData.length-21] != 0x4b ||
+ zipData[zipData.length-20] != 0x05 ||
+ zipData[zipData.length-19] != 0x06) {
+ throw new IllegalArgumentException("zip data already has an archive comment");
+ }
+
+ Signature signature = Signature.getInstance("SHA1withRSA");
+ signature.initSign(privateKey);
+ signature.update(zipData, 0, zipData.length-2);
+
+ ByteArrayOutputStream temp = new ByteArrayOutputStream();
+
+ // put a readable message and a null char at the start of the
+ // archive comment, so that tools that display the comment
+ // (hopefully) show something sensible.
+ // TODO: anything more useful we can put in this message?
+ byte[] message = "signed by SignApk".getBytes("UTF-8");
+ temp.write(message);
+ temp.write(0);
+ writeSignatureBlock(signature, publicKey, temp);
+ int total_size = temp.size() + 6;
+ if (total_size > 0xffff) {
+ throw new IllegalArgumentException("signature is too big for ZIP file comment");
+ }
+ // signature starts this many bytes from the end of the file
+ int signature_start = total_size - message.length - 1;
+ temp.write(signature_start & 0xff);
+ temp.write((signature_start >> 8) & 0xff);
+ // Why the 0xff bytes? In a zip file with no archive comment,
+ // bytes [-6:-2] of the file are the little-endian offset from
+ // the start of the file to the central directory. So for the
+ // two high bytes to be 0xff 0xff, the archive would have to
+ // be nearly 4GB in side. So it's unlikely that a real
+ // commentless archive would have 0xffs here, and lets us tell
+ // an old signed archive from a new one.
+ temp.write(0xff);
+ temp.write(0xff);
+ temp.write(total_size & 0xff);
+ temp.write((total_size >> 8) & 0xff);
+ temp.flush();
+
+ // Signature verification checks that the EOCD header is the
+ // last such sequence in the file (to avoid minzip finding a
+ // fake EOCD appended after the signature in its scan). The
+ // odds of producing this sequence by chance are very low, but
+ // let's catch it here if it does.
+ byte[] b = temp.toByteArray();
+ for (int i = 0; i < b.length-3; ++i) {
+ if (b[i] == 0x50 && b[i+1] == 0x4b && b[i+2] == 0x05 && b[i+3] == 0x06) {
+ throw new IllegalArgumentException("found spurious EOCD header at " + i);
+ }
+ }
+
+ outputStream.write(zipData, 0, zipData.length-2);
+ outputStream.write(total_size & 0xff);
+ outputStream.write((total_size >> 8) & 0xff);
+ temp.writeTo(outputStream);
+ }
+
/**
* Copy all the files in a manifest from input to output. We set
* the modification times in the output to a fixed time, so as to
@@ -340,25 +409,40 @@
}
public static void main(String[] args) {
- if (args.length != 4) {
- System.err.println("Usage: signapk " +
+ if (args.length != 4 && args.length != 5) {
+ System.err.println("Usage: signapk [-w] " +
"publickey.x509[.pem] privatekey.pk8 " +
"input.jar output.jar");
System.exit(2);
}
+ boolean signWholeFile = false;
+ int argstart = 0;
+ if (args[0].equals("-w")) {
+ signWholeFile = true;
+ argstart = 1;
+ }
+
JarFile inputJar = null;
JarOutputStream outputJar = null;
+ FileOutputStream outputFile = null;
try {
- X509Certificate publicKey = readPublicKey(new File(args[0]));
+ X509Certificate publicKey = readPublicKey(new File(args[argstart+0]));
// Assume the certificate is valid for at least an hour.
long timestamp = publicKey.getNotBefore().getTime() + 3600L * 1000;
- PrivateKey privateKey = readPrivateKey(new File(args[1]));
- inputJar = new JarFile(new File(args[2]), false); // Don't verify.
- outputJar = new JarOutputStream(new FileOutputStream(args[3]));
+ PrivateKey privateKey = readPrivateKey(new File(args[argstart+1]));
+ inputJar = new JarFile(new File(args[argstart+2]), false); // Don't verify.
+
+ OutputStream outputStream = null;
+ if (signWholeFile) {
+ outputStream = new ByteArrayOutputStream();
+ } else {
+ outputStream = outputFile = new FileOutputStream(args[argstart+3]);
+ }
+ outputJar = new JarOutputStream(outputStream);
outputJar.setLevel(9);
JarEntry je;
@@ -387,13 +471,23 @@
// Everything else
copyFiles(manifest, inputJar, outputJar, timestamp);
+
+ outputJar.close();
+ outputJar = null;
+ outputStream.flush();
+
+ if (signWholeFile) {
+ outputFile = new FileOutputStream(args[argstart+3]);
+ signWholeOutputFile(((ByteArrayOutputStream)outputStream).toByteArray(),
+ outputFile, publicKey, privateKey);
+ }
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
} finally {
try {
if (inputJar != null) inputJar.close();
- if (outputJar != null) outputJar.close();
+ if (outputFile != null) outputFile.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
diff --git a/tools/warn.py b/tools/warn.py
new file mode 100755
index 0000000..6fea20a
--- /dev/null
+++ b/tools/warn.py
@@ -0,0 +1,523 @@
+#!/usr/bin/env python
+
+import sys
+import re
+
+if len(sys.argv) == 1:
+ print 'usage: ' + sys.argv[0] + ' <build.log>'
+ sys.exit()
+
+# if you add another level, don't forget to give it a color below
+class severity:
+ UNKNOWN=0
+ SKIP=100
+ FIXMENOW=1
+ HIGH=2
+ MEDIUM=3
+ LOW=4
+ HARMLESS=5
+
+def colorforseverity(sev):
+ if sev == severity.FIXMENOW:
+ return 'fuchsia'
+ if sev == severity.HIGH:
+ return 'red'
+ if sev == severity.MEDIUM:
+ return 'orange'
+ if sev == severity.LOW:
+ return 'yellow'
+ if sev == severity.HARMLESS:
+ return 'limegreen'
+ if sev == severity.UNKNOWN:
+ return 'blue'
+ return 'grey'
+
+warnpatterns = [
+ { 'category':'make', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'make: overriding commands/ignoring old commands',
+ 'patterns':[r".*: warning: overriding commands for target .+",
+ r".*: warning: ignoring old commands for target .+"] },
+ { 'category':'C/C++', 'severity':severity.HIGH, 'members':[], 'option':'-Wimplicit-function-declaration',
+ 'description':'Implicit function declaration',
+ 'patterns':[r".*: warning: implicit declaration of function .+"] },
+ { 'category':'C/C++', 'severity':severity.SKIP, 'members':[], 'option':'',
+ 'description':'',
+ 'patterns':[r".*: warning: conflicting types for '.+'"] },
+ { 'category':'C/C++', 'severity':severity.HIGH, 'members':[], 'option':'-Wtype-limits',
+ 'description':'Expression always evaluates to true or false',
+ 'patterns':[r".*: warning: comparison is always false due to limited range of data type",
+ r".*: warning: comparison of unsigned expression >= 0 is always true",
+ r".*: warning: comparison of unsigned expression < 0 is always false"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Incompatible pointer types',
+ 'patterns':[r".*: warning: assignment from incompatible pointer type",
+ r".*: warning: passing argument [0-9]+ of '.*' from incompatible pointer type",
+ r".*: warning: initialization from incompatible pointer type"] },
+ { 'category':'C/C++', 'severity':severity.HIGH, 'members':[], 'option':'-fno-builtin',
+ 'description':'Incompatible declaration of built in function',
+ 'patterns':[r".*: warning: incompatible implicit declaration of built-in function .+"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wunused-parameter',
+ 'description':'Unused parameter',
+ 'patterns':[r".*: warning: unused parameter '.*'"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wunused',
+ 'description':'Unused function, variable or label',
+ 'patterns':[r".*: warning: '.+' defined but not used"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wunused-value',
+ 'description':'Statement with no effect',
+ 'patterns':[r".*: warning: statement with no effect"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wmissing-field-initializers',
+ 'description':'Missing initializer',
+ 'patterns':[r".*: warning: missing initializer"] },
+ { 'category':'cont.', 'severity':severity.SKIP, 'members':[], 'option':'',
+ 'description':'',
+ 'patterns':[r".*: warning: \(near initialization for '.+'\)"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wformat',
+ 'description':'Format string does not match arguments',
+ 'patterns':[r".*: warning: format '.+' expects type '.+', but argument [0-9]+ has type '.+'"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wformat-extra-args',
+ 'description':'Too many arguments for format string',
+ 'patterns':[r".*: warning: too many arguments for format"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wsign-compare',
+ 'description':'Comparison between signed and unsigned',
+ 'patterns':[r".*: warning: comparison between signed and unsigned",
+ r".*: warning: comparison of promoted \~unsigned with unsigned",
+ r".*: warning: signed and unsigned type in conditional expression"] },
+ { 'category':'libpng', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'libpng: zero area',
+ 'patterns':[r".*libpng warning: Ignoring attempt to set cHRM RGB triangle with zero area"] },
+ { 'category':'aapt', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'aapt: no comment for public symbol',
+ 'patterns':[r".*: warning: No comment for public symbol .+"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wmissing-braces',
+ 'description':'Missing braces around initializer',
+ 'patterns':[r".*: warning: missing braces around initializer.*"] },
+ { 'category':'C/C++', 'severity':severity.HARMLESS, 'members':[], 'option':'',
+ 'description':'No newline at end of file',
+ 'patterns':[r".*: warning: no newline at end of file"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wcast-qual',
+ 'description':'Qualifier discarded',
+ 'patterns':[r".*: warning: passing argument [0-9]+ of '.+' discards qualifiers from pointer target type",
+ r".*: warning: assignment discards qualifiers from pointer target type",
+ r".*: warning: return discards qualifiers from pointer target type"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wattributes',
+ 'description':'Attribute ignored',
+ 'patterns':[r".*: warning: '_*packed_*' attribute ignored"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wattributes',
+ 'description':'Visibility mismatch',
+ 'patterns':[r".*: warning: '.+' declared with greater visibility than the type of its field '.+'"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Shift count greater than width of type',
+ 'patterns':[r".*: warning: (left|right) shift count >= width of type"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'extern <foo> is initialized',
+ 'patterns':[r".*: warning: '.+' initialized and declared 'extern'"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wold-style-declaration',
+ 'description':'Old style declaration',
+ 'patterns':[r".*: warning: 'static' is not at beginning of declaration"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wuninitialized',
+ 'description':'Variable may be used uninitialized',
+ 'patterns':[r".*: warning: '.+' may be used uninitialized in this function"] },
+ { 'category':'C/C++', 'severity':severity.HIGH, 'members':[], 'option':'-Wuninitialized',
+ 'description':'Variable is used uninitialized',
+ 'patterns':[r".*: warning: '.+' is used uninitialized in this function"] },
+ { 'category':'ld', 'severity':severity.MEDIUM, 'members':[], 'option':'-fshort-enums',
+ 'description':'ld: possible enum size mismatch',
+ 'patterns':[r".*: warning: .* uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wpointer-sign',
+ 'description':'Pointer targets differ in signedness',
+ 'patterns':[r".*: warning: pointer targets in initialization differ in signedness",
+ r".*: warning: pointer targets in assignment differ in signedness",
+ r".*: warning: pointer targets in return differ in signedness",
+ r".*: warning: pointer targets in passing argument [0-9]+ of '.+' differ in signedness"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wstrict-overflow',
+ 'description':'Assuming overflow does not occur',
+ 'patterns':[r".*: warning: assuming signed overflow does not occur when assuming that .* is always (true|false)"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wempty-body',
+ 'description':'Suggest adding braces around empty body',
+ 'patterns':[r".*: warning: suggest braces around empty body in an 'if' statement",
+ r".*: warning: empty body in an if-statement",
+ r".*: warning: suggest braces around empty body in an 'else' statement",
+ r".*: warning: empty body in an else-statement"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wparentheses',
+ 'description':'Suggest adding parentheses',
+ 'patterns':[r".*: warning: suggest explicit braces to avoid ambiguous 'else'",
+ r".*: warning: suggest parentheses around arithmetic in operand of '.+'",
+ r".*: warning: suggest parentheses around comparison in operand of '.+'",
+ r".*: warning: suggest parentheses around '.+?' .+ '.+?'",
+ r".*: warning: suggest parentheses around assignment used as truth value"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Static variable used in non-static inline function',
+ 'patterns':[r".*: warning: '.+' is static but used in inline function '.+' which is not static"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wimplicit int',
+ 'description':'No type or storage class (will default to int)',
+ 'patterns':[r".*: warning: data definition has no type or storage class"] },
+ { 'category':'cont.', 'severity':severity.SKIP, 'members':[], 'option':'',
+ 'description':'',
+ 'patterns':[r".*: warning: type defaults to 'int' in declaration of '.+'"] },
+ { 'category':'cont.', 'severity':severity.SKIP, 'members':[], 'option':'',
+ 'description':'',
+ 'patterns':[r".*: warning: parameter names \(without types\) in function declaration"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wstrict-aliasing',
+ 'description':'Dereferencing <foo> breaks strict aliasing rules',
+ 'patterns':[r".*: warning: dereferencing .* break strict-aliasing rules"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wpointer-to-int-cast',
+ 'description':'Cast from pointer to integer of different size',
+ 'patterns':[r".*: warning: cast from pointer to integer of different size"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wint-to-pointer-cast',
+ 'description':'Cast to pointer from integer of different size',
+ 'patterns':[r".*: warning: cast to pointer from integer of different size"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Symbol redefined',
+ 'patterns':[r".*: warning: "".+"" redefined"] },
+ { 'category':'cont.', 'severity':severity.SKIP, 'members':[], 'option':'',
+ 'description':'',
+ 'patterns':[r".*: warning: this is the location of the previous definition"] },
+ { 'category':'ld', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'ld: type and size of dynamic symbol are not defined',
+ 'patterns':[r".*: warning: type and size of dynamic symbol `.+' are not defined"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Pointer from integer without cast',
+ 'patterns':[r".*: warning: assignment makes pointer from integer without a cast"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Pointer from integer without cast',
+ 'patterns':[r".*: warning: passing argument [0-9]+ of '.+' makes pointer from integer without a cast"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Integer from pointer without cast',
+ 'patterns':[r".*: warning: assignment makes integer from pointer without a cast"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Integer from pointer without cast',
+ 'patterns':[r".*: warning: passing argument [0-9]+ of '.+' makes integer from pointer without a cast"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Integer from pointer without cast',
+ 'patterns':[r".*: warning: return makes integer from pointer without a cast"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wunknown-pragmas',
+ 'description':'Ignoring pragma',
+ 'patterns':[r".*: warning: ignoring #pragma .+"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wclobbered',
+ 'description':'Variable might be clobbered by longjmp or vfork',
+ 'patterns':[r".*: warning: variable '.+' might be clobbered by 'longjmp' or 'vfork'"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wclobbered',
+ 'description':'Argument might be clobbered by longjmp or vfork',
+ 'patterns':[r".*: warning: argument '.+' might be clobbered by 'longjmp' or 'vfork'"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wredundant-decls',
+ 'description':'Redundant declaration',
+ 'patterns':[r".*: warning: redundant redeclaration of '.+'"] },
+ { 'category':'cont.', 'severity':severity.SKIP, 'members':[], 'option':'',
+ 'description':'',
+ 'patterns':[r".*: warning: previous declaration of '.+' was here"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wswitch-enum',
+ 'description':'Enum value not handled in switch',
+ 'patterns':[r".*: warning: enumeration value '.+' not handled in switch"] },
+ { 'category':'java', 'severity':severity.MEDIUM, 'members':[], 'option':'-encoding',
+ 'description':'Java: Non-ascii characters used, but ascii encoding specified',
+ 'patterns':[r".*: warning: unmappable character for encoding ascii"] },
+ { 'category':'java', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Java: Non-varargs call of varargs method with inexact argument type for last parameter',
+ 'patterns':[r".*: warning: non-varargs call of varargs method with inexact argument type for last parameter"] },
+ { 'category':'aapt', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'aapt: String marked untranslatable, but translation exists',
+ 'patterns':[r".*: warning: string '.+' in .* marked untranslatable but exists in locale '??_??'"] },
+ { 'category':'aapt', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'aapt: empty span in string',
+ 'patterns':[r".*: warning: empty '.+' span found in text '.+"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Taking address of temporary',
+ 'patterns':[r".*: warning: taking address of temporary"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Possible broken line continuation',
+ 'patterns':[r".*: warning: backslash and newline separated by space"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Warray-bounds',
+ 'description':'Array subscript out of bounds',
+ 'patterns':[r".*: warning: array subscript is above array bounds"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Decimal constant is unsigned only in ISO C90',
+ 'patterns':[r".*: warning: this decimal constant is unsigned only in ISO C90"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wmain',
+ 'description':'main is usually a function',
+ 'patterns':[r".*: warning: 'main' is usually a function"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Typedef ignored',
+ 'patterns':[r".*: warning: 'typedef' was ignored in this declaration"] },
+ { 'category':'C/C++', 'severity':severity.HIGH, 'members':[], 'option':'-Waddress',
+ 'description':'Address always evaluates to true',
+ 'patterns':[r".*: warning: the address of '.+' will always evaluate as 'true'"] },
+ { 'category':'C/C++', 'severity':severity.FIXMENOW, 'members':[], 'option':'',
+ 'description':'Freeing a non-heap object',
+ 'patterns':[r".*: warning: attempt to free a non-heap object '.+'"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wchar-subscripts',
+ 'description':'Array subscript has type char',
+ 'patterns':[r".*: warning: array subscript has type 'char'"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Constant too large for type',
+ 'patterns':[r".*: warning: integer constant is too large for '.+' type"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Woverflow',
+ 'description':'Constant too large for type, truncated',
+ 'patterns':[r".*: warning: large integer implicitly truncated to unsigned type"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Woverflow',
+ 'description':'Overflow in implicit constant conversion',
+ 'patterns':[r".*: warning: overflow in implicit constant conversion"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Declaration does not declare anything',
+ 'patterns':[r".*: warning: declaration 'class .+' does not declare anything"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wreorder',
+ 'description':'Initialization order will be different',
+ 'patterns':[r".*: warning: '.+' will be initialized after"] },
+ { 'category':'cont.', 'severity':severity.SKIP, 'members':[], 'option':'',
+ 'description':'',
+ 'patterns':[r".*: warning: '.+'"] },
+ { 'category':'cont.', 'severity':severity.SKIP, 'members':[], 'option':'',
+ 'description':'',
+ 'patterns':[r".*: warning: when initialized here"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wmissing-parameter-type',
+ 'description':'Parameter type not specified',
+ 'patterns':[r".*: warning: type of '.+' defaults to 'int'"] },
+ { 'category':'gcc', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Invalid option for C file',
+ 'patterns':[r".*: warning: command line option "".+"" is valid for C\+\+\/ObjC\+\+ but not for C"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'User warning',
+ 'patterns':[r".*: warning: #warning "".+"""] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wextra',
+ 'description':'Dereferencing void*',
+ 'patterns':[r".*: warning: dereferencing 'void \*' pointer"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wextra',
+ 'description':'Comparison of pointer to zero',
+ 'patterns':[r".*: warning: ordered comparison of pointer with integer zero"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wwrite-strings',
+ 'description':'Conversion of string constant to non-const char*',
+ 'patterns':[r".*: warning: deprecated conversion from string constant to '.+'"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wstrict-prototypes',
+ 'description':'Function declaration isn''t a prototype',
+ 'patterns':[r".*: warning: function declaration isn't a prototype"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wignored-qualifiers',
+ 'description':'Type qualifiers ignored on function return value',
+ 'patterns':[r".*: warning: type qualifiers ignored on function return type"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'<foo> declared inside parameter list, scope limited to this definition',
+ 'patterns':[r".*: warning: '.+' declared inside parameter list"] },
+ { 'category':'cont.', 'severity':severity.SKIP, 'members':[], 'option':'',
+ 'description':'',
+ 'patterns':[r".*: warning: its scope is only this definition or declaration, which is probably not what you want"] },
+ { 'category':'C/C++', 'severity':severity.LOW, 'members':[], 'option':'-Wcomment',
+ 'description':'Line continuation inside comment',
+ 'patterns':[r".*: warning: multi-line comment"] },
+ { 'category':'C/C++', 'severity':severity.HARMLESS, 'members':[], 'option':'',
+ 'description':'Extra tokens after #endif',
+ 'patterns':[r".*: warning: extra tokens at end of #endif directive"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wenum-compare',
+ 'description':'Comparison between different enums',
+ 'patterns':[r".*: warning: comparison between 'enum .+' and 'enum .+'"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wconversion',
+ 'description':'Implicit conversion of negative number to unsigned type',
+ 'patterns':[r".*: warning: converting negative value '.+' to '.+'"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Passing NULL as non-pointer argument',
+ 'patterns':[r".*: warning: passing NULL to non-pointer argument [0-9]+ of '.+'"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wctor-dtor-privacy',
+ 'description':'Class seems unusable because of private ctor/dtor' ,
+ 'patterns':[r".*: warning: all member functions in class '.+' are private"] },
+ # skip this next one, because it only points out some RefBase-based classes where having a private destructor is perfectly fine
+ { 'category':'C/C++', 'severity':severity.SKIP, 'members':[], 'option':'-Wctor-dtor-privacy',
+ 'description':'Class seems unusable because of private ctor/dtor' ,
+ 'patterns':[r".*: warning: 'class .+' only defines a private destructor and has no friends"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wctor-dtor-privacy',
+ 'description':'Class seems unusable because of private ctor/dtor' ,
+ 'patterns':[r".*: warning: 'class .+' only defines private constructors and has no friends"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wpointer-arith',
+ 'description':'void* used in arithmetic' ,
+ 'patterns':[r".*: warning: pointer of type 'void \*' used in (arithmetic|subtraction)",
+ r".*: warning: wrong type argument to increment"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'-Wsign-promo',
+ 'description':'Overload resolution chose to promote from unsigned or enum to signed type' ,
+ 'patterns':[r".*: warning: passing '.+' chooses 'int' over '.* int'"] },
+ { 'category':'cont.', 'severity':severity.SKIP, 'members':[], 'option':'',
+ 'description':'',
+ 'patterns':[r".*: warning: in call to '.+'"] },
+ { 'category':'C/C++', 'severity':severity.HIGH, 'members':[], 'option':'-Wextra',
+ 'description':'Base should be explicitly initialized in copy constructor',
+ 'patterns':[r".*: warning: base class '.+' should be explicitly initialized in the copy constructor"] },
+ { 'category':'C/C++', 'severity':severity.MEDIUM, 'members':[], 'option':'',
+ 'description':'Converting from <type> to <other type>',
+ 'patterns':[r".*: warning: converting to '.+' from '.+'"] },
+
+ # these next ones are to deal with formatting problems resulting from the log being mixed up by 'make -j'
+ { 'category':'C/C++', 'severity':severity.SKIP, 'members':[], 'option':'',
+ 'description':'',
+ 'patterns':[r".*: warning: ,$"] },
+ { 'category':'C/C++', 'severity':severity.SKIP, 'members':[], 'option':'',
+ 'description':'',
+ 'patterns':[r".*: warning: $"] },
+ { 'category':'C/C++', 'severity':severity.SKIP, 'members':[], 'option':'',
+ 'description':'',
+ 'patterns':[r".*: warning: In file included from .+,"] },
+
+ # catch-all for warnings this script doesn't know about yet
+ { 'category':'C/C++', 'severity':severity.UNKNOWN, 'members':[], 'option':'',
+ 'description':'Unclassified/unrecognized warnings',
+ 'patterns':[r".*: warning: .+"] },
+]
+
+anchor = 0
+cur_row_color = 0
+row_colors = [ 'e0e0e0', 'd0d0d0' ]
+
+def output(text):
+ print text,
+
+def htmlbig(param):
+ return '<font size="+2">' + param + '</font>'
+
+def dumphtmlprologue(title):
+ output('<html>\n<head>\n<title>' + title + '</title>\n<body>\n')
+ output(htmlbig(title))
+ output('<p>\n')
+
+def tablerow(text):
+ global cur_row_color
+ output('<tr bgcolor="' + row_colors[cur_row_color] + '"><td colspan="2">',)
+ cur_row_color = 1 - cur_row_color
+ output(text,)
+ output('</td></tr>')
+
+def begintable(text, backgroundcolor):
+ global anchor
+ output('<table border="1" rules="cols" frame="box" width="100%" bgcolor="black"><tr bgcolor="' +
+ backgroundcolor + '"><a name="anchor' + str(anchor) + '"><td>')
+ output(htmlbig(text[0]) + '<br>')
+ for i in text[1:]:
+ output(i + '<br>')
+ output('</td>')
+ output('<td width="100" bgcolor="grey"><a align="right" href="#anchor' + str(anchor-1) +
+ '">previous</a><br><a align="right" href="#anchor' + str(anchor+1) + '">next</a>')
+ output('</td></a></tr>')
+ anchor += 1
+
+def endtable():
+ output('</table><p>')
+
+
+# dump some stats about total number of warnings and such
+def dumpstats():
+ known = 0
+ unknown = 0
+ for i in warnpatterns:
+ if i['severity'] == severity.UNKNOWN:
+ unknown += len(i['members'])
+ elif i['severity'] != severity.SKIP:
+ known += len(i['members'])
+ output('Number of classified warnings: <b>' + str(known) + '</b><br>' )
+ output('Number of unclassified warnings: <b>' + str(unknown) + '</b><br>')
+ total = unknown + known
+ output('Total number of warnings: <b>' + str(total) + '</b>')
+ if total < 1000:
+ output('(low count may indicate incremental build)')
+ output('<p>')
+
+def allpatterns(cat):
+ pats = ''
+ for i in cat['patterns']:
+ pats += i
+ pats += ' / '
+ return pats
+
+def descriptionfor(cat):
+ if cat['description'] != '':
+ return cat['description']
+ return allpatterns(cat)
+
+
+# show which warnings no longer occur
+def dumpfixed():
+ tablestarted = False
+ for i in warnpatterns:
+ if len(i['members']) == 0 and i['severity'] != severity.SKIP:
+ if tablestarted == False:
+ tablestarted = True
+ begintable(['Fixed warnings', 'No more occurences. Please consider turning these in to errors if possible, before they are reintroduced in to the build'], 'blue')
+ tablerow(i['description'] + ' (' + allpatterns(i) + ') ' + i['option'])
+ if tablestarted:
+ endtable()
+
+
+# dump a category, provided it is not marked as 'SKIP' and has more than 0 occurrences
+def dumpcategory(cat):
+ if cat['severity'] != severity.SKIP and len(cat['members']) != 0:
+ header = [descriptionfor(cat),str(len(cat['members'])) + ' occurences:']
+ if cat['option'] != '':
+ header[1:1] = [' (related option: ' + cat['option'] +')']
+ begintable(header, colorforseverity(cat['severity']))
+ for i in cat['members']:
+ tablerow(i)
+ endtable()
+
+
+# dump everything for a given severity
+def dumpseverity(sev):
+ for i in warnpatterns:
+ if i['severity'] == sev:
+ dumpcategory(i)
+
+
+def classifywarning(line):
+ for i in warnpatterns:
+ for cpat in i['compiledpatterns']:
+ if cpat.match(line):
+ i['members'].append(line)
+ return
+ else:
+ # If we end up here, there was a problem parsing the log
+ # probably caused by 'make -j' mixing the output from
+ # 2 or more concurrent compiles
+ pass
+
+# precompiling every pattern speeds up parsing by about 30x
+def compilepatterns():
+ for i in warnpatterns:
+ i['compiledpatterns'] = []
+ for pat in i['patterns']:
+ i['compiledpatterns'].append(re.compile(pat))
+
+infile = open(sys.argv[1], 'r')
+warnings = []
+
+platformversion = 'unknown'
+targetproduct = 'unknown'
+targetvariant = 'unknown'
+linecounter = 0
+
+warningpattern = re.compile('.* warning:.*')
+compilepatterns()
+
+# read the log file and classify all the warnings
+lastmatchedline = ''
+for line in infile:
+ if warningpattern.match(line):
+ if line != lastmatchedline:
+ classifywarning(line)
+ lastmatchedline = line
+ else:
+ # save a little bit of time by only doing this for the first few lines
+ if linecounter < 50:
+ linecounter +=1
+ m = re.search('(?<=^PLATFORM_VERSION=).*', line)
+ if m != None:
+ platformversion = m.group(0)
+ m = re.search('(?<=^TARGET_PRODUCT=).*', line)
+ if m != None:
+ targetproduct = m.group(0)
+ m = re.search('(?<=^TARGET_BUILD_VARIANT=).*', line)
+ if m != None:
+ targetvariant = m.group(0)
+
+
+# dump the html output to stdout
+dumphtmlprologue('Warnings for ' + platformversion + ' - ' + targetproduct + ' - ' + targetvariant)
+dumpstats()
+dumpseverity(severity.FIXMENOW)
+dumpseverity(severity.HIGH)
+dumpseverity(severity.MEDIUM)
+dumpseverity(severity.LOW)
+dumpseverity(severity.HARMLESS)
+dumpseverity(severity.UNKNOWN)
+dumpfixed()
+
diff --git a/tools/zipalign/Android.mk b/tools/zipalign/Android.mk
index e23b699..f90a31c 100644
--- a/tools/zipalign/Android.mk
+++ b/tools/zipalign/Android.mk
@@ -8,7 +8,9 @@
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
- ZipAlign.cpp
+ ZipAlign.cpp \
+ ZipEntry.cpp \
+ ZipFile.cpp
LOCAL_C_INCLUDES += external/zlib
diff --git a/tools/zipalign/README.txt b/tools/zipalign/README.txt
index a2e1a5e..9c7d07e 100644
--- a/tools/zipalign/README.txt
+++ b/tools/zipalign/README.txt
@@ -1,7 +1,9 @@
zipalign -- zip archive alignment tool
usage: zipalign [-f] [-v] <align> infile.zip outfile.zip
+ zipalign -c [-v] <align> infile.zip
+ -c : check alignment only (does not modify file)
-f : overwrite existing outfile.zip
-v : verbose output
<align> is in bytes, e.g. "4" provides 32-bit alignment
@@ -29,3 +31,5 @@
By default, zipalign will not overwrite an existing output file. With the
"-f" flag, an existing file will be overwritten.
+You can use the "-c" flag to test whether a zip archive is properly aligned.
+
diff --git a/tools/zipalign/ZipAlign.cpp b/tools/zipalign/ZipAlign.cpp
index 058f9ed..c2d8159 100644
--- a/tools/zipalign/ZipAlign.cpp
+++ b/tools/zipalign/ZipAlign.cpp
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
/*
* Zip alignment tool
*/
-#include "utils/ZipFile.h"
+#include "ZipFile.h"
#include <stdlib.h>
#include <stdio.h>
@@ -29,9 +30,15 @@
void usage(void)
{
fprintf(stderr, "Zip alignment utility\n");
+ fprintf(stderr, "Copyright (C) 2009 The Android Open Source Project\n\n");
fprintf(stderr,
"Usage: zipalign [-f] [-v] <align> infile.zip outfile.zip\n"
- " zipalign -c [-v] <align> infile.zip\n" );
+ " zipalign -c [-v] <align> infile.zip\n\n" );
+ fprintf(stderr,
+ " <align>: alignment in bytes, e.g. '4' provides 32-bit alignment\n");
+ fprintf(stderr, " -c: check alignment only (does not modify file)\n");
+ fprintf(stderr, " -f: overwrite existing outfile.zip\n");
+ fprintf(stderr, " -v: verbose output\n");
}
/*
diff --git a/tools/zipalign/ZipEntry.cpp b/tools/zipalign/ZipEntry.cpp
new file mode 100644
index 0000000..bed0333
--- /dev/null
+++ b/tools/zipalign/ZipEntry.cpp
@@ -0,0 +1,696 @@
+/*
+ * Copyright (C) 2006 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// Access to entries in a Zip archive.
+//
+
+#define LOG_TAG "zip"
+
+#include "ZipEntry.h"
+#include <utils/Log.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+using namespace android;
+
+/*
+ * Initialize a new ZipEntry structure from a FILE* positioned at a
+ * CentralDirectoryEntry.
+ *
+ * On exit, the file pointer will be at the start of the next CDE or
+ * at the EOCD.
+ */
+status_t ZipEntry::initFromCDE(FILE* fp)
+{
+ status_t result;
+ long posn;
+ bool hasDD;
+
+ //LOGV("initFromCDE ---\n");
+
+ /* read the CDE */
+ result = mCDE.read(fp);
+ if (result != NO_ERROR) {
+ LOGD("mCDE.read failed\n");
+ return result;
+ }
+
+ //mCDE.dump();
+
+ /* using the info in the CDE, go load up the LFH */
+ posn = ftell(fp);
+ if (fseek(fp, mCDE.mLocalHeaderRelOffset, SEEK_SET) != 0) {
+ LOGD("local header seek failed (%ld)\n",
+ mCDE.mLocalHeaderRelOffset);
+ return UNKNOWN_ERROR;
+ }
+
+ result = mLFH.read(fp);
+ if (result != NO_ERROR) {
+ LOGD("mLFH.read failed\n");
+ return result;
+ }
+
+ if (fseek(fp, posn, SEEK_SET) != 0)
+ return UNKNOWN_ERROR;
+
+ //mLFH.dump();
+
+ /*
+ * We *might* need to read the Data Descriptor at this point and
+ * integrate it into the LFH. If this bit is set, the CRC-32,
+ * compressed size, and uncompressed size will be zero. In practice
+ * these seem to be rare.
+ */
+ hasDD = (mLFH.mGPBitFlag & kUsesDataDescr) != 0;
+ if (hasDD) {
+ // do something clever
+ //LOGD("+++ has data descriptor\n");
+ }
+
+ /*
+ * Sanity-check the LFH. Note that this will fail if the "kUsesDataDescr"
+ * flag is set, because the LFH is incomplete. (Not a problem, since we
+ * prefer the CDE values.)
+ */
+ if (!hasDD && !compareHeaders()) {
+ LOGW("WARNING: header mismatch\n");
+ // keep going?
+ }
+
+ /*
+ * If the mVersionToExtract is greater than 20, we may have an
+ * issue unpacking the record -- could be encrypted, compressed
+ * with something we don't support, or use Zip64 extensions. We
+ * can defer worrying about that to when we're extracting data.
+ */
+
+ return NO_ERROR;
+}
+
+/*
+ * Initialize a new entry. Pass in the file name and an optional comment.
+ *
+ * Initializes the CDE and the LFH.
+ */
+void ZipEntry::initNew(const char* fileName, const char* comment)
+{
+ assert(fileName != NULL && *fileName != '\0'); // name required
+
+ /* most fields are properly initialized by constructor */
+ mCDE.mVersionMadeBy = kDefaultMadeBy;
+ mCDE.mVersionToExtract = kDefaultVersion;
+ mCDE.mCompressionMethod = kCompressStored;
+ mCDE.mFileNameLength = strlen(fileName);
+ if (comment != NULL)
+ mCDE.mFileCommentLength = strlen(comment);
+ mCDE.mExternalAttrs = 0x81b60020; // matches what WinZip does
+
+ if (mCDE.mFileNameLength > 0) {
+ mCDE.mFileName = new unsigned char[mCDE.mFileNameLength+1];
+ strcpy((char*) mCDE.mFileName, fileName);
+ }
+ if (mCDE.mFileCommentLength > 0) {
+ /* TODO: stop assuming null-terminated ASCII here? */
+ mCDE.mFileComment = new unsigned char[mCDE.mFileCommentLength+1];
+ strcpy((char*) mCDE.mFileComment, comment);
+ }
+
+ copyCDEtoLFH();
+}
+
+/*
+ * Initialize a new entry, starting with the ZipEntry from a different
+ * archive.
+ *
+ * Initializes the CDE and the LFH.
+ */
+status_t ZipEntry::initFromExternal(const ZipFile* pZipFile,
+ const ZipEntry* pEntry)
+{
+ /*
+ * Copy everything in the CDE over, then fix up the hairy bits.
+ */
+ memcpy(&mCDE, &pEntry->mCDE, sizeof(mCDE));
+
+ if (mCDE.mFileNameLength > 0) {
+ mCDE.mFileName = new unsigned char[mCDE.mFileNameLength+1];
+ if (mCDE.mFileName == NULL)
+ return NO_MEMORY;
+ strcpy((char*) mCDE.mFileName, (char*)pEntry->mCDE.mFileName);
+ }
+ if (mCDE.mFileCommentLength > 0) {
+ mCDE.mFileComment = new unsigned char[mCDE.mFileCommentLength+1];
+ if (mCDE.mFileComment == NULL)
+ return NO_MEMORY;
+ strcpy((char*) mCDE.mFileComment, (char*)pEntry->mCDE.mFileComment);
+ }
+ if (mCDE.mExtraFieldLength > 0) {
+ /* we null-terminate this, though it may not be a string */
+ mCDE.mExtraField = new unsigned char[mCDE.mExtraFieldLength+1];
+ if (mCDE.mExtraField == NULL)
+ return NO_MEMORY;
+ memcpy(mCDE.mExtraField, pEntry->mCDE.mExtraField,
+ mCDE.mExtraFieldLength+1);
+ }
+
+ /* construct the LFH from the CDE */
+ copyCDEtoLFH();
+
+ /*
+ * The LFH "extra" field is independent of the CDE "extra", so we
+ * handle it here.
+ */
+ assert(mLFH.mExtraField == NULL);
+ mLFH.mExtraFieldLength = pEntry->mLFH.mExtraFieldLength;
+ if (mLFH.mExtraFieldLength > 0) {
+ mLFH.mExtraField = new unsigned char[mLFH.mExtraFieldLength+1];
+ if (mLFH.mExtraField == NULL)
+ return NO_MEMORY;
+ memcpy(mLFH.mExtraField, pEntry->mLFH.mExtraField,
+ mLFH.mExtraFieldLength+1);
+ }
+
+ return NO_ERROR;
+}
+
+/*
+ * Insert pad bytes in the LFH by tweaking the "extra" field. This will
+ * potentially confuse something that put "extra" data in here earlier,
+ * but I can't find an actual problem.
+ */
+status_t ZipEntry::addPadding(int padding)
+{
+ if (padding <= 0)
+ return INVALID_OPERATION;
+
+ //LOGI("HEY: adding %d pad bytes to existing %d in %s\n",
+ // padding, mLFH.mExtraFieldLength, mCDE.mFileName);
+
+ if (mLFH.mExtraFieldLength > 0) {
+ /* extend existing field */
+ unsigned char* newExtra;
+
+ newExtra = new unsigned char[mLFH.mExtraFieldLength + padding];
+ if (newExtra == NULL)
+ return NO_MEMORY;
+ memset(newExtra + mLFH.mExtraFieldLength, 0, padding);
+ memcpy(newExtra, mLFH.mExtraField, mLFH.mExtraFieldLength);
+
+ delete[] mLFH.mExtraField;
+ mLFH.mExtraField = newExtra;
+ mLFH.mExtraFieldLength += padding;
+ } else {
+ /* create new field */
+ mLFH.mExtraField = new unsigned char[padding];
+ memset(mLFH.mExtraField, 0, padding);
+ mLFH.mExtraFieldLength = padding;
+ }
+
+ return NO_ERROR;
+}
+
+/*
+ * Set the fields in the LFH equal to the corresponding fields in the CDE.
+ *
+ * This does not touch the LFH "extra" field.
+ */
+void ZipEntry::copyCDEtoLFH(void)
+{
+ mLFH.mVersionToExtract = mCDE.mVersionToExtract;
+ mLFH.mGPBitFlag = mCDE.mGPBitFlag;
+ mLFH.mCompressionMethod = mCDE.mCompressionMethod;
+ mLFH.mLastModFileTime = mCDE.mLastModFileTime;
+ mLFH.mLastModFileDate = mCDE.mLastModFileDate;
+ mLFH.mCRC32 = mCDE.mCRC32;
+ mLFH.mCompressedSize = mCDE.mCompressedSize;
+ mLFH.mUncompressedSize = mCDE.mUncompressedSize;
+ mLFH.mFileNameLength = mCDE.mFileNameLength;
+ // the "extra field" is independent
+
+ delete[] mLFH.mFileName;
+ if (mLFH.mFileNameLength > 0) {
+ mLFH.mFileName = new unsigned char[mLFH.mFileNameLength+1];
+ strcpy((char*) mLFH.mFileName, (const char*) mCDE.mFileName);
+ } else {
+ mLFH.mFileName = NULL;
+ }
+}
+
+/*
+ * Set some information about a file after we add it.
+ */
+void ZipEntry::setDataInfo(long uncompLen, long compLen, unsigned long crc32,
+ int compressionMethod)
+{
+ mCDE.mCompressionMethod = compressionMethod;
+ mCDE.mCRC32 = crc32;
+ mCDE.mCompressedSize = compLen;
+ mCDE.mUncompressedSize = uncompLen;
+ mCDE.mCompressionMethod = compressionMethod;
+ if (compressionMethod == kCompressDeflated) {
+ mCDE.mGPBitFlag |= 0x0002; // indicates maximum compression used
+ }
+ copyCDEtoLFH();
+}
+
+/*
+ * See if the data in mCDE and mLFH match up. This is mostly useful for
+ * debugging these classes, but it can be used to identify damaged
+ * archives.
+ *
+ * Returns "false" if they differ.
+ */
+bool ZipEntry::compareHeaders(void) const
+{
+ if (mCDE.mVersionToExtract != mLFH.mVersionToExtract) {
+ LOGV("cmp: VersionToExtract\n");
+ return false;
+ }
+ if (mCDE.mGPBitFlag != mLFH.mGPBitFlag) {
+ LOGV("cmp: GPBitFlag\n");
+ return false;
+ }
+ if (mCDE.mCompressionMethod != mLFH.mCompressionMethod) {
+ LOGV("cmp: CompressionMethod\n");
+ return false;
+ }
+ if (mCDE.mLastModFileTime != mLFH.mLastModFileTime) {
+ LOGV("cmp: LastModFileTime\n");
+ return false;
+ }
+ if (mCDE.mLastModFileDate != mLFH.mLastModFileDate) {
+ LOGV("cmp: LastModFileDate\n");
+ return false;
+ }
+ if (mCDE.mCRC32 != mLFH.mCRC32) {
+ LOGV("cmp: CRC32\n");
+ return false;
+ }
+ if (mCDE.mCompressedSize != mLFH.mCompressedSize) {
+ LOGV("cmp: CompressedSize\n");
+ return false;
+ }
+ if (mCDE.mUncompressedSize != mLFH.mUncompressedSize) {
+ LOGV("cmp: UncompressedSize\n");
+ return false;
+ }
+ if (mCDE.mFileNameLength != mLFH.mFileNameLength) {
+ LOGV("cmp: FileNameLength\n");
+ return false;
+ }
+#if 0 // this seems to be used for padding, not real data
+ if (mCDE.mExtraFieldLength != mLFH.mExtraFieldLength) {
+ LOGV("cmp: ExtraFieldLength\n");
+ return false;
+ }
+#endif
+ if (mCDE.mFileName != NULL) {
+ if (strcmp((char*) mCDE.mFileName, (char*) mLFH.mFileName) != 0) {
+ LOGV("cmp: FileName\n");
+ return false;
+ }
+ }
+
+ return true;
+}
+
+
+/*
+ * Convert the DOS date/time stamp into a UNIX time stamp.
+ */
+time_t ZipEntry::getModWhen(void) const
+{
+ struct tm parts;
+
+ parts.tm_sec = (mCDE.mLastModFileTime & 0x001f) << 1;
+ parts.tm_min = (mCDE.mLastModFileTime & 0x07e0) >> 5;
+ parts.tm_hour = (mCDE.mLastModFileTime & 0xf800) >> 11;
+ parts.tm_mday = (mCDE.mLastModFileDate & 0x001f);
+ parts.tm_mon = ((mCDE.mLastModFileDate & 0x01e0) >> 5) -1;
+ parts.tm_year = ((mCDE.mLastModFileDate & 0xfe00) >> 9) + 80;
+ parts.tm_wday = parts.tm_yday = 0;
+ parts.tm_isdst = -1; // DST info "not available"
+
+ return mktime(&parts);
+}
+
+/*
+ * Set the CDE/LFH timestamp from UNIX time.
+ */
+void ZipEntry::setModWhen(time_t when)
+{
+#ifdef HAVE_LOCALTIME_R
+ struct tm tmResult;
+#endif
+ time_t even;
+ unsigned short zdate, ztime;
+
+ struct tm* ptm;
+
+ /* round up to an even number of seconds */
+ even = (time_t)(((unsigned long)(when) + 1) & (~1));
+
+ /* expand */
+#ifdef HAVE_LOCALTIME_R
+ ptm = localtime_r(&even, &tmResult);
+#else
+ ptm = localtime(&even);
+#endif
+
+ int year;
+ year = ptm->tm_year;
+ if (year < 80)
+ year = 80;
+
+ zdate = (year - 80) << 9 | (ptm->tm_mon+1) << 5 | ptm->tm_mday;
+ ztime = ptm->tm_hour << 11 | ptm->tm_min << 5 | ptm->tm_sec >> 1;
+
+ mCDE.mLastModFileTime = mLFH.mLastModFileTime = ztime;
+ mCDE.mLastModFileDate = mLFH.mLastModFileDate = zdate;
+}
+
+
+/*
+ * ===========================================================================
+ * ZipEntry::LocalFileHeader
+ * ===========================================================================
+ */
+
+/*
+ * Read a local file header.
+ *
+ * On entry, "fp" points to the signature at the start of the header.
+ * On exit, "fp" points to the start of data.
+ */
+status_t ZipEntry::LocalFileHeader::read(FILE* fp)
+{
+ status_t result = NO_ERROR;
+ unsigned char buf[kLFHLen];
+
+ assert(mFileName == NULL);
+ assert(mExtraField == NULL);
+
+ if (fread(buf, 1, kLFHLen, fp) != kLFHLen) {
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+
+ if (ZipEntry::getLongLE(&buf[0x00]) != kSignature) {
+ LOGD("whoops: didn't find expected signature\n");
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+
+ mVersionToExtract = ZipEntry::getShortLE(&buf[0x04]);
+ mGPBitFlag = ZipEntry::getShortLE(&buf[0x06]);
+ mCompressionMethod = ZipEntry::getShortLE(&buf[0x08]);
+ mLastModFileTime = ZipEntry::getShortLE(&buf[0x0a]);
+ mLastModFileDate = ZipEntry::getShortLE(&buf[0x0c]);
+ mCRC32 = ZipEntry::getLongLE(&buf[0x0e]);
+ mCompressedSize = ZipEntry::getLongLE(&buf[0x12]);
+ mUncompressedSize = ZipEntry::getLongLE(&buf[0x16]);
+ mFileNameLength = ZipEntry::getShortLE(&buf[0x1a]);
+ mExtraFieldLength = ZipEntry::getShortLE(&buf[0x1c]);
+
+ // TODO: validate sizes
+
+ /* grab filename */
+ if (mFileNameLength != 0) {
+ mFileName = new unsigned char[mFileNameLength+1];
+ if (mFileName == NULL) {
+ result = NO_MEMORY;
+ goto bail;
+ }
+ if (fread(mFileName, 1, mFileNameLength, fp) != mFileNameLength) {
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+ mFileName[mFileNameLength] = '\0';
+ }
+
+ /* grab extra field */
+ if (mExtraFieldLength != 0) {
+ mExtraField = new unsigned char[mExtraFieldLength+1];
+ if (mExtraField == NULL) {
+ result = NO_MEMORY;
+ goto bail;
+ }
+ if (fread(mExtraField, 1, mExtraFieldLength, fp) != mExtraFieldLength) {
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+ mExtraField[mExtraFieldLength] = '\0';
+ }
+
+bail:
+ return result;
+}
+
+/*
+ * Write a local file header.
+ */
+status_t ZipEntry::LocalFileHeader::write(FILE* fp)
+{
+ unsigned char buf[kLFHLen];
+
+ ZipEntry::putLongLE(&buf[0x00], kSignature);
+ ZipEntry::putShortLE(&buf[0x04], mVersionToExtract);
+ ZipEntry::putShortLE(&buf[0x06], mGPBitFlag);
+ ZipEntry::putShortLE(&buf[0x08], mCompressionMethod);
+ ZipEntry::putShortLE(&buf[0x0a], mLastModFileTime);
+ ZipEntry::putShortLE(&buf[0x0c], mLastModFileDate);
+ ZipEntry::putLongLE(&buf[0x0e], mCRC32);
+ ZipEntry::putLongLE(&buf[0x12], mCompressedSize);
+ ZipEntry::putLongLE(&buf[0x16], mUncompressedSize);
+ ZipEntry::putShortLE(&buf[0x1a], mFileNameLength);
+ ZipEntry::putShortLE(&buf[0x1c], mExtraFieldLength);
+
+ if (fwrite(buf, 1, kLFHLen, fp) != kLFHLen)
+ return UNKNOWN_ERROR;
+
+ /* write filename */
+ if (mFileNameLength != 0) {
+ if (fwrite(mFileName, 1, mFileNameLength, fp) != mFileNameLength)
+ return UNKNOWN_ERROR;
+ }
+
+ /* write "extra field" */
+ if (mExtraFieldLength != 0) {
+ if (fwrite(mExtraField, 1, mExtraFieldLength, fp) != mExtraFieldLength)
+ return UNKNOWN_ERROR;
+ }
+
+ return NO_ERROR;
+}
+
+
+/*
+ * Dump the contents of a LocalFileHeader object.
+ */
+void ZipEntry::LocalFileHeader::dump(void) const
+{
+ LOGD(" LocalFileHeader contents:\n");
+ LOGD(" versToExt=%u gpBits=0x%04x compression=%u\n",
+ mVersionToExtract, mGPBitFlag, mCompressionMethod);
+ LOGD(" modTime=0x%04x modDate=0x%04x crc32=0x%08lx\n",
+ mLastModFileTime, mLastModFileDate, mCRC32);
+ LOGD(" compressedSize=%lu uncompressedSize=%lu\n",
+ mCompressedSize, mUncompressedSize);
+ LOGD(" filenameLen=%u extraLen=%u\n",
+ mFileNameLength, mExtraFieldLength);
+ if (mFileName != NULL)
+ LOGD(" filename: '%s'\n", mFileName);
+}
+
+
+/*
+ * ===========================================================================
+ * ZipEntry::CentralDirEntry
+ * ===========================================================================
+ */
+
+/*
+ * Read the central dir entry that appears next in the file.
+ *
+ * On entry, "fp" should be positioned on the signature bytes for the
+ * entry. On exit, "fp" will point at the signature word for the next
+ * entry or for the EOCD.
+ */
+status_t ZipEntry::CentralDirEntry::read(FILE* fp)
+{
+ status_t result = NO_ERROR;
+ unsigned char buf[kCDELen];
+
+ /* no re-use */
+ assert(mFileName == NULL);
+ assert(mExtraField == NULL);
+ assert(mFileComment == NULL);
+
+ if (fread(buf, 1, kCDELen, fp) != kCDELen) {
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+
+ if (ZipEntry::getLongLE(&buf[0x00]) != kSignature) {
+ LOGD("Whoops: didn't find expected signature\n");
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+
+ mVersionMadeBy = ZipEntry::getShortLE(&buf[0x04]);
+ mVersionToExtract = ZipEntry::getShortLE(&buf[0x06]);
+ mGPBitFlag = ZipEntry::getShortLE(&buf[0x08]);
+ mCompressionMethod = ZipEntry::getShortLE(&buf[0x0a]);
+ mLastModFileTime = ZipEntry::getShortLE(&buf[0x0c]);
+ mLastModFileDate = ZipEntry::getShortLE(&buf[0x0e]);
+ mCRC32 = ZipEntry::getLongLE(&buf[0x10]);
+ mCompressedSize = ZipEntry::getLongLE(&buf[0x14]);
+ mUncompressedSize = ZipEntry::getLongLE(&buf[0x18]);
+ mFileNameLength = ZipEntry::getShortLE(&buf[0x1c]);
+ mExtraFieldLength = ZipEntry::getShortLE(&buf[0x1e]);
+ mFileCommentLength = ZipEntry::getShortLE(&buf[0x20]);
+ mDiskNumberStart = ZipEntry::getShortLE(&buf[0x22]);
+ mInternalAttrs = ZipEntry::getShortLE(&buf[0x24]);
+ mExternalAttrs = ZipEntry::getLongLE(&buf[0x26]);
+ mLocalHeaderRelOffset = ZipEntry::getLongLE(&buf[0x2a]);
+
+ // TODO: validate sizes and offsets
+
+ /* grab filename */
+ if (mFileNameLength != 0) {
+ mFileName = new unsigned char[mFileNameLength+1];
+ if (mFileName == NULL) {
+ result = NO_MEMORY;
+ goto bail;
+ }
+ if (fread(mFileName, 1, mFileNameLength, fp) != mFileNameLength) {
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+ mFileName[mFileNameLength] = '\0';
+ }
+
+ /* read "extra field" */
+ if (mExtraFieldLength != 0) {
+ mExtraField = new unsigned char[mExtraFieldLength+1];
+ if (mExtraField == NULL) {
+ result = NO_MEMORY;
+ goto bail;
+ }
+ if (fread(mExtraField, 1, mExtraFieldLength, fp) != mExtraFieldLength) {
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+ mExtraField[mExtraFieldLength] = '\0';
+ }
+
+
+ /* grab comment, if any */
+ if (mFileCommentLength != 0) {
+ mFileComment = new unsigned char[mFileCommentLength+1];
+ if (mFileComment == NULL) {
+ result = NO_MEMORY;
+ goto bail;
+ }
+ if (fread(mFileComment, 1, mFileCommentLength, fp) != mFileCommentLength)
+ {
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+ mFileComment[mFileCommentLength] = '\0';
+ }
+
+bail:
+ return result;
+}
+
+/*
+ * Write a central dir entry.
+ */
+status_t ZipEntry::CentralDirEntry::write(FILE* fp)
+{
+ unsigned char buf[kCDELen];
+
+ ZipEntry::putLongLE(&buf[0x00], kSignature);
+ ZipEntry::putShortLE(&buf[0x04], mVersionMadeBy);
+ ZipEntry::putShortLE(&buf[0x06], mVersionToExtract);
+ ZipEntry::putShortLE(&buf[0x08], mGPBitFlag);
+ ZipEntry::putShortLE(&buf[0x0a], mCompressionMethod);
+ ZipEntry::putShortLE(&buf[0x0c], mLastModFileTime);
+ ZipEntry::putShortLE(&buf[0x0e], mLastModFileDate);
+ ZipEntry::putLongLE(&buf[0x10], mCRC32);
+ ZipEntry::putLongLE(&buf[0x14], mCompressedSize);
+ ZipEntry::putLongLE(&buf[0x18], mUncompressedSize);
+ ZipEntry::putShortLE(&buf[0x1c], mFileNameLength);
+ ZipEntry::putShortLE(&buf[0x1e], mExtraFieldLength);
+ ZipEntry::putShortLE(&buf[0x20], mFileCommentLength);
+ ZipEntry::putShortLE(&buf[0x22], mDiskNumberStart);
+ ZipEntry::putShortLE(&buf[0x24], mInternalAttrs);
+ ZipEntry::putLongLE(&buf[0x26], mExternalAttrs);
+ ZipEntry::putLongLE(&buf[0x2a], mLocalHeaderRelOffset);
+
+ if (fwrite(buf, 1, kCDELen, fp) != kCDELen)
+ return UNKNOWN_ERROR;
+
+ /* write filename */
+ if (mFileNameLength != 0) {
+ if (fwrite(mFileName, 1, mFileNameLength, fp) != mFileNameLength)
+ return UNKNOWN_ERROR;
+ }
+
+ /* write "extra field" */
+ if (mExtraFieldLength != 0) {
+ if (fwrite(mExtraField, 1, mExtraFieldLength, fp) != mExtraFieldLength)
+ return UNKNOWN_ERROR;
+ }
+
+ /* write comment */
+ if (mFileCommentLength != 0) {
+ if (fwrite(mFileComment, 1, mFileCommentLength, fp) != mFileCommentLength)
+ return UNKNOWN_ERROR;
+ }
+
+ return NO_ERROR;
+}
+
+/*
+ * Dump the contents of a CentralDirEntry object.
+ */
+void ZipEntry::CentralDirEntry::dump(void) const
+{
+ LOGD(" CentralDirEntry contents:\n");
+ LOGD(" versMadeBy=%u versToExt=%u gpBits=0x%04x compression=%u\n",
+ mVersionMadeBy, mVersionToExtract, mGPBitFlag, mCompressionMethod);
+ LOGD(" modTime=0x%04x modDate=0x%04x crc32=0x%08lx\n",
+ mLastModFileTime, mLastModFileDate, mCRC32);
+ LOGD(" compressedSize=%lu uncompressedSize=%lu\n",
+ mCompressedSize, mUncompressedSize);
+ LOGD(" filenameLen=%u extraLen=%u commentLen=%u\n",
+ mFileNameLength, mExtraFieldLength, mFileCommentLength);
+ LOGD(" diskNumStart=%u intAttr=0x%04x extAttr=0x%08lx relOffset=%lu\n",
+ mDiskNumberStart, mInternalAttrs, mExternalAttrs,
+ mLocalHeaderRelOffset);
+
+ if (mFileName != NULL)
+ LOGD(" filename: '%s'\n", mFileName);
+ if (mFileComment != NULL)
+ LOGD(" comment: '%s'\n", mFileComment);
+}
+
diff --git a/tools/zipalign/ZipEntry.h b/tools/zipalign/ZipEntry.h
new file mode 100644
index 0000000..7f721b4
--- /dev/null
+++ b/tools/zipalign/ZipEntry.h
@@ -0,0 +1,345 @@
+/*
+ * Copyright (C) 2006 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// Zip archive entries.
+//
+// The ZipEntry class is tightly meshed with the ZipFile class.
+//
+#ifndef __LIBS_ZIPENTRY_H
+#define __LIBS_ZIPENTRY_H
+
+#include <utils/Errors.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+
+namespace android {
+
+class ZipFile;
+
+/*
+ * ZipEntry objects represent a single entry in a Zip archive.
+ *
+ * You can use one of these to get or set information about an entry, but
+ * there are no functions here for accessing the data itself. (We could
+ * tuck a pointer to the ZipFile in here for convenience, but that raises
+ * the likelihood of using ZipEntry objects after discarding the ZipFile.)
+ *
+ * File information is stored in two places: next to the file data (the Local
+ * File Header, and possibly a Data Descriptor), and at the end of the file
+ * (the Central Directory Entry). The two must be kept in sync.
+ */
+class ZipEntry {
+public:
+ friend class ZipFile;
+
+ ZipEntry(void)
+ : mDeleted(false), mMarked(false)
+ {}
+ ~ZipEntry(void) {}
+
+ /*
+ * Returns "true" if the data is compressed.
+ */
+ bool isCompressed(void) const {
+ return mCDE.mCompressionMethod != kCompressStored;
+ }
+ int getCompressionMethod(void) const { return mCDE.mCompressionMethod; }
+
+ /*
+ * Return the uncompressed length.
+ */
+ off_t getUncompressedLen(void) const { return mCDE.mUncompressedSize; }
+
+ /*
+ * Return the compressed length. For uncompressed data, this returns
+ * the same thing as getUncompresesdLen().
+ */
+ off_t getCompressedLen(void) const { return mCDE.mCompressedSize; }
+
+ /*
+ * Return the absolute file offset of the start of the compressed or
+ * uncompressed data.
+ */
+ off_t getFileOffset(void) const {
+ return mCDE.mLocalHeaderRelOffset +
+ LocalFileHeader::kLFHLen +
+ mLFH.mFileNameLength +
+ mLFH.mExtraFieldLength;
+ }
+
+ /*
+ * Return the data CRC.
+ */
+ unsigned long getCRC32(void) const { return mCDE.mCRC32; }
+
+ /*
+ * Return file modification time in UNIX seconds-since-epoch.
+ */
+ time_t getModWhen(void) const;
+
+ /*
+ * Return the archived file name.
+ */
+ const char* getFileName(void) const { return (const char*) mCDE.mFileName; }
+
+ /*
+ * Application-defined "mark". Can be useful when synchronizing the
+ * contents of an archive with contents on disk.
+ */
+ bool getMarked(void) const { return mMarked; }
+ void setMarked(bool val) { mMarked = val; }
+
+ /*
+ * Some basic functions for raw data manipulation. "LE" means
+ * Little Endian.
+ */
+ static inline unsigned short getShortLE(const unsigned char* buf) {
+ return buf[0] | (buf[1] << 8);
+ }
+ static inline unsigned long getLongLE(const unsigned char* buf) {
+ return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
+ }
+ static inline void putShortLE(unsigned char* buf, short val) {
+ buf[0] = (unsigned char) val;
+ buf[1] = (unsigned char) (val >> 8);
+ }
+ static inline void putLongLE(unsigned char* buf, long val) {
+ buf[0] = (unsigned char) val;
+ buf[1] = (unsigned char) (val >> 8);
+ buf[2] = (unsigned char) (val >> 16);
+ buf[3] = (unsigned char) (val >> 24);
+ }
+
+ /* defined for Zip archives */
+ enum {
+ kCompressStored = 0, // no compression
+ // shrunk = 1,
+ // reduced 1 = 2,
+ // reduced 2 = 3,
+ // reduced 3 = 4,
+ // reduced 4 = 5,
+ // imploded = 6,
+ // tokenized = 7,
+ kCompressDeflated = 8, // standard deflate
+ // Deflate64 = 9,
+ // lib imploded = 10,
+ // reserved = 11,
+ // bzip2 = 12,
+ };
+
+ /*
+ * Deletion flag. If set, the entry will be removed on the next
+ * call to "flush".
+ */
+ bool getDeleted(void) const { return mDeleted; }
+
+protected:
+ /*
+ * Initialize the structure from the file, which is pointing at
+ * our Central Directory entry.
+ */
+ status_t initFromCDE(FILE* fp);
+
+ /*
+ * Initialize the structure for a new file. We need the filename
+ * and comment so that we can properly size the LFH area. The
+ * filename is mandatory, the comment is optional.
+ */
+ void initNew(const char* fileName, const char* comment);
+
+ /*
+ * Initialize the structure with the contents of a ZipEntry from
+ * another file.
+ */
+ status_t initFromExternal(const ZipFile* pZipFile, const ZipEntry* pEntry);
+
+ /*
+ * Add some pad bytes to the LFH. We do this by adding or resizing
+ * the "extra" field.
+ */
+ status_t addPadding(int padding);
+
+ /*
+ * Set information about the data for this entry.
+ */
+ void setDataInfo(long uncompLen, long compLen, unsigned long crc32,
+ int compressionMethod);
+
+ /*
+ * Set the modification date.
+ */
+ void setModWhen(time_t when);
+
+ /*
+ * Return the offset of the local file header.
+ */
+ off_t getLFHOffset(void) const { return mCDE.mLocalHeaderRelOffset; }
+
+ /*
+ * Set the offset of the local file header, relative to the start of
+ * the current file.
+ */
+ void setLFHOffset(off_t offset) {
+ mCDE.mLocalHeaderRelOffset = (long) offset;
+ }
+
+ /* mark for deletion; used by ZipFile::remove() */
+ void setDeleted(void) { mDeleted = true; }
+
+private:
+ /* these are private and not defined */
+ ZipEntry(const ZipEntry& src);
+ ZipEntry& operator=(const ZipEntry& src);
+
+ /* returns "true" if the CDE and the LFH agree */
+ bool compareHeaders(void) const;
+ void copyCDEtoLFH(void);
+
+ bool mDeleted; // set if entry is pending deletion
+ bool mMarked; // app-defined marker
+
+ /*
+ * Every entry in the Zip archive starts off with one of these.
+ */
+ class LocalFileHeader {
+ public:
+ LocalFileHeader(void) :
+ mVersionToExtract(0),
+ mGPBitFlag(0),
+ mCompressionMethod(0),
+ mLastModFileTime(0),
+ mLastModFileDate(0),
+ mCRC32(0),
+ mCompressedSize(0),
+ mUncompressedSize(0),
+ mFileNameLength(0),
+ mExtraFieldLength(0),
+ mFileName(NULL),
+ mExtraField(NULL)
+ {}
+ virtual ~LocalFileHeader(void) {
+ delete[] mFileName;
+ delete[] mExtraField;
+ }
+
+ status_t read(FILE* fp);
+ status_t write(FILE* fp);
+
+ // unsigned long mSignature;
+ unsigned short mVersionToExtract;
+ unsigned short mGPBitFlag;
+ unsigned short mCompressionMethod;
+ unsigned short mLastModFileTime;
+ unsigned short mLastModFileDate;
+ unsigned long mCRC32;
+ unsigned long mCompressedSize;
+ unsigned long mUncompressedSize;
+ unsigned short mFileNameLength;
+ unsigned short mExtraFieldLength;
+ unsigned char* mFileName;
+ unsigned char* mExtraField;
+
+ enum {
+ kSignature = 0x04034b50,
+ kLFHLen = 30, // LocalFileHdr len, excl. var fields
+ };
+
+ void dump(void) const;
+ };
+
+ /*
+ * Every entry in the Zip archive has one of these in the "central
+ * directory" at the end of the file.
+ */
+ class CentralDirEntry {
+ public:
+ CentralDirEntry(void) :
+ mVersionMadeBy(0),
+ mVersionToExtract(0),
+ mGPBitFlag(0),
+ mCompressionMethod(0),
+ mLastModFileTime(0),
+ mLastModFileDate(0),
+ mCRC32(0),
+ mCompressedSize(0),
+ mUncompressedSize(0),
+ mFileNameLength(0),
+ mExtraFieldLength(0),
+ mFileCommentLength(0),
+ mDiskNumberStart(0),
+ mInternalAttrs(0),
+ mExternalAttrs(0),
+ mLocalHeaderRelOffset(0),
+ mFileName(NULL),
+ mExtraField(NULL),
+ mFileComment(NULL)
+ {}
+ virtual ~CentralDirEntry(void) {
+ delete[] mFileName;
+ delete[] mExtraField;
+ delete[] mFileComment;
+ }
+
+ status_t read(FILE* fp);
+ status_t write(FILE* fp);
+
+ // unsigned long mSignature;
+ unsigned short mVersionMadeBy;
+ unsigned short mVersionToExtract;
+ unsigned short mGPBitFlag;
+ unsigned short mCompressionMethod;
+ unsigned short mLastModFileTime;
+ unsigned short mLastModFileDate;
+ unsigned long mCRC32;
+ unsigned long mCompressedSize;
+ unsigned long mUncompressedSize;
+ unsigned short mFileNameLength;
+ unsigned short mExtraFieldLength;
+ unsigned short mFileCommentLength;
+ unsigned short mDiskNumberStart;
+ unsigned short mInternalAttrs;
+ unsigned long mExternalAttrs;
+ unsigned long mLocalHeaderRelOffset;
+ unsigned char* mFileName;
+ unsigned char* mExtraField;
+ unsigned char* mFileComment;
+
+ void dump(void) const;
+
+ enum {
+ kSignature = 0x02014b50,
+ kCDELen = 46, // CentralDirEnt len, excl. var fields
+ };
+ };
+
+ enum {
+ //kDataDescriptorSignature = 0x08074b50, // currently unused
+ kDataDescriptorLen = 16, // four 32-bit fields
+
+ kDefaultVersion = 20, // need deflate, nothing much else
+ kDefaultMadeBy = 0x0317, // 03=UNIX, 17=spec v2.3
+ kUsesDataDescr = 0x0008, // GPBitFlag bit 3
+ };
+
+ LocalFileHeader mLFH;
+ CentralDirEntry mCDE;
+};
+
+}; // namespace android
+
+#endif // __LIBS_ZIPENTRY_H
diff --git a/tools/zipalign/ZipFile.cpp b/tools/zipalign/ZipFile.cpp
new file mode 100644
index 0000000..62c9383
--- /dev/null
+++ b/tools/zipalign/ZipFile.cpp
@@ -0,0 +1,1297 @@
+/*
+ * Copyright (C) 2006 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// Access to Zip archives.
+//
+
+#define LOG_TAG "zip"
+
+#include <utils/ZipUtils.h>
+#include <utils/Log.h>
+
+#include "ZipFile.h"
+
+#include <zlib.h>
+#define DEF_MEM_LEVEL 8 // normally in zutil.h?
+
+#include <memory.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <assert.h>
+
+using namespace android;
+
+/*
+ * Some environments require the "b", some choke on it.
+ */
+#define FILE_OPEN_RO "rb"
+#define FILE_OPEN_RW "r+b"
+#define FILE_OPEN_RW_CREATE "w+b"
+
+/* should live somewhere else? */
+static status_t errnoToStatus(int err)
+{
+ if (err == ENOENT)
+ return NAME_NOT_FOUND;
+ else if (err == EACCES)
+ return PERMISSION_DENIED;
+ else
+ return UNKNOWN_ERROR;
+}
+
+/*
+ * Open a file and parse its guts.
+ */
+status_t ZipFile::open(const char* zipFileName, int flags)
+{
+ bool newArchive = false;
+
+ assert(mZipFp == NULL); // no reopen
+
+ if ((flags & kOpenTruncate))
+ flags |= kOpenCreate; // trunc implies create
+
+ if ((flags & kOpenReadOnly) && (flags & kOpenReadWrite))
+ return INVALID_OPERATION; // not both
+ if (!((flags & kOpenReadOnly) || (flags & kOpenReadWrite)))
+ return INVALID_OPERATION; // not neither
+ if ((flags & kOpenCreate) && !(flags & kOpenReadWrite))
+ return INVALID_OPERATION; // create requires write
+
+ if (flags & kOpenTruncate) {
+ newArchive = true;
+ } else {
+ newArchive = (access(zipFileName, F_OK) != 0);
+ if (!(flags & kOpenCreate) && newArchive) {
+ /* not creating, must already exist */
+ LOGD("File %s does not exist", zipFileName);
+ return NAME_NOT_FOUND;
+ }
+ }
+
+ /* open the file */
+ const char* openflags;
+ if (flags & kOpenReadWrite) {
+ if (newArchive)
+ openflags = FILE_OPEN_RW_CREATE;
+ else
+ openflags = FILE_OPEN_RW;
+ } else {
+ openflags = FILE_OPEN_RO;
+ }
+ mZipFp = fopen(zipFileName, openflags);
+ if (mZipFp == NULL) {
+ int err = errno;
+ LOGD("fopen failed: %d\n", err);
+ return errnoToStatus(err);
+ }
+
+ status_t result;
+ if (!newArchive) {
+ /*
+ * Load the central directory. If that fails, then this probably
+ * isn't a Zip archive.
+ */
+ result = readCentralDir();
+ } else {
+ /*
+ * Newly-created. The EndOfCentralDir constructor actually
+ * sets everything to be the way we want it (all zeroes). We
+ * set mNeedCDRewrite so that we create *something* if the
+ * caller doesn't add any files. (We could also just unlink
+ * the file if it's brand new and nothing was added, but that's
+ * probably doing more than we really should -- the user might
+ * have a need for empty zip files.)
+ */
+ mNeedCDRewrite = true;
+ result = NO_ERROR;
+ }
+
+ if (flags & kOpenReadOnly)
+ mReadOnly = true;
+ else
+ assert(!mReadOnly);
+
+ return result;
+}
+
+/*
+ * Return the Nth entry in the archive.
+ */
+ZipEntry* ZipFile::getEntryByIndex(int idx) const
+{
+ if (idx < 0 || idx >= (int) mEntries.size())
+ return NULL;
+
+ return mEntries[idx];
+}
+
+/*
+ * Find an entry by name.
+ */
+ZipEntry* ZipFile::getEntryByName(const char* fileName) const
+{
+ /*
+ * Do a stupid linear string-compare search.
+ *
+ * There are various ways to speed this up, especially since it's rare
+ * to intermingle changes to the archive with "get by name" calls. We
+ * don't want to sort the mEntries vector itself, however, because
+ * it's used to recreate the Central Directory.
+ *
+ * (Hash table works, parallel list of pointers in sorted order is good.)
+ */
+ int idx;
+
+ for (idx = mEntries.size()-1; idx >= 0; idx--) {
+ ZipEntry* pEntry = mEntries[idx];
+ if (!pEntry->getDeleted() &&
+ strcmp(fileName, pEntry->getFileName()) == 0)
+ {
+ return pEntry;
+ }
+ }
+
+ return NULL;
+}
+
+/*
+ * Empty the mEntries vector.
+ */
+void ZipFile::discardEntries(void)
+{
+ int count = mEntries.size();
+
+ while (--count >= 0)
+ delete mEntries[count];
+
+ mEntries.clear();
+}
+
+
+/*
+ * Find the central directory and read the contents.
+ *
+ * The fun thing about ZIP archives is that they may or may not be
+ * readable from start to end. In some cases, notably for archives
+ * that were written to stdout, the only length information is in the
+ * central directory at the end of the file.
+ *
+ * Of course, the central directory can be followed by a variable-length
+ * comment field, so we have to scan through it backwards. The comment
+ * is at most 64K, plus we have 18 bytes for the end-of-central-dir stuff
+ * itself, plus apparently sometimes people throw random junk on the end
+ * just for the fun of it.
+ *
+ * This is all a little wobbly. If the wrong value ends up in the EOCD
+ * area, we're hosed. This appears to be the way that everbody handles
+ * it though, so we're in pretty good company if this fails.
+ */
+status_t ZipFile::readCentralDir(void)
+{
+ status_t result = NO_ERROR;
+ unsigned char* buf = NULL;
+ off_t fileLength, seekStart;
+ long readAmount;
+ int i;
+
+ fseek(mZipFp, 0, SEEK_END);
+ fileLength = ftell(mZipFp);
+ rewind(mZipFp);
+
+ /* too small to be a ZIP archive? */
+ if (fileLength < EndOfCentralDir::kEOCDLen) {
+ LOGD("Length is %ld -- too small\n", (long)fileLength);
+ result = INVALID_OPERATION;
+ goto bail;
+ }
+
+ buf = new unsigned char[EndOfCentralDir::kMaxEOCDSearch];
+ if (buf == NULL) {
+ LOGD("Failure allocating %d bytes for EOCD search",
+ EndOfCentralDir::kMaxEOCDSearch);
+ result = NO_MEMORY;
+ goto bail;
+ }
+
+ if (fileLength > EndOfCentralDir::kMaxEOCDSearch) {
+ seekStart = fileLength - EndOfCentralDir::kMaxEOCDSearch;
+ readAmount = EndOfCentralDir::kMaxEOCDSearch;
+ } else {
+ seekStart = 0;
+ readAmount = (long) fileLength;
+ }
+ if (fseek(mZipFp, seekStart, SEEK_SET) != 0) {
+ LOGD("Failure seeking to end of zip at %ld", (long) seekStart);
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+
+ /* read the last part of the file into the buffer */
+ if (fread(buf, 1, readAmount, mZipFp) != (size_t) readAmount) {
+ LOGD("short file? wanted %ld\n", readAmount);
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+
+ /* find the end-of-central-dir magic */
+ for (i = readAmount - 4; i >= 0; i--) {
+ if (buf[i] == 0x50 &&
+ ZipEntry::getLongLE(&buf[i]) == EndOfCentralDir::kSignature)
+ {
+ LOGV("+++ Found EOCD at buf+%d\n", i);
+ break;
+ }
+ }
+ if (i < 0) {
+ LOGD("EOCD not found, not Zip\n");
+ result = INVALID_OPERATION;
+ goto bail;
+ }
+
+ /* extract eocd values */
+ result = mEOCD.readBuf(buf + i, readAmount - i);
+ if (result != NO_ERROR) {
+ LOGD("Failure reading %ld bytes of EOCD values", readAmount - i);
+ goto bail;
+ }
+ //mEOCD.dump();
+
+ if (mEOCD.mDiskNumber != 0 || mEOCD.mDiskWithCentralDir != 0 ||
+ mEOCD.mNumEntries != mEOCD.mTotalNumEntries)
+ {
+ LOGD("Archive spanning not supported\n");
+ result = INVALID_OPERATION;
+ goto bail;
+ }
+
+ /*
+ * So far so good. "mCentralDirSize" is the size in bytes of the
+ * central directory, so we can just seek back that far to find it.
+ * We can also seek forward mCentralDirOffset bytes from the
+ * start of the file.
+ *
+ * We're not guaranteed to have the rest of the central dir in the
+ * buffer, nor are we guaranteed that the central dir will have any
+ * sort of convenient size. We need to skip to the start of it and
+ * read the header, then the other goodies.
+ *
+ * The only thing we really need right now is the file comment, which
+ * we're hoping to preserve.
+ */
+ if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0) {
+ LOGD("Failure seeking to central dir offset %ld\n",
+ mEOCD.mCentralDirOffset);
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+
+ /*
+ * Loop through and read the central dir entries.
+ */
+ LOGV("Scanning %d entries...\n", mEOCD.mTotalNumEntries);
+ int entry;
+ for (entry = 0; entry < mEOCD.mTotalNumEntries; entry++) {
+ ZipEntry* pEntry = new ZipEntry;
+
+ result = pEntry->initFromCDE(mZipFp);
+ if (result != NO_ERROR) {
+ LOGD("initFromCDE failed\n");
+ delete pEntry;
+ goto bail;
+ }
+
+ mEntries.add(pEntry);
+ }
+
+
+ /*
+ * If all went well, we should now be back at the EOCD.
+ */
+ {
+ unsigned char checkBuf[4];
+ if (fread(checkBuf, 1, 4, mZipFp) != 4) {
+ LOGD("EOCD check read failed\n");
+ result = INVALID_OPERATION;
+ goto bail;
+ }
+ if (ZipEntry::getLongLE(checkBuf) != EndOfCentralDir::kSignature) {
+ LOGD("EOCD read check failed\n");
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+ LOGV("+++ EOCD read check passed\n");
+ }
+
+bail:
+ delete[] buf;
+ return result;
+}
+
+
+/*
+ * Add a new file to the archive.
+ *
+ * This requires creating and populating a ZipEntry structure, and copying
+ * the data into the file at the appropriate position. The "appropriate
+ * position" is the current location of the central directory, which we
+ * casually overwrite (we can put it back later).
+ *
+ * If we were concerned about safety, we would want to make all changes
+ * in a temp file and then overwrite the original after everything was
+ * safely written. Not really a concern for us.
+ */
+status_t ZipFile::addCommon(const char* fileName, const void* data, size_t size,
+ const char* storageName, int sourceType, int compressionMethod,
+ ZipEntry** ppEntry)
+{
+ ZipEntry* pEntry = NULL;
+ status_t result = NO_ERROR;
+ long lfhPosn, startPosn, endPosn, uncompressedLen;
+ FILE* inputFp = NULL;
+ unsigned long crc;
+ time_t modWhen;
+
+ if (mReadOnly)
+ return INVALID_OPERATION;
+
+ assert(compressionMethod == ZipEntry::kCompressDeflated ||
+ compressionMethod == ZipEntry::kCompressStored);
+
+ /* make sure we're in a reasonable state */
+ assert(mZipFp != NULL);
+ assert(mEntries.size() == mEOCD.mTotalNumEntries);
+
+ /* make sure it doesn't already exist */
+ if (getEntryByName(storageName) != NULL)
+ return ALREADY_EXISTS;
+
+ if (!data) {
+ inputFp = fopen(fileName, FILE_OPEN_RO);
+ if (inputFp == NULL)
+ return errnoToStatus(errno);
+ }
+
+ if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0) {
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+
+ pEntry = new ZipEntry;
+ pEntry->initNew(storageName, NULL);
+
+ /*
+ * From here on out, failures are more interesting.
+ */
+ mNeedCDRewrite = true;
+
+ /*
+ * Write the LFH, even though it's still mostly blank. We need it
+ * as a place-holder. In theory the LFH isn't necessary, but in
+ * practice some utilities demand it.
+ */
+ lfhPosn = ftell(mZipFp);
+ pEntry->mLFH.write(mZipFp);
+ startPosn = ftell(mZipFp);
+
+ /*
+ * Copy the data in, possibly compressing it as we go.
+ */
+ if (sourceType == ZipEntry::kCompressStored) {
+ if (compressionMethod == ZipEntry::kCompressDeflated) {
+ bool failed = false;
+ result = compressFpToFp(mZipFp, inputFp, data, size, &crc);
+ if (result != NO_ERROR) {
+ LOGD("compression failed, storing\n");
+ failed = true;
+ } else {
+ /*
+ * Make sure it has compressed "enough". This probably ought
+ * to be set through an API call, but I don't expect our
+ * criteria to change over time.
+ */
+ long src = inputFp ? ftell(inputFp) : size;
+ long dst = ftell(mZipFp) - startPosn;
+ if (dst + (dst / 10) > src) {
+ LOGD("insufficient compression (src=%ld dst=%ld), storing\n",
+ src, dst);
+ failed = true;
+ }
+ }
+
+ if (failed) {
+ compressionMethod = ZipEntry::kCompressStored;
+ if (inputFp) rewind(inputFp);
+ fseek(mZipFp, startPosn, SEEK_SET);
+ /* fall through to kCompressStored case */
+ }
+ }
+ /* handle "no compression" request, or failed compression from above */
+ if (compressionMethod == ZipEntry::kCompressStored) {
+ if (inputFp) {
+ result = copyFpToFp(mZipFp, inputFp, &crc);
+ } else {
+ result = copyDataToFp(mZipFp, data, size, &crc);
+ }
+ if (result != NO_ERROR) {
+ // don't need to truncate; happens in CDE rewrite
+ LOGD("failed copying data in\n");
+ goto bail;
+ }
+ }
+
+ // currently seeked to end of file
+ uncompressedLen = inputFp ? ftell(inputFp) : size;
+ } else if (sourceType == ZipEntry::kCompressDeflated) {
+ /* we should support uncompressed-from-compressed, but it's not
+ * important right now */
+ assert(compressionMethod == ZipEntry::kCompressDeflated);
+
+ bool scanResult;
+ int method;
+ long compressedLen;
+
+ scanResult = ZipUtils::examineGzip(inputFp, &method, &uncompressedLen,
+ &compressedLen, &crc);
+ if (!scanResult || method != ZipEntry::kCompressDeflated) {
+ LOGD("this isn't a deflated gzip file?");
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+
+ result = copyPartialFpToFp(mZipFp, inputFp, compressedLen, NULL);
+ if (result != NO_ERROR) {
+ LOGD("failed copying gzip data in\n");
+ goto bail;
+ }
+ } else {
+ assert(false);
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+
+ /*
+ * We could write the "Data Descriptor", but there doesn't seem to
+ * be any point since we're going to go back and write the LFH.
+ *
+ * Update file offsets.
+ */
+ endPosn = ftell(mZipFp); // seeked to end of compressed data
+
+ /*
+ * Success! Fill out new values.
+ */
+ pEntry->setDataInfo(uncompressedLen, endPosn - startPosn, crc,
+ compressionMethod);
+ modWhen = getModTime(inputFp ? fileno(inputFp) : fileno(mZipFp));
+ pEntry->setModWhen(modWhen);
+ pEntry->setLFHOffset(lfhPosn);
+ mEOCD.mNumEntries++;
+ mEOCD.mTotalNumEntries++;
+ mEOCD.mCentralDirSize = 0; // mark invalid; set by flush()
+ mEOCD.mCentralDirOffset = endPosn;
+
+ /*
+ * Go back and write the LFH.
+ */
+ if (fseek(mZipFp, lfhPosn, SEEK_SET) != 0) {
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+ pEntry->mLFH.write(mZipFp);
+
+ /*
+ * Add pEntry to the list.
+ */
+ mEntries.add(pEntry);
+ if (ppEntry != NULL)
+ *ppEntry = pEntry;
+ pEntry = NULL;
+
+bail:
+ if (inputFp != NULL)
+ fclose(inputFp);
+ delete pEntry;
+ return result;
+}
+
+/*
+ * Add an entry by copying it from another zip file. If "padding" is
+ * nonzero, the specified number of bytes will be added to the "extra"
+ * field in the header.
+ *
+ * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
+ */
+status_t ZipFile::add(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
+ int padding, ZipEntry** ppEntry)
+{
+ ZipEntry* pEntry = NULL;
+ status_t result;
+ long lfhPosn, endPosn;
+
+ if (mReadOnly)
+ return INVALID_OPERATION;
+
+ /* make sure we're in a reasonable state */
+ assert(mZipFp != NULL);
+ assert(mEntries.size() == mEOCD.mTotalNumEntries);
+
+ if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0) {
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+
+ pEntry = new ZipEntry;
+ if (pEntry == NULL) {
+ result = NO_MEMORY;
+ goto bail;
+ }
+
+ result = pEntry->initFromExternal(pSourceZip, pSourceEntry);
+ if (result != NO_ERROR)
+ goto bail;
+ if (padding != 0) {
+ result = pEntry->addPadding(padding);
+ if (result != NO_ERROR)
+ goto bail;
+ }
+
+ /*
+ * From here on out, failures are more interesting.
+ */
+ mNeedCDRewrite = true;
+
+ /*
+ * Write the LFH. Since we're not recompressing the data, we already
+ * have all of the fields filled out.
+ */
+ lfhPosn = ftell(mZipFp);
+ pEntry->mLFH.write(mZipFp);
+
+ /*
+ * Copy the data over.
+ *
+ * If the "has data descriptor" flag is set, we want to copy the DD
+ * fields as well. This is a fixed-size area immediately following
+ * the data.
+ */
+ if (fseek(pSourceZip->mZipFp, pSourceEntry->getFileOffset(), SEEK_SET) != 0)
+ {
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+
+ off_t copyLen;
+ copyLen = pSourceEntry->getCompressedLen();
+ if ((pSourceEntry->mLFH.mGPBitFlag & ZipEntry::kUsesDataDescr) != 0)
+ copyLen += ZipEntry::kDataDescriptorLen;
+
+ if (copyPartialFpToFp(mZipFp, pSourceZip->mZipFp, copyLen, NULL)
+ != NO_ERROR)
+ {
+ LOGW("copy of '%s' failed\n", pEntry->mCDE.mFileName);
+ result = UNKNOWN_ERROR;
+ goto bail;
+ }
+
+ /*
+ * Update file offsets.
+ */
+ endPosn = ftell(mZipFp);
+
+ /*
+ * Success! Fill out new values.
+ */
+ pEntry->setLFHOffset(lfhPosn); // sets mCDE.mLocalHeaderRelOffset
+ mEOCD.mNumEntries++;
+ mEOCD.mTotalNumEntries++;
+ mEOCD.mCentralDirSize = 0; // mark invalid; set by flush()
+ mEOCD.mCentralDirOffset = endPosn;
+
+ /*
+ * Add pEntry to the list.
+ */
+ mEntries.add(pEntry);
+ if (ppEntry != NULL)
+ *ppEntry = pEntry;
+ pEntry = NULL;
+
+ result = NO_ERROR;
+
+bail:
+ delete pEntry;
+ return result;
+}
+
+/*
+ * Copy all of the bytes in "src" to "dst".
+ *
+ * On exit, "srcFp" will be seeked to the end of the file, and "dstFp"
+ * will be seeked immediately past the data.
+ */
+status_t ZipFile::copyFpToFp(FILE* dstFp, FILE* srcFp, unsigned long* pCRC32)
+{
+ unsigned char tmpBuf[32768];
+ size_t count;
+
+ *pCRC32 = crc32(0L, Z_NULL, 0);
+
+ while (1) {
+ count = fread(tmpBuf, 1, sizeof(tmpBuf), srcFp);
+ if (ferror(srcFp) || ferror(dstFp))
+ return errnoToStatus(errno);
+ if (count == 0)
+ break;
+
+ *pCRC32 = crc32(*pCRC32, tmpBuf, count);
+
+ if (fwrite(tmpBuf, 1, count, dstFp) != count) {
+ LOGD("fwrite %d bytes failed\n", (int) count);
+ return UNKNOWN_ERROR;
+ }
+ }
+
+ return NO_ERROR;
+}
+
+/*
+ * Copy all of the bytes in "src" to "dst".
+ *
+ * On exit, "dstFp" will be seeked immediately past the data.
+ */
+status_t ZipFile::copyDataToFp(FILE* dstFp,
+ const void* data, size_t size, unsigned long* pCRC32)
+{
+ size_t count;
+
+ *pCRC32 = crc32(0L, Z_NULL, 0);
+ if (size > 0) {
+ *pCRC32 = crc32(*pCRC32, (const unsigned char*)data, size);
+ if (fwrite(data, 1, size, dstFp) != size) {
+ LOGD("fwrite %d bytes failed\n", (int) size);
+ return UNKNOWN_ERROR;
+ }
+ }
+
+ return NO_ERROR;
+}
+
+/*
+ * Copy some of the bytes in "src" to "dst".
+ *
+ * If "pCRC32" is NULL, the CRC will not be computed.
+ *
+ * On exit, "srcFp" will be seeked to the end of the file, and "dstFp"
+ * will be seeked immediately past the data just written.
+ */
+status_t ZipFile::copyPartialFpToFp(FILE* dstFp, FILE* srcFp, long length,
+ unsigned long* pCRC32)
+{
+ unsigned char tmpBuf[32768];
+ size_t count;
+
+ if (pCRC32 != NULL)
+ *pCRC32 = crc32(0L, Z_NULL, 0);
+
+ while (length) {
+ long readSize;
+
+ readSize = sizeof(tmpBuf);
+ if (readSize > length)
+ readSize = length;
+
+ count = fread(tmpBuf, 1, readSize, srcFp);
+ if ((long) count != readSize) { // error or unexpected EOF
+ LOGD("fread %d bytes failed\n", (int) readSize);
+ return UNKNOWN_ERROR;
+ }
+
+ if (pCRC32 != NULL)
+ *pCRC32 = crc32(*pCRC32, tmpBuf, count);
+
+ if (fwrite(tmpBuf, 1, count, dstFp) != count) {
+ LOGD("fwrite %d bytes failed\n", (int) count);
+ return UNKNOWN_ERROR;
+ }
+
+ length -= readSize;
+ }
+
+ return NO_ERROR;
+}
+
+/*
+ * Compress all of the data in "srcFp" and write it to "dstFp".
+ *
+ * On exit, "srcFp" will be seeked to the end of the file, and "dstFp"
+ * will be seeked immediately past the compressed data.
+ */
+status_t ZipFile::compressFpToFp(FILE* dstFp, FILE* srcFp,
+ const void* data, size_t size, unsigned long* pCRC32)
+{
+ status_t result = NO_ERROR;
+ const size_t kBufSize = 32768;
+ unsigned char* inBuf = NULL;
+ unsigned char* outBuf = NULL;
+ z_stream zstream;
+ bool atEof = false; // no feof() aviailable yet
+ unsigned long crc;
+ int zerr;
+
+ /*
+ * Create an input buffer and an output buffer.
+ */
+ inBuf = new unsigned char[kBufSize];
+ outBuf = new unsigned char[kBufSize];
+ if (inBuf == NULL || outBuf == NULL) {
+ result = NO_MEMORY;
+ goto bail;
+ }
+
+ /*
+ * Initialize the zlib stream.
+ */
+ memset(&zstream, 0, sizeof(zstream));
+ zstream.zalloc = Z_NULL;
+ zstream.zfree = Z_NULL;
+ zstream.opaque = Z_NULL;
+ zstream.next_in = NULL;
+ zstream.avail_in = 0;
+ zstream.next_out = outBuf;
+ zstream.avail_out = kBufSize;
+ zstream.data_type = Z_UNKNOWN;
+
+ zerr = deflateInit2(&zstream, Z_BEST_COMPRESSION,
+ Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
+ if (zerr != Z_OK) {
+ result = UNKNOWN_ERROR;
+ if (zerr == Z_VERSION_ERROR) {
+ LOGE("Installed zlib is not compatible with linked version (%s)\n",
+ ZLIB_VERSION);
+ } else {
+ LOGD("Call to deflateInit2 failed (zerr=%d)\n", zerr);
+ }
+ goto bail;
+ }
+
+ crc = crc32(0L, Z_NULL, 0);
+
+ /*
+ * Loop while we have data.
+ */
+ do {
+ size_t getSize;
+ int flush;
+
+ /* only read if the input buffer is empty */
+ if (zstream.avail_in == 0 && !atEof) {
+ LOGV("+++ reading %d bytes\n", (int)kBufSize);
+ if (data) {
+ getSize = size > kBufSize ? kBufSize : size;
+ memcpy(inBuf, data, getSize);
+ data = ((const char*)data) + getSize;
+ size -= getSize;
+ } else {
+ getSize = fread(inBuf, 1, kBufSize, srcFp);
+ if (ferror(srcFp)) {
+ LOGD("deflate read failed (errno=%d)\n", errno);
+ goto z_bail;
+ }
+ }
+ if (getSize < kBufSize) {
+ LOGV("+++ got %d bytes, EOF reached\n",
+ (int)getSize);
+ atEof = true;
+ }
+
+ crc = crc32(crc, inBuf, getSize);
+
+ zstream.next_in = inBuf;
+ zstream.avail_in = getSize;
+ }
+
+ if (atEof)
+ flush = Z_FINISH; /* tell zlib that we're done */
+ else
+ flush = Z_NO_FLUSH; /* more to come! */
+
+ zerr = deflate(&zstream, flush);
+ if (zerr != Z_OK && zerr != Z_STREAM_END) {
+ LOGD("zlib deflate call failed (zerr=%d)\n", zerr);
+ result = UNKNOWN_ERROR;
+ goto z_bail;
+ }
+
+ /* write when we're full or when we're done */
+ if (zstream.avail_out == 0 ||
+ (zerr == Z_STREAM_END && zstream.avail_out != (uInt) kBufSize))
+ {
+ LOGV("+++ writing %d bytes\n", (int) (zstream.next_out - outBuf));
+ if (fwrite(outBuf, 1, zstream.next_out - outBuf, dstFp) !=
+ (size_t)(zstream.next_out - outBuf))
+ {
+ LOGD("write %d failed in deflate\n",
+ (int) (zstream.next_out - outBuf));
+ goto z_bail;
+ }
+
+ zstream.next_out = outBuf;
+ zstream.avail_out = kBufSize;
+ }
+ } while (zerr == Z_OK);
+
+ assert(zerr == Z_STREAM_END); /* other errors should've been caught */
+
+ *pCRC32 = crc;
+
+z_bail:
+ deflateEnd(&zstream); /* free up any allocated structures */
+
+bail:
+ delete[] inBuf;
+ delete[] outBuf;
+
+ return result;
+}
+
+/*
+ * Mark an entry as deleted.
+ *
+ * We will eventually need to crunch the file down, but if several files
+ * are being removed (perhaps as part of an "update" process) we can make
+ * things considerably faster by deferring the removal to "flush" time.
+ */
+status_t ZipFile::remove(ZipEntry* pEntry)
+{
+ /*
+ * Should verify that pEntry is actually part of this archive, and
+ * not some stray ZipEntry from a different file.
+ */
+
+ /* mark entry as deleted, and mark archive as dirty */
+ pEntry->setDeleted();
+ mNeedCDRewrite = true;
+ return NO_ERROR;
+}
+
+/*
+ * Flush any pending writes.
+ *
+ * In particular, this will crunch out deleted entries, and write the
+ * Central Directory and EOCD if we have stomped on them.
+ */
+status_t ZipFile::flush(void)
+{
+ status_t result = NO_ERROR;
+ long eocdPosn;
+ int i, count;
+
+ if (mReadOnly)
+ return INVALID_OPERATION;
+ if (!mNeedCDRewrite)
+ return NO_ERROR;
+
+ assert(mZipFp != NULL);
+
+ result = crunchArchive();
+ if (result != NO_ERROR)
+ return result;
+
+ if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0)
+ return UNKNOWN_ERROR;
+
+ count = mEntries.size();
+ for (i = 0; i < count; i++) {
+ ZipEntry* pEntry = mEntries[i];
+ pEntry->mCDE.write(mZipFp);
+ }
+
+ eocdPosn = ftell(mZipFp);
+ mEOCD.mCentralDirSize = eocdPosn - mEOCD.mCentralDirOffset;
+
+ mEOCD.write(mZipFp);
+
+ /*
+ * If we had some stuff bloat up during compression and get replaced
+ * with plain files, or if we deleted some entries, there's a lot
+ * of wasted space at the end of the file. Remove it now.
+ */
+ if (ftruncate(fileno(mZipFp), ftell(mZipFp)) != 0) {
+ LOGW("ftruncate failed %ld: %s\n", ftell(mZipFp), strerror(errno));
+ // not fatal
+ }
+
+ /* should we clear the "newly added" flag in all entries now? */
+
+ mNeedCDRewrite = false;
+ return NO_ERROR;
+}
+
+/*
+ * Crunch deleted files out of an archive by shifting the later files down.
+ *
+ * Because we're not using a temp file, we do the operation inside the
+ * current file.
+ */
+status_t ZipFile::crunchArchive(void)
+{
+ status_t result = NO_ERROR;
+ int i, count;
+ long delCount, adjust;
+
+#if 0
+ printf("CONTENTS:\n");
+ for (i = 0; i < (int) mEntries.size(); i++) {
+ printf(" %d: lfhOff=%ld del=%d\n",
+ i, mEntries[i]->getLFHOffset(), mEntries[i]->getDeleted());
+ }
+ printf(" END is %ld\n", (long) mEOCD.mCentralDirOffset);
+#endif
+
+ /*
+ * Roll through the set of files, shifting them as appropriate. We
+ * could probably get a slight performance improvement by sliding
+ * multiple files down at once (because we could use larger reads
+ * when operating on batches of small files), but it's not that useful.
+ */
+ count = mEntries.size();
+ delCount = adjust = 0;
+ for (i = 0; i < count; i++) {
+ ZipEntry* pEntry = mEntries[i];
+ long span;
+
+ if (pEntry->getLFHOffset() != 0) {
+ long nextOffset;
+
+ /* Get the length of this entry by finding the offset
+ * of the next entry. Directory entries don't have
+ * file offsets, so we need to find the next non-directory
+ * entry.
+ */
+ nextOffset = 0;
+ for (int ii = i+1; nextOffset == 0 && ii < count; ii++)
+ nextOffset = mEntries[ii]->getLFHOffset();
+ if (nextOffset == 0)
+ nextOffset = mEOCD.mCentralDirOffset;
+ span = nextOffset - pEntry->getLFHOffset();
+
+ assert(span >= ZipEntry::LocalFileHeader::kLFHLen);
+ } else {
+ /* This is a directory entry. It doesn't have
+ * any actual file contents, so there's no need to
+ * move anything.
+ */
+ span = 0;
+ }
+
+ //printf("+++ %d: off=%ld span=%ld del=%d [count=%d]\n",
+ // i, pEntry->getLFHOffset(), span, pEntry->getDeleted(), count);
+
+ if (pEntry->getDeleted()) {
+ adjust += span;
+ delCount++;
+
+ delete pEntry;
+ mEntries.removeAt(i);
+
+ /* adjust loop control */
+ count--;
+ i--;
+ } else if (span != 0 && adjust > 0) {
+ /* shuffle this entry back */
+ //printf("+++ Shuffling '%s' back %ld\n",
+ // pEntry->getFileName(), adjust);
+ result = filemove(mZipFp, pEntry->getLFHOffset() - adjust,
+ pEntry->getLFHOffset(), span);
+ if (result != NO_ERROR) {
+ /* this is why you use a temp file */
+ LOGE("error during crunch - archive is toast\n");
+ return result;
+ }
+
+ pEntry->setLFHOffset(pEntry->getLFHOffset() - adjust);
+ }
+ }
+
+ /*
+ * Fix EOCD info. We have to wait until the end to do some of this
+ * because we use mCentralDirOffset to determine "span" for the
+ * last entry.
+ */
+ mEOCD.mCentralDirOffset -= adjust;
+ mEOCD.mNumEntries -= delCount;
+ mEOCD.mTotalNumEntries -= delCount;
+ mEOCD.mCentralDirSize = 0; // mark invalid; set by flush()
+
+ assert(mEOCD.mNumEntries == mEOCD.mTotalNumEntries);
+ assert(mEOCD.mNumEntries == count);
+
+ return result;
+}
+
+/*
+ * Works like memmove(), but on pieces of a file.
+ */
+status_t ZipFile::filemove(FILE* fp, off_t dst, off_t src, size_t n)
+{
+ if (dst == src || n <= 0)
+ return NO_ERROR;
+
+ unsigned char readBuf[32768];
+
+ if (dst < src) {
+ /* shift stuff toward start of file; must read from start */
+ while (n != 0) {
+ size_t getSize = sizeof(readBuf);
+ if (getSize > n)
+ getSize = n;
+
+ if (fseek(fp, (long) src, SEEK_SET) != 0) {
+ LOGD("filemove src seek %ld failed\n", (long) src);
+ return UNKNOWN_ERROR;
+ }
+
+ if (fread(readBuf, 1, getSize, fp) != getSize) {
+ LOGD("filemove read %ld off=%ld failed\n",
+ (long) getSize, (long) src);
+ return UNKNOWN_ERROR;
+ }
+
+ if (fseek(fp, (long) dst, SEEK_SET) != 0) {
+ LOGD("filemove dst seek %ld failed\n", (long) dst);
+ return UNKNOWN_ERROR;
+ }
+
+ if (fwrite(readBuf, 1, getSize, fp) != getSize) {
+ LOGD("filemove write %ld off=%ld failed\n",
+ (long) getSize, (long) dst);
+ return UNKNOWN_ERROR;
+ }
+
+ src += getSize;
+ dst += getSize;
+ n -= getSize;
+ }
+ } else {
+ /* shift stuff toward end of file; must read from end */
+ assert(false); // write this someday, maybe
+ return UNKNOWN_ERROR;
+ }
+
+ return NO_ERROR;
+}
+
+
+/*
+ * Get the modification time from a file descriptor.
+ */
+time_t ZipFile::getModTime(int fd)
+{
+ struct stat sb;
+
+ if (fstat(fd, &sb) < 0) {
+ LOGD("HEY: fstat on fd %d failed\n", fd);
+ return (time_t) -1;
+ }
+
+ return sb.st_mtime;
+}
+
+
+#if 0 /* this is a bad idea */
+/*
+ * Get a copy of the Zip file descriptor.
+ *
+ * We don't allow this if the file was opened read-write because we tend
+ * to leave the file contents in an uncertain state between calls to
+ * flush(). The duplicated file descriptor should only be valid for reads.
+ */
+int ZipFile::getZipFd(void) const
+{
+ if (!mReadOnly)
+ return INVALID_OPERATION;
+ assert(mZipFp != NULL);
+
+ int fd;
+ fd = dup(fileno(mZipFp));
+ if (fd < 0) {
+ LOGD("didn't work, errno=%d\n", errno);
+ }
+
+ return fd;
+}
+#endif
+
+
+#if 0
+/*
+ * Expand data.
+ */
+bool ZipFile::uncompress(const ZipEntry* pEntry, void* buf) const
+{
+ return false;
+}
+#endif
+
+// free the memory when you're done
+void* ZipFile::uncompress(const ZipEntry* entry)
+{
+ size_t unlen = entry->getUncompressedLen();
+ size_t clen = entry->getCompressedLen();
+
+ void* buf = malloc(unlen);
+ if (buf == NULL) {
+ return NULL;
+ }
+
+ fseek(mZipFp, 0, SEEK_SET);
+
+ off_t offset = entry->getFileOffset();
+ if (fseek(mZipFp, offset, SEEK_SET) != 0) {
+ goto bail;
+ }
+
+ switch (entry->getCompressionMethod())
+ {
+ case ZipEntry::kCompressStored: {
+ ssize_t amt = fread(buf, 1, unlen, mZipFp);
+ if (amt != (ssize_t)unlen) {
+ goto bail;
+ }
+#if 0
+ printf("data...\n");
+ const unsigned char* p = (unsigned char*)buf;
+ const unsigned char* end = p+unlen;
+ for (int i=0; i<32 && p < end; i++) {
+ printf("0x%08x ", (int)(offset+(i*0x10)));
+ for (int j=0; j<0x10 && p < end; j++) {
+ printf(" %02x", *p);
+ p++;
+ }
+ printf("\n");
+ }
+#endif
+
+ }
+ break;
+ case ZipEntry::kCompressDeflated: {
+ if (!ZipUtils::inflateToBuffer(mZipFp, buf, unlen, clen)) {
+ goto bail;
+ }
+ }
+ break;
+ default:
+ goto bail;
+ }
+ return buf;
+
+bail:
+ free(buf);
+ return NULL;
+}
+
+
+/*
+ * ===========================================================================
+ * ZipFile::EndOfCentralDir
+ * ===========================================================================
+ */
+
+/*
+ * Read the end-of-central-dir fields.
+ *
+ * "buf" should be positioned at the EOCD signature, and should contain
+ * the entire EOCD area including the comment.
+ */
+status_t ZipFile::EndOfCentralDir::readBuf(const unsigned char* buf, int len)
+{
+ /* don't allow re-use */
+ assert(mComment == NULL);
+
+ if (len < kEOCDLen) {
+ /* looks like ZIP file got truncated */
+ LOGD(" Zip EOCD: expected >= %d bytes, found %d\n",
+ kEOCDLen, len);
+ return INVALID_OPERATION;
+ }
+
+ /* this should probably be an assert() */
+ if (ZipEntry::getLongLE(&buf[0x00]) != kSignature)
+ return UNKNOWN_ERROR;
+
+ mDiskNumber = ZipEntry::getShortLE(&buf[0x04]);
+ mDiskWithCentralDir = ZipEntry::getShortLE(&buf[0x06]);
+ mNumEntries = ZipEntry::getShortLE(&buf[0x08]);
+ mTotalNumEntries = ZipEntry::getShortLE(&buf[0x0a]);
+ mCentralDirSize = ZipEntry::getLongLE(&buf[0x0c]);
+ mCentralDirOffset = ZipEntry::getLongLE(&buf[0x10]);
+ mCommentLen = ZipEntry::getShortLE(&buf[0x14]);
+
+ // TODO: validate mCentralDirOffset
+
+ if (mCommentLen > 0) {
+ if (kEOCDLen + mCommentLen > len) {
+ LOGD("EOCD(%d) + comment(%d) exceeds len (%d)\n",
+ kEOCDLen, mCommentLen, len);
+ return UNKNOWN_ERROR;
+ }
+ mComment = new unsigned char[mCommentLen];
+ memcpy(mComment, buf + kEOCDLen, mCommentLen);
+ }
+
+ return NO_ERROR;
+}
+
+/*
+ * Write an end-of-central-directory section.
+ */
+status_t ZipFile::EndOfCentralDir::write(FILE* fp)
+{
+ unsigned char buf[kEOCDLen];
+
+ ZipEntry::putLongLE(&buf[0x00], kSignature);
+ ZipEntry::putShortLE(&buf[0x04], mDiskNumber);
+ ZipEntry::putShortLE(&buf[0x06], mDiskWithCentralDir);
+ ZipEntry::putShortLE(&buf[0x08], mNumEntries);
+ ZipEntry::putShortLE(&buf[0x0a], mTotalNumEntries);
+ ZipEntry::putLongLE(&buf[0x0c], mCentralDirSize);
+ ZipEntry::putLongLE(&buf[0x10], mCentralDirOffset);
+ ZipEntry::putShortLE(&buf[0x14], mCommentLen);
+
+ if (fwrite(buf, 1, kEOCDLen, fp) != kEOCDLen)
+ return UNKNOWN_ERROR;
+ if (mCommentLen > 0) {
+ assert(mComment != NULL);
+ if (fwrite(mComment, mCommentLen, 1, fp) != mCommentLen)
+ return UNKNOWN_ERROR;
+ }
+
+ return NO_ERROR;
+}
+
+/*
+ * Dump the contents of an EndOfCentralDir object.
+ */
+void ZipFile::EndOfCentralDir::dump(void) const
+{
+ LOGD(" EndOfCentralDir contents:\n");
+ LOGD(" diskNum=%u diskWCD=%u numEnt=%u totalNumEnt=%u\n",
+ mDiskNumber, mDiskWithCentralDir, mNumEntries, mTotalNumEntries);
+ LOGD(" centDirSize=%lu centDirOff=%lu commentLen=%u\n",
+ mCentralDirSize, mCentralDirOffset, mCommentLen);
+}
+
diff --git a/tools/zipalign/ZipFile.h b/tools/zipalign/ZipFile.h
new file mode 100644
index 0000000..dbbd072
--- /dev/null
+++ b/tools/zipalign/ZipFile.h
@@ -0,0 +1,270 @@
+/*
+ * Copyright (C) 2006 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// General-purpose Zip archive access. This class allows both reading and
+// writing to Zip archives, including deletion of existing entries.
+//
+#ifndef __LIBS_ZIPFILE_H
+#define __LIBS_ZIPFILE_H
+
+#include <utils/Vector.h>
+#include <utils/Errors.h>
+#include <stdio.h>
+
+#include "ZipEntry.h"
+
+namespace android {
+
+/*
+ * Manipulate a Zip archive.
+ *
+ * Some changes will not be visible in the until until "flush" is called.
+ *
+ * The correct way to update a file archive is to make all changes to a
+ * copy of the archive in a temporary file, and then unlink/rename over
+ * the original after everything completes. Because we're only interested
+ * in using this for packaging, we don't worry about such things. Crashing
+ * after making changes and before flush() completes could leave us with
+ * an unusable Zip archive.
+ */
+class ZipFile {
+public:
+ ZipFile(void)
+ : mZipFp(NULL), mReadOnly(false), mNeedCDRewrite(false)
+ {}
+ ~ZipFile(void) {
+ if (!mReadOnly)
+ flush();
+ if (mZipFp != NULL)
+ fclose(mZipFp);
+ discardEntries();
+ }
+
+ /*
+ * Open a new or existing archive.
+ */
+ typedef enum {
+ kOpenReadOnly = 0x01,
+ kOpenReadWrite = 0x02,
+ kOpenCreate = 0x04, // create if it doesn't exist
+ kOpenTruncate = 0x08, // if it exists, empty it
+ };
+ status_t open(const char* zipFileName, int flags);
+
+ /*
+ * Add a file to the end of the archive. Specify whether you want the
+ * library to try to store it compressed.
+ *
+ * If "storageName" is specified, the archive will use that instead
+ * of "fileName".
+ *
+ * If there is already an entry with the same name, the call fails.
+ * Existing entries with the same name must be removed first.
+ *
+ * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
+ */
+ status_t add(const char* fileName, int compressionMethod,
+ ZipEntry** ppEntry)
+ {
+ return add(fileName, fileName, compressionMethod, ppEntry);
+ }
+ status_t add(const char* fileName, const char* storageName,
+ int compressionMethod, ZipEntry** ppEntry)
+ {
+ return addCommon(fileName, NULL, 0, storageName,
+ ZipEntry::kCompressStored,
+ compressionMethod, ppEntry);
+ }
+
+ /*
+ * Add a file that is already compressed with gzip.
+ *
+ * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
+ */
+ status_t addGzip(const char* fileName, const char* storageName,
+ ZipEntry** ppEntry)
+ {
+ return addCommon(fileName, NULL, 0, storageName,
+ ZipEntry::kCompressDeflated,
+ ZipEntry::kCompressDeflated, ppEntry);
+ }
+
+ /*
+ * Add a file from an in-memory data buffer.
+ *
+ * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
+ */
+ status_t add(const void* data, size_t size, const char* storageName,
+ int compressionMethod, ZipEntry** ppEntry)
+ {
+ return addCommon(NULL, data, size, storageName,
+ ZipEntry::kCompressStored,
+ compressionMethod, ppEntry);
+ }
+
+ /*
+ * Add an entry by copying it from another zip file. If "padding" is
+ * nonzero, the specified number of bytes will be added to the "extra"
+ * field in the header.
+ *
+ * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
+ */
+ status_t add(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
+ int padding, ZipEntry** ppEntry);
+
+ /*
+ * Mark an entry as having been removed. It is not actually deleted
+ * from the archive or our internal data structures until flush() is
+ * called.
+ */
+ status_t remove(ZipEntry* pEntry);
+
+ /*
+ * Flush changes. If mNeedCDRewrite is set, this writes the central dir.
+ */
+ status_t flush(void);
+
+ /*
+ * Expand the data into the buffer provided. The buffer must hold
+ * at least <uncompressed len> bytes. Variation expands directly
+ * to a file.
+ *
+ * Returns "false" if an error was encountered in the compressed data.
+ */
+ //bool uncompress(const ZipEntry* pEntry, void* buf) const;
+ //bool uncompress(const ZipEntry* pEntry, FILE* fp) const;
+ void* uncompress(const ZipEntry* pEntry);
+
+ /*
+ * Get an entry, by name. Returns NULL if not found.
+ *
+ * Does not return entries pending deletion.
+ */
+ ZipEntry* getEntryByName(const char* fileName) const;
+
+ /*
+ * Get the Nth entry in the archive.
+ *
+ * This will return an entry that is pending deletion.
+ */
+ int getNumEntries(void) const { return mEntries.size(); }
+ ZipEntry* getEntryByIndex(int idx) const;
+
+private:
+ /* these are private and not defined */
+ ZipFile(const ZipFile& src);
+ ZipFile& operator=(const ZipFile& src);
+
+ class EndOfCentralDir {
+ public:
+ EndOfCentralDir(void) :
+ mDiskNumber(0),
+ mDiskWithCentralDir(0),
+ mNumEntries(0),
+ mTotalNumEntries(0),
+ mCentralDirSize(0),
+ mCentralDirOffset(0),
+ mCommentLen(0),
+ mComment(NULL)
+ {}
+ virtual ~EndOfCentralDir(void) {
+ delete[] mComment;
+ }
+
+ status_t readBuf(const unsigned char* buf, int len);
+ status_t write(FILE* fp);
+
+ //unsigned long mSignature;
+ unsigned short mDiskNumber;
+ unsigned short mDiskWithCentralDir;
+ unsigned short mNumEntries;
+ unsigned short mTotalNumEntries;
+ unsigned long mCentralDirSize;
+ unsigned long mCentralDirOffset; // offset from first disk
+ unsigned short mCommentLen;
+ unsigned char* mComment;
+
+ enum {
+ kSignature = 0x06054b50,
+ kEOCDLen = 22, // EndOfCentralDir len, excl. comment
+
+ kMaxCommentLen = 65535, // longest possible in ushort
+ kMaxEOCDSearch = kMaxCommentLen + EndOfCentralDir::kEOCDLen,
+
+ };
+
+ void dump(void) const;
+ };
+
+
+ /* read all entries in the central dir */
+ status_t readCentralDir(void);
+
+ /* crunch deleted entries out */
+ status_t crunchArchive(void);
+
+ /* clean up mEntries */
+ void discardEntries(void);
+
+ /* common handler for all "add" functions */
+ status_t addCommon(const char* fileName, const void* data, size_t size,
+ const char* storageName, int sourceType, int compressionMethod,
+ ZipEntry** ppEntry);
+
+ /* copy all of "srcFp" into "dstFp" */
+ status_t copyFpToFp(FILE* dstFp, FILE* srcFp, unsigned long* pCRC32);
+ /* copy all of "data" into "dstFp" */
+ status_t copyDataToFp(FILE* dstFp,
+ const void* data, size_t size, unsigned long* pCRC32);
+ /* copy some of "srcFp" into "dstFp" */
+ status_t copyPartialFpToFp(FILE* dstFp, FILE* srcFp, long length,
+ unsigned long* pCRC32);
+ /* like memmove(), but on parts of a single file */
+ status_t filemove(FILE* fp, off_t dest, off_t src, size_t n);
+ /* compress all of "srcFp" into "dstFp", using Deflate */
+ status_t compressFpToFp(FILE* dstFp, FILE* srcFp,
+ const void* data, size_t size, unsigned long* pCRC32);
+
+ /* get modification date from a file descriptor */
+ time_t getModTime(int fd);
+
+ /*
+ * We use stdio FILE*, which gives us buffering but makes dealing
+ * with files >2GB awkward. Until we support Zip64, we're fine.
+ */
+ FILE* mZipFp; // Zip file pointer
+
+ /* one of these per file */
+ EndOfCentralDir mEOCD;
+
+ /* did we open this read-only? */
+ bool mReadOnly;
+
+ /* set this when we trash the central dir */
+ bool mNeedCDRewrite;
+
+ /*
+ * One ZipEntry per entry in the zip file. I'm using pointers instead
+ * of objects because it's easier than making operator= work for the
+ * classes and sub-classes.
+ */
+ Vector<ZipEntry*> mEntries;
+};
+
+}; // namespace android
+
+#endif // __LIBS_ZIPFILE_H