merge in oc-release history after reset to master
diff --git a/core/Makefile b/core/Makefile
index c898e7d..acc1a65 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -2234,7 +2234,7 @@
 	@# Zip everything up, preserving symlinks and placing META/ files first to
 	@# help early validation of the .zip file while uploading it.
 	$(hide) find $(zip_root)/META | sort >$@.list
-	$(hide) find $(zip_root) | grep -v "^$(zip_root)/META/" | sort >>$@.list
+	$(hide) find $(zip_root) -path $(zip_root)/META -prune -o -print | sort >>$@.list
 	$(hide) $(SOONG_ZIP) -d -o $@ -C $(zip_root) -l $@.list
 
 .PHONY: target-files-package
@@ -2273,6 +2273,7 @@
 	$(hide) PATH=$(foreach p,$(INTERNAL_USERIMAGES_BINARY_PATHS),$(p):)$$PATH MKBOOTIMG=$(MKBOOTIMG) \
 	   ./build/tools/releasetools/ota_from_target_files -v \
 	   --block \
+	   --extracted_input_target_files $(patsubst %.zip,%,$(BUILT_TARGET_FILES_PACKAGE)) \
 	   -p $(HOST_OUT) \
 	   -k $(KEY_CERT_PAIR) \
 	   $(if $(OEM_OTA_CONFIG), -o $(OEM_OTA_CONFIG)) \
diff --git a/core/build_id.mk b/core/build_id.mk
index 5bac4d6..0e8e2cf 100644
--- a/core/build_id.mk
+++ b/core/build_id.mk
@@ -13,21 +13,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-# BUILD_ID is of the form NPM1.YYMMDD.nnn
-#
-# N - dessert designator
-# P - vertical, or category of release
-# M1 - release abbreviation
-# YY - year
-# MM - month
-# DD - day
-# nnn - the patch sequence, starting at 001 for the initial snap
-#
-# OPAT.161221.002
-#
-# See also:
-#
-# https://docs.google.com/document/d/17eqVTxMc2do05T6qwt4eASVyxy8u3Cme4u4fVD5q0VM/view#
-#
+# BUILD_ID is usually used to specify the branch name
+# (like "MAIN") or a branch name and a release candidate
+# (like "CRB01").  It must be a single word, and is
+# capitalized by convention.
 
-export BUILD_ID=OPR1.170321.003
+export BUILD_ID=MASTER
diff --git a/core/definitions.mk b/core/definitions.mk
index 62942ee..159073e 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -2521,6 +2521,13 @@
 $(filter-out -classpath -bootclasspath "",$(subst :,$(space),$(1)))
 endef
 
+# Takes an sdk version that might be PLATFORM_VERSION_CODENAME (for example P),
+# returns a number greater than the highest existing sdk version if it is, or
+# the input if it is not.
+define codename-or-sdk-to-sdk
+$(if $(filter $(1),$(PLATFORM_VERSION_CODENAME)),10000,$(1))
+endef
+
 define desugar-classes-jar
 @echo Desugar: $@
 @mkdir -p $(dir $@)
@@ -2528,7 +2535,7 @@
 $(hide) java -jar $(DESUGAR) \
     $(addprefix --bootclasspath_entry ,$(call desugar-bootclasspath,$(PRIVATE_BOOTCLASSPATH))) \
     $(addprefix --classpath_entry ,$(PRIVATE_ALL_JAVA_LIBRARIES)) \
-    --min_sdk_version $(PRIVATE_SDK_VERSION) \
+    --min_sdk_version $(call codename-or-sdk-to-sdk,$(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
     --allow_empty_bootclasspath \
     $(if $(filter --core-library,$(PRIVATE_DX_FLAGS)),--core_library) \
     -i $< -o $@.tmp
@@ -2545,7 +2552,7 @@
 $(hide) $(DX) \
     -JXms16M -JXmx2048M \
     --dex --output=$(dir $@) \
-    --min-sdk-version=$(PRIVATE_SDK_VERSION) \
+    --min-sdk-version=$(call codename-or-sdk-to-sdk,$(PRIVATE_DEFAULT_APP_TARGET_SDK)) \
     $(if $(NO_OPTIMIZE_DX), \
         --no-optimize) \
     $(if $(GENERATE_DEX_DEBUG), \
diff --git a/core/java.mk b/core/java.mk
index 2864e56..175311c 100644
--- a/core/java.mk
+++ b/core/java.mk
@@ -466,12 +466,14 @@
 my_desugaring :=
 ifndef LOCAL_JACK_ENABLED
 ifeq ($(LOCAL_JAVA_LANGUAGE_VERSION),1.8)
+ifndef LOCAL_IS_STATIC_JAVA_LIBRARY
 my_desugaring := true
 $(full_classes_desugar_jar): PRIVATE_DX_FLAGS := $(LOCAL_DX_FLAGS)
 $(full_classes_desugar_jar): $(full_classes_compiled_jar) $(DESUGAR)
 	$(desugar-classes-jar)
 endif
 endif
+endif
 
 ifndef my_desugaring
 full_classes_desugar_jar := $(full_classes_compiled_jar)
diff --git a/core/version_defaults.mk b/core/version_defaults.mk
index 6b19ad2..2efff77 100644
--- a/core/version_defaults.mk
+++ b/core/version_defaults.mk
@@ -52,17 +52,22 @@
 #$(warning $(call find_and_earlier,A B C,D))
 
 define version-list
-$(1) $(1)DR1 $(1)DR2 $(1)MR1 $(1)MR2
+$(1)PR1 $(1)PD1 $(1)PD2 $(1)PM1 $(1)PM2
 endef
 
 ALL_VERSIONS := O P
 ALL_VERSIONS := $(foreach v,$(ALL_VERSIONS),$(call version-list,$(v)))
 
+# HACK: forward P to PPR1 until the build server config is updated
+ifeq (P,$(TARGET_PLATFORM_VERSION))
+  TARGET_PLATFORM_VERSION := PPR1
+endif
+
 ifeq (,$(TARGET_PLATFORM_VERSION))
   # Default targeted platform version
   # TODO: PLATFORM_VERSION, PLATFORM_SDK_VERSION, etc. should be conditional
   # on this
-  TARGET_PLATFORM_VERSION := O
+  TARGET_PLATFORM_VERSION := OPR1
 endif
 
 ifeq (,$(filter $(ALL_VERSIONS), $(TARGET_PLATFORM_VERSION)))
@@ -91,11 +96,11 @@
 # When you change PLATFORM_VERSION for a given PLATFORM_SDK_VERSION
 # please add that PLATFORM_VERSION to the following text file:
 # cts/tests/tests/os/assets/platform_versions.txt
-PLATFORM_VERSION.O := O
+PLATFORM_VERSION.OPR1 := O
 
 # 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.O := O
+PLATFORM_VERSION_CODENAME.OPR1 := O
 
 ifndef PLATFORM_VERSION
   PLATFORM_VERSION := $(PLATFORM_VERSION.$(TARGET_PLATFORM_VERSION))
diff --git a/target/product/base.mk b/target/product/base.mk
index 1d49c75c..239aabd 100644
--- a/target/product/base.mk
+++ b/target/product/base.mk
@@ -114,7 +114,6 @@
     mediadrmserver \
     mediaserver \
     mediametrics \
-    mediacodec \
     mediaextractor \
     monkey \
     mtpd \
@@ -142,6 +141,10 @@
     vold \
     wm
 
+# Essential HAL modules
+PRODUCT_PACKAGES += \
+    android.hardware.media.omx@1.0-service
+
 # Packages included only for eng or userdebug builds, previously debug tagged
 PRODUCT_PACKAGES_DEBUG := \
     perfprofd
diff --git a/target/product/embedded.mk b/target/product/embedded.mk
index f55d9a9..5ee297a 100644
--- a/target/product/embedded.mk
+++ b/target/product/embedded.mk
@@ -20,7 +20,6 @@
 PRODUCT_PACKAGES += \
     adb \
     adbd \
-    android.hardware.configstore@1.0-impl \
     android.hardware.configstore@1.0-service \
     android.hidl.allocator@1.0-service \
     android.hidl.memory@1.0-impl \
diff --git a/tools/releasetools/ota_from_target_files.py b/tools/releasetools/ota_from_target_files.py
index 8222377..c3f063f 100755
--- a/tools/releasetools/ota_from_target_files.py
+++ b/tools/releasetools/ota_from_target_files.py
@@ -1235,6 +1235,8 @@
       OPTIONS.payload_signer = a
     elif o == "--payload_signer_args":
       OPTIONS.payload_signer_args = shlex.split(a)
+    elif o == "--extracted_input_target_files":
+      OPTIONS.extracted_input = a
     else:
       return False
     return True
@@ -1265,6 +1267,7 @@
                                  "log_diff=",
                                  "payload_signer=",
                                  "payload_signer_args=",
+                                 "extracted_input_target_files=",
                              ], extra_option_handler=option_handler)
 
   if len(args) != 2:
@@ -1287,9 +1290,12 @@
 
   # Load the dict file from the zip directly to have a peek at the OTA type.
   # For packages using A/B update, unzipping is not needed.
-  input_zip = zipfile.ZipFile(args[0], "r")
-  OPTIONS.info_dict = common.LoadInfoDict(input_zip)
-  common.ZipClose(input_zip)
+  if OPTIONS.extracted_input is not None:
+    OPTIONS.info_dict = common.LoadInfoDict(OPTIONS.extracted_input, OPTIONS.extracted_input)
+  else:
+    input_zip = zipfile.ZipFile(args[0], "r")
+    OPTIONS.info_dict = common.LoadInfoDict(input_zip)
+    common.ZipClose(input_zip)
 
   ab_update = OPTIONS.info_dict.get("ab_update") == "true"
 
@@ -1319,12 +1325,18 @@
   if OPTIONS.extra_script is not None:
     OPTIONS.extra_script = open(OPTIONS.extra_script).read()
 
-  print("unzipping target target-files...")
-  OPTIONS.input_tmp, input_zip = common.UnzipTemp(
-      args[0], UNZIP_PATTERN)
+  if OPTIONS.extracted_input is not None:
+    OPTIONS.input_tmp = OPTIONS.extracted_input
+    OPTIONS.target_tmp = OPTIONS.input_tmp
+    OPTIONS.info_dict = common.LoadInfoDict(OPTIONS.input_tmp, OPTIONS.input_tmp)
+    input_zip = zipfile.ZipFile(args[0], "r")
+  else:
+    print("unzipping target target-files...")
+    OPTIONS.input_tmp, input_zip = common.UnzipTemp(
+        args[0], UNZIP_PATTERN)
 
-  OPTIONS.target_tmp = OPTIONS.input_tmp
-  OPTIONS.info_dict = common.LoadInfoDict(input_zip, OPTIONS.target_tmp)
+    OPTIONS.target_tmp = OPTIONS.input_tmp
+    OPTIONS.info_dict = common.LoadInfoDict(input_zip, OPTIONS.target_tmp)
 
   if OPTIONS.verbose:
     print("--- target info ---")