Switch from GCM to FCM.
parent
ebe8d38a91
commit
d482c60a98
@ -0,0 +1,42 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "312334754206",
|
||||
"firebase_url": "https://api-project-312334754206.firebaseio.com",
|
||||
"project_id": "api-project-312334754206",
|
||||
"storage_bucket": "api-project-312334754206.appspot.com"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:312334754206:android:a9297b152879f266",
|
||||
"android_client_info": {
|
||||
"package_name": "org.thoughtcrime.securesms"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "312334754206-dg1p1mtekis8ivja3ica50vonmrlunh4.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyDrfzNAPBPzX6key51hqo3p5LZXF5Y-yxU"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"analytics_service": {
|
||||
"status": 1
|
||||
},
|
||||
"appinvite_service": {
|
||||
"status": 1,
|
||||
"other_platform_oauth_client": []
|
||||
},
|
||||
"ads_service": {
|
||||
"status": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package org.thoughtcrime.securesms.gcm;
|
||||
|
||||
import android.support.annotation.WorkerThread;
|
||||
|
||||
import com.google.firebase.iid.FirebaseInstanceId;
|
||||
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public final class FcmUtil {
|
||||
|
||||
private static final String TAG = FcmUtil.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* Retrieves the current FCM token. If one isn't available, it'll be generated.
|
||||
*/
|
||||
@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) {
|
||||
token.set(task.getResult().getToken());
|
||||
} else {
|
||||
Log.w(TAG, "Failed to get the token.", task.getException());
|
||||
}
|
||||
|
||||
latch.countDown();
|
||||
});
|
||||
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
Log.w(TAG, "Was interrupted while waiting for the token.");
|
||||
}
|
||||
|
||||
return Optional.fromNullable(token.get());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue