红果免费短剧 v6.2.3.32版本的 MD5 值为:a6b05492607eab2c8a25f26d2f238ae0

以下内容为反编译后的 ad.java 源代码,内容仅作参考


package com.ss.android.update;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.URLUtil;
import androidx.core.app.NotificationCompat;
import androidx.core.content.FileProvider;
import com.bytedance.apm.agent.instrumentation.ThreadMonitor;
import com.bytedance.common.utility.DigestUtils;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.NetworkUtils;
import com.bytedance.common.utility.StringUtils;
import com.bytedance.common.utility.concurrent.ThreadPlus;
import com.bytedance.common.utility.persistent.SharedPrefsEditorCompat;
import com.bytedance.helios.statichook.api.ExtraInfo;
import com.bytedance.helios.statichook.api.HeliosApiHook;
import com.bytedance.helios.statichook.api.Result;
import com.bytedance.news.common.service.manager.ServiceManager;
import com.bytedance.services.app.common.context.api.AppCommonContext;
import com.phoenix.read.R;
import com.service.middleware.applog.ApplogService;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.socialbase.downloader.depend.AbsDownloadListener;
import com.ss.android.socialbase.downloader.model.DownloadInfo;
import com.ss.android.ugc.bytex.pthread.base.PThreadExecutorsUtils;
import com.ss.android.ugc.bytex.thread_rename.base.DefaultThreadFactory;
import com.ss.android.update.aa;
import com.ss.android.update.ab;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONObject;

public class ad implements j {

    public static final int f106770b = 2;

    public static final int f106771c = 12;
    private static ad p;
    private final com.ss.android.update.c Y;
    private ExecutorService aB;
    private AppCommonContext aE;
    private ah aF;
    private int aG;
    private int ak;
    private int al;
    private int am;
    private String an;
    private OnDownloadStatusChangedListener ar;
    private l as;
    private i at;
    private h au;
    private t az;
    public Context d;
    public final Handler e;
    public final com.ss.android.update.c i;
    public aa k;
    public ApplogService l;
    public volatile boolean m;
    private NotificationManager q;
    private NotificationCompat.Builder r;
    private String s;
    private String t;
    private String u;
    private String v;
    private String w;

    public volatile boolean f106773a = true;
    private boolean x = false;
    private String y = "";
    private int z = 0;
    private int A = 0;
    private int B = 0;
    public int f = 0;
    private String C = "";
    private String D = "";
    private String E = "";
    private long F = 0;
    private String G = "";
    private String H = "";
    private boolean I = false;

    private boolean f106772J = false;
    private boolean K = false;
    private String L = "";
    private String M = "";
    private String N = "";
    public String g = "";
    private boolean O = false;
    private int P = 2;
    private long Q = -1;
    private int R = 0;
    private String S = "";
    private int T = 0;
    private int U = 0;
    public volatile boolean h = false;
    private c V = null;
    private int W = 0;
    private volatile boolean X = false;
    private int Z = 0;
    private String aa = "";
    private int ab = 0;
    private int ac = 0;
    private int ad = -1;
    private String ae = "";
    private String af = "";
    private volatile boolean ag = false;
    private int ah = 0;
    private int ai = 0;
    private String aj = "";
    private a ao = null;
    private final b ap = new b();
    private List<OnUpdateStatusChangedListener> aq = new ArrayList();
    private String av = "";
    private String aw = "";
    public String j = "";
    private boolean ax = false;
    private com.ss.android.common.dialog.b aA = null;
    private volatile int aC = 2;
    private volatile int aD = 3;
    private i aH = null;
    private h aI = null;
    private l aJ = null;
    private f aK = null;
    private volatile boolean aL = false;
    public boolean n = false;
    public String o = "";
    private long aM = 0;
    private IUpdateConfig ay = (IUpdateConfig) ServiceManager.getService(IUpdateConfig.class);

    private static List a(PackageManager packageManager, Intent intent, int i) {
        Result preInvoke = new HeliosApiHook().preInvoke(101311, "android/content/pm/PackageManager", "queryIntentActivities", packageManager, new Object[]{intent, Integer.valueOf(i)}, "java.util.List", new ExtraInfo(false, "(Landroid/content/Intent;I)Ljava/util/List;"));
        return preInvoke.isIntercept() ? (List) preInvoke.getReturnValue() : packageManager.queryIntentActivities(intent, i);
    }

    String a(Context context, t tVar) {
        String str;
        if (tVar != null && !TextUtils.isEmpty(tVar.s)) {
            try {
                File file = new File(tVar.s);
                if (file.exists() && file.isDirectory()) {
                    return file.getAbsolutePath();
                }
                if (file.mkdirs()) {
                    return file.getAbsolutePath();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        try {
            str = Environment.getExternalStorageDirectory().getPath() + "/Android/data/" + context.getPackageName() + "/files";
        } catch (Exception e2) {
            e2.printStackTrace();
            File a2 = ac.a(context, true);
            if (a2 != null) {
                str = a2.getPath();
            } else {
                str = "/sdcard/Android/data/" + context.getPackageName() + "/files";
            }
        }
        if (str.isEmpty()) {
            return str;
        }
        File file2 = new File(str, "update");
        if (!file2.exists()) {
            file2.mkdirs();
        }
        return file2.getPath();
    }

    void a(Message message) {
        r10 = 0;
        r10 = 0;
        char c2 = 0;
        switch (message.what) {
            case 1:
                b(R.id.eo3);
                b(R.id.eo4);
                b(R.id.eo1);
                ak();
                if (this.ao != null) {
                    if (Logger.debug()) {
                        Logger.d("UpdateHelper", "from MSG_UPDATE_READY");
                    }
                    K();
                    return;
                }
                return;
            case 2:
                b(R.id.eo2);
                b(R.id.eo1);
                am();
                return;
            case 3:
                b(R.id.eo3);
                b(R.id.eo1);
                b(R.id.eo2);
                b(R.id.eo4);
                a(R.id.eo3, d(0));
                return;
            case 4:
                b(R.id.eo3);
                b(R.id.eo2);
                b(R.id.eo4);
                al();
                return;
            case 5:
                int i = message.arg1;
                int i2 = i >= 0 ? i : 0;
                if (i2 > 99) {
                    i2 = 99;
                }
                a(R.id.eo3, d(i2));
                return;
            case 6:
                final boolean z = message.arg1 == 1;
                if (this.aL) {
                    if (Z() && !p.a().k()) {
                        ab.b("reason_local_block_dialog");
                        this.aL = false;
                        return;
                    } else {
                        this.e.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                ad.this.m(z);
                            }
                        }, Math.min(Math.max(this.R, 0), 60) * 1000);
                        return;
                    }
                }
                if (this.aC != -2) {
                    break;
                }
                if (z && this.az.d && p.a().m() && p.a().o() && !p.a().b(this.f)) {
                    ThreadPlus.submitRunnable(new Runnable() {
                        @Override
                        public void run() {
                            if (ad.this.Q()) {
                                Message obtainMessage = ad.this.e.obtainMessage(17);
                                obtainMessage.arg1 = 2;
                                obtainMessage.sendToTarget();
                                return;
                            }
                            ad.this.P();
                        }
                    });
                    ab.b("reason_alpha_pkg_update_bg_download");
                    return;
                }
                if (c2 != 0) {
                    synchronized (this.aq) {
                        for (OnUpdateStatusChangedListener onUpdateStatusChangedListener : this.aq) {
                            if (onUpdateStatusChangedListener != null) {
                                onUpdateStatusChangedListener.a(1);
                            }
                        }
                    }
                } else {
                    synchronized (this.aq) {
                        for (OnUpdateStatusChangedListener onUpdateStatusChangedListener2 : this.aq) {
                            if (onUpdateStatusChangedListener2 != null) {
                                onUpdateStatusChangedListener2.a(-2);
                            }
                        }
                    }
                }
                if (this.aF == null) {
                    this.aF = new ah();
                }
                ah ahVar = this.aF;
                i iVar = this.at;
                ahVar.a(iVar != null ? iVar : null);
                if (this.aC == 2) {
                    this.aF.a(z);
                    return;
                } else {
                    if (this.aC == 1) {
                        this.aF.a(l() ? 1 : -2);
                        return;
                    }
                    return;
                }
            case 7:
                this.aL = false;
                if (Logger.debug()) {
                    Logger.d("UpdateHelper", "from MSG_CHECK_UPDATE_FAIL");
                }
                K();
                synchronized (this.aq) {
                    for (OnUpdateStatusChangedListener onUpdateStatusChangedListener3 : this.aq) {
                        if (onUpdateStatusChangedListener3 != null) {
                            if (l()) {
                                onUpdateStatusChangedListener3.a(-1);
                            } else {
                                onUpdateStatusChangedListener3.a(-2);
                            }
                        }
                    }
                }
                if (this.aC == 1) {
                    if (this.aF == null) {
                        this.aF = new ah();
                    }
                    ah ahVar2 = this.aF;
                    i iVar2 = this.at;
                    ahVar2.a(iVar2 != null ? iVar2 : null);
                    if (l()) {
                        this.aF.a(-1);
                        return;
                    } else {
                        this.aF.a(-2);
                        return;
                    }
                }
                return;
            case 8:
                a(message.arg1 == 1, message.arg2 == 1, message.obj instanceof aa.a ? (aa.a) message.obj : null);
                return;
            case 9:
                this.aL = false;
                if (this.h) {
                    this.h = false;
                }
                JSONObject jSONObject = new JSONObject();
                a(jSONObject, "errorMsg", "has not get positive result from update checking");
                a(jSONObject, "url", this.y);
                a(jSONObject, "pre", Integer.valueOf(message.arg1 == 1 ? 1 : 0));
                a(jSONObject, "canceled", (Object) 0);
                a(jSONObject, "success", (Object) 0);
                ApplogService applogService = this.l;
                if (applogService != null) {
                    applogService.onEvent(this.d, "umeng", "app_update", "download", 0L, 0L, jSONObject);
                }
                ab.a(this.y, this.f, message.arg1 == 1, "fail", "has not get positive result from update checking");
                return;
            case 10:
                b(R.id.eo2);
                return;
            case 11:
                b(R.id.eo4);
                return;
            case 12:
                b(R.id.eo1);
                return;
            case 13:
                b(R.id.eo3);
                if (Logger.debug()) {
                    Logger.d("UpdateHelper", "from MSG_CANCEL_PROGRESS");
                }
                K();
                return;
            case 14:
                m(message.arg1 == 1);
                return;
            case 15:
                final int i3 = message.arg1;
                final int i4 = message.arg2;
                ThreadPlus.submitRunnable(new Runnable() {
                    @Override
                    public void run() {
                        ad.this.a(i3, i4);
                    }
                });
                return;
            case 16:
                if (p.a().b(this.f)) {
                    return;
                }
                ThreadPlus.submitRunnable(new Runnable() {
                    @Override
                    public void run() {
                        if (ad.this.Q()) {
                            Message obtainMessage = ad.this.e.obtainMessage(17);
                            obtainMessage.arg1 = 2;
                            obtainMessage.sendToTarget();
                        }
                    }
                });
                return;
            case 17:
                c(message.arg1);
                return;
            default:
                return;
        }
    }

    public void a(int i, int i2, OnUpdateStatusChangedListener onUpdateStatusChangedListener, final boolean z) {
        synchronized (this) {
            this.aC = i;
            this.aD = i2;
            synchronized (this.aq) {
                this.aq.add(onUpdateStatusChangedListener);
            }
            if (!this.x) {
                aj();
                this.x = true;
            }
            if (this.h) {
                return;
            }
            new com.ss.android.common.a("UpdateHelper-Thread") {
                @Override
                public void run() {
                    try {
                        ad.this.d(z);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }.d();
        }
    }

    public void a(OnUpdateStatusChangedListener onUpdateStatusChangedListener) {
        synchronized (this) {
            synchronized (this.aq) {
                this.aq.remove(onUpdateStatusChangedListener);
            }
        }
    }

    public void a(int i) {
        this.ag = true;
        ab.a(1, (String) null, ab.a.a().a("from", String.valueOf(i)).f106769a);
    }

    void a(boolean z, boolean z2, aa.a aVar) {
        aa.a a2 = aVar == null ? aa.a.a() : aVar;
        JSONObject jSONObject = new JSONObject();
        String str = null;
        if (ad()) {
            File file = new File(this.s);
            if (!file.isDirectory() && !file.mkdirs()) {
                str = "can not mkdir files dir: " + this.s;
                Logger.e("UpdateHelper", str);
            }
        } else {
            str = "canDownloadApk = false";
        }
        if (TextUtils.isEmpty(str)) {
            this.k.a(this.y, z ? "predownload.apk.part" : z2 ? "update_alpha.apk.part" : "update.apk.part", this.s + File.separator, z, this.f, this, a2);
            if (z) {
                return;
            }
            this.e.sendEmptyMessage(3);
            return;
        }
        this.h = false;
        if (!a2.f106767a) {
            a(jSONObject, "errorMsg", str);
            a(jSONObject, "url", this.y);
            a(jSONObject, "pre", Integer.valueOf(z ? 1 : 0));
            a(jSONObject, "canceled", (Object) 0);
            a(jSONObject, "success", (Object) 0);
            ApplogService applogService = this.l;
            if (applogService != null) {
                applogService.onEvent(this.d, "umeng", "app_update", "download", 0L, 0L, jSONObject);
            }
            ab.a(str);
            ab.a(this.y, this.f, z, "fail", str);
            return;
        }
        if (a().k.d == null) {
            a().k.d = a2;
        }
        ab.a(this.y, this.f, z, "fail", str);
    }

    public String a(String str) {
        if (str == null || str.length() == 0) {
            return "";
        }
        String[] split = str.split("\\\\n");
        StringBuilder sb = new StringBuilder();
        for (String str2 : split) {
            sb.append(str2.trim());
            sb.append("\n");
        }
        return sb.toString();
    }

    synchronized void a(int i, int i2, String str, boolean z) {
        this.T = i;
        if (z) {
            this.W = i2;
        } else {
            this.U = i2;
        }
        this.S = str;
        SharedPreferences.Editor edit = this.d.getSharedPreferences("update_info", 0).edit();
        edit.putInt("download_version", this.T);
        if (z) {
            edit.putInt("pre_download_size", this.W);
        } else {
            edit.putInt("download_size", this.U);
        }
        edit.putString("download_etag", this.S);
        SharedPrefsEditorCompat.apply(edit);
    }

    @Override
    public synchronized void a(int i, String str, boolean z) {
        synchronized (this.aq) {
            for (OnUpdateStatusChangedListener onUpdateStatusChangedListener : this.aq) {
                if (onUpdateStatusChangedListener != null) {
                    onUpdateStatusChangedListener.a(i, str, z);
                }
            }
        }
        if (z) {
            this.W = i;
        } else {
            this.U = i;
        }
        this.S = str;
        SharedPreferences.Editor edit = this.d.getSharedPreferences("update_info", 0).edit();
        if (z) {
            edit.putInt("pre_download_size", this.W);
        } else {
            edit.putInt("download_size", this.U);
        }
        edit.putString("download_etag", this.S);
        SharedPrefsEditorCompat.apply(edit);
    }

    @Override
    public void a(int i, int i2, boolean z) {
        synchronized (this.i) {
            this.i.f106824a = i;
            this.i.f106825b = i2;
            synchronized (this.aq) {
                for (OnUpdateStatusChangedListener onUpdateStatusChangedListener : this.aq) {
                    if (onUpdateStatusChangedListener != null) {
                        onUpdateStatusChangedListener.a(i, i2, z);
                    }
                }
            }
        }
    }

    @Override
    public void a(final boolean z, final boolean z2) {
        final aa.a a2 = this.k.d != null ? this.k.d : aa.a.a();
        this.aB.execute(new Runnable() {
            @Override
            public void run() {
                ad.this.b(z, z2, a2);
            }
        });
    }

    @Override
    public void a(boolean z) {
        synchronized (this.aq) {
            for (OnUpdateStatusChangedListener onUpdateStatusChangedListener : this.aq) {
                if (onUpdateStatusChangedListener != null) {
                    onUpdateStatusChangedListener.a(z);
                }
            }
        }
        c cVar = new c();
        this.V = cVar;
        cVar.start();
    }

    public void a(com.ss.android.update.c cVar) {
        synchronized (this.i) {
            cVar.f106824a = this.i.f106824a;
            cVar.f106825b = this.i.f106825b;
        }
    }

    public void a(final Context context, final String str, final String str2) {
        ak.a().b();
        if (!l()) {
            ab.b("reason_check_version_code_fail");
            return;
        }
        final boolean X = X();
        String a2 = af.a().a(h());
        DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                if (X) {
                    ad.this.a(context);
                    dialogInterface.dismiss();
                    return;
                }
                if (!ad.this.l()) {
                    dialogInterface.dismiss();
                    return;
                }
                ad.this.m = true;
                ad.this.b();
                if (str != null && ad.this.d != null && ad.this.l != null) {
                    ad.this.l.onEvent(context, str, str2);
                }
                File C = ad.this.C();
                if (C != null) {
                    ad.this.c();
                    ad.this.a(context, C);
                } else {
                    ad.this.R();
                }
                ad.this.g(false);
            }
        };
        if (this.ag) {
            ab.b("reason_other_update_dialog_showing");
            return;
        }
        i iVar = this.at;
        if (iVar == null) {
            a(context, X, a2, onClickListener);
        } else if (iVar != null) {
            if (!iVar.a()) {
                iVar.a(1);
            }
        } else {
            a(context, X, a2, onClickListener);
        }
        ab.a("test_invitation_popup_show", this.y, this.f, "trigger", -1, this.I);
    }

    public void a(Context context, File file) {
        if (context == null || file == null) {
            ab.a(this.y, this.f, false, "install_fail", "context == null || file == null");
            return;
        }
        try {
            h hVar = this.aI;
            if (hVar instanceof o) {
                if (hVar.b()) {
                    ((o) this.aI).d();
                }
            } else {
                l lVar = this.aJ;
                if ((lVar instanceof y) && lVar.bz_()) {
                    ((y) this.aJ).d();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            t tVar = this.az;
            if (tVar != null && tVar.q != null) {
                this.az.q.a(context, file);
            } else {
                context.startActivity(b(context, file));
            }
            ab.a(1, (String) null);
        } catch (Exception e2) {
            e2.printStackTrace();
            ab.a(this.y, this.f, false, "install_fail", Log.getStackTraceString(e2));
            ab.a(2, Log.getStackTraceString(e2));
        }
    }

    public void a(Context context, boolean z) {
        if (k()) {
            l lVar = this.as;
            if (lVar == null) {
                if (this.ay.getUpdateConfig().g) {
                    this.aJ = new y(context, z);
                } else {
                    this.aJ = new w(context, z);
                }
            } else {
                this.aJ = lVar;
                if (lVar == null) {
                    if (this.ay.getUpdateConfig().g) {
                        this.aJ = new y(context, z);
                    } else {
                        this.aJ = new w(context, z);
                    }
                }
            }
            if (this.aJ.bz_()) {
                return;
            }
            if (context.getResources().getConfiguration().orientation == 2 && !this.ay.getUpdateConfig().o) {
                ab.b("reason_no_oriental_dialog");
                return;
            }
            if (this.ag) {
                ab.b("reason_other_update_dialog_showing");
                return;
            }
            if (this.az.d && !p.a().j()) {
                ab.b("reason_local_out_of_house");
                this.aJ = null;
            } else {
                try {
                    this.aJ.by_();
                } catch (Exception e) {
                    ab.b(e.toString());
                }
                ab.a("test_invitation_popup_show", this.y, this.f, z ? "auto" : "trigger", -1, this.I);
            }
        }
    }

    public void a(Context context) {
        if (context == null) {
            return;
        }
        try {
            context.startActivity(Y());
        } catch (Throwable th) {
            Logger.d("UpdateHelper", th.getMessage(), th);
        }
    }

    public void a(l lVar, i iVar) {
        synchronized (this) {
            this.as = lVar;
            this.at = iVar;
        }
    }

    public void a(int i, boolean z) {
        Message obtain = Message.obtain();
        obtain.what = 15;
        obtain.arg1 = i;
        obtain.arg2 = z ? 1 : 0;
        this.e.sendMessage(obtain);
    }

    public void a(int i, int i2) {
        boolean z = i2 == 1;
        if (!this.x) {
            synchronized (this) {
                if (!this.x) {
                    aj();
                    this.x = true;
                }
            }
        }
        if (i == 1) {
            p(z);
        }
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("event_type", i);
            jSONObject.put("distribute_id", this.aa);
            jSONObject.put("artifact_id", this.ab);
            jSONObject.put("device_id", this.az.e());
            jSONObject.put("package_type", this.ac);
            jSONObject.put("enable_client_strategy", this.Z);
            jSONObject.put("tip_version_code", this.B);
            jSONObject.put("tip_version_name", this.C);
            if (z) {
                jSONObject.put("call_type", 1);
            } else {
                jSONObject.put("call_type", 0);
            }
            jSONObject.put("ac", NetworkUtils.getNetworkAccessType(this.az.a().getContext()));
            byte[] bytes = jSONObject.toString().getBytes();
            String str = "https://ichannel.snssdk.com/check_version/report/";
            if (!StringUtils.isEmpty(this.az.l)) {
                str = "https://ichannel.snssdk.com/check_version/report/" + this.az.l;
            }
            Logger.d("UpdateHelper", "update dialog report result: " + com.ss.android.common.util.NetworkUtils.executePost(20480, str, bytes, NetworkUtils.CompressType.NONE, "application/json; charset=utf-8"));
        } catch (Throwable th) {
            Logger.w("UpdateHelper", "update dialog report error: " + th);
        }
    }

    public void a(h hVar) {
        synchronized (this) {
            this.au = hVar;
        }
    }

    private void ah() {
        l(true);
    }

    public boolean H() {
        return c(false);
    }

    public void K() {
        a aVar = this.ao;
        if (aVar != null) {
            aVar.a();
        }
    }

    public void L() {
        a aVar = this.ao;
        if (aVar != null) {
            aVar.b();
        }
    }

    public void R() {
        k(false);
    }

    public void S() {
        l(false);
    }

    public void b() {
        this.e.sendEmptyMessage(11);
    }

    public void c() {
        this.e.sendEmptyMessage(10);
    }

    public synchronized boolean j() {
        return this.h;
    }

    public synchronized File C() {
        return b(false);
    }

    public void M() {
        this.ag = false;
        ab.i(2);
        a(1, true);
        a(3, true);
    }

    public void O() {
        this.ag = false;
        ab.i(3);
        a(1, true);
        a(2, true);
    }

    public boolean W() {
        l lVar = this.aJ;
        if (lVar != null) {
            return lVar.bz_();
        }
        return false;
    }

    public boolean ab() {
        int i = this.ad;
        if (i == 0 || i == 1) {
            return true;
        }
        return false;
    }

    public boolean ac() {
        t tVar = this.az;
        if (tVar != null && tVar.d) {
            return true;
        }
        return false;
    }

    public String d() {
        AppCommonContext appCommonContext = this.aE;
        if (appCommonContext != null) {
            return appCommonContext.getStringAppName();
        }
        return "";
    }

    class b extends AbsDownloadListener {

        private boolean f106796b = false;

        private void a() {
            try {
                if (this.f106796b) {
                    return;
                }
                this.f106796b = true;
                ad.this.K();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onFirstSuccess(DownloadInfo downloadInfo) {
            a();
        }

        @Override
        public void onSuccessed(DownloadInfo downloadInfo) {
            a();
        }

        b() {
        }
    }

    public static ad a() {
        if (p == null) {
            synchronized (ad.class) {
                if (p == null) {
                    p = new ad();
                }
            }
        }
        return p;
    }

    private boolean ae() {
        boolean a2 = q.a().a(this.d, this.g);
        if (!StringUtils.isEmpty(this.N) && ToolUtils.isInstalledApp(this.d, this.N)) {
            return false;
        }
        return a2;
    }

    public synchronized int D() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.ad;
    }

    public synchronized int E() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.ac;
    }

    public synchronized int F() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.ah;
    }

    public synchronized int G() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.ai;
    }

    public void I() {
        a aVar = new a(new CountDownLatch(2));
        this.ao = aVar;
        new ThreadPlus(aVar, "DownloadCountDownLatchThread", true).start();
    }

    public void N() {
        this.ag = false;
        p.a().a(this.f);
        ab.i(5);
        a(1, true);
        a(3, true);
    }

    public void U() {
        synchronized (this.i) {
            c cVar = this.V;
            if (cVar != null) {
                cVar.a();
            }
            aa aaVar = this.k;
            if (aaVar != null) {
                aaVar.a();
            }
        }
    }

    public boolean V() {
        i iVar = this.at;
        if (iVar != null && iVar != null) {
            return iVar.a();
        }
        com.ss.android.common.dialog.b bVar = this.aA;
        if (bVar != null) {
            return bVar.isShowing();
        }
        return false;
    }

    public boolean X() {
        if (!this.ax || this.I || this.O || v()) {
            return false;
        }
        return a(Y());
    }

    public synchronized boolean Z() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        if (this.Z != 0) {
            return true;
        }
        return false;
    }

    public synchronized int e() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.B;
    }

    public synchronized String f() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.y;
    }

    public synchronized String g() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        if (!TextUtils.isEmpty(this.D)) {
            return this.D;
        }
        return this.C;
    }

    public synchronized String h() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.E;
    }

    public synchronized String i() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.ae;
    }

    public synchronized boolean k() {
        boolean z = true;
        if (!this.x) {
            aj();
            this.x = true;
        }
        if (this.ad == 1) {
            return true;
        }
        if (this.z >= this.B) {
            z = false;
        }
        return z;
    }

    public synchronized boolean l() {
        boolean z;
        z = true;
        if (!this.x) {
            aj();
            this.x = true;
        }
        if (this.z >= this.f) {
            if (!this.aL) {
                z = false;
            }
        }
        return z;
    }

    public synchronized boolean m() {
        boolean z;
        z = true;
        if (!this.x) {
            aj();
            this.x = true;
        }
        if (System.currentTimeMillis() <= this.F + 86400000) {
            z = false;
        }
        return z;
    }

    public synchronized boolean n() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.O;
    }

    public synchronized int o() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.P;
    }

    public synchronized long p() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.Q;
    }

    public synchronized boolean q() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.I;
    }

    public synchronized String r() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.G;
    }

    public synchronized String s() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.H;
    }

    public synchronized int t() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return Math.min(Math.max(this.R, 0), 60);
    }

    public synchronized int u() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.aG;
    }

    public synchronized boolean v() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        if (ae()) {
            return false;
        }
        return this.f106772J;
    }

    public synchronized boolean w() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.K;
    }

    public synchronized String x() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.L;
    }

    public synchronized String y() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.M;
    }

    public synchronized String z() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        return this.g;
    }

    public class a implements Runnable {

        private CountDownLatch f106793b;

        private AtomicBoolean f106794c;

        public void a() {
            CountDownLatch countDownLatch = this.f106793b;
            if (countDownLatch == null) {
                return;
            }
            countDownLatch.countDown();
            if (Logger.debug()) {
                Logger.d("UpdateHelper", "countDown current count = " + this.f106793b.getCount());
            }
        }

        @Override
        public void run() {
            Thread.currentThread().setName("DownloadCountDownLatchThread");
            try {
                this.f106793b.await();
                if (!this.f106794c.get()) {
                    q.a().b(ad.this.d, ad.this.g);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        public void b() {
            long count;
            this.f106794c.getAndSet(true);
            CountDownLatch countDownLatch = this.f106793b;
            if (countDownLatch == null) {
                count = 0;
            } else {
                count = countDownLatch.getCount();
            }
            for (int i = 0; i < count; i++) {
                this.f106793b.countDown();
            }
            if (Logger.debug() && this.f106793b != null) {
                Logger.d("UpdateHelper", "cancel current count = " + this.f106793b.getCount());
            }
        }

        private a(CountDownLatch countDownLatch) {
            this.f106794c = new AtomicBoolean(false);
            this.f106793b = countDownLatch;
        }
    }

    private synchronized boolean ad() {
        boolean z;
        z = true;
        if (!this.x) {
            aj();
            this.x = true;
        }
        int i = this.z;
        if (i >= this.f && i >= this.B) {
            if (this.aL) {
            }
            z = false;
        }
        return z;
    }

    private synchronized void af() {
        try {
            File file = new File(this.u);
            if (file.exists()) {
                file.delete();
            }
            File file2 = new File(this.t);
            if (file2.exists()) {
                file2.delete();
            }
        } finally {
        }
    }

    private synchronized void ag() {
        try {
            File file = new File(this.w);
            if (file.exists()) {
                file.delete();
            }
            File file2 = new File(this.v);
            if (file2.exists()) {
                file2.delete();
            }
        } finally {
        }
    }

    public void T() {
        synchronized (this.i) {
            c cVar = this.V;
            if (cVar != null) {
                cVar.a();
            }
            aa aaVar = this.k;
            if (aaVar != null) {
                aaVar.a();
            }
            b(R.id.eo3);
            b(R.id.eo1);
        }
    }

    public Intent Y() {
        try {
            if (TextUtils.isEmpty(this.av) || TextUtils.isEmpty(this.aw)) {
                return null;
            }
            Intent intent = new Intent();
            intent.setPackage(this.av);
            intent.setData(Uri.parse(this.aw));
            intent.addFlags(268435456);
            return intent;
        } catch (Exception e) {
            Logger.d("UpdateHelper", e.getMessage(), e);
            return null;
        }
    }

    public Intent aa() {
        Context context;
        if (p.a().d() && (context = this.d) != null) {
            PackageManager packageManager = context.getPackageManager();
            t tVar = this.az;
            if (tVar != null) {
                String str = tVar.h;
                if (!TextUtils.isEmpty(str)) {
                    return packageManager.getLaunchIntentForPackage(str);
                }
                return null;
            }
            return null;
        }
        return null;
    }

    class c extends Thread {

        volatile boolean f106797a = false;

        public void a() {
            this.f106797a = true;
        }

        @Override
        public void run() {
            while (true) {
                try {
                    ThreadMonitor.sleepMonitor(1500L);
                } catch (Exception unused) {
                }
                synchronized (ad.this.i) {
                    if (this.f106797a) {
                        return;
                    }
                    if (Logger.debug()) {
                        Logger.d("UpdateHelper", "mUpdating " + ad.this.h);
                    }
                    if (!ad.this.h) {
                        return;
                    }
                    int i = ad.this.i.f106824a;
                    int i2 = ad.this.i.f106825b;
                    long j = 1;
                    if (i2 > 0) {
                        j = (i * 100) / i2;
                        if (j > 99) {
                            j = 99;
                        }
                    }
                    Message obtainMessage = ad.this.e.obtainMessage(5);
                    obtainMessage.arg1 = (int) j;
                    ad.this.e.sendMessage(obtainMessage);
                }
            }
        }

        c() {
        }
    }

    private void al() {
        String str;
        int i;
        if (!ad()) {
            return;
        }
        AppCommonContext appCommonContext = this.aE;
        if (appCommonContext != null) {
            str = appCommonContext.getStringAppName();
        } else {
            str = "";
        }
        String string = this.d.getString(R.string.c4y);
        if (Build.VERSION.SDK_INT >= 23) {
            i = 67108864;
        } else {
            i = 0;
        }
        PendingIntent activity = PendingIntent.getActivity(this.d, 0, new Intent(), i);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this.d);
        if (Build.VERSION.SDK_INT >= 26) {
            builder.setChannelId("update_channel_01");
            builder.setVibrate(new long[]{0});
        }
        builder.setSmallIcon(android.R.drawable.stat_notify_error).setChannelId("update_channel_01").setTicker(string).setWhen(System.currentTimeMillis()).setContentTitle(str).setContentText(string).setContentIntent(activity).setAutoCancel(true);
        a(R.id.eo1, builder.build());
    }

    public synchronized boolean A() {
        boolean z = true;
        if (!this.x) {
            aj();
            this.x = true;
        }
        if (this.T != this.f) {
            return false;
        }
        long currentTimeMillis = System.currentTimeMillis();
        File file = new File(this.t);
        if (file.exists() && file.isFile() && currentTimeMillis - file.lastModified() < 86400000) {
            return false;
        }
        File file2 = new File(this.v);
        if (file2.exists() && file2.isFile()) {
        }
        z = false;
        return z;
    }

    public synchronized File B() {
        if (!this.x) {
            aj();
            this.x = true;
        }
        String str = this.s + File.separator + "predownload.apk";
        this.v = str;
        try {
            File file = new File(str);
            if (!file.exists()) {
                return null;
            }
            if (!file.isFile()) {
                return null;
            }
            if (System.currentTimeMillis() - file.lastModified() > 86400000) {
                file.delete();
                return null;
            }
            return file;
        } catch (Throwable th) {
            th.printStackTrace();
            return null;
        }
    }

    public void J() {
        if (!TextUtils.isEmpty(this.g) && !TextUtils.isEmpty(this.M)) {
            try {
                JSONObject jSONObject = new JSONObject();
                jSONObject.put("label", "detail_ad");
                jSONObject.put("ext_json", (Object) null);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (com.ss.android.common.app.permission.h.b().a(this.d, "android.permission.WRITE_EXTERNAL_STORAGE") || Build.VERSION.SDK_INT >= 30) {
                q.a().a(this.g, this.M, this.d, true, true, false, this.ap);
                return;
            }
            return;
        }
        if (Logger.debug()) {
            Logger.d("UpdateHelper", "from startBindAppDownload has no Permission");
        }
        K();
    }

    public void P() {
        if (!p.a().m()) {
            ab.b(6, "condition not match");
            return;
        }
        if (!p.a().h()) {
            ab.b(6, "network not available");
            return;
        }
        if (!p.a().i()) {
            ab.b(6, "network not wifi");
            return;
        }
        if (!p.a().j()) {
            ab.b(6, "network not in house");
        } else if (!URLUtil.isValidUrl(this.y)) {
            ab.b(6, "url not valid");
        } else {
            ah();
        }
    }

    public boolean Q() {
        File file = new File(this.v);
        if (!file.isFile() || !file.exists()) {
            file = new File(this.t);
            if (!file.isFile() || !file.exists()) {
                ab.b(6, "downloaded file not exist");
                Logger.w("UpdateHelper", "checkBgDownloadApkValid: downloaded file not exist");
                return false;
            }
        }
        String md5Hex = DigestUtils.md5Hex(file);
        if (!TextUtils.isEmpty(md5Hex) && !TextUtils.isEmpty(this.af) && md5Hex.equalsIgnoreCase(this.af)) {
            if (!com.bytedance.common.utility.h.a(this.d, file.getPath())) {
                ab.b(6, "signature not match");
                Logger.w("UpdateHelper", "checkBgDownloadApkValid: signature not match");
                return false;
            }
            return true;
        }
        ab.b(6, "md5 not match");
        Logger.w("UpdateHelper", "checkBgDownloadApkValid: md5 not match");
        return false;
    }

    private void ak() {
        String str;
        int i;
        int i2;
        File file = new File(this.t);
        if (file.exists() && file.isFile()) {
            AppCommonContext appCommonContext = this.aE;
            if (appCommonContext != null) {
                str = appCommonContext.getStringAppName();
            } else {
                str = "";
            }
            String format = String.format(this.d.getString(R.string.c53), str, g());
            String format2 = String.format(this.d.getString(R.string.c52), g());
            Intent b2 = b(this.d, file);
            if (Build.VERSION.SDK_INT >= 23) {
                i = 67108864;
            } else {
                i = 0;
            }
            PendingIntent activity = PendingIntent.getActivity(this.d, 0, b2, i);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this.d);
            if (Build.VERSION.SDK_INT >= 26) {
                builder.setChannelId("update_channel_01");
                builder.setVibrate(new long[]{0});
            }
            t tVar = this.az;
            if (tVar != null) {
                i2 = tVar.f106861a;
            } else if (Build.VERSION.SDK_INT >= 21) {
                i2 = R.drawable.status_icon_l;
            } else {
                i2 = R.drawable.status_icon;
            }
            builder.setSmallIcon(i2);
            builder.setTicker(format);
            builder.setWhen(System.currentTimeMillis());
            builder.setContentTitle(str).setContentText(format2);
            builder.setContentIntent(activity);
            builder.setAutoCancel(true);
            a(R.id.eo2, builder.build());
            a(this.d, file);
            return;
        }
        ab.a(this.y, this.f, false, "install_fail", "notifyDownloadReady");
    }

    private void am() {
        String str;
        String str2;
        int i;
        int i2;
        if (!ad()) {
            return;
        }
        AppCommonContext appCommonContext = this.aE;
        if (appCommonContext != null) {
            str = appCommonContext.getStringAppName();
        } else {
            str = "";
        }
        String format = String.format(this.d.getString(R.string.c50), str, g());
        String format2 = String.format(this.d.getString(R.string.c4z), g());
        t tVar = this.az;
        PendingIntent pendingIntent = null;
        if (tVar != null) {
            str2 = tVar.f106862b;
        } else {
            str2 = null;
        }
        Intent intent = new Intent();
        if (!TextUtils.isEmpty(str2)) {
            if (Logger.debug()) {
                Logger.d("UpdateHelper", "iUpdateActivity.getClass().getName() " + str2);
            }
            intent.setClassName(this.d, str2);
        } else {
            intent.setClassName(this.d, UpdateProgressActivity.class.getName());
        }
        intent.putExtra("from_update_avail", true);
        intent.addFlags(536870912);
        if (Build.VERSION.SDK_INT >= 23) {
            i = 67108864;
        } else {
            i = 0;
        }
        PendingIntent activity = PendingIntent.getActivity(this.d, 0, intent, i);
        t tVar2 = this.az;
        if (tVar2 == null || !tVar2.f106863c) {
            pendingIntent = activity;
        }
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this.d);
        if (Build.VERSION.SDK_INT >= 26) {
            builder.setChannelId("update_channel_01");
            builder.setVibrate(new long[]{0});
        }
        t tVar3 = this.az;
        if (tVar3 != null) {
            i2 = tVar3.f106861a;
        } else if (Build.VERSION.SDK_INT >= 21) {
            i2 = R.drawable.status_icon_l;
        } else {
            i2 = R.drawable.status_icon;
        }
        builder.setSmallIcon(i2).setTicker(format).setWhen(System.currentTimeMillis()).setContentTitle(str).setContentText(format2).setContentIntent(pendingIntent).setAutoCancel(true);
        a(R.id.eo4, builder.build());
    }

    private ad() {
        this.d = null;
        this.ak = 0;
        this.al = 0;
        this.am = 0;
        this.an = "";
        this.aE = (AppCommonContext) ServiceManager.getService(AppCommonContext.class);
        IUpdateConfig iUpdateConfig = this.ay;
        if (iUpdateConfig != null) {
            t updateConfig = iUpdateConfig.getUpdateConfig();
            this.az = updateConfig;
            this.ar = updateConfig.r;
        }
        if (this.az.j != null) {
            this.aB = this.az.j;
        } else {
            this.aB = PThreadExecutorsUtils.newFixedThreadPool(2, new DefaultThreadFactory("/UpdateHelper"));
        }
        this.l = (ApplogService) ServiceManager.getService(ApplogService.class);
        AppCommonContext appCommonContext = this.aE;
        if (appCommonContext != null) {
            this.d = appCommonContext.getContext().getApplicationContext();
        } else if (this.az.a() != null) {
            AppCommonContext a2 = this.az.a();
            this.aE = a2;
            this.d = a2.getContext().getApplicationContext();
        }
        SharedPreferences sharedPreferences = this.d.getSharedPreferences("update_info", 0);
        this.ak = sharedPreferences.getInt("persistent_release_rule_id", 0);
        this.al = sharedPreferences.getInt("persistent_strategy_id", 0);
        this.an = sharedPreferences.getString("persistent_channel", "");
        this.am = sharedPreferences.getInt("persistent_tip_version_code", 0);
        this.k = new aa(this.d);
        b(this.d);
        this.e = new Handler(Looper.getMainLooper()) {
            @Override
            public void handleMessage(Message message) {
                ad.this.a(message);
            }
        };
        this.s = a(this.d, this.az);
        this.t = this.s + File.separator + "update.apk";
        this.u = this.s + File.separator + "update.apk.part";
        this.v = this.s + File.separator + "predownload.apk";
        this.w = this.s + File.separator + "predownload.apk.part";
        com.ss.android.update.c cVar = new com.ss.android.update.c();
        this.i = cVar;
        cVar.f106824a = 0;
        cVar.f106825b = 0;
        com.ss.android.update.c cVar2 = new com.ss.android.update.c();
        this.Y = cVar2;
        cVar2.f106824a = 0;
        cVar2.f106825b = 0;
        try {
            this.q.cancel(R.id.eo3);
        } catch (Exception unused) {
        }
    }

    private void ai() {
        SharedPreferences.Editor edit = this.d.getSharedPreferences("update_info", 0).edit();
        edit.putInt("tip_version_code", this.B);
        edit.putInt("real_version_code", this.f);
        edit.putString("tip_version_name", this.C);
        edit.putString("real_version_name", this.D);
        edit.putString("title", this.H);
        edit.putString("download_url", this.y);
        edit.putString("whats_new", this.E);
        edit.putLong("last_check_time", this.F);
        edit.putBoolean("force_update", this.I);
        edit.putString("already_download_tips", this.G);
        edit.putBoolean("pre_download", this.O);
        edit.putInt("interval_since_notify_update", this.P);
        edit.putLong("pre_download_max_wait_seconds", this.Q);
        edit.putInt("latency", this.R);
        edit.putInt("official", this.aG);
        edit.putBoolean("bind_download_data", this.f106772J);
        edit.putBoolean("hint_checked", this.K);
        edit.putString("hint_text", this.L);
        edit.putString("name", this.M);
        edit.putString("package", this.N);
        edit.putString("bind_app_download_url", this.g);
        edit.putString("market_update_package", this.av);
        edit.putString("market_update_intent_tips", this.j);
        edit.putString("market_update_intent_url", this.aw);
        edit.putBoolean("market_update_enable", this.ax);
        edit.putInt("enable_client_strategy", this.Z);
        edit.putString("distribute_id", this.aa);
        edit.putInt("artifact_id", this.ab);
        edit.putInt("package_type", this.ac);
        edit.putInt("popup_type", this.ad);
        edit.putString("update_button_text", this.ae);
        edit.putString("md5", this.af);
        edit.putInt("release_rule_id", this.ah);
        edit.putInt("strategy_id", this.ai);
        edit.putString("channel", this.aj);
        SharedPrefsEditorCompat.apply(edit);
    }

    private void aj() {
        AppCommonContext appCommonContext = this.aE;
        if (appCommonContext != null) {
            this.z = appCommonContext.getUpdateVersionCode();
        }
        if (this.z < 1) {
            this.z = 1;
        }
        SharedPreferences sharedPreferences = this.d.getSharedPreferences("update_info", 0);
        this.B = sharedPreferences.getInt("tip_version_code", 0);
        this.f = sharedPreferences.getInt("real_version_code", 0);
        this.C = sharedPreferences.getString("tip_version_name", "");
        this.D = sharedPreferences.getString("real_version_name", "");
        this.E = sharedPreferences.getString("whats_new", "");
        this.F = sharedPreferences.getLong("last_check_time", 0L);
        this.H = sharedPreferences.getString("title", "");
        this.y = sharedPreferences.getString("download_url", "");
        this.I = sharedPreferences.getBoolean("force_update", false);
        this.G = sharedPreferences.getString("already_download_tips", "");
        this.O = sharedPreferences.getBoolean("pre_download", false);
        this.P = sharedPreferences.getInt("interval_since_notify_update", 2);
        this.Q = sharedPreferences.getLong("pre_download_max_wait_seconds", -1L);
        this.R = sharedPreferences.getInt("latency", 0);
        this.aG = sharedPreferences.getInt("official", 0);
        this.S = sharedPreferences.getString("download_etag", "");
        this.T = sharedPreferences.getInt("download_version", 0);
        this.U = sharedPreferences.getInt("download_size", -1);
        this.W = sharedPreferences.getInt("pre_download_size", -1);
        this.f106772J = sharedPreferences.getBoolean("bind_download_data", false);
        this.K = sharedPreferences.getBoolean("hint_checked", false);
        this.L = sharedPreferences.getString("hint_text", "");
        this.M = sharedPreferences.getString("name", "");
        this.N = sharedPreferences.getString("package", "");
        this.g = sharedPreferences.getString("bind_app_download_url", "");
        this.j = sharedPreferences.getString("market_update_intent_tips", "");
        this.aw = sharedPreferences.getString("market_update_intent_url", "");
        this.av = sharedPreferences.getString("market_update_package", "");
        this.ax = sharedPreferences.getBoolean("market_update_enable", false);
        this.Z = sharedPreferences.getInt("enable_client_strategy", 0);
        this.aa = sharedPreferences.getString("distribute_id", "");
        this.ab = sharedPreferences.getInt("artifact_id", 0);
        this.ac = sharedPreferences.getInt("package_type", 0);
        this.ad = sharedPreferences.getInt("popup_type", -1);
        this.ae = sharedPreferences.getString("update_button_text", "");
        this.af = sharedPreferences.getString("md5", "");
        this.ah = sharedPreferences.getInt("release_rule_id", 0);
        this.ai = sharedPreferences.getInt("strategy_id", 0);
        this.aj = sharedPreferences.getString("channel", "");
        this.aM = sharedPreferences.getLong("last_any_dialog_show_time", 0L);
    }

    public void e(boolean z) {
        this.ag = true;
        ab.g(0);
        a(1, z);
    }

    public void f(boolean z) {
        this.ag = true;
        ab.g(0);
        a(1, z);
    }

    private void p(boolean z) {
        if (!this.x) {
            synchronized (this) {
                if (!this.x) {
                    aj();
                    this.x = true;
                }
            }
        }
        if (!this.I && z) {
            this.aM = System.currentTimeMillis();
            SharedPreferences.Editor edit = this.d.getSharedPreferences("update_info", 0).edit();
            edit.putLong("last_any_dialog_show_time", this.aM);
            SharedPrefsEditorCompat.apply(edit);
        }
    }

    private boolean q(boolean z) {
        if (!this.x) {
            synchronized (this) {
                if (!this.x) {
                    aj();
                    this.x = true;
                }
            }
        }
        if (this.I || !z) {
            return false;
        }
        long currentTimeMillis = System.currentTimeMillis();
        if (currentTimeMillis - this.aM < this.az.i) {
            return true;
        }
        return false;
    }

    public void g(boolean z) {
        String str;
        a(2, z);
        ab.g(1);
        String str2 = this.y;
        int i = this.f;
        if (z) {
            str = "auto";
        } else {
            str = "trigger";
        }
        ab.a("test_invitation_popup_click", str2, i, str, -1, this.I);
        this.ag = false;
    }

    public void h(boolean z) {
        String str;
        a(3, z);
        ab.g(2);
        String str2 = this.y;
        int i = this.f;
        if (z) {
            str = "auto";
        } else {
            str = "trigger";
        }
        ab.a("test_invitation_popup_close", str2, i, str, -1, this.I);
        this.ag = false;
    }

    public void i(boolean z) {
        int i;
        String str;
        a(2, z);
        if (p.a().d()) {
            i = 4;
        } else {
            i = 3;
        }
        ab.g(1);
        String str2 = this.y;
        int i2 = this.f;
        if (z) {
            str = "auto";
        } else {
            str = "trigger";
        }
        ab.a("test_invitation_popup_click", str2, i2, str, i, this.I);
        this.ag = false;
    }

    public void j(boolean z) {
        int i;
        String str;
        a(3, z);
        if (p.a().d()) {
            i = 4;
        } else {
            i = 3;
        }
        ab.g(2);
        String str2 = this.y;
        int i2 = this.f;
        if (z) {
            str = "auto";
        } else {
            str = "trigger";
        }
        ab.a("test_invitation_popup_close", str2, i2, str, i, this.I);
        this.ag = false;
    }

    public void l(final boolean z) {
        synchronized (this) {
            if (!this.x) {
                aj();
                this.x = true;
            }
            if (this.X) {
                return;
            }
            this.Y.f106824a = 0;
            this.Y.f106825b = 0;
            this.X = true;
            ag();
            int i = this.T;
            int i2 = this.f;
            if (i != i2) {
                this.T = i2;
                a(i2, -1, "", true);
            }
            new ThreadPlus("StartDownload-Thread") {
                @Override
                public void run() {
                    try {
                        aa.a aVar = new aa.a();
                        aVar.f106767a = z;
                        if (ad.this.n) {
                            Message obtain = Message.obtain();
                            obtain.what = 8;
                            obtain.arg1 = 1;
                            obtain.obj = aVar;
                            ad.this.e.sendMessage(obtain);
                        } else {
                            Message obtain2 = Message.obtain();
                            obtain2.what = 9;
                            obtain2.arg1 = 1;
                            obtain2.obj = aVar;
                            ad.this.e.sendMessage(obtain2);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }.start();
        }
    }

    private void b(int i) {
        if (Build.VERSION.SDK_INT >= 24 && !this.q.areNotificationsEnabled()) {
            Log.w("UpdateHelper", "(cancelNotification)notification is disable, id = " + i);
            return;
        }
        try {
            this.q.cancel(i);
        } catch (Exception e) {
            Log.e("UpdateHelper", "cancel notification exception, e = " + e);
            e.printStackTrace();
        }
    }

    private void o(boolean z) {
        if (z) {
            this.f106773a = false;
            this.t = this.s + File.separator + "update_alpha.apk";
            this.u = this.s + File.separator + "update_alpha.apk.part";
            return;
        }
        this.t = this.s + File.separator + "update.apk";
        this.u = this.s + File.separator + "update.apk.part";
        if (!this.f106773a) {
            this.f106773a = true;
        }
    }

    public void k(final boolean z) {
        synchronized (this) {
            if (!this.x) {
                aj();
                this.x = true;
            }
            if (this.h) {
                ab.a(this.y, this.f, false, "start_download", "mUpdating");
                return;
            }
            o(z);
            this.i.f106824a = 0;
            this.i.f106825b = 0;
            this.h = true;
            af();
            int i = this.T;
            int i2 = this.f;
            if (i != i2) {
                this.T = i2;
                a(i2, -1, "", false);
            }
            new ThreadPlus("StartDownload-Thread") {
                @Override
                public void run() {
                    try {
                        if (ad.this.n) {
                            Message obtain = Message.obtain();
                            obtain.what = 8;
                            obtain.arg1 = 0;
                            if (z) {
                                obtain.arg2 = 1;
                            }
                            ad.this.e.sendMessage(obtain);
                            return;
                        }
                        Message obtain2 = Message.obtain();
                        obtain2.what = 9;
                        obtain2.arg1 = 0;
                        ad.this.e.sendMessage(obtain2);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }.start();
        }
    }

    private void b(Context context) {
        try {
            this.q = (NotificationManager) this.d.getSystemService(com.bytedance.ies.bullet.core.event.c.f18806b);
            if (Build.VERSION.SDK_INT >= 26) {
                int i = 3;
                t tVar = this.az;
                if (tVar != null && tVar.t) {
                    i = 0;
                }
                String str = "update_channel_name";
                t tVar2 = this.az;
                if (tVar2 != null && !TextUtils.isEmpty(tVar2.p)) {
                    str = this.az.p;
                }
                NotificationChannel notificationChannel = new NotificationChannel("update_channel_01", str, i);
                notificationChannel.enableVibration(false);
                notificationChannel.setSound(null, null);
                this.q.createNotificationChannel(notificationChannel);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void c(int i) {
        WeakReference<Activity> weakReference;
        if (this.ag) {
            ab.b(6, "other dialog showing");
            return;
        }
        f fVar = this.aK;
        if (fVar != null && fVar.c()) {
            ab.b(6, "already shown");
            return;
        }
        if (p.a().b(this.f)) {
            ab.b(6, "ignore version:" + this.f);
            return;
        }
        if (!p.a().m()) {
            ab.b(6, "condition not match2");
            return;
        }
        aj c2 = this.ay.getUpdateConfig().c();
        if (c2 == null || (weakReference = c2.f106814a) == null) {
            return;
        }
        Activity activity = weakReference.get();
        if (activity != null && !activity.isFinishing()) {
            if (activity.getResources().getConfiguration().orientation == 2 && !this.ay.getUpdateConfig().o) {
                ab.b(6, "reason_no_oriental_dialog");
                return;
            }
            f fVar2 = this.aK;
            if (fVar2 == null || !fVar2.c()) {
                this.aK = new com.ss.android.update.a(activity);
            }
            this.aK.a(i);
            return;
        }
        ab.b(6, "activity_is_not_active");
    }

    private Notification d(int i) {
        String str;
        String str2;
        int i2;
        PendingIntent pendingIntent;
        NotificationCompat.Builder builder;
        AppCommonContext appCommonContext = this.aE;
        if (appCommonContext == null) {
            str = "";
        } else {
            str = appCommonContext.getStringAppName();
        }
        String format = String.format(this.d.getString(R.string.c51), str, g());
        String str3 = "" + i + "%";
        t tVar = this.az;
        if (tVar != null) {
            str2 = tVar.f106862b;
        } else {
            str2 = null;
        }
        Intent intent = new Intent();
        if (!TextUtils.isEmpty(str2)) {
            if (Logger.debug()) {
                Logger.d("UpdateHelper", "iUpdateActivity.getClass().getName() " + str2);
            }
            intent.setClassName(this.d, str2);
        } else {
            intent.setClassName(this.d, UpdateProgressActivity.class.getName());
        }
        intent.addFlags(536870912);
        if (Build.VERSION.SDK_INT >= 23) {
            i2 = 67108864;
        } else {
            i2 = 0;
        }
        PendingIntent activity = PendingIntent.getActivity(this.d, 0, intent, i2);
        t tVar2 = this.az;
        if (tVar2 != null && tVar2.f106863c) {
            pendingIntent = null;
        } else {
            pendingIntent = activity;
        }
        if (i != 0 && (builder = this.r) != null) {
            return m.a(this.d, builder, format, str3, i);
        }
        NotificationCompat.Builder builder2 = new NotificationCompat.Builder(this.d);
        this.r = builder2;
        builder2.setChannelId("update_channel_01");
        return m.a(this.d, this.r, android.R.drawable.stat_sys_download, null, str, format, str3, i, pendingIntent);
    }

    private boolean n(boolean z) {
        int i = this.ad;
        if ((i != 2 && i != 0) || (!TextUtils.isEmpty(this.H) && this.f != -1 && this.B != -1 && !TextUtils.isEmpty(this.E))) {
            if (this.ad == 1 && (TextUtils.isEmpty(this.H) || TextUtils.isEmpty(this.E))) {
                ab.b("reason_lack_information_normal");
                this.n = false;
                this.aL = false;
                return false;
            }
            int i2 = this.ad;
            if (i2 != 0 && i2 != 1) {
                if (i2 == 2) {
                    if (!p.a().f106847c) {
                        ab.b("reason_no_normal_guide");
                        this.n = false;
                        return false;
                    }
                    this.aL = false;
                }
            } else {
                if (!p.a().f106845a) {
                    ab.b("reason_no_local_guide");
                    this.n = false;
                    this.aL = false;
                    return false;
                }
                if (TextUtils.isEmpty(this.ae)) {
                    ab.b("reason_no_button_text");
                    this.n = false;
                    this.aL = false;
                    return false;
                }
                if (!p.a().j()) {
                    this.aL = false;
                    ab.b("reason_local_out_of_house");
                    this.n = false;
                    return false;
                }
                this.aL = true;
                if (this.ad == 1) {
                    if (!p.a().f()) {
                        ab.b("reason_cannot_open_local_package");
                        this.aL = false;
                        this.n = false;
                        return false;
                    }
                    if (!q(z)) {
                        return true;
                    }
                    ab.b("reason_local_limit_block_dialog");
                    this.aL = false;
                    this.n = false;
                    return false;
                }
            }
            if (StringUtils.isEmpty(this.y)) {
                ab.b("reason_no_updating_url_from_server");
                this.aL = false;
                this.n = false;
                return false;
            }
            if (this.az.d) {
                if (this.ac != 1) {
                    ab.b("reason_local_package_should_not_upgrade_to_other_package");
                    this.aL = false;
                    this.n = false;
                    return false;
                }
                if (!p.a().j()) {
                    ab.b("reason_local_package_should_not_work_out_of_house");
                    this.aL = false;
                    this.n = false;
                    return false;
                }
            }
            if (q(z)) {
                ab.b("reason_local_limit_block_dialog");
                this.aL = false;
                this.n = false;
                return false;
            }
            if (!k()) {
                ab.b("reason_check_version_code_fail");
                this.aL = false;
                this.n = false;
                return false;
            }
            this.n = true;
            return true;
        }
        ab.b("reason_lack_information_normal");
        this.n = false;
        this.aL = false;
        return false;
    }

    public synchronized File b(boolean z) {
        File file;
        File file2;
        o(z);
        if (!this.x) {
            aj();
            this.x = true;
        }
        try {
            long currentTimeMillis = System.currentTimeMillis();
            file = new File(this.t);
            if (file.exists()) {
                if (this.T != this.f || currentTimeMillis - file.lastModified() >= 86400000) {
                    file.delete();
                } else {
                    file2 = new File(this.v);
                    if (file2.exists()) {
                        if (this.T == this.f && currentTimeMillis - file2.lastModified() < 604800000) {
                            if (file == null) {
                                file = file2;
                            }
                        } else {
                            file2.delete();
                        }
                    }
                }
            }
            file = null;
            file2 = new File(this.v);
            if (file2.exists()) {
            }
        } catch (Throwable th) {
            th.printStackTrace();
            return null;
        }
        return file;
    }

    void d(boolean z) {
        if (c(z)) {
            boolean z2 = true;
            if (this.ad == 1) {
                if (p.a().f()) {
                    Message obtain = Message.obtain();
                    obtain.what = 14;
                    obtain.arg1 = z ? 1 : 0;
                    this.e.sendMessageDelayed(obtain, Math.max(this.R, 10));
                } else {
                    ab.b("reason_local_package_not_installed");
                }
            } else {
                boolean m = p.a().m();
                boolean o = p.a().o();
                boolean b2 = p.a().b(this.f);
                boolean z3 = false;
                if (z && this.ad == 2 && m && !b2 && o && Q()) {
                    Message obtainMessage = this.e.obtainMessage(17);
                    obtainMessage.arg1 = 1;
                    obtainMessage.sendToTarget();
                    z2 = false;
                }
                if (!z || !z2 || this.ad != 2 || !m || !o || !b2) {
                    z3 = z2;
                }
                if (z3) {
                    Message obtain2 = Message.obtain();
                    obtain2.what = 6;
                    obtain2.arg1 = z ? 1 : 0;
                    this.e.sendMessage(obtain2);
                }
            }
        } else {
            this.e.sendEmptyMessage(7);
        }
        ab.a();
    }

    public void m(boolean z) {
        int i;
        WeakReference<Activity> weakReference;
        int i2;
        String str;
        if (!this.aL) {
            return;
        }
        this.aL = false;
        if (this.ad == 1 && !p.a().f()) {
            ab.b("reason_cannot_local_package");
            return;
        }
        if (this.aC != 3 && this.aC != -3) {
            i = this.aD;
        } else {
            i = this.aC;
        }
        aj c2 = this.ay.getUpdateConfig().c();
        if (c2 == null || (weakReference = c2.f106814a) == null) {
            return;
        }
        Activity activity = weakReference.get();
        if (activity != null && !activity.isFinishing()) {
            h hVar = this.aI;
            if (hVar != null && !hVar.b()) {
                this.aI = null;
            }
            if (this.aI == null) {
                if (i == -3) {
                    h hVar2 = this.au;
                    this.aI = hVar2;
                    if (hVar2 == null) {
                        if (this.ay.getUpdateConfig().g) {
                            this.aI = new o(activity, z);
                        } else {
                            this.aI = new n(activity, z);
                        }
                    }
                } else if (this.ay.getUpdateConfig().g) {
                    this.aI = new o(activity, z);
                } else {
                    this.aI = new n(activity, z);
                }
            }
            if (!p.a().j()) {
                ab.b("reason_local_out_of_house");
                this.aI = null;
                return;
            }
            if (!this.aI.b()) {
                if (activity.getResources().getConfiguration().orientation == 2 && !this.ay.getUpdateConfig().o) {
                    ab.b("reason_no_oriental_dialog");
                    return;
                }
                if (this.ag) {
                    ab.b("reason_other_update_dialog_showing");
                    return;
                }
                this.aI.a();
                if (p.a().d()) {
                    i2 = 4;
                } else {
                    i2 = 3;
                }
                String str2 = this.y;
                int i3 = this.f;
                if (z) {
                    str = "auto";
                } else {
                    str = "trigger";
                }
                ab.a("test_invitation_popup_show", str2, i3, str, i2, this.I);
                return;
            }
            return;
        }
        ab.b("activity_is_not_active");
    }

    private boolean a(Intent intent) {
        if (intent == null) {
            return false;
        }
        try {
            List a2 = a(this.d.getPackageManager(), intent, 65536);
            if (a2 == null) {
                return false;
            }
            if (a2.size() <= 0) {
                return false;
            }
            return true;
        } catch (Throwable th) {
            Logger.d("UpdateHelper", th.getMessage(), th);
            return false;
        }
    }

    public boolean c(boolean z) {
        JSONObject jSONObject;
        ?? r3;
        ?? r32;
        String str;
        String str2;
        String str3;
        String str4;
        String str5;
        String str6;
        t tVar;
        String executeGet;
        boolean z2;
        boolean z3;
        String str7;
        int i;
        boolean z4;
        String str8;
        String str9;
        String str10;
        boolean z5;
        String str11;
        boolean z6;
        String str12;
        String str13;
        String str14;
        String str15;
        boolean z7;
        ApplogService applogService;
        ?? r33;
        JSONObject optJSONObject;
        boolean z8;
        boolean z9;
        JSONObject optJSONObject2;
        ?? r34;
        ?? r35;
        t tVar2;
        ?? r36;
        if (!this.az.n) {
            return false;
        }
        ?? jSONObject2 = new JSONObject();
        try {
            if (!p.a().b()) {
                ab.a(this.y, this.f, false, "ping_fail", "ping_fail");
                this.n = false;
                Context context = this.d;
                if (context != null && (r36 = this.l) != 0) {
                    r36.onEvent(context, "umeng", "app_update", "check", 0L, 0L, jSONObject2);
                }
                return false;
            }
            StringBuilder sb = new StringBuilder("https://ichannel.snssdk.com/check_version/v7/");
            Context context2 = this.d;
            if (context2 != null && context2.getApplicationInfo() != null) {
                sb.append("?target_sdk_version=");
                sb.append(String.valueOf(this.d.getApplicationInfo().targetSdkVersion));
            }
            if (this.d != null && (tVar2 = this.az) != null && tVar2.k && !TextUtils.isEmpty(this.d.getPackageName())) {
                sb.append("&package_name=");
                sb.append(this.d.getPackageName());
            }
            t tVar3 = this.az;
            if (tVar3 != null && tVar3.e != null) {
                String str16 = this.az.e.f106858a;
                String str17 = this.az.e.f106859b;
                String str18 = this.az.e.f106860c;
                if (!TextUtils.isEmpty(str16)) {
                    sb.append("&city=");
                    sb.append(str16);
                }
                if (!TextUtils.isEmpty(str17)) {
                    sb.append("&longitude=");
                    sb.append(str17);
                }
                if (!TextUtils.isEmpty(str18)) {
                    sb.append("&latitude=");
                    sb.append(str18);
                }
            }
            String a2 = al.a();
            if (!TextUtils.isEmpty(a2)) {
                sb.append("&cpu_abi=");
                sb.append(a2);
            }
            sb.append("&app_extra=");
            sb.append(this.o);
            if (z) {
                str = "1";
            } else {
                str = "0";
            }
            sb.append("&call_type=");
            sb.append(str);
            t tVar4 = this.az;
            if (tVar4 != null) {
                if (tVar4.d) {
                    str2 = "1";
                } else {
                    str2 = "0";
                }
            } else {
                str2 = "0";
            }
            sb.append("&package_type=");
            sb.append(str2);
            ab.a(Integer.parseInt(str2));
            if (p.a().j()) {
                str3 = "1";
            } else {
                str3 = "0";
            }
            sb.append("&inhouse_network=");
            sb.append(str3);
            String g = p.a().g();
            sb.append("&inhouse_network_attr=");
            sb.append(g);
            if (p.a().f106845a) {
                str4 = "1";
            } else {
                str4 = "0";
            }
            sb.append("&enable_intranet_guide=");
            sb.append(str4);
            ab.c(Integer.parseInt(str4));
            if (p.a().d()) {
                str5 = "1";
            } else {
                str5 = "0";
            }
            sb.append("&is_local_installed=");
            sb.append(str5);
            ab.b(Integer.parseInt(str5));
            if (p.a().f106847c) {
                str6 = "1";
            } else {
                str6 = "0";
            }
            sb.append("&enable_normal_popup=");
            sb.append(str6);
            ab.d(Integer.parseInt(str6));
            String str19 = "";
            AppCommonContext appCommonContext = this.aE;
            if (appCommonContext != null) {
                this.z = appCommonContext.getUpdateVersionCode();
                str19 = this.aE.getChannel();
            }
            SharedPreferences sharedPreferences = this.d.getSharedPreferences("update_info", 0);
            int i2 = sharedPreferences.getInt("tip_version_code", 0);
            this.B = i2;
            if (i2 == this.z) {
                this.ak = sharedPreferences.getInt("release_rule_id", 0);
                this.al = sharedPreferences.getInt("strategy_id", 0);
                this.am = this.B;
                this.an = sharedPreferences.getString("channel", "");
                sharedPreferences.edit().putInt("persistent_release_rule_id", this.ak).putInt("persistent_strategy_id", this.al).putInt("persistent_tip_version_code", this.am).putString("persistent_channel", this.an).apply();
            }
            if (this.am == this.z && str19.equals(this.an)) {
                sb.append("&release_rule_id=");
                sb.append(this.ak);
                sb.append("&strategy_id=");
                sb.append(this.al);
                tVar = this.az;
                if (tVar != null && !StringUtils.isEmpty(tVar.l)) {
                    sb.append(this.az.l);
                }
                String sb2 = sb.toString();
                a(jSONObject2, "request", sb2);
                executeGet = com.ss.android.common.util.NetworkUtils.executeGet(androidx.core.view.accessibility.b.g, sb2);
                if (!StringUtils.isEmpty(executeGet)) {
                    ab.h(0);
                    ab.a(this.y, this.f, false, "check_fail", jSONObject2.toString());
                    this.n = false;
                    Context context3 = this.d;
                    if (context3 != null && (r35 = this.l) != 0) {
                        r35.onEvent(context3, "umeng", "app_update", "check", 0L, 0L, jSONObject2);
                    }
                    return false;
                }
                a(jSONObject2, "respone", executeGet);
                JSONObject jSONObject3 = new JSONObject(executeGet);
                if (!"success".equals(jSONObject3.getString("message"))) {
                    ab.h(1);
                    ab.a(this.y, this.f, false, "check_fail", jSONObject2.toString());
                    this.n = false;
                    Context context4 = this.d;
                    if (context4 != null && (r34 = this.l) != 0) {
                        r34.onEvent(context4, "umeng", "app_update", "check", 0L, 0L, jSONObject2);
                    }
                    return false;
                }
                ab.h(-1);
                JSONObject jSONObject4 = jSONObject3.getJSONObject(com.bytedance.accountseal.a.l.n);
                int optInt = jSONObject4.optInt("tip_version_code", -1);
                String optString = jSONObject4.optString("tip_version_name");
                String optString2 = jSONObject4.optString("real_version_name");
                int optInt2 = jSONObject4.optInt("real_version_code", -1);
                String optString3 = jSONObject4.optString("download_url");
                String optString4 = jSONObject4.optString("whats_new", "");
                String optString5 = jSONObject4.optString("title", "");
                if (jSONObject4.optInt("force_update", 0) == 1) {
                    z2 = true;
                } else {
                    z2 = false;
                }
                String optString6 = jSONObject4.optString("already_download_tips", "");
                if (jSONObject4.optInt("pre_download", 0) == 1) {
                    z3 = true;
                } else {
                    z3 = false;
                }
                int optInt3 = jSONObject4.optInt("interval_since_notify_update", 2);
                boolean z10 = z3;
                long optLong = jSONObject4.optLong("pre_download_max_wait_seconds", -1L);
                int optInt4 = jSONObject4.optInt("latency", 0);
                int optInt5 = jSONObject4.optInt("official", 0);
                int optInt6 = jSONObject4.optInt("enable_client_strategy", 0);
                String optString7 = jSONObject4.optString("distribute_id", "");
                int optInt7 = jSONObject4.optInt("artifact_id", 0);
                int optInt8 = jSONObject4.optInt("package_type", 0);
                int optInt9 = jSONObject4.optInt("popup_type", -1);
                String optString8 = jSONObject4.optString("update_button_text", "");
                String optString9 = jSONObject4.optString("md5", "");
                int optInt10 = jSONObject4.optInt("release_rule_id", 0);
                int optInt11 = jSONObject4.optInt("strategy_id", 0);
                String optString10 = jSONObject4.optString("channel", "");
                String str20 = "";
                String str21 = "";
                String str22 = "";
                try {
                    optJSONObject2 = jSONObject4.optJSONObject("market_update");
                    str7 = optString10;
                    i = optInt11;
                } catch (Throwable th) {
                    th = th;
                    str7 = optString10;
                    i = optInt11;
                }
                try {
                    if (jSONObject4.optInt("market_update_enable", 0) > 0) {
                        z4 = true;
                    } else {
                        z4 = false;
                    }
                    if (optJSONObject2 != null) {
                        try {
                            str20 = optJSONObject2.optString("market_update_package");
                            str21 = optJSONObject2.optString("market_update_intent_url");
                            str22 = optJSONObject2.optString("market_update_intent_tips");
                        } catch (Throwable th2) {
                            th = th2;
                            boolean z11 = z4;
                            Logger.d("UpdateHelper", th.getMessage(), th);
                            str8 = str20;
                            str9 = str21;
                            str10 = "";
                            z5 = z11;
                            String str23 = "";
                            String str24 = "";
                            String str25 = "";
                            String str26 = "";
                            boolean z12 = jSONObject4.has("bind_download_data");
                            optJSONObject = jSONObject4.optJSONObject("bind_download_data");
                            if (optJSONObject != null) {
                            }
                            str12 = str23;
                            str13 = str24;
                            str14 = str25;
                            str15 = str26;
                            String str27 = str8;
                            boolean z13 = z12;
                            if (optInt <= 0) {
                            }
                            synchronized (this) {
                            }
                        }
                    }
                    str8 = str20;
                    str10 = str22;
                    z5 = z4;
                    str9 = str21;
                } catch (Throwable th3) {
                    th = th3;
                    z4 = false;
                    boolean z112 = z4;
                    Logger.d("UpdateHelper", th.getMessage(), th);
                    str8 = str20;
                    str9 = str21;
                    str10 = "";
                    z5 = z112;
                    String str232 = "";
                    String str242 = "";
                    String str252 = "";
                    String str262 = "";
                    boolean z122 = jSONObject4.has("bind_download_data");
                    optJSONObject = jSONObject4.optJSONObject("bind_download_data");
                    if (optJSONObject != null) {
                    }
                    str12 = str232;
                    str13 = str242;
                    str14 = str252;
                    str15 = str262;
                    String str272 = str8;
                    boolean z132 = z122;
                    if (optInt <= 0) {
                    }
                    synchronized (this) {
                    }
                }
                String str2322 = "";
                String str2422 = "";
                String str2522 = "";
                String str2622 = "";
                boolean z1222 = jSONObject4.has("bind_download_data");
                optJSONObject = jSONObject4.optJSONObject("bind_download_data");
                if (optJSONObject != null) {
                    str11 = str9;
                    try {
                        if (optJSONObject.optInt("hint_checked", 1) == 1) {
                            z8 = true;
                        } else {
                            z8 = false;
                        }
                        z9 = z8;
                    } catch (Exception e) {
                        e = e;
                        z6 = true;
                        Logger.d("UpdateHelper", e.getMessage(), e);
                        str12 = str2322;
                        str13 = str2422;
                        str14 = str2522;
                        str15 = "";
                        z7 = z6;
                        String str2722 = str8;
                        boolean z1322 = z1222;
                        if (optInt <= 0) {
                        }
                        synchronized (this) {
                        }
                    }
                    try {
                        str2322 = optJSONObject.optString("hint_text", "");
                        str2422 = optJSONObject.optString("name", "");
                        str2522 = optJSONObject.optString("package", "");
                        str2622 = optJSONObject.optString("bind_app_download_url");
                        z7 = z9;
                    } catch (Exception e2) {
                        e = e2;
                        z6 = z9;
                        Logger.d("UpdateHelper", e.getMessage(), e);
                        str12 = str2322;
                        str13 = str2422;
                        str14 = str2522;
                        str15 = "";
                        z7 = z6;
                        String str27222 = str8;
                        boolean z13222 = z1222;
                        if (optInt <= 0) {
                        }
                        synchronized (this) {
                        }
                    }
                } else {
                    str11 = str9;
                    z7 = true;
                }
                str12 = str2322;
                str13 = str2422;
                str14 = str2522;
                str15 = str2622;
                String str272222 = str8;
                boolean z132222 = z1222;
                if (optInt <= 0 && !URLUtil.isValidUrl(optString3)) {
                    a(jSONObject2, "errorMsg", "url is not valid:" + optString3);
                    ab.a(this.y, this.f, false, "check_fail", jSONObject2.toString());
                    this.aL = false;
                    this.n = false;
                    Context context5 = this.d;
                    if (context5 != null && (r33 = this.l) != 0) {
                        r33.onEvent(context5, "umeng", "app_update", "check", 0L, 0L, jSONObject2);
                        return false;
                    }
                    return false;
                }
                synchronized (this) {
                    jSONObject = jSONObject2;
                    try {
                        boolean z14 = this.x;
                        jSONObject2 = z14;
                        if (!z14) {
                            aj();
                            jSONObject2 = 1;
                            this.x = true;
                        }
                        this.B = optInt;
                        this.f = optInt2;
                        this.C = optString;
                        this.D = optString2;
                        this.y = optString3;
                        this.E = optString4;
                        this.F = System.currentTimeMillis();
                        this.H = optString5;
                        this.I = z2;
                        this.G = optString6;
                        this.O = z10;
                        this.P = optInt3;
                        this.Q = optLong;
                        this.R = optInt4;
                        this.aG = optInt5;
                        this.f106772J = z132222;
                        this.K = z7;
                        this.L = str12;
                        this.M = str13;
                        this.N = str14;
                        this.g = str15;
                        this.av = str272222;
                        this.aw = str11;
                        this.j = str10;
                        this.ax = z5;
                        this.Z = optInt6;
                        this.aa = optString7;
                        this.ab = optInt7;
                        this.ac = optInt8;
                        this.ad = optInt9;
                        this.ae = optString8;
                        this.af = optString9;
                        this.ah = optInt10;
                        this.ai = i;
                        this.aj = str7;
                        ai();
                    } catch (Throwable th4) {
                        th = th4;
                        try {
                            Logger.w("UpdateHelper", "check update error: " + th);
                            int a3 = q.a().a(this.d, th);
                            try {
                                if (18 != a3) {
                                    JSONObject jSONObject5 = jSONObject;
                                    a(jSONObject5, "errorCode", Integer.valueOf(a3));
                                    jSONObject2 = jSONObject5;
                                } else {
                                    JSONObject jSONObject6 = jSONObject;
                                    a(jSONObject6, "errorMsg", th.getMessage());
                                    jSONObject2 = jSONObject6;
                                }
                                ab.a(jSONObject2.optString("request"), this.f, false, "check_fail", jSONObject2.toString());
                                Context context6 = this.d;
                                if (context6 != null && (r32 = this.l) != 0) {
                                    r32.onEvent(context6, "umeng", "app_update", "check", 0L, 0L, jSONObject2);
                                }
                                this.n = false;
                                return false;
                            } catch (Throwable th5) {
                                th = th5;
                                Context context7 = this.d;
                                if (context7 != null && (r3 = this.l) != 0) {
                                    r3.onEvent(context7, "umeng", "app_update", "check", 0L, 0L, jSONObject2);
                                }
                                throw th;
                            }
                        } catch (Throwable th6) {
                            th = th6;
                            jSONObject2 = jSONObject;
                        }
                    }
                }
                Logger.i("UpdateHelper", "update info: latest version " + this.B + " " + this.f + ", now " + this.z);
                boolean n = n(z);
                Context context8 = this.d;
                if (context8 != null && (applogService = this.l) != null) {
                    applogService.onEvent(context8, "umeng", "app_update", "check", 0L, 0L, jSONObject);
                }
                return n;
            }
            sb.append("&release_rule_id=");
            sb.append(0);
            sb.append("&strategy_id=");
            sb.append(0);
            tVar = this.az;
            if (tVar != null) {
                sb.append(this.az.l);
            }
            String sb22 = sb.toString();
            a(jSONObject2, "request", sb22);
            executeGet = com.ss.android.common.util.NetworkUtils.executeGet(androidx.core.view.accessibility.b.g, sb22);
            if (!StringUtils.isEmpty(executeGet)) {
            }
        } catch (Throwable th7) {
            th = th7;
            jSONObject = jSONObject2;
        }
    }

    public void a(int i, OnUpdateStatusChangedListener onUpdateStatusChangedListener) {
        a(i, 3, onUpdateStatusChangedListener, true);
    }

    public static String a(Context context, String str) {
        try {
            return context.getPackageManager().getPackageArchiveInfo(str, 64).packageName;
        } catch (Throwable th) {
            Logger.w("UpdateHelper", "failed to get package signatures: " + th);
            return null;
        }
    }

    private Intent b(Context context, File file) {
        Uri fromFile;
        String str;
        if (Build.VERSION.SDK_INT >= 24) {
            t tVar = this.az;
            if (tVar != null) {
                str = tVar.b();
            } else {
                str = "com.ss.android.uri.key";
            }
            fromFile = FileProvider.getUriForFile(context, str, file);
        } else {
            fromFile = Uri.fromFile(file);
        }
        Intent intent = new Intent("android.intent.action.VIEW");
        intent.setDataAndType(fromFile, "application/vnd.android.package-archive");
        int i = 268435456;
        if (Build.VERSION.SDK_INT >= 24) {
            i = 268435457;
        }
        intent.addFlags(i);
        return intent;
    }

    private void a(int i, Notification notification) {
        if (Build.VERSION.SDK_INT >= 24 && !this.q.areNotificationsEnabled()) {
            Log.w("UpdateHelper", "(notifyNotification)notification is disable, id = " + i);
            return;
        }
        try {
            this.q.notify(i, notification);
        } catch (Exception e) {
            Log.e("UpdateHelper", "notify notification exception, e = " + e);
            e.printStackTrace();
        }
    }

    public void a(int i, OnUpdateStatusChangedListener onUpdateStatusChangedListener, boolean z) {
        a(i, 3, onUpdateStatusChangedListener, z);
    }

    private void a(JSONObject jSONObject, String str, Object obj) {
        if (jSONObject != null && !StringUtils.isEmpty(str) && obj != null) {
            try {
                jSONObject.put(str, obj);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public void b(boolean z, boolean z2, aa.a aVar) {
        File file;
        File file2;
        boolean z3;
        String str;
        String str2;
        JSONObject jSONObject = new JSONObject();
        String str3 = null;
        boolean z4 = z;
        if (z) {
            if (!z2) {
                file = new File(this.t);
                file.delete();
                file2 = new File(this.u);
                if (!file2.isFile()) {
                    file2.delete();
                    str3 = this.u + " is not a file.";
                    z4 = z;
                }
                if (!com.bytedance.common.utility.h.a(this.d, file2.getPath())) {
                    a(jSONObject, "wrong_apk", (Object) true);
                    String a2 = a(this.d, file2.getPath());
                    if (!TextUtils.isEmpty(a2)) {
                        a(jSONObject, "apk_package", a2);
                    }
                    if (this.f106773a) {
                        file2.delete();
                        Logger.e("UpdateHelper", "sign check error");
                        str3 = "sign check error";
                        z4 = z;
                    }
                }
                z3 = z;
                if (file2.renameTo(file)) {
                    z3 = true;
                }
                if (!z3) {
                    str = DigestUtils.md5Hex(file);
                } else {
                    str = null;
                }
                z4 = z3;
                if (!StringUtils.isEmpty(str)) {
                    a(jSONObject, "md5", str);
                    z4 = z3;
                }
            } else {
                file = new File(this.v);
                file.delete();
                file2 = new File(this.w);
                if (!file2.isFile()) {
                    file2.delete();
                    str3 = this.w + " is not a file.";
                    z4 = z;
                }
                if (!com.bytedance.common.utility.h.a(this.d, file2.getPath())) {
                }
                z3 = z;
                if (file2.renameTo(file)) {
                }
                if (!z3) {
                }
                z4 = z3;
                if (!StringUtils.isEmpty(str)) {
                }
            }
        }
        String str4 = str3;
        ?? r12 = z4;
        if (z4) {
            if (z2) {
                str2 = this.v;
            } else {
                str2 = this.t;
            }
            r12 = z4;
            if (!new File(str2).isFile()) {
                r12 = 0;
            }
        }
        boolean z5 = this.k.f106761a;
        synchronized (this.i) {
            if (z2) {
                this.X = false;
                if (r12 != 0 && aVar != null && aVar.f106767a) {
                    this.e.sendEmptyMessage(16);
                }
            } else {
                this.h = false;
                if (r12 != 0) {
                    this.e.sendEmptyMessage(1);
                    OnDownloadStatusChangedListener onDownloadStatusChangedListener = this.ar;
                    if (onDownloadStatusChangedListener != null) {
                        onDownloadStatusChangedListener.a(1);
                    }
                } else if (z5) {
                    this.e.sendEmptyMessage(13);
                    OnDownloadStatusChangedListener onDownloadStatusChangedListener2 = this.ar;
                    if (onDownloadStatusChangedListener2 != null) {
                        onDownloadStatusChangedListener2.a(-2);
                    }
                } else {
                    this.e.sendEmptyMessage(4);
                    OnDownloadStatusChangedListener onDownloadStatusChangedListener3 = this.ar;
                    if (onDownloadStatusChangedListener3 != null) {
                        onDownloadStatusChangedListener3.a(-1);
                    }
                }
            }
            synchronized (this.aq) {
                for (OnUpdateStatusChangedListener onUpdateStatusChangedListener : this.aq) {
                    if (onUpdateStatusChangedListener != 0) {
                        onUpdateStatusChangedListener.a(r12, z2);
                    }
                }
            }
        }
        a(jSONObject, "errorMsg", str4);
        a(jSONObject, "url", this.y);
        a(jSONObject, "pre", Integer.valueOf(z2 ? 1 : 0));
        a(jSONObject, "canceled", Integer.valueOf(z5 ? 1 : 0));
        a(jSONObject, "success", Integer.valueOf((int) r12));
        ApplogService applogService = this.l;
        if (applogService != null) {
            applogService.onEvent(this.d, "umeng", "app_update", "download", 0L, 0L, jSONObject);
        }
        if (r12 == 0 && !TextUtils.isEmpty(str4)) {
            ab.a(str4);
            ab.a(this.y, this.f, z2, "fail", str4);
        }
        this.k.b();
    }

    private void a(Context context, boolean z, String str, DialogInterface.OnClickListener onClickListener) {
        i iVar = this.aH;
        if (iVar != null && !iVar.a()) {
            this.aH = null;
        }
        if (this.aH == null) {
            this.aH = new r(context);
        }
        if (!this.aH.a()) {
            this.aH.a(1);
        }
    }
}