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


package com.ss.android.ugc.aweme.profile.edit;

import X.AbstractC17460ml;
import X.AbstractC23460wR;
import X.AbstractC61034Nxn;
import X.AnonymousClass1FW;
import X.AnonymousClass1IL;
import X.AnonymousClass1PN;
import X.AnonymousClass2O8;
import X.AnonymousClass32N;
import X.C12290eQ;
import X.C12740f9;
import X.C14300hf;
import X.C1789771q;
import X.C20470rc;
import X.C21090sc;
import X.C38141f1;
import X.E8L;
import X.EnumC17500mp;
import X.EnumC17520mr;
import X.EnumC17530ms;
import X.FHV;
import X.FHW;
import X.FI5;
import X.FI6;
import X.FI9;
import X.FIR;
import X.FIS;
import X.FIT;
import X.FIU;
import X.FIV;
import android.content.Context;
import android.net.Uri;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.IAccountUserService;
import com.ss.android.ugc.aweme.global.config.settings.SettingsManagerProxy;
import com.ss.android.ugc.aweme.global.config.settings.pojo.IESSettingsProxy;
import com.ss.android.ugc.aweme.profile.edit.api.YoutubeApi;
import com.ss.android.ugc.aweme.profile.model.User;
import java.util.List;
import java.util.concurrent.TimeUnit;
import kotlin.g.b.m;

public final class YoutubeRefreshTask implements WeakHandler.IHandler, AbstractC61034Nxn, AnonymousClass1FW {
    public static final FIV LIZIZ = new FIV((byte) 0);
    public static final boolean LJFF = false;
    public Context LIZ;
    public Handler LIZJ;
    public int LIZLLL;
    public final AbstractC23460wR LJ = AnonymousClass1PN.LIZ((AnonymousClass1IL) FIU.LIZ);

    static {
        Covode.recordClassIndex(87252);
    }

    public static /* synthetic */ void LIZ(YoutubeRefreshTask youtubeRefreshTask, boolean z, Boolean bool, Exception exc, Integer num, C1789771q r11, int i2) {
        Boolean bool2 = bool;
        Exception exc2 = exc;
        Integer num2 = num;
        C1789771q r5 = null;
        if ((i2 & 2) != 0) {
            bool2 = null;
        }
        if ((i2 & 4) != 0) {
            exc2 = null;
        }
        if ((i2 & 8) != 0) {
            num2 = null;
        }
        if ((i2 & 16) == 0) {
            r5 = r11;
        }
        youtubeRefreshTask.LIZ(z, bool2, exc2, num2, r5);
    }

    private final void LIZ(boolean z, Boolean bool, Exception exc, Integer num, C1789771q r9) {
        YoutubeApi youtubeApi = YoutubeApi.LIZ;
        Context context = this.LIZ;
        if (context == null) {
            m.LIZ("");
        }
        C14300hf.LIZ("social_profile_check", new C12740f9().LIZ("platform", "youtube").LIZ("is_success", Boolean.valueOf(z)).LIZ("auto_unlink", m.LIZ(bool, true) ? 1 : 0).LIZ("error_code", String.valueOf(r9 != null ? r9.LIZ : null)).LIZ("error_desc", youtubeApi.LIZ(context, exc, num, r9)).LIZ);
    }

    private final boolean LIZJ() {
        try {
            IESSettingsProxy iESSettingsProxy = C38141f1.LIZ.LIZIZ;
            m.LIZIZ(iESSettingsProxy, "");
            Integer thirdPartyDataRefresh = iESSettingsProxy.getThirdPartyDataRefresh();
            if (thirdPartyDataRefresh == null) {
                return false;
            }
            return thirdPartyDataRefresh.intValue() == 1;
        } catch (AnonymousClass2O8 unused) {
            return false;
        }
    }

    public final String LIZ() {
        return (String) this.LJ.getValue();
    }

    @Override // X.AbstractC61034Nxn
    public final void LIZ(IESSettingsProxy iESSettingsProxy) {
        C21090sc.LIZ(iESSettingsProxy);
        Handler handler = this.LIZJ;
        if (handler != null) {
            handler.removeCallbacksAndMessages(null);
        }
        Context context = this.LIZ;
        if (context == null) {
            m.LIZ("");
        }
        run(context);
    }

    public final void LIZ(User user) {
        String LIZ2;
        String youtubeRawRefreshToken;
        String youTubeRefreshToken = user.getYouTubeRefreshToken();
        if ((youTubeRefreshToken != null && youTubeRefreshToken.length() != 0) || ((youtubeRawRefreshToken = user.getYoutubeRawRefreshToken()) != null && youtubeRawRefreshToken.length() != 0)) {
            if (!TextUtils.isEmpty(user.getYoutubeRawRefreshToken())) {
                LIZ2 = user.getYoutubeRawRefreshToken();
            } else {
                String LIZ3 = FIS.LIZIZ.LIZ();
                String youTubeRefreshToken2 = user.getYouTubeRefreshToken();
                m.LIZIZ(youTubeRefreshToken2, "");
                LIZ2 = E8L.LIZ(youTubeRefreshToken2, LIZ3, "AES/CBC/PKCS7Padding", LIZ3);
            }
            if (TextUtils.isEmpty(LIZ2)) {
                LIZ(this, false, null, new Exception("Failed to decrypt refresh token, cannot continue"), null, null, 26);
                return;
            }
            FI6 LIZ4 = new FI5(new FI9(Uri.parse("https://accounts.google.com/o/oauth2/v2/auth"), Uri.parse("https://www.googleapis.com/oauth2/v4/token")), LIZ()).LIZ("refresh_token").LIZIZ("https://www.googleapis.com/auth/youtube.readonly").LIZLLL(LIZ2).LIZ();
            m.LIZIZ(LIZ4, "");
            Context context = this.LIZ;
            if (context == null) {
                m.LIZ("");
            }
            new FHV(context).LIZ(LIZ4, FHW.LIZ, new FIR(this, LIZ2));
        }
    }

    public final void LIZIZ() {
        if (YoutubeApi.LIZ()) {
            C12290eQ.LJFF().queryUser();
        }
    }

    @Override // com.bytedance.common.utility.collection.WeakHandler.IHandler
    public final void handleMsg(Message message) {
        if (message != null && message.what == 1) {
            Handler handler = this.LIZJ;
            if (handler != null) {
                handler.removeMessages(1);
            }
            int i2 = this.LIZLLL + 1;
            this.LIZLLL = i2;
            if (i2 > 3) {
                SettingsManagerProxy.inst().removeSettingsWatcher(this);
                Handler handler2 = this.LIZJ;
                if (handler2 != null) {
                    handler2.removeCallbacksAndMessages(null);
                    return;
                }
                return;
            }
            Handler handler3 = this.LIZJ;
            if (handler3 != null) {
                handler3.sendEmptyMessageDelayed(1, 1000);
            }
        }
    }

    @Override // X.AbstractC17430mi
    public final String key() {
        return getClass().getSimpleName();
    }

    @Override // X.AbstractC17430mi
    public final boolean meetTrigger() {
        return true;
    }

    @Override // X.AbstractC17430mi
    public final String prefix() {
        return "task_";
    }

    @Override // X.AbstractC17430mi
    public final void run(Context context) {
        C21090sc.LIZ(context);
        this.LIZ = context;
        AnonymousClass32N LIZ2 = AnonymousClass32N.LIZ();
        m.LIZIZ(LIZ2, "");
        if (!LIZ2.LIZIZ()) {
            SettingsManagerProxy.inst().registerSettingsWatcher(this, true);
            if (this.LIZJ == null) {
                HandlerThread handlerThread = new HandlerThread("youtube-refresh-timer");
                handlerThread.start();
                this.LIZJ = new WeakHandler(handlerThread.getLooper(), this);
            }
            Handler handler = this.LIZJ;
            if (handler == null) {
                m.LIZIZ();
            }
            if (handler.hasMessages(1)) {
                Handler handler2 = this.LIZJ;
                if (handler2 == null) {
                    m.LIZIZ();
                }
                handler2.removeMessages(1);
            }
            Handler handler3 = this.LIZJ;
            if (handler3 == null) {
                m.LIZIZ();
            }
            handler3.sendEmptyMessage(1);
        } else if (LIZJ()) {
            IAccountUserService LJFF2 = C12290eQ.LJFF();
            m.LIZIZ(LJFF2, "");
            User curUser = LJFF2.getCurUser();
            long currentTimeMillis = System.currentTimeMillis() / 1000;
            m.LIZIZ(curUser, "");
            long youTubeLastRefreshTime = curUser.getYouTubeLastRefreshTime();
            if (youTubeLastRefreshTime > 0 && currentTimeMillis - youTubeLastRefreshTime > TimeUnit.DAYS.toSeconds(30)) {
                if (m.LIZ(Looper.myLooper(), Looper.getMainLooper())) {
                    C20470rc.LIZ(new FIT(this, curUser), "YoutubeRefreshTask");
                } else {
                    LIZ(curUser);
                }
            }
        }
    }

    @Override // X.AbstractC17430mi
    public final EnumC17500mp scenesType() {
        return EnumC17500mp.DEFAULT;
    }

    @Override // X.AnonymousClass1FW
    public final boolean serialExecute() {
        return false;
    }

    @Override // X.AbstractC17430mi
    public final int targetProcess() {
        return 1;
    }

    @Override // X.AbstractC17430mi
    public final List triggerOtherLegoComponents() {
        return null;
    }

    @Override // X.AbstractC17430mi
    public final EnumC17520mr triggerType() {
        return AbstractC17460ml.LIZ(this);
    }

    @Override // X.AnonymousClass1FW
    public final EnumC17530ms type() {
        return EnumC17530ms.BOOT_FINISH;
    }
}