From c905f18e37225b1a61eb20c5292bf1843e28c66a Mon Sep 17 00:00:00 2001 From: Jens Trillmann Date: Wed, 5 Jul 2023 09:33:03 +0200 Subject: [PATCH] Improve Intent source app detection Activity.getReferrer does not only return app IDs but also URLs if Intent.EXTRA_REFERRER is set on the Intent. In the case of Chrome the referrer is set to the website triggering the Intent. To improve the detection of the calling app we check first if the browser specific Browser.EXTRAS_APPLICATION_ID is set. If it is not set we fall back to Intent.getReferrer. Change-Id: I33d1edd52de98486d9616713e531ea20ada87bcb Reviewed-by: Assam Boudjelthia (cherry picked from commit 7012bea614fb47a07a4626c2e2e2855dba3742b4) Reviewed-by: Qt Cherry-pick Bot --- .../qtproject/qt/android/bindings/QtActivity.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/android/java/src/org/qtproject/qt/android/bindings/QtActivity.java b/src/android/java/src/org/qtproject/qt/android/bindings/QtActivity.java index 94d3c2dee17..f85218c1546 100644 --- a/src/android/java/src/org/qtproject/qt/android/bindings/QtActivity.java +++ b/src/android/java/src/org/qtproject/qt/android/bindings/QtActivity.java @@ -16,6 +16,7 @@ import android.graphics.Canvas; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.provider.Browser; import android.util.AttributeSet; import android.view.ActionMode; import android.view.ActionMode.Callback; @@ -242,10 +243,18 @@ public class QtActivity extends Activity if (intent.getExtras() != null && intent.getExtras().getString(EXTRA_SOURCE_INFO) != null) return; + String browserApplicationId = ""; + if (intent.getExtras() != null) + browserApplicationId = intent.getExtras().getString(Browser.EXTRA_APPLICATION_ID); + String sourceInformation = ""; - Uri referrer = getReferrer(); - if (referrer != null) - sourceInformation = referrer.toString().replaceFirst("android-app://", ""); + if (browserApplicationId != null && !browserApplicationId.isEmpty()) { + sourceInformation = browserApplicationId; + } else { + Uri referrer = getReferrer(); + if (referrer != null) + sourceInformation = referrer.toString().replaceFirst("android-app://", ""); + } intent.putExtra(EXTRA_SOURCE_INFO, sourceInformation); }