package com.tencent.connect.auth; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.AlertDialog; 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.Button; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; import anet.channel.strategy.dispatch.DispatchConstants; import com.tencent.connect.auth.b; import com.tencent.connect.common.Constants; import com.tencent.open.SocialConstants; import com.tencent.open.a.g; import com.tencent.open.log.SLog; import com.tencent.open.utils.HttpUtils; import com.tencent.open.utils.k; 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 com.umeng.commonsdk.proguard.e; import com.umeng.message.proguard.l; import java.util.HashMap; import java.util.List; import java.util.Locale; import org.json.JSONException; import org.json.JSONObject; /* compiled from: ProGuard */ public class a extends Dialog { /* renamed from: a reason: collision with root package name */ private String f11534a; /* renamed from: b reason: collision with root package name */ private b f11535b; private IUiListener c; private Handler d; private FrameLayout e; private LinearLayout f; private FrameLayout g; private ProgressBar h; private Button i; private String j; private com.tencent.open.b.c k; private Context l; private com.tencent.open.web.security.b m; private boolean n = false; private int o; private String p; private String q; private long r = 0; private long s = e.d; private HashMap<String, Runnable> t; static /* synthetic */ int m(a aVar) { int i2 = aVar.o; aVar.o = i2 + 1; return i2; } public a(Context context, String str, String str2, IUiListener iUiListener, QQToken qQToken) { super(context, 16973840); this.l = context; this.f11534a = str2; this.f11535b = new b(str, str2, qQToken.getAppId(), iUiListener); this.d = new c(this.f11535b, context.getMainLooper()); this.c = iUiListener; this.j = str; this.m = new com.tencent.open.web.security.b(); getWindow().setSoftInputMode(32); } /* access modifiers changed from: protected */ public void onCreate(Bundle bundle) { requestWindowFeature(1); super.onCreate(bundle); b(); e(); this.t = new HashMap<>(); } public void onBackPressed() { if (!this.n) { this.f11535b.onCancel(); } super.onBackPressed(); } /* access modifiers changed from: protected */ public void onStop() { super.onStop(); } /* compiled from: ProGuard */ private class c extends Handler { /* renamed from: b reason: collision with root package name */ private b f11549b; public c(b bVar, Looper looper) { super(looper); this.f11549b = bVar; } public void handleMessage(Message message) { int i = message.what; if (i == 1) { this.f11549b.a((String) message.obj); } else if (i == 2) { this.f11549b.onCancel(); } else if (i == 3) { a.b(a.this.l, (String) message.obj); } } } /* access modifiers changed from: private */ /* compiled from: ProGuard */ public class b implements IUiListener { /* renamed from: a reason: collision with root package name */ String f11546a; /* renamed from: b reason: collision with root package name */ String f11547b; private String d; private IUiListener e; public b(String str, String str2, String str3, IUiListener iUiListener) { this.d = str; this.f11546a = str2; this.f11547b = str3; this.e = iUiListener; } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void a(String str) { try { onComplete(k.d(str)); } catch (JSONException e2) { e2.printStackTrace(); onError(new UiError(-4, Constants.MSG_JSON_ERROR, str)); } } @Override // com.tencent.tauth.IUiListener public void onComplete(Object obj) { JSONObject jSONObject = (JSONObject) obj; g a2 = g.a(); a2.a(this.d + "_H5", SystemClock.elapsedRealtime(), 0, 0, jSONObject.optInt("ret", -6), this.f11546a, false); IUiListener iUiListener = this.e; if (iUiListener != null) { iUiListener.onComplete(jSONObject); this.e = null; } } @Override // com.tencent.tauth.IUiListener public void onError(UiError uiError) { String str; if (uiError.errorMessage != null) { str = uiError.errorMessage + this.f11546a; } else { str = this.f11546a; } g.a().a(this.d + "_H5", SystemClock.elapsedRealtime(), 0, 0, uiError.errorCode, str, false); a.this.a((a) str); IUiListener iUiListener = this.e; if (iUiListener != null) { iUiListener.onError(uiError); this.e = null; } } @Override // com.tencent.tauth.IUiListener public void onCancel() { IUiListener iUiListener = this.e; if (iUiListener != null) { iUiListener.onCancel(); this.e = null; } } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private String a(String str) { StringBuilder sb = new StringBuilder(str); if (!TextUtils.isEmpty(this.q) && this.q.length() >= 4) { String str2 = this.q; String substring = str2.substring(str2.length() - 4); sb.append("_u_"); sb.append(substring); } return sb.toString(); } /* access modifiers changed from: private */ /* renamed from: com.tencent.connect.auth.a$a reason: collision with other inner class name */ /* compiled from: ProGuard */ public class C0286a extends WebViewClient { private C0286a() { } @Override // android.webkit.WebViewClient public boolean shouldOverrideUrlLoading(WebView webView, String str) { Uri uri; SLog.v("openSDK_LOG.AuthDialog", "-->Redirect URL: " + str); if (str.startsWith("auth://browser")) { JSONObject c = k.c(str); a aVar = a.this; aVar.n = aVar.f(); if (!a.this.n) { 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; StringBuilder sb = new StringBuilder(); sb.append(a.this.f11534a); String str2 = "?"; if (a.this.f11534a.indexOf(str2) > -1) { str2 = DispatchConstants.SIGN_SPLIT_SYMBOL; } sb.append(str2); aVar2.f11534a = sb.toString(); a aVar3 = a.this; aVar3.f11534a = a.this.f11534a + "browser_error=1"; a.this.k.loadUrl(a.this.f11534a); } else { String optString = c.optString("redir", null); if (optString != null) { a.this.k.loadUrl(optString); } } } return true; } else if (str.startsWith("auth://tauth.qq.com/")) { a.this.f11535b.onComplete(k.c(str)); a.this.dismiss(); return true; } else if (str.startsWith(Constants.CANCEL_URI)) { a.this.f11535b.onCancel(); a.this.dismiss(); return true; } else if (str.startsWith(Constants.CLOSE_URI)) { a.this.dismiss(); return true; } else if (str.startsWith(Constants.DOWNLOAD_URI) || str.endsWith(".apk")) { try { if (str.startsWith(Constants.DOWNLOAD_URI)) { uri = Uri.parse(Uri.decode(str.substring(11))); } else { uri = Uri.parse(Uri.decode(str)); } Intent intent = new Intent("android.intent.action.VIEW", uri); intent.addFlags(268435456); a.this.l.startActivity(intent); } catch (Exception e) { SLog.e("openSDK_LOG.AuthDialog", "-->start download activity exception, e: ", e); } return true; } else if (str.startsWith("auth://progress")) { try { List<String> pathSegments = Uri.parse(str).getPathSegments(); if (pathSegments.isEmpty()) { return true; } int intValue = Integer.valueOf(pathSegments.get(0)).intValue(); if (intValue == 0) { a.this.g.setVisibility(8); a.this.k.setVisibility(0); } else if (intValue == 1) { a.this.g.setVisibility(0); } return true; } catch (Exception unused) { } } else if (str.startsWith("auth://onLoginSubmit")) { try { List<String> pathSegments2 = Uri.parse(str).getPathSegments(); if (!pathSegments2.isEmpty()) { a.this.q = pathSegments2.get(0); } } catch (Exception unused2) { } return true; } else if (a.this.m.a(a.this.k, str)) { return true; } else { SLog.i("openSDK_LOG.AuthDialog", "-->Redirect URL: return false"); return false; } } public void onReceivedError(WebView webView, int i, String str, String str2) { super.onReceivedError(webView, i, str, str2); SLog.i("openSDK_LOG.AuthDialog", "-->onReceivedError, errorCode: " + i + " | description: " + str); if (!k.b(a.this.l)) { a.this.f11535b.onError(new UiError(9001, "当前网络不可用,请稍后重试!", str2)); a.this.dismiss(); } else if (!a.this.p.startsWith("http://login.imgcache.qq.com/ptlogin/static/qzsjump.html?")) { long elapsedRealtime = SystemClock.elapsedRealtime() - a.this.r; if (a.this.o >= 1 || elapsedRealtime >= a.this.s) { a.this.k.loadUrl(a.this.a()); return; } a.m(a.this); a.this.d.postDelayed(new Runnable() { /* class com.tencent.connect.auth.a.C0286a.AnonymousClass1 */ public void run() { a.this.k.loadUrl(a.this.p); } }, 500); } else { a.this.f11535b.onError(new UiError(i, str, str2)); a.this.dismiss(); } } public void onPageStarted(WebView webView, String str, Bitmap bitmap) { SLog.v("openSDK_LOG.AuthDialog", "-->onPageStarted, url: " + str); super.onPageStarted(webView, str, bitmap); a.this.g.setVisibility(0); a.this.r = SystemClock.elapsedRealtime(); if (!TextUtils.isEmpty(a.this.p)) { a.this.d.removeCallbacks((Runnable) a.this.t.remove(a.this.p)); } a.this.p = str; a aVar = a.this; d dVar = new d(aVar.p); a.this.t.put(str, dVar); a.this.d.postDelayed(dVar, 120000); } public void onPageFinished(WebView webView, String str) { super.onPageFinished(webView, str); SLog.v("openSDK_LOG.AuthDialog", "-->onPageFinished, url: " + str); a.this.g.setVisibility(8); if (a.this.k != null) { a.this.k.setVisibility(0); } if (!TextUtils.isEmpty(str)) { a.this.d.removeCallbacks((Runnable) a.this.t.remove(str)); } } @TargetApi(8) public void onReceivedSslError(WebView webView, final SslErrorHandler sslErrorHandler, SslError sslError) { String str; String str2; String str3; SLog.e("openSDK_LOG.AuthDialog", "-->onReceivedSslError " + sslError.getPrimaryError() + "请求不合法,请检查手机安全设置,如系统时间、代理等"); if (Locale.getDefault().getLanguage().equals("zh")) { str2 = "ssl证书无效,是否继续访问?"; str = "是"; str3 = "否"; } else { str2 = "The SSL certificate is invalid,do you countinue?"; str = "yes"; str3 = "no"; } AlertDialog.Builder builder = new AlertDialog.Builder(a.this.l); builder.setMessage(str2); builder.setPositiveButton(str, new DialogInterface.OnClickListener() { /* class com.tencent.connect.auth.a.C0286a.AnonymousClass2 */ public void onClick(DialogInterface dialogInterface, int i) { sslErrorHandler.proceed(); } }); builder.setNegativeButton(str3, new DialogInterface.OnClickListener() { /* class com.tencent.connect.auth.a.C0286a.AnonymousClass3 */ public void onClick(DialogInterface dialogInterface, int i) { sslErrorHandler.cancel(); a.this.dismiss(); } }); builder.create().show(); } } /* compiled from: ProGuard */ class d implements Runnable { /* renamed from: a reason: collision with root package name */ String f11550a = ""; public d(String str) { this.f11550a = str; } public void run() { SLog.v("openSDK_LOG.AuthDialog", "-->timeoutUrl: " + this.f11550a + " | mRetryUrl: " + a.this.p); if (this.f11550a.equals(a.this.p)) { a.this.f11535b.onError(new UiError(9002, "请求页面超时,请稍后重试!", a.this.p)); a.this.dismiss(); } } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private String a() { String str = this.f11534a; String str2 = "http://login.imgcache.qq.com/ptlogin/static/qzsjump.html?" + str.substring(str.indexOf("?") + 1); SLog.i("openSDK_LOG.AuthDialog", "-->generateDownloadUrl, url: http://login.imgcache.qq.com/ptlogin/static/qzsjump.html?"); return str2; } private void b() { d(); c(); FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, -1); this.k = new com.tencent.open.b.c(this.l); if (Build.VERSION.SDK_INT >= 11) { this.k.setLayerType(1, null); } this.k.setLayoutParams(layoutParams); this.e = new FrameLayout(this.l); layoutParams.gravity = 17; this.e.setLayoutParams(layoutParams); this.e.addView(this.k); this.e.addView(this.g); String string = k.b(this.f11534a).getString("style"); if (string != null && "qr".equals(string)) { this.e.addView(this.i); } setContentView(this.e); } private void c() { this.i = new Button(this.l); this.i.setBackgroundDrawable(k.a("h5_qr_back.png", this.l)); FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-2, -2); layoutParams.leftMargin = com.tencent.connect.avatar.a.a(this.l, 20.0f); layoutParams.topMargin = com.tencent.connect.avatar.a.a(this.l, 10.0f); this.i.setLayoutParams(layoutParams); this.i.setOnClickListener(new View.OnClickListener() { /* class com.tencent.connect.auth.a.AnonymousClass1 */ public void onClick(View view) { a.this.dismiss(); if (!a.this.n && a.this.f11535b != null) { a.this.f11535b.onCancel(); } } }); } private void d() { TextView textView; this.h = new ProgressBar(this.l); this.h.setLayoutParams(new LinearLayout.LayoutParams(-2, -2)); this.f = new LinearLayout(this.l); if (this.j.equals("action_login")) { LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2); layoutParams.gravity = 16; layoutParams.leftMargin = 5; textView = new TextView(this.l); 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.l); FrameLayout.LayoutParams layoutParams3 = new FrameLayout.LayoutParams(-1, -1); layoutParams3.gravity = 17; this.g.setLayoutParams(layoutParams3); this.g.setBackgroundColor(Color.parseColor("#B3000000")); this.g.addView(this.f); } @SuppressLint({"SetJavaScriptEnabled"}) private void e() { this.k.setVerticalScrollBarEnabled(false); this.k.setHorizontalScrollBarEnabled(false); this.k.setWebViewClient(new C0286a()); this.k.setWebChromeClient(new WebChromeClient()); this.k.clearFormData(); this.k.clearSslPreferences(); this.k.setOnLongClickListener(new View.OnLongClickListener() { /* class com.tencent.connect.auth.a.AnonymousClass2 */ public boolean onLongClick(View view) { return true; } }); this.k.setOnTouchListener(new View.OnTouchListener() { /* class com.tencent.connect.auth.a.AnonymousClass3 */ 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.k.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.l.getDir("databases", 0).getPath()); settings.setDomStorageEnabled(true); SLog.v("openSDK_LOG.AuthDialog", "-->mUrl : " + this.f11534a); String str = this.f11534a; this.p = str; this.k.loadUrl(str); this.k.setVisibility(4); this.k.getSettings().setSavePassword(false); this.m.a(new SecureJsInterface(), "SecureJsInterface"); SecureJsInterface.isPWDEdit = false; super.setOnDismissListener(new DialogInterface.OnDismissListener() { /* class com.tencent.connect.auth.a.AnonymousClass4 */ public void onDismiss(DialogInterface dialogInterface) { try { if (JniInterface.isJniOk) { JniInterface.clearAllPWD(); } } catch (Exception unused) { } } }); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private boolean f() { b a2 = b.a(); String c2 = a2.c(); b.a aVar = new b.a(); aVar.f11554a = this.c; aVar.f11555b = this; aVar.c = c2; String a3 = a2.a(aVar); String str = this.f11534a; String substring = str.substring(0, str.indexOf("?")); Bundle b2 = k.b(this.f11534a); b2.putString("token_key", c2); b2.putString("serial", a3); b2.putString("browser", "1"); this.f11534a = substring + "?" + HttpUtils.encodeUrl(b2); return k.a(this.l, this.f11534a); } /* access modifiers changed from: private */ public static void b(Context context, String str) { try { JSONObject d2 = k.d(str); int i2 = d2.getInt("type"); Toast.makeText(context.getApplicationContext(), d2.getString(SocialConstants.PARAM_SEND_MSG), i2).show(); } catch (JSONException e2) { e2.printStackTrace(); } } public void a(String str, String str2) { this.k.loadUrl("javascript:" + str + l.s + str2 + ");void(" + System.currentTimeMillis() + ");"); } public void dismiss() { this.t.clear(); this.d.removeCallbacksAndMessages(null); if (isShowing()) { super.dismiss(); } com.tencent.open.b.c cVar = this.k; if (cVar != null) { cVar.destroy(); this.k = null; } } }