package com.zj.zjsdk.a; import android.content.Context; import android.content.Intent; import android.util.Pair; import com.mbridge.msdk.foundation.same.report.e; import com.zj.zjsdk.ZjSdk; import com.zj.zjsdk.activity.IBaseActivityLifeCycle; import com.zj.zjsdk.activity.ZjCompatExtActivity; import com.zj.zjsdk.api.AdApi; import com.zj.zjsdk.utils.SPUtil; import com.zj.zjsdk.utils.b; import com.zj.zmmkv.ZMMKV; import dalvik.system.DexClassLoader; import java.io.File; public enum a { INSTANCE; public static final int b = 2040700; private static final String c = "Zcaaaa2da1f400981J.jar"; private DexClassLoader d = null; private AdApi e; private a() { } private void a(Context context) { String a = com.zj.zjsdk.utils.a.a(context); Pair<Integer, String> c2 = c(context); int intValue = ((Integer) c2.first).intValue(); String str = (String) c2.second; b.c("test", "sdk:2040700, curr:" + intValue); if (2040700 < intValue) { String str2 = a + File.separator + str; if (new File(str2).exists()) { try { this.d = new DexClassLoader(str2, a, null, context.getClassLoader()); return; } catch (Throwable th) { th.printStackTrace(); } } } String str3 = a + File.separator + c; File file = new File(str3); try { if (!file.exists()) { file.createNewFile(); com.zj.zjsdk.utils.a.a(context, c, file); b(context); } } catch (Throwable th2) { th2.printStackTrace(); b.c("ZJSdk", "load plug error"); } try { this.d = new DexClassLoader(str3, a, null, context.getClassLoader()); } catch (Throwable th3) { th3.printStackTrace(); try { Class.forName("android.util.Log").getDeclaredMethod(e.a, String.class, String.class).invoke(null, "ZjSdk", "on load plug file error: " + th3); } catch (Throwable th4) { th4.printStackTrace(); } } } private void b(Context context) { if (ZMMKV.IS_VALID) { ZMMKV.defaultMMKV().encode("plug_ver", b); ZMMKV.defaultMMKV().encode("plug_name", c); return; } SPUtil.instance(context).setIntValueWhitKey("plug_ver", b); SPUtil.instance(context).setStringValue("plug_name", c); } private Pair<Integer, String> c(Context context) { int i; String str; if (ZMMKV.IS_VALID) { i = ZMMKV.defaultMMKV().decodeInt("plug_ver", b); str = ZMMKV.defaultMMKV().decodeString("plug_name", c); } else { int intValueWhitKey = SPUtil.instance(context).getIntValueWhitKey("plug_ver", b); str = SPUtil.instance(context).getStringValue("plug_name", c); i = intValueWhitKey; } return new Pair<>(Integer.valueOf(i), str); } public AdApi a() { if (this.e == null) { synchronized (this) { try { Object newInstance = this.d.loadClass("com.zj.zjsdkplug.Api").newInstance(); if (newInstance instanceof AdApi) { this.e = (AdApi) newInstance; } else { b.e("ZJSdk", "instance of '" + newInstance.getClass().getName() + "' not support."); } } catch (Throwable th) { th.printStackTrace(); } } } return this.e; } public void a(Context context, String str) { AdApi adApi = this.e; if (adApi != null) { try { adApi.setUserId(context, str); } catch (Throwable th) { th.printStackTrace(); } } } public void a(Context context, String str, ZjSdk.ZjSdkInitListener zjSdkInitListener) { try { if (this.d == null) { a(context); } a().init(context, str, zjSdkInitListener); } catch (Throwable th) { th.printStackTrace(); b.e("ZJSdk", "startInit.e=" + th); if (zjSdkInitListener != null) { zjSdkInitListener.initFail(); } } } public void a(Context context, String str, String str2) { Intent intent = new Intent(context, ZjCompatExtActivity.class); intent.putExtra(IBaseActivityLifeCycle.TAG_CLASS_NAME, str); if (str2 != null) { intent.putExtra(IBaseActivityLifeCycle.TAG_THEME_RES_NAME, str2); } context.startActivity(intent); } public void a(Context context, boolean z) { if (this.e == null && context != null) { a(context); a(); } AdApi adApi = this.e; if (adApi != null) { try { adApi.isDebug(z); } catch (Throwable th) { th.printStackTrace(); } } } public boolean a(int i) { AdApi adApi = this.e; if (adApi == null) { return false; } try { return adApi.setPersonalizedState(i); } catch (Throwable th) { th.printStackTrace(); return false; } } public ClassLoader b() { return this.d; } public void b(Context context, String str) { a(context, str, (String) null); } }