package com.mbridge.msdk.foundation.tools; 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; /* loaded from: classes4.dex */ public final class b { public final a a(Context context) throws Exception { if (Looper.myLooper() == Looper.getMainLooper()) { throw new IllegalStateException("Cannot be called from the main thread"); } context.getPackageManager().getPackageInfo("com.android.vending", 0); ServiceConnectionC0203b serviceConnectionC0203b = new ServiceConnectionC0203b(); Intent intent = new Intent("com.google.android.gms.ads.identifier.service.START"); intent.setPackage("com.google.android.gms"); if (context.bindService(intent, serviceConnectionC0203b, 1)) { try { try { c cVar = new c(serviceConnectionC0203b.a()); return new a(cVar.a(), cVar.a(true)); } catch (Exception e) { throw e; } } finally { context.unbindService(serviceConnectionC0203b); } } throw new IOException("Google Play connection failed"); } public final class a { private final String b; private final boolean c; public final String a() { return this.b; } public final boolean b() { return this.c; } public a(String str, boolean z) { this.b = str; this.c = z; } } /* renamed from: com.mbridge.msdk.foundation.tools.b$b, reason: collision with other inner class name */ public final class ServiceConnectionC0203b implements ServiceConnection { boolean a; private final LinkedBlockingQueue c; @Override // android.content.ServiceConnection public final void onServiceDisconnected(ComponentName componentName) { } private ServiceConnectionC0203b() { this.c = new LinkedBlockingQueue<>(1); this.a = false; } public final IBinder a() throws InterruptedException { if (this.a) { throw new IllegalStateException(); } this.a = true; return this.c.take(); } @Override // android.content.ServiceConnection public final void onServiceConnected(ComponentName componentName, IBinder iBinder) { try { this.c.put(iBinder); } catch (InterruptedException e) { af.b("AdvertisingIdClient", e.getMessage()); } } } public final class c implements IInterface { private IBinder b; @Override // android.os.IInterface public final IBinder asBinder() { return this.b; } public c(IBinder iBinder) { this.b = iBinder; } public final String a() throws RemoteException { Parcel obtain = Parcel.obtain(); Parcel obtain2 = Parcel.obtain(); try { obtain.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService"); this.b.transact(1, obtain, obtain2, 0); obtain2.readException(); return obtain2.readString(); } catch (Throwable th) { try { af.b("AdvertisingIdClient", th.getMessage()); obtain2.recycle(); obtain.recycle(); return null; } finally { obtain2.recycle(); obtain.recycle(); } } } public final boolean a(boolean z) throws RemoteException { Parcel obtain = Parcel.obtain(); Parcel obtain2 = Parcel.obtain(); boolean z2 = false; try { obtain.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService"); obtain.writeInt(z ? 1 : 0); this.b.transact(2, obtain, obtain2, 0); obtain2.readException(); if (obtain2.readInt() != 0) { z2 = true; } } finally { try { return z2; } finally { } } return z2; } } }