Search in sources :

Example 1 with AnyThread

use of androidx.annotation.AnyThread in project grpc-java by grpc.

the class ServiceBinding method unbindInternal.

@AnyThread
void unbindInternal(Status reason) {
    Context unbindFrom = null;
    synchronized (this) {
        if (state == State.BINDING || state == State.BOUND) {
            unbindFrom = sourceContext;
        }
        state = State.UNBOUND;
    }
    mainThreadExecutor.execute(() -> notifyUnbound(reason));
    if (unbindFrom != null) {
        unbindFrom.unbindService(this);
    }
}
Also used : Context(android.content.Context) AnyThread(androidx.annotation.AnyThread)

Example 2 with AnyThread

use of androidx.annotation.AnyThread in project grpc-java by grpc.

the class ServiceBinding method bind.

@AnyThread
@Override
public synchronized void bind() {
    if (state == State.NOT_BINDING) {
        state = State.BINDING;
        Status bindResult = bindInternal(sourceContext, bindIntent, this, bindFlags);
        if (!bindResult.isOk()) {
            handleBindServiceFailure(sourceContext, this);
            state = State.UNBOUND;
            mainThreadExecutor.execute(() -> notifyUnbound(bindResult));
        }
    }
}
Also used : Status(io.grpc.Status) AnyThread(androidx.annotation.AnyThread)

Example 3 with AnyThread

use of androidx.annotation.AnyThread in project Signal-Android by WhisperSystems.

the class BlobProvider method initialize.

/**
 * Allows the class to be initialized. Part of this initialization is deleting any leftover
 * single-session blobs from the previous session. However, this class defers that work to a
 * background thread, so callers don't have to worry about it.
 */
@AnyThread
public synchronized void initialize(@NonNull Context context) {
    SignalExecutors.BOUNDED.execute(() -> {
        synchronized (this) {
            File directory = getOrCreateDirectory(context, SINGLE_SESSION_DIRECTORY);
            File[] files = directory.listFiles();
            if (files != null) {
                for (File file : files) {
                    if (file.delete()) {
                        Log.d(TAG, "Deleted single-session file: " + file.getName());
                    } else {
                        Log.w(TAG, "Failed to delete single-session file! " + file.getName());
                    }
                }
            } else {
                Log.w(TAG, "Null directory listing!");
            }
            deleteOrphanedDraftFiles(context);
            Log.i(TAG, "Initialized.");
            initialized = true;
            notifyAll();
        }
    });
}
Also used : File(java.io.File) AnyThread(androidx.annotation.AnyThread)

Example 4 with AnyThread

use of androidx.annotation.AnyThread in project Signal-Android by WhisperSystems.

the class LiveRecipientCache method addToCache.

/**
 * Adds a recipient to the cache if we don't have an entry. This will also update a cache entry
 * if the provided recipient is resolved, or if the existing cache entry is unresolved.
 *
 * If the recipient you add is unresolved, this will enqueue a resolve on a background thread.
 */
@AnyThread
public void addToCache(@NonNull Collection<Recipient> newRecipients) {
    newRecipients.stream().filter(this::isValidForCache).forEach(recipient -> {
        LiveRecipient live;
        boolean needsResolve;
        synchronized (recipients) {
            live = recipients.get(recipient.getId());
            if (live == null) {
                live = new LiveRecipient(context, recipient);
                recipients.put(recipient.getId(), live);
                needsResolve = recipient.isResolving();
            } else if (live.get().isResolving() || !recipient.isResolving()) {
                live.set(recipient);
                needsResolve = recipient.isResolving();
            } else {
                needsResolve = false;
            }
        }
        if (needsResolve) {
            LiveRecipient toResolve = live;
            MissingRecipientException prettyStackTraceError = new MissingRecipientException(toResolve.getId());
            resolveExecutor.execute(() -> {
                try {
                    toResolve.resolve();
                } catch (MissingRecipientException e) {
                    throw prettyStackTraceError;
                }
            });
        }
    });
}
Also used : MissingRecipientException(org.thoughtcrime.securesms.database.RecipientDatabase.MissingRecipientException) AnyThread(androidx.annotation.AnyThread)

Example 5 with AnyThread

use of androidx.annotation.AnyThread in project Signal-Android by WhisperSystems.

the class KeyValueStore method blockUntilAllWritesFinished.

/**
 * Ensures that any pending writes (such as those made via {@link Writer#apply()}) are finished.
 */
@AnyThread
synchronized void blockUntilAllWritesFinished() {
    CountDownLatch latch = new CountDownLatch(1);
    executor.execute(latch::countDown);
    try {
        latch.await();
    } catch (InterruptedException e) {
        Log.w(TAG, "Failed to wait for all writes.");
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) AnyThread(androidx.annotation.AnyThread)

Aggregations

AnyThread (androidx.annotation.AnyThread)15 Cursor (android.database.Cursor)3 IOException (java.io.IOException)3 Paint (android.graphics.Paint)2 Point (android.graphics.Point)2 NonNull (androidx.annotation.NonNull)2 ExifInterface (androidx.exifinterface.media.ExifInterface)2 UUID (java.util.UUID)2 MegaphoneRecord (org.thoughtcrime.securesms.database.model.MegaphoneRecord)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 Uri (android.net.Uri)1 WorkerThread (androidx.annotation.WorkerThread)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 Stopwatch (com.google.common.base.Stopwatch)1 ByteString (com.google.protobuf.ByteString)1 Toast (de.schildbach.wallet.util.Toast)1 Status (io.grpc.Status)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1