androidx.core.os.CancellationSignal Java Examples
The following examples show how to use
androidx.core.os.CancellationSignal.
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: SQLiteSession.java From sqlite-android with Apache License 2.0 | 6 votes |
/** * Executes a statement that does not return a result. * * @param sql The SQL statement to execute. * @param bindArgs The arguments to bind, or null if none. * @param connectionFlags The connection flags to use if a connection must be * acquired by this operation. Refer to {@link SQLiteConnectionPool}. * @param cancellationSignal A signal to cancel the operation in progress, or null if none. * * @throws SQLiteException if an error occurs, such as a syntax error * or invalid number of bind arguments. * @throws OperationCanceledException if the operation was canceled. */ public void execute(String sql, Object[] bindArgs, int connectionFlags, CancellationSignal cancellationSignal) { if (sql == null) { throw new IllegalArgumentException("sql must not be null."); } if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) { return; } acquireConnection(sql, connectionFlags, cancellationSignal); // might throw try { mConnection.execute(sql, bindArgs, cancellationSignal); // might throw } finally { releaseConnection(); // might throw } }
Example #2
Source File: SQLiteSession.java From sqlite-android with Apache License 2.0 | 6 votes |
/** * Performs special reinterpretation of certain SQL statements such as "BEGIN", * "COMMIT" and "ROLLBACK" to ensure that transaction state invariants are * maintained. * * This function is mainly used to support legacy apps that perform their * own transactions by executing raw SQL rather than calling {@link #beginTransaction} * and the like. * * @param sql The SQL statement to execute. * @param bindArgs The arguments to bind, or null if none. * @param connectionFlags The connection flags to use if a connection must be * acquired by this operation. Refer to {@link SQLiteConnectionPool}. * @param cancellationSignal A signal to cancel the operation in progress, or null if none. * @return True if the statement was of a special form that was handled here, * false otherwise. * * @throws SQLiteException if an error occurs, such as a syntax error * or invalid number of bind arguments. * @throws OperationCanceledException if the operation was canceled. */ private boolean executeSpecial(String sql, Object[] bindArgs, int connectionFlags, CancellationSignal cancellationSignal) { if (cancellationSignal != null) { cancellationSignal.throwIfCanceled(); } final int type = SQLiteStatementType.getSqlStatementType(sql); switch (type) { case SQLiteStatementType.STATEMENT_BEGIN: beginTransaction(TRANSACTION_MODE_EXCLUSIVE, null, connectionFlags, cancellationSignal); return true; case SQLiteStatementType.STATEMENT_COMMIT: setTransactionSuccessful(); endTransaction(cancellationSignal); return true; case SQLiteStatementType.STATEMENT_ABORT: endTransaction(cancellationSignal); return true; } return false; }
Example #3
Source File: SQLiteSession.java From sqlite-android with Apache License 2.0 | 6 votes |
/** * Executes a statement that returns a single <code>long</code> result. * * @param sql The SQL statement to execute. * @param bindArgs The arguments to bind, or null if none. * @param connectionFlags The connection flags to use if a connection must be * acquired by this operation. Refer to {@link SQLiteConnectionPool}. * @param cancellationSignal A signal to cancel the operation in progress, or null if none. * @return The value of the first column in the first row of the result set * as a <code>long</code>, or zero if none. * * @throws SQLiteException if an error occurs, such as a syntax error * or invalid number of bind arguments. * @throws OperationCanceledException if the operation was canceled. */ public long executeForLong(String sql, Object[] bindArgs, int connectionFlags, CancellationSignal cancellationSignal) { if (sql == null) { throw new IllegalArgumentException("sql must not be null."); } if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) { return 0; } acquireConnection(sql, connectionFlags, cancellationSignal); // might throw try { return mConnection.executeForLong(sql, bindArgs, cancellationSignal); // might throw } finally { releaseConnection(); // might throw } }
Example #4
Source File: SQLiteSession.java From sqlite-android with Apache License 2.0 | 6 votes |
/** * Executes a statement that returns the row id of the last row inserted * by the statement. Use for INSERT SQL statements. * * @param sql The SQL statement to execute. * @param bindArgs The arguments to bind, or null if none. * @param connectionFlags The connection flags to use if a connection must be * acquired by this operation. Refer to {@link SQLiteConnectionPool}. * @param cancellationSignal A signal to cancel the operation in progress, or null if none. * @return The row id of the last row that was inserted, or 0 if none. * * @throws SQLiteException if an error occurs, such as a syntax error * or invalid number of bind arguments. * @throws OperationCanceledException if the operation was canceled. */ public long executeForLastInsertedRowId(String sql, Object[] bindArgs, int connectionFlags, CancellationSignal cancellationSignal) { if (sql == null) { throw new IllegalArgumentException("sql must not be null."); } if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) { return 0; } acquireConnection(sql, connectionFlags, cancellationSignal); // might throw try { return mConnection.executeForLastInsertedRowId(sql, bindArgs, cancellationSignal); // might throw } finally { releaseConnection(); // might throw } }
Example #5
Source File: SQLiteSession.java From sqlite-android with Apache License 2.0 | 6 votes |
/** * Executes a statement that returns a count of the number of rows * that were changed. Use for UPDATE or DELETE SQL statements. * * @param sql The SQL statement to execute. * @param bindArgs The arguments to bind, or null if none. * @param connectionFlags The connection flags to use if a connection must be * acquired by this operation. Refer to {@link SQLiteConnectionPool}. * @param cancellationSignal A signal to cancel the operation in progress, or null if none. * @return The number of rows that were changed. * * @throws SQLiteException if an error occurs, such as a syntax error * or invalid number of bind arguments. * @throws OperationCanceledException if the operation was canceled. */ public int executeForChangedRowCount(String sql, Object[] bindArgs, int connectionFlags, CancellationSignal cancellationSignal) { if (sql == null) { throw new IllegalArgumentException("sql must not be null."); } if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) { return 0; } acquireConnection(sql, connectionFlags, cancellationSignal); // might throw try { return mConnection.executeForChangedRowCount(sql, bindArgs, cancellationSignal); // might throw } finally { releaseConnection(); // might throw } }
Example #6
Source File: SQLiteSession.java From sqlite-android with Apache License 2.0 | 6 votes |
/** * Executes a statement that returns a single BLOB result as a * file descriptor to a shared memory region. * * @param sql The SQL statement to execute. * @param bindArgs The arguments to bind, or null if none. * @param connectionFlags The connection flags to use if a connection must be * acquired by this operation. Refer to {@link SQLiteConnectionPool}. * @param cancellationSignal A signal to cancel the operation in progress, or null if none. * @return The file descriptor for a shared memory region that contains * the value of the first column in the first row of the result set as a BLOB, * or null if none. * * @throws SQLiteException if an error occurs, such as a syntax error * or invalid number of bind arguments. * @throws OperationCanceledException if the operation was canceled. */ public ParcelFileDescriptor executeForBlobFileDescriptor(String sql, Object[] bindArgs, int connectionFlags, CancellationSignal cancellationSignal) { if (sql == null) { throw new IllegalArgumentException("sql must not be null."); } if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) { return null; } acquireConnection(sql, connectionFlags, cancellationSignal); // might throw try { return mConnection.executeForBlobFileDescriptor(sql, bindArgs, cancellationSignal); // might throw } finally { releaseConnection(); // might throw } }
Example #7
Source File: SQLiteDatabase.java From sqlite-android with Apache License 2.0 | 6 votes |
/** * Runs the provided SQL and returns a {@link Cursor} over the result set. * * @param supportQuery the SQL query. The SQL string must not be ; terminated * @param signal A signal to cancel the operation in progress, or null if none. * If the operation is canceled, then {@link OperationCanceledException} will be thrown * when the query is executed. * @return A {@link Cursor} object, which is positioned before the first entry. Note that * {@link Cursor}s are not synchronized, see the documentation for more details. */ @Override @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) public Cursor query(SupportSQLiteQuery supportQuery, android.os.CancellationSignal signal) { if (signal != null) { final CancellationSignal supportCancellationSignal = new CancellationSignal(); signal.setOnCancelListener(new android.os.CancellationSignal.OnCancelListener() { @Override public void onCancel() { supportCancellationSignal.cancel(); } }); return query(supportQuery, supportCancellationSignal); } else { return query(supportQuery, (CancellationSignal) null); } }
Example #8
Source File: SQLiteSession.java From sqlite-android with Apache License 2.0 | 6 votes |
/** * Executes a statement that returns a single {@link String} result. * * @param sql The SQL statement to execute. * @param bindArgs The arguments to bind, or null if none. * @param connectionFlags The connection flags to use if a connection must be * acquired by this operation. Refer to {@link SQLiteConnectionPool}. * @param cancellationSignal A signal to cancel the operation in progress, or null if none. * @return The value of the first column in the first row of the result set * as a <code>String</code>, or null if none. * * @throws SQLiteException if an error occurs, such as a syntax error * or invalid number of bind arguments. * @throws OperationCanceledException if the operation was canceled. */ public String executeForString(String sql, Object[] bindArgs, int connectionFlags, CancellationSignal cancellationSignal) { if (sql == null) { throw new IllegalArgumentException("sql must not be null."); } if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) { return null; } acquireConnection(sql, connectionFlags, cancellationSignal); // might throw try { return mConnection.executeForString(sql, bindArgs, cancellationSignal); // might throw } finally { releaseConnection(); // might throw } }
Example #9
Source File: SQLiteConnection.java From sqlite-android with Apache License 2.0 | 5 votes |
/** * Executes a statement that returns a count of the number of rows * that were changed. Use for UPDATE or DELETE SQL statements. * * @param sql The SQL statement to execute. * @param bindArgs The arguments to bind, or null if none. * @param cancellationSignal A signal to cancel the operation in progress, or null if none. * @return The number of rows that were changed. * * @throws SQLiteException if an error occurs, such as a syntax error * or invalid number of bind arguments. * @throws OperationCanceledException if the operation was canceled. */ public int executeForChangedRowCount(String sql, Object[] bindArgs, CancellationSignal cancellationSignal) { if (sql == null) { throw new IllegalArgumentException("sql must not be null."); } int changedRows = 0; final int cookie = mRecentOperations.beginOperation("executeForChangedRowCount", sql, bindArgs); try { final PreparedStatement statement = acquirePreparedStatement(sql); try { throwIfStatementForbidden(statement); bindArguments(statement, bindArgs); applyBlockGuardPolicy(statement); attachCancellationSignal(cancellationSignal); try { changedRows = nativeExecuteForChangedRowCount( mConnectionPtr, statement.mStatementPtr); return changedRows; } finally { detachCancellationSignal(cancellationSignal); } } finally { releasePreparedStatement(statement); } } catch (RuntimeException ex) { mRecentOperations.failOperation(cookie, ex); throw ex; } finally { if (mRecentOperations.endOperationDeferLog(cookie)) { mRecentOperations.logOperation(cookie, "changedRows=" + changedRows); } } }
Example #10
Source File: FingerprintUiHelper.java From SmartPack-Kernel-Manager with GNU General Public License v3.0 | 5 votes |
public void startListening(FingerprintManagerCompat.CryptoObject cryptoObject) { if (!mListening) { mListening = true; mCancellationSignal = new CancellationSignal(); mSelfCancelled = false; mFingerprintManagerCompat .authenticate(cryptoObject, 0, mCancellationSignal, this, null); mSwirlView.setState(SwirlView.State.ON); } }
Example #11
Source File: SQLiteConnection.java From sqlite-android with Apache License 2.0 | 5 votes |
/** * Executes a statement that returns the row id of the last row inserted * by the statement. Use for INSERT SQL statements. * * @param sql The SQL statement to execute. * @param bindArgs The arguments to bind, or null if none. * @param cancellationSignal A signal to cancel the operation in progress, or null if none. * @return The row id of the last row that was inserted, or 0 if none. * * @throws SQLiteException if an error occurs, such as a syntax error * or invalid number of bind arguments. * @throws OperationCanceledException if the operation was canceled. */ public long executeForLastInsertedRowId(String sql, Object[] bindArgs, CancellationSignal cancellationSignal) { if (sql == null) { throw new IllegalArgumentException("sql must not be null."); } final int cookie = mRecentOperations.beginOperation("executeForLastInsertedRowId", sql, bindArgs); try { final PreparedStatement statement = acquirePreparedStatement(sql); try { throwIfStatementForbidden(statement); bindArguments(statement, bindArgs); applyBlockGuardPolicy(statement); attachCancellationSignal(cancellationSignal); try { return nativeExecuteForLastInsertedRowId( mConnectionPtr, statement.mStatementPtr); } finally { detachCancellationSignal(cancellationSignal); } } finally { releasePreparedStatement(statement); } } catch (RuntimeException ex) { mRecentOperations.failOperation(cookie, ex); throw ex; } finally { mRecentOperations.endOperation(cookie); } }
Example #12
Source File: SQLiteConnection.java From sqlite-android with Apache License 2.0 | 5 votes |
private void attachCancellationSignal(CancellationSignal cancellationSignal) { if (cancellationSignal != null) { cancellationSignal.throwIfCanceled(); mCancellationSignalAttachCount += 1; if (mCancellationSignalAttachCount == 1) { // Reset cancellation flag before executing the statement. nativeResetCancel(mConnectionPtr, true /*cancelable*/); // After this point, onCancel() may be called concurrently. cancellationSignal.setOnCancelListener(this); } } }
Example #13
Source File: SQLiteConnection.java From sqlite-android with Apache License 2.0 | 5 votes |
@SuppressLint("Assert") private void detachCancellationSignal(CancellationSignal cancellationSignal) { if (cancellationSignal != null) { assert mCancellationSignalAttachCount > 0; mCancellationSignalAttachCount -= 1; if (mCancellationSignalAttachCount == 0) { // After this point, onCancel() cannot be called concurrently. cancellationSignal.setOnCancelListener(null); // Reset cancellation flag after executing the statement. nativeResetCancel(mConnectionPtr, false /*cancelable*/); } } }
Example #14
Source File: SQLiteSession.java From sqlite-android with Apache License 2.0 | 5 votes |
private boolean yieldTransactionUnchecked(long sleepAfterYieldDelayMillis, CancellationSignal cancellationSignal) { if (cancellationSignal != null) { cancellationSignal.throwIfCanceled(); } if (!mConnectionPool.shouldYieldConnection(mConnection, mConnectionFlags)) { return false; } final int transactionMode = mTransactionStack.mMode; final SQLiteTransactionListener listener = mTransactionStack.mListener; final int connectionFlags = mConnectionFlags; endTransactionUnchecked(cancellationSignal, true); // might throw if (sleepAfterYieldDelayMillis > 0) { try { Thread.sleep(sleepAfterYieldDelayMillis); } catch (InterruptedException ex) { // we have been interrupted, that's all we need to do } } beginTransactionUnchecked(transactionMode, listener, connectionFlags, cancellationSignal); // might throw return true; }
Example #15
Source File: SQLiteSession.java From sqlite-android with Apache License 2.0 | 5 votes |
/** * Executes a statement and populates the specified {@link CursorWindow} * with a range of results. Returns the number of rows that were counted * during query execution. * * @param sql The SQL statement to execute. * @param bindArgs The arguments to bind, or null if none. * @param window The cursor window to clear and fill. * @param startPos The start position for filling the window. * @param requiredPos The position of a row that MUST be in the window. * If it won't fit, then the query should discard part of what it filled * so that it does. Must be greater than or equal to <code>startPos</code>. * @param countAllRows True to count all rows that the query would return * regagless of whether they fit in the window. * @param connectionFlags The connection flags to use if a connection must be * acquired by this operation. Refer to {@link SQLiteConnectionPool}. * @param cancellationSignal A signal to cancel the operation in progress, or null if none. * @return The number of rows that were counted during query execution. Might * not be all rows in the result set unless <code>countAllRows</code> is true. * * @throws SQLiteException if an error occurs, such as a syntax error * or invalid number of bind arguments. * @throws OperationCanceledException if the operation was canceled. */ public int executeForCursorWindow(String sql, Object[] bindArgs, CursorWindow window, int startPos, int requiredPos, boolean countAllRows, int connectionFlags, CancellationSignal cancellationSignal) { if (sql == null) { throw new IllegalArgumentException("sql must not be null."); } if (window == null) { throw new IllegalArgumentException("window must not be null."); } if (executeSpecial(sql, bindArgs, connectionFlags, cancellationSignal)) { window.clear(); return 0; } acquireConnection(sql, connectionFlags, cancellationSignal); // might throw try { return mConnection.executeForCursorWindow(sql, bindArgs, window, startPos, requiredPos, countAllRows, cancellationSignal); // might throw } finally { releaseConnection(); // might throw } }
Example #16
Source File: SQLiteSession.java From sqlite-android with Apache License 2.0 | 5 votes |
private void acquireConnection(String sql, int connectionFlags, CancellationSignal cancellationSignal) { if (mConnection == null) { assert mConnectionUseCount == 0; mConnection = mConnectionPool.acquireConnection(sql, connectionFlags, cancellationSignal); // might throw mConnectionFlags = connectionFlags; } mConnectionUseCount += 1; }
Example #17
Source File: MarshmallowReprintModule.java From reprint with Apache License 2.0 | 5 votes |
void authenticate(final CancellationSignal cancellationSignal, final AuthenticationListener listener, final Reprint.RestartPredicate restartPredicate, final int restartCount) throws SecurityException { final FingerprintManager fingerprintManager = fingerprintManager(); if (fingerprintManager == null) { listener.onFailure(AuthenticationFailureReason.UNKNOWN, true, context.getString(R.string.fingerprint_error_hw_not_available), TAG, FINGERPRINT_ERROR_CANCELED); return; } final FingerprintManager.AuthenticationCallback callback = new AuthCallback(restartCount, restartPredicate, cancellationSignal, listener); // Why getCancellationSignalObject returns an Object is unexplained final android.os.CancellationSignal signalObject = cancellationSignal == null ? null : (android.os.CancellationSignal) cancellationSignal.getCancellationSignalObject(); // Occasionally, an NPE will bubble up out of FingerprintManager.authenticate try { fingerprintManager.authenticate(null, signalObject, 0, callback, null); } catch (NullPointerException e) { logger.logException(e, "MarshmallowReprintModule: authenticate failed unexpectedly"); listener.onFailure(AuthenticationFailureReason.UNKNOWN, true, context.getString(R.string.fingerprint_error_unable_to_process), TAG, FINGERPRINT_ERROR_CANCELED); } }
Example #18
Source File: MarshmallowReprintModule.java From reprint with Apache License 2.0 | 5 votes |
private AuthCallback(int restartCount, Reprint.RestartPredicate restartPredicate, CancellationSignal cancellationSignal, AuthenticationListener listener) { this.restartCount = restartCount; this.restartPredicate = restartPredicate; this.cancellationSignal = cancellationSignal; this.listener = listener; }
Example #19
Source File: FingerprintManagerCompat.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
@Override public void authenticate(Context context, CryptoObject crypto, int flags, CancellationSignal cancel, AuthenticationCallback callback, Handler handler) { FingerprintManagerCompatApi23.authenticate(context, wrapCryptoObject(crypto), flags, cancel != null ? cancel.getCancellationSignalObject() : null, wrapCallback(callback), handler); }
Example #20
Source File: FingerprintManagerCompat.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public void authenticate(Context context, CryptoObject crypto, int flags, CancellationSignal cancel, AuthenticationCallback callback, Handler handler) { FingerprintManagerCompatApi23.authenticate(context, wrapCryptoObject(crypto), flags, cancel != null ? cancel.getCancellationSignalObject() : null, wrapCallback(callback), handler); }
Example #21
Source File: RawSqlCursorLoader.java From geopaparazzi with GNU General Public License v3.0 | 5 votes |
@Override public Cursor loadInBackground() { synchronized (this) { if (isLoadInBackgroundCanceled()) { throw new OperationCanceledException(); } mCancellationSignal = new CancellationSignal(); } try { Cursor cursor = null; String errorMsg = null; try { cursor = mDatabase.rawQuery(mSql, null); } catch (Exception e) { errorMsg = "cannot run query: " + mSql;//NON-NLS } if (cursor != null) { try { // Ensure the cursor window is filled. cursor.getCount(); cursor.registerContentObserver(mObserver); } catch (RuntimeException ex) { cursor.close(); throw ex; } } if (cursor == null && errorMsg != null) { cursor = mDatabase.rawQuery("select 'asd' as _id, '" + errorMsg + "' as ERROR", null);//NON-NLS NON-NLS } return cursor; } finally { synchronized (this) { mCancellationSignal = null; } } }
Example #22
Source File: SQLiteConnection.java From sqlite-android with Apache License 2.0 | 5 votes |
/** * Executes a statement that returns a single {@link String} result. * * @param sql The SQL statement to execute. * @param bindArgs The arguments to bind, or null if none. * @param cancellationSignal A signal to cancel the operation in progress, or null if none. * @return The value of the first column in the first row of the result set * as a <code>String</code>, or null if none. * * @throws SQLiteException if an error occurs, such as a syntax error * or invalid number of bind arguments. * @throws OperationCanceledException if the operation was canceled. */ public String executeForString(String sql, Object[] bindArgs, CancellationSignal cancellationSignal) { if (sql == null) { throw new IllegalArgumentException("sql must not be null."); } final int cookie = mRecentOperations.beginOperation("executeForString", sql, bindArgs); try { final PreparedStatement statement = acquirePreparedStatement(sql); try { throwIfStatementForbidden(statement); bindArguments(statement, bindArgs); applyBlockGuardPolicy(statement); attachCancellationSignal(cancellationSignal); try { return nativeExecuteForString(mConnectionPtr, statement.mStatementPtr); } finally { detachCancellationSignal(cancellationSignal); } } finally { releasePreparedStatement(statement); } } catch (RuntimeException ex) { mRecentOperations.failOperation(cookie, ex); throw ex; } finally { mRecentOperations.endOperation(cookie); } }
Example #23
Source File: PFFingerprintUIHelper.java From PFLockScreen-Android with Apache License 2.0 | 5 votes |
public void startListening(FingerprintManagerCompat.CryptoObject cryptoObject) { if (!isFingerprintAuthAvailable()) { return; } mCancellationSignal = new CancellationSignal(); mSelfCancelled = false; // The line below prevents the false positive inspection from Android Studio // noinspection ResourceType mFingerprintManager.authenticate( cryptoObject, 0, mCancellationSignal, this, null); mIcon.setImageResource(R.drawable.ic_fp_40px_pf); }
Example #24
Source File: FingerprintUiHelper.java From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 | 5 votes |
public void startListening(FingerprintManagerCompat.CryptoObject cryptoObject) { if (!mListening) { mListening = true; mCancellationSignal = new CancellationSignal(); mSelfCancelled = false; mFingerprintManagerCompat .authenticate(cryptoObject, 0, mCancellationSignal, this, null); mSwirlView.setState(SwirlView.State.ON); } }
Example #25
Source File: AndroidFingerprint.java From FingerprintIdentify with MIT License | 5 votes |
@Override protected void doIdentify() { try { mCancellationSignal = new CancellationSignal(); mFingerprintManagerCompat.authenticate(null, 0, mCancellationSignal, new FingerprintManagerCompat.AuthenticationCallback() { @Override public void onAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult result) { super.onAuthenticationSucceeded(result); onSucceed(); } @Override public void onAuthenticationFailed() { super.onAuthenticationFailed(); onNotMatch(); } @Override public void onAuthenticationError(int errMsgId, CharSequence errString) { super.onAuthenticationError(errMsgId, errString); if (errMsgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED || errMsgId == FingerprintManager.FINGERPRINT_ERROR_USER_CANCELED) { return; } onFailed(errMsgId == FingerprintManager.FINGERPRINT_ERROR_LOCKOUT || errMsgId == FingerprintManager.FINGERPRINT_ERROR_LOCKOUT_PERMANENT); } }, null); } catch (Throwable e) { onCatchException(e); onFailed(false); } }
Example #26
Source File: SQLiteDirectCursorDriver.java From sqlite-android with Apache License 2.0 | 5 votes |
public SQLiteDirectCursorDriver(SQLiteDatabase db, String sql, String editTable, CancellationSignal cancellationSignal) { mDatabase = db; mEditTable = editTable; mSql = sql; mCancellationSignal = cancellationSignal; }
Example #27
Source File: SQLiteConnection.java From sqlite-android with Apache License 2.0 | 5 votes |
/** * Executes a statement that returns a single BLOB result as a * file descriptor to a shared memory region. * * @param sql The SQL statement to execute. * @param bindArgs The arguments to bind, or null if none. * @param cancellationSignal A signal to cancel the operation in progress, or null if none. * @return The file descriptor for a shared memory region that contains * the value of the first column in the first row of the result set as a BLOB, * or null if none. * * @throws SQLiteException if an error occurs, such as a syntax error * or invalid number of bind arguments. * @throws OperationCanceledException if the operation was canceled. */ public ParcelFileDescriptor executeForBlobFileDescriptor(String sql, Object[] bindArgs, CancellationSignal cancellationSignal) { if (sql == null) { throw new IllegalArgumentException("sql must not be null."); } final int cookie = mRecentOperations.beginOperation("executeForBlobFileDescriptor", sql, bindArgs); try { final PreparedStatement statement = acquirePreparedStatement(sql); try { throwIfStatementForbidden(statement); bindArguments(statement, bindArgs); applyBlockGuardPolicy(statement); attachCancellationSignal(cancellationSignal); try { int fd = nativeExecuteForBlobFileDescriptor( mConnectionPtr, statement.mStatementPtr); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { return fd >= 0 ? ParcelFileDescriptor.adoptFd(fd) : null; } else { throw new UnsupportedOperationException(); } } finally { detachCancellationSignal(cancellationSignal); } } finally { releasePreparedStatement(statement); } } catch (RuntimeException ex) { mRecentOperations.failOperation(cookie, ex); throw ex; } finally { mRecentOperations.endOperation(cookie); } }
Example #28
Source File: SQLiteConnection.java From sqlite-android with Apache License 2.0 | 5 votes |
/** * Executes a statement that returns a single <code>long</code> result. * * @param sql The SQL statement to execute. * @param bindArgs The arguments to bind, or null if none. * @param cancellationSignal A signal to cancel the operation in progress, or null if none. * @return The value of the first column in the first row of the result set * as a <code>long</code>, or zero if none. * * @throws SQLiteException if an error occurs, such as a syntax error * or invalid number of bind arguments. * @throws OperationCanceledException if the operation was canceled. */ public long executeForLong(String sql, Object[] bindArgs, CancellationSignal cancellationSignal) { if (sql == null) { throw new IllegalArgumentException("sql must not be null."); } final int cookie = mRecentOperations.beginOperation("executeForLong", sql, bindArgs); try { final PreparedStatement statement = acquirePreparedStatement(sql); try { throwIfStatementForbidden(statement); bindArguments(statement, bindArgs); applyBlockGuardPolicy(statement); attachCancellationSignal(cancellationSignal); try { return nativeExecuteForLong(mConnectionPtr, statement.mStatementPtr); } finally { detachCancellationSignal(cancellationSignal); } } finally { releasePreparedStatement(statement); } } catch (RuntimeException ex) { mRecentOperations.failOperation(cookie, ex); throw ex; } finally { mRecentOperations.endOperation(cookie); } }
Example #29
Source File: SQLiteConnection.java From sqlite-android with Apache License 2.0 | 5 votes |
/** * Executes a statement that does not return a result. * * @param sql The SQL statement to execute. * @param bindArgs The arguments to bind, or null if none. * @param cancellationSignal A signal to cancel the operation in progress, or null if none. * * @throws SQLiteException if an error occurs, such as a syntax error * or invalid number of bind arguments. * @throws OperationCanceledException if the operation was canceled. */ public void execute(String sql, Object[] bindArgs, CancellationSignal cancellationSignal) { if (sql == null) { throw new IllegalArgumentException("sql must not be null."); } final int cookie = mRecentOperations.beginOperation("execute", sql, bindArgs); try { final PreparedStatement statement = acquirePreparedStatement(sql); try { throwIfStatementForbidden(statement); bindArguments(statement, bindArgs); applyBlockGuardPolicy(statement); attachCancellationSignal(cancellationSignal); try { nativeExecute(mConnectionPtr, statement.mStatementPtr); } finally { detachCancellationSignal(cancellationSignal); } } finally { releasePreparedStatement(statement); } } catch (RuntimeException ex) { mRecentOperations.failOperation(cookie, ex); throw ex; } finally { mRecentOperations.endOperation(cookie); } }
Example #30
Source File: FingerprintManagerCompat.java From FingerprintIdentify with MIT License | 4 votes |
@Override public void authenticate(Context context, CryptoObject crypto, int flags, CancellationSignal cancel, AuthenticationCallback callback, Handler handler) { FingerprintManagerCompatApi23.authenticate(context, wrapCryptoObject(crypto), flags, cancel != null ? cancel.getCancellationSignalObject() : null, wrapCallback(callback), handler); }