session-android/src/org/thoughtcrime/securesms/gcm/GcmBroadcastReceiver.java
Moxie Marlinspike 94964474b2 So long redphone
// FREEBIE
2017-03-14 13:24:24 -07:00

53 lines
No EOL
1.9 KiB
Java

package org.thoughtcrime.securesms.gcm;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.text.TextUtils;
import android.util.Log;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import org.thoughtcrime.securesms.ApplicationContext;
import org.thoughtcrime.securesms.jobs.PushContentReceiveJob;
import org.thoughtcrime.securesms.jobs.PushNotificationReceiveJob;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
private static final String TAG = GcmBroadcastReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String messageType = gcm.getMessageType(intent);
if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
Log.w(TAG, "GCM message...");
if (!TextSecurePreferences.isPushRegistered(context)) {
Log.w(TAG, "Not push registered!");
return;
}
String messageData = intent.getStringExtra("message");
String receiptData = intent.getStringExtra("receipt");
if (!TextUtils.isEmpty(messageData)) handleReceivedMessage(context, messageData);
else if (!TextUtils.isEmpty(receiptData)) handleReceivedMessage(context, receiptData);
else if (intent.hasExtra("notification")) handleReceivedNotification(context);
}
}
private void handleReceivedMessage(Context context, String data) {
ApplicationContext.getInstance(context)
.getJobManager()
.add(new PushContentReceiveJob(context, data));
}
private void handleReceivedNotification(Context context) {
ApplicationContext.getInstance(context)
.getJobManager()
.add(new PushNotificationReceiveJob(context));
}
}