package o;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Looper;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import android.util.Log;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class B30 {
    public static int h;
    public static PendingIntent i;
    public static final Pattern j = Pattern.compile("\\|ID\\|([^|]+)\\|:?+(.*)");
    public final Context b;
    public final C3111zf c;
    public final ScheduledThreadPoolExecutor d;
    public Messenger f;
    public C3132zp0 g;
    public final I80 a = new I80(0);
    public final Messenger e = new Messenger(new Qn0(this, Looper.getMainLooper()));

    public B30(Context context) {
        this.b = context;
        this.c = new C3111zf(context);
        ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
        scheduledThreadPoolExecutor.setKeepAliveTime(60L, TimeUnit.SECONDS);
        scheduledThreadPoolExecutor.allowCoreThreadTimeOut(true);
        this.d = scheduledThreadPoolExecutor;
    }

    public final Hw0 a(Bundle bundle) throws RemoteException {
        String string;
        synchronized (B30.class) {
            int i2 = h;
            h = i2 + 1;
            string = Integer.toString(i2);
        }
        Qc0 qc0 = new Qc0();
        synchronized (this.a) {
            this.a.put(string, qc0);
        }
        Intent intent = new Intent();
        intent.setPackage("com.google.android.gms");
        if (this.c.v() == 2) {
            intent.setAction("com.google.iid.TOKEN_REQUEST");
        } else {
            intent.setAction("com.google.android.c2dm.intent.REGISTER");
        }
        intent.putExtras(bundle);
        Context context = this.b;
        synchronized (B30.class) {
            try {
                if (i == null) {
                    Intent intent2 = new Intent();
                    intent2.setPackage("com.google.example.invalidpackage");
                    i = PendingIntent.getBroadcast(context, 0, intent2, Dn0.a);
                }
                intent.putExtra("app", i);
            } finally {
            }
        }
        intent.putExtra("kid", "|ID|" + string + "|");
        if (Log.isLoggable("Rpc", 3)) {
            "Sending ".concat(String.valueOf(intent.getExtras()));
        }
        intent.putExtra("google.messenger", this.e);
        if (this.f != null || this.g != null) {
            Message messageObtain = Message.obtain();
            messageObtain.obj = intent;
            try {
                Messenger messenger = this.f;
                if (messenger != null) {
                    messenger.send(messageObtain);
                } else {
                    Messenger messenger2 = this.g.l;
                    messenger2.getClass();
                    messenger2.send(messageObtain);
                }
            } catch (RemoteException unused) {
                Log.isLoggable("Rpc", 3);
            }
        } else if (this.c.v() == 2) {
            this.b.sendBroadcast(intent);
        } else {
            this.b.startService(intent);
        }
        qc0.a.a(ExecutorC0614Xr.f416o, new C70(this, string, this.d.schedule(new RunnableC2017o3(25, qc0), 30L, TimeUnit.SECONDS), 9));
        return qc0.a;
    }

    public final void b(String str, Bundle bundle) {
        synchronized (this.a) {
            try {
                Qc0 qc0 = (Qc0) this.a.remove(str);
                if (qc0 == null) {
                    return;
                }
                qc0.b(bundle);
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
