Tighter control of stripping in dex_preopt_odex_install.

- Move logic to uncompress dexs in an APK in dex_preopt_odex_install.mk
  and definitions.mk.
- Explicitly mark nostripping cases where dexpreopt will not embed the dex
  file in the APK.

bug: 63920015
Test: m
Test: verify priv-apps dexs are uncompressed and unstripped
Test: Verify a non priv-app APK with uncompressed dex doesn't get stripped.

Change-Id: I624a03e3d965cebc0cae43fd6f7a6260178e6b8a
diff --git a/core/definitions.mk b/core/definitions.mk
index a20bf44..9727275 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -2781,18 +2781,22 @@
 # $(3): LOCAL_DEX_PREOPT, if nostripping then leave classes*.dex
 define dexpreopt-copy-jar
 $(2): $(1)
-	@echo $(if $(filter nostripping,$(3)),"Copy: $$@","Copy without dex: $$@")
+	@echo "Copy: $$@"
 	$$(copy-file-to-target)
 	$(if $(filter nostripping,$(3)),,$$(call dexpreopt-remove-classes.dex,$$@))
 endef
 
-# $(1): the .jar or .apk to remove classes.dex
+# $(1): the .jar or .apk to remove classes.dex. Note that if all dex files
+# are uncompressed in the archive, then dexopt will not do a copy of the dex
+# files and we should not strip.
 define dexpreopt-remove-classes.dex
-$(hide) zip --quiet --delete $(1) classes.dex; \
+$(hide) if (zipinfo $1 '*.dex' 2>/dev/null | grep -v ' stor ' >/dev/null) ; then \
+zip --quiet --delete $(1) classes.dex; \
 dex_index=2; \
 while zip --quiet --delete $(1) classes$${dex_index}.dex > /dev/null; do \
   let dex_index=dex_index+1; \
-done
+done \
+fi
 endef
 
 ###########################################################