Merge "Initialize ro.build.version.preview_sdk" into mnc-dev
diff --git a/core/base_rules.mk b/core/base_rules.mk
index 1a2dc5e..ea64cc6 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -87,6 +87,7 @@
 # file, tag the module as "gnu".  Search for "*_GPL*", "*_LGPL*" and "*_MPL*"
 # so that we can also find files like MODULE_LICENSE_GPL_AND_AFL
 #
+license_files := $(call find-parent-file,$(LOCAL_PATH),MODULE_LICENSE*)
 gpl_license_file := $(call find-parent-file,$(LOCAL_PATH),MODULE_LICENSE*_GPL* MODULE_LICENSE*_MPL* MODULE_LICENSE*_LGPL*)
 ifneq ($(gpl_license_file),)
   my_module_tags += gnu
@@ -646,6 +647,21 @@
 
 INSTALLABLE_FILES.$(LOCAL_INSTALLED_MODULE).MODULE := $(my_register_name)
 
+##########################################################
+# Track module-level dependencies.
+# Use $(LOCAL_MODULE) instead of $(my_register_name) to ignore module's bitness.
+ALL_DEPS.MODULES := $(sort $(ALL_DEPS.MODULES) $(LOCAL_MODULE))
+ALL_DEPS.$(LOCAL_MODULE).ALL_DEPS := $(sort \
+  $(ALL_MODULES.$(LOCAL_MODULE).ALL_DEPS) \
+  $(LOCAL_STATIC_LIBRARIES) \
+  $(LOCAL_WHOLE_STATIC_LIBRARIES) \
+  $(LOCAL_SHARED_LIBRARIES) \
+  $(LOCAL_STATIC_JAVA_LIBRARIES) \
+  $(LOCAL_JAVA_LIBRARIES)\
+  $(LOCAL_JNI_SHARED_LIBRARIES))
+
+ALL_DEPS.$(LOCAL_MODULE).LICENSE := $(sort $(ALL_DEPS.$(LOCAL_MODULE).LICENSE) $(license_files))
+
 ###########################################################
 ## Take care of my_module_tags
 ###########################################################
diff --git a/core/config.mk b/core/config.mk
index 5ad79e3..c3ed00f 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -450,7 +450,7 @@
 ifneq ($(ANDROID_JACK_EXTRA_ARGS),)
 DEFAULT_JACK_EXTRA_ARGS := $(ANDROID_JACK_EXTRA_ARGS)
 else
-DEFAULT_JACK_EXTRA_ARGS := -D sched.runner=multi-threaded -D  sched.runner.thread.kind=fixed -D sched.runner.thread.fixed.count=4 --sanity-checks off -D jack.reporter.level.file=error=--,warning=-
+DEFAULT_JACK_EXTRA_ARGS := @$(BUILD_SYSTEM)/jack-default.args
 endif
 # Turn off jack warnings by default.
 DEFAULT_JACK_EXTRA_ARGS += --verbose error
@@ -623,6 +623,13 @@
 HISTORICAL_SDK_VERSIONS_ROOT := $(TOPDIR)prebuilts/sdk
 HISTORICAL_NDK_VERSIONS_ROOT := $(TOPDIR)prebuilts/ndk
 
+# The path where app can reference the support library resources.
+ifdef TARGET_BUILD_APPS
+SUPPORT_LIBRARY_ROOT := $(HISTORICAL_SDK_VERSIONS_ROOT)/current/support
+else
+SUPPORT_LIBRARY_ROOT := frameworks/support
+endif
+
 # Historical SDK version N is stored in $(HISTORICAL_SDK_VERSIONS_ROOT)/N.
 # The 'current' version is whatever this source tree is.
 #
diff --git a/core/jack-default.args b/core/jack-default.args
new file mode 100644
index 0000000..8d70a82
--- /dev/null
+++ b/core/jack-default.args
@@ -0,0 +1,5 @@
+-D sched.runner=multi-threaded
+-D sched.runner.thread.kind=fixed
+-D sched.runner.thread.fixed.count=4
+--sanity-checks off
+-D jack.reporter.level.file=error=--,warning=-
\ No newline at end of file
diff --git a/core/java.mk b/core/java.mk
index 73b8780..66993e7 100644
--- a/core/java.mk
+++ b/core/java.mk
@@ -447,7 +447,7 @@
 else
   # For platform build, we can't just raise to the "current" SDK,
   # that would break apps that use APIs removed from the current SDK.
-  my_support_library_sdk_raise := $(call java-lib-files,framework)
+  my_support_library_sdk_raise := $(call java-lib-files,$(TARGET_DEFAULT_JAVA_LIBRARIES))
 endif
 endif
 endif
diff --git a/core/tasks/deps_licenses.mk b/core/tasks/deps_licenses.mk
new file mode 100644
index 0000000..bb20fa0
--- /dev/null
+++ b/core/tasks/deps_licenses.mk
@@ -0,0 +1,59 @@
+#
+# Copyright (C) 2015 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.
+#
+
+# Print modules and their transitive dependencies with license files.
+# To invoke, run "make deps-license PROJ_PATH=<proj-path-patterns> DEP_PATH=<dep-path-patterns>".
+# PROJ_PATH restricts the paths of the source modules; DEP_PATH restricts the paths of the dependency modules.
+# Both can be makefile patterns supported by makefile function $(filter).
+# Example: "make deps-license packages/app/% external/%" prints all modules in packages/app/ with their dpendencies in external/.
+# The printout lines look like "<module_name> :: <module_paths> :: <license_files>".
+
+ifneq (,$(filter deps-license,$(MAKECMDGOALS)))
+ifndef PROJ_PATH
+$(error To "make deps-license" you must specify PROJ_PATH and DEP_PATH.)
+endif
+ifndef DEP_PATH
+$(error To "make deps-license" you must specify PROJ_PATH and DEP_PATH.)
+endif
+
+# Expand a module's dependencies transitively.
+# $(1): the variable name to hold the result.
+# $(2): the initial module name.
+define get-module-all-dependencies
+$(eval _gmad_new := $(sort $(filter-out $($(1)),\
+  $(foreach m,$(2),$(ALL_DEPS.$(m).ALL_DEPS)))))\
+$(if $(_gmad_new),$(eval $(1) += $(_gmad_new))\
+  $(call get-module-all-dependencies,$(1),$(_gmad_new)))
+endef
+
+define print-deps-license
+$(foreach m, $(ALL_DEPS.MODULES),\
+  $(eval m_p := $(sort $(ALL_MODULES.$(m).PATH) $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).PATH)))\
+  $(if $(filter $(PROJ_PATH),$(m_p)),\
+    $(eval deps :=)\
+    $(eval $(call get-module-all-dependencies,deps,$(m)))\
+    $(info $(m) :: $(m_p) :: $(ALL_DEPS.$(m).LICENSE))\
+    $(foreach d,$(deps),\
+      $(eval d_p := $(sort $(ALL_MODULES.$(d).PATH) $(ALL_MODULES.$(d)$(TARGET_2ND_ARCH_MODULE_SUFFIX).PATH)))\
+      $(if $(filter $(DEP_PATH),$(d_p)),\
+        $(info $(space)$(space)$(space)$(space)$(d) :: $(d_p) :: $(ALL_DEPS.$(d).LICENSE))))))
+endef
+
+.PHONY: deps-license
+deps-license:
+	@$(call print-deps-license)
+
+endif
diff --git a/target/board/generic/sepolicy/goldfish_setup.te b/target/board/generic/sepolicy/goldfish_setup.te
index 584731e..3fb79e7 100644
--- a/target/board/generic/sepolicy/goldfish_setup.te
+++ b/target/board/generic/sepolicy/goldfish_setup.te
@@ -13,6 +13,12 @@
 allow goldfish_setup self:udp_socket create_socket_perms;
 
 # Set net.eth0.dns*, debug.sf.nobootanimation
-unix_socket_connect(goldfish_setup, property, init)
-allow goldfish_setup system_prop:property_service set;
-allow goldfish_setup debug_prop:property_service set;
+set_prop(goldfish_setup, system_prop)
+set_prop(goldfish_setup, debug_prop)
+
+# Set ro.radio.noril
+set_prop(goldfish_setup, radio_noril_prop)
+
+# Stop ril-daemon service (by setting ctl.stop to ril-daemon, which
+# transforms to a permission check on ctl.ril-daemon).
+set_prop(goldfish_setup, ctl_rildaemon_prop)
diff --git a/target/board/generic/sepolicy/property.te b/target/board/generic/sepolicy/property.te
index b3d15f8..b316d08 100644
--- a/target/board/generic/sepolicy/property.te
+++ b/target/board/generic/sepolicy/property.te
@@ -1 +1,2 @@
 type qemu_prop, property_type;
+type radio_noril_prop, property_type;
diff --git a/target/board/generic/sepolicy/property_contexts b/target/board/generic/sepolicy/property_contexts
index 5f741f8..09b9b06 100644
--- a/target/board/generic/sepolicy/property_contexts
+++ b/target/board/generic/sepolicy/property_contexts
@@ -1 +1,2 @@
 qemu.                   u:object_r:qemu_prop:s0
+radio.noril             u:object_r:radio_noril_prop:s0
diff --git a/target/board/generic/sepolicy/qemu_props.te b/target/board/generic/sepolicy/qemu_props.te
index 05c7461..4a91c4c 100644
--- a/target/board/generic/sepolicy/qemu_props.te
+++ b/target/board/generic/sepolicy/qemu_props.te
@@ -5,5 +5,6 @@
 init_daemon_domain(qemu_props)
 
 # Set properties.
-unix_socket_connect(qemu_props, property, init)
-allow qemu_props { qemu_prop dalvik_prop config_prop }:property_service set;
+set_prop(qemu_props, qemu_prop)
+set_prop(qemu_props, dalvik_prop)
+set_prop(qemu_props, config_prop)
diff --git a/target/product/core.mk b/target/product/core.mk
index 519dbb8..d27fb8e 100644
--- a/target/product/core.mk
+++ b/target/product/core.mk
@@ -40,7 +40,7 @@
     KeyChain \
     Keyguard \
     LatinIME \
-    Launcher2 \
+    Launcher3 \
     ManagedProvisioning \
     PicoTts \
     PacProcessor \
diff --git a/target/product/core_minimal.mk b/target/product/core_minimal.mk
index f455561..022462e 100644
--- a/target/product/core_minimal.mk
+++ b/target/product/core_minimal.mk
@@ -51,7 +51,6 @@
     ip6tables \
     iptables \
     gatekeeperd \
-    gatekeeper.default \
     keystore \
     keystore.default \
     ld.mc \
diff --git a/target/product/core_tiny.mk b/target/product/core_tiny.mk
index 4f8fd7f..0a92275 100644
--- a/target/product/core_tiny.mk
+++ b/target/product/core_tiny.mk
@@ -55,7 +55,6 @@
     ip6tables \
     iptables \
     gatekeeperd \
-    gatekeeper.default \
     keystore \
     keystore.default \
     libOpenMAXAL \
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 8ab98e7..4f85491 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -862,7 +862,7 @@
     zipfile.ZIP64_LIMIT = saved_zip64_limit
 
 
-def ZipWriteStr(zip_file, zinfo_or_arcname, data, perms=0o644,
+def ZipWriteStr(zip_file, zinfo_or_arcname, data, perms=None,
                 compress_type=None):
   """Wrap zipfile.writestr() function to work around the zip64 limit.
 
@@ -881,6 +881,8 @@
   if not isinstance(zinfo_or_arcname, zipfile.ZipInfo):
     zinfo = zipfile.ZipInfo(filename=zinfo_or_arcname)
     zinfo.compress_type = zip_file.compression
+    if perms is None:
+      perms = 0o644
   else:
     zinfo = zinfo_or_arcname
 
@@ -888,8 +890,11 @@
   if compress_type is not None:
     zinfo.compress_type = compress_type
 
+  # If perms is given, it has a priority.
+  if perms is not None:
+    zinfo.external_attr = perms << 16
+
   # Use a fixed timestamp so the output is repeatable.
-  zinfo.external_attr = perms << 16
   zinfo.date_time = (2009, 1, 1, 0, 0, 0)
 
   zip_file.writestr(zinfo, data)
diff --git a/tools/releasetools/test_common.py b/tools/releasetools/test_common.py
index f28934d..a861346 100644
--- a/tools/releasetools/test_common.py
+++ b/tools/releasetools/test_common.py
@@ -121,15 +121,18 @@
       time.sleep(5)  # Make sure the atime/mtime will change measurably.
 
       if not isinstance(zinfo_or_arcname, zipfile.ZipInfo):
-        zinfo = zipfile.ZipInfo(filename=zinfo_or_arcname)
+        arcname = zinfo_or_arcname
+        expected_mode = extra_args.get("perms", 0o644)
       else:
-        zinfo = zinfo_or_arcname
-      arcname = zinfo.filename
+        arcname = zinfo_or_arcname.filename
+        expected_mode = extra_args.get("perms",
+                                       zinfo_or_arcname.external_attr >> 16)
 
-      common.ZipWriteStr(zip_file, zinfo, contents, **extra_args)
+      common.ZipWriteStr(zip_file, zinfo_or_arcname, contents, **extra_args)
       common.ZipClose(zip_file)
 
       self._verify(zip_file, zip_file_name, arcname, contents,
+                   expected_mode=expected_mode,
                    expected_compress_type=expected_compress_type)
     finally:
       os.remove(zip_file_name)
@@ -228,9 +231,10 @@
     random_string = os.urandom(1024)
     # Passing arcname
     self._test_ZipWriteStr("foo", random_string, {
+        "perms": 0o700,
         "compress_type": zipfile.ZIP_DEFLATED,
     })
-    self._test_ZipWriteStr("foo", random_string, {
+    self._test_ZipWriteStr("bar", random_string, {
         "compress_type": zipfile.ZIP_STORED,
     })
 
@@ -240,6 +244,7 @@
         "compress_type": zipfile.ZIP_DEFLATED,
     })
     self._test_ZipWriteStr(zinfo, random_string, {
+        "perms": 0o600,
         "compress_type": zipfile.ZIP_STORED,
     })
 
@@ -257,3 +262,36 @@
     self._test_reset_ZIP64_LIMIT(self._test_ZipWriteStr, "foo", "")
     zinfo = zipfile.ZipInfo(filename="foo")
     self._test_reset_ZIP64_LIMIT(self._test_ZipWriteStr, zinfo, "")
+
+  def test_bug21309935(self):
+    zip_file = tempfile.NamedTemporaryFile(delete=False)
+    zip_file_name = zip_file.name
+    zip_file.close()
+
+    try:
+      random_string = os.urandom(1024)
+      zip_file = zipfile.ZipFile(zip_file_name, "w")
+      # Default perms should be 0o644 when passing the filename.
+      common.ZipWriteStr(zip_file, "foo", random_string)
+      # Honor the specified perms.
+      common.ZipWriteStr(zip_file, "bar", random_string, perms=0o755)
+      # The perms in zinfo should be untouched.
+      zinfo = zipfile.ZipInfo(filename="baz")
+      zinfo.external_attr = 0o740 << 16
+      common.ZipWriteStr(zip_file, zinfo, random_string)
+      # Explicitly specified perms has the priority.
+      zinfo = zipfile.ZipInfo(filename="qux")
+      zinfo.external_attr = 0o700 << 16
+      common.ZipWriteStr(zip_file, zinfo, random_string, perms=0o400)
+      common.ZipClose(zip_file)
+
+      self._verify(zip_file, zip_file_name, "foo", random_string,
+                   expected_mode=0o644)
+      self._verify(zip_file, zip_file_name, "bar", random_string,
+                   expected_mode=0o755)
+      self._verify(zip_file, zip_file_name, "baz", random_string,
+                   expected_mode=0o740)
+      self._verify(zip_file, zip_file_name, "qux", random_string,
+                   expected_mode=0o400)
+    finally:
+      os.remove(zip_file_name)