Fix FCM not initialized crash.
This commit is contained in:
parent
2eb933c2d4
commit
5df20d755a
3 changed files with 9 additions and 3 deletions
|
@ -1,10 +1,12 @@
|
|||
package org.thoughtcrime.securesms.gcm;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.google.android.gms.tasks.Tasks;
|
||||
import com.google.firebase.FirebaseApp;
|
||||
import com.google.firebase.messaging.FirebaseMessaging;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
|
@ -20,8 +22,12 @@ public final class FcmUtil {
|
|||
* Retrieves the current FCM token. If one isn't available, it'll be generated.
|
||||
*/
|
||||
@WorkerThread
|
||||
public static Optional<String> getToken() {
|
||||
public static Optional<String> getToken(Context context) {
|
||||
String token = null;
|
||||
|
||||
// Must be called manually if running outside of main process
|
||||
FirebaseApp.initializeApp(context);
|
||||
|
||||
try {
|
||||
token = Tasks.await(FirebaseMessaging.getInstance().getToken());
|
||||
} catch (InterruptedException e) {
|
||||
|
|
|
@ -87,7 +87,7 @@ public class FcmRefreshJob extends BaseJob {
|
|||
if (result != ConnectionResult.SUCCESS) {
|
||||
notifyFcmFailure();
|
||||
} else {
|
||||
Optional<String> token = FcmUtil.getToken();
|
||||
Optional<String> token = FcmUtil.getToken(context);
|
||||
|
||||
if (token.isPresent()) {
|
||||
String oldToken = SignalStore.account().getFcmToken();
|
||||
|
|
|
@ -39,7 +39,7 @@ class VerifyAccountRepository(private val context: Application) {
|
|||
Log.d(TAG, "SMS Verification requested")
|
||||
|
||||
return Single.fromCallable {
|
||||
val fcmToken: Optional<String> = FcmUtil.getToken()
|
||||
val fcmToken: Optional<String> = FcmUtil.getToken(context)
|
||||
val accountManager = AccountManagerFactory.createUnauthenticated(context, e164, SignalServiceAddress.DEFAULT_DEVICE_ID, password)
|
||||
val pushChallenge = PushChallengeRequest.getPushChallengeBlocking(accountManager, fcmToken, e164, PUSH_REQUEST_TIMEOUT)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue