Skip to content

Use custom tab only for web actions #2310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ private void notifyFiamDismiss() {
}

private void launchUriIntent(Activity activity, Uri uri) {
if (supportsCustomTabs(activity)) {
if (ishttpOrHttpsUri(uri) && supportsCustomTabs(activity)) {
// If we can launch a chrome view, try that.
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();
Intent intent = customTabsIntent.intent;
Expand Down Expand Up @@ -563,4 +563,12 @@ private boolean supportsCustomTabs(Activity activity) {
activity.getPackageManager().queryIntentServices(customTabIntent, 0);
return resolveInfos != null && !resolveInfos.isEmpty();
}

private boolean ishttpOrHttpsUri(Uri uri) {
if (uri == null) {
return false;
}
String scheme = uri.getScheme();
return scheme != null && (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import static com.google.firebase.inappmessaging.testutil.TestData.CARD_MESSAGE_MODEL;
import static com.google.firebase.inappmessaging.testutil.TestData.IMAGE_MESSAGE_MODEL;
import static com.google.firebase.inappmessaging.testutil.TestData.IMAGE_MESSAGE_MODEL_WITHOUT_ACTION;
import static com.google.firebase.inappmessaging.testutil.TestData.IMAGE_MESSAGE_WEB_ACTION_MODEL;
import static com.google.firebase.inappmessaging.testutil.TestData.IMAGE_URL_STRING;
import static com.google.firebase.inappmessaging.testutil.TestData.MODAL_MESSAGE_MODEL;
import static com.google.firebase.inappmessaging.testutil.TestData.WEB_ACTION_URL_STRING;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -589,12 +591,15 @@ public void fiamClickListener_whenActionUrlProvided_andChromeAvailable_opensCust
customTabIntent.setPackage("com.android.chrome");
shadowPackageManager.addResolveInfoForIntent(customTabIntent, resolveInfo);
resumeActivity(activity);
listener.displayMessage(IMAGE_MESSAGE_MODEL, callbacks);
listener.displayMessage(IMAGE_MESSAGE_WEB_ACTION_MODEL, callbacks);
verify(imageBindingWrapper)
.inflate(onClickListenerArgCaptor.capture(), any(OnClickListener.class));
onClickListenerArgCaptor.getValue().get(IMAGE_MESSAGE_MODEL.getAction()).onClick(null);
onClickListenerArgCaptor
.getValue()
.get(IMAGE_MESSAGE_WEB_ACTION_MODEL.getAction())
.onClick(null);
assertThat(shadowActivity.getNextStartedActivity().getData())
.isEqualTo(Uri.parse(ACTION_URL_STRING));
.isEqualTo(Uri.parse(WEB_ACTION_URL_STRING));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public class TestData {
Button.builder().setText(BUTTON_TEXT_MODEL).setButtonHexColor(BUTTON_BG_STRING).build();

// ************************* ACTION *************************
public static final String ACTION_URL_STRING = "action_url";
public static final String ACTION_URL_STRING = "fiam://action_url";
public static final String WEB_ACTION_URL_STRING = "http://action_url";
public static final String SECONDARY_ACTION_URL_STRING = "secondary_action";
public static final Action ACTION_MODEL_WITHOUT_BUTTON =
Action.builder().setActionUrl(ACTION_URL_STRING).build();
Expand All @@ -89,6 +90,8 @@ public class TestData {
Action.builder().setActionUrl(ACTION_URL_STRING).setButton(BUTTON_MODEL).build();
public static final Action SECONDARY_ACTION_MODEL_WITH_BUTTON =
Action.builder().setActionUrl(SECONDARY_ACTION_URL_STRING).setButton(BUTTON_MODEL).build();
public static final Action WEB_ACTION_MODEL_WITHOUT_BUTTON =
Action.builder().setActionUrl(WEB_ACTION_URL_STRING).build();

// ************************* BANNER *************************
public static final BannerMessage BANNER_MESSAGE_MODEL =
Expand Down Expand Up @@ -156,6 +159,12 @@ public class TestData {
.setImageData(IMAGE_DATA)
.build(CAMPAIGN_METADATA_MODEL, DATA);

public static final ImageOnlyMessage IMAGE_MESSAGE_WEB_ACTION_MODEL =
ImageOnlyMessage.builder()
.setAction(WEB_ACTION_MODEL_WITHOUT_BUTTON)
.setImageData(IMAGE_DATA)
.build(CAMPAIGN_METADATA_MODEL, DATA);

public static final ImageOnlyMessage IMAGE_MESSAGE_MODEL_WITHOUT_ACTION =
ImageOnlyMessage.builder().setImageData(IMAGE_DATA).build(CAMPAIGN_METADATA_MODEL, DATA);

Expand Down