summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/com/android/documentsui/AbstractActionHandler.java10
-rw-r--r--src/com/android/documentsui/archives/ReadableArchive.java6
-rw-r--r--tests/Android.bp11
-rw-r--r--tests/unit/com/android/documentsui/files/ActionHandlerTest.java35
4 files changed, 55 insertions, 7 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/src/com/android/documentsui/archives/ReadableArchive.java b/src/com/android/documentsui/archives/ReadableArchive.java
index 302f582f5..ad9c8242e 100644
--- a/src/com/android/documentsui/archives/ReadableArchive.java
+++ b/src/com/android/documentsui/archives/ReadableArchive.java
@@ -105,10 +105,10 @@ public class ReadableArchive extends Archive {
continue;
}
entryPath = getEntryPath(entry);
- if (mEntries.containsKey(entryPath)) {
- throw new IOException("Multiple entries with the same name are not supported.");
+ if (mEntries.putIfAbsent(entryPath, entry) != null) {
+ if (DEBUG) Log.d(TAG, "Ignored conflicting entry for '" + entryPath + "'");
+ continue;
}
- mEntries.put(entryPath, entry);
if (entry.isDirectory()) {
mTree.put(entryPath, new ArrayList<ArchiveEntry>());
}
diff --git a/tests/Android.bp b/tests/Android.bp
index e412919bd..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",
],
}
@@ -67,6 +69,7 @@ android_library {
srcs: [
"common/**/*.java",
"unit/**/*.java",
+ "unit/**/*.kt",
],
libs: [
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);