summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Erfan Norozi <erfanio@google.com> 2024-12-02 03:04:27 +0000
committer Erfan Norozi <erfanio@google.com> 2025-01-14 17:22:16 +1100
commitf9206c9e9c54fba72ab018e6d8470fbfc9f16c85 (patch)
tree6c10cbfdca7e986a4a8d7eac2e13fe6f63119823
parent4eb696797660dce4855585659f033d97c7ec773a (diff)
On desktop, open files in a new window
The desktop behaviour relies on `documentLaunchMode` which is implicitly enabled in all apps unless they override it in their manifest. Apps that set `documentLaunchMode="never"` will still open in a new window but will have a weird behaviour if two documents are opened using the same app (i.e. opening the second document will bring the app window to the front but the app will still display the first document). See https://issuetracker.google.com/issues/373759691#comment3 Bug: 373759691 Flag: com.android.documentsui.flags.desktop_file_handling Test: Unit tests and manual testing Change-Id: I9d21364879e4f3de780b207365da9bac97ff47ce
-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 e412919bd..915964f63 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);