package com.mbridge.msdk.foundation.controller; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Handler; import android.os.IBinder; import android.os.IInterface; import android.os.Looper; import android.os.Message; import android.os.Parcel; import android.os.RemoteException; import android.text.TextUtils; import com.google.android.gms.ads.identifier.AdvertisingIdClient; import com.mbridge.msdk.MBridgeConstans; import com.mbridge.msdk.foundation.entity.i; import com.mbridge.msdk.foundation.tools.ac; import com.mbridge.msdk.foundation.tools.ae; import com.mbridge.msdk.foundation.tools.k; import com.mbridge.msdk.foundation.tools.r; import com.mbridge.msdk.foundation.tools.s; import com.mbridge.msdk.foundation.tools.w; import java.io.IOException; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.LinkedBlockingQueue; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; /* compiled from: MBSDKContext */ public class a { public static final String a = "a"; public static HashMap<String, String> b = new HashMap<>(); public static List<String> c = new ArrayList(); private static a d; private static CopyOnWriteArraySet<i> r = new CopyOnWriteArraySet<>(); private Context e; private String f; private String g; private String h; private String i; private int j; private WeakReference<Context> k; private WeakReference<Activity> l; private int m = 0; private JSONObject n; private int o; private boolean p = false; private List<String> q = null; private String s; /* compiled from: MBSDKContext */ public interface b { void a(); } public final WeakReference<Activity> a() { return this.l; } public final void a(WeakReference<Activity> weakReference) { this.l = weakReference; } public final int b() { return this.j; } public final void a(int i2) { this.j = i2; } public final Context c() { WeakReference<Context> weakReference = this.k; if (weakReference == null) { return null; } return weakReference.get(); } public final void a(Context context) { this.k = new WeakReference<>(context); } public final void b(int i2) { this.o = i2; } public final String d() { try { Context context = this.e; if (context != null) { return context.getPackageName(); } return null; } catch (Exception e2) { e2.printStackTrace(); return null; } } public final void a(String str) { Context context; try { this.s = str; if (!TextUtils.isEmpty(str) && (context = this.e) != null) { ac.a(context, "applicationIds", str); } } catch (Exception e2) { e2.printStackTrace(); } } public static Set<i> e() { return r; } private a() { } public static a f() { if (d == null) { synchronized (a.class) { if (d == null) { d = new a(); } } } return d; } public final void a(final b bVar, final Handler handler) { if (!this.p) { try { JSONObject jSONObject = new JSONObject(); this.n = jSONObject; jSONObject.put("webgl", 0); } catch (JSONException e2) { e2.printStackTrace(); } try { Object b2 = ac.b(this.e, "ga_id", "-1"); if (b2 != null && (b2 instanceof String)) { String str = (String) b2; if (ae.b(str) && !"-1".equals(str)) { String str2 = a; w.b(str2, "sp init gaid:" + str); if (com.mbridge.msdk.foundation.controller.authoritycontroller.a.a().a(MBridgeConstans.AUTHORITY_DEVICE_ID)) { s.a(str); } } } } catch (Exception e3) { e3.printStackTrace(); } new Thread(new Runnable() { /* class com.mbridge.msdk.foundation.controller.a.AnonymousClass1 */ public final void run() { if (com.mbridge.msdk.foundation.controller.authoritycontroller.a.a().a(MBridgeConstans.AUTHORITY_DEVICE_ID)) { try { Class.forName("com.google.android.gms.ads.identifier.AdvertisingIdClient"); AdvertisingIdClient.Info advertisingIdInfo = AdvertisingIdClient.getAdvertisingIdInfo(a.this.e); s.a(advertisingIdInfo.getId()); a.a(a.this, advertisingIdInfo.getId()); } catch (Exception unused) { w.c(a.a, "GET ADID ERROR TRY TO GET FROM GOOGLE PLAY APP"); try { C0203a.C0204a a2 = new C0203a().a(a.this.e); s.a(a2.a()); a.a(a.this, a2.a()); } catch (Exception unused2) { w.c(a.a, "GET ADID FROM GOOGLE PLAY APP ERROR"); } } catch (Throwable th) { th.printStackTrace(); } } try { com.mbridge.msdk.c.a b2 = com.mbridge.msdk.c.b.a().b(a.f().k()); if (b2 == null) { b2 = com.mbridge.msdk.c.b.a().b(); } Message obtain = Message.obtain(); obtain.obj = b2; obtain.what = 9; handler.sendMessage(obtain); } catch (Exception e) { e.printStackTrace(); } try { s.q(a.this.e); a.g(); com.mbridge.msdk.c.b.a(a.this.e, a.this.g); a.this.a(false); a.this.a(bVar); } catch (Exception unused3) { } } }).start(); } } /* JADX WARNING: Exception block dominator not found, dom blocks: [] */ public static synchronized void g() { com.mbridge.msdk.c.a b2; synchronized (a.class) { if (!TextUtils.isEmpty(f().k()) && (b2 = com.mbridge.msdk.c.b.a().b(f().k())) != null) { String ai = b2.ai(); if (!TextUtils.isEmpty(ai)) { String b3 = r.b(ai); if (!TextUtils.isEmpty(b3)) { JSONArray jSONArray = new JSONArray(b3); if (jSONArray.length() > 0) { ArrayList arrayList = new ArrayList(); for (int i2 = 0; i2 < jSONArray.length(); i2++) { arrayList.add(jSONArray.optString(i2)); } f().q = arrayList; } } } } } } public final synchronized void a(b bVar) { try { CopyOnWriteArraySet<i> a2 = k.a(this.e).a(this.g); r = a2; if (a2 != null) { if (a2.size() != 0) { CopyOnWriteArraySet copyOnWriteArraySet = new CopyOnWriteArraySet(); Iterator<i> it = r.iterator(); if (it != null) { while (it.hasNext()) { try { i next = it.next(); List<String> list = c; if (!(list == null || list.size() <= 0 || next == null)) { for (int i2 = 0; i2 < c.size(); i2++) { String str = c.get(i2); String b2 = next.b(); if (!TextUtils.isEmpty(str) && !TextUtils.isEmpty(b2) && str.equals(b2)) { copyOnWriteArraySet.add(next); } } } } catch (Exception e2) { e2.printStackTrace(); w.d(a, "remove list error"); } } } CopyOnWriteArraySet<i> copyOnWriteArraySet2 = r; if (copyOnWriteArraySet2 != null) { copyOnWriteArraySet2.clear(); } if (copyOnWriteArraySet.size() > 0) { r.addAll(copyOnWriteArraySet); } k.a(this.e).a(r); if (bVar != null) { bVar.a(); } return; } } if (bVar != null) { bVar.a(); } } catch (Throwable unused) { } } public final void h() { try { CopyOnWriteArraySet<i> copyOnWriteArraySet = r; if (copyOnWriteArraySet != null && copyOnWriteArraySet.size() > 0) { k.a(this.e).a(r); } } catch (Throwable unused) { } } public final List<Long> i() { try { CopyOnWriteArraySet<i> copyOnWriteArraySet = r; if (copyOnWriteArraySet == null || copyOnWriteArraySet.size() <= 0) { return null; } Iterator<i> it = r.iterator(); ArrayList arrayList = new ArrayList(); while (it.hasNext()) { i next = it.next(); if (!arrayList.contains(next.a())) { try { arrayList.add(Long.valueOf(Long.parseLong(next.a()))); } catch (NumberFormatException e2) { e2.printStackTrace(); } } } return arrayList; } catch (Throwable unused) { return null; } } public final Context j() { return this.e; } public final void b(Context context) { this.e = context; } public final void b(String str) { this.f = str; } public final String k() { try { if (!TextUtils.isEmpty(this.g)) { return this.g; } Context context = this.e; if (context != null) { return (String) ac.b(context, "sp_appId", ""); } return ""; } catch (Exception e2) { e2.printStackTrace(); } } public final void c(String str) { Context context; try { this.g = str; if (!TextUtils.isEmpty(str) && (context = this.e) != null) { ac.a(context, "sp_appId", str); } } catch (Exception e2) { e2.printStackTrace(); } } public final String l() { if (!TextUtils.isEmpty(this.h)) { return this.h; } Context context = this.e; if (context != null) { return (String) ac.b(context, "sp_appKey", ""); } return null; } public final void d(String str) { Context context; try { this.h = str; if (!TextUtils.isEmpty(str) && (context = this.e) != null) { ac.a(context, "sp_appKey", str); } } catch (Exception e2) { e2.printStackTrace(); } } public final String m() { if (!TextUtils.isEmpty(this.i)) { return this.i; } Context context = this.e; if (context != null) { return (String) ac.b(context, "sp_wx_appKey", ""); } return null; } public final void e(String str) { Context context; try { this.i = str; if (!TextUtils.isEmpty(str) && (context = this.e) != null) { ac.a(context, "sp_wx_appKey", str); } } catch (Exception e2) { e2.printStackTrace(); } } public final List<String> a(boolean z) { try { List<String> list = f().q; if (z) { return c; } List<String> list2 = c; if (list2 == null || list2.size() <= 0) { return c; } return c; } catch (Exception unused) { w.d(a, "get package info list error"); return null; } } /* renamed from: com.mbridge.msdk.foundation.controller.a$a reason: collision with other inner class name */ /* compiled from: MBSDKContext */ public class C0203a { public C0203a() { } /* renamed from: com.mbridge.msdk.foundation.controller.a$a$a reason: collision with other inner class name */ /* compiled from: MBSDKContext */ public final class C0204a { private final String b; private final boolean c; C0204a(String str, boolean z) { this.b = str; this.c = z; } public final String a() { return this.b; } } public final C0204a a(Context context) throws Exception { if (Looper.myLooper() != Looper.getMainLooper()) { try { context.getPackageManager().getPackageInfo("com.android.vending", 0); b bVar = new b(); Intent intent = new Intent("com.google.android.gms.ads.identifier.service.START"); intent.setPackage("com.google.android.gms"); if (context.bindService(intent, bVar, 1)) { try { c cVar = new c(bVar.a()); C0204a aVar = new C0204a(cVar.a(), cVar.a(true)); context.unbindService(bVar); return aVar; } catch (Exception e) { throw e; } catch (Throwable th) { context.unbindService(bVar); throw th; } } else { throw new IOException("Google Play connection failed"); } } catch (Exception e2) { throw e2; } } else { throw new IllegalStateException("Cannot be called from the main thread"); } } /* access modifiers changed from: private */ /* renamed from: com.mbridge.msdk.foundation.controller.a$a$b */ /* compiled from: MBSDKContext */ public final class b implements ServiceConnection { boolean a; private final LinkedBlockingQueue<IBinder> c; public final void onServiceDisconnected(ComponentName componentName) { } private b() { this.a = false; this.c = new LinkedBlockingQueue<>(1); } public final void onServiceConnected(ComponentName componentName, IBinder iBinder) { try { this.c.put(iBinder); } catch (InterruptedException unused) { } } public final IBinder a() throws InterruptedException { if (!this.a) { this.a = true; return this.c.take(); } throw new IllegalStateException(); } } /* access modifiers changed from: private */ /* renamed from: com.mbridge.msdk.foundation.controller.a$a$c */ /* compiled from: MBSDKContext */ public final class c implements IInterface { private IBinder b; public c(IBinder iBinder) { this.b = iBinder; } public final IBinder asBinder() { return this.b; } /* JADX INFO: finally extract failed */ 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(); String readString = obtain2.readString(); obtain2.recycle(); obtain.recycle(); return readString; } catch (Throwable th) { obtain2.recycle(); obtain.recycle(); throw th; } } 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; } } catch (Throwable th) { obtain2.recycle(); obtain.recycle(); throw th; } obtain2.recycle(); obtain.recycle(); return z2; } } } public final int n() { return this.m; } public final void c(int i2) { this.m = i2; } public final JSONObject o() { return this.n; } public final void a(JSONObject jSONObject) { this.n = jSONObject; } static /* synthetic */ void a(a aVar, String str) { try { if (ae.b(str)) { String str2 = a; w.b(str2, "saveGAID gaid:" + str); ac.a(aVar.e, "ga_id", str); } } catch (Exception e2) { e2.printStackTrace(); } } }