Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd7cd391 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Integrate API into App-to-Web" into main

parents 3675ccac a954ef9a
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@

package com.android.wm.shell.apptoweb

import android.app.assist.AssistContent
import android.app.assist.AssistContent.EXTRA_SESSION_TRANSFER_WEB_URI
import android.content.Context
import android.content.Intent
import android.content.Intent.ACTION_VIEW
@@ -102,3 +104,10 @@ fun getDomainVerificationUserState(
        return null
    }
}

/**
 * Returns the web uri from the given [AssistContent].
 */
fun AssistContent.getSessionWebUri(): Uri? {
    return extras.getParcelable(EXTRA_SESSION_TRANSFER_WEB_URI) ?: webUri
}
+4 −4
Original line number Diff line number Diff line
@@ -557,10 +557,10 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
    @Nullable
    private Intent getBrowserLink() {
        final Uri browserLink;
        if (isCapturedLinkAvailable()) {
            browserLink = mCapturedLink.mUri;
        } else if (mWebUri != null) {
        if (mWebUri != null) {
            browserLink = mWebUri;
        } else if (isCapturedLinkAvailable()) {
            browserLink = mCapturedLink.mUri;
        } else {
            browserLink = mGenericLink;
        }
@@ -1317,7 +1317,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
     */
    @VisibleForTesting
    void onAssistContentReceived(@Nullable AssistContent assistContent) {
        mWebUri = assistContent == null ? null : assistContent.getWebUri();
        mWebUri = assistContent == null ? null : AppToWebUtils.getSessionWebUri(assistContent);
        loadAppInfoIfNeeded();
        updateGenericLink();
        final boolean supportsMultiInstance = mMultiInstanceHelper
+50 −14
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.app.assist.AssistContent.EXTRA_SESSION_TRANSFER_WEB_URI;
import static android.platform.test.flag.junit.SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT;
import static android.view.InsetsSource.FLAG_FORCE_CONSUMING;
import static android.view.InsetsSource.FLAG_FORCE_CONSUMING_OPAQUE_CAPTION_BAR;
@@ -157,6 +158,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
    private static final Uri TEST_URI1 = Uri.parse("https://www.google.com/");
    private static final Uri TEST_URI2 = Uri.parse("https://docs.google.com/");
    private static final Uri TEST_URI3 = Uri.parse("https://slides.google.com/");
    private static final Uri TEST_URI4 = Uri.parse("https://calendar.google.com/");

    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(DEVICE_DEFAULT);

@@ -1322,11 +1324,11 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB)
    public void capturedLink_handleMenuBrowserLinkSetToCapturedLinkIfValid() {
    public void capturedLink_CapturedLinkUsedIfValidAndWebUriUnavailable() {
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final DesktopModeWindowDecoration decor = createWindowDecoration(
                taskInfo, TEST_URI1 /* captured link */, TEST_URI2 /* web uri */,
                TEST_URI3 /* generic link */);
                taskInfo, TEST_URI1 /* captured link */, null /* web uri */,
                null /* session transfer uri */, TEST_URI4 /* generic link */);

        // Verify handle menu's browser link set as captured link
        createHandleMenu(decor);
@@ -1339,7 +1341,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final DesktopModeWindowDecoration decor = createWindowDecoration(
                taskInfo, TEST_URI1 /* captured link */, null /* web uri */,
                null /* generic link */);
                null /* session transfer uri */, null /* generic link */);
        final ArgumentCaptor<Function1<Intent, Unit>> openInBrowserCaptor =
                ArgumentCaptor.forClass(Function1.class);

@@ -1373,7 +1375,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final DesktopModeWindowDecoration decor = createWindowDecoration(
                taskInfo, TEST_URI1 /* captured link */, null /* web uri */,
                null /* generic link */);
                null /* session transfer uri */, null /* generic link */);
        final ArgumentCaptor<Function1<Intent, Unit>> openInBrowserCaptor =
                ArgumentCaptor.forClass(Function1.class);

@@ -1406,7 +1408,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final DesktopModeWindowDecoration decor = createWindowDecoration(
                taskInfo, TEST_URI1 /* captured link */, null /* web uri */,
                null /* generic link */);
                null /* session transfer uri */, null /* generic link */);
        final ArgumentCaptor<Function1<Intent, Unit>> openInBrowserCaptor =
                ArgumentCaptor.forClass(Function1.class);
        createHandleMenu(decor);
@@ -1432,11 +1434,23 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB)
    public void webUriLink_webUriLinkUsedWhenCapturedLinkUnavailable() {
    public void webUriLink_webUriLinkUsedWhenWhenAvailable() {
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final DesktopModeWindowDecoration decor = createWindowDecoration(
                taskInfo, null /* captured link */, TEST_URI2 /* web uri */,
                TEST_URI3 /* generic link */);
                taskInfo, TEST_URI1 /* captured link */, TEST_URI2 /* web uri */,
                TEST_URI3 /* session transfer uri */, TEST_URI4 /* generic link */);
        // Verify handle menu's browser link set as web uri link when captured link is unavailable
        createHandleMenu(decor);
        verifyHandleMenuCreated(TEST_URI3);
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB)
    public void webUriLink_webUriLinkUsedWhenSessionTransferUriUnavailable() {
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final DesktopModeWindowDecoration decor = createWindowDecoration(
                taskInfo, TEST_URI1 /* captured link */, TEST_URI2 /* web uri */,
                null /* session transfer uri */, TEST_URI4 /* generic link */);
        // Verify handle menu's browser link set as web uri link when captured link is unavailable
        createHandleMenu(decor);
        verifyHandleMenuCreated(TEST_URI2);
@@ -1448,12 +1462,12 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final DesktopModeWindowDecoration decor = createWindowDecoration(
                taskInfo, null /* captured link */, null /* web uri */,
                TEST_URI3 /* generic link */);
                null /* session transfer uri */, TEST_URI4 /* generic link */);

        // Verify handle menu's browser link set as generic link when captured link and web uri link
        // are unavailable
        createHandleMenu(decor);
        verifyHandleMenuCreated(TEST_URI3);
        verifyHandleMenuCreated(TEST_URI4);
    }

    @Test
@@ -1637,7 +1651,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB)
    public void browserApp_webUriUsedForBrowserApp() {
    public void browserApp_transferSessionUriUsedForBrowserAppWhenAvailable() {
        // Make {@link AppToWebUtils#isBrowserApp} return true
        ResolveInfo resolveInfo = new ResolveInfo();
        resolveInfo.handleAllWebDataURI = true;
@@ -1648,7 +1662,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final DesktopModeWindowDecoration decor = createWindowDecoration(
                taskInfo, TEST_URI1 /* captured link */, TEST_URI2 /* web uri */,
                TEST_URI3 /* generic link */);
                null /* transfer session uri */, TEST_URI4 /* generic link */);

        // Verify web uri used for browser applications
        createHandleMenu(decor);
@@ -1656,6 +1670,27 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
    }


    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB)
    public void browserApp_webUriUsedForBrowserAppWhenTransferSessionUriUnavailable() {
        // Make {@link AppToWebUtils#isBrowserApp} return true
        ResolveInfo resolveInfo = new ResolveInfo();
        resolveInfo.handleAllWebDataURI = true;
        resolveInfo.activityInfo = createActivityInfo();
        when(mMockPackageManager.queryIntentActivitiesAsUser(any(), anyInt(), anyInt()))
                .thenReturn(List.of(resolveInfo));

        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final DesktopModeWindowDecoration decor = createWindowDecoration(
                taskInfo, TEST_URI1 /* captured link */, TEST_URI2 /* web uri */,
                TEST_URI3 /* transfer session uri */, TEST_URI4 /* generic link */);

        // Verify web uri used for browser applications
        createHandleMenu(decor);
        verifyHandleMenuCreated(TEST_URI3);
    }


    private void verifyHandleMenuCreated(@Nullable Uri uri) {
        verify(mMockHandleMenuFactory).create(any(), any(), anyInt(), any(), any(),
                any(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(),
@@ -1692,10 +1727,11 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {

    private DesktopModeWindowDecoration createWindowDecoration(
            ActivityManager.RunningTaskInfo taskInfo, @Nullable Uri capturedLink,
            @Nullable Uri webUri, @Nullable Uri genericLink) {
            @Nullable Uri webUri, @Nullable Uri sessionTransferUri, @Nullable Uri genericLink) {
        taskInfo.capturedLink = capturedLink;
        taskInfo.capturedLinkTimestamp = System.currentTimeMillis();
        mAssistContent.setWebUri(webUri);
        mAssistContent.getExtras().putObject(EXTRA_SESSION_TRANSFER_WEB_URI, sessionTransferUri);
        final String genericLinkString = genericLink == null ? null : genericLink.toString();
        doReturn(genericLinkString).when(mMockGenericLinksParser).getGenericLink(any());
        // Relayout to set captured link