public static void beginSection(String section) { if (!traceEnabled) { return; } if (traceDepth == MAX_DEPTH) { depthPastMaxDepth++; return; } sections[traceDepth] = section; startTimeNs[traceDepth] = System.nanoTime(); TraceCompat.beginSection(section); traceDepth++; }
public static float endSection(String section) { if (depthPastMaxDepth > 0) { depthPastMaxDepth--; return 0; } if (!traceEnabled) { return 0; } traceDepth--; if (traceDepth == -1) { throw new IllegalStateException("Can't end trace section. There are none."); } if (!section.equals(sections[traceDepth])) { throw new IllegalStateException("Unbalanced trace call " + section + ". Expected " + sections[traceDepth] + "."); } TraceCompat.endSection(); return (System.nanoTime() - startTimeNs[traceDepth]) / 1000000f; } }
@Override protected void doCancelIdentify() { try { if (mCancellationSignal != null) { mCancellationSignal.cancel(); } } catch (Throwable e) { onCatchException(e); } }
@Override protected void doIdentify() { try { mCancellationSignal = new CancellationSignal(); mFingerprintManagerCompat.authenticate(null, 0, mCancellationSignal, new FingerprintManagerCompat.AuthenticationCallback() { @Override
/** * Get default locale language from the supported locales. * * @param context The context to get configuration. * @param supportedLocales The supported locales. * * @return The default locale according to the supported locales. */ public static @NonNull Locale getDefaultLocale( @NonNull Context context, @Nullable String[] supportedLocales) { if (supportedLocales == null) { return ConfigurationCompat.getLocales( Resources.getSystem().getConfiguration()).get(0); } else { Locale defaultLocale = ConfigurationCompat.getLocales( Resources.getSystem().getConfiguration()).getFirstMatch(supportedLocales); return defaultLocale != null ? defaultLocale : Locale.getDefault(); } }
@VisibleForTesting Locale getCurrentLocale() { return ConfigurationCompat.getLocales(mContext.getResources().getConfiguration()).get(0); }
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); } } }
@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); }
@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*/); } } }
@Test public void unsubscribe_cancels() throws Exception { assertFalse(module.cancellationSignal.isCanceled()); ts.dispose(); assertTrue(module.cancellationSignal.isCanceled()); } }
private void cancelConnectionWaiterLocked(ConnectionWaiter waiter) { if (waiter.mAssignedConnection != null || waiter.mException != null) { // Waiter is done waiting but has not woken up yet. return; } // Waiter must still be waiting. Dequeue it. ConnectionWaiter predecessor = null; ConnectionWaiter current = mConnectionWaiterQueue; while (current != waiter) { assert current != null; predecessor = current; current = current.mNext; } if (predecessor != null) { predecessor.mNext = waiter.mNext; } else { mConnectionWaiterQueue = waiter.mNext; } // Send the waiter an exception and unpark it. waiter.mException = new OperationCanceledException(); LockSupport.unpark(waiter.mThread); // Check whether removing this waiter will enable other waiters to make progress. wakeConnectionWaitersLocked(); }
private static File findCollectionDirectory(Context context) { String subDirectory = "Collection"; File[] storage = context.getExternalFilesDirs(subDirectory); for (File file : storage) { if (file != null) { String state = EnvironmentCompat.getStorageState(file); if (Environment.MEDIA_MOUNTED.equals(state)) { LogHelper.v(LOG_TAG, "External storage: " + file.toString()); return file; } } } return null; }
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; }
@Override public void onCancel() { supportCancellationSignal.cancel(); } });
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); } }
@Test public void unsubscribe_cancels() throws Exception { assertFalse(module.cancellationSignal.isCanceled()); ts.unsubscribe(); assertTrue(module.cancellationSignal.isCanceled()); } }
void cancel() { cancellationSignal.cancel(); this.canceled = true; }
public void stopListening() { if (mCancellationSignal != null) { mSelfCancelled = true; mCancellationSignal.cancel(); mCancellationSignal = null; mListening = false; } }
public void cancelAuthentication() { final CancellationSignal signal = cancellationSignal.getAndSet(null); if (signal != null) { try { signal.cancel(); } catch (NullPointerException e) { // Occasionally the cancel call throws an NPE when trying to unparcelize something. } } }
@Override public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) { if (!restartPredicate.invoke(AuthenticationFailureReason.SENSOR_FAILED, restartCount++)) { cancellationSignal.cancel(); } listener.onFailure(AuthenticationFailureReason.SENSOR_FAILED, false, helpString, TAG, helpMsgId); }