discord-jadx/app/src/main/java/c/i/a/f/d/g.java

132 lines
4.6 KiB
Java

package c.i.a.f.d;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.Looper;
import android.os.Messenger;
import android.util.Log;
import android.util.SparseArray;
import androidx.annotation.MainThread;
import androidx.annotation.Nullable;
import c.i.a.f.h.f.a;
import com.airbnb.lottie.parser.AnimatableValueParser;
import com.google.android.gms.cloudmessaging.zzp;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.concurrent.TimeUnit;
/* compiled from: com.google.android.gms:play-services-cloud-messaging@@16.0.0 */
public final class g implements ServiceConnection {
public int i = 0;
public final Messenger j = new Messenger(new a(Looper.getMainLooper(), new j(this)));
public p k;
public final Queue<q<?>> l = new ArrayDeque();
public final SparseArray<q<?>> m = new SparseArray<>();
public final /* synthetic */ f n;
public g(f fVar, h hVar) {
this.n = fVar;
}
public final synchronized void a(int i, @Nullable String str) {
if (Log.isLoggable("MessengerIpcClient", 3)) {
String valueOf = String.valueOf(str);
Log.d("MessengerIpcClient", valueOf.length() != 0 ? "Disconnected: ".concat(valueOf) : new String("Disconnected: "));
}
int i2 = this.i;
if (i2 == 0) {
throw new IllegalStateException();
} else if (i2 == 1 || i2 == 2) {
if (Log.isLoggable("MessengerIpcClient", 2)) {
Log.v("MessengerIpcClient", "Unbinding service");
}
this.i = 4;
c.i.a.f.e.n.a.b().c(this.n.b, this);
zzp zzp = new zzp(i, str);
for (q<?> qVar : this.l) {
qVar.b(zzp);
}
this.l.clear();
for (int i3 = 0; i3 < this.m.size(); i3++) {
this.m.valueAt(i3).b(zzp);
}
this.m.clear();
} else if (i2 == 3) {
this.i = 4;
} else if (i2 != 4) {
int i4 = this.i;
StringBuilder sb = new StringBuilder(26);
sb.append("Unknown state: ");
sb.append(i4);
throw new IllegalStateException(sb.toString());
}
}
public final synchronized boolean b(q<?> qVar) {
int i = this.i;
if (i == 0) {
this.l.add(qVar);
AnimatableValueParser.F(this.i == 0);
if (Log.isLoggable("MessengerIpcClient", 2)) {
Log.v("MessengerIpcClient", "Starting bind to GmsCore");
}
this.i = 1;
Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
intent.setPackage("com.google.android.gms");
if (!c.i.a.f.e.n.a.b().a(this.n.b, intent, this, 1)) {
a(0, "Unable to bind to service");
} else {
this.n.f1025c.schedule(new i(this), 30, TimeUnit.SECONDS);
}
return true;
} else if (i == 1) {
this.l.add(qVar);
return true;
} else if (i != 2) {
if (i != 3) {
if (i != 4) {
int i2 = this.i;
StringBuilder sb = new StringBuilder(26);
sb.append("Unknown state: ");
sb.append(i2);
throw new IllegalStateException(sb.toString());
}
}
return false;
} else {
this.l.add(qVar);
this.n.f1025c.execute(new k(this));
return true;
}
}
public final synchronized void c() {
if (this.i == 2 && this.l.isEmpty() && this.m.size() == 0) {
if (Log.isLoggable("MessengerIpcClient", 2)) {
Log.v("MessengerIpcClient", "Finished handling requests, unbinding");
}
this.i = 3;
c.i.a.f.e.n.a.b().c(this.n.b, this);
}
}
@Override // android.content.ServiceConnection
@MainThread
public final void onServiceConnected(ComponentName componentName, IBinder iBinder) {
if (Log.isLoggable("MessengerIpcClient", 2)) {
Log.v("MessengerIpcClient", "Service connected");
}
this.n.f1025c.execute(new l(this, iBinder));
}
@Override // android.content.ServiceConnection
@MainThread
public final void onServiceDisconnected(ComponentName componentName) {
if (Log.isLoggable("MessengerIpcClient", 2)) {
Log.v("MessengerIpcClient", "Service disconnected");
}
this.n.f1025c.execute(new n(this));
}
}