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


package X;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.google.gson.Gson;
import com.snapchat.kit.sdk.a.a;
import com.snapchat.kit.sdk.core.metrics.MetricQueue;
import com.snapchat.kit.sdk.core.metrics.model.KitPluginType;
import com.snapchat.kit.sdk.core.metrics.model.OpMetric;
import com.snapchat.kit.sdk.core.metrics.model.ServerEvent;
import com.snapchat.kit.sdk.core.networking.AuthTokenManager;
import com.snapchat.kit.sdk.core.networking.FirebaseTokenManager;
import com.snapchat.kit.sdk.core.networking.RefreshAccessTokenResult;
import com.snapchat.kit.sdk.core.security.SecureSharedPreferences;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import okhttp3.Request;

/* renamed from: X.FOt  reason: case insensitive filesystem */
public final class C38882FOt implements AuthTokenManager, FirebaseTokenManager {
    public static final Set<String> LIZ = new FIL();
    public final String LIZIZ;
    public final String LIZJ;
    public final List<String> LIZLLL;
    public final FPE LJ;
    public final Gson LJFF;
    public final AbstractC27362Aox<MetricQueue<ServerEvent>> LJI;
    public final C60614Nr1 LJII;
    public a LJIIIIZZ;
    public final KitPluginType LJIIIZ;
    public final boolean LJIIJ;
    public C38883FOu LJIIJJI;
    public C38880FOr LJIIL;
    public int LJIILIIL = 0;
    public boolean LJIILJJIL;
    public final Context LJIILL;
    public final C30711Jk LJIILLIIL;
    public final AbstractC27362Aox<FIW> LJIIZILJ;
    public final AtomicBoolean LJIJ = new AtomicBoolean(false);

    static {
        Covode.recordClassIndex(41051);
    }

    public C38882FOt(String str, String str2, List<String> list, Context context, SecureSharedPreferences secureSharedPreferences, C38030Ewd ewd, FPE fpe, C30711Jk r12, AbstractC27362Aox<FIW> aox, Gson gson, AbstractC27362Aox<MetricQueue<ServerEvent>> aox2, C60614Nr1 nr1, AbstractC27362Aox<MetricQueue<OpMetric>> aox3, KitPluginType kitPluginType, boolean z) {
        this.LIZIZ = str;
        this.LIZJ = str2;
        this.LIZLLL = list;
        this.LJIILL = context;
        this.LJ = fpe;
        this.LJIILLIIL = r12;
        this.LJIIZILJ = aox;
        this.LJFF = gson;
        this.LJI = aox2;
        this.LJII = nr1;
        this.LJIIIIZZ = new a(aox3);
        C38880FOr fOr = new C38880FOr(secureSharedPreferences, ewd);
        this.LJIIL = fOr;
        this.LJIIIZ = kitPluginType;
        this.LJIIJ = z;
        if (fOr.LIZ()) {
            new FP3(this, (byte) 0).execute(new Void[0]);
        }
    }

    public static Request LIZ(AbstractC24610yI r4, String str) {
        return new C24600yH().LIZ("Content-Type", "application/x-www-form-urlencoded").LIZ(AnonymousClass0EJ.LIZ("%s%s", new Object[]{"https://accounts.snapchat.com", str})).LIZ("POST", r4).LIZ();
    }

    private void LIZ(C38883FOu fOu, String str) {
        C80593Fg r2 = new C80593Fg();
        r2.LIZ("grant_type", "authorization_code");
        r2.LIZ("code", str);
        r2.LIZ("redirect_uri", fOu.getRedirectUri());
        r2.LIZ("client_id", this.LIZIZ);
        r2.LIZ("code_verifier", fOu.getCodeVerifier());
        Request LIZ2 = LIZ(r2.LIZ(), "/accounts/oauth2/token");
        if (LIZ2 == null) {
            LIZIZ();
            return;
        }
        this.LJ.LIZJ();
        this.LJIIIIZZ.LIZ(a.EnumC0014a.GRANT);
        C39105FXi.LIZ(this.LJIILLIIL, LIZ2, false).LIZ(new C38886FOx(this));
    }

    private void LIZ(FPM fpm) {
        if (!TextUtils.isEmpty(this.LIZJ)) {
            List<String> list = this.LIZLLL;
            if (list == null || list.isEmpty()) {
                throw new IllegalStateException("Valid scopes must be set");
            }
            C38883FOu LIZ2 = C38884FOv.LIZ(this.LIZIZ, this.LIZJ, this.LIZLLL, fpm, this.LJIIIZ, this.LJIIJ, this.LJIILJJIL);
            this.LJIIJJI = LIZ2;
            PackageManager packageManager = this.LJIILL.getPackageManager();
            String str = FPN.LIZ;
            if (this.LJIILIIL < 3 && C69622oh.LIZ(packageManager, str)) {
                Context context = this.LJIILL;
                if (LIZ(context, packageManager, str, LIZ2.toUri("snapchat://", "oauth2", context.getPackageName(), null))) {
                    if (this.LJIILJJIL) {
                        this.LJIIIIZZ.LIZ("authSnapchatForFirebase");
                    } else {
                        this.LJIIIIZZ.LIZ("authSnapchat");
                    }
                    this.LJI.get().push(this.LJII.LIZ(fpm, this.LJIILJJIL));
                    this.LJIILIIL++;
                    return;
                }
            }
            Uri uri = LIZ2.toUri("https://accounts.snapchat.com/accounts", "/oauth2/auth", null, "snapkit_web");
            if (this.LJIILJJIL) {
                this.LJIIIIZZ.LIZ("authWebForFirebase");
            } else {
                this.LJIIIIZZ.LIZ("authWeb");
            }
            LIZ(uri, this.LJIILL);
            this.LJI.get().push(this.LJII.LIZ(fpm, this.LJIILJJIL));
            return;
        }
        throw new IllegalStateException("Redirect URL must be set!");
    }

    public static void LIZ(Context context, Intent intent) {
        C21280sv.LIZ(intent, context);
        context.startActivity(intent);
    }

    public static void LIZ(Uri uri, Context context) {
        try {
            Intent intent = new Intent("android.intent.action.VIEW", uri);
            intent.setFlags(268435456);
            LIZ(context, intent);
        } catch (Exception unused) {
        }
    }

    public static void LIZ(Runnable runnable) {
        new Handler(Looper.getMainLooper()).post(runnable);
    }

    public static boolean LIZ(Context context, PackageManager packageManager, String str, Uri uri) {
        Intent intent = new Intent("android.intent.action.VIEW", uri);
        intent.setPackage(str);
        intent.setFlags(268435456);
        if (intent.resolveActivity(packageManager) == null) {
            return false;
        }
        LIZ(context, intent);
        return true;
    }

    private void LIZIZ(C38883FOu fOu, String str) {
        this.LJIIIIZZ.LIZ(a.EnumC0014a.FIREBASE_TOKEN_GRANT);
        this.LJIIZILJ.get().LIZ(str, fOu.getRedirectUri(), fOu.getCodeVerifier(), new C38885FOw(this));
    }

    /* JADX WARNING: Code restructure failed: missing block: B:40:?, code lost:
        r6 = X.FP8.d;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:43:0x00ec, code lost:
        r1 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:44:0x00ed, code lost:
        r7.LJIJ.set(false);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:45:0x00f2, code lost:
        throw r1;
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing exception handler attribute for start block: B:39:0x00e4 */
    public final int LIZ() {
        C37636EqH eqH;
        C38881FOs fOs;
        String LJ2 = this.LJIIL.LJ();
        if (LJ2 == null) {
            return FP8.f43a;
        }
        C80593Fg r2 = new C80593Fg();
        r2.LIZ("grant_type", "refresh_token");
        r2.LIZ("refresh_token", LJ2);
        r2.LIZ("client_id", this.LIZIZ);
        Request LIZ2 = LIZ(r2.LIZ(), "/accounts/oauth2/token");
        if (!this.LJIJ.compareAndSet(false, true)) {
            return FP8.c;
        }
        this.LJIIIIZZ.LIZ(a.EnumC0014a.REFRESH);
        int i2 = FP8.e;
        C24630yK LIZIZ2 = C39105FXi.LIZ(this.LJIILLIIL, LIZ2, false).LIZIZ();
        if (!(LIZIZ2 == null || !LIZIZ2.LIZ() || LIZIZ2.LJI == null || LIZIZ2.LJI.charStream() == null || (fOs = (C38881FOs) this.LJFF.fromJson(LIZIZ2.LJI.charStream(), C38881FOs.class)) == null)) {
            if (TextUtils.isEmpty(fOs.getRefreshToken())) {
                fOs.setRefreshToken(this.LJIIL.LJ());
            }
            fOs.setLastUpdated(System.currentTimeMillis());
            if (fOs.isComplete()) {
                this.LJIIL.LIZ(fOs);
                this.LJIIIIZZ.LIZ(a.EnumC0014a.REFRESH, true);
                this.LJIJ.set(false);
                return i2;
            }
        }
        if (LIZIZ2 != null && !LIZIZ2.LIZ() && LIZIZ2.LIZJ == 400 && (eqH = (C37636EqH) this.LJFF.fromJson(LIZIZ2.LJI.charStream(), C37636EqH.class)) != null && !TextUtils.isEmpty(eqH.LIZ) && LIZ.contains(eqH.LIZ.toLowerCase())) {
            this.LJIIL.LJI();
        }
        this.LJIIIIZZ.LIZ(a.EnumC0014a.REFRESH, false);
        i2 = FP8.b;
        this.LJIJ.set(false);
        return i2;
    }

    public final void LIZ(EnumC38876FOn fOn) {
        this.LJI.get().push(this.LJII.LIZ(false, true));
        this.LJ.LIZ(fOn);
    }

    public final void LIZ(C38883FOu fOu, String str, String str2) {
        if (fOu != null && !TextUtils.isEmpty(str) && !TextUtils.isEmpty(str2) && TextUtils.equals(str2, fOu.getState()) && !TextUtils.isEmpty(fOu.getRedirectUri()) && !TextUtils.isEmpty(fOu.getCodeVerifier())) {
            this.LJIILIIL = 0;
            if (this.LJIILJJIL) {
                LIZIZ(fOu, str);
            } else {
                LIZ(fOu, str);
            }
        } else if (this.LJIILJJIL) {
            LIZ(EnumC38876FOn.INVALID_OAUTH_RESPONSE);
        } else {
            LIZIZ();
        }
    }

    public final void LIZIZ() {
        this.LJI.get().push(this.LJII.LIZ(false, false));
        this.LJ.LIZLLL();
    }

    @Override // com.snapchat.kit.sdk.core.networking.AuthTokenManager
    public final void clearToken() {
        boolean LJFF2 = this.LJIIL.LJFF();
        this.LJIIL.LJI();
        if (LJFF2) {
            this.LJ.LJ();
        }
    }

    @Override // com.snapchat.kit.sdk.core.networking.AuthTokenManager
    public final String getAccessToken() {
        return this.LJIIL.LIZJ();
    }

    @Override // com.snapchat.kit.sdk.core.networking.AuthTokenManager
    public final boolean hasAccessToScope(String str) {
        return this.LJIIL.LIZ(str);
    }

    @Override // com.snapchat.kit.sdk.core.networking.AuthTokenManager
    public final boolean isUserLoggedIn() {
        return this.LJIIL.LJFF();
    }

    @Override // com.snapchat.kit.sdk.core.networking.AuthTokenManager
    public final void refreshAccessToken(RefreshAccessTokenResult refreshAccessTokenResult) {
        new FP1(this, refreshAccessTokenResult, (byte) 0).execute(new Void[0]);
    }

    @Override // com.snapchat.kit.sdk.core.networking.FirebaseTokenManager
    public final void startFirebaseTokenGrant() {
        this.LJIILJJIL = true;
        LIZ(new FPM());
    }

    @Override // com.snapchat.kit.sdk.core.networking.AuthTokenManager
    public final void startTokenGrant() {
        this.LJIILJJIL = false;
        LIZ(new FPM());
    }

    @Override // com.snapchat.kit.sdk.core.networking.AuthTokenManager
    public final void startTokenGrantWithOptions(FPM fpm) {
        this.LJIILJJIL = false;
        LIZ(fpm);
    }
}