Java Code Examples for com.android.internal.util.Preconditions#checkArgumentNonnegative()

The following examples show how to use com.android.internal.util.Preconditions#checkArgumentNonnegative() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SQLiteCursor.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void fillWindow(int requiredPos) {
    clearOrCreateWindow(getDatabase().getPath());
    try {
        Preconditions.checkArgumentNonnegative(requiredPos,
                "requiredPos cannot be negative, but was " + requiredPos);

        if (mCount == NO_COUNT) {
            mCount = mQuery.fillWindow(mWindow, requiredPos, requiredPos, true);
            mCursorWindowCapacity = mWindow.getNumRows();
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "received count(*) from native_fill_window: " + mCount);
            }
        } else {
            int startPos = mFillWindowForwardOnly ? requiredPos : DatabaseUtils
                    .cursorPickFillWindowStartPosition(requiredPos, mCursorWindowCapacity);
            mQuery.fillWindow(mWindow, startPos, requiredPos, false);
        }
    } catch (RuntimeException ex) {
        // Close the cursor window if the query failed and therefore will
        // not produce any results.  This helps to avoid accidentally leaking
        // the cursor window if the client does not correctly handle exceptions
        // and fails to close the cursor.
        closeWindow();
        throw ex;
    }
}
 
Example 2
Source File: WindowInsets.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a copy of this instance inset in the given directions.
 *
 * This is intended for dispatching insets to areas of the window that are smaller than the
 * current area.
 *
 * <p>Example:
 * <pre>
 * childView.dispatchApplyWindowInsets(insets.inset(
 *         childMarginLeft, childMarginTop, childMarginBottom, childMarginRight));
 * </pre>
 *
 * @param left the amount of insets to remove from the left. Must be non-negative.
 * @param top the amount of insets to remove from the top. Must be non-negative.
 * @param right the amount of insets to remove from the right. Must be non-negative.
 * @param bottom the amount of insets to remove from the bottom. Must be non-negative.
 *
 * @return the inset insets
 *
 * @hide pending API
 */
public WindowInsets inset(int left, int top, int right, int bottom) {
    Preconditions.checkArgumentNonnegative(left);
    Preconditions.checkArgumentNonnegative(top);
    Preconditions.checkArgumentNonnegative(right);
    Preconditions.checkArgumentNonnegative(bottom);

    WindowInsets result = new WindowInsets(this);
    if (!result.mSystemWindowInsetsConsumed) {
        result.mSystemWindowInsets =
                insetInsets(result.mSystemWindowInsets, left, top, right, bottom);
    }
    if (!result.mWindowDecorInsetsConsumed) {
        result.mWindowDecorInsets =
                insetInsets(result.mWindowDecorInsets, left, top, right, bottom);
    }
    if (!result.mStableInsetsConsumed) {
        result.mStableInsets = insetInsets(result.mStableInsets, left, top, right, bottom);
    }
    if (mDisplayCutout != null) {
        result.mDisplayCutout = result.mDisplayCutout.inset(left, top, right, bottom);
        if (result.mDisplayCutout.isEmpty()) {
            result.mDisplayCutout = null;
        }
    }
    return result;
}
 
Example 3
Source File: PrintDocumentInfo.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param parcel Data from which to initialize.
 */
private PrintDocumentInfo(Parcel parcel) {
    mName = Preconditions.checkStringNotEmpty(parcel.readString());
    mPageCount = parcel.readInt();
    Preconditions.checkArgument(mPageCount == PAGE_COUNT_UNKNOWN || mPageCount > 0);
    mContentType = parcel.readInt();
    mDataSize = Preconditions.checkArgumentNonnegative(parcel.readLong());
}
 
Example 4
Source File: IntArray.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Changes the size of this IntArray. If this IntArray is shrinked, the backing array capacity
 * is unchanged. If the new size is larger than backing array capacity, a new backing array is
 * created from the current content of this IntArray padded with 0s.
 */
public void resize(int newSize) {
    Preconditions.checkArgumentNonnegative(newSize);
    if (newSize <= mValues.length) {
        Arrays.fill(mValues, newSize, mValues.length, 0);
    } else {
        ensureCapacity(newSize - mSize);
    }
    mSize = newSize;
}
 
Example 5
Source File: LongArray.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Changes the size of this LongArray. If this LongArray is shrinked, the backing array capacity
 * is unchanged. If the new size is larger than backing array capacity, a new backing array is
 * created from the current content of this LongArray padded with 0s.
 */
public void resize(int newSize) {
    Preconditions.checkArgumentNonnegative(newSize);
    if (newSize <= mValues.length) {
        Arrays.fill(mValues, newSize, mValues.length, 0);
    } else {
        ensureCapacity(newSize - mSize);
    }
    mSize = newSize;
}
 
Example 6
Source File: CacheQuotaHint.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public @NonNull Builder setUid(int uid) {
    Preconditions.checkArgumentNonnegative(uid, "Proposed uid was negative.");
    mUid = uid;
    return this;
}
 
Example 7
Source File: UsbDeviceConnection.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Waits for the result of a {@link android.hardware.usb.UsbRequest#queue} operation
 * <p>Note that this may return requests queued on multiple
 * {@link android.hardware.usb.UsbEndpoint}s. When multiple endpoints are in use,
 * {@link android.hardware.usb.UsbRequest#getEndpoint} and {@link
 * android.hardware.usb.UsbRequest#getClientData} can be useful in determining how to process
 * the result of this function.</p>
 * <p>Android processes {@link UsbRequest UsbRequests} asynchronously. Hence it is not
 * guaranteed that {@link #requestWait(long) requestWait(0)} returns a request that has been
 * queued right before even if the request could have been processed immediately.</p>
 *
 * @param timeout timeout in milliseconds. If 0 this method does not wait.
 *
 * @return a completed USB request, or {@code null} if an error occurred
 *
 * @throws BufferOverflowException if the number of bytes read or written is more than the
 *                                 limit of the request's buffer. The number of bytes is
 *                                 determined by the {@code length} parameter of
 *                                 {@link UsbRequest#queue(ByteBuffer, int)}
 * @throws TimeoutException if no request was received in {@code timeout} milliseconds.
 */
public UsbRequest requestWait(long timeout) throws TimeoutException {
    timeout = Preconditions.checkArgumentNonnegative(timeout, "timeout");

    UsbRequest request = native_request_wait(timeout);
    if (request != null) {
        request.dequeue(true);
    }
    return request;
}
 
Example 8
Source File: PrinterInfo.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Set a drawable resource as icon for this printer. If no icon is set the printer's
 * service's icon is used for the printer.
 *
 * @param iconResourceId The resource ID of the icon.
 * @return This builder.
 * @see PrinterInfo.Builder#setHasCustomPrinterIcon
 */
public @NonNull Builder setIconResourceId(@DrawableRes int iconResourceId) {
    mIconResourceId = Preconditions.checkArgumentNonnegative(iconResourceId,
            "iconResourceId can't be negative");
    return this;
}