diff options
author | 2024-12-10 01:10:24 +0000 | |
---|---|---|
committer | 2024-12-10 01:10:24 +0000 | |
commit | bd7cd39106eb72b7c5bcec45f02e0500bf620b9a (patch) | |
tree | ff3ebb331fb83f37a616fea73a8be8b1a6693ae2 | |
parent | 3675ccacfcb0ae1825dbfce7ff472b3dbd338d47 (diff) | |
parent | a954ef9a4cec65378d5f5c54d76a282dcf9c65db (diff) |
Merge "Integrate API into App-to-Web" into main
3 files changed, 63 insertions, 18 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/AppToWebUtils.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/AppToWebUtils.kt index 7243ea36b137..68c42d6a2648 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/AppToWebUtils.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/AppToWebUtils.kt @@ -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 +} diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java index 4f211c852697..01319fb8c713 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java @@ -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 diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java index 5d5d1f220ae0..db7b1f22768f 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java @@ -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 |