package com.google.firebase.messaging; import android.app.Service; import android.content.Intent; import android.os.Binder; import android.os.IBinder; import android.util.Log; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.Task; import com.google.android.gms.tasks.TaskCompletionSource; import com.google.android.gms.tasks.Tasks; import com.google.firebase.messaging.g1; import java.util.concurrent.ExecutorService; /* loaded from: classes2.dex */ public abstract class j extends Service { /* renamed from: b, reason: collision with root package name */ private Binder f5595b; /* renamed from: d, reason: collision with root package name */ private int f5597d; /* renamed from: a, reason: collision with root package name */ final ExecutorService f5594a = p.d(); /* renamed from: c, reason: collision with root package name */ private final Object f5596c = new Object(); /* renamed from: e, reason: collision with root package name */ private int f5598e = 0; class a implements g1.a { a() { } @Override // com.google.firebase.messaging.g1.a public Task a(Intent intent) { return j.this.j(intent); } } private void d(Intent intent) { if (intent != null) { e1.c(intent); } synchronized (this.f5596c) { int i10 = this.f5598e - 1; this.f5598e = i10; if (i10 == 0) { k(this.f5597d); } } } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void h(Intent intent, Task task) { d(intent); } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void i(Intent intent, TaskCompletionSource taskCompletionSource) { try { f(intent); } finally { taskCompletionSource.setResult(null); } } /* JADX INFO: Access modifiers changed from: private */ public Task j(final Intent intent) { if (g(intent)) { return Tasks.forResult(null); } final TaskCompletionSource taskCompletionSource = new TaskCompletionSource(); this.f5594a.execute(new Runnable() { // from class: com.google.firebase.messaging.i @Override // java.lang.Runnable public final void run() { j.this.i(intent, taskCompletionSource); } }); return taskCompletionSource.getTask(); } protected abstract Intent e(Intent intent); public abstract void f(Intent intent); public boolean g(Intent intent) { return false; } boolean k(int i10) { return stopSelfResult(i10); } @Override // android.app.Service public final synchronized IBinder onBind(Intent intent) { if (Log.isLoggable("EnhancedIntentService", 3)) { Log.d("EnhancedIntentService", "Service received bind request"); } if (this.f5595b == null) { this.f5595b = new g1(new a()); } return this.f5595b; } @Override // android.app.Service public void onDestroy() { this.f5594a.shutdown(); super.onDestroy(); } @Override // android.app.Service public final int onStartCommand(final Intent intent, int i10, int i11) { synchronized (this.f5596c) { this.f5597d = i11; this.f5598e++; } Intent e10 = e(intent); if (e10 == null) { d(intent); return 2; } Task j10 = j(e10); if (j10.isComplete()) { d(intent); return 2; } j10.addOnCompleteListener(new g(), new OnCompleteListener() { // from class: com.google.firebase.messaging.h @Override // com.google.android.gms.tasks.OnCompleteListener public final void onComplete(Task task) { j.this.h(intent, task); } }); return 3; } }