From 4a574954065d7f03e9d9f1d8e24a09068b552b9f Mon Sep 17 00:00:00 2001 From: Sumit Pundir Date: Thu, 20 Aug 2020 21:54:03 +0530 Subject: [PATCH 1/6] core/Makefile: Update Build Description --- core/sysprop.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/sysprop.mk b/core/sysprop.mk index 0fcc92c84f..18eaef5954 100644 --- a/core/sysprop.mk +++ b/core/sysprop.mk @@ -221,7 +221,7 @@ BUILD_THUMBPRINT := # # BUILD_ID: detail info; has the same info as the build fingerprint -BUILD_DESC := $(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER_FROM_FILE) $(BUILD_VERSION_TAGS) +BUILD_DESC := e_$(TARGET_DEVICE)-$(TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER_FROM_FILE) $(BUILD_VERSION_TAGS) # BUILD_DISPLAY_ID is shown under Settings -> About Phone ifeq ($(TARGET_BUILD_VARIANT),user) -- GitLab From 1f0bb7f9415326f3326a8a95a19c2af5f6b0c0ab Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Tue, 4 Oct 2022 13:38:47 +0200 Subject: [PATCH 2/6] Spoof target build variant for Whatsapp Whatsapp was detecting us as a custom ROM because our display id contained the "debug" pattern. --- core/sysprop.mk | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/sysprop.mk b/core/sysprop.mk index 18eaef5954..563916360a 100644 --- a/core/sysprop.mk +++ b/core/sysprop.mk @@ -220,8 +220,15 @@ BUILD_THUMBPRINT := # Define human readable strings that describe this build # +# Spoof target build variant because Whatsapp (and maybe others) +# is checking the "debug" pattern in the Build.DISPLAY variable. +SPOOFED_TARGET_BUILD_VARIANT := $(TARGET_BUILD_VARIANT) +ifeq (userdebug,$(TARGET_BUILD_VARIANT)) + SPOOFED_TARGET_BUILD_VARIANT := user +endif + # BUILD_ID: detail info; has the same info as the build fingerprint -BUILD_DESC := e_$(TARGET_DEVICE)-$(TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER_FROM_FILE) $(BUILD_VERSION_TAGS) +BUILD_DESC := e_$(TARGET_DEVICE)-$(SPOOFED_TARGET_BUILD_VARIANT) $(PLATFORM_VERSION) $(BUILD_ID) $(BUILD_NUMBER_FROM_FILE) $(BUILD_VERSION_TAGS) # BUILD_DISPLAY_ID is shown under Settings -> About Phone ifeq ($(TARGET_BUILD_VARIANT),user) -- GitLab From 84a488bf2b585301f431b95494cfde37eea14d14 Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Wed, 14 Dec 2022 11:51:20 +0000 Subject: [PATCH 3/6] make: Add Patch Trichrome script * inspired form calyx and https://github.com/danielfullmer/robotnix/blob/master/modules/apps/chromium-trichrome-patcher.py --- core/app_prebuilt_internal.mk | 1 + core/config.mk | 2 ++ core/definitions.mk | 5 ++++ tools/chromium_trichrome_patcher.py | 36 +++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100755 tools/chromium_trichrome_patcher.py diff --git a/core/app_prebuilt_internal.mk b/core/app_prebuilt_internal.mk index 2671956c7a..d7fc5e2770 100644 --- a/core/app_prebuilt_internal.mk +++ b/core/app_prebuilt_internal.mk @@ -245,6 +245,7 @@ ifeq ($(module_run_appcompat),true) $(call appcompat-header, aapt2) $(run-appcompat) endif # module_run_appcompat + $(patch-trichrome) $(sign-package) # No need for align-package because sign-package takes care of alignment else # LOCAL_CERTIFICATE == PRESIGNED diff --git a/core/config.mk b/core/config.mk index a8a5e5f711..2bc2896bd9 100644 --- a/core/config.mk +++ b/core/config.mk @@ -749,6 +749,8 @@ JETIFIER := prebuilts/sdk/tools/jetifier/jetifier-standalone/bin/jetifier-standa EXTRACT_KERNEL := build/make/tools/extract_kernel.py +PATCH_TRICHROME := build/make/tools/chromium_trichrome_patcher.py + # Path to tools.jar HOST_JDK_TOOLS_JAR := $(ANDROID_JAVA8_HOME)/lib/tools.jar diff --git a/core/definitions.mk b/core/definitions.mk index 8a781e9982..4cf34a2e89 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -4024,3 +4024,8 @@ define use_soong_sdk_libraries $(foreach l,$(1),$(if $(filter $(l),$(SOONG_SDK_VARIANT_MODULES)),\ $(l).sdk,$(l))) endef + +# Patch Trichrome to add cert digest at buildtime +define patch-trichrome +$(hide) $(PATCH_TRICHROME) $@ $(PRIVATE_CERTIFICATE) +endef diff --git a/tools/chromium_trichrome_patcher.py b/tools/chromium_trichrome_patcher.py new file mode 100755 index 0000000000..06cdea0448 --- /dev/null +++ b/tools/chromium_trichrome_patcher.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +import os +import subprocess +import sys +import zipfile + +infilename, sign_key = sys.argv[1:] + +def ExtractFingerprint(cert): + cmd = ['openssl', 'x509', '-sha256', '-fingerprint', '-noout', '-in', cert] + proc = subprocess.run(cmd, stdout=subprocess.PIPE) + return proc.stdout.decode('utf-8').split('=')[1].replace(':', '') + +def patch_trichrome(infilename, sign_key): + orig_certdigest = "32a2fc74d731105859e5a85df16d95f102d85b22099b8064c5d8915c61dad1e0" + new_certdigest = ExtractFingerprint(sign_key).lower().rstrip() + + with zipfile.ZipFile(infilename, 'r') as zin, zipfile.ZipFile(infilename + ".patched", 'w') as zout: + for info in zin.infolist(): + data = zin.read(info.filename) + if info.filename == 'AndroidManifest.xml': + # Make sure we can find the certdigest + data.rindex(orig_certdigest.encode('utf-16-le')) + # Replace it + data = data.replace(orig_certdigest.encode('utf-16-le'), new_certdigest.encode('utf-16-le')) + zout.writestr(info, data) + + # Delete the original file + os.remove(infilename) + + # Rename the output file to the original file name + os.rename(infilename + ".patched", infilename) + +if "Browser_" in infilename or "BrowserWebView_" in infilename: + patch_trichrome(infilename, sign_key) -- GitLab From 7a72356d9e362c8faf05f6428f2584ed477d92d6 Mon Sep 17 00:00:00 2001 From: althafvly Date: Wed, 21 Dec 2022 15:43:03 +0530 Subject: [PATCH 4/6] make: Catch exception for no certdigest - Fixes build for non-trichrome browser apks --- tools/chromium_trichrome_patcher.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/chromium_trichrome_patcher.py b/tools/chromium_trichrome_patcher.py index 06cdea0448..bda96b3fa6 100755 --- a/tools/chromium_trichrome_patcher.py +++ b/tools/chromium_trichrome_patcher.py @@ -21,7 +21,10 @@ def patch_trichrome(infilename, sign_key): data = zin.read(info.filename) if info.filename == 'AndroidManifest.xml': # Make sure we can find the certdigest - data.rindex(orig_certdigest.encode('utf-16-le')) + try: + data.rindex(orig_certdigest.encode('utf-16-le')) + except: + pass # Replace it data = data.replace(orig_certdigest.encode('utf-16-le'), new_certdigest.encode('utf-16-le')) zout.writestr(info, data) -- GitLab From 6f05b3f213b76b8a0464b52636b6d0c65c467c23 Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Thu, 26 Jan 2023 18:13:16 +0000 Subject: [PATCH 5/6] build: dont't leave sdk_addon out Change-Id: I4455b6d181bde0c3845f40e751a82f2604f70efd --- core/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Makefile b/core/Makefile index 68179f76ff..313240b0e8 100644 --- a/core/Makefile +++ b/core/Makefile @@ -7598,7 +7598,7 @@ endif # ----------------------------------------------------------------- # The SDK -ifneq ($(filter sdk,$(MAKECMDGOALS)),) +ifneq ($(filter sdk sdk_addon,$(MAKECMDGOALS)),) # The SDK includes host-specific components, so it belongs under HOST_OUT. sdk_dir := $(HOST_OUT)/sdk/$(TARGET_PRODUCT) -- GitLab From 8990c6c5dad44015746d4f36b997db6f332c7913 Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Fri, 27 Jan 2023 08:01:29 +0000 Subject: [PATCH 6/6] [dnm]: Specify userdata for sdk_addon Change-Id: I372f0c2cd91248070a80a131283b1ea0ae61fb27 --- core/tasks/sdk-addon.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/tasks/sdk-addon.mk b/core/tasks/sdk-addon.mk index 2fd4ce9ec7..7d16220014 100644 --- a/core/tasks/sdk-addon.mk +++ b/core/tasks/sdk-addon.mk @@ -123,7 +123,7 @@ $(full_target): $(sdk_addon_deps) | $(SOONG_ZIP) $(hide) $(SOONG_ZIP) -o $@ -C $(dir $(PRIVATE_STAGING_DIR)) -D $(PRIVATE_STAGING_DIR) $(full_target_img): PRIVATE_STAGING_DIR := $(call append-path,$(staging),$(addon_dir_img))/images/$(TARGET_CPU_ABI) -$(full_target_img): $(full_target) $(addon_img_source_prop) | $(SOONG_ZIP) +$(full_target_img): $(full_target) $(INSTALLED_USERDATAIMAGE_TARGET) $(addon_img_source_prop) | $(SOONG_ZIP) @echo Packaging SDK Addon System-Image: $@ $(hide) mkdir -p $(dir $@) cp -R $(PRODUCT_OUT)/data $(PRIVATE_STAGING_DIR) -- GitLab