Search in sources :

Example 36 with CancellationSignal

use of android.os.CancellationSignal in project fresco by facebook.

the class LocalThumbnailBitmapProducer method produceResults.

@Override
public void produceResults(final Consumer<CloseableReference<CloseableImage>> consumer, final ProducerContext context) {
    final ProducerListener2 listener = context.getProducerListener();
    final ImageRequest imageRequest = context.getImageRequest();
    context.putOriginExtra("local", "thumbnail_bitmap");
    final CancellationSignal cancellationSignal = new CancellationSignal();
    final StatefulProducerRunnable<CloseableReference<CloseableImage>> cancellableProducerRunnable = new StatefulProducerRunnable<CloseableReference<CloseableImage>>(consumer, listener, context, PRODUCER_NAME) {

        @Override
        protected void onSuccess(@Nullable CloseableReference<CloseableImage> result) {
            super.onSuccess(result);
            listener.onUltimateProducerReached(context, PRODUCER_NAME, result != null);
            context.putOriginExtra("local");
        }

        @Override
        protected void onFailure(Exception e) {
            super.onFailure(e);
            listener.onUltimateProducerReached(context, PRODUCER_NAME, false);
            context.putOriginExtra("local");
        }

        @Override
        @Nullable
        protected CloseableReference<CloseableImage> getResult() throws IOException {
            final Bitmap thumbnailBitmap = mContentResolver.loadThumbnail(imageRequest.getSourceUri(), new Size(imageRequest.getPreferredWidth(), imageRequest.getPreferredHeight()), cancellationSignal);
            if (thumbnailBitmap == null) {
                return null;
            }
            CloseableStaticBitmap closeableStaticBitmap = new CloseableStaticBitmap(thumbnailBitmap, SimpleBitmapReleaser.getInstance(), ImmutableQualityInfo.FULL_QUALITY, 0);
            context.setExtra(ProducerContext.ExtraKeys.IMAGE_FORMAT, "thumbnail");
            closeableStaticBitmap.setImageExtras(context.getExtras());
            return CloseableReference.<CloseableImage>of(closeableStaticBitmap);
        }

        @Override
        protected void onCancellation() {
            super.onCancellation();
            cancellationSignal.cancel();
        }

        @Override
        protected Map<String, String> getExtraMapOnSuccess(@Nullable final CloseableReference<CloseableImage> result) {
            return ImmutableMap.of(CREATED_THUMBNAIL, String.valueOf(result != null));
        }

        @Override
        protected void disposeResult(CloseableReference<CloseableImage> result) {
            CloseableReference.closeSafely(result);
        }
    };
    context.addCallbacks(new BaseProducerContextCallbacks() {

        @Override
        public void onCancellationRequested() {
            cancellableProducerRunnable.cancel();
        }
    });
    mExecutor.execute(cancellableProducerRunnable);
}
Also used : Size(android.util.Size) CloseableReference(com.facebook.common.references.CloseableReference) CloseableImage(com.facebook.imagepipeline.image.CloseableImage) IOException(java.io.IOException) Bitmap(android.graphics.Bitmap) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) CancellationSignal(android.os.CancellationSignal) Nullable(javax.annotation.Nullable)

Example 37 with CancellationSignal

use of android.os.CancellationSignal in project robolectric by robolectric.

the class SQLiteDatabaseTest method testRawQueryWithFactoryAndCancellationSignal.

@Test
public void testRawQueryWithFactoryAndCancellationSignal() {
    CancellationSignal signal = new CancellationSignal();
    Cursor cursor = database.rawQueryWithFactory(null, "select * from" + " table_name", null, null, signal);
    assertThat(cursor).isNotNull();
    assertThat(cursor.getColumnCount()).isEqualTo(5);
    assertThat(cursor.isClosed()).isFalse();
    signal.cancel();
    try {
        cursor.moveToNext();
        fail("did not get cancellation signal");
    } catch (OperationCanceledException e) {
    // expected
    }
    cursor.close();
}
Also used : OperationCanceledException(android.os.OperationCanceledException) Cursor(android.database.Cursor) CancellationSignal(android.os.CancellationSignal) Test(org.junit.Test)

Example 38 with CancellationSignal

use of android.os.CancellationSignal in project robolectric by robolectric.

the class ShadowLocationManagerTest method testGetCurrentLocation_Cancel.

@Test
@Config(minSdk = R)
public void testGetCurrentLocation_Cancel() {
    Location loc = createLocation(MY_PROVIDER);
    TestLocationConsumer consumer = new TestLocationConsumer();
    shadowLocationManager.setProviderEnabled(MY_PROVIDER, true);
    CancellationSignal cs = new CancellationSignal();
    locationManager.getCurrentLocation(MY_PROVIDER, cs, Runnable::run, consumer);
    cs.cancel();
    shadowLocationManager.simulateLocation(loc);
    assertThat(consumer.locations).isEmpty();
}
Also used : CancellationSignal(android.os.CancellationSignal) Location(android.location.Location) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 39 with CancellationSignal

use of android.os.CancellationSignal in project robolectric by robolectric.

the class ShadowContentResolverTest method whenCursorHasBeenSet_queryWithCancellationSignal_shouldReturnTheCursor.

@Test
public void whenCursorHasBeenSet_queryWithCancellationSignal_shouldReturnTheCursor() {
    assertThat(shadowContentResolver.query(null, null, null, null, null, new CancellationSignal())).isNull();
    BaseCursor cursor = new BaseCursor();
    shadowContentResolver.setCursor(cursor);
    assertThat((BaseCursor) shadowContentResolver.query(null, null, null, null, null, new CancellationSignal())).isSameInstanceAs(cursor);
}
Also used : BaseCursor(org.robolectric.fakes.BaseCursor) CancellationSignal(android.os.CancellationSignal) Test(org.junit.Test)

Example 40 with CancellationSignal

use of android.os.CancellationSignal in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class FingerprintAuthenticateSidecar method startAuthentication.

public void startAuthentication(int userId) {
    mCancellationSignal = new CancellationSignal();
    mFingerprintManager.authenticate(null, mCancellationSignal, 0, /* flags */
    mAuthenticationCallback, null, userId);
}
Also used : CancellationSignal(android.os.CancellationSignal)

Aggregations

CancellationSignal (android.os.CancellationSignal)79 OperationCanceledException (android.os.OperationCanceledException)18 Cursor (android.database.Cursor)13 FileNotFoundException (java.io.FileNotFoundException)11 IOException (java.io.IOException)11 RemoteException (android.os.RemoteException)10 FingerprintManager (android.hardware.fingerprint.FingerprintManager)8 ContentProviderClient (android.content.ContentProviderClient)7 ContentResolver (android.content.ContentResolver)6 Uri (android.net.Uri)6 ParcelFileDescriptor (android.os.ParcelFileDescriptor)6 AssetFileDescriptor (android.content.res.AssetFileDescriptor)5 MtpEvent (android.mtp.MtpEvent)5 InputStream (java.io.InputStream)5 FutureTask (java.util.concurrent.FutureTask)4 Test (org.junit.Test)4 KeyguardManager (android.app.KeyguardManager)2 BiometricPrompt (android.hardware.biometrics.BiometricPrompt)2 Bundle (android.os.Bundle)2 Handler (android.os.Handler)2