Puzzle King v2.3.8版本的 MD5 值为:1734eb975c9d2843afa462aec387292e
以下内容为反编译后的 h.java 源代码,内容仅作参考
package com.safedk.android.analytics.brandsafety;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.webkit.RenderProcessGoneDetail;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.mbridge.msdk.playercommon.exoplayer2.C;
import com.mbridge.msdk.playercommon.exoplayer2.source.chunk.ChunkedTrackBlacklistUtil;
import com.safedk.android.SafeDK;
import com.safedk.android.analytics.reporters.CrashReporter;
import com.safedk.android.utils.Logger;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
public class h implements com.safedk.android.internal.a {
private static final String a = "ClickUrlsManager";
private static final int b = 2;
private static final String c = "original_url";
private static final String d = "resolved_url";
private static final String e = "fingerprint";
private static final String f = "package";
private static final String g = "https://play.google.com/store/apps/details?id=%s";
private static h h;
private static final Object n = new Object();
private static AtomicBoolean o = new AtomicBoolean();
private static final ScheduledExecutorService p = Executors.newScheduledThreadPool(0);
private String i = null;
private String j = null;
private AtomicBoolean l = new AtomicBoolean(false);
private AtomicInteger m = new AtomicInteger(0);
private Set<String> k = new HashSet();
private h() {
com.safedk.android.internal.b.getInstance().registerBackgroundForegroundListener(this);
}
public static h a() {
h hVar;
synchronized (n) {
if (h == null) {
h = new h();
}
hVar = h;
}
return hVar;
}
public static void a(boolean z) {
synchronized (n) {
Logger.d(a, "setActiveMode to " + z);
h = null;
}
}
public synchronized void b(String str, String str2) {
if (this.i == null && !this.k.contains(str)) {
Logger.d(a, "logging url: " + str + ", fingerprint: " + str2);
this.i = str;
this.j = str2;
if (TextUtils.isEmpty(this.j)) {
this.j = str;
}
}
}
public static String a(String str) {
return com.safedk.android.utils.k.t(str) ? com.safedk.android.utils.k.v(str) : b(str);
}
public static String b(String str) {
try {
URI uri = new URI(URLEncoder.encode(str, C.UTF8_NAME));
String query = uri.getQuery();
if (!TextUtils.isEmpty(query)) {
String str2 = "";
String[] split = query.split("&");
for (String str3 : split) {
if (!com.safedk.android.utils.f.K().matcher(str3).find()) {
if (str2.length() > 0) {
str2 = str2 + "&";
}
str2 = str2 + str3;
}
}
return new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), str2, uri.getFragment()).toString();
}
return str;
} catch (Throwable th) {
Logger.w(a, "Unable to clean url: " + th.getMessage());
return str;
}
}
public static String c(String str) {
return String.format(Locale.ENGLISH, g, str);
}
public synchronized String b() {
return this.j;
}
@Override
public synchronized void g() {
o.set(true);
}
@Override
public synchronized void h() {
String str;
String str2;
Logger.d(a, "onForeground started");
o.set(false);
if (this.l.get()) {
if (this.m.getAndIncrement() <= 2) {
synchronized (h) {
if (this.i != null) {
String str3 = this.i;
str = this.j;
str2 = str3;
} else {
str = null;
str2 = null;
}
}
d(str2, str);
} else {
Logger.d(a, "Exhausted2 attempts to resolve URL. Clearing the slot.");
d();
}
}
}
private void d() {
synchronized (h) {
if (this.i != null) {
String str = this.i;
this.i = null;
this.j = null;
this.k.add(str);
this.l.set(false);
this.m.set(0);
}
}
}
private void c(String str, String str2) {
if (str != null) {
try {
com.safedk.android.a.e eVar = new com.safedk.android.a.e(new URL(str).openConnection());
eVar.c(true);
eVar.a(SafeDK.getInstance().K());
eVar.b();
URL c2 = eVar.c();
a(str, c2 != null ? c2.toString() : null, str2, false);
} catch (MalformedURLException e2) {
Logger.d(a, "Malformed URL", e2);
} catch (IOException e3) {
Logger.d(a, "Error opening connection", e3);
} catch (Throwable th) {
Logger.d(a, "Throwable Error opening connection", th);
}
}
}
public void a(String str, final String str2) {
Logger.d(a, "resolve Url started, url = " + str + ", fingerprint = " + str2);
final String B = com.safedk.android.utils.k.B(str);
if (com.safedk.android.utils.k.t(B)) {
a(B, com.safedk.android.utils.k.u(B), str2, false);
} else {
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
if (h.o.get()) {
h.this.b(B, str2);
h.this.l.set(true);
Logger.d(h.a, "server asked to resolve but currently in background.");
} else {
Logger.d(h.a, "not currently in background, try to resolve.");
h.this.d(B, str2);
}
}
}, 500L);
}
}
public void d(String str, String str2) {
Logger.d(a, "resolveUrlInternal starting Url resolution. url = " + str);
final AtomicBoolean atomicBoolean = new AtomicBoolean(false);
final WebView webView = new WebView(SafeDK.getInstance().l());
Runnable runnable = new Runnable() {
@Override
public void run() {
if (atomicBoolean.get()) {
Logger.d(h.a, "Url resolved. no timeout.");
} else {
webView.post(new Runnable() {
@Override
public void run() {
Logger.d(h.a, "Timeout resolving url");
webView.stopLoading();
}
});
}
}
};
AtomicLong atomicLong = new AtomicLong(0L);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new AnonymousClass3(str, atomicBoolean, str2));
atomicLong.set(System.currentTimeMillis());
webView.loadUrl(str);
Logger.d(a, "Starting resolution, timeout = " + SafeDK.getInstance().K());
p.schedule(runnable, SafeDK.getInstance().K(), TimeUnit.MILLISECONDS);
}
public class AnonymousClass3 extends WebViewClient {
AtomicInteger a = new AtomicInteger(0);
final String b;
final AtomicBoolean c;
final String d;
AnonymousClass3(String str, AtomicBoolean atomicBoolean, String str2) {
this.b = str;
this.c = atomicBoolean;
this.d = str2;
}
@Override
public void onPageStarted(WebView view, final String url, Bitmap favicon) {
final int incrementAndGet = this.a.incrementAndGet();
Logger.d(h.a, "onPageStarted started. callbackCounter=" + incrementAndGet + ", url= " + url);
if (!url.equals(this.b)) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (AnonymousClass3.this.a.get() == incrementAndGet) {
Logger.d(h.a, "onPageFinished never called, assuming last onPageStarted is the landing page.");
Logger.d(h.a, "Landing page detected: " + url);
AnonymousClass3.this.c.set(true);
h.this.a(AnonymousClass3.this.b, url, AnonymousClass3.this.d, true);
return;
}
Logger.d(h.a, "onPageStarted resolveCounter.get() is not equal to callbackCounter. resolveCounter.get()=" + AnonymousClass3.this.a.get() + ", callbackCounter=" + incrementAndGet);
}
}, ChunkedTrackBlacklistUtil.DEFAULT_TRACK_BLACKLIST_MS);
}
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, final String url) {
final int incrementAndGet = this.a.incrementAndGet();
Logger.d(h.a, "onPageFinished started. callbackCounter=" + incrementAndGet + ", url= " + url);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (AnonymousClass3.this.a.get() == incrementAndGet) {
Logger.d(h.a, "Landing page detected: " + url);
AnonymousClass3.this.c.set(true);
h.this.a(AnonymousClass3.this.b, url, AnonymousClass3.this.d, true);
return;
}
Logger.d(h.a, "onPageFinished resolveCounter.get() is not equal to callbackCounter. resolveCounter.get()=" + AnonymousClass3.this.a.get() + ", callbackCounter=" + incrementAndGet);
}
}, 5000L);
super.onPageFinished(view, url);
}
public boolean a(WebView webView, RenderProcessGoneDetail renderProcessGoneDetail) {
Logger.d(h.a, "onRenderProcessGone for view = " + webView.toString());
this.c.set(true);
return true;
}
}
public void a(String str, String str2, String str3, boolean z) {
try {
Logger.d(a, "reportResolvedUrlToServer started. originalUrl=" + str + ", resolvedUrl=" + str2 + ", fingerprint=" + str3);
d();
if (z && com.safedk.android.utils.k.t(str2)) {
str2 = com.safedk.android.utils.k.u(a(str2));
}
Bundle bundle = new Bundle();
bundle.putString(c, str);
bundle.putString(d, str2);
bundle.putString("fingerprint", str3);
bundle.putString("package", SafeDK.getInstance().l().getPackageName());
f.b(bundle);
} catch (Throwable th) {
Logger.d(a, "Failed to report url resolve to server");
new CrashReporter().caughtException(th);
}
}
}