Merge "Adds the compatibility build task and cts_v2 rules."
diff --git a/core/clear_vars.mk b/core/clear_vars.mk
index d850272..63a398a 100644
--- a/core/clear_vars.mk
+++ b/core/clear_vars.mk
@@ -20,7 +20,6 @@
 LOCAL_MODULE_CLASS:=
 LOCAL_MODULE_SUFFIX:=
 LOCAL_PACKAGE_NAME:=
-LOCAL_PAGE_ALIGN_JNI_SHARED_LIBRARIES:=
 LOCAL_OVERRIDES_PACKAGES:=
 LOCAL_EXPORT_PACKAGE_RESOURCES:=
 LOCAL_MANIFEST_PACKAGE_NAME:=
diff --git a/core/definitions.mk b/core/definitions.mk
index 6b9abd8..474a4e6 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -2030,8 +2030,7 @@
 $(foreach abi,$(PRIVATE_JNI_SHARED_LIBRARIES_ABI),\
   $(call _add-jni-shared-libs-to-package-per-abi,$(abi),\
     $(patsubst $(abi):%,%,$(filter $(abi):%,$(PRIVATE_JNI_SHARED_LIBRARIES)))))
-$(hide) (cd $(dir $@) && zip -r \
-    $(if $(filter true, $(PRIVATE_PAGE_ALIGN_JNI_SHARED_LIBRARIES)),-0,) $(notdir $@) lib)
+$(hide) (cd $(dir $@) && zip -r -0 $(notdir $@) lib)
 $(hide) rm -rf $(dir $@)lib
 endef
 
@@ -2077,21 +2076,22 @@
 define align-package
 $(hide) mv $@ $@.unaligned
 $(hide) $(ZIPALIGN) \
-    -f \
-    $(if $(filter true, $(PRIVATE_PAGE_ALIGN_JNI_SHARED_LIBRARIES)),-p,) \
+    -f -p \
     4 \
     $@.unaligned $@.aligned
 $(hide) mv $@.aligned $@
 endef
 
+# Uncompress shared libraries embedded in an apk.
+#
 define uncompress-shared-libs
-$(hide) rm -rf $(dir $@)/tmpworkdir
-$(hide) mv $@ $@.compressed
-$(hide) mkdir $(dir $@)/tmpworkdir
-$(hide) unzip $@.compressed 'lib/*.so' -d $(dir $@)/tmpworkdir
-$(hide) ( cd $(dir $@)/tmpworkdir && zip -D -r -0 ../$(notdir $@).compressed lib )
-$(hide) mv $@.compressed $@
-$(hide) rm -rf $(dir $@)/tmpworkdir
+$(hide) if unzip -l $@ $(PRIVATE_EMBEDDED_JNI_LIBS) >/dev/null ; then \
+  rm -rf $(dir $@)uncompressedlibs && mkdir $(dir $@)uncompressedlibs; \
+  unzip $@ $(PRIVATE_EMBEDDED_JNI_LIBS) -d $(dir $@)uncompressedlibs && \
+  zip -d $@ 'lib/*.so' && \
+  ( cd $(dir $@)uncompressedlibs && zip -D -r -0 ../$(notdir $@) lib ) && \
+  rm -rf $(dir $@)uncompressedlibs; \
+  fi
 endef
 
 define install-dex-debug
diff --git a/core/install_jni_libs.mk b/core/install_jni_libs.mk
index da3032d..625a8a2 100644
--- a/core/install_jni_libs.mk
+++ b/core/install_jni_libs.mk
@@ -8,7 +8,7 @@
 #
 # Output variables:
 #   jni_shared_libraries, jni_shared_libraries_abi, jni_shared_libraries_with_abis if we are going to embed the libraries into the apk;
-#   extracted_jni_libs, if we extract jni libs from prebuilt apk.
+#   embedded_prebuilt_jni_libs, prebuilt jni libs embedded in prebuilt apk.
 #
 
 my_embed_jni :=
@@ -27,7 +27,7 @@
 jni_shared_libraries_abis :=
 # jni_shared_libraries_with_abis is a list of <abi>:<path-to-the-built-jni-lib>
 jni_shared_libraries_with_abis :=
-extracted_jni_libs :=
+embedded_prebuilt_jni_libs :=
 
 #######################################
 # For TARGET_ARCH
@@ -51,7 +51,7 @@
 jni_shared_libraries_abis += $(my_jni_shared_libraries_abi)
 jni_shared_libraries_with_abis += $(addprefix $(my_jni_shared_libraries_abi):,\
     $(my_jni_shared_libraries))
-extracted_jni_libs += $(my_extracted_jni_libs)
+embedded_prebuilt_jni_libs += $(my_embedded_prebuilt_jni_libs)
 
 # Include RS dynamically-generated libraries as well
 # TODO: Add multilib support once RS supports generating multilib libraries.
@@ -83,11 +83,11 @@
 jni_shared_libraries_abis += $(my_jni_shared_libraries_abi)
 jni_shared_libraries_with_abis += $(addprefix $(my_jni_shared_libraries_abi):,\
     $(my_jni_shared_libraries))
-extracted_jni_libs += $(my_extracted_jni_libs)
+embedded_prebuilt_jni_libs += $(my_embedded_prebuilt_jni_libs)
 endif  # my_add_jni
 endif  # TARGET_2ND_ARCH
 
 jni_shared_libraries := $(strip $(jni_shared_libraries))
 jni_shared_libraries_abis := $(sort $(jni_shared_libraries_abis))
 jni_shared_libraries_with_abis := $(strip $(jni_shared_libraries_with_abis))
-extracted_jni_libs := $(strip $(extracted_jni_libs))
+embedded_prebuilt_jni_libs := $(strip $(embedded_prebuilt_jni_libs))
diff --git a/core/install_jni_libs_internal.mk b/core/install_jni_libs_internal.mk
index 634fdf3..16d0962 100644
--- a/core/install_jni_libs_internal.mk
+++ b/core/install_jni_libs_internal.mk
@@ -9,7 +9,7 @@
 #
 # Output variables:
 #   my_jni_shared_libraries, my_jni_shared_libraries_abi, if we are going to embed the libraries into the apk;
-#   my_extracted_jni_libs, if we extract jni libs from prebuilt apk.
+#   my_embedded_prebuilt_jni_libs, prebuilt jni libs embedded in prebuilt apk.
 #
 
 my_jni_shared_libraries := \
@@ -19,7 +19,7 @@
 
 # App-specific lib path.
 my_app_lib_path := $(dir $(LOCAL_INSTALLED_MODULE))lib/$(TARGET_$(my_2nd_arch_prefix)ARCH)
-my_extracted_jni_libs :=
+my_embedded_prebuilt_jni_libs :=
 
 ifdef my_embed_jni
 # App explicitly requires the prebuilt NDK stl shared libraies.
@@ -76,34 +76,10 @@
 endif  # my_embed_jni
 
 ifdef my_prebuilt_jni_libs
-# Install prebuilt JNI libs to the app specific lib path.
-# Files like @path/to/libfoo.so (path inside the apk) are JNI libs extracted from the prebuilt apk;
+# Files like @lib/<abi>/libfoo.so (path inside the apk) are JNI libs embedded prebuilt apk;
 # Files like path/to/libfoo.so (path relative to LOCAL_PATH) are prebuilts in the source tree.
-my_extracted_jni_libs := $(patsubst @%,%, \
+my_embedded_prebuilt_jni_libs := $(patsubst @%,%, \
     $(filter @%, $(my_prebuilt_jni_libs)))
-ifdef my_extracted_jni_libs
-ifndef my_prebuilt_src_file
-$(error No prebuilt apk to extract prebuilt jni libraries $(my_extracted_jni_libs))
-endif
-ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
-$(warning Extracting files using LOCAL_PREBUILT_JNI_LIBS cannot be done while)
-$(warning using LOCAL_CERTIFICATE:=PRESIGNED, as this would corrupt)
-$(warning the APK or waste disk space. Instead, you should delete)
-$(warning LOCAL_PREBUILT_JNI_LIBS and use LOCAL_PAGE_ALIGN_JNI_SHARED_LIBRARIES:=true)
-$(warning This will allow loading of shared libraries directly from the APK,)
-$(warning eliminating the need to separately extract them.)
-$(error Failed to build: $(LOCAL_MODULE))
-endif
-# We use the first jni lib file as dependency.
-my_installed_prebuilt_jni := $(my_app_lib_path)/$(notdir $(firstword $(my_extracted_jni_libs)))
-$(my_installed_prebuilt_jni): PRIVATE_JNI_LIBS := $(my_extracted_jni_libs)
-$(my_installed_prebuilt_jni): $(my_prebuilt_src_file)
-	@echo "Extract JNI libs ($@ <- $<)"
-	@mkdir -p $(dir $@)
-	$(hide) unzip -j -o -d $(dir $@) $< $(PRIVATE_JNI_LIBS) && touch $@
-
-$(LOCAL_INSTALLED_MODULE) : | $(my_installed_prebuilt_jni)
-endif
 
 # prebuilt JNI exsiting as separate source files.
 my_prebuilt_jni_libs := $(addprefix $(LOCAL_PATH)/, \
diff --git a/core/package_internal.mk b/core/package_internal.mk
index 8518f03..305468a 100644
--- a/core/package_internal.mk
+++ b/core/package_internal.mk
@@ -438,7 +438,6 @@
 $(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis)
 # PRIVATE_JNI_SHARED_LIBRARIES_ABI is a list of ABI names.
 $(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES_ABI := $(jni_shared_libraries_abis)
-$(LOCAL_BUILT_MODULE): PRIVATE_PAGE_ALIGN_JNI_SHARED_LIBRARIES := $(LOCAL_PAGE_ALIGN_JNI_SHARED_LIBRARIES)
 ifneq ($(TARGET_BUILD_APPS),)
     # Include all resources for unbundled apps.
     LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk
index 8d03746..0406353 100644
--- a/core/prebuilt_internal.mk
+++ b/core/prebuilt_internal.mk
@@ -195,14 +195,25 @@
 include $(BUILD_SYSTEM)/dex_preopt_odex_install.mk
 #######################################
 # Sign and align non-presigned .apks.
-$(built_module) : PRIVATE_PAGE_ALIGN_JNI_SHARED_LIBRARIES := $(LOCAL_PAGE_ALIGN_JNI_SHARED_LIBRARIES)
+
+# The embedded prebuilt jni to uncompress.
+ifeq ($(LOCAL_CERTIFICATE),PRESIGNED)
+# For PRESIGNED apks we must uncompress every .so file:
+# even if the .so file isn't for the current TARGET_ARCH,
+# we can't strip the file.
+embedded_prebuilt_jni_libs := 'lib/*.so'
+endif
+ifndef embedded_prebuilt_jni_libs
+# No LOCAL_PREBUILT_JNI_LIBS, uncompress all.
+embedded_prebuilt_jni_libs := 'lib/*.so'
+endif
+$(built_module): PRIVATE_EMBEDDED_JNI_LIBS := $(embedded_prebuilt_jni_libs)
+
 $(built_module) : $(my_prebuilt_src_file) | $(ACP) $(ZIPALIGN) $(SIGNAPK_JAR)
 	$(transform-prebuilt-to-target)
+	$(uncompress-shared-libs)
 ifneq ($(LOCAL_CERTIFICATE),PRESIGNED)
 	@# Only strip out files if we can re-sign the package.
-ifdef extracted_jni_libs
-	$(hide) zip -d $@ 'lib/*.so'  # strip embedded JNI libraries.
-endif
 ifdef LOCAL_DEX_PREOPT
 ifneq (nostripping,$(LOCAL_DEX_PREOPT))
 	$(call dexpreopt-remove-classes.dex,$@)
@@ -210,9 +221,6 @@
 endif
 	$(sign-package)
 endif
-ifeq ($(LOCAL_PAGE_ALIGN_JNI_SHARED_LIBRARIES),true)
-	$(uncompress-shared-libs)
-endif
 	$(align-package)
 
 ###############################
diff --git a/tools/droiddoc/templates-sdk/assets/css/default.css b/tools/droiddoc/templates-sdk/assets/css/default.css
index 8297407..693027a 100644
--- a/tools/droiddoc/templates-sdk/assets/css/default.css
+++ b/tools/droiddoc/templates-sdk/assets/css/default.css
@@ -5129,6 +5129,69 @@
   content:url("../images/play-circle-grey.png") url("../images/play-circle-grey_2x.png");
 }
 
+/*
+ * Responsive YouTube embeds from DevSite
+ *
+ * When applied to a <div> that wraps a video, "video-wrapper" forces the video
+ * to float right at 50% of the column width on desktop, but appear as a block
+ * element at 100% of the column width on smaller screens.
+ * "video-wrapper-full-width" works the same but is always 100% width.
+ */
+.video-wrapper,
+.video-wrapper-left {
+  float: right;
+  margin: 0 0 40px 40px;
+  padding-top: calc(((100% - 40px) / 2) / 16 * 9); /* 16:9 including margin */
+  position: relative;
+  width: calc((100% - 40px) / 2);                  /* 50% including margin */
+}
+
+/*
+ * "video-wrapper-left" forces 50% without the float
+ * This is useful for heading content when you want the video to
+ * appear next to an element that is already floated right
+ * (e.g. tb-wrapper <div>)
+ */
+.video-wrapper-left {
+  float: none;
+  margin: 16px 0 20px 0;
+}
+
+.video-wrapper-full-width {
+  margin: 16px 0;
+  padding-top: 56.25%; /* Forces div to 16:9 at 100% width */
+  position: relative;
+  width: 100%;
+}
+
+.video-wrapper embed,
+.video-wrapper iframe,
+.video-wrapper object,
+.video-wrapper-full-width embed,
+.video-wrapper-full-width iframe,
+.video-wrapper-full-width object,
+.video-wrapper-left embed,
+.video-wrapper-left iframe,
+.video-wrapper-left object {
+  height: 100%;
+  left: 0;
+  position: absolute;
+  top: 0;
+  width: 100%;
+}
+
+@media screen and (max-width: 1000px) {
+
+  .video-wrapper,
+  .video-wrapper-left {
+    float: none;
+    margin: 16px 0;
+    padding-top: 56.25%; /* Forces div to 16:9 at 100% width */
+    width: 100%;
+  }
+}
+
+
 /******************
 Styles for d.a.c/index:
 *******************/