package com.ss.android.ugc.aweme.services;

import X.0CB;
import X.0CH;
import X.2kM;
import X.3i8;
import X.486;
import X.487;
import X.6Is;
import X.7lW;
import X.C1568RkC;
import X.C1590RkY;
import X.C1594Rkc;
import X.C1598Rkg;
import X.C1600Rki;
import X.C2133RtJ;
import X.C2160Rtk;
import X.C2162Rtm;
import X.C2449RyP;
import X.C2461Ryb;
import X.C2469Ryj;
import X.JzZ;
import X.Lnj;
import X.M12;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.router.SmartRoute;
import com.bytedance.router.SmartRouter;
import com.ss.android.ugc.aweme.IBindService;
import com.ss.android.ugc.aweme.account.login.authorize.AuthorizeActivity;
import com.ss.android.ugc.aweme.account.login.v2.base.CommonFlowActivity;
import com.ss.android.ugc.aweme.account.ui.BindOrModifyPhoneActivity;
import java.io.Serializable;
import java.util.ArrayList;
import kotlin.h.b.n;

public class BindService extends BaseBindService implements 6Is {
    public JzZ mVerificationService;

    static {
        Covode.recordClassIndex(105027);
    }

    public void onStateChanged(0CH r1, 0CB r2) {
        super.onStateChanged(r1, r2);
    }

    public void setAuthorzieBindResult(C2461Ryb ryb) {
    }

    public void showThirdPartyAccountManagerActivity(Activity activity) {
    }

    public JzZ getVerificationService() {
        if (this.mVerificationService == null) {
            this.mVerificationService = new VerificationService();
        }
        return this.mVerificationService;
    }

    public static Context INVOKEVIRTUAL_com_ss_android_ugc_aweme_services_BindService_com_ss_android_ugc_aweme_lancet_launch_ApplicationContextLancet_getApplicationContext(Activity activity) {
        Context applicationContext = activity.getApplicationContext();
        if (7lW.LIZJ && applicationContext == null) {
            return 7lW.LIZ;
        }
        return applicationContext;
    }

    public static IBindService createIBindServicebyMonsterPlugin(boolean z) {
        MethodCollector.i(157);
        IBindService iBindService = (IBindService) Lnj.LIZ(IBindService.class, z);
        if (iBindService != null) {
            MethodCollector.o(157);
            return iBindService;
        }
        Object LIZIZ = Lnj.LIZIZ(IBindService.class, z);
        if (LIZIZ != null) {
            IBindService iBindService2 = (IBindService) LIZIZ;
            MethodCollector.o(157);
            return iBindService2;
        }
        if (Lnj.am == null) {
            synchronized (IBindService.class) {
                try {
                    if (Lnj.am == null) {
                        Lnj.am = new BindService();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(157);
                    throw th;
                }
            }
        }
        BaseBindService baseBindService = (BaseBindService) Lnj.am;
        MethodCollector.o(157);
        return baseBindService;
    }

    public static void INVOKEVIRTUAL_com_ss_android_ugc_aweme_services_BindService_com_ss_android_ugc_tiktok_security_lancet_ContextLancet_startActivity(Activity activity, Intent intent) {
        3i8.LIZ(intent, activity);
        activity.startActivity(intent);
    }

    public static void INVOKEVIRTUAL_com_ss_android_ugc_aweme_services_BindService_com_ss_android_ugc_tiktok_security_lancet_ContextLancet_startActivityForResult(Activity activity, Intent intent, int i) {
        3i8.LIZ(intent, activity);
        activity.startActivityForResult(intent, i);
    }

    public void bindPlatform(Activity activity, String str, Bundle bundle) {
        super.bindPlatform(activity, str, bundle);
        Intent intent = new Intent(activity, AuthorizeActivity.class);
        intent.putExtra("platform", str);
        intent.putExtra("is_auth_for_bind", true);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        INVOKEVIRTUAL_com_ss_android_ugc_aweme_services_BindService_com_ss_android_ugc_tiktok_security_lancet_ContextLancet_startActivityForResult(activity, intent, 10);
    }

    public void onUnbindResult(C2449RyP ryP, int i, String str) {
        int i2;
        if (ryP != null) {
            Bundle bundle = new Bundle();
            bundle.putInt("error_code", i);
            bundle.putString("error_message", str);
            if (i == 0) {
                i2 = 1;
            } else {
                i2 = 3;
            }
            ryP.onResult(18, i2, bundle);
        }
    }

    public void unbindPlatform(final Activity activity, String str, final C2449RyP ryP) {
        super.unbindPlatform(activity, str, ryP);
        C1598Rkg.LIZIZ(INVOKEVIRTUAL_com_ss_android_ugc_aweme_services_BindService_com_ss_android_ugc_aweme_lancet_launch_ApplicationContextLancet_getApplicationContext(activity)).LIZ(str, (C1568RkC<C1590RkY>) new C1568RkC<C1590RkY>() {
            static {
                Covode.recordClassIndex(105031);
            }

            public void onResponse(C1590RkY rkY) {
                if (rkY.LIZIZ) {
                    C1598Rkg.LIZ(activity).LIZ("normal", (C1594Rkc) new C1594Rkc() {
                        static {
                            Covode.recordClassIndex(105032);
                        }

                        public void onSuccess(C1600Rki rki) {
                            C2469Ryj.LIZ(rki.LJIIIZ);
                            BindService.this.onUnbindResult(ryP, 0, (String) null);
                        }

                        public void onError(C1600Rki rki, int i) {
                            BindService.this.onUnbindResult(ryP, 0, (String) null);
                        }
                    });
                } else {
                    BindService.this.onUnbindResult(ryP, rkY.LIZLLL, rkY.LJFF);
                }
            }
        });
    }

    public void changeUnverifiedEmail(Activity activity, String str, Bundle bundle) {
        Bundle bundle2 = bundle;
        Activity activity2 = activity;
        super.changeUnverifiedEmail(activity2, str, bundle2);
        if (bundle2 == null) {
            bundle2 = new Bundle();
        }
        bundle2.putString("enter_from", str);
        bundle2.putString("enter_from_item", str + "_change_unverified_email");
        CommonFlowActivity.LJII.LIZ(activity2, C2162Rtm.INPUT_EMAIL_CHANGE, C2160Rtk.CHANGE_EMAIL, bundle2, (C2449RyP) null, false);
    }

    public void unbindPhone(Activity activity, ArrayList<String> arrayList, String str) {
        super.unbindPhone(activity, arrayList, str);
        M12.LIZ(activity, arrayList, str);
        SmartRoute buildRoute = SmartRouter.buildRoute((Context) activity, "//account/phone_or_email/unbind");
        buildRoute.withParam("enter_from", str);
        buildRoute.withParam("current_scene", C2160Rtk.UNBIND_PHONE.getValue());
        buildRoute.withParam("next_page", C2162Rtm.UNBIND_PHONE_CONFIRM.getValue());
        buildRoute.withParam("extra_eligible_login_methods", (Serializable) arrayList);
        buildRoute.open();
    }

    public static final /* synthetic */ void lambda$setPassword$1$BindService(C2449RyP ryP, int i, int i2, Object obj) {
        if (ryP != null) {
            ryP.onResult(i, 1, obj);
        }
    }

    public void bindMobile(Activity activity, String str, Bundle bundle, C2449RyP ryP) {
        bindMobile(activity, str, "", bundle, ryP);
    }

    public void modifyMobile(Activity activity, String str, Bundle bundle, C2449RyP ryP) {
        modifyMobileInner(activity, str, bundle, 0, ryP);
    }

    public void modifyMobileVerifyByEmail(Activity activity, String str, Bundle bundle, C2449RyP ryP) {
        modifyMobileInner(activity, str, bundle, 1, ryP);
    }

    public void modifyMobileVerifyByPassword(Activity activity, String str, Bundle bundle, C2449RyP ryP) {
        modifyMobileInner(activity, str, bundle, 2, ryP);
    }

    public void unbindEmail(Activity activity, boolean z, ArrayList<String> arrayList, String str) {
        super.unbindEmail(activity, z, arrayList, str);
        M12.LIZ(activity, arrayList, str);
        SmartRoute buildRoute = SmartRouter.buildRoute((Context) activity, "//account/phone_or_email/unbind");
        buildRoute.withParam("enter_from", str);
        buildRoute.withParam("current_scene", C2160Rtk.UNBIND_EMAIL.getValue());
        buildRoute.withParam("next_page", C2162Rtm.UNBIND_EMAIL_CONFIRM.getValue());
        buildRoute.withParam("is_email_verified", z);
        buildRoute.withParam("extra_eligible_login_methods", (Serializable) arrayList);
        buildRoute.open();
    }

    public void changeEmail(Activity activity, String str, Bundle bundle, C2449RyP ryP) {
        Bundle bundle2 = bundle;
        Activity activity2 = activity;
        C2449RyP ryP2 = ryP;
        super.changeEmail(activity2, str, bundle2, ryP2);
        if (bundle2 == null) {
            bundle2 = new Bundle();
        }
        bundle2.putString("enter_from", str);
        bundle2.putString("enter_from_item", str + "_change_email");
        C2133RtJ.LIZ.LIZ(bundle2, C2469Ryj.LJFF().getEmail());
        CommonFlowActivity.LJII.LIZ(activity2, C2162Rtm.VERIFY_EMAIL_BEFORE_CHANGE, C2160Rtk.CHANGE_EMAIL, bundle2, ryP2, false);
    }

    public void verifyEmail(Activity activity, String str, Bundle bundle, C2449RyP ryP) {
        Bundle bundle2 = bundle;
        Activity activity2 = activity;
        C2449RyP ryP2 = ryP;
        super.verifyEmail(activity2, str, bundle2, ryP2);
        if (bundle2 == null) {
            bundle2 = new Bundle();
        }
        bundle2.putString("enter_from", str);
        bundle2.putString("enter_from_item", str + "_verify_email");
        bundle2.putString("enter_method", "email_verification");
        String email = C2469Ryj.LJFF().getEmail();
        if (!TextUtils.isEmpty(email)) {
            C2133RtJ.LIZ.LIZ(bundle2, email);
        }
        CommonFlowActivity.LJII.LIZ(activity2, C2162Rtm.CONFIRM_EMAIL_BEFORE_VERIFY, C2160Rtk.VERIFY, bundle2, ryP2, false);
    }

    public void bindMobileOrEmail(Activity activity, String str, String str2, Bundle bundle, C2449RyP ryP) {
        Bundle bundle2 = bundle;
        if (bundle2 == null) {
            bundle2 = new Bundle();
        }
        bundle2.putBoolean("use_phone", true);
        bundle2.putBoolean("use_email", true);
        bindMobile(activity, str, str2, bundle2, ryP);
    }

    public void bindMobileOrEmailAndSetPwd(Activity activity, String str, String str2, Bundle bundle, C2449RyP ryP) {
        String str3 = str;
        Activity activity2 = activity;
        String str4 = str2;
        bindMobileOrEmail(activity2, str3, str4, bundle, new BindService$$Lambda$0(this, ryP, activity2, str3, str4));
    }

    public void setPassword(Activity activity, String str, String str2, String str3, C2449RyP ryP) {
        Activity activity2 = activity;
        String str4 = str2;
        C2469Ryj.LIZIZ.LJIIIZ().setPasswordForMT(activity2, str, str4, str3, (Bundle) null, new BindService$$Lambda$1(ryP));
    }

    private void modifyMobileInner(Activity activity, String str, Bundle bundle, int i, C2449RyP ryP) {
        C2162Rtm rtm;
        super.modifyMobile(activity, str, bundle, ryP);
        M12.LIZ(activity);
        if (i == 1) {
            rtm = C2162Rtm.EMAIL_SMS_VERIFY;
        } else if (i != 2) {
            rtm = C2162Rtm.PHONE_SMS_VERIFY;
        } else {
            rtm = C2162Rtm.VERIFY_PASSWORD;
        }
        Intent putExtra = new Intent(activity, BindOrModifyPhoneActivity.class).putExtra("current_scene", C2160Rtk.MODIFY_PHONE.getValue()).putExtra("next_page", rtm.getValue()).putExtra("enter_method", "change_bind_phone_click");
        n.LIZIZ(putExtra, "");
        if (!TextUtils.isEmpty(str)) {
            putExtra.putExtra("ENTER_REASON", str);
        }
        if (bundle != null) {
            putExtra.putExtras(bundle);
        }
        INVOKEVIRTUAL_com_ss_android_ugc_aweme_services_BindService_com_ss_android_ugc_tiktok_security_lancet_ContextLancet_startActivity(activity, putExtra);
    }

    public void bindEmail(Activity activity, String str, String str2, Bundle bundle, C2449RyP ryP) {
        Bundle bundle2 = bundle;
        Activity activity2 = activity;
        C2449RyP ryP2 = ryP;
        super.bindEmail(activity2, str, str2, bundle2, ryP2);
        if (bundle2 == null) {
            bundle2 = new Bundle();
        }
        bundle2.putString("enter_from", str);
        bundle2.putString("enter_from_item", str + "_bind_email");
        if (str2 != null) {
            bundle2.putString("enter_method", str2);
        }
        if ("security_alert".equals(str)) {
            bundle2.putInt("email_source", 486.DYABindEmailSourceTypeSecurityAlertToast.getValue());
            bundle2.putInt("phone_number_source", 487.DYABindPhoneNumberSourceTypeTypeSecurityAlertToast.getValue());
        }
        CommonFlowActivity.LJII.LIZ(activity2, C2162Rtm.INPUT_EMAIL_BIND, C2160Rtk.BIND_EMAIL, bundle2, ryP2, false);
    }

    public void verifyEmailForTicket(Activity activity, String str, String str2, Bundle bundle, C2449RyP ryP) {
        Bundle bundle2 = bundle;
        Activity activity2 = activity;
        C2449RyP ryP2 = ryP;
        super.verifyEmailForTicket(activity2, str, str2, bundle2, ryP2);
        if (bundle2 == null) {
            bundle2 = new Bundle();
        }
        if (!TextUtils.isEmpty(str)) {
            bundle2.putString("enter_from", str);
        }
        if (!TextUtils.isEmpty(str2)) {
            bundle2.putString("enter_method", str2);
        }
        C2133RtJ.LIZ.LIZ(bundle2, C2469Ryj.LJFF().getEmail());
        CommonFlowActivity.LJII.LIZ(activity2, C2162Rtm.VERIFY_EMAIL_FOR_TICKET, C2160Rtk.VERIFY, bundle2, ryP2, false);
    }

    public void verifyMobileForTicket(Activity activity, String str, String str2, Bundle bundle, C2449RyP ryP) {
        Bundle bundle2 = bundle;
        Activity activity2 = activity;
        C2449RyP ryP2 = ryP;
        super.verifyMobileForTicket(activity2, str, str2, bundle2, ryP2);
        if (bundle2 == null) {
            bundle2 = new Bundle();
        }
        if (!TextUtils.isEmpty(str)) {
            bundle2.putString("enter_from", str);
        }
        if (!TextUtils.isEmpty(str2)) {
            bundle2.putString("enter_method", str2);
        }
        C2133RtJ.LIZ.LIZIZ(bundle2, C2469Ryj.LJFF().getBindPhone());
        CommonFlowActivity.LJII.LIZ(activity2, C2162Rtm.VERIFY_PHONE_FOR_TICKET, C2160Rtk.VERIFY, bundle2, ryP2, false);
    }

    public void bindMobile(Activity activity, String str, String str2, Bundle bundle, C2449RyP ryP) {
        super.bindMobile(activity, str, str2, bundle, ryP);
        if (bundle == null) {
            bundle = new Bundle();
        }
        int i = bundle.getInt("current_scene", -1);
        if (i != -1) {
            bundle.putInt("last_scene", i);
            bundle.remove("current_scene");
            bundle.remove("next_page");
            bundle.remove("current_page");
        }
        M12.LIZ(activity);
        Intent putExtra = new Intent(activity, BindOrModifyPhoneActivity.class).putExtra("current_scene", C2160Rtk.BIND_PHONE.getValue()).putExtra("next_page", C2162Rtm.INPUT_PHONE_BIND.getValue()).putExtra("enter_method", "first_bind_phone_click");
        n.LIZIZ(putExtra, "");
        putExtra.putExtras(bundle);
        if (!TextUtils.isEmpty(str)) {
            putExtra.putExtra("ENTER_REASON", str);
        }
        if (!TextUtils.isEmpty(str2)) {
            putExtra.putExtra("enter_method", str2);
        }
        if ("security_alert".equals(str)) {
            putExtra.putExtra("email_source", 486.DYABindEmailSourceTypeSecurityAlertToast.getValue());
            putExtra.putExtra("phone_number_source", 487.DYABindPhoneNumberSourceTypeTypeSecurityAlertToast.getValue());
        }
        INVOKEVIRTUAL_com_ss_android_ugc_aweme_services_BindService_com_ss_android_ugc_tiktok_security_lancet_ContextLancet_startActivity(activity, putExtra);
    }

    public void verifyEmailWithWorkflowTokenForTicket(Activity activity, String str, String str2, String str3, Bundle bundle, C2449RyP ryP) {
        Bundle bundle2 = bundle;
        String str4 = str;
        Activity activity2 = activity;
        String str5 = str2;
        C2449RyP ryP2 = ryP;
        super.verifyEmailForTicket(activity2, str4, str5, bundle2, ryP2);
        if (bundle2 == null) {
            bundle2 = new Bundle();
        }
        if (!TextUtils.isEmpty(str4)) {
            bundle2.putString("enter_from", str4);
        }
        if (!TextUtils.isEmpty(str5)) {
            bundle2.putString("enter_method", str5);
        }
        C2133RtJ.LIZ.LIZ(bundle2, str3);
        CommonFlowActivity.LJII.LIZ(activity2, C2162Rtm.VERIFY_EMAIL_FOR_TICKET, C2160Rtk.VERIFY, bundle2, ryP2, false);
    }

    public void verifyMobileWithWorkflowTokenForTicket(Activity activity, String str, String str2, String str3, Bundle bundle, C2449RyP ryP) {
        Bundle bundle2 = bundle;
        String str4 = str;
        Activity activity2 = activity;
        String str5 = str2;
        C2449RyP ryP2 = ryP;
        super.verifyMobileForTicket(activity2, str4, str5, bundle2, ryP2);
        if (bundle2 == null) {
            bundle2 = new Bundle();
        }
        if (!TextUtils.isEmpty(str4)) {
            bundle2.putString("enter_from", str4);
        }
        if (!TextUtils.isEmpty(str5)) {
            bundle2.putString("enter_method", str5);
        }
        C2133RtJ.LIZ.LIZIZ(bundle2, str3);
        CommonFlowActivity.LJII.LIZ(activity2, C2162Rtm.VERIFY_PHONE_FOR_TICKET, C2160Rtk.VERIFY, bundle2, ryP2, false);
    }

    public final /* synthetic */ void lambda$bindMobileOrEmailAndSetPwd$0$BindService(C2449RyP ryP, Activity activity, String str, String str2, int i, int i2, Object obj) {
        final int i3 = i2;
        final Object obj2 = obj;
        final C2449RyP ryP2 = ryP;
        final int i4 = i;
        if (i3 == 1) {
            if (i4 != 7) {
                if (0 == 0) {
                    final Activity activity2 = activity;
                    final String str3 = str;
                    final String str4 = str2;
                    C2469Ryj.LIZIZ.LJFF().getSetPasswordStatus(new 2kM("email") {
                        static {
                            Covode.recordClassIndex(105030);
                        }

                        public void onUpdateSuccess(boolean z) {
                            if (!z) {
                                BindService.this.setPassword(activity2, "email", str3, str4, ryP2);
                                return;
                            }
                            C2449RyP ryP = ryP2;
                            if (ryP != null) {
                                ryP.onResult(i4, i3, obj2);
                            }
                        }

                        public void onUpdateFailed(String str) {
                            if (!C2469Ryj.LIZIZ.LJFF().hasCurUserSetPassword()) {
                                BindService.this.setPassword(activity2, "email", str3, str4, ryP2);
                                return;
                            }
                            C2449RyP ryP = ryP2;
                            if (ryP != null) {
                                ryP.onResult(i4, i3, obj2);
                            }
                        }
                    });
                    return;
                }
            }
            if (ryP2 != null) {
                ryP2.onResult(i4, i3, obj2);
            }
        } else if (ryP2 != null) {
            ryP2.onResult(i4, i3, obj2);
        }
    }
}
