jimu-decompiled/sources/com/tencent/connect/auth/a.java
2025-05-13 19:24:51 +02:00

558 lines
20 KiB
Java

package com.tencent.connect.auth;
import android.R;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.tencent.connect.auth.b;
import com.tencent.open.SocialConstants;
import com.tencent.open.a.f;
import com.tencent.open.b.g;
import com.tencent.open.utils.HttpUtils;
import com.tencent.open.utils.i;
import com.tencent.open.web.security.JniInterface;
import com.tencent.open.web.security.SecureJsInterface;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.UiError;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import org.json.JSONException;
import org.json.JSONObject;
/* compiled from: ProGuard */
/* loaded from: classes.dex */
public class a extends Dialog {
private String a;
private b b;
private IUiListener c;
private Handler d;
private FrameLayout e;
private LinearLayout f;
private FrameLayout g;
private ProgressBar h;
private String i;
private com.tencent.open.c.c j;
private Context k;
private com.tencent.open.web.security.b l;
private boolean m;
private int n;
private String o;
private String p;
private long q;
private long r;
private HashMap<String, Runnable> s;
/* compiled from: ProGuard */
/* renamed from: com.tencent.connect.auth.a$a, reason: collision with other inner class name */
private class C0014a extends WebViewClient {
private C0014a() {
}
@Override // android.webkit.WebViewClient
public void onPageFinished(WebView webView, String str) {
super.onPageFinished(webView, str);
f.a("openSDK_LOG.AuthDialog", "-->onPageFinished, url: " + str);
a.this.g.setVisibility(8);
if (a.this.j != null) {
a.this.j.setVisibility(0);
}
if (TextUtils.isEmpty(str)) {
return;
}
a.this.d.removeCallbacks((Runnable) a.this.s.remove(str));
}
@Override // android.webkit.WebViewClient
public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
f.a("openSDK_LOG.AuthDialog", "-->onPageStarted, url: " + str);
super.onPageStarted(webView, str, bitmap);
a.this.g.setVisibility(0);
a.this.q = SystemClock.elapsedRealtime();
if (!TextUtils.isEmpty(a.this.o)) {
a.this.d.removeCallbacks((Runnable) a.this.s.remove(a.this.o));
}
a.this.o = str;
a aVar = a.this;
d dVar = aVar.new d(aVar.o);
a.this.s.put(str, dVar);
a.this.d.postDelayed(dVar, 120000L);
}
@Override // android.webkit.WebViewClient
public void onReceivedError(WebView webView, int i, String str, String str2) {
super.onReceivedError(webView, i, str, str2);
f.c("openSDK_LOG.AuthDialog", "-->onReceivedError, errorCode: " + i + " | description: " + str);
if (!i.b(a.this.k)) {
a.this.b.onError(new UiError(9001, "当前网络不可用,请稍后重试!", str2));
a.this.dismiss();
return;
}
if (a.this.o.startsWith("http://qzs.qq.com/open/mobile/login/qzsjump.html?")) {
a.this.b.onError(new UiError(i, str, str2));
a.this.dismiss();
return;
}
long elapsedRealtime = SystemClock.elapsedRealtime() - a.this.q;
if (a.this.n >= 1 || elapsedRealtime >= a.this.r) {
a.this.j.loadUrl(a.this.a());
} else {
a.m(a.this);
a.this.d.postDelayed(new Runnable() { // from class: com.tencent.connect.auth.a.a.1
@Override // java.lang.Runnable
public void run() {
a.this.j.loadUrl(a.this.o);
}
}, 500L);
}
}
@Override // android.webkit.WebViewClient
@TargetApi(8)
public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
f.e("openSDK_LOG.AuthDialog", "-->onReceivedSslError " + sslError.getPrimaryError() + "请求不合法,请检查手机安全设置,如系统时间、代理等");
sslErrorHandler.cancel();
a.this.b.onError(new UiError(sslError.getPrimaryError(), "请求不合法,请检查手机安全设置,如系统时间、代理等。", "ssl error"));
a.this.dismiss();
}
@Override // android.webkit.WebViewClient
public boolean shouldOverrideUrlLoading(WebView webView, String str) {
List<String> pathSegments;
f.a("openSDK_LOG.AuthDialog", "-->Redirect URL: " + str);
if (str.startsWith("auth://browser")) {
JSONObject c = i.c(str);
a aVar = a.this;
aVar.m = aVar.e();
if (!a.this.m) {
if (c.optString("fail_cb", null) != null) {
a.this.a(c.optString("fail_cb"), "");
} else if (c.optInt("fall_to_wv") == 1) {
a aVar2 = a.this;
a.a(aVar2, (Object) (aVar2.a.indexOf("?") > -1 ? "&" : "?"));
a.a(a.this, (Object) "browser_error=1");
a.this.j.loadUrl(a.this.a);
} else {
String optString = c.optString("redir", null);
if (optString != null) {
a.this.j.loadUrl(optString);
}
}
}
return true;
}
if (str.startsWith("auth://tauth.qq.com/")) {
a.this.b.onComplete(i.c(str));
a.this.dismiss();
return true;
}
if (str.startsWith("auth://cancel")) {
a.this.b.onCancel();
a.this.dismiss();
return true;
}
if (str.startsWith("auth://close")) {
a.this.dismiss();
return true;
}
if (str.startsWith("download://")) {
try {
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(Uri.decode(str.substring(11))));
intent.addFlags(268435456);
a.this.k.startActivity(intent);
} catch (Exception e) {
f.b("openSDK_LOG.AuthDialog", "-->start download activity exception, e: ", e);
}
return true;
}
if (!str.startsWith("auth://progress")) {
if (str.startsWith("auth://onLoginSubmit")) {
try {
List<String> pathSegments2 = Uri.parse(str).getPathSegments();
if (!pathSegments2.isEmpty()) {
a.this.p = pathSegments2.get(0);
}
} catch (Exception unused) {
}
return true;
}
if (a.this.l.a(a.this.j, str)) {
return true;
}
f.c("openSDK_LOG.AuthDialog", "-->Redirect URL: return false");
return false;
}
try {
pathSegments = Uri.parse(str).getPathSegments();
} catch (Exception unused2) {
}
if (pathSegments.isEmpty()) {
return true;
}
int intValue = Integer.valueOf(pathSegments.get(0)).intValue();
if (intValue == 0) {
a.this.g.setVisibility(8);
a.this.j.setVisibility(0);
} else if (intValue == 1) {
a.this.g.setVisibility(0);
}
return true;
}
}
/* compiled from: ProGuard */
private class b implements IUiListener {
private String a;
String b;
private IUiListener c;
public b(String str, String str2, String str3, IUiListener iUiListener) {
this.a = str;
this.b = str2;
this.c = iUiListener;
}
@Override // com.tencent.tauth.IUiListener
public void onCancel() {
IUiListener iUiListener = this.c;
if (iUiListener != null) {
iUiListener.onCancel();
this.c = null;
}
}
@Override // com.tencent.tauth.IUiListener
public void onComplete(Object obj) {
JSONObject jSONObject = (JSONObject) obj;
g.a().a(this.a + "_H5", SystemClock.elapsedRealtime(), 0L, 0L, jSONObject.optInt("ret", -6), this.b, false);
IUiListener iUiListener = this.c;
if (iUiListener != null) {
iUiListener.onComplete(jSONObject);
this.c = null;
}
}
@Override // com.tencent.tauth.IUiListener
public void onError(UiError uiError) {
String str;
if (uiError.b != null) {
str = uiError.b + this.b;
} else {
str = this.b;
}
g.a().a(this.a + "_H5", SystemClock.elapsedRealtime(), 0L, 0L, uiError.a, str, false);
a.this.a(str);
IUiListener iUiListener = this.c;
if (iUiListener != null) {
iUiListener.onError(uiError);
this.c = null;
}
}
/* JADX INFO: Access modifiers changed from: private */
public void a(String str) {
try {
onComplete(i.d(str));
} catch (JSONException e) {
e.printStackTrace();
onError(new UiError(-4, "服务器返回数据格式有误!", str));
}
}
}
/* compiled from: ProGuard */
private class c extends Handler {
private b a;
public c(b bVar, Looper looper) {
super(looper);
this.a = bVar;
}
@Override // android.os.Handler
public void handleMessage(Message message) {
int i = message.what;
if (i == 1) {
this.a.a((String) message.obj);
} else if (i == 2) {
this.a.onCancel();
} else {
if (i != 3) {
return;
}
a.b(a.this.k, (String) message.obj);
}
}
}
/* compiled from: ProGuard */
class d implements Runnable {
String a;
public d(String str) {
this.a = "";
this.a = str;
}
@Override // java.lang.Runnable
public void run() {
f.a("openSDK_LOG.AuthDialog", "-->timeoutUrl: " + this.a + " | mRetryUrl: " + a.this.o);
if (this.a.equals(a.this.o)) {
a.this.b.onError(new UiError(9002, "请求页面超时,请稍后重试!", a.this.o));
a.this.dismiss();
}
}
}
public a(Context context, String str, String str2, IUiListener iUiListener, QQToken qQToken) {
super(context, R.style.Theme.Translucent.NoTitleBar);
this.m = false;
this.q = 0L;
this.r = 30000L;
this.k = context;
this.a = str2;
this.b = new b(str, str2, qQToken.b(), iUiListener);
this.d = new c(this.b, context.getMainLooper());
this.c = iUiListener;
this.i = str;
this.l = new com.tencent.open.web.security.b();
getWindow().setSoftInputMode(32);
}
static /* synthetic */ int m(a aVar) {
int i = aVar.n;
aVar.n = i + 1;
return i;
}
@Override // android.app.Dialog, android.content.DialogInterface
public void dismiss() {
this.s.clear();
this.d.removeCallbacksAndMessages(null);
if (isShowing()) {
super.dismiss();
}
com.tencent.open.c.c cVar = this.j;
if (cVar != null) {
cVar.destroy();
this.j = null;
}
}
@Override // android.app.Dialog
public void onBackPressed() {
if (!this.m) {
this.b.onCancel();
}
super.onBackPressed();
}
@Override // android.app.Dialog
protected void onCreate(Bundle bundle) {
requestWindowFeature(1);
super.onCreate(bundle);
b();
d();
this.s = new HashMap<>();
}
@Override // android.app.Dialog
protected void onStop() {
super.onStop();
}
@SuppressLint({"SetJavaScriptEnabled"})
private void d() {
this.j.setVerticalScrollBarEnabled(false);
this.j.setHorizontalScrollBarEnabled(false);
this.j.setWebViewClient(new C0014a());
this.j.setWebChromeClient(new WebChromeClient());
this.j.clearFormData();
this.j.clearSslPreferences();
this.j.setOnLongClickListener(new View.OnLongClickListener(this) { // from class: com.tencent.connect.auth.a.1
@Override // android.view.View.OnLongClickListener
public boolean onLongClick(View view) {
return true;
}
});
this.j.setOnTouchListener(new View.OnTouchListener(this) { // from class: com.tencent.connect.auth.a.2
@Override // android.view.View.OnTouchListener
public boolean onTouch(View view, MotionEvent motionEvent) {
int action = motionEvent.getAction();
if ((action != 0 && action != 1) || view.hasFocus()) {
return false;
}
view.requestFocus();
return false;
}
});
WebSettings settings = this.j.getSettings();
settings.setSavePassword(false);
settings.setSaveFormData(false);
settings.setCacheMode(-1);
settings.setNeedInitialFocus(false);
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
settings.setJavaScriptEnabled(true);
settings.setDatabaseEnabled(true);
settings.setDatabasePath(this.k.getDir("databases", 0).getPath());
settings.setDomStorageEnabled(true);
f.a("openSDK_LOG.AuthDialog", "-->mUrl : " + this.a);
String str = this.a;
this.o = str;
this.j.loadUrl(str);
this.j.setVisibility(4);
this.j.getSettings().setSavePassword(false);
this.l.a(new SecureJsInterface(), "SecureJsInterface");
SecureJsInterface.isPWDEdit = false;
super.setOnDismissListener(new DialogInterface.OnDismissListener(this) { // from class: com.tencent.connect.auth.a.3
@Override // android.content.DialogInterface.OnDismissListener
public void onDismiss(DialogInterface dialogInterface) {
try {
JniInterface.clearAllPWD();
} catch (Exception unused) {
}
}
});
}
/* JADX INFO: Access modifiers changed from: private */
public boolean e() {
com.tencent.connect.auth.b b2 = com.tencent.connect.auth.b.b();
String a = b2.a();
String a2 = b2.a(new b.a());
String str = this.a;
String substring = str.substring(0, str.indexOf("?"));
Bundle b3 = i.b(this.a);
b3.putString("token_key", a);
b3.putString("serial", a2);
b3.putString("browser", "1");
this.a = substring + "?" + HttpUtils.encodeUrl(b3);
return i.a(this.k, this.a);
}
static /* synthetic */ String a(a aVar, Object obj) {
String str = aVar.a + obj;
aVar.a = str;
return str;
}
private void b() {
c();
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, -1);
this.j = new com.tencent.open.c.c(this.k);
if (Build.VERSION.SDK_INT >= 11) {
this.j.setLayerType(1, null);
}
this.j.setLayoutParams(layoutParams);
this.e = new FrameLayout(this.k);
layoutParams.gravity = 17;
this.e.setLayoutParams(layoutParams);
this.e.addView(this.j);
this.e.addView(this.g);
setContentView(this.e);
}
private void c() {
TextView textView;
this.h = new ProgressBar(this.k);
this.h.setLayoutParams(new LinearLayout.LayoutParams(-2, -2));
this.f = new LinearLayout(this.k);
if (this.i.equals("action_login")) {
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
layoutParams.gravity = 16;
layoutParams.leftMargin = 5;
textView = new TextView(this.k);
if (Locale.getDefault().getLanguage().equals("zh")) {
textView.setText("登录中...");
} else {
textView.setText("Logging in...");
}
textView.setTextColor(Color.rgb(255, 255, 255));
textView.setTextSize(18.0f);
textView.setLayoutParams(layoutParams);
} else {
textView = null;
}
FrameLayout.LayoutParams layoutParams2 = new FrameLayout.LayoutParams(-2, -2);
layoutParams2.gravity = 17;
this.f.setLayoutParams(layoutParams2);
this.f.addView(this.h);
if (textView != null) {
this.f.addView(textView);
}
this.g = new FrameLayout(this.k);
FrameLayout.LayoutParams layoutParams3 = new FrameLayout.LayoutParams(-1, -2);
layoutParams3.leftMargin = 80;
layoutParams3.rightMargin = 80;
layoutParams3.topMargin = 40;
layoutParams3.bottomMargin = 40;
layoutParams3.gravity = 17;
this.g.setLayoutParams(layoutParams3);
this.g.setBackgroundResource(R.drawable.alert_dark_frame);
this.g.addView(this.f);
}
/* JADX INFO: Access modifiers changed from: private */
public String a(String str) {
StringBuilder sb = new StringBuilder(str);
if (!TextUtils.isEmpty(this.p) && this.p.length() >= 4) {
String str2 = this.p;
String substring = str2.substring(str2.length() - 4);
sb.append("_u_");
sb.append(substring);
}
return sb.toString();
}
/* JADX INFO: Access modifiers changed from: private */
public String a() {
String str = this.a;
String str2 = "http://qzs.qq.com/open/mobile/login/qzsjump.html?" + str.substring(str.indexOf("?") + 1);
f.c("openSDK_LOG.AuthDialog", "-->generateDownloadUrl, url: http://qzs.qq.com/open/mobile/login/qzsjump.html?");
return str2;
}
/* JADX INFO: Access modifiers changed from: private */
public static void b(Context context, String str) {
try {
JSONObject d2 = i.d(str);
int i = d2.getInt("type");
Toast.makeText(context.getApplicationContext(), d2.getString(SocialConstants.PARAM_SEND_MSG), i).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
public void a(String str, String str2) {
this.j.loadUrl("javascript:" + str + "(" + str2 + ");void(" + System.currentTimeMillis() + ");");
}
}