summaryrefslogtreecommitdiff
path: root/src/com
diff options
context:
space:
mode:
author François Degros <fdegros@google.com> 2025-03-07 04:49:23 +0000
committer François Degros <fdegros@google.com> 2025-03-11 11:40:28 +1100
commitba805cd8e88e4009e5c8d7437099c839e8f27230 (patch)
tree14f5f5071074a1fc0eacb57b74c6594d0ad2ba85 /src/com
parent10d62a35f21e66c4eae67e03b2001b890b4a3f0a (diff)
Control visibility of 'Browse' and 'Extract here' menu items
These menu items are visible when the selection contains exactly one file that is also a supported archive. Bug: 400830188 Bug: 400829875 Flag: com.android.documentsui.flags.use_material3 Flag: com.android.documentsui.flags.zip_ng_ro Test: atest DocumentsUIGoogleTests:com.android.documentsui.picker.MenuManagerTest Test: atest DocumentsUIGoogleTests:com.android.documentsui.files.MenuManagerTest Change-Id: I5fb649a462472a7df69aec3d016b61a35d670c2a
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/documentsui/MenuManager.java33
-rw-r--r--src/com/android/documentsui/archives/ArchiveRegistry.java11
-rw-r--r--src/com/android/documentsui/archives/ArchivesProvider.java13
-rw-r--r--src/com/android/documentsui/dirlist/SelectionMetadata.java19
4 files changed, 45 insertions, 31 deletions
diff --git a/src/com/android/documentsui/MenuManager.java b/src/com/android/documentsui/MenuManager.java
index 144a55245..888a45996 100644
--- a/src/com/android/documentsui/MenuManager.java
+++ b/src/com/android/documentsui/MenuManager.java
@@ -159,11 +159,11 @@ public abstract class MenuManager {
}
/**
- * @see DirectoryFragment#onCreateContextMenu
- *
* Called when user tries to generate a context menu anchored to a file when the selection
* doesn't contain any folder.
*
+ * @see DirectoryFragment#onCreateContextMenu
+ *
* @param selectionDetails
* containsFiles may return false because this may be called when user right clicks on an
* unselectable item in pickers
@@ -193,11 +193,11 @@ public abstract class MenuManager {
}
/**
- * @see DirectoryFragment#onCreateContextMenu
- *
* Called when user tries to generate a context menu anchored to a folder when the selection
* doesn't contain any file.
*
+ * @see DirectoryFragment#onCreateContextMenu
+ *
* @param selectionDetails
* containDirectories may return false because this may be called when user right clicks on
* an unselectable item in pickers
@@ -418,25 +418,42 @@ public abstract class MenuManager {
}
protected abstract void updateSelectAll(MenuItem selectAll);
+
protected abstract void updateSelectAll(MenuItem selectAll, SelectionDetails selectionDetails);
+
protected abstract void updateDeselectAll(
MenuItem deselectAll, SelectionDetails selectionDetails);
+
protected abstract void updateCreateDir(MenuItem createDir);
/**
* Access to meta data about the selection.
*/
public interface SelectionDetails {
+ /** Gets the total number of items (files and directories) in the selection. */
+ int size();
+
+ /** Returns whether the selection contains at least a directory. */
boolean containsDirectories();
+ /** Returns whether the selection contains at least a file. */
boolean containsFiles();
- int size();
-
+ /**
+ * Returns whether the selection contains at least a file that has not been fully downloaded
+ * yet.
+ */
boolean containsPartialFiles();
+ /** Returns whether the selection contains at least a file located in a mounted archive. */
boolean containsFilesInArchive();
+ /**
+ * Returns whether the selection contains exactly one file which is also a supported archive
+ * type.
+ */
+ boolean isArchive();
+
// TODO: Update these to express characteristics instead of answering concrete questions,
// since the answer to those questions is (or can be) activity specific.
boolean canDelete();
@@ -450,10 +467,6 @@ public abstract class MenuManager {
boolean canOpen();
boolean canViewInOwner();
-
- default boolean isArchive() {
- return false;
- }
}
public static class DirectoryDetails {
diff --git a/src/com/android/documentsui/archives/ArchiveRegistry.java b/src/com/android/documentsui/archives/ArchiveRegistry.java
index 91e0e20f5..3417e45ad 100644
--- a/src/com/android/documentsui/archives/ArchiveRegistry.java
+++ b/src/com/android/documentsui/archives/ArchiveRegistry.java
@@ -24,13 +24,12 @@ import static org.apache.commons.compress.compressors.CompressorStreamFactory.XZ
import androidx.annotation.Nullable;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
import org.apache.commons.compress.compressors.brotli.BrotliUtils;
import org.apache.commons.compress.compressors.xz.XZUtils;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* To query how to generate ArchiveHandle, how to create CompressInputStream and how to create
* ArchiveInputStream by using MIME type in ArchiveRegistry.
@@ -136,8 +135,4 @@ final class ArchiveRegistry {
static Integer getArchiveType(String mimeType) {
return sHandleArchiveMap.get(mimeType);
}
-
- static Set<String> getSupportList() {
- return sHandleArchiveMap.keySet();
- }
}
diff --git a/src/com/android/documentsui/archives/ArchivesProvider.java b/src/com/android/documentsui/archives/ArchivesProvider.java
index 3406cd708..dd221f416 100644
--- a/src/com/android/documentsui/archives/ArchivesProvider.java
+++ b/src/com/android/documentsui/archives/ArchivesProvider.java
@@ -44,7 +44,6 @@ import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
-import java.util.Set;
/**
* Provides basic implementation for creating, extracting and accessing
@@ -62,7 +61,6 @@ public class ArchivesProvider extends DocumentsProvider {
private static final String TAG = "ArchivesProvider";
private static final String METHOD_ACQUIRE_ARCHIVE = "acquireArchive";
private static final String METHOD_RELEASE_ARCHIVE = "releaseArchive";
- private static final Set<String> ZIP_MIME_TYPES = ArchiveRegistry.getSupportList();
@GuardedBy("mArchives")
private final Map<Key, Loader> mArchives = new HashMap<>();
@@ -235,16 +233,9 @@ public class ArchivesProvider extends DocumentsProvider {
return loader.get().openDocumentThumbnail(documentId, sizeHint, signal);
}
- /**
- * Returns true if the passed mime type is supported by the helper.
- */
+ /** Returns whether the given mime type is a supported archive type. */
public static boolean isSupportedArchiveType(String mimeType) {
- for (final String zipMimeType : ZIP_MIME_TYPES) {
- if (zipMimeType.equals(mimeType)) {
- return true;
- }
- }
- return false;
+ return ArchiveRegistry.getArchiveType(mimeType) != null;
}
/**
diff --git a/src/com/android/documentsui/dirlist/SelectionMetadata.java b/src/com/android/documentsui/dirlist/SelectionMetadata.java
index 74b6061b3..0559a3b80 100644
--- a/src/com/android/documentsui/dirlist/SelectionMetadata.java
+++ b/src/com/android/documentsui/dirlist/SelectionMetadata.java
@@ -56,7 +56,13 @@ public class SelectionMetadata extends SelectionObserver<String>
private int mWritableDirectoryCount = 0;
private int mNoDeleteCount = 0;
private int mNoRenameCount = 0;
+
+ /** Number of files that are located in mounted archives. */
private int mInArchiveCount = 0;
+
+ /** Number of archives. */
+ private int mArchiveCount = 0;
+
private boolean mSupportsSettings = false;
public SelectionMetadata(Function<String, Cursor> docFinder) {
@@ -79,6 +85,9 @@ public class SelectionMetadata extends SelectionObserver<String>
mDirectoryCount += delta;
} else {
mFileCount += delta;
+ if (ArchivesProvider.isSupportedArchiveType(mimeType)) {
+ mArchiveCount += delta;
+ }
}
final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
@@ -97,9 +106,8 @@ public class SelectionMetadata extends SelectionObserver<String>
if ((docFlags & Document.FLAG_PARTIAL) != 0) {
mPartialCount += delta;
}
- mSupportsSettings = (docFlags & Document.FLAG_SUPPORTS_SETTINGS) != 0 &&
- (mFileCount + mDirectoryCount) == 1;
+ mSupportsSettings = (docFlags & Document.FLAG_SUPPORTS_SETTINGS) != 0 && size() == 1;
final String authority = getCursorString(cursor, RootCursorWrapper.COLUMN_AUTHORITY);
if (ArchivesProvider.AUTHORITY.equals(authority)) {
@@ -115,6 +123,8 @@ public class SelectionMetadata extends SelectionObserver<String>
mWritableDirectoryCount = 0;
mNoDeleteCount = 0;
mNoRenameCount = 0;
+ mInArchiveCount = 0;
+ mArchiveCount = 0;
}
@Override
@@ -143,6 +153,11 @@ public class SelectionMetadata extends SelectionObserver<String>
}
@Override
+ public boolean isArchive() {
+ return mDirectoryCount == 0 && mFileCount == 1 && mArchiveCount == 1;
+ }
+
+ @Override
public boolean canDelete() {
return size() > 0 && mNoDeleteCount == 0;
}