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

Commit f86ea8bc authored by Ats Jenk's avatar Ats Jenk Committed by Android (Google) Code Review
Browse files

Merge "Disable app to web links without desktop" into main

parents 6f6039e6 89cb540f
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -27,8 +27,11 @@ import android.content.pm.PackageManager
import android.content.pm.verify.domain.DomainVerificationManager
import android.content.pm.verify.domain.DomainVerificationUserState
import android.net.Uri
import android.view.Display
import com.android.internal.protolog.ProtoLog
import com.android.wm.shell.protolog.ShellProtoLogGroup
import com.android.wm.shell.shared.bubbles.BubbleAnythingFlagHelper
import com.android.wm.shell.shared.desktopmode.DesktopState

private const val TAG = "AppToWebUtils"

@@ -37,6 +40,16 @@ private val GenericBrowserIntent = Intent()
    .addCategory(Intent.CATEGORY_BROWSABLE)
    .setData(Uri.parse("http:"))

/**
 * Check if app links can be shown
 */
fun canShowAppLinks(display: Display, desktopState: DesktopState): Boolean {
    if (BubbleAnythingFlagHelper.enableBubbleToFullscreen()) {
        return desktopState.isDesktopModeSupportedOnDisplay(display)
    }
    return true
}

/**
 * Returns a boolean indicating whether a given package is a browser app.
 */
+19 −6
Original line number Diff line number Diff line
@@ -1428,11 +1428,16 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
     */
    void createHandleMenu(boolean minimumInstancesFound) {
        if (isHandleMenuActive()) return;
        // Requests assist content. When content is received, calls {@link #onAssistContentReceived}
        // which sets app info and creates the handle menu.
        mMinimumInstancesFound = minimumInstancesFound;
        if (AppToWebUtils.canShowAppLinks(mDisplay, mDesktopState)) {
            // Requests assist content. When content is received, calls
            // {@link #onAssistContentReceived} which sets app info and creates the handle menu.
            mAssistContentRequester.requestAssistContent(
                    mTaskInfo.taskId, this::onAssistContentReceived);
        } else {
            // Skip request for assist content as it is only used for links, which are not supported
            onAssistContentReceived(null);
        }
    }

    /**
@@ -1453,7 +1458,15 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
                .shouldShowRestartButton(mTaskInfo);
        final boolean inDesktopImmersive = mDesktopUserRepositories.getProfile(mTaskInfo.userId)
                .isTaskInFullImmersiveState(mTaskInfo.taskId);
        final boolean isBrowserApp = isBrowserApp();
        final boolean isBrowserApp;
        final Intent openInAppOrBrowserIntent;
        if (AppToWebUtils.canShowAppLinks(mDisplay, mDesktopState)) {
            isBrowserApp = isBrowserApp();
            openInAppOrBrowserIntent = isBrowserApp ? getAppLink() : getBrowserLink();
        } else {
            isBrowserApp = false;
            openInAppOrBrowserIntent = null;
        }
        mHandleMenu = mHandleMenuFactory.create(
                mMainDispatcher,
                mBgScope,
@@ -1470,7 +1483,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
                mDesktopState.isDesktopModeSupportedOnDisplay(mDisplay),
                shouldShowRestartButton,
                isBrowserApp,
                isBrowserApp ? getAppLink() : getBrowserLink(),
                openInAppOrBrowserIntent,
                mDesktopModeUiEventLogger,
                mResult.mCaptionWidth,
                mResult.mCaptionHeight,
+18 −0
Original line number Diff line number Diff line
@@ -1529,6 +1529,24 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
                eq(taskInfo.taskId), argThat(intent -> intent.getData() == TEST_URI1));
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB,
            com.android.wm.shell.Flags.FLAG_ENABLE_CREATE_ANY_BUBBLE,
            com.android.wm.shell.Flags.FLAG_ENABLE_BUBBLE_TO_FULLSCREEN})
    public void capturedLink_desktopNotAvailable_linkNotUsed() {
        mDesktopState.getOverrideDesktopModeSupportPerDisplay().put(Display.DEFAULT_DISPLAY, false);
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final DesktopModeWindowDecoration decor = createWindowDecoration(
                taskInfo, TEST_URI1 /* captured link */, null /* web uri */,
                null /* session transfer uri */, TEST_URI4 /* generic link */);

        decor.createHandleMenu(false);
        // Verify handle menu is created without app or browser link
        verifyHandleMenuCreated(/* uri= */ null);
        // Verify assist content is not requested as it is not used
        verify(mMockAssistContentRequester, never()).requestAssistContent(anyInt(), any());
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB)
    public void sessionTransferUri_sessionTransferUriUsedWhenWhenAvailable() {