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 <assam.boudjelthia@qt.io>
(cherry picked from commit 7012bea614fb47a07a4626c2e2e2855dba3742b4)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Jens Trillmann 2023-07-05 09:33:03 +02:00 committed by Qt Cherry-pick Bot
parent 687af7b1a9
commit c905f18e37

View File

@ -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);
}