Loading src/com/android/documentsui/DirectoryLoader.java +16 −2 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.Context; import android.database.ContentObserver; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.os.CancellationSignal; import android.os.Handler; import android.os.OperationCanceledException; Loading @@ -30,6 +31,7 @@ import android.os.RemoteException; import android.provider.DocumentsContract.Document; import android.util.Log; import com.android.documentsui.base.DebugFlags; import com.android.documentsui.base.DocumentInfo; import com.android.documentsui.base.FilteringCursorWrapper; import com.android.documentsui.base.RootInfo; Loading Loading @@ -92,12 +94,24 @@ public class DirectoryLoader extends AsyncTaskLoader<DirectoryResult> { Cursor cursor; try { client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, authority); cursor = client.query( mUri, null, null, null, mModel.getDocumentSortQuery(), mSignal); 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); cursor = client.query(mUri, null, queryArgs, mSignal); if (cursor == null) { throw new RemoteException("Provider returned null"); } 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)); } cursor.registerContentObserver(mObserver); cursor = new RootCursorWrapper(mUri.getAuthority(), mRoot.rootId, cursor, -1); Loading src/com/android/documentsui/RecentsLoader.java +9 −6 Original line number Diff line number Diff line Loading @@ -35,15 +35,16 @@ import android.util.Log; import com.android.documentsui.base.FilteringCursorWrapper; import com.android.documentsui.base.RootInfo; import com.android.documentsui.base.Shared; import com.android.documentsui.base.State; import com.android.documentsui.roots.RootCursorWrapper; import com.android.documentsui.roots.RootsAccess; import com.android.internal.annotations.GuardedBy; import libcore.io.IoUtils; import com.google.common.util.concurrent.AbstractFuture; import libcore.io.IoUtils; import java.io.Closeable; import java.io.IOException; import java.util.ArrayList; Loading Loading @@ -326,11 +327,13 @@ public class RecentsLoader extends AsyncTaskLoader<DirectoryResult> { final Cursor[] res = new Cursor[rootIds.size()]; mCursors = new Cursor[rootIds.size()]; for (int i = 0; i < rootIds.size(); i++) { final Uri uri = DocumentsContract.buildRecentDocumentsUri(authority, rootIds.get(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, null, null, mState.sortModel.getDocumentSortQuery()); res[i] = client.query(uri, null, queryArgs, null); mCursors[i] = new RootCursorWrapper(authority, rootIds.get(i), res[i], MAX_DOCS_FROM_ROOT); } catch (Exception e) { Loading src/com/android/documentsui/base/DebugFlags.java +25 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,11 @@ */ package com.android.documentsui.base; import android.content.ContentResolver; import android.os.Bundle; import com.android.documentsui.queries.DebugCommandProcessor; import javax.annotation.Nullable; /** Loading @@ -27,6 +32,8 @@ public final class DebugFlags { private static String mQvPackage; private static boolean sGestureScaleEnabled; private static boolean sDocumentDetailsEnabled; private static int sForcedPageOffset = -1; private static int sForcedPageLimit = -1; public static void setQuickViewer(@Nullable String qvPackage) { mQvPackage = qvPackage; Loading @@ -51,4 +58,22 @@ public final class DebugFlags { public static boolean getGestureScaleEnabled() { return sGestureScaleEnabled; } public static void setForcedPaging(int offset, int limit) { sForcedPageOffset = offset; sForcedPageLimit = limit; } public static boolean addForcedPagingArgs(Bundle queryArgs) { boolean flagsAdded = false; if (sForcedPageOffset >= 0) { queryArgs.putInt(ContentResolver.QUERY_ARG_OFFSET, sForcedPageOffset); flagsAdded |= true; } if (sForcedPageLimit >= 0) { queryArgs.putInt(ContentResolver.QUERY_ARG_LIMIT, sForcedPageLimit); flagsAdded |= true; } return flagsAdded; } } src/com/android/documentsui/queries/DebugCommandProcessor.java +26 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ public final class DebugCommandProcessor implements EventHandler<String> { mCommands.add(DebugCommandProcessor::quickViewer); mCommands.add(DebugCommandProcessor::gestureScale); mCommands.add(DebugCommandProcessor::docDetails); mCommands.add(DebugCommandProcessor::forcePaging); } } Loading Loading @@ -108,6 +109,31 @@ public final class DebugCommandProcessor implements EventHandler<String> { return false; } private static boolean forcePaging(String[] tokens) { if ("page".equals(tokens[0])) { if (tokens.length >= 2) { try { int offset = Integer.parseInt(tokens[1]); int limit = (tokens.length == 3) ? Integer.parseInt(tokens[2]) : -1; DebugFlags.setForcedPaging(offset, limit); Log.i(TAG, "Set forced paging to offset: " + offset + ", limit: " + limit); return true; } catch (NumberFormatException e) { Log.w(TAG, "Command input does not contain valid numbers: " + TextUtils.join(" ", tokens)); return false; } } else { Log.w(TAG, "Invalid command structure: " + TextUtils.join(" ", tokens)); } } else if ("deqv".equals(tokens[0])) { Log.i(TAG, "Unset quick viewer"); DebugFlags.setQuickViewer(null); return true; } return false; } private static final boolean asBool(String val) { if (val == null || val.equals("0")) { return false; Loading src/com/android/documentsui/sorting/SortModel.java +19 −11 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.annotation.IntDef; import android.annotation.Nullable; import android.content.ContentResolver; import android.database.Cursor; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.provider.DocumentsContract.Document; Loading Loading @@ -239,20 +240,26 @@ public class SortModel implements Parcelable { } } public @Nullable String getDocumentSortQuery() { public void addQuerySortArgs(Bundle queryArgs) { final int id = getSortedDimensionId(); final String columnName; switch (id) { case SORT_DIMENSION_ID_UNKNOWN: return null; return; case SortModel.SORT_DIMENSION_ID_TITLE: columnName = Document.COLUMN_DISPLAY_NAME; queryArgs.putStringArray( ContentResolver.QUERY_ARG_SORT_COLUMNS, new String[]{ Document.COLUMN_DISPLAY_NAME }); break; case SortModel.SORT_DIMENSION_ID_DATE: columnName = Document.COLUMN_LAST_MODIFIED; queryArgs.putStringArray( ContentResolver.QUERY_ARG_SORT_COLUMNS, new String[]{ Document.COLUMN_LAST_MODIFIED }); break; case SortModel.SORT_DIMENSION_ID_SIZE: columnName = Document.COLUMN_SIZE; queryArgs.putStringArray( ContentResolver.QUERY_ARG_SORT_COLUMNS, new String[]{ Document.COLUMN_SIZE }); break; default: throw new IllegalStateException( Loading @@ -260,20 +267,21 @@ public class SortModel implements Parcelable { } final SortDimension dimension = getDimensionById(id); final String direction; switch (dimension.getSortDirection()) { case SortDimension.SORT_DIRECTION_ASCENDING: direction = " ASC"; queryArgs.putInt( ContentResolver.QUERY_ARG_SORT_DIRECTION, ContentResolver.QUERY_SORT_DIRECTION_ASCENDING); break; case SortDimension.SORT_DIRECTION_DESCENDING: direction = " DESC"; queryArgs.putInt( ContentResolver.QUERY_ARG_SORT_DIRECTION, ContentResolver.QUERY_SORT_DIRECTION_DESCENDING); break; default: throw new IllegalStateException( "Unexpected sort direction: " + dimension.getSortDirection()); } return columnName + direction; } private void notifyListeners(@UpdateType int updateType) { Loading Loading
src/com/android/documentsui/DirectoryLoader.java +16 −2 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.Context; import android.database.ContentObserver; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.os.CancellationSignal; import android.os.Handler; import android.os.OperationCanceledException; Loading @@ -30,6 +31,7 @@ import android.os.RemoteException; import android.provider.DocumentsContract.Document; import android.util.Log; import com.android.documentsui.base.DebugFlags; import com.android.documentsui.base.DocumentInfo; import com.android.documentsui.base.FilteringCursorWrapper; import com.android.documentsui.base.RootInfo; Loading Loading @@ -92,12 +94,24 @@ public class DirectoryLoader extends AsyncTaskLoader<DirectoryResult> { Cursor cursor; try { client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, authority); cursor = client.query( mUri, null, null, null, mModel.getDocumentSortQuery(), mSignal); 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); cursor = client.query(mUri, null, queryArgs, mSignal); if (cursor == null) { throw new RemoteException("Provider returned null"); } 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)); } cursor.registerContentObserver(mObserver); cursor = new RootCursorWrapper(mUri.getAuthority(), mRoot.rootId, cursor, -1); Loading
src/com/android/documentsui/RecentsLoader.java +9 −6 Original line number Diff line number Diff line Loading @@ -35,15 +35,16 @@ import android.util.Log; import com.android.documentsui.base.FilteringCursorWrapper; import com.android.documentsui.base.RootInfo; import com.android.documentsui.base.Shared; import com.android.documentsui.base.State; import com.android.documentsui.roots.RootCursorWrapper; import com.android.documentsui.roots.RootsAccess; import com.android.internal.annotations.GuardedBy; import libcore.io.IoUtils; import com.google.common.util.concurrent.AbstractFuture; import libcore.io.IoUtils; import java.io.Closeable; import java.io.IOException; import java.util.ArrayList; Loading Loading @@ -326,11 +327,13 @@ public class RecentsLoader extends AsyncTaskLoader<DirectoryResult> { final Cursor[] res = new Cursor[rootIds.size()]; mCursors = new Cursor[rootIds.size()]; for (int i = 0; i < rootIds.size(); i++) { final Uri uri = DocumentsContract.buildRecentDocumentsUri(authority, rootIds.get(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, null, null, mState.sortModel.getDocumentSortQuery()); res[i] = client.query(uri, null, queryArgs, null); mCursors[i] = new RootCursorWrapper(authority, rootIds.get(i), res[i], MAX_DOCS_FROM_ROOT); } catch (Exception e) { Loading
src/com/android/documentsui/base/DebugFlags.java +25 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,11 @@ */ package com.android.documentsui.base; import android.content.ContentResolver; import android.os.Bundle; import com.android.documentsui.queries.DebugCommandProcessor; import javax.annotation.Nullable; /** Loading @@ -27,6 +32,8 @@ public final class DebugFlags { private static String mQvPackage; private static boolean sGestureScaleEnabled; private static boolean sDocumentDetailsEnabled; private static int sForcedPageOffset = -1; private static int sForcedPageLimit = -1; public static void setQuickViewer(@Nullable String qvPackage) { mQvPackage = qvPackage; Loading @@ -51,4 +58,22 @@ public final class DebugFlags { public static boolean getGestureScaleEnabled() { return sGestureScaleEnabled; } public static void setForcedPaging(int offset, int limit) { sForcedPageOffset = offset; sForcedPageLimit = limit; } public static boolean addForcedPagingArgs(Bundle queryArgs) { boolean flagsAdded = false; if (sForcedPageOffset >= 0) { queryArgs.putInt(ContentResolver.QUERY_ARG_OFFSET, sForcedPageOffset); flagsAdded |= true; } if (sForcedPageLimit >= 0) { queryArgs.putInt(ContentResolver.QUERY_ARG_LIMIT, sForcedPageLimit); flagsAdded |= true; } return flagsAdded; } }
src/com/android/documentsui/queries/DebugCommandProcessor.java +26 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ public final class DebugCommandProcessor implements EventHandler<String> { mCommands.add(DebugCommandProcessor::quickViewer); mCommands.add(DebugCommandProcessor::gestureScale); mCommands.add(DebugCommandProcessor::docDetails); mCommands.add(DebugCommandProcessor::forcePaging); } } Loading Loading @@ -108,6 +109,31 @@ public final class DebugCommandProcessor implements EventHandler<String> { return false; } private static boolean forcePaging(String[] tokens) { if ("page".equals(tokens[0])) { if (tokens.length >= 2) { try { int offset = Integer.parseInt(tokens[1]); int limit = (tokens.length == 3) ? Integer.parseInt(tokens[2]) : -1; DebugFlags.setForcedPaging(offset, limit); Log.i(TAG, "Set forced paging to offset: " + offset + ", limit: " + limit); return true; } catch (NumberFormatException e) { Log.w(TAG, "Command input does not contain valid numbers: " + TextUtils.join(" ", tokens)); return false; } } else { Log.w(TAG, "Invalid command structure: " + TextUtils.join(" ", tokens)); } } else if ("deqv".equals(tokens[0])) { Log.i(TAG, "Unset quick viewer"); DebugFlags.setQuickViewer(null); return true; } return false; } private static final boolean asBool(String val) { if (val == null || val.equals("0")) { return false; Loading
src/com/android/documentsui/sorting/SortModel.java +19 −11 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.annotation.IntDef; import android.annotation.Nullable; import android.content.ContentResolver; import android.database.Cursor; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.provider.DocumentsContract.Document; Loading Loading @@ -239,20 +240,26 @@ public class SortModel implements Parcelable { } } public @Nullable String getDocumentSortQuery() { public void addQuerySortArgs(Bundle queryArgs) { final int id = getSortedDimensionId(); final String columnName; switch (id) { case SORT_DIMENSION_ID_UNKNOWN: return null; return; case SortModel.SORT_DIMENSION_ID_TITLE: columnName = Document.COLUMN_DISPLAY_NAME; queryArgs.putStringArray( ContentResolver.QUERY_ARG_SORT_COLUMNS, new String[]{ Document.COLUMN_DISPLAY_NAME }); break; case SortModel.SORT_DIMENSION_ID_DATE: columnName = Document.COLUMN_LAST_MODIFIED; queryArgs.putStringArray( ContentResolver.QUERY_ARG_SORT_COLUMNS, new String[]{ Document.COLUMN_LAST_MODIFIED }); break; case SortModel.SORT_DIMENSION_ID_SIZE: columnName = Document.COLUMN_SIZE; queryArgs.putStringArray( ContentResolver.QUERY_ARG_SORT_COLUMNS, new String[]{ Document.COLUMN_SIZE }); break; default: throw new IllegalStateException( Loading @@ -260,20 +267,21 @@ public class SortModel implements Parcelable { } final SortDimension dimension = getDimensionById(id); final String direction; switch (dimension.getSortDirection()) { case SortDimension.SORT_DIRECTION_ASCENDING: direction = " ASC"; queryArgs.putInt( ContentResolver.QUERY_ARG_SORT_DIRECTION, ContentResolver.QUERY_SORT_DIRECTION_ASCENDING); break; case SortDimension.SORT_DIRECTION_DESCENDING: direction = " DESC"; queryArgs.putInt( ContentResolver.QUERY_ARG_SORT_DIRECTION, ContentResolver.QUERY_SORT_DIRECTION_DESCENDING); break; default: throw new IllegalStateException( "Unexpected sort direction: " + dimension.getSortDirection()); } return columnName + direction; } private void notifyListeners(@UpdateType int updateType) { Loading