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

Commit 89cb540f authored by Ats Jenk's avatar Ats Jenk
Browse files

Disable app to web links without desktop

Open app in browser is for desktop enabled devices. When the display
only supports app handle, but not desktop, hide the option to open app
in browser.

Bug: 399911375
Flag: com.android.wm.shell.enable_bubble_to_fullscreen
Test: atest WMShellUnitTests:DesktopModeWindowDecorationTests
Test: manual, open youtube on foldable, check that open in browser is
  not shown
Test: manual, open youtube on tablet, check that open in browser is
  shown
Change-Id: Ib563788b9acf97b807bacc28d2da70483bdf8844
parent 8e304b1f
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
@@ -1427,11 +1427,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);
        }
    }

    /**
@@ -1452,7 +1457,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,
@@ -1469,7 +1482,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() {