mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-24 11:45:28 +00:00
Fix ANR by upgrading Firebase Messaging.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package org.thoughtcrime.securesms.components.settings.app.privacy.advanced
|
||||
|
||||
import android.content.Context
|
||||
import com.google.firebase.iid.FirebaseInstanceId
|
||||
import com.google.android.gms.tasks.Tasks
|
||||
import com.google.firebase.installations.FirebaseInstallations
|
||||
import org.signal.core.util.concurrent.SignalExecutors
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
@@ -14,6 +15,7 @@ import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.whispersystems.libsignal.util.guava.Optional
|
||||
import org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.ExecutionException
|
||||
|
||||
private val TAG = Log.tag(AdvancedPrivacySettingsRepository::class.java)
|
||||
|
||||
@@ -29,12 +31,18 @@ class AdvancedPrivacySettingsRepository(private val context: Context) {
|
||||
Log.w(TAG, e)
|
||||
}
|
||||
if (!TextSecurePreferences.isFcmDisabled(context)) {
|
||||
FirebaseInstanceId.getInstance().deleteInstanceId()
|
||||
Tasks.await(FirebaseInstallations.getInstance().delete())
|
||||
}
|
||||
DisablePushMessagesResult.SUCCESS
|
||||
} catch (ioe: IOException) {
|
||||
Log.w(TAG, ioe)
|
||||
DisablePushMessagesResult.NETWORK_ERROR
|
||||
} catch (e: InterruptedException) {
|
||||
Log.w(TAG, "Interrupted while deleting", e)
|
||||
DisablePushMessagesResult.NETWORK_ERROR
|
||||
} catch (e: ExecutionException) {
|
||||
Log.w(TAG, "Error deleting", e.cause)
|
||||
DisablePushMessagesResult.NETWORK_ERROR
|
||||
}
|
||||
|
||||
consumer(result)
|
||||
|
||||
@@ -4,13 +4,13 @@ import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.google.firebase.iid.FirebaseInstanceId;
|
||||
import com.google.android.gms.tasks.Tasks;
|
||||
import com.google.firebase.messaging.FirebaseMessaging;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public final class FcmUtil {
|
||||
|
||||
@@ -21,25 +21,15 @@ public final class FcmUtil {
|
||||
*/
|
||||
@WorkerThread
|
||||
public static Optional<String> getToken() {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
AtomicReference<String> token = new AtomicReference<>(null);
|
||||
|
||||
FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(task -> {
|
||||
if (task.isSuccessful() && task.getResult() != null && !TextUtils.isEmpty(task.getResult().getToken())) {
|
||||
token.set(task.getResult().getToken());
|
||||
} else {
|
||||
Log.w(TAG, "Failed to get the token.", task.getException());
|
||||
}
|
||||
|
||||
latch.countDown();
|
||||
});
|
||||
|
||||
String token = null;
|
||||
try {
|
||||
latch.await();
|
||||
token = Tasks.await(FirebaseMessaging.getInstance().getToken());
|
||||
} catch (InterruptedException e) {
|
||||
Log.w(TAG, "Was interrupted while waiting for the token.");
|
||||
} catch (ExecutionException e) {
|
||||
Log.w(TAG, "Failed to get the token.", e.getCause());
|
||||
}
|
||||
|
||||
return Optional.fromNullable(token.get());
|
||||
return Optional.fromNullable(TextUtils.isEmpty(token) ? null : token);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user