Make Sorting/paging honor ENABLE_OMC_FEATURES flag
BUG: 30927484
Change-Id: Ia15b566da9e8fa7de6e5b70bc39f542cf4f5ff11
diff --git a/src/com/android/documentsui/DirectoryLoader.java b/src/com/android/documentsui/DirectoryLoader.java
index 12abd21..5c93f76 100644
--- a/src/com/android/documentsui/DirectoryLoader.java
+++ b/src/com/android/documentsui/DirectoryLoader.java
@@ -99,22 +99,23 @@
ArchivesProvider.acquireArchive(client, mUri);
}
result.client = client;
- Bundle queryArgs = new Bundle();
- mModel.addQuerySortArgs(queryArgs);
- // TODO: At some point we don't want forced flags to override real paging...
- // and that point is when we have real paging.
- DebugFlags.addForcedPagingArgs(queryArgs);
+ if (Shared.ENABLE_OMC_API_FEATURES) {
+ Bundle queryArgs = new Bundle();
+ mModel.addQuerySortArgs(queryArgs);
- cursor = client.query(mUri, null, queryArgs, mSignal);
- if (cursor == null) {
- throw new RemoteException("Provider returned null");
+ // TODO: At some point we don't want forced flags to override real paging...
+ // and that point is when we have real paging.
+ DebugFlags.addForcedPagingArgs(queryArgs);
+
+ cursor = client.query(mUri, null, queryArgs, mSignal);
+ } else {
+ cursor = client.query(
+ mUri, null, null, null, mModel.getDocumentSortQuery(), mSignal);
}
- Bundle extras = cursor.getExtras();
- if (extras.containsKey(ContentResolver.QUERY_RESULT_SIZE)) {
- Log.i(TAG, "[PAGING INDICATED] Cursor extras specify recordset size of: "
- + extras.getInt(ContentResolver.QUERY_RESULT_SIZE));
+ if (cursor == null) {
+ throw new RemoteException("Provider returned null");
}
cursor.registerContentObserver(mObserver);
diff --git a/src/com/android/documentsui/RecentsLoader.java b/src/com/android/documentsui/RecentsLoader.java
index e05a328..ead5e8f 100644
--- a/src/com/android/documentsui/RecentsLoader.java
+++ b/src/com/android/documentsui/RecentsLoader.java
@@ -329,11 +329,15 @@
for (int i = 0; i < rootIds.size(); i++) {
final Uri uri =
DocumentsContract.buildRecentDocumentsUri(authority, rootIds.get(i));
- final Bundle queryArgs = new Bundle();
- mState.sortModel.addQuerySortArgs(queryArgs);
-
try {
- res[i] = client.query(uri, null, queryArgs, null);
+ if (Shared.ENABLE_OMC_API_FEATURES) {
+ final Bundle queryArgs = new Bundle();
+ mState.sortModel.addQuerySortArgs(queryArgs);
+ res[i] = client.query(uri, null, queryArgs, null);
+ } else {
+ res[i] = client.query(
+ uri, null, null, null, mState.sortModel.getDocumentSortQuery());
+ }
mCursors[i] = new RootCursorWrapper(authority, rootIds.get(i), res[i],
MAX_DOCS_FROM_ROOT);
} catch (Exception e) {
diff --git a/src/com/android/documentsui/base/DebugFlags.java b/src/com/android/documentsui/base/DebugFlags.java
index 2298e76..e131d8e 100644
--- a/src/com/android/documentsui/base/DebugFlags.java
+++ b/src/com/android/documentsui/base/DebugFlags.java
@@ -65,6 +65,7 @@
}
public static boolean addForcedPagingArgs(Bundle queryArgs) {
+ assert(Shared.ENABLE_OMC_API_FEATURES);
boolean flagsAdded = false;
if (sForcedPageOffset >= 0) {
queryArgs.putInt(ContentResolver.QUERY_ARG_OFFSET, sForcedPageOffset);
diff --git a/src/com/android/documentsui/queries/DebugCommandProcessor.java b/src/com/android/documentsui/queries/DebugCommandProcessor.java
index 7b36d5b..ff62526 100644
--- a/src/com/android/documentsui/queries/DebugCommandProcessor.java
+++ b/src/com/android/documentsui/queries/DebugCommandProcessor.java
@@ -24,6 +24,7 @@
import com.android.documentsui.DocumentsApplication;
import com.android.documentsui.base.DebugFlags;
import com.android.documentsui.base.EventHandler;
+import com.android.documentsui.base.Shared;
import java.util.ArrayList;
import java.util.List;
@@ -110,6 +111,11 @@
}
private static boolean forcePaging(String[] tokens) {
+ if (!Shared.ENABLE_OMC_API_FEATURES) {
+ Log.i(TAG, "Paging is disabled.");
+ return false;
+ }
+
if ("page".equals(tokens[0])) {
if (tokens.length >= 2) {
try {
diff --git a/src/com/android/documentsui/sorting/SortModel.java b/src/com/android/documentsui/sorting/SortModel.java
index 7ff49ef..e3eb1e9 100644
--- a/src/com/android/documentsui/sorting/SortModel.java
+++ b/src/com/android/documentsui/sorting/SortModel.java
@@ -33,6 +33,7 @@
import android.view.View;
import com.android.documentsui.R;
+import com.android.documentsui.base.Shared;
import com.android.documentsui.sorting.SortDimension.SortDirection;
import java.lang.annotation.Retention;
@@ -241,6 +242,7 @@
}
public void addQuerySortArgs(Bundle queryArgs) {
+ assert(Shared.ENABLE_OMC_API_FEATURES);
final int id = getSortedDimensionId();
switch (id) {
@@ -284,6 +286,45 @@
}
}
+ public @Nullable String getDocumentSortQuery() {
+ assert(!Shared.ENABLE_OMC_API_FEATURES);
+
+ final int id = getSortedDimensionId();
+ final String columnName;
+ switch (id) {
+ case SORT_DIMENSION_ID_UNKNOWN:
+ return null;
+ case SortModel.SORT_DIMENSION_ID_TITLE:
+ columnName = Document.COLUMN_DISPLAY_NAME;
+ break;
+ case SortModel.SORT_DIMENSION_ID_DATE:
+ columnName = Document.COLUMN_LAST_MODIFIED;
+ break;
+ case SortModel.SORT_DIMENSION_ID_SIZE:
+ columnName = Document.COLUMN_SIZE;
+ break;
+ default:
+ throw new IllegalStateException(
+ "Unexpected sort dimension id: " + id);
+ }
+
+ final SortDimension dimension = getDimensionById(id);
+ final String direction;
+ switch (dimension.getSortDirection()) {
+ case SortDimension.SORT_DIRECTION_ASCENDING:
+ direction = " ASC";
+ break;
+ case SortDimension.SORT_DIRECTION_DESCENDING:
+ direction = " DESC";
+ break;
+ default:
+ throw new IllegalStateException(
+ "Unexpected sort direction: " + dimension.getSortDirection());
+ }
+
+ return columnName + direction;
+ }
+
private void notifyListeners(@UpdateType int updateType) {
for (int i = mListeners.size() - 1; i >= 0; --i) {
mListeners.get(i).onModelUpdate(this, updateType);