mirror of
https://github.com/oxen-io/session-android.git
synced 2023-12-14 02:53:01 +01:00
94964474b2
// FREEBIE
53 lines
No EOL
1.9 KiB
Java
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));
|
|
}
|
|
} |