TikTok.apk(点击下载) / InstagramAuthActivity.java


package com.bytedance.lobby.instagram;

import X.ActivityC32381Pv;
import X.AnonymousClass0VA;
import X.AnonymousClass0WN;
import X.C11450d4;
import X.C16500lD;
import X.C21290sw;
import X.C24770yY;
import X.C37086EhP;
import X.C37259EkC;
import X.C45324Hqz;
import X.C48146IvP;
import X.C82193Lk;
import X.C96423qp;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.webkit.CookieManager;
import android.webkit.RenderProcessGoneDetail;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.bytedance.covode.number.Covode;
import com.bytedance.sysoptimizer.EnterTransitionCrashOptimizer;
import com.zhiliaoapp.musically.R;
import java.util.UUID;

public class InstagramAuthActivity extends ActivityC32381Pv {
    public static String LIZIZ;
    public static String LIZJ;
    public static String LIZLLL;
    public static String LJ;
    public static final boolean LJFF = C37259EkC.LIZ;
    public static String LJII;
    public String LIZ = "";
    public WebView LJI;

    static {
        Covode.recordClassIndex(29751);
    }

    public static View LIZ(Window window) {
        View decorView;
        if (C16500lD.LIZIZ) {
            decorView = window.getDecorView();
        } else {
            synchronized (C16500lD.LIZ) {
                try {
                    decorView = window.getDecorView();
                } finally {
                }
            }
        }
        return decorView;
    }

    public static String LIZ(Intent intent, String str) {
        try {
            return intent.getStringExtra(str);
        } catch (Exception unused) {
            return null;
        }
    }

    public final boolean LIZ(String str) {
        C24770yY LJFF2 = C24770yY.LJFF(str);
        Intent intent = new Intent();
        if (LJFF2 != null) {
            try {
                if (TextUtils.equals(LJFF2.LIZ + "://" + LJFF2.LIZ().getHost() + LJFF2.LIZ().getPath(), LIZIZ)) {
                    int i2 = -1;
                    if (!this.LIZ.equals(LJFF2.LIZJ("state"))) {
                        intent.putExtra("ig_result_error_info", "State does not match");
                        intent.putExtra("error_stage", "redirect_and_get_token");
                        setResult(-1, intent);
                        finish();
                        return true;
                    }
                    String LIZJ2 = LJFF2.LIZJ("error");
                    if (!TextUtils.isEmpty(LIZJ2)) {
                        String LIZJ3 = LJFF2.LIZJ("error_description");
                        String str2 = "error = [ " + LIZJ2 + " ], desc = [ " + LIZJ3 + " ]";
                        if (!TextUtils.equals(LIZJ3, "The user denied your request.")) {
                            i2 = 0;
                        }
                        intent.putExtra("ig_result_error_info", str2);
                        intent.putExtra("error_stage", "redirect_and_get_token");
                        setResult(i2, intent);
                        finish();
                        return true;
                    }
                    intent.putExtra("ig_result_code", LJFF2.LIZJ("code"));
                    setResult(1, intent);
                    finish();
                    return true;
                }
            } catch (Exception e) {
                intent.putExtra("ig_result_error_info", "exception: url = [" + str + "], message = [" + e.getMessage() + "], stacktrace = [" + Log.getStackTraceString(e) + "]");
                setResult(0, intent);
                intent.putExtra("error_stage", "redirect_and_get_token");
                finish();
                return true;
            }
        }
        return false;
    }

    @Override // X.ActivityC31021Kp
    public void onBackPressed() {
        Intent intent = new Intent();
        intent.putExtra("ig_result_error_info", "Login flow cancelled by pressing back");
        intent.putExtra("error_stage", "goto_URL_and_auth");
        setResult(-1, intent);
        super.onBackPressed();
    }

    @Override // X.ActivityC32381Pv, X.ActivityC31021Kp, X.AnonymousClass114
    public void onCreate(Bundle bundle) {
        String cookie;
        AnonymousClass0VA.LIZ(this, bundle);
        super.onCreate(bundle);
        setContentView(R.layout.d1);
        this.LJI = (WebView) findViewById(R.id.c7p);
        Intent intent = getIntent();
        if (intent != null) {
            LIZJ = LIZ(intent, "client_id");
            LJII = LIZ(intent, "login_auth_url");
            LIZIZ = LIZ(intent, "redirect_url");
            LIZLLL = LIZ(intent, "response_type");
            LJ = LIZ(intent, "scope");
        }
        try {
            WebSettings settings = this.LJI.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setLoadsImagesAutomatically(true);
            settings.setDefaultTextEncodingName("utf-8");
            settings.setDomStorageEnabled(true);
        } catch (Exception unused) {
        }
        WebView webView = this.LJI;
        AnonymousClass1 r9 = new WebViewClient() {
            /* class com.bytedance.lobby.instagram.InstagramAuthActivity.AnonymousClass1 */
            public String LIZIZ;

            static {
                Covode.recordClassIndex(29752);
            }

            public final boolean onRenderProcessGone(WebView webView, RenderProcessGoneDetail renderProcessGoneDetail) {
                return C45324Hqz.LIZ(webView, renderProcessGoneDetail);
            }

            @Override // android.webkit.WebViewClient
            public final boolean shouldOverrideUrlLoading(WebView webView, String str) {
                C24770yY LJFF;
                if (C48146IvP.LIZ.LIZIZ(webView, str)) {
                    return true;
                }
                String str2 = this.LIZIZ;
                if (str2 == null || !str2.contains("www.instagram.com/challenge") || !TextUtils.equals("https://www.instagram.com/", str) || (LJFF = C24770yY.LJFF("https://www.instagram.com/oauth/authorize")) == null) {
                    this.LIZIZ = str;
                    if (InstagramAuthActivity.this.LIZ(str) || super.shouldOverrideUrlLoading(webView, str)) {
                        return true;
                    }
                } else {
                    String r2 = LJFF.LJIIIZ().LIZ("client_id", InstagramAuthActivity.LIZJ).LIZ("redirect_uri", InstagramAuthActivity.LIZIZ).LIZ("response_type", InstagramAuthActivity.LIZLLL).LIZ("state", InstagramAuthActivity.this.LIZ).LIZ("scope", InstagramAuthActivity.LJ).LIZIZ().toString();
                    this.LIZIZ = r2;
                    String LIZ2 = C82193Lk.LIZ.LIZ(webView, r2);
                    if (!TextUtils.isEmpty(LIZ2)) {
                        r2 = LIZ2;
                    }
                    webView.loadUrl(r2);
                }
                return false;
            }
        };
        if (C21290sw.LIZIZ.LIZ()) {
            WebSettings settings2 = webView.getSettings();
            String userAgentString = settings2.getUserAgentString();
            if (!userAgentString.contains("BytedanceWebview/d8a21c6")) {
                StringBuilder sb = new StringBuilder(userAgentString);
                if (!TextUtils.isEmpty(sb)) {
                    sb.append(" ");
                }
                sb.append("BytedanceWebview/d8a21c6");
                settings2.setUserAgentString(sb.toString());
            }
        }
        webView.setWebViewClient(C45324Hqz.LIZ(r9));
        CookieManager instance = CookieManager.getInstance();
        if (!TextUtils.isEmpty(instance.getCookie("https://.instagram.com"))) {
            instance.setCookie("https://.instagram.com", "sessionid=");
            if (C11450d4.LIZ(AnonymousClass0WN.LIZ()) && C37086EhP.LIZJ.LIZ() && (cookie = CookieManager.getInstance().getCookie(C96423qp.LIZIZ.LIZ())) != null && !TextUtils.equals(cookie, C96423qp.LIZIZ.LIZIZ())) {
                C96423qp r1 = C96423qp.LIZIZ;
                r1.LIZ(r1.LIZ(), cookie);
            }
        }
        this.LIZ = UUID.randomUUID().toString();
        C24770yY LJFF2 = C24770yY.LJFF(LJII);
        if (LJFF2 != null) {
            C24770yY LIZIZ2 = LJFF2.LJIIIZ().LIZ("client_id", LIZJ).LIZ("redirect_uri", LIZIZ).LIZ("response_type", LIZLLL).LIZ("state", this.LIZ).LIZ("scope", LJ).LIZIZ();
            WebView webView2 = this.LJI;
            String r2 = LIZIZ2.toString();
            String LIZ2 = C82193Lk.LIZ.LIZ(webView2, r2);
            if (!TextUtils.isEmpty(LIZ2)) {
                r2 = LIZ2;
            }
            webView2.loadUrl(r2);
        }
    }

    @Override // X.ActivityC32381Pv, X.ActivityC31021Kp
    public void onDestroy() {
        AnonymousClass0VA.LJ(this);
        super.onDestroy();
    }

    @Override // X.ActivityC31021Kp
    public void onPause() {
        AnonymousClass0VA.LIZJ(this);
        super.onPause();
    }

    @Override // X.ActivityC31021Kp
    public void onResume() {
        AnonymousClass0VA.LIZIZ(this);
        super.onResume();
    }

    @Override // X.ActivityC32381Pv, X.ActivityC31021Kp
    public void onStart() {
        AnonymousClass0VA.LIZ(this);
        super.onStart();
    }

    @Override // X.ActivityC32381Pv, X.ActivityC31021Kp
    public void onStop() {
        AnonymousClass0VA.LIZLLL(this);
        super.onStop();
        if (EnterTransitionCrashOptimizer.getContext() != null && Build.VERSION.SDK_INT >= 21) {
            try {
                LIZ(getWindow()).getViewTreeObserver().dispatchOnPreDraw();
            } catch (Throwable unused) {
            }
        }
        if (Build.VERSION.SDK_INT >= 21) {
            try {
                LIZ(getWindow()).getViewTreeObserver().dispatchOnPreDraw();
            } catch (Throwable unused2) {
            }
        }
    }
}