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


package X;

import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.l;
import com.google.gson.p;
import com.ss.android.ugc.aweme.account.login.model.AccountPassLoginMethod;
import com.ss.android.ugc.aweme.account.login.model.BaseLoginMethod;
import com.ss.android.ugc.aweme.account.login.model.CommonUserInfo;
import com.ss.android.ugc.aweme.account.login.model.LoginMethodName;
import com.ss.android.ugc.aweme.account.login.model.PhoneLoginMethod;
import com.ss.android.ugc.aweme.account.login.model.TPLoginMethod;
import com.ss.android.ugc.aweme.account.login.model.TPUserInfo;
import com.ss.android.ugc.aweme.profile.model.User;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
import kotlin.g.b.m;

/* renamed from: X.3Or */
public final class C83043Or {
    public static boolean LIZ = false;
    public static List<BaseLoginMethod> LIZIZ;
    public static volatile boolean LIZJ = true;
    public static final C83043Or LIZLLL;

    static {
        Covode.recordClassIndex(44608);
        C83043Or r1 = new C83043Or();
        LIZLLL = r1;
        LIZIZ = new ArrayList();
        LIZIZ = r1.LIZ();
        r1.LJ();
    }

    public static final void LIZ(C20300rL r5) {
        if (r5 != null) {
            List<BaseLoginMethod> list = LIZIZ;
            ArrayList<BaseLoginMethod> arrayList = new ArrayList();
            for (T t : list) {
                if (m.LIZ((Object) t.getUid(), (Object) r5.LIZ)) {
                    arrayList.add(t);
                }
            }
            for (BaseLoginMethod baseLoginMethod : arrayList) {
                baseLoginMethod.updateUserInfo(r5);
            }
            LIZLLL.LJFF();
        }
    }

    public static final void LIZ(User user) {
        C21090sc.LIZ(user);
        List<BaseLoginMethod> list = LIZIZ;
        ArrayList<BaseLoginMethod> arrayList = new ArrayList();
        for (T t : list) {
            if (m.LIZ((Object) t.getUid(), (Object) user.getUid())) {
                arrayList.add(t);
            }
        }
        for (BaseLoginMethod baseLoginMethod : arrayList) {
            baseLoginMethod.updateUserInfo(user);
        }
        LIZLLL.LJFF();
    }

    public static final void LIZ(String str) {
        C21090sc.LIZ(str);
        AnonymousClass1ZP.LIZIZ((List) LIZIZ, (AnonymousClass1IM) new AnonymousClass3P0(str));
        LIZLLL.LJFF();
    }

    public static final void LIZ(String str, long j, boolean z) {
        Object next;
        C21090sc.LIZ(str);
        ArrayList arrayList = new ArrayList();
        for (BaseLoginMethod baseLoginMethod : LIZIZ) {
            if (m.LIZ((Object) baseLoginMethod.getUid(), (Object) str)) {
                arrayList.add(baseLoginMethod);
            }
        }
        if (!z) {
            j += C13920h3.LIZIZ.LJIIIZ().isOneKeyLoginExprimentEnable() ? 15552000000L : 2592000000L;
        }
        Iterator it = arrayList.iterator();
        if (!it.hasNext()) {
            next = null;
        } else {
            next = it.next();
            if (it.hasNext()) {
                Date expires = ((BaseLoginMethod) next).getExpires();
                do {
                    Object next2 = it.next();
                    Date expires2 = ((BaseLoginMethod) next2).getExpires();
                    if (expires.compareTo((Object) expires2) < 0) {
                        next = next2;
                        expires = expires2;
                    }
                } while (it.hasNext());
            }
        }
        BaseLoginMethod baseLoginMethod2 = (BaseLoginMethod) next;
        if (baseLoginMethod2 != null) {
            baseLoginMethod2.setExpires(new Date(j));
        }
    }

    public static final void LIZIZ(BaseLoginMethod baseLoginMethod) {
        T t;
        String str;
        Integer LIZ2;
        String str2;
        Long lastActiveTime;
        C21090sc.LIZ(baseLoginMethod);
        if (baseLoginMethod.getLoginMethodName() == LoginMethodName.DEFAULT && (lastActiveTime = baseLoginMethod.getLastActiveTime()) != null && lastActiveTime.longValue() == -1) {
            baseLoginMethod.setLastActiveTime(Long.valueOf(System.currentTimeMillis()));
        }
        Iterator<T> it = LIZIZ.iterator();
        while (true) {
            if (!it.hasNext()) {
                t = null;
                break;
            }
            t = it.next();
            if (m.LIZ((Object) t.getUid(), (Object) baseLoginMethod.getUid())) {
                break;
            }
        }
        T t2 = t;
        if (t2 != null) {
            baseLoginMethod.setAllowOneKeyLogin(t2.getAllowOneKeyLogin());
        } else {
            AnonymousClass1GW r1 = AnonymousClass1GW.LJIIJ;
            C20370rS LJFF = r1.LJFF(r1.LJ());
            String str3 = "";
            if (LJFF == null || (str = LJFF.LJFF) == null) {
                str = str3;
            }
            boolean z = false;
            if (!TextUtils.isEmpty(str)) {
                if (!(LJFF == null || (str2 = LJFF.LJFF) == null)) {
                    str3 = str2;
                }
                if (!(str3 == null || str3.length() == 0 || (LIZ2 = C57072Mu.LIZ.LIZ(str3, "save_login")) == null || LIZ2.intValue() != 1)) {
                    z = true;
                }
            }
            baseLoginMethod.setAllowOneKeyLogin(Boolean.valueOf(z));
        }
        AnonymousClass1ZP.LIZIZ((List) LIZIZ, (AnonymousClass1IM) new C83123Oz(baseLoginMethod));
        LIZIZ.add(baseLoginMethod);
        LIZLLL.LJFF();
    }

    public static final void LIZIZ(String str, long j) {
        C21090sc.LIZ(str);
        for (T t : LIZIZ) {
            if (m.LIZ((Object) t.getUid(), (Object) str)) {
                t.setLastActiveTime(Long.valueOf(j));
            }
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:58:0x0136, code lost:
        if (r4.intValue() != 1) goto L_0x0080;
     */
    public static final void LIZIZ(List<AnonymousClass2BO> list) {
        boolean z;
        String str;
        String str2;
        C21090sc.LIZ(list);
        AnonymousClass1ZP.LIZIZ((List) LIZIZ, (AnonymousClass1IM) C83093Ow.LIZ);
        for (AnonymousClass2BO r0 : list) {
            Long l = r0.LIZJ;
            long longValue = (l != null ? l.longValue() : System.currentTimeMillis()) * 1000;
            String str3 = r0.LJ;
            if (str3 == null) {
                m.LIZIZ();
            }
            String str4 = r0.LJI;
            if (str4 == null) {
                m.LIZIZ();
            }
            CommonUserInfo commonUserInfo = new CommonUserInfo(str3, str4, r0.LIZIZ, r0.LIZLLL);
            String str5 = r0.LIZIZ;
            String str6 = "";
            if (str5 == null) {
                str5 = str6;
            }
            BaseLoginMethod baseLoginMethod = new BaseLoginMethod(str5, LoginMethodName.DEFAULT, commonUserInfo, new Date(System.currentTimeMillis() + 2592000000L), Long.valueOf(longValue), Long.valueOf(longValue), true, true, null, 256, null);
            if (r0.LJFF != null) {
                Integer num = r0.LJFF.LIZ;
                if (num == null) {
                    z = true;
                } else {
                    z = true;
                }
                if ((num == null || num.intValue() != 2) && (num == null || num.intValue() != 3)) {
                    if ((num != null && num.intValue() == 4) || (num != null && num.intValue() == 5)) {
                        String str7 = r0.LIZIZ;
                        if (str7 == null) {
                            str7 = str6;
                        }
                        LoginMethodName loginMethodName = LoginMethodName.EMAIL_PASS;
                        String str8 = r0.LJFF.LIZJ;
                        if (str8 != null) {
                            str6 = str8;
                        }
                        baseLoginMethod = new AccountPassLoginMethod(str7, loginMethodName, str6, commonUserInfo, Long.valueOf(longValue), Long.valueOf(longValue), Boolean.valueOf(z));
                    } else if (num != null && num.intValue() == 6) {
                        AnonymousClass2BV r2 = r0.LJFF.LJ;
                        if (r2 == null || (str = r2.LIZ) == null) {
                            str = str6;
                        }
                        if (!TextUtils.isEmpty(str)) {
                            TPUserInfo tPUserInfo = new TPUserInfo(r0.LJ, r0.LJI);
                            String str9 = r0.LIZIZ;
                            if (str9 == null) {
                                str9 = str6;
                            }
                            AnonymousClass2BV r02 = r0.LJFF.LJ;
                            if (!(r02 == null || (str2 = r02.LIZ) == null)) {
                                str6 = str2;
                            }
                            baseLoginMethod = new TPLoginMethod(str9, str6, tPUserInfo, false, commonUserInfo, Long.valueOf(longValue), Long.valueOf(longValue), Boolean.valueOf(z));
                        }
                    }
                }
                String str10 = r0.LIZIZ;
                if (str10 != null) {
                    str6 = str10;
                }
                baseLoginMethod = new PhoneLoginMethod(str6, LoginMethodName.PHONE_SMS, new C83103Ox(), commonUserInfo, Long.valueOf(longValue), Long.valueOf(longValue), Boolean.valueOf(z));
            } else {
                z = true;
            }
            baseLoginMethod.setFromReInstallNet(Boolean.valueOf(z));
            baseLoginMethod.setTransToNormal(false);
            LIZIZ.add(baseLoginMethod);
        }
        LIZLLL.LJFF();
    }

    public static final BaseLoginMethod LIZLLL() {
        T next;
        long j;
        long time;
        if (!((AbstractC68912nY) C45211qQ.LIZ(C12260eN.LIZ, AbstractC68912nY.class)).LIZIZ(true)) {
            return new BaseLoginMethod(null, null, null, null, -1L, null, null, null, null, 495, null);
        }
        LIZLLL.LJ();
        if (LIZ) {
            Iterator<BaseLoginMethod> it = LIZIZ.iterator();
            while (it.hasNext()) {
                it.next();
            }
        }
        Iterator<T> it2 = LIZIZ.iterator();
        if (!it2.hasNext()) {
            next = null;
        } else {
            next = it2.next();
            if (it2.hasNext()) {
                T t = next;
                Long lastActiveTime = t.getLastActiveTime();
                if ((lastActiveTime != null ? lastActiveTime.longValue() : -1) > 0) {
                    Long lastActiveTime2 = t.getLastActiveTime();
                    if (lastActiveTime2 == null) {
                        m.LIZIZ();
                    }
                    j = lastActiveTime2.longValue();
                } else {
                    j = t.getExpires().getTime() - 2592000000L;
                }
                do {
                    T next2 = it2.next();
                    T t2 = next2;
                    Long lastActiveTime3 = t2.getLastActiveTime();
                    if ((lastActiveTime3 != null ? lastActiveTime3.longValue() : -1) > 0) {
                        Long lastActiveTime4 = t2.getLastActiveTime();
                        if (lastActiveTime4 == null) {
                            m.LIZIZ();
                        }
                        time = lastActiveTime4.longValue();
                    } else {
                        time = t2.getExpires().getTime() - 2592000000L;
                    }
                    if (j < time) {
                        next = next2;
                        j = time;
                    }
                } while (it2.hasNext());
            }
        }
        T t3 = next;
        return t3 == null ? new BaseLoginMethod(null, null, null, null, -1L, null, null, null, null, 495, null) : t3;
    }

    public final List<BaseLoginMethod> LIZ() {
        ArrayList arrayList = new ArrayList();
        C83063Ot r4 = new C83063Ot(arrayList);
        Gson gson = new Gson();
        JsonElement LIZ2 = new l().LIZ(((AbstractC68912nY) C45211qQ.LIZ(C12260eN.LIZ, AbstractC68912nY.class)).LIZIZ("[]"));
        Objects.requireNonNull(LIZ2, "null cannot be cast to non-null type com.google.gson.JsonArray");
        Iterator<JsonElement> it = ((JsonArray) LIZ2).iterator();
        m.LIZIZ(it, "");
        while (it.hasNext()) {
            JsonElement next = it.next();
            try {
                m.LIZIZ(next, "");
                JsonElement jsonElement = next.getAsJsonObject().get("loginMethodName");
                m.LIZIZ(jsonElement, "");
                String asString = jsonElement.getAsString();
                if (m.LIZ((Object) asString, (Object) LoginMethodName.EMAIL_PASS.name()) || m.LIZ((Object) asString, (Object) LoginMethodName.USER_NAME_PASS.name())) {
                    Object fromJson = gson.fromJson(next, AccountPassLoginMethod.class);
                    m.LIZIZ(fromJson, "");
                    r4.LIZ((BaseLoginMethod) fromJson);
                } else if (m.LIZ((Object) asString, (Object) LoginMethodName.PHONE_NUMBER_PASS.name()) || m.LIZ((Object) asString, (Object) LoginMethodName.PHONE_SMS.name())) {
                    Object fromJson2 = gson.fromJson(next, PhoneLoginMethod.class);
                    m.LIZIZ(fromJson2, "");
                    r4.LIZ((BaseLoginMethod) fromJson2);
                } else if (m.LIZ((Object) asString, (Object) LoginMethodName.THIRD_PARTY.name())) {
                    Object fromJson3 = gson.fromJson(next, TPLoginMethod.class);
                    m.LIZIZ(fromJson3, "");
                    r4.LIZ((BaseLoginMethod) fromJson3);
                } else if (m.LIZ((Object) asString, (Object) LoginMethodName.DEFAULT.name())) {
                    Object fromJson4 = gson.fromJson(next, BaseLoginMethod.class);
                    m.LIZIZ(fromJson4, "");
                    r4.LIZ((BaseLoginMethod) fromJson4);
                }
            } catch (p e) {
                e.printStackTrace();
                it.remove();
            }
        }
        return arrayList;
    }

    public final List<BaseLoginMethod> LIZ(List<String> list) {
        AnonymousClass3WF r2 = new AnonymousClass3WF();
        r2.element = LIZIZ();
        AbstractC23600wf LIZ2 = C34651Yo.LIZ(C34651Yo.LIZ(AnonymousClass1ZP.LJIJI(LIZIZ), (AnonymousClass1IM) new C83053Os(r2)), (Comparator) new C67312ky());
        return AnonymousClass0N6.LIZ(list) ? C34651Yo.LJI(LIZ2) : C34651Yo.LJI(C34651Yo.LIZ(LIZ2, (AnonymousClass1IM) new C70212pe(list)));
    }

    public final void LIZ(String str, C83103Ox r6) {
        C21090sc.LIZ(str, r6);
        boolean z = false;
        for (T t : LIZIZ) {
            if (m.LIZ((Object) t.getUid(), (Object) str) && (t instanceof PhoneLoginMethod)) {
                z = true;
                t.setPhoneNumber(r6);
            }
        }
        if (z) {
            LJFF();
        }
    }

    public final void LIZ(String str, String str2) {
        C21090sc.LIZ(str, str2);
        boolean z = false;
        for (T t : LIZIZ) {
            if (m.LIZ((Object) t.getUid(), (Object) str) && t.getLoginMethodName() == LoginMethodName.USER_NAME_PASS) {
                z = true;
                Objects.requireNonNull(t, "null cannot be cast to non-null type com.ss.android.ugc.aweme.account.login.model.AccountPassLoginMethod");
                t.setName(str2);
            }
        }
        if (z) {
            LJFF();
        }
    }

    public final void LIZ(boolean z) {
        List<BaseLoginMethod> list = LIZIZ;
        ArrayList<BaseLoginMethod> arrayList = new ArrayList();
        for (T t : list) {
            if (m.LIZ((Object) t.getUid(), (Object) C13920h3.LIZIZ())) {
                arrayList.add(t);
            }
        }
        for (BaseLoginMethod baseLoginMethod : arrayList) {
            baseLoginMethod.allowOneKeyLogin(z);
        }
        LJFF();
    }

    public final boolean LIZ(BaseLoginMethod baseLoginMethod) {
        try {
            if (!(baseLoginMethod instanceof PhoneLoginMethod)) {
                baseLoginMethod = null;
            }
            PhoneLoginMethod phoneLoginMethod = (PhoneLoginMethod) baseLoginMethod;
            if (phoneLoginMethod == null) {
                return true;
            }
            if (phoneLoginMethod.getPhoneNumber() == null) {
                return false;
            }
            return m.LIZ(phoneLoginMethod.isFromReInstallNet(), true) || C83113Oy.LIZ(phoneLoginMethod.getPhoneNumber().getNationalNumber()) > 0;
        } catch (Exception unused) {
        }
    }

    public final List<BaseLoginMethod> LIZIZ(String str) {
        C21090sc.LIZ(str);
        List<BaseLoginMethod> list = LIZIZ;
        ArrayList arrayList = new ArrayList();
        for (T t : list) {
            if (m.LIZ((Object) t.getUid(), (Object) str)) {
                arrayList.add(t);
            }
        }
        return arrayList;
    }

    public final boolean LIZIZ() {
        List<BaseLoginMethod> list = LIZIZ;
        ArrayList arrayList = new ArrayList();
        for (T t : list) {
            T t2 = t;
            if (!TextUtils.isEmpty(t2.getUid()) && ((!m.LIZ((Object) t2.isFromReInstallNet(), (Object) true)) || m.LIZ((Object) t2.isTransToNormal(), (Object) true))) {
                arrayList.add(t);
            }
        }
        return !arrayList.isEmpty();
    }

    public final boolean LIZJ() {
        List<BaseLoginMethod> list = LIZIZ;
        ArrayList arrayList = new ArrayList();
        for (T t : list) {
            if (m.LIZ((Object) t.isFromReInstallNet(), (Object) true)) {
                arrayList.add(t);
            }
        }
        return !arrayList.isEmpty();
    }

    public final void LJ() {
        List<BaseLoginMethod> list = LIZIZ;
        if (!(list instanceof Collection) || !list.isEmpty()) {
            Iterator<T> it = list.iterator();
            while (it.hasNext()) {
                if (it.next().isExpired()) {
                    List<BaseLoginMethod> list2 = LIZIZ;
                    ArrayList arrayList = new ArrayList();
                    for (T t : list2) {
                        T t2 = t;
                        if (!t2.isExpired() || t2.getLoginMethodName() == LoginMethodName.DEFAULT) {
                            arrayList.add(t);
                        }
                    }
                    LIZIZ = AnonymousClass1ZP.LJII((Collection) arrayList);
                    LJFF();
                    return;
                }
            }
        }
    }

    public final void LJFF() {
        AnonymousClass0ED.LIZ((Callable) CallableC68892nW.LIZ);
    }
}