151 lines
6.0 KiB
Java
151 lines
6.0 KiB
Java
package com.google.android.gms.cloudmessaging;
|
|
|
|
import android.app.PendingIntent;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.os.Parcelable;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
import com.google.android.gms.common.util.concurrent.NamedThreadFactory;
|
|
import com.google.android.gms.tasks.Task;
|
|
import com.google.android.gms.tasks.Tasks;
|
|
import com.google.firebase.messaging.Constants;
|
|
import com.google.firebase.messaging.ServiceStarter;
|
|
import java.lang.ref.SoftReference;
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.concurrent.Executor;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeoutException;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public abstract class CloudMessagingReceiver extends BroadcastReceiver {
|
|
private static SoftReference zza;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public static final class IntentActionKeys {
|
|
public static final String NOTIFICATION_DISMISS = "com.google.firebase.messaging.NOTIFICATION_DISMISS";
|
|
public static final String NOTIFICATION_OPEN = "com.google.firebase.messaging.NOTIFICATION_OPEN";
|
|
|
|
private IntentActionKeys() {
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes3.dex */
|
|
public static final class IntentKeys {
|
|
public static final String PENDING_INTENT = "pending_intent";
|
|
public static final String WRAPPED_INTENT = "wrapped_intent";
|
|
|
|
private IntentKeys() {
|
|
}
|
|
}
|
|
|
|
private final int zzb(Context context, Intent intent) {
|
|
Task zzc;
|
|
if (intent.getExtras() == null) {
|
|
return ServiceStarter.ERROR_UNKNOWN;
|
|
}
|
|
CloudMessage cloudMessage = new CloudMessage(intent);
|
|
if (TextUtils.isEmpty(cloudMessage.getMessageId())) {
|
|
zzc = Tasks.forResult(null);
|
|
} else {
|
|
Bundle bundle = new Bundle();
|
|
bundle.putString(Constants.MessagePayloadKeys.MSGID, cloudMessage.getMessageId());
|
|
Integer zza2 = cloudMessage.zza();
|
|
if (zza2 != null) {
|
|
bundle.putInt(Constants.MessagePayloadKeys.PRODUCT_ID, zza2.intValue());
|
|
}
|
|
bundle.putBoolean("supports_message_handled", true);
|
|
zzc = zzu.zzb(context).zzc(2, bundle);
|
|
}
|
|
int onMessageReceive = onMessageReceive(context, cloudMessage);
|
|
try {
|
|
Tasks.await(zzc, TimeUnit.SECONDS.toMillis(1L), TimeUnit.MILLISECONDS);
|
|
return onMessageReceive;
|
|
} catch (InterruptedException | ExecutionException | TimeoutException e4) {
|
|
Log.w("CloudMessagingReceiver", "Message ack failed: ".concat(e4.toString()));
|
|
return onMessageReceive;
|
|
}
|
|
}
|
|
|
|
private final int zzc(Context context, Intent intent) {
|
|
PendingIntent pendingIntent = (PendingIntent) intent.getParcelableExtra(IntentKeys.PENDING_INTENT);
|
|
if (pendingIntent != null) {
|
|
try {
|
|
pendingIntent.send();
|
|
} catch (PendingIntent.CanceledException unused) {
|
|
Log.e("CloudMessagingReceiver", "Notification pending intent canceled");
|
|
}
|
|
}
|
|
Bundle extras = intent.getExtras();
|
|
if (extras != null) {
|
|
extras.remove(IntentKeys.PENDING_INTENT);
|
|
} else {
|
|
extras = new Bundle();
|
|
}
|
|
String action = intent.getAction();
|
|
if (action == IntentActionKeys.NOTIFICATION_DISMISS || (action != null && action.equals(IntentActionKeys.NOTIFICATION_DISMISS))) {
|
|
onNotificationDismissed(context, extras);
|
|
return -1;
|
|
}
|
|
Log.e("CloudMessagingReceiver", "Unknown notification action");
|
|
return ServiceStarter.ERROR_UNKNOWN;
|
|
}
|
|
|
|
public Executor getBroadcastExecutor() {
|
|
ExecutorService executorService;
|
|
synchronized (CloudMessagingReceiver.class) {
|
|
try {
|
|
SoftReference softReference = zza;
|
|
executorService = softReference != null ? (ExecutorService) softReference.get() : null;
|
|
if (executorService == null) {
|
|
com.google.android.gms.internal.cloudmessaging.zze.zza();
|
|
executorService = Executors.unconfigurableExecutorService(Executors.newCachedThreadPool(new NamedThreadFactory("firebase-iid-executor")));
|
|
zza = new SoftReference(executorService);
|
|
}
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
return executorService;
|
|
}
|
|
|
|
public abstract int onMessageReceive(Context context, CloudMessage cloudMessage);
|
|
|
|
public void onNotificationDismissed(Context context, Bundle bundle) {
|
|
}
|
|
|
|
@Override // android.content.BroadcastReceiver
|
|
public final void onReceive(final Context context, final Intent intent) {
|
|
if (intent == null) {
|
|
return;
|
|
}
|
|
final boolean isOrderedBroadcast = isOrderedBroadcast();
|
|
final BroadcastReceiver.PendingResult goAsync = goAsync();
|
|
getBroadcastExecutor().execute(new Runnable() { // from class: com.google.android.gms.cloudmessaging.zzf
|
|
@Override // java.lang.Runnable
|
|
public final void run() {
|
|
CloudMessagingReceiver.this.zza(intent, context, isOrderedBroadcast, goAsync);
|
|
}
|
|
});
|
|
}
|
|
|
|
public final /* synthetic */ void zza(Intent intent, Context context, boolean z3, BroadcastReceiver.PendingResult pendingResult) {
|
|
try {
|
|
Parcelable parcelableExtra = intent.getParcelableExtra(IntentKeys.WRAPPED_INTENT);
|
|
Intent intent2 = parcelableExtra instanceof Intent ? (Intent) parcelableExtra : null;
|
|
int zzc = intent2 != null ? zzc(context, intent2) : zzb(context, intent);
|
|
if (z3) {
|
|
pendingResult.setResultCode(zzc);
|
|
}
|
|
pendingResult.finish();
|
|
} catch (Throwable th) {
|
|
pendingResult.finish();
|
|
throw th;
|
|
}
|
|
}
|
|
}
|