kopia lustrzana https://github.com/ryukoposting/Signal-Android
Fix FCM not initialized crash.
rodzic
2eb933c2d4
commit
5df20d755a
|
@ -1,10 +1,12 @@
|
||||||
package org.thoughtcrime.securesms.gcm;
|
package org.thoughtcrime.securesms.gcm;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.annotation.WorkerThread;
|
import androidx.annotation.WorkerThread;
|
||||||
|
|
||||||
import com.google.android.gms.tasks.Tasks;
|
import com.google.android.gms.tasks.Tasks;
|
||||||
|
import com.google.firebase.FirebaseApp;
|
||||||
import com.google.firebase.messaging.FirebaseMessaging;
|
import com.google.firebase.messaging.FirebaseMessaging;
|
||||||
|
|
||||||
import org.signal.core.util.logging.Log;
|
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.
|
* Retrieves the current FCM token. If one isn't available, it'll be generated.
|
||||||
*/
|
*/
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
public static Optional<String> getToken() {
|
public static Optional<String> getToken(Context context) {
|
||||||
String token = null;
|
String token = null;
|
||||||
|
|
||||||
|
// Must be called manually if running outside of main process
|
||||||
|
FirebaseApp.initializeApp(context);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
token = Tasks.await(FirebaseMessaging.getInstance().getToken());
|
token = Tasks.await(FirebaseMessaging.getInstance().getToken());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class FcmRefreshJob extends BaseJob {
|
||||||
if (result != ConnectionResult.SUCCESS) {
|
if (result != ConnectionResult.SUCCESS) {
|
||||||
notifyFcmFailure();
|
notifyFcmFailure();
|
||||||
} else {
|
} else {
|
||||||
Optional<String> token = FcmUtil.getToken();
|
Optional<String> token = FcmUtil.getToken(context);
|
||||||
|
|
||||||
if (token.isPresent()) {
|
if (token.isPresent()) {
|
||||||
String oldToken = SignalStore.account().getFcmToken();
|
String oldToken = SignalStore.account().getFcmToken();
|
||||||
|
|
|
@ -39,7 +39,7 @@ class VerifyAccountRepository(private val context: Application) {
|
||||||
Log.d(TAG, "SMS Verification requested")
|
Log.d(TAG, "SMS Verification requested")
|
||||||
|
|
||||||
return Single.fromCallable {
|
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 accountManager = AccountManagerFactory.createUnauthenticated(context, e164, SignalServiceAddress.DEFAULT_DEVICE_ID, password)
|
||||||
val pushChallenge = PushChallengeRequest.getPushChallengeBlocking(accountManager, fcmToken, e164, PUSH_REQUEST_TIMEOUT)
|
val pushChallenge = PushChallengeRequest.getPushChallengeBlocking(accountManager, fcmToken, e164, PUSH_REQUEST_TIMEOUT)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue