diff --git a/core/app_prebuilt_internal.mk b/core/app_prebuilt_internal.mk index dd263dd330..69f411ce75 100644 --- a/core/app_prebuilt_internal.mk +++ b/core/app_prebuilt_internal.mk @@ -92,6 +92,32 @@ my_preopt_for_extracted_apk := true endif endif +# Verify LOCAL_USES_LIBRARIES/LOCAL_OPTIONAL_USES_LIBRARIES +# If LOCAL_ENFORCE_USES_LIBRARIES is not set, default to true if either of LOCAL_USES_LIBRARIES or +# LOCAL_OPTIONAL_USES_LIBRARIES are specified. +# Will change the default to true unconditionally in the future. +ifndef LOCAL_ENFORCE_USES_LIBRARIES + ifneq (,$(strip $(LOCAL_USES_LIBRARIES)$(LOCAL_OPTIONAL_USES_LIBRARIES))) + LOCAL_ENFORCE_USES_LIBRARIES := true + endif +endif + +my_enforced_uses_libraries := +ifdef LOCAL_ENFORCE_USES_LIBRARIES + my_enforced_uses_libraries := $(intermediates.COMMON)/enforce_uses_libraries.timestamp + $(my_enforced_uses_libraries): PRIVATE_USES_LIBRARIES := $(LOCAL_USES_LIBRARIES) + $(my_enforced_uses_libraries): PRIVATE_OPTIONAL_USES_LIBRARIES := $(LOCAL_OPTIONAL_USES_LIBRARIES) + $(my_enforced_uses_libraries): $(BUILD_SYSTEM)/verify_uses_libraries.sh $(AAPT) + $(my_enforced_uses_libraries): $(my_prebuilt_src_file) + @echo Verifying uses-libraries: $< + aapt_binary=$(AAPT) \ + uses_library_names="$(strip $(PRIVATE_USES_LIBRARIES))" \ + optional_uses_library_names="$(strip $(PRIVATE_OPTIONAL_USES_LIBRARIES))" \ + $(BUILD_SYSTEM)/verify_uses_libraries.sh $< + touch $@ + $(built_module) : $(my_enforced_uses_libraries) +endif + dex_preopt_profile_src_file := $(my_prebuilt_src_file) rs_compatibility_jni_libs := diff --git a/core/construct_context.sh b/core/construct_context.sh index 399c15d629..794795a7b5 100755 --- a/core/construct_context.sh +++ b/core/construct_context.sh @@ -22,6 +22,11 @@ set -e # class_loader_context_arg: final class loader conext arg # stored_class_loader_context_arg: final stored class loader context arg +if [ -z "${target_sdk_version}" ]; then + echo "ERROR: target_sdk_version not set" + exit 2 +fi + # The hidl.manager shared library has a dependency on hidl.base. We'll manually # add that information to the class loader context if we see those libraries. hidl_manager="android.hidl.manager-V1.0-java" diff --git a/core/dex_preopt_config.mk b/core/dex_preopt_config.mk index c44e4bdb5f..5693147d0a 100644 --- a/core/dex_preopt_config.mk +++ b/core/dex_preopt_config.mk @@ -116,7 +116,6 @@ ifeq ($(WRITE_SOONG_VARIABLES),true) $(call add_json_bool, NeverSystemServerDebugInfo, $(filter false,$(PRODUCT_SYSTEM_SERVER_DEBUG_INFO))) $(call add_json_bool, AlwaysOtherDebugInfo, $(filter true,$(PRODUCT_OTHER_JAVA_DEBUG_INFO))) $(call add_json_bool, NeverOtherDebugInfo, $(filter false,$(PRODUCT_OTHER_JAVA_DEBUG_INFO))) - $(call add_json_list, MissingUsesLibraries, $(INTERNAL_PLATFORM_MISSING_USES_LIBRARIES)) $(call add_json_bool, IsEng, $(filter eng,$(TARGET_BUILD_VARIANT))) $(call add_json_bool, SanitizeLite, $(SANITIZE_LITE)) $(call add_json_bool, DefaultAppImages, $(WITH_DEX_PREOPT_APP_IMAGE)) @@ -152,7 +151,7 @@ ifeq ($(WRITE_SOONG_VARIABLES),true) $(call add_json_str, Aapt, $(SOONG_HOST_OUT_EXECUTABLES)/aapt) $(call add_json_str, SoongZip, $(SOONG_ZIP)) $(call add_json_str, Zip2zip, $(ZIP2ZIP)) - $(call add_json_str, VerifyUsesLibraries, $(BUILD_SYSTEM)/verify_uses_libraries.sh) + $(call add_json_str, ManifestCheck, $(SOONG_HOST_OUT_EXECUTABLES)/manifest_check) $(call add_json_str, ConstructContext, $(BUILD_SYSTEM)/construct_context.sh) $(call end_json_map) @@ -175,7 +174,6 @@ DEXPREOPT_GEN_DEPS := \ $(SOONG_HOST_OUT_EXECUTABLES)/aapt \ $(SOONG_ZIP) \ $(ZIP2ZIP) \ - $(BUILD_SYSTEM)/verify_uses_libraries.sh \ $(BUILD_SYSTEM)/construct_context.sh \ DEXPREOPT_STRIP_DEPS := \ diff --git a/core/dex_preopt_odex_install.mk b/core/dex_preopt_odex_install.mk index 152962bcbb..9832c2f075 100644 --- a/core/dex_preopt_odex_install.mk +++ b/core/dex_preopt_odex_install.mk @@ -103,18 +103,6 @@ ifeq (true,$(my_process_profile)) endif endif -# If LOCAL_ENFORCE_USES_LIBRARIES is not set, default to true if either of LOCAL_USES_LIBRARIES or -# LOCAL_OPTIONAL_USES_LIBRARIES are specified. -ifeq (,$(LOCAL_ENFORCE_USES_LIBRARIES)) - # Will change the default to true unconditionally in the future. - ifneq (,$(LOCAL_OPTIONAL_USES_LIBRARIES)) - LOCAL_ENFORCE_USES_LIBRARIES := true - endif - ifneq (,$(LOCAL_USES_LIBRARIES)) - LOCAL_ENFORCE_USES_LIBRARIES := true - endif -endif - my_dexpreopt_archs := my_dexpreopt_images := my_dexpreopt_infix := boot @@ -218,6 +206,7 @@ ifdef LOCAL_DEX_PREOPT $(call add_json_str, Name, $(LOCAL_MODULE)) $(call add_json_str, DexLocation, $(patsubst $(PRODUCT_OUT)%,%,$(LOCAL_INSTALLED_MODULE))) $(call add_json_str, BuildPath, $(LOCAL_BUILT_MODULE)) + $(call add_json_str, ManifestPath, $(full_android_manifest)) $(call add_json_str, ExtrasOutputPath, $$2) $(call add_json_bool, Privileged, $(filter true,$(LOCAL_PRIVILEGED_MODULE))) $(call add_json_bool, UncompressedDex, $(filter true,$(LOCAL_UNCOMPRESS_DEX))) @@ -226,7 +215,7 @@ ifdef LOCAL_DEX_PREOPT $(call add_json_str, ProfileClassListing, $(if $(my_process_profile),$(LOCAL_DEX_PREOPT_PROFILE))) $(call add_json_bool, ProfileIsTextListing, $(my_profile_is_text_listing)) $(call add_json_bool, EnforceUsesLibraries, $(LOCAL_ENFORCE_USES_LIBRARIES)) - $(call add_json_list, OptionalUsesLibraries, $(LOCAL_OPTIONAL_USES_LIBRARIES)) + $(call add_json_list, OptionalUsesLibraries, $(my_filtered_optional_uses_libraries)) $(call add_json_list, UsesLibraries, $(LOCAL_USES_LIBRARIES)) $(call add_json_map, LibraryPaths) $(foreach lib,$(my_dexpreopt_libs),\ diff --git a/core/package_internal.mk b/core/package_internal.mk index 493a0f102f..e2d79cd460 100644 --- a/core/package_internal.mk +++ b/core/package_internal.mk @@ -483,6 +483,31 @@ PACKAGES.$(LOCAL_PACKAGE_NAME).CERTIFICATE := $(certificate) $(LOCAL_BUILT_MODULE): $(additional_certificates) $(LOCAL_BUILT_MODULE): PRIVATE_ADDITIONAL_CERTIFICATES := $(additional_certificates) +# Verify LOCAL_USES_LIBRARIES/LOCAL_OPTIONAL_USES_LIBRARIES +# If LOCAL_ENFORCE_USES_LIBRARIES is not set, default to true if either of LOCAL_USES_LIBRARIES or +# LOCAL_OPTIONAL_USES_LIBRARIES are specified. +# Will change the default to true unconditionally in the future. +ifndef LOCAL_ENFORCE_USES_LIBRARIES + ifneq (,$(strip $(LOCAL_USES_LIBRARIES)$(LOCAL_OPTIONAL_USES_LIBRARIES))) + LOCAL_ENFORCE_USES_LIBRARIES := true + endif +endif + +my_enforced_uses_libraries := +ifdef LOCAL_ENFORCE_USES_LIBRARIES + my_manifest_check := $(intermediates.COMMON)/manifest/AndroidManifest.xml.check + $(my_manifest_check): $(MANIFEST_CHECK) + $(my_manifest_check): PRIVATE_USES_LIBRARIES := $(LOCAL_USES_LIBRARIES) + $(my_manifest_check): PRIVATE_OPTIONAL_USES_LIBRARIES := $(LOCAL_OPTIONAL_USES_LIBRARIES) + $(my_manifest_check): $(full_android_manifest) + @echo Checking manifest: $< + $(MANIFEST_CHECK) --enforce-uses-libraries \ + $(addprefix --uses-library ,$(PRIVATE_USES_LIBRARIES)) \ + $(addprefix --optional-uses-library ,$(PRIVATE_OPTIONAL_USES_LIBRARIES)) \ + $< -o $@ + $(LOCAL_BUILT_MODULE): $(my_manifest_check) +endif + # Define the rule to build the actual package. # PRIVATE_JNI_SHARED_LIBRARIES is a list of :. $(LOCAL_BUILT_MODULE): PRIVATE_JNI_SHARED_LIBRARIES := $(jni_shared_libraries_with_abis) diff --git a/core/soong_config.mk b/core/soong_config.mk index 220e2c89df..0b8e961337 100644 --- a/core/soong_config.mk +++ b/core/soong_config.mk @@ -183,6 +183,8 @@ $(call add_json_bool, ProductCompatibleProperty, $(PRODUCT_COMPATIBLE_PR $(call add_json_list, TargetFSConfigGen, $(TARGET_FS_CONFIG_GEN)) +$(call add_json_list, MissingUsesLibraries, $(INTERNAL_PLATFORM_MISSING_USES_LIBRARIES)) + $(call add_json_map, VendorVars) $(foreach namespace,$(SOONG_CONFIG_NAMESPACES),\ $(call add_json_map, $(namespace))\