package com.appsflyer.internal;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Looper;
import android.os.Parcel;
import android.os.RemoteException;
import java.io.IOException;
import java.util.concurrent.LinkedBlockingQueue;

public final class x {

    public static final class a implements IInterface {

        /* renamed from: ˋ  reason: contains not printable characters */
        public IBinder f2145;

        public a(IBinder iBinder) {
            this.f2145 = iBinder;
        }

        public final IBinder asBinder() {
            return this.f2145;
        }

        /* renamed from: ˋ  reason: contains not printable characters */
        public final String m1250() throws RemoteException {
            Parcel obtain = Parcel.obtain();
            Parcel obtain2 = Parcel.obtain();
            try {
                obtain.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");
                this.f2145.transact(1, obtain, obtain2, 0);
                obtain2.readException();
                return obtain2.readString();
            } finally {
                obtain2.recycle();
                obtain.recycle();
            }
        }

        /* renamed from: ˎ  reason: contains not printable characters */
        public final boolean m1251() throws RemoteException {
            Parcel obtain = Parcel.obtain();
            Parcel obtain2 = Parcel.obtain();
            try {
                obtain.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");
                boolean z = true;
                obtain.writeInt(1);
                this.f2145.transact(2, obtain, obtain2, 0);
                obtain2.readException();
                if (obtain2.readInt() == 0) {
                    z = false;
                }
                return z;
            } finally {
                obtain2.recycle();
                obtain.recycle();
            }
        }
    }

    public static final class c {

        /* renamed from: ˎ  reason: contains not printable characters */
        public final boolean f2148;

        /* renamed from: ˏ  reason: contains not printable characters */
        public final String f2149;

        public c(String str, boolean z) {
            this.f2149 = str;
            this.f2148 = z;
        }
    }

    /* renamed from: ˊ  reason: contains not printable characters */
    public static c m1249(Context context) throws Exception {
        if (Looper.myLooper() != Looper.getMainLooper()) {
            try {
                context.getPackageManager().getPackageInfo("com.android.vending", 0);
                b bVar = new b((byte) 0);
                Intent intent = new Intent("com.google.android.gms.ads.identifier.service.START");
                intent.setPackage("com.google.android.gms");
                try {
                    if (!context.bindService(intent, bVar, 1)) {
                        context.unbindService(bVar);
                        throw new IOException("Google Play connection failed");
                    } else if (!bVar.f2146) {
                        bVar.f2146 = true;
                        a aVar = new a(bVar.f2147.take());
                        c cVar = new c(aVar.m1250(), aVar.m1251());
                        context.unbindService(bVar);
                        return cVar;
                    } else {
                        throw new IllegalStateException();
                    }
                } catch (Exception e) {
                    throw e;
                } catch (Throwable th) {
                    context.unbindService(bVar);
                    throw th;
                }
            } catch (Exception e2) {
                throw e2;
            }
        } else {
            throw new IllegalStateException("Cannot be called from the main thread");
        }
    }

    public static final class b implements ServiceConnection {

        /* renamed from: ˊ  reason: contains not printable characters */
        public boolean f2146;

        /* renamed from: ॱ  reason: contains not printable characters */
        public final LinkedBlockingQueue<IBinder> f2147;

        public b() {
            this.f2147 = new LinkedBlockingQueue<>(1);
            this.f2146 = false;
        }

        public final void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            try {
                this.f2147.put(iBinder);
            } catch (InterruptedException unused) {
            }
        }

        public final void onServiceDisconnected(ComponentName componentName) {
        }

        public /* synthetic */ b(byte b) {
            this();
        }
    }
}
