Sunbit v2.4.4版本的 MD5 值为:a5021e5e2a58eb1d6741b432fe7533c4
以下内容为反编译后的 AgentWebView.java 源代码,内容仅作参考
package com.just.agentweb;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Pair;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityManager;
import android.webkit.JsPromptResult;
import android.webkit.WebBackForwardList;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.Toast;
import com.just.agentweb.m;
import com.just.agentweb.r1;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
public class AgentWebView extends WebView implements m.a, r1.a {
private static final String f5423f = AgentWebView.class.getSimpleName();
private Map<String, m0> f5424a;
private Map<String, String> b;
private b c;
private boolean f5425d;
private Boolean f5426e;
private static class b {
private WebChromeClient f5427a;
private boolean b;
private b() {
}
public void a(WebChromeClient webChromeClient) {
this.f5427a = webChromeClient;
}
public void b() {
this.b = true;
}
public void a() {
this.b = false;
}
public void a(WebView webView) {
if (this.b || this.f5427a == null) {
return;
}
WebBackForwardList webBackForwardList = null;
try {
webBackForwardList = webView.copyBackForwardList();
} catch (NullPointerException e2) {
if (v0.a()) {
e2.printStackTrace();
}
}
if (webBackForwardList == null || webBackForwardList.getSize() <= 0 || webBackForwardList.getCurrentIndex() < 0 || webBackForwardList.getItemAtIndex(webBackForwardList.getCurrentIndex()) == null) {
return;
}
this.f5427a.onReceivedTitle(webView, webBackForwardList.getItemAtIndex(webBackForwardList.getCurrentIndex()).getTitle());
}
}
public AgentWebView(Context context) {
this(context, null);
}
public static Pair<Boolean, String> a(Throwable th) {
String th2 = th.getCause() == null ? th.toString() : th.getCause().toString();
String stackTraceString = Log.getStackTraceString(th);
if (!stackTraceString.contains("android.content.pm.PackageManager$NameNotFoundException") && !stackTraceString.contains("java.lang.RuntimeException: Cannot load WebView") && !stackTraceString.contains("android.webkit.WebViewFactory$MissingWebViewPackageException: Failed to load WebView provider: No WebView installed")) {
return new Pair<>(false, th2);
}
v0.b(f5423f, "isWebViewPackageException", th);
return new Pair<>(true, "WebView load failed, " + th2);
}
private void d() {
if (getParent() instanceof ViewGroup) {
((ViewGroup) getParent()).removeAllViewsInLayout();
}
}
private void e() {
for (Map.Entry<String, String> entry : this.b.entrySet()) {
loadUrl(a(entry.getKey(), entry.getValue()));
}
}
private void f() {
for (Map.Entry<String, m0> entry : this.f5424a.entrySet()) {
loadUrl(a(entry.getKey(), entry.getValue().a()));
}
}
private boolean g() {
return ((AccessibilityManager) getContext().getSystemService("accessibility")).isEnabled();
}
private void h() {
int i2 = Build.VERSION.SDK_INT;
if (i2 < 16) {
try {
Field declaredField = WebView.class.getDeclaredField("mWebViewCore").getType().getDeclaredField("mBrowserFrame").getType().getDeclaredField("sConfigCallback");
declaredField.setAccessible(true);
declaredField.set(null, null);
} catch (IllegalAccessException e2) {
if (v0.a()) {
e2.printStackTrace();
}
} catch (NoSuchFieldException e3) {
if (v0.a()) {
e3.printStackTrace();
}
}
} else if (i2 < 19) {
try {
Field declaredField2 = Class.forName("android.webkit.BrowserFrame").getDeclaredField("sConfigCallback");
if (declaredField2 != null) {
declaredField2.setAccessible(true);
declaredField2.set(null, null);
}
} catch (ClassNotFoundException e4) {
if (v0.a()) {
e4.printStackTrace();
}
} catch (IllegalAccessException e5) {
if (v0.a()) {
e5.printStackTrace();
}
} catch (NoSuchFieldException e6) {
if (v0.a()) {
e6.printStackTrace();
}
}
}
}
private void i() {
Boolean bool = this.f5426e;
if (bool != null) {
setAccessibilityEnabled(bool.booleanValue());
}
}
private void setAccessibilityEnabled(boolean z) {
AccessibilityManager accessibilityManager = (AccessibilityManager) getContext().getSystemService("accessibility");
try {
Method declaredMethod = accessibilityManager.getClass().getDeclaredMethod("setAccessibilityState", Boolean.TYPE);
declaredMethod.setAccessible(true);
declaredMethod.invoke(accessibilityManager, Boolean.valueOf(z));
declaredMethod.setAccessible(false);
} catch (Throwable th) {
if (v0.a()) {
v0.a(f5423f, "setAccessibilityEnabled", th);
}
}
}
@Override
@Deprecated
public void addJavascriptInterface(Object obj, String str) {
if (Build.VERSION.SDK_INT >= 17) {
super.addJavascriptInterface(obj, str);
return;
}
v0.b(f5423f, "addJavascriptInterface:" + obj + " interfaceName:" + str);
if (this.f5424a == null) {
this.f5424a = new HashMap();
}
this.f5424a.put(str, new m0(obj, str));
f();
if (v0.a()) {
String str2 = "injectJavaScript, addJavascriptInterface.interfaceObj = " + obj + ", interfaceName = " + str;
}
}
public String b(String str) {
return "javascript:try{" + str + "}catch(e){console.warn(e)}";
}
@TargetApi(19)
protected void c() {
if (!v0.a() || Build.VERSION.SDK_INT < 19) {
return;
}
try {
WebView.class.getMethod("setWebContentsDebuggingEnabled", Boolean.TYPE).invoke(null, true);
} catch (Throwable th) {
if (v0.a()) {
th.printStackTrace();
}
}
}
@Override
public void clearHistory() {
if (this.f5425d) {
super.clearHistory();
}
}
@Override
public void destroy() {
setVisibility(8);
Map<String, m0> map = this.f5424a;
if (map != null) {
map.clear();
}
Map<String, String> map2 = this.b;
if (map2 != null) {
map2.clear();
}
removeAllViewsInLayout();
d();
h();
if (this.f5425d) {
i();
v0.b(f5423f, "destroy web");
super.destroy();
}
}
@Override
public boolean isPrivateBrowsingEnabled() {
if (Build.VERSION.SDK_INT == 15 && getSettings() == null) {
return false;
}
return super.isPrivateBrowsingEnabled();
}
@Override
public void setOverScrollMode(int i2) {
try {
super.setOverScrollMode(i2);
} catch (Throwable th) {
Pair<Boolean, String> a2 = a(th);
if (((Boolean) a2.first).booleanValue()) {
Toast.makeText(getContext(), (CharSequence) a2.second, 0).show();
destroy();
return;
}
throw th;
}
}
@Override
public void setWebChromeClient(WebChromeClient webChromeClient) {
this.c.a(webChromeClient);
super.setWebChromeClient(webChromeClient);
}
public AgentWebView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
b();
this.f5425d = true;
this.c = new b();
}
@Override
public void b(WebView webView, String str) {
this.c.a(webView);
if (v0.a()) {
String str2 = "onPageFinished.url = " + webView.getUrl();
}
}
protected void c(String str) {
if (Build.VERSION.SDK_INT == 16 && getSettings().getJavaScriptEnabled() && this.f5426e == null && g()) {
try {
try {
URLEncoder.encode(String.valueOf(new URI(str)), "utf-8");
} catch (IllegalArgumentException e2) {
if ("bad parameter".equals(e2.getMessage())) {
this.f5426e = true;
setAccessibilityEnabled(false);
String str2 = f5423f;
v0.b(str2, "fixedAccessibilityInjectorExceptionForOnPageFinished.url = " + str, e2);
}
}
} catch (Throwable th) {
if (v0.a()) {
v0.a(f5423f, "fixedAccessibilityInjectorExceptionForOnPageFinished", th);
}
}
}
}
public void a(String str) {
if (this.b == null) {
this.b = new HashMap();
}
this.b.put(String.valueOf(str.hashCode()), str);
e();
}
@TargetApi(11)
protected boolean b() {
try {
if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 17) {
getClass().getMethod("removeJavascriptInterface", String.class).invoke(this, "searchBoxJavaBridge_");
return true;
}
} catch (Exception e2) {
if (v0.a()) {
e2.printStackTrace();
}
}
return false;
}
public String a(String str, String str2) {
String format = String.format("__injectFlag_%1$s__", str);
return "javascript:try{(function(){if(window." + format + "){console.log('" + format + " has been injected');return;}window." + format + "=true;" + str2 + "}())}catch(e){console.warn(e)}";
}
@Override
public boolean a(WebView webView, String str, String str2, String str3, JsPromptResult jsPromptResult) {
m0 m0Var;
String str4 = "onJsPrompt:" + str + " message:" + str2 + " d:" + str3 + " ";
if (this.f5424a == null || !m0.b(str2)) {
return false;
}
q.e.i a2 = m0.a(str2);
String a3 = m0.a(a2);
if (a3 == null || (m0Var = this.f5424a.get(a3)) == null) {
return true;
}
jsPromptResult.confirm(m0Var.a(webView, a2));
return true;
}
@Override
public void a(WebView webView, String str) {
this.c.b();
}
@Override
public void a(WebView webView, int i2) {
if (this.f5424a != null) {
f();
if (v0.a()) {
String str = "injectJavaScript, onProgressChanged.newProgress = " + i2 + ", url = " + webView.getUrl();
}
}
if (this.b != null) {
e();
}
}
@Override
public void a(WebView webView, String str, Bitmap bitmap) {
if (this.f5424a != null) {
f();
if (v0.a()) {
String str2 = "injectJavaScript, onPageStarted.url = " + webView.getUrl();
}
}
if (this.b != null) {
e();
}
this.c.a();
c(str);
}
protected void a() {
if (Build.VERSION.SDK_INT == 17 && this.f5426e == null && g()) {
this.f5426e = true;
setAccessibilityEnabled(false);
}
}
}