Merge "Update preconditions to be asserts..." into nyc-dev

am: 9e9bce724e

* commit '9e9bce724e73c4d553dc1ff0ff8f80289487f609':
  Update preconditions to be asserts...
This commit is contained in:
Steve McKay
2016-02-29 23:01:23 +00:00
committed by android-build-merger
29 changed files with 129 additions and 145 deletions

View File

@@ -30,6 +30,10 @@ LOCAL_AAPT_FLAGS := \
--extra-packages android.support.design \
--extra-packages android.support.v7.recyclerview
LOCAL_JACK_FLAGS := \
-D jack.assert.policy=enable \
-D jack.optimization.inner-class.accessors=true
LOCAL_PACKAGE_NAME := DocumentsUI
LOCAL_CERTIFICATE := platform

View File

@@ -22,8 +22,6 @@ import static com.android.documentsui.dirlist.DirectoryFragment.ANIM_ENTER;
import static com.android.documentsui.dirlist.DirectoryFragment.ANIM_LEAVE;
import static com.android.documentsui.dirlist.DirectoryFragment.ANIM_NONE;
import static com.android.documentsui.dirlist.DirectoryFragment.ANIM_SIDE;
import static com.android.internal.util.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import android.app.Activity;
import android.app.Fragment;
@@ -54,7 +52,6 @@ import com.android.documentsui.dirlist.Model;
import com.android.documentsui.model.DocumentInfo;
import com.android.documentsui.model.DocumentStack;
import com.android.documentsui.model.RootInfo;
import com.android.internal.util.Preconditions;
import java.io.FileNotFoundException;
import java.util.ArrayList;
@@ -330,7 +327,8 @@ public abstract class BaseActivity extends Activity
}
void openContainerDocument(DocumentInfo doc) {
checkArgument(doc.isContainer());
assert(doc.isContainer());
mState.pushDocument(doc);
// Show an opening animation only if pressing "back" would get us back to the
// previous directory. Especially after opening a root document, pressing
@@ -373,7 +371,8 @@ public abstract class BaseActivity extends Activity
@Override
public void onSearchChanged(@Nullable String query) {
// We should not get here if root is not searchable
checkState(canSearchRoot());
assert(canSearchRoot());
reloadSearch(query);
}
@@ -673,7 +672,8 @@ public abstract class BaseActivity extends Activity
@Override
protected RootInfo run(RootInfo... roots) {
checkArgument(roots.length == 1);
assert(roots.length == 1);
final RootInfo currentRoot = roots[0];
final Collection<RootInfo> cachedRoots = mOwner.mRoots.getRootsBlocking();
RootInfo homeRoot = null;
@@ -686,7 +686,7 @@ public abstract class BaseActivity extends Activity
return null;
}
}
Preconditions.checkNotNull(homeRoot);
assert(homeRoot != null);
mHome = mOwner.getRootDocumentBlocking(homeRoot);
return homeRoot;
}

View File

@@ -28,7 +28,6 @@ import android.support.annotation.Nullable;
import android.util.Log;
import com.android.documentsui.model.DocumentInfo;
import com.android.internal.util.Preconditions;
import libcore.io.IoUtils;
@@ -85,7 +84,7 @@ public final class DocumentClipper {
* This should be run from inside an AsyncTask.
*/
public List<DocumentInfo> getDocumentsFromClipData(ClipData clipData) {
Preconditions.checkNotNull(clipData);
assert(clipData != null);
final List<DocumentInfo> srcDocs = new ArrayList<>();
int count = clipData.getItemCount();

View File

@@ -23,7 +23,6 @@ import static com.android.documentsui.State.ACTION_OPEN;
import static com.android.documentsui.State.ACTION_OPEN_TREE;
import static com.android.documentsui.State.ACTION_PICK_COPY_DESTINATION;
import static com.android.documentsui.dirlist.DirectoryFragment.ANIM_NONE;
import static com.android.internal.util.Preconditions.checkArgument;
import android.app.Activity;
import android.app.Fragment;
@@ -333,7 +332,7 @@ public class DocumentsActivity extends BaseActivity {
@Override
void onDirectoryCreated(DocumentInfo doc) {
checkArgument(doc.isDirectory());
assert(doc.isDirectory());
openContainerDocument(doc);
}

View File

@@ -16,10 +16,8 @@
package com.android.documentsui;
import static com.android.documentsui.Shared.DEBUG;
import static com.android.documentsui.State.ACTION_MANAGE;
import static com.android.documentsui.dirlist.DirectoryFragment.ANIM_NONE;
import static com.android.internal.util.Preconditions.checkState;
import android.app.Activity;
import android.app.Fragment;
@@ -41,7 +39,6 @@ import com.android.documentsui.dirlist.DirectoryFragment;
import com.android.documentsui.dirlist.Model;
import com.android.documentsui.model.DocumentInfo;
import com.android.documentsui.model.RootInfo;
import com.android.internal.util.Preconditions;
import java.util.Arrays;
import java.util.List;
@@ -121,11 +118,11 @@ public class DownloadsActivity extends BaseActivity {
final RootInfo root = getCurrentRoot();
final DocumentInfo cwd = getCurrentDirectory();
if (DEBUG) checkState(!mSearchManager.isSearching());
assert(!mSearchManager.isSearching());
// If started in manage roots mode, there has to be a cwd (i.e. the root dir of the managed
// root).
Preconditions.checkNotNull(cwd);
assert(cwd != null);
// Normal boring directory
DirectoryFragment.showDirectory(fm, root, cwd, anim);
@@ -133,7 +130,8 @@ public class DownloadsActivity extends BaseActivity {
@Override
public void onDocumentPicked(DocumentInfo doc, Model model) {
Preconditions.checkArgument(!doc.isDirectory());
assert(!doc.isDirectory());
// First try managing the document; we expect manager to filter
// based on authority, so we don't grant.
final Intent manage = new Intent(DocumentsContract.ACTION_MANAGE_DOCUMENT);

View File

@@ -16,8 +16,6 @@
package com.android.documentsui;
import static com.android.internal.util.Preconditions.checkArgument;
import android.app.Activity;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
@@ -83,7 +81,7 @@ abstract class DrawerController implements DrawerListener {
DrawerLayout layout, View drawer, ActionBarDrawerToggle toggle,
Toolbar drawerToolbar) {
mToolbar = drawerToolbar;
checkArgument(layout != null);
assert(layout != null);
mLayout = layout;
mDrawer = drawer;

View File

@@ -19,8 +19,6 @@ package com.android.documentsui;
import static com.android.documentsui.OperationDialogFragment.DIALOG_TYPE_UNKNOWN;
import static com.android.documentsui.Shared.DEBUG;
import static com.android.documentsui.dirlist.DirectoryFragment.ANIM_NONE;
import static com.android.internal.util.Preconditions.checkArgument;
import static com.android.internal.util.Preconditions.checkState;
import android.app.Activity;
import android.app.FragmentManager;
@@ -97,11 +95,11 @@ public class FilesActivity extends BaseActivity {
// Launch URIs support sensible activity management, but don't specify a real
// content target.
if (DEBUG) Log.d(TAG, "Launching with non-empty stack.");
checkState(uri == null || uri.getAuthority() == null ||
assert(uri == null || uri.getAuthority() == null ||
LauncherActivity.isLaunchUri(uri));
refreshCurrentRootAndDirectory(ANIM_NONE);
} else if (intent.getAction() == Intent.ACTION_VIEW) {
checkArgument(uri != null);
assert(uri != null);
new OpenUriForViewTask(this).executeOnExecutor(
ProviderExecutor.forAuthority(uri.getAuthority()), uri);
} else if (DocumentsContract.isRootUri(this, uri)) {
@@ -143,7 +141,7 @@ public class FilesActivity extends BaseActivity {
state.allowMultiple = true;
// Options specific to the DocumentsActivity.
checkArgument(!intent.hasExtra(Intent.EXTRA_LOCAL_ONLY));
assert(!intent.hasExtra(Intent.EXTRA_LOCAL_ONLY));
final DocumentStack stack = intent.getParcelableExtra(Shared.EXTRA_STACK);
if (stack != null) {
@@ -212,7 +210,7 @@ public class FilesActivity extends BaseActivity {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_create_dir:
checkState(canCreateDirectory());
assert(canCreateDirectory());
showCreateDirectoryDialog();
return true;
case R.id.menu_new_window:
@@ -250,7 +248,7 @@ public class FilesActivity extends BaseActivity {
final RootInfo root = getCurrentRoot();
final DocumentInfo cwd = getCurrentDirectory();
if (DEBUG) checkState(!mSearchManager.isSearching());
assert(!mSearchManager.isSearching());
if (cwd == null) {
DirectoryFragment.showRecentsOpen(fm, anim);

View File

@@ -17,7 +17,6 @@
package com.android.documentsui;
import static com.android.documentsui.State.MODE_UNKNOWN;
import static com.android.internal.util.Preconditions.checkArgument;
import android.content.Context;
import android.preference.PreferenceManager;
@@ -59,7 +58,8 @@ public class LocalPreferences {
}
public static void setViewMode(Context context, RootInfo root, @ViewMode int viewMode) {
checkArgument(viewMode != MODE_UNKNOWN);
assert(viewMode != MODE_UNKNOWN);
PreferenceManager.getDefaultSharedPreferences(context).edit()
.putInt(createKey(root), viewMode).apply();
}

View File

@@ -17,7 +17,6 @@
package com.android.documentsui;
import static com.android.documentsui.Shared.DEBUG;
import static com.android.internal.util.Preconditions.checkArgument;
import android.annotation.IntDef;
import android.annotation.Nullable;
@@ -363,7 +362,7 @@ public final class Metrics {
if (operationType == FileOperationService.OPERATION_DELETE) {
logHistogram(context, histogram, FILEOP_DELETE);
} else {
checkArgument(dst != null);
assert(dst != null);
@Provider int providerType =
isSystemProvider(dst.authority) ? PROVIDER_SYSTEM : PROVIDER_EXTERNAL;
logHistogram(context, histogram, getOpCode(operationType, providerType));

View File

@@ -19,7 +19,6 @@ package com.android.documentsui;
import static com.android.documentsui.services.FileOperationService.OPERATION_DELETE;
import static com.android.documentsui.services.FileOperationService.OPERATION_MOVE;
import static com.android.documentsui.services.FileOperationService.OPERATION_UNKNOWN;
import static com.android.internal.util.Preconditions.checkArgument;
import android.app.Activity;
import android.app.Fragment;
@@ -101,7 +100,8 @@ public class PickFragment extends Fragment {
*/
public void setPickTarget(
int action, @OpType int copyOperationSubType, DocumentInfo pickTarget) {
checkArgument(copyOperationSubType != OPERATION_DELETE);
assert(copyOperationSubType != OPERATION_DELETE);
mAction = action;
mCopyOperationSubType = copyOperationSubType;
mPickTarget = pickTarget;

View File

@@ -19,7 +19,6 @@ package com.android.documentsui;
import android.os.AsyncTask;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
@@ -85,7 +84,7 @@ public class ProviderExecutor extends Thread implements Executor {
private Executor mNonPreemptingExecutor = new Executor() {
@Override
public void execute(Runnable command) {
Preconditions.checkNotNull(command);
assert(command != null);
mQueue.add(command);
}
};
@@ -93,7 +92,7 @@ public class ProviderExecutor extends Thread implements Executor {
@Override
public void execute(Runnable command) {
preempt();
Preconditions.checkNotNull(command);
assert(command != null);
mQueue.add(command);
}

View File

@@ -18,7 +18,6 @@ package com.android.documentsui;
import static com.android.documentsui.Shared.DEBUG;
import static com.android.documentsui.Shared.TAG;
import static com.android.internal.util.Preconditions.checkState;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
@@ -41,7 +40,6 @@ import android.util.Log;
import com.android.documentsui.model.RootInfo;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
@@ -118,17 +116,16 @@ public class RootsCache {
*/
public void updateAsync() {
// Verifying an assumption about the recents root being immutable.
if (DEBUG) {
checkState(mRecentsRoot.authority == null);
checkState(mRecentsRoot.rootId == null);
checkState(mRecentsRoot.derivedIcon == R.drawable.ic_root_recent);
checkState(mRecentsRoot.derivedType == RootInfo.TYPE_RECENTS);
checkState(mRecentsRoot.flags == (Root.FLAG_LOCAL_ONLY
| Root.FLAG_SUPPORTS_IS_CHILD
| Root.FLAG_SUPPORTS_CREATE));
checkState(mRecentsRoot.title == mContext.getString(R.string.root_recent));
checkState(mRecentsRoot.availableBytes == -1);
}
assert(mRecentsRoot.authority == null);
assert(mRecentsRoot.rootId == null);
assert(mRecentsRoot.derivedIcon == R.drawable.ic_root_recent);
assert(mRecentsRoot.derivedType == RootInfo.TYPE_RECENTS);
assert(mRecentsRoot.flags == (Root.FLAG_LOCAL_ONLY
| Root.FLAG_SUPPORTS_IS_CHILD
| Root.FLAG_SUPPORTS_CREATE));
assert(mRecentsRoot.title == mContext.getString(R.string.root_recent));
assert(mRecentsRoot.availableBytes == -1);
new UpdateTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

View File

@@ -61,7 +61,8 @@ final class SearchViewManager implements
}
public void install(DocumentsToolbar actionBar) {
assert (mActionBar == null);
// assert(mActionBar == null);
mActionBar = actionBar;
mMenu = actionBar.getSearchMenu();
mView = (SearchView) mMenu.getActionView();

View File

@@ -28,6 +28,10 @@ import java.util.List;
/** @hide */
public final class Shared {
public static final String TAG = "Documents";
public static final boolean DEBUG = true;
/** Intent action name to pick a copy destination. */
public static final String ACTION_PICK_COPY_DESTINATION =
"com.android.documentsui.PICK_COPY_DESTINATION";
@@ -79,9 +83,6 @@ public final class Shared {
*/
public static final String EXTRA_IGNORE_STATE = "ignoreState";
public static final boolean DEBUG = true;
public static final String TAG = "Documents";
/**
* String prefix used to indicate the document is a directory.

View File

@@ -16,8 +16,6 @@
package com.android.documentsui;
import static com.android.internal.util.Preconditions.checkNotNull;
import android.app.Activity;
import android.support.design.widget.Snackbar;
import android.view.View;
@@ -26,12 +24,13 @@ public final class Snackbars {
private Snackbars() {}
public static final Snackbar makeSnackbar(Activity activity, int messageId, int duration) {
return Snackbars.makeSnackbar(activity, activity.getResources().getText(messageId), duration);
return Snackbars.makeSnackbar(
activity, activity.getResources().getText(messageId), duration);
}
public static final Snackbar makeSnackbar(Activity activity, CharSequence message, int duration)
{
final View view = checkNotNull(activity.findViewById(R.id.coordinator_layout));
public static final Snackbar makeSnackbar(
Activity activity, CharSequence message, int duration) {
final View view = activity.findViewById(R.id.coordinator_layout);
return Snackbar.make(view, message, duration);
}
}

View File

@@ -23,9 +23,6 @@ import static com.android.documentsui.State.MODE_LIST;
import static com.android.documentsui.State.SORT_ORDER_UNKNOWN;
import static com.android.documentsui.model.DocumentInfo.getCursorInt;
import static com.android.documentsui.model.DocumentInfo.getCursorString;
import static com.android.internal.util.Preconditions.checkNotNull;
import static com.android.internal.util.Preconditions.checkState;
import static com.google.common.base.Preconditions.checkArgument;
import android.annotation.IntDef;
import android.annotation.StringRes;
@@ -102,6 +99,7 @@ import com.android.documentsui.model.RootInfo;
import com.android.documentsui.services.FileOperationService;
import com.android.documentsui.services.FileOperationService.OpType;
import com.android.documentsui.services.FileOperations;
import com.google.common.collect.Lists;
import java.lang.annotation.Retention;
@@ -359,7 +357,9 @@ public class DirectoryFragment extends Fragment
private boolean handleViewItem(String id) {
final Cursor cursor = mModel.getItem(id);
checkNotNull(cursor, "Cursor cannot be null.");
assert(cursor != null);
final String docMimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
if (mTuner.isDocumentEnabled(docMimeType, docFlags)) {
@@ -430,7 +430,8 @@ public class DirectoryFragment extends Fragment
int cellMargin = 2 * getResources().getDimensionPixelSize(R.dimen.grid_item_margin);
int viewPadding = mRecView.getPaddingLeft() + mRecView.getPaddingRight();
checkState(mRecView.getWidth() > 0);
assert(mRecView.getWidth() > 0);
int columnCount = Math.max(1,
(mRecView.getWidth() - viewPadding) / (cellWidth + cellMargin));
@@ -471,7 +472,9 @@ public class DirectoryFragment extends Fragment
public boolean onBeforeItemStateChange(String modelId, boolean selected) {
if (selected) {
final Cursor cursor = mModel.getItem(modelId);
checkNotNull(cursor, "Cursor cannot be null.");
assert(cursor != null);
final String docMimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
return mTuner.canSelectType(docMimeType, docFlags);
@@ -564,7 +567,7 @@ public class DirectoryFragment extends Fragment
}
private void updateActionMenu() {
checkNotNull(mMenu);
assert(mMenu != null);
// Delegate update logic to our owning action, since specialized logic is desired.
mTuner.updateActionMenu(mMenu, mType, canDeleteSelection(), canRenameSelection());
@@ -699,8 +702,8 @@ public class DirectoryFragment extends Fragment
}
private void deleteDocuments(final Selection selected) {
assert(!selected.isEmpty());
checkArgument(!selected.isEmpty());
final DocumentInfo srcParent = getDisplayState().stack.peek();
new GetDocumentsTask() {
@Override
@@ -777,7 +780,7 @@ public class DirectoryFragment extends Fragment
private void renameDocuments(Selection selected) {
// Batch renaming not supported
// Rename option is only available in menu when 1 document selected
checkArgument(selected.size() == 1);
assert(selected.size() == 1);
new GetDocumentsTask() {
@Override
@@ -890,7 +893,8 @@ public class DirectoryFragment extends Fragment
}
private void copyFromClipData(final ClipData clipData, final DocumentInfo destination) {
checkNotNull(clipData);
assert(clipData != null);
new AsyncTask<Void, Void, List<DocumentInfo>>() {
@Override
@@ -941,7 +945,7 @@ public class DirectoryFragment extends Fragment
}
void copySelectionToClipboard(Selection selection) {
checkArgument(!selection.isEmpty());
assert(!selection.isEmpty());
new GetDocumentsTask() {
@Override
void onDocumentsReady(List<DocumentInfo> docs) {
@@ -1059,7 +1063,7 @@ public class DirectoryFragment extends Fragment
String id = getModelId(v);
if (id != null) {
Cursor dstCursor = mModel.getItem(id);
checkNotNull(dstCursor, "Cursor cannot be null.");
assert(dstCursor != null);
return DocumentInfo.fromDirectoryCursor(dstCursor);
}
@@ -1132,10 +1136,11 @@ public class DirectoryFragment extends Fragment
}
final Cursor cursor = mModel.getItem(modelId);
checkNotNull(cursor, "Cursor cannot be null.");
final DocumentInfo doc = DocumentInfo.fromDirectoryCursor(cursor);
return Lists.newArrayList(doc);
assert(cursor != null);
return Lists.newArrayList(
DocumentInfo.fromDirectoryCursor(cursor));
}
private Drawable getDragShadowIcon(List<DocumentInfo> docs) {

View File

@@ -16,9 +16,6 @@
package com.android.documentsui.dirlist;
import static com.android.internal.util.Preconditions.checkNotNull;
import static com.android.internal.util.Preconditions.checkState;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Rect;
@@ -97,19 +94,20 @@ public abstract class DocumentHolder
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// Event listener should always be set.
checkNotNull(mEventListener);
assert(mEventListener != null);
return mEventListener.onKey(this, keyCode, event);
}
public void addEventListener(DocumentHolder.EventListener listener) {
// Just handle one for now; switch to a list if necessary.
checkState(mEventListener == null);
assert(mEventListener == null);
mEventListener = listener;
}
public void addOnKeyListener(View.OnKeyListener listener) {
// Just handle one for now; switch to a list if necessary.
checkState(mKeyListener == null);
assert(mKeyListener == null);
mKeyListener = listener;
}

View File

@@ -22,7 +22,6 @@ import static com.android.documentsui.State.ACTION_GET_CONTENT;
import static com.android.documentsui.State.ACTION_MANAGE;
import static com.android.documentsui.State.ACTION_OPEN;
import static com.android.documentsui.State.ACTION_OPEN_TREE;
import static com.android.internal.util.Preconditions.checkArgument;
import android.content.Context;
import android.provider.DocumentsContract.Document;
@@ -172,7 +171,7 @@ public abstract class FragmentTuner {
@Override
public void updateActionMenu(
Menu menu, @ResultType int resultType, boolean canDelete, boolean canRename) {
checkArgument(resultType != DirectoryFragment.TYPE_RECENT_OPEN);
assert(resultType != DirectoryFragment.TYPE_RECENT_OPEN);
MenuItem open = menu.findItem(R.id.menu_open);
MenuItem delete = menu.findItem(R.id.menu_delete);

View File

@@ -17,7 +17,6 @@
package com.android.documentsui.dirlist;
import static com.android.documentsui.model.DocumentInfo.getCursorString;
import static com.android.internal.util.Preconditions.checkNotNull;
import android.content.Context;
import android.database.Cursor;
@@ -58,7 +57,7 @@ final class GridDirectoryHolder extends DocumentHolder {
* @param state Current display state.
*/
public void bind(Cursor cursor, String modelId, State state) {
checkNotNull(cursor, "Cursor cannot be null.");
assert(cursor != null);
this.modelId = modelId;

View File

@@ -19,7 +19,6 @@ package com.android.documentsui.dirlist;
import static com.android.documentsui.model.DocumentInfo.getCursorInt;
import static com.android.documentsui.model.DocumentInfo.getCursorLong;
import static com.android.documentsui.model.DocumentInfo.getCursorString;
import static com.android.internal.util.Preconditions.checkNotNull;
import android.content.Context;
import android.database.Cursor;
@@ -79,9 +78,9 @@ final class GridDocumentHolder extends DocumentHolder {
* @param state Current display state.
*/
public void bind(Cursor cursor, String modelId, State state) {
this.modelId = modelId;
assert(cursor != null);
checkNotNull(cursor, "Cursor cannot be null.");
this.modelId = modelId;
final String docAuthority = getCursorString(cursor, RootCursorWrapper.COLUMN_AUTHORITY);
final String docId = getCursorString(cursor, Document.COLUMN_DOCUMENT_ID);

View File

@@ -19,7 +19,6 @@ package com.android.documentsui.dirlist;
import static com.android.documentsui.model.DocumentInfo.getCursorInt;
import static com.android.documentsui.model.DocumentInfo.getCursorLong;
import static com.android.documentsui.model.DocumentInfo.getCursorString;
import static com.android.internal.util.Preconditions.checkNotNull;
import android.content.Context;
import android.database.Cursor;
@@ -79,9 +78,9 @@ final class ListDocumentHolder extends DocumentHolder {
*/
@Override
public void bind(Cursor cursor, String modelId, State state) {
this.modelId = modelId;
assert(cursor != null);
checkNotNull(cursor, "Cursor cannot be null.");
this.modelId = modelId;
final String docAuthority = getCursorString(cursor, RootCursorWrapper.COLUMN_AUTHORITY);
final String docId = getCursorString(cursor, Document.COLUMN_DOCUMENT_ID);

View File

@@ -22,11 +22,9 @@ import static com.android.documentsui.State.SORT_ORDER_LAST_MODIFIED;
import static com.android.documentsui.State.SORT_ORDER_SIZE;
import static com.android.documentsui.model.DocumentInfo.getCursorLong;
import static com.android.documentsui.model.DocumentInfo.getCursorString;
import static com.android.internal.util.Preconditions.checkNotNull;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Looper;
import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Document;
import android.support.annotation.Nullable;
@@ -381,9 +379,9 @@ public class Model {
final List<DocumentInfo> docs = new ArrayList<>(size);
for (String modelId: items.getAll()) {
final Cursor cursor = getItem(modelId);
checkNotNull(cursor, "Cursor cannot be null.");
final DocumentInfo doc = DocumentInfo.fromDirectoryCursor(cursor);
docs.add(doc);
assert(cursor != null);
docs.add(DocumentInfo.fromDirectoryCursor(cursor));
}
return docs;
}

View File

@@ -19,9 +19,6 @@ package com.android.documentsui.dirlist;
import static com.android.documentsui.Shared.DEBUG;
import static com.android.documentsui.dirlist.ModelBackedDocumentsAdapter.ITEM_TYPE_DIRECTORY;
import static com.android.documentsui.dirlist.ModelBackedDocumentsAdapter.ITEM_TYPE_DOCUMENT;
import static com.android.internal.util.Preconditions.checkArgument;
import static com.android.internal.util.Preconditions.checkNotNull;
import static com.android.internal.util.Preconditions.checkState;
import android.annotation.IntDef;
import android.graphics.Point;
@@ -134,8 +131,12 @@ public final class MultiSelectManager {
@SelectionMode int mode,
@Nullable Selection initialSelection) {
mEnvironment = checkNotNull(environment, "'environment' cannot be null.");
mAdapter = checkNotNull(adapter, "'adapter' cannot be null.");
assert(environment != null);
assert(adapter != null);
mEnvironment = environment;
mAdapter = adapter;
mSingleSelect = mode == MODE_SINGLE;
if (initialSelection != null) {
mSelection.copyFrom(initialSelection);
@@ -168,8 +169,8 @@ public final class MultiSelectManager {
@Override
public void onItemRangeRemoved(int startPosition, int itemCount) {
checkState(startPosition >= 0);
checkState(itemCount > 0);
assert(startPosition >= 0);
assert(itemCount > 0);
mSelection.cancelProvisionalSelection();
// Remove any disappeared IDs from the selection.
@@ -356,7 +357,8 @@ public final class MultiSelectManager {
* @param modelId
*/
public void toggleSelection(String modelId) {
checkNotNull(modelId);
assert(modelId != null);
boolean changed = false;
if (mSelection.contains(modelId)) {
changed = attemptDeselect(modelId);
@@ -389,7 +391,8 @@ public final class MultiSelectManager {
* @param pos The new end position for the selection range.
*/
void snapRangeSelection(int pos) {
checkNotNull(mRanger);
assert(mRanger != null);
mRanger.snapSelection(pos);
notifySelectionChanged();
}
@@ -436,7 +439,7 @@ public final class MultiSelectManager {
* @param selected New selection state.
*/
private void updateRange(int begin, int end, boolean selected) {
checkState(end >= begin);
assert(end >= begin);
for (int i = begin; i <= end; i++) {
String id = mAdapter.getModelId(i);
if (id == null) {
@@ -474,7 +477,7 @@ public final class MultiSelectManager {
* @return True if the update was applied.
*/
private boolean attemptDeselect(String id) {
checkArgument(id != null);
assert(id != null);
if (notifyBeforeItemStateChange(id, false)) {
mSelection.remove(id);
notifyItemStateChanged(id, false);
@@ -491,7 +494,7 @@ public final class MultiSelectManager {
* @return True if the update was applied.
*/
private boolean attemptSelect(String id) {
checkArgument(id != null);
assert(id != null);
boolean canSelect = notifyBeforeItemStateChange(id, true);
if (!canSelect) {
return false;
@@ -519,7 +522,7 @@ public final class MultiSelectManager {
* (identified by {@code position}) changes.
*/
private void notifyItemStateChanged(String id, boolean selected) {
checkArgument(id != null);
assert(id != null);
int lastListener = mCallbacks.size() - 1;
for (int i = lastListener; i > -1; i--) {
mCallbacks.get(i).onItemStateChanged(id, selected);
@@ -555,8 +558,8 @@ public final class MultiSelectManager {
}
private void snapSelection(int position) {
checkState(mRanger != null);
checkArgument(position != RecyclerView.NO_POSITION);
assert(mRanger != null);
assert(position != RecyclerView.NO_POSITION);
if (mEnd == UNDEFINED || mEnd == mBegin) {
// Reset mEnd so it can be established in establishRange.
@@ -568,7 +571,7 @@ public final class MultiSelectManager {
}
private void establishRange(int position) {
checkState(mRanger.mEnd == UNDEFINED);
assert(mRanger.mEnd == UNDEFINED);
if (position == mBegin) {
mEnd = position;
@@ -584,8 +587,8 @@ public final class MultiSelectManager {
}
private void reviseRange(int position) {
checkState(mEnd != UNDEFINED);
checkState(mBegin != mEnd);
assert(mEnd != UNDEFINED);
assert(mBegin != mEnd);
if (position == mEnd) {
if (DEBUG) Log.i(TAG, "Skipping no-op revision click on mEndRange.");
@@ -1185,7 +1188,7 @@ public final class MultiSelectManager {
* @param input
*/
private void processInputEvent(InputEvent input) {
checkArgument(input.isMouseEvent());
assert(input.isMouseEvent());
if (shouldStop(input)) {
endBandSelect();
@@ -1199,7 +1202,6 @@ public final class MultiSelectManager {
}
mCurrentPosition = input.getOrigin();
mModel.resizeSelection(input.getOrigin());
scrollViewIfNecessary();
resizeBandSelectRectangle();
}
@@ -1488,6 +1490,7 @@ public final class MultiSelectManager {
* top-left of the viewport would have a relative origin of (0, 0), even though its
* absolute point has a higher y-value.
*/
@VisibleForTesting
void resizeSelection(Point relativePointer) {
mPointer = mHelper.createAbsolutePoint(relativePointer);
updateModel();
@@ -1615,7 +1618,7 @@ public final class MultiSelectManager {
private void updateSelection(Rect rect) {
int columnStart =
Collections.binarySearch(mColumnBounds, new Limits(rect.left, rect.left));
checkState(columnStart >= 0);
assert(columnStart >= 0);
int columnEnd = columnStart;
for (int i = columnStart; i < mColumnBounds.size()

View File

@@ -17,7 +17,6 @@
package com.android.documentsui.dirlist;
import static com.android.documentsui.Shared.TAG;
import static com.android.internal.util.Preconditions.checkArgument;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -36,9 +35,9 @@ import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
@@ -205,7 +204,7 @@ public class RenameDocumentFragment extends DialogFragment {
@Override
protected DocumentInfo doInBackground(DocumentInfo... document) {
checkArgument(document.length == 1);
assert(document.length == 1);
final ContentResolver resolver = mActivity.getContentResolver();
ContentProviderClient client = null;

View File

@@ -16,8 +16,6 @@
package com.android.documentsui.dirlist;
import static com.android.internal.util.Preconditions.checkArgument;
import android.content.Context;
import android.database.Cursor;
import android.support.v7.widget.GridLayoutManager;
@@ -204,12 +202,12 @@ final class SectionBreakDocumentsAdapterWrapper extends DocumentsAdapter {
}
public void onItemRangeChanged(int positionStart, int itemCount, Object payload) {
checkArgument(itemCount == 1);
assert(itemCount == 1);
notifyItemRangeChanged(toViewPosition(positionStart), itemCount, payload);
}
public void onItemRangeInserted(int positionStart, int itemCount) {
checkArgument(itemCount == 1);
assert(itemCount == 1);
if (positionStart < mBreakPosition) {
mBreakPosition++;
}
@@ -217,7 +215,7 @@ final class SectionBreakDocumentsAdapterWrapper extends DocumentsAdapter {
}
public void onItemRangeRemoved(int positionStart, int itemCount) {
checkArgument(itemCount == 1);
assert(itemCount == 1);
if (positionStart < mBreakPosition) {
mBreakPosition--;
}

View File

@@ -29,7 +29,6 @@ import static com.android.documentsui.services.FileOperationService.EXTRA_DIALOG
import static com.android.documentsui.services.FileOperationService.EXTRA_OPERATION;
import static com.android.documentsui.services.FileOperationService.EXTRA_SRC_LIST;
import static com.android.documentsui.services.FileOperationService.OPERATION_COPY;
import static com.google.common.base.Preconditions.checkArgument;
import android.annotation.StringRes;
import android.app.Notification;
@@ -95,7 +94,7 @@ class CopyJob extends Job {
String id, DocumentStack stack, List<DocumentInfo> srcs) {
super(service, appContext, listener, OPERATION_COPY, id, stack);
checkArgument(!srcs.isEmpty());
assert(!srcs.isEmpty());
this.mSrcs = srcs;
}
@@ -108,7 +107,7 @@ class CopyJob extends Job {
@OpType int opType, String id, DocumentStack destination, List<DocumentInfo> srcs) {
super(service, appContext, listener, opType, id, destination);
checkArgument(!srcs.isEmpty());
assert(!srcs.isEmpty());
this.mSrcs = srcs;
}

View File

@@ -17,9 +17,6 @@
package com.android.documentsui.services;
import static com.android.documentsui.Shared.DEBUG;
import static com.android.internal.util.Preconditions.checkArgument;
import static com.android.internal.util.Preconditions.checkNotNull;
import static com.android.internal.util.Preconditions.checkState;
import android.annotation.IntDef;
import android.app.NotificationManager;
@@ -136,12 +133,12 @@ public class FileOperationService extends Service implements Job.Listener {
String jobId = intent.getStringExtra(EXTRA_JOB_ID);
@OpType int operationType = intent.getIntExtra(EXTRA_OPERATION, OPERATION_UNKNOWN);
checkArgument(jobId != null);
assert(jobId != null);
if (intent.hasExtra(EXTRA_CANCEL)) {
handleCancel(intent);
} else {
checkArgument(operationType != OPERATION_UNKNOWN);
assert(operationType != OPERATION_UNKNOWN);
handleOperation(intent, serviceId, jobId, operationType);
}
@@ -173,9 +170,9 @@ public class FileOperationService extends Service implements Job.Listener {
mWakeLock.acquire();
}
checkState(job != null);
assert(job != null);
int delay = intent.getIntExtra(EXTRA_DELAY, DEFAULT_DELAY);
checkArgument(delay <= MAX_DELAY);
assert(delay <= MAX_DELAY);
if (DEBUG) Log.d(
TAG, "Scheduling job " + job.id + " to run in " + delay + " milliseconds.");
ScheduledFuture<?> future = executor.schedule(job, delay, TimeUnit.MILLISECONDS);
@@ -188,8 +185,10 @@ public class FileOperationService extends Service implements Job.Listener {
* @param intent The cancellation intent.
*/
private void handleCancel(Intent intent) {
checkArgument(intent.hasExtra(EXTRA_CANCEL));
String jobId = checkNotNull(intent.getStringExtra(EXTRA_JOB_ID));
assert(intent.hasExtra(EXTRA_CANCEL));
assert(intent.getStringExtra(EXTRA_JOB_ID) != null);
String jobId = intent.getStringExtra(EXTRA_JOB_ID);
if (DEBUG) Log.d(TAG, "handleCancel: " + jobId);
@@ -253,7 +252,8 @@ public class FileOperationService extends Service implements Job.Listener {
throw new UnsupportedOperationException();
}
return checkNotNull(job);
assert(job != null);
return job;
}
@GuardedBy("mRunning")
@@ -261,7 +261,7 @@ public class FileOperationService extends Service implements Job.Listener {
if (DEBUG) Log.d(TAG, "deleteJob: " + job.id);
JobRecord record = mRunning.remove(job.id);
checkArgument(record != null);
assert(record != null);
record.job.cleanup();
if (mRunning.isEmpty()) {

View File

@@ -23,8 +23,6 @@ import static com.android.documentsui.services.FileOperationService.EXTRA_JOB_ID
import static com.android.documentsui.services.FileOperationService.EXTRA_OPERATION;
import static com.android.documentsui.services.FileOperationService.EXTRA_SRC_LIST;
import static com.android.documentsui.services.FileOperationService.OPERATION_UNKNOWN;
import static com.android.internal.util.Preconditions.checkArgument;
import static com.android.internal.util.Preconditions.checkNotNull;
import android.annotation.DrawableRes;
import android.annotation.PluralsRes;
@@ -98,7 +96,7 @@ abstract public class Job implements Runnable {
Job(Context service, Context appContext, Listener listener,
@OpType int operationType, String id, DocumentStack stack) {
checkArgument(operationType != OPERATION_UNKNOWN);
assert(operationType != OPERATION_UNKNOWN);
this.service = service;
this.appContext = appContext;
@@ -150,7 +148,8 @@ abstract public class Job implements Runnable {
mClients.put(doc.authority, client);
}
return checkNotNull(client);
assert(client != null);
return client;
}
final void cleanup() {

View File

@@ -21,11 +21,9 @@ import static com.android.documentsui.services.FileOperationService.OPERATION_MO
import android.app.Notification;
import android.app.Notification.Builder;
import android.content.Context;
import android.net.Uri;
import android.os.RemoteException;
import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Document;
import android.util.Log;
import com.android.documentsui.R;
import com.android.documentsui.model.DocumentInfo;
@@ -36,7 +34,6 @@ import java.util.List;
// TODO: Stop extending CopyJob.
final class MoveJob extends CopyJob {
private static final String TAG = "MoveJob";
final DocumentInfo mSrcParent;
/**