package com.tencent.open; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; import android.webkit.CookieSyncManager; import android.webkit.WebSettings; import com.tencent.connect.auth.QQToken; import com.tencent.connect.auth.c; import com.tencent.connect.common.BaseApi; import com.tencent.connect.common.Constants; import com.tencent.connect.common.UIListenerManager; import com.tencent.open.b.b; import com.tencent.open.log.SLog; import com.tencent.open.utils.HttpUtils; import com.tencent.open.utils.e; import com.tencent.open.utils.f; import com.tencent.open.utils.g; import com.tencent.open.utils.h; import com.tencent.open.utils.k; import com.tencent.tauth.IUiListener; import com.tencent.tauth.UiError; import org.json.JSONException; import org.json.JSONObject; /* compiled from: ProGuard */ public class SocialApiIml extends BaseApi { /* renamed from: a reason: collision with root package name */ private Activity f11941a; public SocialApiIml(QQToken qQToken) { super(qQToken); } public SocialApiIml(c cVar, QQToken qQToken) { super(cVar, qQToken); } public void gift(Activity activity, Bundle bundle, IUiListener iUiListener) { a(activity, SocialConstants.ACTION_GIFT, bundle, iUiListener); } public void ask(Activity activity, Bundle bundle, IUiListener iUiListener) { a(activity, SocialConstants.ACTION_ASK, bundle, iUiListener); } private void a(Activity activity, String str, Bundle bundle, IUiListener iUiListener) { this.f11941a = activity; Intent c = c(SocialConstants.ACTIVITY_FRIEND_CHOOSER); if (c == null) { SLog.i("openSDK_LOG.SocialApiIml", "--askgift--friend chooser not found"); c = c(SocialConstants.ACTIVITY_ASK_GIFT); } bundle.putAll(b()); if (SocialConstants.ACTION_ASK.equals(str)) { bundle.putString("type", SocialConstants.TYPE_REQUEST); } else if (SocialConstants.ACTION_GIFT.equals(str)) { bundle.putString("type", SocialConstants.TYPE_FREEGIFT); } a(activity, c, str, bundle, g.a().a(e.a(), "http://login.imgcache.qq.com/open/mobile/request/sdk_request.html?"), iUiListener, false); } public void invite(Activity activity, Bundle bundle, IUiListener iUiListener) { this.f11941a = activity; Intent c = c(SocialConstants.ACTIVITY_FRIEND_CHOOSER); if (c == null) { SLog.i("openSDK_LOG.SocialApiIml", "--invite--friend chooser not found"); c = c(SocialConstants.ACTIVITY_INVITE); } bundle.putAll(b()); a(activity, c, SocialConstants.ACTION_INVITE, bundle, g.a().a(e.a(), "http://login.imgcache.qq.com/open/mobile/invite/sdk_invite.html?"), iUiListener, false); } public void story(Activity activity, Bundle bundle, IUiListener iUiListener) { this.f11941a = activity; Intent c = c(SocialConstants.ACTIVITY_STORY); bundle.putAll(b()); a(activity, c, SocialConstants.ACTION_STORY, bundle, g.a().a(e.a(), "http://login.imgcache.qq.com/open/mobile/sendstory/sdk_sendstory_v1.3.html?"), iUiListener, false); } private void a(Activity activity, Intent intent, String str, Bundle bundle, String str2, IUiListener iUiListener, boolean z) { StringBuilder sb = new StringBuilder(); sb.append("-->handleIntent action = "); sb.append(str); sb.append(", activityIntent = null ? "); boolean z2 = true; sb.append(intent == null); SLog.i("openSDK_LOG.SocialApiIml", sb.toString()); if (intent != null) { a(activity, intent, str, bundle, iUiListener); return; } f a2 = f.a(e.a(), this.c.getAppId()); if (!z && !a2.b("C_LoginH5")) { z2 = false; } if (z2) { a(activity, str, bundle, str2, iUiListener); } else { a(activity, bundle, iUiListener); } } private void a(Activity activity, Intent intent, String str, Bundle bundle, IUiListener iUiListener) { SLog.i("openSDK_LOG.SocialApiIml", "-->handleIntentWithAgent action = " + str); intent.putExtra(Constants.KEY_ACTION, str); intent.putExtra(Constants.KEY_PARAMS, bundle); UIListenerManager.getInstance().setListenerWithRequestcode(Constants.REQUEST_SOCIAL_API, iUiListener); a(activity, intent, Constants.REQUEST_SOCIAL_API); } private void a(Activity activity, String str, Bundle bundle, String str2, IUiListener iUiListener) { SLog.i("openSDK_LOG.SocialApiIml", "-->handleIntentWithH5 action = " + str); Intent b2 = b("com.tencent.open.agent.AgentActivity"); a aVar = new a(activity, iUiListener, str, str2, bundle); Intent b3 = b("com.tencent.open.agent.EncryTokenActivity"); if (b3 == null || b2 == null || b2.getComponent() == null || b3.getComponent() == null || !b2.getComponent().getPackageName().equals(b3.getComponent().getPackageName())) { SLog.i("openSDK_LOG.SocialApiIml", "-->handleIntentWithH5--token activity not found"); String f = k.f("tencent&sdk&qazxc***14969%%" + this.c.getAccessToken() + this.c.getAppId() + this.c.getOpenId() + "qzone3.4"); JSONObject jSONObject = new JSONObject(); try { jSONObject.put(SocialConstants.PARAM_ENCRY_EOKEN, f); } catch (JSONException e) { e.printStackTrace(); } aVar.onComplete(jSONObject); return; } b3.putExtra("oauth_consumer_key", this.c.getAppId()); b3.putExtra("openid", this.c.getOpenId()); b3.putExtra(Constants.PARAM_ACCESS_TOKEN, this.c.getAccessToken()); b3.putExtra(Constants.KEY_ACTION, SocialConstants.ACTION_CHECK_TOKEN); if (a(b3)) { SLog.i("openSDK_LOG.SocialApiIml", "-->handleIntentWithH5--found token activity"); UIListenerManager.getInstance().setListenerWithRequestcode(Constants.REQUEST_SOCIAL_H5, aVar); a(activity, b3, Constants.REQUEST_SOCIAL_H5); } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void a(Context context, String str, Bundle bundle, String str2, IUiListener iUiListener) { SLog.v("openSDK_LOG.SocialApiIml", "OpenUi, showDialog --start"); CookieSyncManager.createInstance(context); bundle.putString("oauth_consumer_key", this.c.getAppId()); if (this.c.isSessionValid()) { bundle.putString(Constants.PARAM_ACCESS_TOKEN, this.c.getAccessToken()); } String openId = this.c.getOpenId(); if (openId != null) { bundle.putString("openid", openId); } try { bundle.putString(Constants.PARAM_PLATFORM_ID, e.a().getSharedPreferences(Constants.PREFERENCE_PF, 0).getString(Constants.PARAM_PLATFORM_ID, Constants.DEFAULT_PF)); } catch (Exception e) { e.printStackTrace(); bundle.putString(Constants.PARAM_PLATFORM_ID, Constants.DEFAULT_PF); } String str3 = str2 + HttpUtils.encodeUrl(bundle); SLog.d("openSDK_LOG.SocialApiIml", "OpenUi, showDialog TDialog"); if (SocialConstants.ACTION_CHALLENGE.equals(str) || SocialConstants.ACTION_BRAG.equals(str)) { SLog.d("openSDK_LOG.SocialApiIml", "OpenUi, showDialog PKDialog"); new c(this.f11941a, str, str3, iUiListener, this.c).show(); return; } new TDialog(this.f11941a, str, str3, iUiListener, this.c).show(); } /* access modifiers changed from: private */ /* compiled from: ProGuard */ public class a implements IUiListener { /* renamed from: b reason: collision with root package name */ private IUiListener f11943b; private String c; private String d; private Bundle e; private Activity f; a(Activity activity, IUiListener iUiListener, String str, String str2, Bundle bundle) { this.f11943b = iUiListener; this.c = str; this.d = str2; this.e = bundle; } @Override // com.tencent.tauth.IUiListener public void onComplete(Object obj) { String str; try { str = ((JSONObject) obj).getString(SocialConstants.PARAM_ENCRY_EOKEN); } catch (JSONException e2) { e2.printStackTrace(); SLog.e("openSDK_LOG.SocialApiIml", "OpenApi, EncrytokenListener() onComplete error", e2); str = null; } this.e.putString("encrytoken", str); SocialApiIml socialApiIml = SocialApiIml.this; socialApiIml.a((SocialApiIml) socialApiIml.f11941a, (Context) this.c, (String) this.e, (Bundle) this.d, (String) this.f11943b); if (TextUtils.isEmpty(str)) { SLog.d("openSDK_LOG.SocialApiIml", "The token get from qq or qzone is empty. Write temp token to localstorage."); SocialApiIml.this.writeEncryToken(this.f); } } @Override // com.tencent.tauth.IUiListener public void onError(UiError uiError) { SLog.d("openSDK_LOG.SocialApiIml", "OpenApi, EncryptTokenListener() onError" + uiError.errorMessage); this.f11943b.onError(uiError); } @Override // com.tencent.tauth.IUiListener public void onCancel() { this.f11943b.onCancel(); } } @SuppressLint({"SetJavaScriptEnabled"}) public void writeEncryToken(Context context) { String str; String accessToken = this.c.getAccessToken(); String appId = this.c.getAppId(); String openId = this.c.getOpenId(); if (accessToken == null || accessToken.length() <= 0 || appId == null || appId.length() <= 0 || openId == null || openId.length() <= 0) { str = null; } else { str = k.f("tencent&sdk&qazxc***14969%%" + accessToken + appId + openId + "qzone3.4"); } b bVar = new b(context); WebSettings settings = bVar.getSettings(); settings.setDomStorageEnabled(true); settings.setJavaScriptEnabled(true); settings.setDatabaseEnabled(true); String a2 = g.a().a(context, "http://login.imgcache.qq.com"); bVar.loadDataWithBaseURL(a2, "<!DOCTYPE HTML><html lang=\"en-US\"><head><meta charset=\"UTF-8\"><title>localStorage Test</title><script type=\"text/javascript\">document.domain = 'qq.com';localStorage[\"" + this.c.getOpenId() + "_" + this.c.getAppId() + "\"]=\"" + str + "\";</script></head><body></body></html>", "text/html", "utf-8", a2); } /* access modifiers changed from: protected */ @Override // com.tencent.connect.common.BaseApi public Intent b(String str) { Intent intent = new Intent(); intent.setClassName(Constants.PACKAGE_QZONE, str); Intent intent2 = new Intent(); intent2.setClassName("com.tencent.mobileqq", str); Intent intent3 = new Intent(); intent3.setClassName(Constants.PACKAGE_QQ_PAD, str); if (k.d(e.a()) && h.a(e.a(), intent3)) { return intent3; } if (h.a(e.a(), intent2) && h.c(e.a(), "4.7") >= 0) { return intent2; } if (!h.a(e.a(), intent) || h.a(h.a(e.a(), Constants.PACKAGE_QZONE), "4.2") < 0) { return null; } if (h.a(e.a(), intent.getComponent().getPackageName(), Constants.SIGNATRUE_QZONE)) { return intent; } return null; } }