Aqara Home v2.4.1版本的 MD5 值为:529779ac2bc0131db52a1fc3098d2b35
以下内容为反编译后的 BaseWebView.java 源代码,内容仅作参考
package com.lumiunited.aqara.common.ui.webView;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.webkit.GeolocationPermissions;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import anet.channel.util.HttpConstant;
import com.google.android.material.badge.BadgeDrawable;
import com.lumiunited.aqara.common.ui.webView.BaseWebView;
import com.lumiunited.aqarahome.R;
import com.sensorsdata.analytics.android.sdk.SensorsDataAPI;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URLDecoder;
import k.u.c.d.a.t;
import k.u.c.f.a.l0.l;
import k.u.c.f.a.q.y0;
import p.a.k0;
import p.a.m0;
import p.a.o0;
import p.a.x0.g;
public class BaseWebView extends WebView {
public static final String f9870m = "http://192.168.5.144:8085/#/messageCenter?userId=0fbed49bc76c33ec.6717435826049770&token=4061b0822564055957132100545efb77&language=zh-CN";
public boolean a;
public JsPromptResult b;
public boolean c;
public String d;
public boolean f9871e;
public l f9872f;
public d f9873g;
public boolean f9874h;
public ValueCallback<String> f9875i;
public boolean f9876j;
public String f9877k;
public y0 f9878l;
public class a implements l {
public a() {
}
@Override
public void A(int i2) {
}
@Override
public void R0() {
}
@Override
public void Z0() {
}
@Override
public void a(ValueCallback<Uri[]> valueCallback, WebChromeClient.FileChooserParams fileChooserParams) {
}
@Override
public void a(String str, GeolocationPermissions.Callback callback) {
}
@Override
public void d(String str, String str2) {
}
@Override
public void f(int i2, String str) {
}
@Override
public void setTitle(String str) {
}
}
public class b implements ValueCallback<String> {
public b() {
}
@Override
public void onReceiveValue(String str) {
}
}
public class c extends WebViewClient {
public c() {
}
@Override
public void onPageFinished(WebView webView, String str) {
super.onPageFinished(webView, str);
l lVar = BaseWebView.this.f9872f;
if (lVar != null) {
lVar.R0();
}
BaseWebView baseWebView = BaseWebView.this;
if (baseWebView.a) {
baseWebView.setLayerType(0, null);
}
}
@Override
public void onReceivedError(WebView webView, int i2, String str, String str2) {
super.onReceivedError(webView, i2, str, str2);
if (str.contains("ERR_INTERNET_DISCONNECTED")) {
i2 = 20;
}
BaseWebView.this.f9872f.f(i2, str);
}
@Override
public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
BaseWebView.this.d = webResourceRequest.getUrl().toString();
if (BaseWebView.this.d.contains(".pdf") && BaseWebView.this.e()) {
try {
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(BaseWebView.this.d));
intent.setFlags(805306368);
BaseWebView.this.getContext().startActivity(intent);
return true;
} catch (Exception e2) {
e2.printStackTrace();
return false;
}
}
return super.shouldOverrideUrlLoading(webView, webResourceRequest);
}
}
public class d extends WebChromeClient {
public Context a;
public d(Context context) {
this.a = context;
}
public void a(JsResult jsResult, View view) {
jsResult.cancel();
BaseWebView.this.f9878l.dismiss();
}
public void b(JsResult jsResult, View view) {
jsResult.confirm();
BaseWebView.this.f9878l.dismiss();
}
@Override
public void onGeolocationPermissionsShowPrompt(String str, GeolocationPermissions.Callback callback) {
super.onGeolocationPermissionsShowPrompt(str, callback);
l lVar = BaseWebView.this.f9872f;
if (lVar != null) {
lVar.a(str, callback);
}
}
@Override
public boolean onJsAlert(WebView webView, String str, String str2, final JsResult jsResult) {
BaseWebView.this.f9878l = new y0.c(this.a).d(this.a.getString(R.string.tips)).a(str2).b(this.a.getString(R.string.confirm), new View.OnClickListener() {
@Override
public final void onClick(View view) {
jsResult.confirm();
}
}).a(false).a();
BaseWebView.this.f9878l.show();
return true;
}
@Override
public boolean onJsConfirm(WebView webView, String str, String str2, final JsResult jsResult) {
BaseWebView.this.f9878l = new y0.c(this.a).d(this.a.getString(R.string.tips)).a(str2).a(this.a.getString(R.string.cancel), new View.OnClickListener() {
@Override
public final void onClick(View view) {
BaseWebView.d.this.a(jsResult, view);
}
}).c(this.a.getString(R.string.confirm), new View.OnClickListener() {
@Override
public final void onClick(View view) {
BaseWebView.d.this.b(jsResult, view);
}
}).a(false).a();
BaseWebView.this.f9878l.show();
return true;
}
@Override
public boolean onJsPrompt(WebView webView, String str, String str2, String str3, JsPromptResult jsPromptResult) {
char c;
String lowerCase = str2.toLowerCase();
int hashCode = lowerCase.hashCode();
if (hashCode == -1097519099) {
if (lowerCase.equals("loaded")) {
c = 2;
}
c = 65535;
} else if (hashCode != 106642994) {
if (hashCode == 110371416 && lowerCase.equals("title")) {
c = 1;
}
c = 65535;
} else {
if (lowerCase.equals("photo")) {
c = 0;
}
c = 65535;
}
if (c == 0) {
jsPromptResult.confirm(null);
} else if (c == 1) {
jsPromptResult.confirm(null);
l lVar = BaseWebView.this.f9872f;
if (lVar != null) {
lVar.setTitle(str3);
return true;
}
} else if (c != 2) {
jsPromptResult.confirm(null);
} else {
jsPromptResult.confirm(null);
}
l lVar2 = BaseWebView.this.f9872f;
if (lVar2 != null) {
lVar2.d(str2, str3);
}
return true;
}
@Override
public void onProgressChanged(WebView webView, int i2) {
super.onProgressChanged(webView, i2);
BaseWebView.this.f9872f.A(i2);
}
@Override
public void onReceivedTitle(WebView webView, String str) {
l lVar;
super.onReceivedTitle(webView, str);
if (!TextUtils.isEmpty(str) && str.toLowerCase().contains("error")) {
BaseWebView.this.f9872f.f(20, t.f21896o);
} else if (TextUtils.isEmpty(str) || str.contains(HttpConstant.SCHEME_SPLIT) || !BaseWebView.this.c || (lVar = BaseWebView.this.f9872f) == null) {
} else {
lVar.setTitle(str);
}
}
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> valueCallback, WebChromeClient.FileChooserParams fileChooserParams) {
l lVar = BaseWebView.this.f9872f;
if (lVar != null) {
lVar.a(valueCallback, fileChooserParams);
return true;
}
return true;
}
}
public BaseWebView(Context context) {
super(a(context));
this.a = false;
this.c = false;
this.d = "";
this.f9871e = false;
this.f9872f = new a();
this.f9875i = new b();
this.f9876j = true;
b(a(context));
}
private void b(Context context) {
getSettings().setJavaScriptEnabled(true);
getSettings().setDomStorageEnabled(true);
getSettings().setSupportMultipleWindows(false);
getSettings().setLoadWithOverviewMode(true);
getSettings().setCacheMode(2);
getSettings().setUseWideViewPort(true);
getSettings().setBuiltInZoomControls(true);
getSettings().setBlockNetworkImage(false);
getSettings().setCacheMode(-1);
getSettings().setGeolocationEnabled(true);
if (Build.VERSION.SDK_INT >= 21) {
getSettings().setMixedContentMode(0);
}
boolean z2 = this.f9876j;
if (!z2) {
setScrollContainer(z2);
setVerticalScrollBarEnabled(this.f9876j);
setHorizontalScrollBarEnabled(this.f9876j);
}
d dVar = new d(context);
this.f9873g = dVar;
setWebChromeClient(dVar);
setWebViewClient(new c());
SensorsDataAPI.sharedInstance().showUpWebView(this, false);
if (Build.VERSION.SDK_INT >= 19) {
WebView.setWebContentsDebuggingEnabled(true);
}
String str = this.f9877k;
if (str != null) {
loadUrl(str);
}
l lVar = this.f9872f;
if (lVar != null) {
lVar.Z0();
}
}
private void f(String str) {
File file = new File(str);
if (file.exists()) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(str, options);
options.inJustDecodeBounds = false;
long j2 = 2457600;
if (file.length() > j2) {
double length = file.length() / j2;
int i2 = (length > 1.0d ? 1 : (length == 1.0d ? 0 : -1));
int i3 = options.outWidth;
if (i2 > 0) {
i3 = (int) (i3 / length);
}
options.outWidth = i3;
options.outHeight = i2 > 0 ? (int) (options.outHeight / length) : options.outHeight;
}
Bitmap decodeFile = BitmapFactory.decodeFile(str, options);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
try {
try {
decodeFile.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
this.b.confirm(k.u.c.d.j.l.a(byteArray, 0, byteArray.length));
this.b = null;
byteArrayOutputStream.close();
} catch (Exception e2) {
e2.printStackTrace();
byteArrayOutputStream.close();
}
} catch (IOException e3) {
e3.printStackTrace();
}
} catch (Throwable th) {
try {
byteArrayOutputStream.close();
} catch (IOException e4) {
e4.printStackTrace();
}
throw th;
}
}
}
public String c() {
return "";
}
public void c(String str) {
loadUrl(String.format("javascript: {0}", str));
}
public boolean d(String str) {
if (getUrl() == null) {
return false;
}
if (getUrl().equals(str)) {
return true;
}
return URLDecoder.decode(getUrl()).equals(str);
}
public void e(String str) throws Exception {
loadUrl("javascript:" + str);
}
public l getWebCallBack() {
return this.f9872f;
}
@Override
public void loadUrl(String str) {
if (str.contains(BadgeDrawable.DEFAULT_EXCEED_MAX_BADGE_NUMBER_SUFFIX)) {
str = str.replaceAll("\\+", "%2B");
}
super.loadUrl(str);
}
public void setCanGetWebTitle(boolean z2) {
this.c = z2;
}
public void setOpenInOtherWebClient(boolean z2) {
this.f9871e = z2;
}
public void setSoftwareFirst(boolean z2) {
this.a = z2;
if (z2) {
setLayerType(1, null);
}
}
public void setWebCallBack(l lVar) {
this.f9872f = lVar;
}
public static Context a(Context context) {
int i2 = Build.VERSION.SDK_INT;
return (i2 < 21 || i2 >= 23) ? context : context.createConfigurationContext(new Configuration());
}
public boolean e() {
return this.f9871e;
}
public void a() {
boolean canGoBack = canGoBack();
this.f9874h = canGoBack;
if (canGoBack) {
goBack();
}
}
public boolean d() {
return this.c;
}
public void a(String str) {
if (TextUtils.isEmpty(str) || !isAttachedToWindow()) {
return;
}
evaluateJavascript(str, this.f9875i);
}
public void a(m0 m0Var) throws Exception {
ByteArrayOutputStream byteArrayOutputStream;
InputStream inputStream = null;
try {
try {
try {
InputStream open = getContext().getAssets().open("inject_js_sdk.js");
try {
byte[] bArr = new byte[1024];
byteArrayOutputStream = new ByteArrayOutputStream();
while (true) {
try {
int read = open.read(bArr);
if (read == -1) {
break;
}
byteArrayOutputStream.write(bArr, 0, read);
} catch (MalformedURLException e2) {
e = e2;
inputStream = open;
e.printStackTrace();
if (inputStream != null) {
inputStream.close();
}
if (byteArrayOutputStream != null) {
byteArrayOutputStream.close();
}
return;
} catch (IOException e3) {
e = e3;
inputStream = open;
e.printStackTrace();
if (inputStream != null) {
inputStream.close();
}
if (byteArrayOutputStream != null) {
byteArrayOutputStream.close();
}
return;
} catch (Throwable th) {
th = th;
inputStream = open;
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e4) {
e4.printStackTrace();
throw th;
}
}
if (byteArrayOutputStream != null) {
byteArrayOutputStream.close();
}
throw th;
}
}
m0Var.onSuccess("javascript:" + byteArrayOutputStream.toString());
if (open != null) {
open.close();
}
byteArrayOutputStream.close();
} catch (MalformedURLException e5) {
e = e5;
byteArrayOutputStream = null;
} catch (IOException e6) {
e = e6;
byteArrayOutputStream = null;
} catch (Throwable th2) {
th = th2;
byteArrayOutputStream = null;
}
} catch (Throwable th3) {
th = th3;
}
} catch (MalformedURLException e7) {
e = e7;
byteArrayOutputStream = null;
} catch (IOException e8) {
e = e8;
byteArrayOutputStream = null;
} catch (Throwable th4) {
th = th4;
byteArrayOutputStream = null;
}
} catch (IOException e9) {
e9.printStackTrace();
}
}
public BaseWebView(Context context, AttributeSet attributeSet) {
super(a(context), attributeSet);
this.a = false;
this.c = false;
this.d = "";
this.f9871e = false;
this.f9872f = new a();
this.f9875i = new b();
this.f9876j = true;
b(a(context));
}
public BaseWebView(Context context, AttributeSet attributeSet, int i2) {
super(a(context), attributeSet, i2);
this.a = false;
this.c = false;
this.d = "";
this.f9871e = false;
this.f9872f = new a();
this.f9875i = new b();
this.f9876j = true;
b(a(context));
}
public void b(String str) {
if (TextUtils.isEmpty(str)) {
JsPromptResult jsPromptResult = this.b;
if (jsPromptResult != null) {
jsPromptResult.confirm(null);
this.b = null;
return;
}
evaluateJavascript(str, this.f9875i);
}
}
public void b() {
k0.a(new o0() {
@Override
public final void subscribe(m0 m0Var) {
BaseWebView.this.a(m0Var);
}
}).b(p.a.e1.b.b()).a(p.a.s0.d.a.a()).j().subscribe(new g() {
@Override
public final void accept(Object obj) {
BaseWebView.this.e((String) obj);
}
});
}
}