MD5 校验值:c9acc583577d8b1a394e7959c947bec3
SafeDK.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package com.safedk.android; import android.app.Activity; import android.app.Application; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Build; import android.os.Bundle; import com.safedk.android.analytics.AppLovinBridge; import com.safedk.android.analytics.StatsCollector; import com.safedk.android.analytics.StatsReporter; import com.safedk.android.analytics.brandsafety.BannerFinder; import com.safedk.android.analytics.brandsafety.BrandSafetyUtils; import com.safedk.android.analytics.brandsafety.InterstitialFinder; import com.safedk.android.analytics.brandsafety.b; import com.safedk.android.analytics.brandsafety.creatives.CreativeInfoManager; import com.safedk.android.analytics.brandsafety.f; import com.safedk.android.analytics.brandsafety.i; import com.safedk.android.analytics.brandsafety.m; import com.safedk.android.analytics.reporters.CrashReporter; import com.safedk.android.internal.DeviceData; import com.safedk.android.internal.d; import com.safedk.android.utils.Logger; import com.safedk.android.utils.annotations.Api; import com.safedk.android.utils.h; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; import org.json.JSONObject; public class SafeDK { public static final String a = "com.safedk"; private static final String c = "SafeDKMain"; private static final String d = "SafeDK"; private static final String e = "https://config.safedk.com/"; private static final String f = "com.safedk.AppID"; private static final String g = "com.safedk.ConfigPrefix"; private static final String h = "com.safedk.APIPrefix"; private static final String i = "com.safedk.DebugMode"; private static final String j = "com.safedk.MaximumStatsSetSize"; private static final String k = "com.safedk.AggregationThreshold"; private static String n; private static String o; private static String p; private static int q; private static boolean r; private static boolean t; private static Context v; private h B; private boolean s; private DeviceData z; private static final List<String> l = Arrays.asList("com.android.vending", "com.amazon.venezia", "com.sec.android.app.samsungapps"); private static boolean m = false; private static SafeDK u = null; private static d w = new d(); private static AtomicBoolean x = new AtomicBoolean(false); private static AtomicBoolean F = new AtomicBoolean(false); private static AtomicBoolean G = new AtomicBoolean(false); private static Boolean H = false; private static Boolean I = false; private static Boolean J = false; private String y = null; private final Map<BrandSafetyUtils.AdType, b> A = new HashMap(); private AtomicBoolean C = new AtomicBoolean(false); private int D = 0; private int E = 0; com.safedk.android.analytics.brandsafety.h b = null; public static String getSdkKey() { return "vyibrKebHJJhAAA-g3rzhh_fxlQSUMWh6wRtNyXpZwvT9DINwe5ubwg_-cfChtZFTwV4n6kpF8CmsgJremtcX3"; } public static boolean a() { return t; } public static synchronized boolean b() { boolean z; synchronized (SafeDK.class) { z = x.get(); } return z; } private SafeDK(Context context) { Logger.d(c, "SafeDK ctor started"); v = context; AppLovinBridge.init(context); c(); Logger.d(c, "Before reading shared prefs"); this.z = new DeviceData(context, this.B); } public void c() { Logger.d(c, "loading config from prefs"); this.B = new h(v.getSharedPreferences("SafeDKToggles", 0), m); } private void U() { Logger.d(c, "init"); if (!m()) { Iterator<b> it = this.A.values().iterator(); while (it.hasNext()) { it.next().a((String) null); } this.A.clear(); } } private void V() { try { ApplicationInfo applicationInfo = v.getPackageManager().getApplicationInfo(v.getPackageName(), 128); if (applicationInfo.metaData != null) { a(applicationInfo); b(applicationInfo); c(applicationInfo); d(applicationInfo); } else { Logger.e(c, "SafeDK meta data is missing from manifest file"); } } catch (PackageManager.NameNotFoundException e2) { Logger.d(c, "Couldn't get application's meta data"); } } private void a(ApplicationInfo applicationInfo) { try { try { PackageInfo packageInfo = v.getPackageManager().getPackageInfo(v.getPackageName(), 0); Logger.d(c, "package is: " + packageInfo.packageName + ", Installer Package Name is " + v.getPackageManager().getInstallerPackageName(packageInfo.packageName)); t = l.contains(v.getPackageManager().getInstallerPackageName(packageInfo.packageName)); r = (applicationInfo.flags & 2) != 0; p = extractAppIdentifier(applicationInfo.metaData); Uri.Builder appendQueryParameter = new Uri.Builder().appendPath("apps").appendPath("cfg").appendPath(p).appendPath(String.valueOf(packageInfo.versionCode)).appendQueryParameter("store", String.valueOf(t)); if (t) { appendQueryParameter = appendQueryParameter.appendQueryParameter("versionName", packageInfo.versionName); } String uri = appendQueryParameter.build().toString(); o = extractUrlPrefix(applicationInfo.metaData); if (o != null && o.length() > 0) { Logger.d(c, "apiURL Value from manifest is " + o + ". Setting new edge urls"); AppLovinBridge.receiveEdgeUrls(o, o); } else { Logger.d(c, "no apiURL Value in manifest"); } q = packageInfo.versionCode; String string = applicationInfo.metaData.getString(g); if (string == null) { n = getDefaultConfig() + uri; return; } if (!string.endsWith(File.separator)) { string = string + File.separator; } if (uri.startsWith(File.separator)) { uri = uri.substring(1); } n = string + uri; Logger.d(c, "basePrefix != null, configUrl:" + n); } catch (PackageManager.NameNotFoundException e2) { Logger.d(c, "Bad URL; won't update toggles"); } } catch (Throwable th) { Logger.e(c, "Caught exception", th); new CrashReporter().caughtException(th); } } private static String extractAppIdentifier(Bundle metaData) { return metaData.getString(f); } private static String extractUrlPrefix(Bundle metaData) { return metaData.getString(h, "https://edge.safedk.com"); } private static String getDefaultConfig() { return e; } public static String getProguardMD5() { return ""; } private void b(ApplicationInfo applicationInfo) { boolean z = false; if (w.v() && (applicationInfo.metaData.getBoolean(i, false) || Z())) { z = true; } Logger.setDebugMode(z); } private void c(ApplicationInfo applicationInfo) { w.a(applicationInfo.metaData.getInt(j, d.b)); } private void d(ApplicationInfo applicationInfo) { w.b(applicationInfo.metaData.getInt(k, d.c)); } private void W() { this.y = UUID.randomUUID().toString(); this.B.a(this.y); } public static synchronized SafeDK a(Context context) { SafeDK safeDK; synchronized (SafeDK.class) { Logger.d(c, "start started"); if (u == null) { u = new SafeDK(context); u.a(false); if (w.v()) { Logger.i("SafeDK", "SafeDK Device ID: " + u.y); Logger.i("SafeDK", "SafeDK version: " + getVersion()); } u.b(true); } else { Logger.d(c, "SafeDK already started"); } safeDK = u; } return safeDK; } public static void a(Application application) { if (getInstance().k() && Build.VERSION.SDK_INT >= 14) { application.registerActivityLifecycleCallbacks(com.safedk.android.internal.b.getInstance()); } } private void X() { try { Logger.d(c, "setIsFirstSession started"); if (!G.get()) { String p2 = this.B.p(); Logger.d(c, "setIsFirstSession Current safedk version : 4.8.3 , stored version is " + p2); if (p2 == null || !a.a.equals(p2)) { Logger.d(c, "setIsFirstSession setting is_first_session to true"); this.s = true; } this.B.c(a.a); G.set(true); return; } Logger.d(c, "setIsFirstSession already executed, value is " + this.s); } catch (Throwable th) { Logger.d(c, "setIsFirstSession Exception : " + th.getMessage(), th); } } public boolean d() { return this.s; } public static SafeDK getInstance() { return u; } public int e() { return w.a(); } public boolean f() { return w.b(); } private void a(boolean z, boolean z2) { try { if (u == null) { Logger.d(c, "instance is null, existing"); return; } u.b(false); if (!w.v()) { Logger.d(c, "SafeDK is disabled."); Logger.setDebugMode(false); com.safedk.android.internal.b.getInstance().clearBackgroundForegroundListeners(); return; } V(); if (Z()) { Logger.setDebugMode(true); } Logger.d(c, "Configuration download completed, configurationDownloadedSuccessfully=" + z); Logger.d(c, "configurationDownloadCompleted isMaxProcess " + z2); Logger.d(c, "configurationDownloadCompleted isActive " + w.v() + ", packageId = " + getInstance().h().getPackageName()); if (w.v() && z2 && !F.get()) { F.set(true); CreativeInfoManager.e(); Y(); if (z) { Logger.d(c, "Will attempt to load events from storage"); StatsCollector.c().d(); } else { X(); } X(); Logger.d(c, "Loading singletons"); f.a(); i.a(); if (this.b == null) { this.b = com.safedk.android.analytics.brandsafety.h.a(); } if (!this.A.containsKey(BrandSafetyUtils.AdType.INTERSTITIAL)) { this.A.put(BrandSafetyUtils.AdType.INTERSTITIAL, new InterstitialFinder()); } if (!this.A.containsKey(BrandSafetyUtils.AdType.BANNER) && l()) { this.A.put(BrandSafetyUtils.AdType.BANNER, new BannerFinder()); } if (!this.A.containsKey(BrandSafetyUtils.AdType.MREC) && l()) { this.A.put(BrandSafetyUtils.AdType.MREC, new m()); } } this.C.set(true); } catch (Throwable th) { Logger.e(c, "Exception handling configuration event", th); new CrashReporter().caughtException(th); } } private static void Y() { if (!x.get()) { Logger.d(c, "Starting reporter thread"); StatsCollector.a(true); int x2 = w.x(); int A = w.A(); StatsReporter.a(); StatsCollector.c().a(x2, com.safedk.android.internal.b.getInstance().isInBackground(), A, StatsReporter.b()); StatsCollector.a(false); StatsCollector.b(getInstance().m()); x.set(true); Logger.d(c, "Reporter thread started"); return; } Logger.d(c, "Reporter thread already initialized, skipping"); } public void a(Bundle bundle, boolean z) { Logger.d(c, "Updating configuration"); boolean a2 = w.a(bundle, true); if (a2) { a(bundle); } a(a2, z); } private void a(Bundle bundle) { Logger.d(c, "Writing to shared preferences: " + bundle.toString()); this.B.a(bundle); } public static int g() { return q; } public Context h() { return v; } public boolean i() { return w.w() || Z(); } public boolean j() { return r; } public boolean k() { return w.v(); } public boolean l() { return w.r(); } public boolean m() { return !n() && w.v(); } public boolean n() { return this.B.b(); } private boolean Z() { try { Set<String> E = w.E(); if (!E.contains("*")) { if (!E.contains(this.y)) { return false; } } return true; } catch (Throwable th) { Logger.e(c, "Caught exception", th); new CrashReporter().caughtException(th); return false; } } public static boolean o() { return w.z(); } public List<String> p() { return w.s(); } public List<String> q() { return w.t(); } public DeviceData r() { return this.z; } public Map<BrandSafetyUtils.AdType, b> s() { return this.A; } public com.safedk.android.analytics.brandsafety.a a(BrandSafetyUtils.AdType adType) { return this.A.get(adType); } public InterstitialFinder t() { return (InterstitialFinder) a(BrandSafetyUtils.AdType.INTERSTITIAL); } public BannerFinder u() { return (BannerFinder) a(BrandSafetyUtils.AdType.BANNER); } public m v() { return (m) a(BrandSafetyUtils.AdType.MREC); } public int w() { return this.E; } public int x() { return this.D; } public int a(String str) { int c2; if (str.equals(com.safedk.android.utils.f.h)) { c2 = 16384; } else { c2 = w.c(); } Logger.d(c, "getMinValidImageSize sdkPackage=" + str + ", result = " + c2); return c2; } public int y() { return w.d(); } public float z() { return w.e(); } public float A() { return w.f(); } public boolean B() { return w.g(); } public int C() { return w.h(); } public long D() { return w.i(); } public int E() { return w.j(); } public int F() { return w.k(); } public int G() { return w.l(); } public void a(boolean z) { Logger.d(c, "Reading configuration from shared preferences"); try { this.y = this.B.a(); if (this.y == null) { W(); } Bundle e2 = this.B.e(); Logger.d(c, "configurationBundle loaded : " + e2.toString()); if (e2 != null && !e2.isEmpty()) { Logger.d(c, "Parsing configuration from shared preferences"); w.a(e2, false); } else { Logger.d(c, "Configuration bundle from storage is empty"); } a(false, z); } catch (Throwable th) { Logger.e(c, "Caught exception", th); new CrashReporter().caughtException(th); } } public synchronized void a(Activity activity) { Logger.d(c, "Starting interstitial finder in activity " + activity.getClass().getName()); InterstitialFinder interstitialFinder = (InterstitialFinder) a(BrandSafetyUtils.AdType.INTERSTITIAL); if (interstitialFinder != null) { interstitialFinder.a(activity); } } public synchronized void b(Activity activity) { Logger.d(c, "Stopping interstitial finder in activity " + activity.getClass().getName()); InterstitialFinder interstitialFinder = (InterstitialFinder) a(BrandSafetyUtils.AdType.INTERSTITIAL); if (interstitialFinder != null) { interstitialFinder.c(activity); } } public synchronized void b(String str) { InterstitialFinder interstitialFinder = (InterstitialFinder) a(BrandSafetyUtils.AdType.INTERSTITIAL); if (interstitialFinder != null) { interstitialFinder.i(str); } } public synchronized void c(Activity activity) { if (k()) { Logger.d(c, "onForegroundActivity " + activity.getClass().getName()); } } public synchronized void d(Activity activity) { if (k()) { Logger.d(c, "onBackgroundActivity " + activity.getClass().getName()); } } public String c(String str) { JSONObject jSONObject; String str2 = null; Logger.d(c, "getSdkVersion getSdkVersion: " + str); JSONObject j2 = this.B.j(); if (j2 != null) { Logger.d(c, "getSdkVersion sdkVersionsJson=" + j2.toString()); } try { jSONObject = j2.getJSONObject(str); } catch (Throwable th) { } if (jSONObject == null) { Logger.d(c, "getSdkVersion sdkData is null"); return str2; } Logger.d(c, "getSdkVersion sdkData : " + jSONObject.toString()); str2 = jSONObject.getString("sdk_version"); Logger.d(c, "getSdkVersion version : " + str2); Logger.d(c, "return sdk version: " + str2); return str2; } public JSONObject H() { return this.B.j(); } @Api public String getUserId() { return this.y; } public static String getVersion() { return a.a; } public static boolean I() { return a.a.contains("rc"); } private void b(boolean z) { boolean m2 = m(); Logger.d(c, "notifyMonitorUserActivityUpdate shouldMonitorUser is " + m2); CreativeInfoManager.a(m2); com.safedk.android.internal.b.setActiveMode(m2); com.safedk.android.analytics.brandsafety.h.a(m2); if (z) { U(); } } public long J() { return w.H(); } public int K() { return w.I(); } public int L() { return w.J(); } public ArrayList<String> M() { return w.K(); } public float N() { return w.m(); } public float O() { return w.n(); } public int P() { return w.o(); } public int Q() { return w.p(); } public int R() { return w.q(); } public static boolean S() { return H.booleanValue(); } public static void T() { H = true; if (!b()) { Y(); } if (!I.booleanValue()) { CreativeInfoManager.b(); I = true; } } }