package com.facebook.login;

import X.C4105Lea;
import X.C5461M1c;
import X.C5463M1e;
import X.C5478M1t;
import X.C5567M5e;
import X.M12;
import X.M44;
import X.M5M;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcel;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.facebook.FacebookRequestError;
import com.facebook.login.LoginClient;
import com.facebook.s;
import kotlin.h.b.n;

public abstract class NativeAppLoginMethodHandler extends LoginMethodHandler {
    public final M44 LIZ = M44.FACEBOOK_APPLICATION_WEB;

    static {
        Covode.recordClassIndex(41958);
    }

    public M44 LIZLLL() {
        return this.LIZ;
    }

    public static Bundle LIZ(Intent intent) {
        try {
            return intent.getExtras();
        } catch (Exception unused) {
            return null;
        }
    }

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

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

    private String LIZ(Bundle bundle) {
        if (bundle != null) {
            String string = bundle.getString("error");
            if (string != null) {
                return string;
            }
            if (bundle != null) {
                return bundle.getString("error_type");
            }
        }
        return null;
    }

    private String LIZIZ(Bundle bundle) {
        if (bundle != null) {
            String string = bundle.getString("error_message");
            if (string != null) {
                return string;
            }
            if (bundle != null) {
                return bundle.getString("error_description");
            }
        }
        return null;
    }

    private final void LIZ(LoginClient.Result result) {
        if (result != null) {
            LJFF().LIZ(result);
        } else {
            LJFF().LIZLLL();
        }
    }

    public static Object LIZ(Bundle bundle, String str) {
        try {
            return bundle.get(str);
        } catch (Exception | OutOfMemoryError unused) {
            return null;
        }
    }

    private void LIZ(LoginClient.Request request, Bundle bundle) {
        M12.LIZ((Object) request, (Object) bundle);
        try {
            LIZ(LoginClient.Result.LIZ.LIZ(request, LoginMethodHandler.LIZJ.LIZ(request.LIZJ, bundle, LIZLLL(), request.LJ), LoginMethodHandler.LIZJ.LIZIZ(bundle, request.LJIILL)));
        } catch (M5M e) {
            LIZ(LoginClient.Result.LIZ.LIZ(request, (String) null, e.getMessage(), (String) null));
        }
    }

    public final boolean LIZ(Intent intent, int i) {
        if (intent == null) {
            return false;
        }
        try {
            Fragment fragment = LJFF().LIZLLL;
            if (fragment == null) {
                return true;
            }
            fragment.startActivityForResult(intent, i);
            return true;
        } catch (Exception unused) {
            return false;
        }
    }

    public static final /* synthetic */ void LIZ(NativeAppLoginMethodHandler nativeAppLoginMethodHandler, LoginClient.Request request, Bundle bundle) {
        M12.LIZ(nativeAppLoginMethodHandler, request, bundle);
        try {
            nativeAppLoginMethodHandler.LIZIZ(request, bundle);
            nativeAppLoginMethodHandler.LIZ(request, bundle);
        } catch (C5461M1c e) {
            FacebookRequestError requestError = e.getRequestError();
            nativeAppLoginMethodHandler.LIZ(request, requestError.LJ, requestError.LIZ(), String.valueOf(requestError.LIZJ));
        } catch (M5M e2) {
            nativeAppLoginMethodHandler.LIZ(request, (String) null, e2.getMessage(), (String) null);
        }
    }

    public final boolean LIZ(int i, int i2, Intent intent) {
        Object LIZ2;
        LoginClient.Request request = LJFF().LJII;
        if (intent == null) {
            LIZ(LoginClient.Result.LIZ.LIZ(request, "Operation canceled"));
        } else {
            String str = null;
            if (i2 == 0) {
                M12.LIZ((Object) intent);
                Bundle LIZ3 = LIZ(intent);
                String LIZ4 = LIZ(LIZ3);
                if (!(LIZ3 == null || (LIZ2 = LIZ(LIZ3, "error_code")) == null)) {
                    str = LIZ2.toString();
                }
                if (n.LIZ("CONNECTION_FAILURE", str)) {
                    LIZ(LoginClient.Result.LIZ.LIZ(request, LIZ4, LIZIZ(LIZ3), str));
                } else {
                    LIZ(LoginClient.Result.LIZ.LIZ(request, LIZ4));
                }
            } else if (i2 != -1) {
                LIZ(LoginClient.Result.LIZ.LIZ(request, "Unexpected resultCode from authorization.", (String) null, (String) null));
            } else {
                Bundle LIZ5 = LIZ(intent);
                if (LIZ5 == null) {
                    LIZ(LoginClient.Result.LIZ.LIZ(request, "Unexpected null from returned authorization data.", (String) null, (String) null));
                    return true;
                }
                String LIZ6 = LIZ(LIZ5);
                Object LIZ7 = LIZ(LIZ5, "error_code");
                if (LIZ7 != null) {
                    str = LIZ7.toString();
                }
                String LIZIZ = LIZIZ(LIZ5);
                String string = LIZ5.getString("e2e");
                if (!C5478M1t.LIZ(string)) {
                    LIZIZ(string);
                }
                if (LIZ6 != null || str != null || LIZIZ != null || request == null) {
                    LIZ(request, LIZ6, LIZIZ, str);
                } else if (!LIZ5.containsKey("code") || C5478M1t.LIZ(LIZ5.getString("code"))) {
                    LIZ(request, LIZ5);
                } else {
                    s.LIZ().execute(new C5567M5e(this, request, LIZ5));
                }
            }
        }
        return true;
    }

    private void LIZ(LoginClient.Request request, String str, String str2, String str3) {
        if (str != null && n.LIZ(str, "logged_out")) {
            CustomTabLoginMethodHandler.LIZIZ = true;
            LIZ((LoginClient.Result) null);
        } else if (C4105Lea.LIZ(C5463M1e.LIZ(), str)) {
            LIZ((LoginClient.Result) null);
        } else if (C4105Lea.LIZ(C5463M1e.LIZIZ(), str)) {
            LIZ(LoginClient.Result.LIZ.LIZ(request, (String) null));
        } else {
            LIZ(LoginClient.Result.LIZ.LIZ(request, str, str2, str3));
        }
    }
}
