package com.mbridge.msdk.foundation.controller; import android.app.Activity; import android.content.Context; import android.content.pm.PackageManager; import android.graphics.drawable.BitmapDrawable; import android.os.Handler; import android.os.Message; import android.text.TextUtils; import com.mbridge.msdk.MBridgeConstans; import com.mbridge.msdk.c.g; import com.mbridge.msdk.foundation.same.report.i; import com.mbridge.msdk.foundation.tools.SameMD5; import com.mbridge.msdk.foundation.tools.ab; import com.mbridge.msdk.foundation.tools.af; import com.mbridge.msdk.foundation.tools.ah; import com.mbridge.msdk.foundation.tools.ak; import com.mbridge.msdk.foundation.tools.an; import com.mbridge.msdk.foundation.tools.f; import com.mbridge.msdk.foundation.tools.h; import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Iterator; import java.util.concurrent.ConcurrentHashMap; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes4.dex */ public abstract class a { public static final String a = c.class.getSimpleName(); public static HashMap b = new HashMap<>(); protected String c; protected Context d; protected String e; private WeakReference g; private String h; private int i; private String l; private String m; private int n; private WeakReference p; private JSONObject q; private String s; private final h f = new h(); private JSONObject j = new JSONObject(); private boolean k = false; private ConcurrentHashMap o = new ConcurrentHashMap<>(); private int r = 0; /* renamed from: com.mbridge.msdk.foundation.controller.a$a, reason: collision with other inner class name */ public interface InterfaceC0196a { } public final WeakReference a() { return this.g; } public final void a(int i) { this.i = i; } public abstract void a(InterfaceC0196a interfaceC0196a); public final void a(WeakReference weakReference) { this.g = weakReference; } public final void a(JSONObject jSONObject) { this.q = jSONObject; } public final void b(int i) { this.n = i; } public final void b(Context context) { this.d = context; } public final Context c() { return this.d; } public final void c(int i) { this.r = i; } public final h d() { return this.f; } public final int f() { return this.i; } public final JSONObject i() { return this.q; } public final int j() { return this.r; } public final String b() { if (!TextUtils.isEmpty(this.l)) { return this.l; } Context context = this.d; if (context != null) { return (String) an.a(context, "sp_appKey", ""); } return null; } public final Context e() { WeakReference weakReference = this.p; if (weakReference == null) { return null; } return weakReference.get(); } public final void a(Context context) { if (context instanceof Activity) { this.p = new WeakReference<>(context); } } public final String g() { try { if (!TextUtils.isEmpty(this.e)) { return this.e; } Context context = this.d; if (context == null) { return null; } String packageName = context.getPackageName(); this.e = packageName; return packageName; } catch (Exception e) { e.printStackTrace(); return null; } } public final String h() { if (!TextUtils.isEmpty(this.m)) { return this.m; } Context context = this.d; if (context != null) { return (String) an.a(context, "sp_wx_appKey", ""); } return null; } public final void a(String str) { try { if (TextUtils.isEmpty(str)) { return; } this.m = str; Context context = this.d; if (context != null) { an.b(context, "sp_wx_appKey", str); } } catch (Exception e) { e.printStackTrace(); } } public final BitmapDrawable a(String str, int i) { ConcurrentHashMap concurrentHashMap; if (TextUtils.isEmpty(str) || (concurrentHashMap = this.o) == null || !concurrentHashMap.containsKey(str) || !ah.a().a("w_m_r_l", true)) { return null; } String str2 = this.o.get(str); BitmapDrawable n = ak.n(str2); i.a(str, i, TextUtils.isEmpty(str2) ? 2 : 1, TextUtils.isEmpty(str2) ? "get watermark failed" : n != null ? "" : "str to bitmap failed", n == null ? 2 : 1, str2); return n; } public final String k() { try { } catch (Exception e) { e.printStackTrace(); } if (!TextUtils.isEmpty(this.c)) { return this.c; } Context context = this.d; if (context != null) { return (String) an.a(context, "sp_appId", ""); } return ""; } public final void b(String str) { try { if (this.o != null && !TextUtils.isEmpty(str) && this.o.containsKey(str)) { this.o.remove(str); } } catch (Exception e) { e.printStackTrace(); } } public final void c(String str) { Context context; try { this.h = str; if (TextUtils.isEmpty(str) || (context = this.d) == null) { return; } an.b(context, "applicationIds", str); } catch (Exception e) { e.printStackTrace(); } } public final void a(String str, JSONObject jSONObject) { if (ah.a().a("w_m_r_l", true)) { try { if (this.j == null) { this.j = jSONObject; } else if (jSONObject != null) { Iterator keys = jSONObject.keys(); while (keys.hasNext()) { String next = keys.next(); this.j.put(next, jSONObject.get(next)); } } if (this.j.has(MBridgeConstans.EXTRA_KEY_WM)) { if (this.o == null) { this.o = new ConcurrentHashMap<>(); } this.o.put(str, this.j.getString(MBridgeConstans.EXTRA_KEY_WM)); } } catch (Exception e) { e.printStackTrace(); } } } public final void d(String str) { Context context; try { this.c = str; if (TextUtils.isEmpty(str) || (context = this.d) == null) { return; } an.b(context, "sp_appId", str); } catch (Exception e) { e.printStackTrace(); } } public final void e(String str) { Context context; try { this.l = str; if (TextUtils.isEmpty(str) || (context = this.d) == null) { return; } an.b(context, "sp_appKey", str); } catch (Exception e) { e.printStackTrace(); } } public final void f(String str) { if (TextUtils.isEmpty(str)) { return; } this.e = str; } public final String l() { if (!TextUtils.isEmpty(this.s)) { return this.s; } try { String md5 = SameMD5.getMD5(c.m().k() + c.m().b()); this.s = md5; return md5; } catch (Exception unused) { return ""; } } public final void a(final InterfaceC0196a interfaceC0196a, final Handler handler) { if (this.k) { return; } try { if (com.mbridge.msdk.foundation.controller.authoritycontroller.b.a() && com.mbridge.msdk.foundation.controller.authoritycontroller.c.j().c(MBridgeConstans.AUTHORITY_DEVICE_ID)) { Object a2 = an.a(this.d, MBridgeConstans.SP_GA_ID, ""); Object a3 = an.a(this.d, MBridgeConstans.SP_GA_ID_LIMIT, 0); if (a2 instanceof String) { String str = (String) a2; if (!TextUtils.isEmpty(str)) { f.a(str); } else { f.c(); } if (a3 instanceof Integer) { f.a(((Integer) a3).intValue()); } } } } catch (Exception e) { af.b(a, e.getMessage()); } try { JSONObject jSONObject = new JSONObject(); this.q = jSONObject; jSONObject.put("webgl", 0); } catch (JSONException e2) { af.b(a, e2.getMessage()); } new Thread(new Runnable() { // from class: com.mbridge.msdk.foundation.controller.a.1 @Override // java.lang.Runnable public final void run() { try { ab.p(a.this.d); a.this.a(interfaceC0196a); a aVar = a.this; com.mbridge.msdk.c.h.a(aVar.d, aVar.c); } catch (Exception e3) { af.b(a.a, e3.getMessage()); } if (com.mbridge.msdk.foundation.controller.authoritycontroller.c.j().c(MBridgeConstans.AUTHORITY_DEVICE_ID)) { try { ab.c(a.this.d.getPackageManager().getApplicationInfo("com.android.vending", 0).enabled ? 1 : 2); } catch (PackageManager.NameNotFoundException unused) { ab.c(0); } catch (Throwable th) { af.b(a.a, th.getMessage()); } } try { g b2 = com.mbridge.msdk.c.h.a().b(c.m().k()); if (b2 == null) { com.mbridge.msdk.c.h.a(); b2 = com.mbridge.msdk.c.i.a(); } Message obtain = Message.obtain(); obtain.obj = b2; obtain.what = 9; handler.sendMessage(obtain); } catch (Exception e4) { af.b(a.a, e4.getMessage()); } } }).start(); } }