package com.tencent.mm.plugin.account.bind.ui; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.text.TextUtils; import android.view.MenuItem; import android.webkit.ConsoleMessage; import android.widget.TextView; import b10.s0; import com.google.android.gms.common.Scopes; import com.tencent.mm.R; import com.tencent.mm.plugin.report.service.q; import com.tencent.mm.sdk.platformtools.ErrorCode; import com.tencent.mm.sdk.platformtools.Log; import com.tencent.mm.sdk.platformtools.NetStatusUtil; import com.tencent.mm.storage.t1; import com.tencent.mm.ui.MMActivity; import com.tencent.mm.ui.widget.MMWebView; import com.tencent.xweb.CookieManager; import com.tencent.xweb.WebChromeClient; import com.tencent.xweb.WebView; import com.tencent.xweb.WebViewClient; import com.tencent.xweb.xwalk.plugin.XWalkReaderBasePlugin; import d60.z; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; import java.util.ArrayList; import org.apache.http.message.BasicNameValuePair; import org.json.JSONException; import org.json.JSONObject; import sk0.h0; import sk0.u; import yf0.n; import yf0.y; import yz3.j; public class BindGoogleContactUI extends MMActivity implements n { /* renamed from: t reason: collision with root package name */ public static final /* synthetic */ int f80996t = 0; /* renamed from: e reason: collision with root package name */ public boolean f80997e = false; /* renamed from: f reason: collision with root package name */ public MMWebView f80998f; /* renamed from: g reason: collision with root package name */ public TextView f80999g; /* renamed from: h reason: collision with root package name */ public String f81000h; /* renamed from: i reason: collision with root package name */ public String f81001i; /* renamed from: j reason: collision with root package name */ public String f81002j; /* renamed from: n reason: collision with root package name */ public String f81003n; /* renamed from: o reason: collision with root package name */ public ProgressDialog f81004o; /* renamed from: p reason: collision with root package name */ public h0 f81005p; /* renamed from: q reason: collision with root package name */ public boolean f81006q = false; /* renamed from: r reason: collision with root package name */ public int f81007r; /* renamed from: s reason: collision with root package name */ public boolean f81008s = false; public class a implements MenuItem.OnMenuItemClickListener { public a() { } public boolean onMenuItemClick(MenuItem menuItem) { BindGoogleContactUI.this.finish(); return true; } } public class b extends WebViewClient { public b() { } @Override // com.tencent.xweb.WebViewClient public void onPageFinished(WebView webView, String str) { MMWebView mMWebView = BindGoogleContactUI.this.f80998f; if (!(mMWebView == null || mMWebView.getVisibility() == 0)) { BindGoogleContactUI.this.f80998f.setVisibility(0); TextView textView = BindGoogleContactUI.this.f80999g; if (textView != null) { textView.setVisibility(4); } } BindGoogleContactUI.this.U7(); if (webView != null) { String title = webView.getTitle(); if (TextUtils.isEmpty(title)) { return; } if (title.toLowerCase().contains("success")) { MMWebView mMWebView2 = BindGoogleContactUI.this.f80998f; if (mMWebView2 != null) { mMWebView2.setVisibility(4); } ((s0) j.c(s0.class)).sf0(BindGoogleContactUI.this.f80998f, "weixin://private/googlegetcode", "document.getElementById('code').value"); } else if (title.toLowerCase().contains("error")) { Log.w("MicroMsg.GoogleContact.BindGoogleContactUI", "failed." + title.substring(title.indexOf("="))); } } } @Override // com.tencent.xweb.WebViewClient public boolean shouldOverrideUrlLoading(WebView webView, String str) { if (!str.toLowerCase().startsWith("weixin://private/googlegetcode")) { return super.shouldOverrideUrlLoading(webView, str); } BindGoogleContactUI bindGoogleContactUI = BindGoogleContactUI.this; int i15 = BindGoogleContactUI.f80996t; bindGoogleContactUI.getClass(); String substring = str.substring(30); bindGoogleContactUI.X7(); new f(substring).execute(new Void[0]); return true; } } public class c extends WebChromeClient { public c() { } @Override // com.tencent.xweb.WebChromeClient public boolean onConsoleMessage(ConsoleMessage consoleMessage) { String str; s0 s0Var = (s0) j.c(s0.class); if (consoleMessage != null) { str = consoleMessage.message(); } else { str = null; } String hG0 = s0Var.hG0(str); if (!hG0.toLowerCase().startsWith("weixin://private/googlegetcode")) { return super.onConsoleMessage(consoleMessage); } BindGoogleContactUI bindGoogleContactUI = BindGoogleContactUI.this; int i15 = BindGoogleContactUI.f80996t; bindGoogleContactUI.getClass(); String substring = hG0.substring(30); bindGoogleContactUI.X7(); new f(substring).execute(new Void[0]); return true; } } public class d implements DialogInterface.OnCancelListener { public d() { } public void onCancel(DialogInterface dialogInterface) { BindGoogleContactUI bindGoogleContactUI = BindGoogleContactUI.this; bindGoogleContactUI.f81006q = true; if (bindGoogleContactUI.f81005p != null) { z.d().d(BindGoogleContactUI.this.f81005p); } } } public class e extends AsyncTask<Void, Void, Void> { /* renamed from: a reason: collision with root package name */ public String f81013a; /* renamed from: b reason: collision with root package name */ public String f81014b; /* renamed from: c reason: collision with root package name */ public boolean f81015c; public e(String str) { this.f81013a = str; } public final String a(String str) { return new JSONObject(str).optString(Scopes.EMAIL); } public final String b(String str) { String str2; HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + str).openConnection(); httpURLConnection.setRequestProperty("Charset", "UTF-8"); httpURLConnection.setRequestMethod("GET"); httpURLConnection.setConnectTimeout(20000); httpURLConnection.setReadTimeout(20000); int responseCode = httpURLConnection.getResponseCode(); Log.e("MicroMsg.GoogleContact.BindGoogleContactUI", "responseCode:" + responseCode); if (200 == responseCode) { StringBuffer stringBuffer = new StringBuffer(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream(), "UTF-8")); while (true) { String readLine = bufferedReader.readLine(); if (readLine == null) { break; } stringBuffer.append(readLine); } bufferedReader.close(); str2 = stringBuffer.toString(); Log.i("MicroMsg.GoogleContact.BindGoogleContactUI", "get EmailAccount respone:%s", str2); } else { str2 = ""; } try { httpURLConnection.getInputStream().close(); } catch (Exception e15) { Log.e("MicroMsg.GoogleContact.BindGoogleContactUI", e15.getMessage()); } httpURLConnection.disconnect(); return str2; } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object[]] */ @Override // android.os.AsyncTask public Void doInBackground(Void[] voidArr) { Log.i("MicroMsg.GoogleContact.BindGoogleContactUI", "doInBackground"); try { String a15 = a(b(this.f81013a)); this.f81014b = a15; if (TextUtils.isEmpty(a15)) { return null; } this.f81015c = true; return null; } catch (MalformedURLException e15) { Log.e("MicroMsg.GoogleContact.BindGoogleContactUI", "MalformedURLException:%s", e15.getMessage()); return null; } catch (ProtocolException e16) { Log.e("MicroMsg.GoogleContact.BindGoogleContactUI", "ProtocolException:%s", e16.getMessage()); return null; } catch (UnsupportedEncodingException e17) { Log.e("MicroMsg.GoogleContact.BindGoogleContactUI", "UnsupportedEncodingException:%s", e17.getMessage()); return null; } catch (IOException e18) { Log.e("MicroMsg.GoogleContact.BindGoogleContactUI", "IOException:%s", e18.getMessage()); return null; } catch (JSONException e19) { Log.printErrStackTrace("MicroMsg.GoogleContact.BindGoogleContactUI", e19, "", new Object[0]); return null; } } /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // android.os.AsyncTask public void onPostExecute(Void r55) { super.onPostExecute(r55); Log.i("MicroMsg.GoogleContact.BindGoogleContactUI", "onPostExecute"); BindGoogleContactUI bindGoogleContactUI = BindGoogleContactUI.this; boolean z15 = this.f81015c; String str = this.f81014b; if (z15) { bindGoogleContactUI.getClass(); if (!TextUtils.isEmpty(str)) { if (TextUtils.isEmpty(bindGoogleContactUI.f81000h) || TextUtils.isEmpty(str) || bindGoogleContactUI.f81000h.equalsIgnoreCase(str)) { bindGoogleContactUI.f81000h = str; bindGoogleContactUI.T7(0); return; } bindGoogleContactUI.U7(); i14.j.u(bindGoogleContactUI, bindGoogleContactUI.getString(R.string.fqv), "", new rk0.b(bindGoogleContactUI, str), new rk0.c(bindGoogleContactUI)); return; } } bindGoogleContactUI.U7(); bindGoogleContactUI.W7(); } public void onPreExecute() { super.onPreExecute(); Log.i("MicroMsg.GoogleContact.BindGoogleContactUI", "onPreExecute"); this.f81015c = false; } } public class f extends AsyncTask<Void, Void, Void> { /* renamed from: a reason: collision with root package name */ public String f81017a; /* renamed from: b reason: collision with root package name */ public String f81018b; /* renamed from: c reason: collision with root package name */ public String f81019c; /* renamed from: d reason: collision with root package name */ public boolean f81020d; public f(String str) { this.f81017a = str; } public final String a(String str) { HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("https://accounts.google.com/o/oauth2/token").openConnection(); httpURLConnection.setRequestProperty("Charset", "UTF-8"); httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); httpURLConnection.setRequestMethod("POST"); httpURLConnection.setConnectTimeout(20000); httpURLConnection.setReadTimeout(20000); httpURLConnection.setDoInput(true); httpURLConnection.setDoOutput(true); ArrayList arrayList = new ArrayList(); arrayList.add(new BasicNameValuePair("code", str)); arrayList.add(new BasicNameValuePair("client_id", "369820936870.apps.googleusercontent.com")); arrayList.add(new BasicNameValuePair("client_secret", "wcFhvo-s7wNcmQ9Zjr00H06u")); arrayList.add(new BasicNameValuePair("redirect_uri", "urn:ietf:wg:oauth:2.0:oob")); arrayList.add(new BasicNameValuePair("grant_type", "authorization_code")); String a15 = u.a(arrayList); Log.i("MicroMsg.GoogleContact.BindGoogleContactUI", "QueryString:%s", a15); int length = a15.getBytes().length; StringBuilder sb5 = new StringBuilder(); sb5.append(length); String str2 = ""; sb5.append(str2); httpURLConnection.setRequestProperty("Content-length", sb5.toString()); BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(httpURLConnection.getOutputStream(), "UTF-8")); bufferedWriter.write(a15); bufferedWriter.flush(); bufferedWriter.close(); int responseCode = httpURLConnection.getResponseCode(); Log.e("MicroMsg.GoogleContact.BindGoogleContactUI", "responseCode:" + responseCode); if (200 == responseCode) { StringBuffer stringBuffer = new StringBuffer(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream(), "UTF-8")); while (true) { String readLine = bufferedReader.readLine(); if (readLine == null) { break; } stringBuffer.append(readLine); } bufferedReader.close(); str2 = stringBuffer.toString(); Log.i("MicroMsg.GoogleContact.BindGoogleContactUI", "exchange token respone:%s", str2); } try { httpURLConnection.getInputStream().close(); } catch (Exception e15) { Log.e("MicroMsg.GoogleContact.BindGoogleContactUI", e15.getMessage()); } httpURLConnection.disconnect(); return str2; } public final String b(String str) { return new JSONObject(str).optString("access_token"); } public final String c(String str) { return new JSONObject(str).optString("refresh_token"); } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object[]] */ @Override // android.os.AsyncTask public Void doInBackground(Void[] voidArr) { try { String a15 = a(this.f81017a); this.f81018b = b(a15); this.f81019c = c(a15); Log.i("MicroMsg.GoogleContact.BindGoogleContactUI", "response:%s", a15); Log.i("MicroMsg.GoogleContact.BindGoogleContactUI", "mAccessToken:%s", this.f81018b); Log.i("MicroMsg.GoogleContact.BindGoogleContactUI", "mRefreshToken:%s", this.f81019c); this.f81020d = true; return null; } catch (MalformedURLException e15) { Log.e("MicroMsg.GoogleContact.BindGoogleContactUI", "MalformedURLException:%s" + e15.getMessage()); return null; } catch (ProtocolException e16) { Log.e("MicroMsg.GoogleContact.BindGoogleContactUI", "ProtocolException:%s" + e16.getMessage()); return null; } catch (IOException e17) { Log.e("MicroMsg.GoogleContact.BindGoogleContactUI", "IOException:%s" + e17.getMessage()); return null; } catch (JSONException e18) { Log.e("MicroMsg.GoogleContact.BindGoogleContactUI", "JSONException:%s" + e18.getMessage()); return null; } } /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // android.os.AsyncTask public void onPostExecute(Void r45) { super.onPostExecute(r45); Log.i("MicroMsg.GoogleContact.BindGoogleContactUI", "onPostExecute"); BindGoogleContactUI bindGoogleContactUI = BindGoogleContactUI.this; boolean z15 = this.f81020d; String str = this.f81018b; String str2 = this.f81019c; if (z15) { bindGoogleContactUI.getClass(); if (!TextUtils.isEmpty(str)) { bindGoogleContactUI.f81002j = str; bindGoogleContactUI.f81003n = str2; new e(str).execute(new Void[0]); return; } } bindGoogleContactUI.U7(); bindGoogleContactUI.W7(); } public void onPreExecute() { super.onPreExecute(); Log.i("MicroMsg.GoogleContact.BindGoogleContactUI", "onPreExecute"); this.f81018b = ""; this.f81019c = ""; this.f81020d = false; } } public final void T7(int i15) { this.f81005p = new h0(h0.a.MM_BIND_GCONTACT_OPCODE_BIND, this.f81000h, i15); z.d().f(this.f81005p); Log.i("MicroMsg.GoogleContact.BindGoogleContactUI", "doScene mAppToken:%s, mWebToke:%s", this.f81001i, this.f81002j); } public final void U7() { ProgressDialog progressDialog = this.f81004o; if (progressDialog != null && progressDialog.isShowing()) { this.f81004o.dismiss(); } } public final void V7() { X7(); this.f80998f.getSettings().setJavaScriptEnabled(true); this.f80998f.setWebViewClient(new b()); this.f80998f.setWebChromeClient(new c()); MMWebView mMWebView = this.f80998f; Log.i("MicroMsg.GoogleContactLogic", "getRequestCodeUrl:%s", "https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/userinfo.email https://www.google.com/m8/feeds&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=369820936870.apps.googleusercontent.com"); mMWebView.loadUrl("https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/userinfo.email https://www.google.com/m8/feeds&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=369820936870.apps.googleusercontent.com"); } public final void W7() { String str; MMWebView mMWebView = this.f80998f; if (mMWebView != null) { mMWebView.setVisibility(4); } TextView textView = this.f80999g; if (textView != null) { textView.setVisibility(0); } if (!NetStatusUtil.isConnected(this)) { str = getString(R.string.fqw); } else { str = getString(R.string.fqo); } this.f80999g.setText(str); } public final void X7() { ProgressDialog progressDialog = this.f81004o; if (progressDialog == null || !progressDialog.isShowing()) { this.f81004o = i14.j.Q(this, getString(R.string.f367625yv), getString(R.string.f367656zq), true, true, new d()); } } public void Y7() { if (this.f80997e) { this.f80998f.setVisibility(8); X7(); startActivityForResult(new Intent("com.tencent.mm.gms.ACTION_CHOOSE_ACCOUNT"), 1003); return; } this.f80999g.setVisibility(4); this.f80998f.setVisibility(0); V7(); } @Override // com.tencent.mm.ui.MMActivity public int getLayoutId() { return R.layout.f365512k9; } @Override // com.tencent.mm.ui.MMActivity public void initView() { setMMTitle(R.string.fqn); setBackBtn(new a()); MMWebView mMWebView = (MMWebView) findViewById(R.id.gqc); mMWebView.getClass(); this.f80998f = mMWebView; this.f80999g = (TextView) findViewById(R.id.dez); } @Override // androidx.activity.ComponentActivity, androidx.fragment.app.FragmentActivity, com.tencent.mm.ui.component.UIComponentActivity, com.tencent.mm.ui.MMActivity, com.tencent.mm.ui.MMFragmentActivity public void onActivityResult(int i15, int i16, Intent intent) { Log.i("MicroMsg.GoogleContact.BindGoogleContactUI", "requestCode:%d, resultCode:%d", Integer.valueOf(i15), Integer.valueOf(i16)); if (i16 == -1) { switch (i15) { case 1003: int intExtra = intent.getIntExtra("error_code", -1); Log.i("MicroMsg.GoogleContact.BindGoogleContactUI", "errorCode:%d ", Integer.valueOf(intExtra)); if (intExtra == 0) { this.f81000h = intent.getStringExtra("account"); if (this.f81006q) { U7(); return; } Intent intent2 = new Intent("com.tencent.mm.gms.ACTION_GET_TOKEN"); intent2.putExtra("gmail", this.f81000h); intent2.putExtra("scope", "oauth2:https://www.googleapis.com/auth/userinfo.email https://www.google.com/m8/feeds"); startActivityForResult(intent2, 1004); return; } U7(); W7(); return; case 1004: int intExtra2 = intent.getIntExtra("error_code", -1); Log.i("MicroMsg.GoogleContact.BindGoogleContactUI", "errorCode:%d errorMsg:%s", Integer.valueOf(intExtra2), intent.getStringExtra("error_msg")); if (intExtra2 == 0) { this.f81001i = intent.getStringExtra(XWalkReaderBasePlugin.PARAM_KEY_TOKEN); T7(0); return; } else if (intExtra2 == -3) { U7(); W7(); return; } else { U7(); W7(); return; } case 1005: this.f80997e = intent.getBooleanExtra("gpservices", false); Y7(); return; default: return; } } else if (i15 == 1005) { this.f80997e = intent.getBooleanExtra("gpservices", false); Y7(); } else { U7(); W7(); } } @Override // androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, com.tencent.mm.ui.component.UIComponentActivity, com.tencent.mm.ui.MMActivity, com.tencent.mm.hellhoundlib.activities.HellActivity, com.tencent.mm.ui.MMFragmentActivity public void onCreate(Bundle bundle) { super.onCreate(bundle); this.f81007r = getIntent().getIntExtra("enter_scene", 0); this.f81008s = getIntent().getBooleanExtra("KEnterFromBanner", false); this.f80997e = u.b(this); this.f81000h = (String) z.s().i().e(208903, null); initView(); if (this.f80997e) { startActivityForResult(new Intent("com.tencent.mm.gms.CHECK_GP_SERVICES"), 1005); } else { Y7(); } } @Override // androidx.fragment.app.FragmentActivity, com.tencent.mm.ui.component.UIComponentActivity, com.tencent.mm.ui.MMActivity, com.tencent.mm.hellhoundlib.activities.HellActivity, com.tencent.mm.ui.MMFragmentActivity public void onPause() { super.onPause(); z.d().p(487, this); } @Override // androidx.fragment.app.FragmentActivity, com.tencent.mm.ui.component.UIComponentActivity, com.tencent.mm.ui.MMActivity, com.tencent.mm.hellhoundlib.activities.HellActivity, com.tencent.mm.ui.MMFragmentActivity public void onResume() { super.onResume(); z.d().a(487, this); t1 i15 = z.s().i(); Boolean bool = Boolean.FALSE; if (((Boolean) i15.e(208905, bool)).booleanValue()) { try { CookieManager.getInstance().removeAllCookie(); } catch (Exception unused) { } z.s().i().K(208905, bool); } } @Override // yf0.n public void onSceneEnd(int i15, int i16, String str, y yVar) { Object[] objArr = new Object[3]; objArr[0] = Integer.valueOf(i15); objArr[1] = Integer.valueOf(i16); if (TextUtils.isEmpty(str)) { str = ""; } objArr[2] = str; Log.i("MicroMsg.GoogleContact.BindGoogleContactUI", "[onSceneEnd] errType:%d,errCode:%d,errMsg:%s", objArr); U7(); if (i15 == 0 && i16 == 0) { if (this.f80997e) { z.s().i().K(208903, this.f81000h); z.s().i().K(208901, this.f81001i); } else { z.s().i().K(208903, this.f81000h); z.s().i().K(208902, this.f81002j); z.s().i().K(208904, this.f81003n); } z.s().i().a(true); Intent intent = new Intent(this, GoogleFriendUI.class); intent.putExtra("enter_scene", this.f81007r); k30.a aVar = new k30.a(); aVar.c(intent); j30.a.d(this, aVar.b(), "com/tencent/mm/plugin/account/bind/ui/BindGoogleContactUI", "onSceneEnd", "(IILjava/lang/String;Lcom/tencent/mm/modelbase/NetSceneBase;)V", "Undefined", "startActivity", "(Landroid/content/Intent;)V"); startActivity((Intent) aVar.a(0)); j30.a.e(this, "com/tencent/mm/plugin/account/bind/ui/BindGoogleContactUI", "onSceneEnd", "(IILjava/lang/String;Lcom/tencent/mm/modelbase/NetSceneBase;)V", "Undefined", "startActivity", "(Landroid/content/Intent;)V"); finish(); if (this.f81008s) { q.INSTANCE.g(ErrorCode.ERROR_OUTOF_MEMORY, 6, 6); } } else if (i16 == -85) { i14.j.u(this, getString(R.string.fqu), "", new rk0.d(this), new rk0.e(this)); } else { W7(); } } }