summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-12-12 23:00:09 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2024-12-12 23:00:09 -0800
commitffdfbbda663302ad1336bfbc67beb5714b7900a3 (patch)
treea4c861281546e9b45cb34796e62a29e381878924
parentae4cc62fbb06cd176879f6d0e1de4e0706b27552 (diff)
parentabc2e065952bf165d51f00f94e986c020622e2c6 (diff)
Merge "Do not return intent if resolved to browser activity" into main
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/apptoweb/AppToWebUtils.kt28
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java6
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java20
3 files changed, 33 insertions, 21 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 68c42d6a2648..06a55d3dbbd0 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
@@ -24,7 +24,6 @@ import android.content.Context
import android.content.Intent
import android.content.Intent.ACTION_VIEW
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
-import android.content.Intent.FLAG_ACTIVITY_REQUIRE_NON_BROWSER
import android.content.pm.PackageManager
import android.content.pm.verify.domain.DomainVerificationManager
import android.content.pm.verify.domain.DomainVerificationUserState
@@ -60,13 +59,15 @@ fun isBrowserApp(context: Context, packageName: String, userId: Int): Boolean {
* Returns intent if there is a browser application available to handle the uri. Otherwise, returns
* null.
*/
-fun getBrowserIntent(uri: Uri, packageManager: PackageManager): Intent? {
+fun getBrowserIntent(uri: Uri, packageManager: PackageManager, userId: Int): Intent? {
val intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_BROWSER)
.setData(uri)
.addFlags(FLAG_ACTIVITY_NEW_TASK)
- // If there is no browser application available to handle intent, return null
- val component = intent.resolveActivity(packageManager) ?: return null
- intent.setComponent(component)
+ // If there is a browser application available to handle the intent, return the intent.
+ // Otherwise, return null.
+ val resolveInfo = packageManager.resolveActivityAsUser(intent, /* flags= */ 0, userId)
+ ?: return null
+ intent.setComponent(resolveInfo.componentInfo.componentName)
return intent
}
@@ -74,14 +75,17 @@ fun getBrowserIntent(uri: Uri, packageManager: PackageManager): Intent? {
* Returns intent if there is a non-browser application available to handle the uri. Otherwise,
* returns null.
*/
-fun getAppIntent(uri: Uri, packageManager: PackageManager): Intent? {
- val intent = Intent(ACTION_VIEW, uri).apply {
- flags = FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_REQUIRE_NON_BROWSER
+fun getAppIntent(uri: Uri, packageManager: PackageManager, userId: Int): Intent? {
+ val intent = Intent(ACTION_VIEW, uri).addFlags(FLAG_ACTIVITY_NEW_TASK)
+ val resolveInfo = packageManager.resolveActivityAsUser(intent, /* flags= */ 0, userId)
+ ?: return null
+ // If there is a non-browser application available to handle the intent, return the intent.
+ // Otherwise, return null.
+ if (resolveInfo.activityInfo != null && !resolveInfo.handleAllWebDataURI) {
+ intent.setComponent(resolveInfo.componentInfo.componentName)
+ return intent
}
- // If there is no application available to handle intent, return null
- val component = intent.resolveActivity(packageManager) ?: return null
- intent.setComponent(component)
- return intent
+ return null
}
/**
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 a035b24913d6..0d1960ad6e29 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
@@ -617,14 +617,16 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
}
if (browserLink == null) return null;
- return AppToWebUtils.getBrowserIntent(browserLink, mContext.getPackageManager());
+ return AppToWebUtils.getBrowserIntent(browserLink, mContext.getPackageManager(),
+ mUserContext.getUserId());
}
@Nullable
private Intent getAppLink() {
return mWebUri == null ? null
- : AppToWebUtils.getAppIntent(mWebUri, mContext.getPackageManager());
+ : AppToWebUtils.getAppIntent(mWebUri, mContext.getPackageManager(),
+ mUserContext.getUserId());
}
private boolean isBrowserApp() {
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 8a1a9b5ef80b..855b3ddd99b5 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
@@ -278,9 +278,9 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
when(mMockPackageManager.getApplicationLabel(any())).thenReturn("applicationLabel");
final ActivityInfo activityInfo = createActivityInfo();
when(mMockPackageManager.getActivityInfo(any(), anyInt())).thenReturn(activityInfo);
- final ResolveInfo resolveInfo = new ResolveInfo();
- resolveInfo.activityInfo = activityInfo;
- when(mMockPackageManager.resolveActivity(any(), anyInt())).thenReturn(resolveInfo);
+ final ResolveInfo resolveInfo = createResolveInfo(false /* handleAllWebDataUri */);
+ when(mMockPackageManager.resolveActivityAsUser(any(), anyInt(), anyInt()))
+ .thenReturn(resolveInfo);
final Display defaultDisplay = mock(Display.class);
doReturn(defaultDisplay).when(mMockDisplayController).getDisplay(Display.DEFAULT_DISPLAY);
doReturn(mInsetsState).when(mMockDisplayController).getInsetsState(anyInt());
@@ -1664,11 +1664,9 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
@EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_APP_TO_WEB)
public void browserApp_transferSessionUriUsedForBrowserAppWhenAvailable() {
// Make {@link AppToWebUtils#isBrowserApp} return true
- ResolveInfo resolveInfo = new ResolveInfo();
- resolveInfo.handleAllWebDataURI = true;
- resolveInfo.activityInfo = createActivityInfo();
+ ResolveInfo browserResolveInfo = createResolveInfo(true /* handleAllWebUriData */);
when(mMockPackageManager.queryIntentActivitiesAsUser(any(), anyInt(), anyInt()))
- .thenReturn(List.of(resolveInfo));
+ .thenReturn(List.of(browserResolveInfo));
final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
final DesktopModeWindowDecoration decor = createWindowDecoration(
@@ -1793,6 +1791,13 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
return windowDecor;
}
+ private ResolveInfo createResolveInfo(boolean handleAllWebDataURI) {
+ final ResolveInfo info = new ResolveInfo();
+ info.handleAllWebDataURI = handleAllWebDataURI;
+ info.activityInfo = createActivityInfo();
+ return info;
+ }
+
private ActivityManager.RunningTaskInfo createTaskInfo(boolean visible) {
final ActivityManager.TaskDescription.Builder taskDescriptionBuilder =
new ActivityManager.TaskDescription.Builder();
@@ -1821,6 +1826,7 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
applicationInfo.packageName = "DesktopModeWindowDecorationTestPackage";
final ActivityInfo activityInfo = new ActivityInfo();
activityInfo.applicationInfo = applicationInfo;
+ activityInfo.packageName = "DesktopModeWindowDecorationTestPackage";
activityInfo.name = "DesktopModeWindowDecorationTest";
return activityInfo;
}