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

Commit 10bdc1d1 authored by Maryam Dehaini's avatar Maryam Dehaini Committed by Android (Google) Code Review
Browse files

Merge changes from topic "SessionTransferApi" into main

* changes:
  Updating AppToWebUtils due to API changes
  Session Transfer Uri API Changes
parents 4335f45e d6ed0b70
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -8947,18 +8947,19 @@ package android.app.assist {
    method public android.content.ClipData getClipData();
    method public android.content.ClipData getClipData();
    method public android.os.Bundle getExtras();
    method public android.os.Bundle getExtras();
    method public android.content.Intent getIntent();
    method public android.content.Intent getIntent();
    method @FlaggedApi("com.android.window.flags.enable_desktop_windowing_app_to_web_education") @Nullable public android.net.Uri getSessionTransferUri();
    method public String getStructuredData();
    method public String getStructuredData();
    method public android.net.Uri getWebUri();
    method public android.net.Uri getWebUri();
    method public boolean isAppProvidedIntent();
    method public boolean isAppProvidedIntent();
    method public boolean isAppProvidedWebUri();
    method public boolean isAppProvidedWebUri();
    method public void setClipData(android.content.ClipData);
    method public void setClipData(android.content.ClipData);
    method public void setIntent(android.content.Intent);
    method public void setIntent(android.content.Intent);
    method @FlaggedApi("com.android.window.flags.enable_desktop_windowing_app_to_web_education") public void setSessionTransferUri(@Nullable android.net.Uri);
    method public void setStructuredData(String);
    method public void setStructuredData(String);
    method public void setWebUri(android.net.Uri);
    method public void setWebUri(android.net.Uri);
    method public void writeToParcel(android.os.Parcel, int);
    method public void writeToParcel(android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.app.assist.AssistContent> CREATOR;
    field @NonNull public static final android.os.Parcelable.Creator<android.app.assist.AssistContent> CREATOR;
    field @FlaggedApi("android.app.appfunctions.flags.enable_app_function_manager") public static final String EXTRA_APP_FUNCTION_DATA = "android.app.assist.extra.APP_FUNCTION_DATA";
    field @FlaggedApi("android.app.appfunctions.flags.enable_app_function_manager") public static final String EXTRA_APP_FUNCTION_DATA = "android.app.assist.extra.APP_FUNCTION_DATA";
    field @FlaggedApi("com.android.window.flags.enable_desktop_windowing_app_to_web_education") public static final String EXTRA_SESSION_TRANSFER_WEB_URI = "android.app.assist.extra.SESSION_TRANSFER_WEB_URI";
  }
  }
  public class AssistStructure implements android.os.Parcelable {
  public class AssistStructure implements android.os.Parcelable {
+4 −4
Original line number Original line Diff line number Diff line
@@ -1273,8 +1273,8 @@ public class Activity extends ContextThemeWrapper
     * Requests to show the “Open in browser” education. “Open in browser” is a feature
     * Requests to show the “Open in browser” education. “Open in browser” is a feature
     * within the app header that allows users to switch from an app to the web. The feature
     * within the app header that allows users to switch from an app to the web. The feature
     * is made available when an application is opened by a user clicking a link or when a
     * is made available when an application is opened by a user clicking a link or when a
     * link is provided by an application. Links can be provided by utilizing
     * link is provided by an application. Links can be provided by calling
     * {@link AssistContent#EXTRA_AUTHENTICATING_USER_WEB_URI} or
     * {@link AssistContent#setSessionTransferUri} or
     * {@link AssistContent#setWebUri}.
     * {@link AssistContent#setWebUri}.
     *
     *
     * <p>This method should be utilized when an activity wants to nudge the user to switch
     * <p>This method should be utilized when an activity wants to nudge the user to switch
@@ -1287,7 +1287,7 @@ public class Activity extends ContextThemeWrapper
     * disruptive to the user to show the education and when it is optimal to switch the user to a
     * disruptive to the user to show the education and when it is optimal to switch the user to a
     * browser session. Before requesting to show the education, developers should assert that they
     * browser session. Before requesting to show the education, developers should assert that they
     * have set a link that can be used by the "Open in browser" feature through either
     * have set a link that can be used by the "Open in browser" feature through either
     * {@link AssistContent#EXTRA_AUTHENTICATING_USER_WEB_URI} or
     * {@link AssistContent#setSessionTransferUri} or
     * {@link AssistContent#setWebUri} so that users are navigated to a relevant page if they choose
     * {@link AssistContent#setWebUri} so that users are navigated to a relevant page if they choose
     * to switch to the browser. If a URI is not set using either method, "Open in browser" will
     * to switch to the browser. If a URI is not set using either method, "Open in browser" will
     * utilize a generic link if available which will direct users to the homepage of the site
     * utilize a generic link if available which will direct users to the homepage of the site
@@ -1296,7 +1296,7 @@ public class Activity extends ContextThemeWrapper
     * the user will not be provided with the option to switch to the browser and the education will
     * the user will not be provided with the option to switch to the browser and the education will
     * not be shown if requested.
     * not be shown if requested.
     *
     *
     * @see android.app.assist.AssistContent#EXTRA_SESSION_TRANSFER_WEB_URI
     * @see android.app.assist.AssistContent#setSessionTransferUri
     */
     */
    @FlaggedApi(com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB_EDUCATION)
    @FlaggedApi(com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB_EDUCATION)
    public final void requestOpenInBrowserEducation() {
    public final void requestOpenInBrowserEducation() {
+46 −25
Original line number Original line Diff line number Diff line
package android.app.assist;
package android.app.assist;


import android.annotation.FlaggedApi;
import android.annotation.FlaggedApi;
import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ClipData;
import android.content.ClipData;
import android.content.Intent;
import android.content.Intent;
@@ -30,31 +31,6 @@ public class AssistContent implements Parcelable {
    public static final String EXTRA_APP_FUNCTION_DATA =
    public static final String EXTRA_APP_FUNCTION_DATA =
            "android.app.assist.extra.APP_FUNCTION_DATA";
            "android.app.assist.extra.APP_FUNCTION_DATA";


    /**
     * This extra can be optionally supplied in the {@link #getExtras} bundle to provide a
     * {@link Uri} which will be utilized when transitioning a user's session to another surface.
     *
     * <p>If provided, instead of using the URI provided in {@link #setWebUri}, the
     * "Open in browser" feature will use this URI to transition the current session from one
     * surface to the other. Apps may choose to encode session or user information into this
     * URI in order to provide a better session transfer experience.
     *
     * <p>Unlike {@link #setWebUri}, this URI will not be used for features where the user might
     * accidentally share it with another user. However, developers should not encode
     * authentication credentials into this URI, because it will be surfaced in the browser URL
     * bar and may be copied and shared from there.
     *
     * <p>When providing this extra, developers should still continue to provide
     * {@link #setWebUri} for backwards compatibility with features such as
     * <a href="https://developer.android.com/guide/components/activities/recents#url-sharing">
     * recents URL sharing</a> which do not benefit from a session-transfer web URI.
     *
     * @see android.app.Activity#requestOpenInBrowserEducation()
     */
    @FlaggedApi(com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB_EDUCATION)
    public static final String EXTRA_SESSION_TRANSFER_WEB_URI =
            "android.app.assist.extra.SESSION_TRANSFER_WEB_URI";

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    private boolean mIsAppProvidedIntent = false;
    private boolean mIsAppProvidedIntent = false;
    private boolean mIsAppProvidedWebUri = false;
    private boolean mIsAppProvidedWebUri = false;
@@ -66,6 +42,7 @@ public class AssistContent implements Parcelable {
    private ClipData mClipData;
    private ClipData mClipData;
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    private Uri mUri;
    private Uri mUri;
    private Uri mSessionTransferUri;
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    private final Bundle mExtras;
    private final Bundle mExtras;


@@ -199,6 +176,41 @@ public class AssistContent implements Parcelable {
        return mIsAppProvidedWebUri;
        return mIsAppProvidedWebUri;
    }
    }


    /**
     * This method can be used to provide a {@link Uri} which will be utilized when transitioning a
     * user's session to another surface.
     *
     * <p>If provided, instead of using the URI provided in {@link #setWebUri}, the
     * "Open in browser" feature will use this URI to transition the current session from one
     * surface to the other. Apps may choose to encode session or user information into this
     * URI in order to provide a better session transfer experience. However, while this URI will
     * only be available to the system and not other applications, developers should not encode
     * authentication credentials into this URI, because it will be surfaced in the browser URL bar
     * and may be copied and shared from there.
     *
     * <p>When providing this URI, developers should still continue to provide
     * {@link #setWebUri} for backwards compatibility with features such as
     * <a href="https://developer.android.com/guide/components/activities/recents#url-sharing">
     * recents URL sharing</a> which facilitate link sharing with other users and would not benefit
     * from a session-transfer URI.
     *
     * @see android.app.Activity#requestOpenInBrowserEducation()
     */
    @FlaggedApi(com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB_EDUCATION)
    public void setSessionTransferUri(@Nullable Uri uri) {
        mSessionTransferUri = uri;
    }

    /**
     * Return the content's session transfer web URI as per
     * {@link #setSessionTransferUri(android.net.Uri)}, or null if there is none.
     */
    @FlaggedApi(com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB_EDUCATION)
    @Nullable
    public Uri getSessionTransferUri() {
        return mSessionTransferUri;
    }

    /**
    /**
     * Return Bundle for extra vendor-specific data that can be modified and examined.
     * Return Bundle for extra vendor-specific data that can be modified and examined.
     */
     */
@@ -217,6 +229,9 @@ public class AssistContent implements Parcelable {
        if (in.readInt() != 0) {
        if (in.readInt() != 0) {
            mUri = Uri.CREATOR.createFromParcel(in);
            mUri = Uri.CREATOR.createFromParcel(in);
        }
        }
        if (in.readInt() != 0) {
            mSessionTransferUri = Uri.CREATOR.createFromParcel(in);
        }
        if (in.readInt() != 0) {
        if (in.readInt() != 0) {
            mStructuredData = in.readString();
            mStructuredData = in.readString();
        }
        }
@@ -245,6 +260,12 @@ public class AssistContent implements Parcelable {
        } else {
        } else {
            dest.writeInt(0);
            dest.writeInt(0);
        }
        }
        if (mSessionTransferUri != null) {
            dest.writeInt(1);
            mSessionTransferUri.writeToParcel(dest, flags);
        } else {
            dest.writeInt(0);
        }
        if (mStructuredData != null) {
        if (mStructuredData != null) {
            dest.writeInt(1);
            dest.writeInt(1);
            dest.writeString(mStructuredData);
            dest.writeString(mStructuredData);
+1 −2
Original line number Original line Diff line number Diff line
@@ -19,7 +19,6 @@
package com.android.wm.shell.apptoweb
package com.android.wm.shell.apptoweb


import android.app.assist.AssistContent
import android.app.assist.AssistContent
import android.app.assist.AssistContent.EXTRA_SESSION_TRANSFER_WEB_URI
import android.content.Context
import android.content.Context
import android.content.Intent
import android.content.Intent
import android.content.Intent.ACTION_VIEW
import android.content.Intent.ACTION_VIEW
@@ -113,5 +112,5 @@ fun getDomainVerificationUserState(
 * Returns the web uri from the given [AssistContent].
 * Returns the web uri from the given [AssistContent].
 */
 */
fun AssistContent.getSessionWebUri(): Uri? {
fun AssistContent.getSessionWebUri(): Uri? {
    return extras.getParcelable(EXTRA_SESSION_TRANSFER_WEB_URI) ?: webUri
    return sessionTransferUri ?: webUri
}
}
+4 −5
Original line number Original line Diff line number Diff line
@@ -20,7 +20,6 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
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.platform.test.flag.junit.SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT;
import static android.view.InsetsSource.FLAG_FORCE_CONSUMING;
import static android.view.InsetsSource.FLAG_FORCE_CONSUMING;
import static android.view.InsetsSource.FLAG_FORCE_CONSUMING_OPAQUE_CAPTION_BAR;
import static android.view.InsetsSource.FLAG_FORCE_CONSUMING_OPAQUE_CAPTION_BAR;
@@ -1176,7 +1175,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {


    @Test
    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB)
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB)
    public void webUriLink_webUriLinkUsedWhenWhenAvailable() {
    public void sessionTransferUri_sessionTransferUriUsedWhenWhenAvailable() {
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final DesktopModeWindowDecoration decor = createWindowDecoration(
        final DesktopModeWindowDecoration decor = createWindowDecoration(
                taskInfo, TEST_URI1 /* captured link */, TEST_URI2 /* web uri */,
                taskInfo, TEST_URI1 /* captured link */, TEST_URI2 /* web uri */,
@@ -1188,7 +1187,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {


    @Test
    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB)
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB)
    public void webUriLink_webUriLinkUsedWhenSessionTransferUriUnavailable() {
    public void webUri_webUriUsedWhenSessionTransferUriUnavailable() {
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final DesktopModeWindowDecoration decor = createWindowDecoration(
        final DesktopModeWindowDecoration decor = createWindowDecoration(
                taskInfo, TEST_URI1 /* captured link */, TEST_URI2 /* web uri */,
                taskInfo, TEST_URI1 /* captured link */, TEST_URI2 /* web uri */,
@@ -1200,7 +1199,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {


    @Test
    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB)
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB)
    public void genericLink_genericLinkUsedWhenCapturedLinkAndWebUriUnavailable() {
    public void genericLink_genericLinkUsedWhenCapturedLinkAndAssistContentUriUnavailable() {
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
        final DesktopModeWindowDecoration decor = createWindowDecoration(
        final DesktopModeWindowDecoration decor = createWindowDecoration(
                taskInfo, null /* captured link */, null /* web uri */,
                taskInfo, null /* captured link */, null /* web uri */,
@@ -1490,7 +1489,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
        taskInfo.capturedLink = capturedLink;
        taskInfo.capturedLink = capturedLink;
        taskInfo.capturedLinkTimestamp = System.currentTimeMillis();
        taskInfo.capturedLinkTimestamp = System.currentTimeMillis();
        mAssistContent.setWebUri(webUri);
        mAssistContent.setWebUri(webUri);
        mAssistContent.getExtras().putObject(EXTRA_SESSION_TRANSFER_WEB_URI, sessionTransferUri);
        mAssistContent.setSessionTransferUri(sessionTransferUri);
        final String genericLinkString = genericLink == null ? null : genericLink.toString();
        final String genericLinkString = genericLink == null ? null : genericLink.toString();
        doReturn(genericLinkString).when(mMockGenericLinksParser).getGenericLink(any());
        doReturn(genericLinkString).when(mMockGenericLinksParser).getGenericLink(any());
        // Relayout to set captured link
        // Relayout to set captured link