/**
* Creates an Intent that can be used to launch a {@link CustomTabActivity}.
*/
public static Intent createCustomTabActivityIntent(
Context context, Intent intent, boolean addHerbExtras) {
// Use the copy constructor to carry over the myriad of extras.
Uri uri = Uri.parse(IntentHandler.getUrlFromIntent(intent));
Intent newIntent = new Intent(intent);
newIntent.setAction(Intent.ACTION_VIEW);
newIntent.setClassName(context, CustomTabActivity.class.getName());
newIntent.setData(uri);
// If a CCT intent triggers First Run, then NEW_TASK will be automatically applied. As
// part of that, it will inherit the EXCLUDE_FROM_RECENTS bit from ChromeLauncherActivity,
// so explicitly remove it to ensure the CCT does not get lost in recents.
if ((newIntent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0
|| (newIntent.getFlags() & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) != 0) {
newIntent.setFlags(
newIntent.getFlags() & ~Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
}
if (addHerbExtras) {
// TODO(tedchoc|mariakhomenko): Specifically not marking the intent is from Chrome via
// IntentHandler.addTrustedIntentExtras as it breaks the
// redirect logic for triggering instant apps. See if
// this is better addressed in TabRedirectHandler long
// term.
newIntent.putExtra(CustomTabIntentDataProvider.EXTRA_IS_OPENED_BY_CHROME, true);
} else {
IntentUtils.safeRemoveExtra(
intent, CustomTabIntentDataProvider.EXTRA_IS_OPENED_BY_CHROME);
}
if (addHerbExtras) updateHerbIntent(context, newIntent);
return newIntent;
}