package com.facebook.login;

import X.8uQ;
import X.C5461M1c;
import X.C5478M1t;
import X.C5588M5z;
import X.M12;
import X.M44;
import X.M5B;
import X.M5G;
import X.M5M;
import android.content.Context;
import android.os.Bundle;
import android.os.Parcel;
import android.webkit.CookieSyncManager;
import com.bytedance.covode.number.Covode;
import com.facebook.AccessToken;
import com.facebook.FacebookRequestError;
import com.facebook.login.LoginClient;
import com.facebook.s;
import kotlin.h.b.n;

public abstract class WebLoginMethodHandler extends LoginMethodHandler {
    public static final C5588M5z LJFF = new C5588M5z((byte) 0);
    public String LIZ;

    static {
        Covode.recordClassIndex(41959);
    }

    public abstract M44 LIZIZ();

    public String LIZLLL() {
        return null;
    }

    /* JADX INFO: super call moved to the top of the method (can break code semantics) */
    public WebLoginMethodHandler(Parcel parcel) {
        super(parcel);
        M12.LIZ((Object) parcel);
    }

    /* JADX INFO: super call moved to the top of the method (can break code semantics) */
    public WebLoginMethodHandler(LoginClient loginClient) {
        super(loginClient);
        M12.LIZ((Object) loginClient);
    }

    /* JADX WARNING: Removed duplicated region for block: B:21:0x008d  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final android.os.Bundle LIZIZ(com.facebook.login.LoginClient.Request r9) {
        /*
            r8 = this;
            X.M12.LIZ((java.lang.Object) r9)
            android.os.Bundle r3 = new android.os.Bundle
            r3.<init>()
            java.util.Set<java.lang.String> r0 = r9.LIZJ
            boolean r0 = X.C5478M1t.LIZ((java.util.Collection<?>) r0)
            if (r0 != 0) goto L_0x0020
            java.lang.String r1 = ","
            java.util.Set<java.lang.String> r0 = r9.LIZJ
            java.lang.String r1 = android.text.TextUtils.join(r1, r0)
            java.lang.String r0 = "scope"
            r3.putString(r0, r1)
            r8.LIZ(r0, r1)
        L_0x0020:
            X.M53 r0 = r9.LIZLLL
            if (r0 != 0) goto L_0x0026
            X.M53 r0 = X.M53.NONE
        L_0x0026:
            java.lang.String r1 = r0.getNativeProtocolAudience()
            java.lang.String r0 = "default_audience"
            r3.putString(r0, r1)
            java.lang.String r0 = r9.LJFF
            java.lang.String r1 = r8.LIZ((java.lang.String) r0)
            java.lang.String r0 = "state"
            r3.putString(r0, r1)
            X.M24 r0 = com.facebook.AccessToken.LIZ
            com.facebook.AccessToken r0 = r0.LIZ()
            if (r0 != 0) goto L_0x00a0
            r7 = 0
        L_0x0043:
            java.lang.String r4 = "1"
            java.lang.String r5 = "0"
            java.lang.String r6 = "access_token"
            if (r7 == 0) goto L_0x008f
            com.facebook.login.LoginClient r0 = r8.LJFF()
            X.1hK r2 = r0.LIZ()
            if (r2 != 0) goto L_0x0059
            android.content.Context r2 = com.facebook.s.LJFF()
        L_0x0059:
            r1 = 0
            java.lang.String r0 = "com.facebook.login.AuthorizationClient.WebViewAuthHandler.TOKEN_STORE_KEY"
            android.content.SharedPreferences r2 = X.8uQ.LIZ(r2, r0, r1)
            java.lang.String r1 = "TOKEN"
            java.lang.String r0 = ""
            java.lang.String r0 = r2.getString(r1, r0)
            boolean r0 = kotlin.h.b.n.LIZ(r7, r0)
            if (r0 == 0) goto L_0x008f
            r3.putString(r6, r7)
            r8.LIZ(r6, r4)
        L_0x0074:
            long r0 = java.lang.System.currentTimeMillis()
            java.lang.String r1 = java.lang.String.valueOf(r0)
            java.lang.String r0 = "cbt"
            r3.putString(r0, r1)
            boolean r0 = X.M3K.LIZIZ()
            if (r0 == 0) goto L_0x008d
        L_0x0087:
            java.lang.String r0 = "ies"
            r3.putString(r0, r4)
            return r3
        L_0x008d:
            r4 = r5
            goto L_0x0087
        L_0x008f:
            com.facebook.login.LoginClient r0 = r8.LJFF()
            X.1hK r0 = r0.LIZ()
            if (r0 == 0) goto L_0x009c
            X.C5478M1t.LIZIZ((android.content.Context) r0)     // Catch:{ Exception -> 0x009c }
        L_0x009c:
            r8.LIZ(r6, r5)
            goto L_0x0074
        L_0x00a0:
            java.lang.String r7 = r0.LJFF
            goto L_0x0043
        */
        throw new UnsupportedOperationException("Method not decompiled: com.facebook.login.WebLoginMethodHandler.LIZIZ(com.facebook.login.LoginClient$Request):android.os.Bundle");
    }

    public final Bundle LIZ(Bundle bundle, LoginClient.Request request) {
        String name;
        String str;
        M12.LIZ((Object) bundle, (Object) request);
        bundle.putString("redirect_uri", LIZJ());
        if (request.LIZIZ()) {
            bundle.putString("app_id", request.LJ);
        } else {
            bundle.putString("client_id", request.LJ);
        }
        bundle.putString("e2e", LoginClient.LIZ.LIZ());
        if (request.LIZIZ()) {
            bundle.putString("response_type", "token,signed_request,graph_domain,granted_scopes");
        } else {
            if (request.LIZJ.contains("openid")) {
                bundle.putString("nonce", request.LJIILL);
            }
            bundle.putString("response_type", "id_token,token,signed_request,graph_domain");
        }
        bundle.putString("code_challenge", request.LJIIZILJ);
        M5B m5b = request.LJIJ;
        if (m5b == null) {
            name = null;
        } else {
            name = m5b.name();
        }
        bundle.putString("code_challenge_method", name);
        bundle.putString("return_scopes", "true");
        bundle.putString("auth_type", request.LJIIIIZZ);
        bundle.putString("login_behavior", request.LIZIZ.name());
        bundle.putString("sdk", n.LIZ("android-", "13.1.0"));
        if (LIZLLL() != null) {
            bundle.putString("sso", LIZLLL());
        }
        String str2 = "1";
        if (s.LJI) {
            str = str2;
        } else {
            str = "0";
        }
        bundle.putString("cct_prefetching", str);
        if (request.LJIILIIL) {
            bundle.putString("fx_app", request.LJIIL.toString());
        }
        if (request.LJIILJJIL) {
            bundle.putString("skip_dedupe", "true");
        }
        if (request.LJIIJ != null) {
            bundle.putString("messenger_page_id", request.LJIIJ);
            if (!request.LJIIJJI) {
                str2 = "0";
            }
            bundle.putString("reset_messenger_state", str2);
        }
        return bundle;
    }

    public final void LIZ(LoginClient.Request request, Bundle bundle, M5M m5m) {
        LoginClient.Result result;
        String message;
        String str;
        M12.LIZ((Object) request);
        LoginClient LJFF2 = LJFF();
        this.LIZ = null;
        if (bundle != null) {
            if (bundle.containsKey("e2e")) {
                this.LIZ = bundle.getString("e2e");
            }
            try {
                AccessToken LIZ2 = LoginMethodHandler.LIZJ.LIZ(request.LIZJ, bundle, LIZIZ(), request.LJ);
                result = LoginClient.Result.LIZ.LIZ(LJFF2.LJII, LIZ2, LoginMethodHandler.LIZJ.LIZIZ(bundle, request.LJIILL));
                if (LJFF2.LIZ() != null) {
                    try {
                        CookieSyncManager.createInstance(LJFF2.LIZ()).sync();
                    } catch (Exception unused) {
                    }
                    if (LIZ2 != null) {
                        String str2 = LIZ2.LJFF;
                        Context LIZ3 = LJFF().LIZ();
                        if (LIZ3 == null) {
                            LIZ3 = s.LJFF();
                        }
                        8uQ.LIZ(LIZ3, "com.facebook.login.AuthorizationClient.WebViewAuthHandler.TOKEN_STORE_KEY", 0).edit().putString("TOKEN", str2).apply();
                    }
                }
            } catch (M5M e) {
                result = LoginClient.Result.LIZ.LIZ(LJFF2.LJII, (String) null, e.getMessage(), (String) null);
            }
        } else if (m5m instanceof M5G) {
            result = LoginClient.Result.LIZ.LIZ(LJFF2.LJII, "User canceled log in.");
        } else {
            this.LIZ = null;
            if (m5m == null) {
                message = null;
            } else {
                message = m5m.getMessage();
            }
            if (m5m instanceof C5461M1c) {
                FacebookRequestError requestError = ((C5461M1c) m5m).getRequestError();
                str = String.valueOf(requestError.LIZJ);
                message = requestError.toString();
            } else {
                str = null;
            }
            result = LoginClient.Result.LIZ.LIZ(LJFF2.LJII, (String) null, message, str);
        }
        if (!C5478M1t.LIZ(this.LIZ)) {
            LIZIZ(this.LIZ);
        }
        LJFF2.LIZ(result);
    }
}
