From d9a4cb1c3c3eb210c8c568a22223dffc19c3ff52 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 5ff93a13e7..cf19ad98c5 100644 --- a/core/sysprop.mk +++ b/core/sysprop.mk @@ -207,7 +207,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 83f357502808be05551048ed6c4c4fe00baea54c 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 cf19ad98c5..1755e12441 100644 --- a/core/sysprop.mk +++ b/core/sysprop.mk @@ -206,8 +206,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 132fc22a10ee5506e3ebf1ffe097e457ae1c6d7b 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 eb429cdd5c..14b2b7fd01 100644 --- a/core/app_prebuilt_internal.mk +++ b/core/app_prebuilt_internal.mk @@ -250,6 +250,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 1c8baff1ae..a7d4beed08 100644 --- a/core/config.mk +++ b/core/config.mk @@ -651,6 +651,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 0c46de9fc6..e475790804 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -3845,3 +3845,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 cb5bf5b9caf4d96b5260b060db94643e02909c9b 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 9e643629fe59cef6780eacd8d601d3c1af876630 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 c19b0754af..00b7f66ea5 100644 --- a/core/Makefile +++ b/core/Makefile @@ -6902,7 +6902,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 1eb4d5527e7d47111164ed7ade5fd871843da1f4 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 5097f1266f..9acbe01ae1 100644 --- a/core/tasks/sdk-addon.mk +++ b/core/tasks/sdk-addon.mk @@ -122,7 +122,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)/data -- GitLab