summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Erfan Norozi <erfanio@google.com> 2025-01-14 15:14:27 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-01-14 15:14:27 -0800
commitf6375d8b7168d0f7d7be95499ebcae88872223a6 (patch)
tree35a0bdb84856b032b83e5ab398a06a8e92464f45
parent1a254eab387a2d1130664f2f12b998db12423493 (diff)
parentf9206c9e9c54fba72ab018e6d8470fbfc9f16c85 (diff)
Merge "On desktop, open files in a new window" into main
-rw-r--r--src/com/android/documentsui/AbstractActionHandler.java10
-rw-r--r--tests/Android.bp10
-rw-r--r--tests/unit/com/android/documentsui/files/ActionHandlerTest.java35
3 files changed, 51 insertions, 4 deletions
diff --git a/src/com/android/documentsui/AbstractActionHandler.java b/src/com/android/documentsui/AbstractActionHandler.java
index 2f64ebf64..b11567344 100644
--- a/src/com/android/documentsui/AbstractActionHandler.java
+++ b/src/com/android/documentsui/AbstractActionHandler.java
@@ -19,6 +19,7 @@ package com.android.documentsui;
import static com.android.documentsui.base.DocumentInfo.getCursorInt;
import static com.android.documentsui.base.DocumentInfo.getCursorString;
import static com.android.documentsui.base.SharedMinimal.DEBUG;
+import static com.android.documentsui.flags.Flags.desktopFileHandling;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
@@ -560,6 +561,15 @@ public abstract class AbstractActionHandler<T extends FragmentActivity & CommonA
if (doc.isWriteSupported()) {
flags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
}
+ // On desktop users expect files to open in a new window.
+ if (desktopFileHandling()) {
+ // The combination of NEW_DOCUMENT and MULTIPLE_TASK allows multiple instances of the
+ // same activity to open in separate windows.
+ flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
+ // If the activity has documentLaunchMode="never", NEW_TASK forces the activity to still
+ // open in a new window.
+ flags |= Intent.FLAG_ACTIVITY_NEW_TASK;
+ }
intent.setFlags(flags);
return intent;
diff --git a/tests/Android.bp b/tests/Android.bp
index 9620230e4..2b2daa45d 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -25,12 +25,14 @@ java_defaults {
],
static_libs: [
- "androidx.test.rules",
"androidx.test.espresso.core",
"androidx.test.ext.truth",
+ "androidx.test.rules",
+ "androidx.test.uiautomator_uiautomator",
+ "docsui-flags-aconfig-java-lib",
+ "flag-junit",
"guava",
"mockito-target",
- "androidx.test.uiautomator_uiautomator",
],
}
@@ -50,11 +52,11 @@ android_library {
static_libs: [
"androidx.legacy_legacy-support-v4",
- "androidx.test.rules",
"androidx.test.espresso.core",
+ "androidx.test.rules",
+ "androidx.test.uiautomator_uiautomator",
"mockito-target",
"ub-janktesthelper",
- "androidx.test.uiautomator_uiautomator",
],
}
diff --git a/tests/unit/com/android/documentsui/files/ActionHandlerTest.java b/tests/unit/com/android/documentsui/files/ActionHandlerTest.java
index be6397069..6aaa3e5d2 100644
--- a/tests/unit/com/android/documentsui/files/ActionHandlerTest.java
+++ b/tests/unit/com/android/documentsui/files/ActionHandlerTest.java
@@ -39,6 +39,9 @@ import android.content.ClipData;
import android.content.Intent;
import android.net.Uri;
import android.os.Parcelable;
+import android.platform.test.annotations.DisableFlags;
+import android.platform.test.annotations.EnableFlags;
+import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Path;
import android.util.Pair;
@@ -59,6 +62,7 @@ import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.DocumentStack;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.Shared;
+import com.android.documentsui.flags.Flags;
import com.android.documentsui.inspector.InspectorActivity;
import com.android.documentsui.testing.ClipDatas;
import com.android.documentsui.testing.DocumentStackAsserts;
@@ -78,6 +82,7 @@ import com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Ignore;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -103,6 +108,9 @@ public class ActionHandlerTest {
private TestConfigStore mTestConfigStore;
private boolean refreshAnswer = false;
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
@Parameter(0)
public boolean isPrivateSpaceEnabled;
@@ -157,6 +165,33 @@ public class ActionHandlerTest {
}
@Test
+ @DisableFlags({Flags.FLAG_DESKTOP_FILE_HANDLING})
+ public void testOpenFileFlags() {
+ mHandler.onDocumentOpened(TestEnv.FILE_GIF,
+ com.android.documentsui.files.ActionHandler.VIEW_TYPE_PREVIEW,
+ com.android.documentsui.files.ActionHandler.VIEW_TYPE_REGULAR, false);
+
+ int expectedFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_SINGLE_TOP
+ | Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
+ Intent actual = mActivity.startActivity.getLastValue();
+ assertEquals(expectedFlags, actual.getFlags());
+ }
+
+ @Test
+ @EnableFlags({Flags.FLAG_DESKTOP_FILE_HANDLING})
+ public void testOpenFileFlagsDesktop() {
+ mHandler.onDocumentOpened(TestEnv.FILE_GIF,
+ com.android.documentsui.files.ActionHandler.VIEW_TYPE_PREVIEW,
+ com.android.documentsui.files.ActionHandler.VIEW_TYPE_REGULAR, false);
+
+ int expectedFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_SINGLE_TOP
+ | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_DOCUMENT
+ | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_TASK;
+ Intent actual = mActivity.startActivity.getLastValue();
+ assertEquals(expectedFlags, actual.getFlags());
+ }
+
+ @Test
public void testSpringOpenDirectory() {
mHandler.springOpenDirectory(TestEnv.FOLDER_0);
assertTrue(mActionModeAddons.finishActionModeCalled);