四虎影院 v4.1.6版本的 MD5 值为:3c86dc44d368396917a29935d39af88b

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


package h.n.a.c;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import androidx.core.app.NotificationCompat;
import com.bumptech.glide.load.resource.drawable.ResourceDrawableDecoder;
import com.ss.android.downloadlib.activity.TTDelegateActivity;
import com.ss.android.socialbase.appdownloader.DownloadHandlerService;
import com.ss.android.socialbase.downloader.g.c;
import com.tencent.smtt.sdk.TbsListener;
import h.n.a.a.a.c.g;
import h.n.a.a.a.e.a;
import h.n.a.b.a.a.a;
import h.n.a.c.b;
import h.n.a.c.f;
import h.n.a.c.g;
import h.n.a.d.a.c;
import h.n.a.d.a.d;
import h.n.a.d.a.i;
import h.n.a.d.b.b.a;
import java.io.File;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class a implements h.n.a.b.a.b, c.e, a.b {

    public static String f13404c = "a";

    public static volatile a f13405d;
    public long a;
    public d b;

    public class RunnableC0221a implements Runnable {
        public final long a;

        public RunnableC0221a(long j2) {
            this.a = j2;
        }

        @Override
        public void run() {
            a.d().a(this.a);
        }
    }

    public class b implements Runnable {
        public final String a;
        public final h.n.a.b.a.c.a b;

        public b(String str, h.n.a.b.a.c.a aVar) {
            this.a = str;
            this.b = aVar;
        }

        @Override
        public void run() {
            String a = g.c.a(this.a);
            if (TextUtils.isEmpty(a)) {
                return;
            }
            q.a().getSharedPreferences("sp_ttdownloader_md5", 0).edit().putString(String.valueOf(this.b.z()), a).apply();
        }
    }

    @WorkerThread
    public class c implements Runnable {
        public final int a;

        public c(int i2) {
            this.a = i2;
        }

        @Override
        public void run() {
            try {
                h.e.c().a();
                ConcurrentHashMap<Long, h.n.a.b.a.c.a> b = h.e.c().b();
                if (b == null || b.isEmpty()) {
                    return;
                }
                a.this.a(b, this.a);
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }

    public static class d implements Runnable {
        public long a;
        public int b;

        public long f13421c;

        public int f13422d;

        public long f13423e;

        public d(long j2, int i2, long j3, int i3, RunnableC0221a runnableC0221a) {
            this(j2, i2, j3, i3);
        }

        public void b() {
            this.f13423e = System.currentTimeMillis();
        }

        @Override
        public void run() {
            try {
                if (a()) {
                    a.d().a(this.a, this.b);
                }
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }

        public d(long j2, int i2, long j3, int i3) {
            this.a = j2;
            this.b = i2;
            this.f13421c = j3;
            this.f13422d = i3;
        }

        public boolean a() {
            com.ss.android.socialbase.downloader.g.c h2;
            JSONObject jSONObject;
            h.n.a.b.a.c.a d2 = h.e.c().d(this.a);
            if (d2 == null || g.k.b(d2) || d2.K.get() || (h2 = h.n.a.d.b.f.f.a(q.a()).h(d2.J())) == null) {
                return false;
            }
            long b = d2.b();
            long b2 = g.k.b(Environment.getDataDirectory());
            long min = Math.min(524288000L, b2 / 10);
            long L0 = h2.L0();
            boolean z = b <= -1 || L0 <= -1 || ((double) b) >= ((double) min) + (((double) L0) * 2.5d);
            boolean a = h.n.a.d.a.c.a(q.a());
            JSONObject jSONObject2 = new JSONObject();
            int a2 = a(z, d2, h2, a, jSONObject2);
            this.f13422d = a2;
            try {
                jSONObject = jSONObject2;
            } catch (Exception e2) {
                e = e2;
                jSONObject = jSONObject2;
            }
            try {
                jSONObject.putOpt("fail_status", Integer.valueOf(a2));
                jSONObject.putOpt("available_space", Long.valueOf(b / 1048576));
                jSONObject.putOpt("total_space", Long.valueOf(b2 / 1048576));
                if (L0 > 0) {
                    jSONObject.putOpt("package_size", Long.valueOf(L0 / 1048576));
                }
                jSONObject.putOpt("space_enough", Integer.valueOf(z ? 1 : 2));
                if (b > 0 && L0 > 0) {
                    jSONObject.put("available_space_ratio", b / L0);
                }
                jSONObject.putOpt("permission_unknown_source_install", Integer.valueOf(a ? 1 : 2));
                jSONObject.put("is_update_download", d2.i() ? 1 : 2);
            } catch (Exception e3) {
                e = e3;
                e.printStackTrace();
                f.c.a().a("install_failed", jSONObject, d2);
                return true;
            }
            f.c.a().a("install_failed", jSONObject, d2);
            return true;
        }

        private int a(boolean z, h.n.a.b.a.c.a aVar, com.ss.android.socialbase.downloader.g.c cVar, boolean z2, JSONObject jSONObject) {
            h.n.a.d.b.n.a a = h.n.a.d.b.n.a.a(cVar.D1());
            int i2 = 1;
            if (a.a("install_failed_check_ttmd5", 1) == 1) {
                int i1 = cVar.i1();
                try {
                    jSONObject.put("ttmd5_status", i1);
                } catch (Throwable unused) {
                }
                if (!h.n.a.d.b.p.d.a(i1)) {
                    return 2005;
                }
            }
            int i3 = this.f13422d;
            if (i3 != 2000) {
                return i3;
            }
            if (a.a("install_failed_check_signature", 1) == 1 && g.k.d(q.a(), aVar.C())) {
                if (!g.k.a(g.k.h(q.a(), cVar.K1()), g.k.g(q.a(), aVar.C()))) {
                    return 2006;
                }
            }
            if (!z) {
                return 2002;
            }
            long j2 = this.f13423e;
            long j3 = this.f13421c;
            if (j2 <= j3) {
                return 2000;
            }
            try {
                jSONObject.put("install_time", j2 - j3);
                if (aVar.v() <= this.f13421c) {
                    i2 = 0;
                }
                jSONObject.put("install_again", i2);
            } catch (Throwable unused2) {
            }
            return !z2 ? 2003 : 2004;
        }
    }

    public class e implements Runnable {
        public final h.n.a.b.a.c.a a;

        public e(h.n.a.b.a.c.a aVar) {
            this.a = aVar;
        }

        @Override
        public void run() {
            try {
                try {
                    this.a.h(true);
                    a.this.c(this.a);
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
            } finally {
                this.a.h(false);
            }
        }
    }

    public class h {
        public static volatile h b;
        public Handler a = null;

        public class RunnableC0222a implements Runnable {
            public final String a;

            public RunnableC0222a(String str) {
                this.a = str;
            }

            @Override
            public void run() {
                q.d().a(3, q.a(), null, "下载失败,请重试!", null, 0);
                m a = h.n.a.c.h.a().a(this.a);
                if (a != null) {
                    a.f();
                }
            }
        }

        public class b {
            public long a;
            public long b;

            public long f13426c;

            public String f13427d;

            public String f13428e;

            public String f13429f;

            public String f13430g;

            public volatile long f13431h;

            public b() {
            }

            public JSONObject a() {
                JSONObject jSONObject = new JSONObject();
                try {
                    jSONObject.put("mDownloadId", this.a);
                    jSONObject.put("mAdId", this.b);
                    jSONObject.put("mExtValue", this.f13426c);
                    jSONObject.put("mPackageName", this.f13427d);
                    jSONObject.put("mAppName", this.f13428e);
                    jSONObject.put("mLogExtra", this.f13429f);
                    jSONObject.put("mFileName", this.f13430g);
                    jSONObject.put("mTimeStamp", this.f13431h);
                } catch (JSONException e2) {
                    e2.printStackTrace();
                }
                return jSONObject;
            }

            public b(long j2, long j3, long j4, String str, String str2, String str3, String str4) {
                this.a = j2;
                this.b = j3;
                this.f13426c = j4;
                this.f13427d = str;
                this.f13428e = str2;
                this.f13429f = str3;
                this.f13430g = str4;
            }

            public static b a(JSONObject jSONObject) {
                if (jSONObject == null) {
                    return null;
                }
                b bVar = new b();
                try {
                    bVar.a = g.k.a(jSONObject, "mDownloadId");
                    bVar.b = g.k.a(jSONObject, "mAdId");
                    bVar.f13426c = g.k.a(jSONObject, "mExtValue");
                    bVar.f13427d = jSONObject.optString("mPackageName");
                    bVar.f13428e = jSONObject.optString("mAppName");
                    bVar.f13429f = jSONObject.optString("mLogExtra");
                    bVar.f13430g = jSONObject.optString("mFileName");
                    bVar.f13431h = g.k.a(jSONObject, "mTimeStamp");
                    return bVar;
                } catch (Exception e2) {
                    e2.printStackTrace();
                    return null;
                }
            }
        }

        public class c {

            public static int f13432g = 0;

            public static int f13433h = 1;

            public static int f13434i = 2;
            public int a = f13432g;
            public long b = 0;

            public JSONObject f13435c = null;

            public int f13436d = 0;

            public String f13437e = "";

            public String f13438f = "";

            public boolean a() {
                return this.a == f13433h;
            }

            public int b() {
                return this.f13436d;
            }

            public c a(int i2) {
                this.a = i2;
                return this;
            }

            public c b(int i2) {
                this.f13436d = i2;
                return this;
            }
        }

        public class e {
            public final AtomicBoolean a;
            public final ConcurrentHashMap<Long, h.n.a.a.a.c.d> b;

            public final ConcurrentHashMap<Long, h.n.a.a.a.c.c> f13444c;

            public final ConcurrentHashMap<Long, h.n.a.a.a.c.b> f13445d;

            public final ConcurrentHashMap<Long, h.n.a.b.a.c.a> f13446e;

            public class RunnableC0224a implements Runnable {
                public RunnableC0224a() {
                }

                @Override
                public void run() {
                    if (e.this.a.compareAndSet(false, true)) {
                        e.this.f13446e.putAll(C0225h.b().a());
                    }
                }
            }

            public static class b {
                public long a;
                public h.n.a.a.a.c.d b;

                public h.n.a.a.a.c.c f13447c;

                public h.n.a.a.a.c.b f13448d;

                public b() {
                }

                public boolean a() {
                    return this.a <= 0 || this.b == null || this.f13447c == null || this.f13448d == null;
                }

                public b(long j2, h.n.a.a.a.c.d dVar, h.n.a.a.a.c.c cVar, h.n.a.a.a.c.b bVar) {
                    this.a = j2;
                    this.b = dVar;
                    this.f13447c = cVar;
                    this.f13448d = bVar;
                }
            }

            public static class c {
                public static e a = new e(null);
            }

            public e(RunnableC0224a runnableC0224a) {
                this();
            }

            public static e c() {
                return c.a;
            }

            public h.n.a.b.a.c.a d(long j2) {
                return this.f13446e.get(Long.valueOf(j2));
            }

            @NonNull
            public b e(long j2) {
                b bVar = new b();
                bVar.a = j2;
                bVar.b = a(j2);
                bVar.f13447c = b(j2);
                h.n.a.a.a.c.b c2 = c(j2);
                bVar.f13448d = c2;
                if (c2 == null) {
                    bVar.f13448d = new h.n.a.b.a.a.a();
                }
                return bVar;
            }

            public void f(long j2) {
                this.b.remove(Long.valueOf(j2));
                this.f13444c.remove(Long.valueOf(j2));
                this.f13445d.remove(Long.valueOf(j2));
            }

            public e() {
                this.a = new AtomicBoolean(false);
                this.b = new ConcurrentHashMap<>();
                this.f13444c = new ConcurrentHashMap<>();
                this.f13445d = new ConcurrentHashMap<>();
                this.f13446e = new ConcurrentHashMap<>();
            }

            public void a() {
                h.n.a.c.f.e().a((Runnable) new RunnableC0224a(), true);
            }

            public h.n.a.a.a.c.c b(long j2) {
                return this.f13444c.get(Long.valueOf(j2));
            }

            public h.n.a.a.a.c.b c(long j2) {
                return this.f13445d.get(Long.valueOf(j2));
            }

            public void a(h.n.a.a.a.c.d dVar) {
                if (dVar != null) {
                    this.b.put(Long.valueOf(dVar.d()), dVar);
                    if (dVar.x() != null) {
                        dVar.x().a(dVar.d());
                        dVar.x().d(dVar.v());
                    }
                }
            }

            public ConcurrentHashMap<Long, h.n.a.b.a.c.a> b() {
                return this.f13446e;
            }

            public h.n.a.b.a.c.a b(String str) {
                if (TextUtils.isEmpty(str)) {
                    return null;
                }
                for (h.n.a.b.a.c.a aVar : this.f13446e.values()) {
                    if (aVar != null && str.equals(aVar.P())) {
                        return aVar;
                    }
                }
                return null;
            }

            public void a(long j2, h.n.a.a.a.c.c cVar) {
                if (cVar != null) {
                    this.f13444c.put(Long.valueOf(j2), cVar);
                }
            }

            public void b(String str, String str2) {
                if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
                    return;
                }
                for (h.n.a.a.a.c.d dVar : this.b.values()) {
                    if ((dVar instanceof h.n.a.b.a.a.c) && TextUtils.equals(dVar.a(), str)) {
                        ((h.n.a.b.a.a.c) dVar).a(str2);
                    }
                }
            }

            public void a(long j2, h.n.a.a.a.c.b bVar) {
                if (bVar != null) {
                    this.f13445d.put(Long.valueOf(j2), bVar);
                }
            }

            public synchronized void a(h.n.a.b.a.c.a aVar) {
                if (aVar == null) {
                    return;
                }
                this.f13446e.put(Long.valueOf(aVar.z()), aVar);
                C0225h.b().a(aVar);
            }

            public h.n.a.a.a.c.d a(long j2) {
                return this.b.get(Long.valueOf(j2));
            }

            public h.n.a.b.a.c.a a(String str) {
                if (TextUtils.isEmpty(str)) {
                    return null;
                }
                for (h.n.a.b.a.c.a aVar : this.f13446e.values()) {
                    if (aVar != null && str.equals(aVar.C())) {
                        return aVar;
                    }
                }
                return null;
            }

            public h.n.a.b.a.c.a a(com.ss.android.socialbase.downloader.g.c cVar) {
                if (cVar == null) {
                    return null;
                }
                if (!TextUtils.isEmpty(cVar.c())) {
                    try {
                        long a = g.k.a(new JSONObject(cVar.c()), "extra");
                        if (a > 0) {
                            for (h.n.a.b.a.c.a aVar : this.f13446e.values()) {
                                if (aVar != null && aVar.z() == a) {
                                    return aVar;
                                }
                            }
                        }
                    } catch (Exception e2) {
                        e2.printStackTrace();
                    }
                }
                for (h.n.a.b.a.c.a aVar2 : this.f13446e.values()) {
                    if (aVar2 != null && aVar2.J() == cVar.D1()) {
                        return aVar2;
                    }
                }
                for (h.n.a.b.a.c.a aVar3 : this.f13446e.values()) {
                    if (aVar3 != null && TextUtils.equals(aVar3.P(), cVar.G1())) {
                        return aVar3;
                    }
                }
                return null;
            }

            public h.n.a.b.a.c.a a(int i2) {
                for (h.n.a.b.a.c.a aVar : this.f13446e.values()) {
                    if (aVar != null && aVar.J() == i2) {
                        return aVar;
                    }
                }
                return null;
            }

            @NonNull
            public Map<Long, h.n.a.b.a.c.a> a(String str, String str2) {
                HashMap hashMap = new HashMap();
                if (!TextUtils.isEmpty(str) && !TextUtils.isEmpty(str2)) {
                    for (h.n.a.b.a.c.a aVar : this.f13446e.values()) {
                        if (aVar != null && TextUtils.equals(aVar.P(), str)) {
                            aVar.b(str2);
                            hashMap.put(Long.valueOf(aVar.z()), aVar);
                        }
                    }
                }
                return hashMap;
            }

            public synchronized void a(List<Long> list) {
                ArrayList arrayList = new ArrayList();
                Iterator<Long> it = list.iterator();
                while (it.hasNext()) {
                    long longValue = it.next().longValue();
                    arrayList.add(String.valueOf(longValue));
                    this.f13446e.remove(Long.valueOf(longValue));
                }
                C0225h.b().a((List<String>) arrayList);
            }
        }

        public class C0225h {

            public class RunnableC0226a implements Runnable {
                public final Collection a;

                public RunnableC0226a(Collection collection) {
                    this.a = collection;
                }

                @Override
                public void run() {
                    SharedPreferences.Editor edit = C0225h.this.c().edit();
                    for (h.n.a.b.a.c.a aVar : this.a) {
                        if (aVar != null && aVar.z() != 0) {
                            edit.putString(String.valueOf(aVar.z()), aVar.m().toString());
                        }
                    }
                    edit.apply();
                }
            }

            public class b implements Runnable {
                public final List a;

                public b(List list) {
                    this.a = list;
                }

                @Override
                public void run() {
                    SharedPreferences.Editor edit = C0225h.this.c().edit();
                    Iterator it = this.a.iterator();
                    while (it.hasNext()) {
                        edit.remove((String) it.next());
                    }
                    edit.apply();
                }
            }

            public static class c {
                public static C0225h a = new C0225h(null);
            }

            public C0225h(RunnableC0226a runnableC0226a) {
                this();
            }

            public static C0225h b() {
                return c.a;
            }

            public SharedPreferences c() {
                return q.a().getSharedPreferences("sp_ad_download_event", 0);
            }

            public C0225h() {
            }

            @NonNull
            public ConcurrentHashMap<Long, h.n.a.b.a.c.a> a() {
                ConcurrentHashMap<Long, h.n.a.b.a.c.a> concurrentHashMap = new ConcurrentHashMap<>();
                Map<String, ?> all = c().getAll();
                if (all == null) {
                    return concurrentHashMap;
                }
                for (Map.Entry<String, ?> entry : all.entrySet()) {
                    if (entry.getValue() != null) {
                        try {
                            long longValue = Long.valueOf(entry.getKey()).longValue();
                            h.n.a.b.a.c.a b2 = h.n.a.b.a.c.a.b(new JSONObject(String.valueOf(entry.getValue())));
                            if (longValue > 0 && b2 != null) {
                                concurrentHashMap.put(Long.valueOf(longValue), b2);
                            }
                        } catch (Exception e2) {
                            e2.printStackTrace();
                        }
                    }
                }
                return concurrentHashMap;
            }

            public void a(h.n.a.b.a.c.a aVar) {
                ArrayList arrayList = new ArrayList();
                arrayList.add(aVar);
                a((Collection<h.n.a.b.a.c.a>) arrayList);
            }

            public synchronized void a(Collection<h.n.a.b.a.c.a> collection) {
                if (collection != null) {
                    if (!collection.isEmpty()) {
                        h.n.a.c.f.e().a((Runnable) new RunnableC0226a(collection), true);
                    }
                }
            }

            public void a(List<String> list) {
                if (list == null || list.isEmpty()) {
                    return;
                }
                h.n.a.c.f.e().a((Runnable) new b(list), true);
            }
        }

        public static h b() {
            if (b == null) {
                synchronized (h.class) {
                    if (b == null) {
                        b = new h();
                    }
                }
            }
            return b;
        }

        public void a(Context context, com.ss.android.socialbase.downloader.g.c cVar) {
            if (a() && cVar != null) {
                try {
                    File file = new File(cVar.H1(), cVar.E1());
                    if (file.isFile() && file.exists()) {
                        file.delete();
                    }
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
                if (this.a == null) {
                    this.a = new Handler(Looper.getMainLooper());
                }
                String G1 = cVar.G1();
                h.n.a.d.b.f.f.a(context).j(cVar.D1());
                this.a.post(new RunnableC0222a(G1));
            }
        }

        public class f {
            public int a;
            public int b;

            public f(int i2) {
                this.a = i2;
            }

            public int a() {
                return this.a;
            }

            public int b() {
                return this.b;
            }

            public f(int i2, int i3) {
                this.a = i2;
                this.b = i3;
            }
        }

        public class d {
            public static volatile d b;

            public static final String[] f13439c = {"com", ResourceDrawableDecoder.b, "ss"};

            public static final int[] f13440d = {3101, 3102, 3103, 3201, 3202, 3203};
            public final LinkedList<b> a = new LinkedList<>();

            public static class b {
                public final String a;
                public final int b;

                public final String f13441c;

                public final String f13442d;

                public final long f13443e;

                public b(String str, int i2, String str2, String str3, long j2) {
                    this.a = str;
                    this.b = i2;
                    this.f13441c = str2 != null ? str2.toLowerCase() : null;
                    this.f13442d = str3 != null ? str3.toLowerCase() : null;
                    this.f13443e = j2;
                }
            }

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

            private b c(String str) {
                try {
                    PackageManager packageManager = q.a().getPackageManager();
                    PackageInfo packageInfo = packageManager.getPackageInfo(str, 0);
                    if (packageInfo != null) {
                        return new b(str, packageInfo.versionCode, packageInfo.versionName, (String) packageManager.getApplicationLabel(packageInfo.applicationInfo), System.currentTimeMillis());
                    }
                    return null;
                } catch (Throwable th) {
                    th.printStackTrace();
                    return null;
                }
            }

            public void b(String str) {
                b();
                if (TextUtils.isEmpty(str)) {
                    return;
                }
                synchronized (this.a) {
                    Iterator<b> it = this.a.iterator();
                    while (it.hasNext()) {
                        if (str.equals(it.next().a)) {
                            it.remove();
                            return;
                        }
                    }
                }
            }

            public void a(String str) {
                b c2;
                b();
                if (TextUtils.isEmpty(str) || (c2 = c(str)) == null) {
                    return;
                }
                synchronized (this.a) {
                    this.a.add(c2);
                }
            }

            public Pair<b, Integer> b(h.n.a.b.a.c.a aVar) {
                int i2;
                b next;
                if (aVar == null) {
                    return null;
                }
                try {
                    b();
                } catch (Throwable th) {
                    th.printStackTrace();
                }
                if (this.a.isEmpty()) {
                    return null;
                }
                String c2 = aVar.c();
                String C = aVar.C();
                String I = aVar.I();
                int H = aVar.H();
                int length = f13440d.length;
                b[] bVarArr = new b[length];
                synchronized (this.a) {
                    Iterator<b> it = this.a.iterator();
                    PackageInfo packageInfo = null;
                    while (true) {
                        if (!it.hasNext()) {
                            break;
                        }
                        next = it.next();
                        if (next.f13443e >= aVar.v()) {
                            if (TextUtils.isEmpty(c2)) {
                                if (packageInfo == null) {
                                    packageInfo = g.k.a(aVar);
                                }
                                if (packageInfo != null) {
                                    try {
                                        c2 = (String) q.a().getPackageManager().getApplicationLabel(packageInfo.applicationInfo);
                                    } catch (Throwable unused) {
                                    }
                                }
                            }
                            if (!TextUtils.isEmpty(c2) && !TextUtils.isEmpty(next.f13442d)) {
                                c2 = c2.toLowerCase();
                                if (c2.equals(next.f13442d)) {
                                    bVarArr[0] = next;
                                    break;
                                }
                                if (c2.contains(next.f13442d) || next.f13442d.contains(c2)) {
                                    break;
                                }
                            }
                            if (TextUtils.isEmpty(C)) {
                                if (packageInfo == null) {
                                    packageInfo = g.k.a(aVar);
                                }
                                if (packageInfo != null) {
                                    C = packageInfo.packageName;
                                }
                            }
                            if (!TextUtils.isEmpty(C) && !TextUtils.isEmpty(next.a)) {
                                C = C.toLowerCase();
                                if (C.contains(next.a) || next.a.contains(C)) {
                                    break;
                                }
                                if (bVarArr[3] == null) {
                                    if (a(C, next.a)) {
                                        bVarArr[3] = next;
                                    }
                                }
                            }
                            if (bVarArr[4] == null) {
                                if (TextUtils.isEmpty(I)) {
                                    if (packageInfo == null) {
                                        packageInfo = g.k.a(aVar);
                                    }
                                    if (packageInfo != null) {
                                        I = packageInfo.versionName;
                                    }
                                }
                                if (!TextUtils.isEmpty(I) && !TextUtils.isEmpty(next.f13441c)) {
                                    I = I.toLowerCase();
                                    if (I.equals(next.f13441c)) {
                                        bVarArr[4] = next;
                                    }
                                }
                                if (bVarArr[5] == null) {
                                    if (H <= 0) {
                                        if (packageInfo == null) {
                                            packageInfo = g.k.a(aVar);
                                        }
                                        if (packageInfo != null) {
                                            H = packageInfo.versionCode;
                                        }
                                    }
                                    if (H == next.b) {
                                        bVarArr[5] = next;
                                    }
                                }
                            }
                        }
                    }
                    bVarArr[2] = next;
                }
                for (i2 = 0; i2 < length; i2++) {
                    if (bVarArr[i2] != null) {
                        return new Pair<>(bVarArr[i2], Integer.valueOf(f13440d[i2]));
                    }
                }
                return null;
            }

            public b a(h.n.a.b.a.c.a aVar) {
                if (aVar == null) {
                    return null;
                }
                b();
                synchronized (this.a) {
                    Iterator<b> it = this.a.iterator();
                    while (it.hasNext()) {
                        b next = it.next();
                        if (next.f13443e > aVar.v()) {
                            return next;
                        }
                    }
                    return null;
                }
            }

            public static boolean a(String str, String str2) {
                String[] split;
                String[] split2;
                boolean z;
                try {
                    split = str.split("\\.");
                    split2 = str2.split("\\.");
                } catch (Throwable th) {
                    th.printStackTrace();
                }
                if (split.length != 0 && split2.length != 0) {
                    int i2 = 0;
                    int i3 = 0;
                    for (String str3 : split) {
                        String[] strArr = f13439c;
                        int length = strArr.length;
                        int i4 = 0;
                        while (true) {
                            if (i4 >= length) {
                                z = false;
                                break;
                            }
                            String str4 = strArr[i4];
                            if (str4.equals(str3)) {
                                if (i2 < split2.length && str4.equals(split2[i2])) {
                                    i2++;
                                }
                                z = true;
                            } else {
                                i4++;
                            }
                        }
                        if (!z) {
                            int i5 = i3;
                            int i6 = i2;
                            while (i2 < split2.length) {
                                if (str3.equals(split2[i2])) {
                                    if (i2 == i6) {
                                        i6++;
                                    }
                                    i5++;
                                    if (i5 >= 2) {
                                        return true;
                                    }
                                }
                                i2++;
                            }
                            i2 = i6;
                            i3 = i5;
                        }
                    }
                    return false;
                }
                return false;
            }

            private void b() {
                long currentTimeMillis = System.currentTimeMillis();
                synchronized (this.a) {
                    Iterator<b> it = this.a.iterator();
                    while (it.hasNext() && currentTimeMillis - it.next().f13443e > 1800000) {
                        it.remove();
                    }
                }
            }
        }

        public class g {
            public static volatile g a;

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

            public void a(int i2, int i3, h.n.a.b.a.c.a aVar) {
                if (aVar == null) {
                    return;
                }
                h.n.a.d.b.n.a a2 = h.n.a.d.b.n.a.a(aVar.J());
                if (a2.a("report_api_hijack", 0) == 0) {
                    return;
                }
                int i4 = i3 - i2;
                if (i2 <= 0 || i4 <= a2.a("check_api_hijack_version_code_diff", 500)) {
                    return;
                }
                JSONObject jSONObject = new JSONObject();
                try {
                    jSONObject.put("version_code_diff", i4);
                    jSONObject.put("installed_version_code", i3);
                    jSONObject.put("hijack_type", 1);
                } catch (JSONException e2) {
                    e2.printStackTrace();
                }
                f.c.a().a("api_hijack", jSONObject, aVar);
            }
        }

        public boolean a() {
            return q.i().optInt("forbid_invalidte_download_file_install", 0) == 1;
        }
    }

    public class k {
        public static c a;
        public static d b;

        public static class C0227a {
            public static final int[] a;

            static {
                int[] iArr = new int[h.n.a.d.b.k.l.values().length];
                a = iArr;
                try {
                    iArr[h.n.a.d.b.k.l.POOR.ordinal()] = 1;
                } catch (NoSuchFieldError unused) {
                }
                try {
                    a[h.n.a.d.b.k.l.MODERATE.ordinal()] = 2;
                } catch (NoSuchFieldError unused2) {
                }
                try {
                    a[h.n.a.d.b.k.l.GOOD.ordinal()] = 3;
                } catch (NoSuchFieldError unused3) {
                }
                try {
                    a[h.n.a.d.b.k.l.EXCELLENT.ordinal()] = 4;
                } catch (NoSuchFieldError unused4) {
                }
                try {
                    a[h.n.a.d.b.k.l.UNKNOWN.ordinal()] = 5;
                } catch (NoSuchFieldError unused5) {
                }
            }
        }

        public static class b implements h.n.a.d.b.f.h {
            public final String a;
            public c b;

            public b(c cVar, String str) {
                this.b = cVar;
                this.a = str;
            }

            @Override
            public int a(long j2) {
                c cVar;
                if (!g.k.c(this.a) || (cVar = this.b) == null) {
                    return 1;
                }
                return cVar.a(j2);
            }
        }

        public static h.n.a.d.b.f.h a(String str) {
            if (a == null) {
                a = new c(q.i());
            }
            return new b(a, str);
        }

        public static h.n.a.d.b.f.h b(JSONObject jSONObject) {
            return new c(jSONObject);
        }

        public static h.n.a.d.b.f.g c(JSONObject jSONObject) {
            return new d(jSONObject);
        }

        public static class c implements h.n.a.d.b.f.h {
            public int a;
            public ArrayList<int[]> b = new ArrayList<>();

            public c(JSONObject jSONObject) {
                a(jSONObject);
            }

            private void a(JSONObject jSONObject) {
                this.a = jSONObject.optInt("is_open_exp", 0);
                b(jSONObject);
            }

            private void b(JSONObject jSONObject) {
                if (jSONObject == null || !jSONObject.has("download_chunk_config")) {
                    return;
                }
                String obj = jSONObject.opt("download_chunk_config").toString();
                if (TextUtils.isEmpty(obj)) {
                    return;
                }
                JSONObject jSONObject2 = null;
                try {
                    jSONObject2 = new JSONObject(obj);
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
                if (jSONObject2 == null) {
                    return;
                }
                String[] strArr = new String[5];
                String[][] strArr2 = new String[5];
                strArr[1] = jSONObject2.optString("download_chunk_1");
                strArr[2] = jSONObject2.optString("download_chunk_2");
                strArr[3] = jSONObject2.optString("download_chunk_3");
                strArr[4] = jSONObject2.optString("download_chunk_4");
                for (int i2 = 1; i2 < 5; i2++) {
                    if (!TextUtils.isEmpty(strArr[i2])) {
                        try {
                            strArr2[i2] = strArr[i2].split(h.k.b.c.f13093g);
                        } catch (Throwable th) {
                            th.printStackTrace();
                        }
                        for (int i3 = 0; i3 < strArr2[i2].length - 1; i3 += 2) {
                            try {
                                this.b.add(new int[]{i2, Integer.parseInt(strArr2[i2][i3]), Integer.parseInt(strArr2[i2][i3 + 1])});
                            } catch (Throwable th2) {
                                th2.printStackTrace();
                            }
                        }
                    }
                }
            }

            public boolean b(long j2) {
                return true;
            }

            @Override
            public int a(long j2) {
                if (a() && b(j2)) {
                    return a((int) (j2 / 1048576));
                }
                return 1;
            }

            public boolean a() {
                int i2 = this.a;
                return i2 == 1 || i2 == 3;
            }

            private int a(int i2) {
                for (int i3 = 0; i3 < this.b.size(); i3++) {
                    int[] iArr = this.b.get(i3);
                    if (i2 >= iArr[1] && i2 < iArr[2]) {
                        return iArr[0];
                    }
                }
                return 1;
            }
        }

        public static class d implements h.n.a.d.b.f.g {
            public int a;
            public ArrayList<int[]> b = new ArrayList<>();

            public d(JSONObject jSONObject) {
                a(jSONObject);
            }

            private void a(JSONObject jSONObject) {
                this.a = jSONObject.optInt("is_open_exp", 0);
                b(jSONObject);
            }

            private void b(JSONObject jSONObject) {
                if (jSONObject == null || !jSONObject.has("download_chunk_config")) {
                    return;
                }
                String obj = jSONObject.opt("download_chunk_config").toString();
                if (TextUtils.isEmpty(obj)) {
                    return;
                }
                JSONObject jSONObject2 = null;
                try {
                    jSONObject2 = new JSONObject(obj);
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
                if (jSONObject2 == null) {
                    return;
                }
                String optString = jSONObject2.optString("network_quality_operation");
                String optString2 = jSONObject2.optString("network_quality_operand");
                if (!TextUtils.isEmpty(optString) && !TextUtils.isEmpty(optString2)) {
                    try {
                        String[] split = optString.split(h.k.b.c.f13093g);
                        String[] split2 = optString2.split(h.k.b.c.f13093g);
                        if (split.length >= 5 && split2.length >= 5) {
                            for (int i2 = 0; i2 < 5; i2++) {
                                this.b.add(new int[]{Integer.parseInt(split[i2]), Integer.parseInt(split2[i2])});
                            }
                        }
                    } catch (Throwable unused) {
                    }
                }
            }

            @Override
            public int a(int i2, h.n.a.d.b.k.l lVar) {
                return a() ? b(i2, lVar) : i2;
            }

            public boolean a() {
                int i2 = this.a;
                return i2 == 2 || i2 == 3;
            }

            private int b(int i2, h.n.a.d.b.k.l lVar) {
                if (this.b.size() < 5) {
                    return i2;
                }
                int[] iArr = null;
                int i3 = C0227a.a[lVar.ordinal()];
                if (i3 == 1) {
                    iArr = this.b.get(0);
                } else if (i3 == 2) {
                    iArr = this.b.get(1);
                } else if (i3 == 3) {
                    iArr = this.b.get(2);
                } else if (i3 == 4) {
                    iArr = this.b.get(3);
                } else if (i3 == 5) {
                    iArr = this.b.get(4);
                }
                if (iArr == null || iArr.length < 2) {
                    return i2;
                }
                int i4 = iArr[0];
                if (i4 == 1) {
                    i2 += iArr[1];
                } else if (i4 == 2) {
                    i2 -= iArr[1];
                } else if (i4 == 3) {
                    i2 = iArr[1];
                }
                if (i2 > 1) {
                    return i2;
                }
                return 1;
            }
        }

        public static h.n.a.d.b.f.g a() {
            if (b == null) {
                b = new d(q.i());
            }
            return b;
        }

        public static h.n.a.d.b.f.h a(String str, JSONObject jSONObject) {
            if (jSONObject != null && jSONObject.has("download_chunk_config") && !h.n.a.d.b.n.a.g("download_chunk_config")) {
                return b(jSONObject);
            }
            return a(str);
        }

        public static h.n.a.d.b.f.g a(JSONObject jSONObject) {
            if (jSONObject == null || !jSONObject.has("download_chunk_config") || h.n.a.d.b.n.a.g("download_chunk_config")) {
                return null;
            }
            return c(jSONObject);
        }

        public class e {

            public static class RunnableC0228a implements Runnable {
                public final Map a;

                public RunnableC0228a(Map map) {
                    this.a = map;
                }

                @Override
                public void run() {
                    q.e().a("POST", "https://i.snssdk.com/inspect/aegis/client/app/resend/", this.a, null);
                }
            }

            public static void a(com.ss.android.socialbase.downloader.g.c cVar, long j2, String str, String str2) {
                if (cVar == null || q.e() == null) {
                    return;
                }
                String optString = q.i().optString("upload_secret_key");
                if (TextUtils.isEmpty(optString)) {
                    return;
                }
                try {
                    HashMap hashMap = new HashMap();
                    String str3 = q.j().b;
                    hashMap.put("from", str3);
                    String valueOf = String.valueOf(System.currentTimeMillis());
                    hashMap.put(NotificationCompat.CarExtender.f1786p, valueOf);
                    hashMap.put("signature", a(str3, valueOf, optString));
                    JSONObject jSONObject = new JSONObject();
                    jSONObject.put("ad_id", j2);
                    jSONObject.put("log_extra", str);
                    jSONObject.put("download_url", cVar.G1());
                    JSONObject jSONObject2 = new JSONObject();
                    jSONObject2.put("app_name", cVar.F1());
                    jSONObject2.put(com.umeng.commonsdk.proguard.e.f9324n, str2);
                    jSONObject2.put("package_size", cVar.L0());
                    List<com.ss.android.socialbase.downloader.g.e> h2 = cVar.h();
                    if (h2 != null && !h2.isEmpty()) {
                        Iterator<com.ss.android.socialbase.downloader.g.e> it = h2.iterator();
                        while (true) {
                            if (!it.hasNext()) {
                                break;
                            }
                            com.ss.android.socialbase.downloader.g.e next = it.next();
                            if (TextUtils.equals(next.a(), "User-Agent")) {
                                jSONObject2.put("User-Agent", next.b());
                                break;
                            }
                        }
                    }
                    jSONObject.put("request_info", jSONObject2.toString());
                    hashMap.put("info", jSONObject.toString());
                    f.e().b(new RunnableC0228a(hashMap));
                } catch (Exception unused) {
                }
            }

            public static String a(String str, String str2, @NonNull String str3) {
                try {
                    return Base64.encodeToString(g.k.a((str + "|" + str2).getBytes(), str3.getBytes(), "HmacSHA1"), 2);
                } catch (Exception e2) {
                    e2.printStackTrace();
                    return "";
                }
            }
        }
    }

    public class l {
        public Handler a;
        public h.e.b b;

        public AtomicBoolean f13451c = new AtomicBoolean(false);

        public AtomicBoolean f13452d = new AtomicBoolean(false);

        public class C0229a implements m.f {
            public final int a;
            public final String b;

            public final h.n.a.b.a.c.a f13453c;

            public final long f13454d;

            public final m.e f13455e;

            public C0229a(int i2, String str, h.n.a.b.a.c.a aVar, long j2, m.e eVar) {
                this.a = i2;
                this.b = str;
                this.f13453c = aVar;
                this.f13454d = j2;
                this.f13455e = eVar;
            }

            @Override
            public void a(long j2) {
                l.this.a(this.a, this.b, j2, this.f13453c, this.f13454d, this.f13455e);
            }
        }

        public class b implements Runnable {
            public final h.n.a.b.a.c.a a;
            public final m.e b;

            public b(h.n.a.b.a.c.a aVar, m.e eVar) {
                this.a = aVar;
                this.b = eVar;
            }

            @Override
            public void run() {
                if (l.this.f13451c.get()) {
                    return;
                }
                l.this.f13451c.set(true);
                f.c.a().a("clean_fetch_apk_head_failed", this.a);
                this.b.a();
            }
        }

        public class c implements h.n.a.d.b.k.j {
            public final h.n.a.b.a.c.a a;
            public final m.f b;

            public c(h.n.a.b.a.c.a aVar, m.f fVar) {
                this.a = aVar;
                this.b = fVar;
            }

            @Override
            public void a(Map<String, String> map) {
                long j2;
                if (l.this.f13451c.get()) {
                    return;
                }
                l.this.f13451c.set(true);
                try {
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
                if (map != null) {
                    f.c.a().a("clean_fetch_apk_head_success", this.a);
                    j2 = Long.parseLong(map.get(q.b.a.c.l.f18763r));
                    if (j2 > 0) {
                        JSONObject jSONObject = new JSONObject();
                        try {
                            jSONObject.putOpt("apk_size", Long.valueOf(j2));
                            jSONObject.putOpt("available_space", Long.valueOf(l.this.b()));
                        } catch (JSONException e3) {
                            e3.printStackTrace();
                        }
                        f.c.a().a("clean_fetch_apk_size_success", jSONObject, this.a);
                    }
                    this.b.a(j2);
                }
                f.c.a().a("clean_fetch_apk_head_failed", this.a);
                j2 = 0;
                if (j2 > 0) {
                }
                this.b.a(j2);
            }
        }

        public class d implements h.n.a.c.a$i.e {
            public final h.n.a.b.a.c.a a;
            public final m.e b;

            public final String f13459c;

            public d(h.n.a.b.a.c.a aVar, m.e eVar, String str) {
                this.a = aVar;
                this.b = eVar;
                this.f13459c = str;
            }
        }

        public class e implements Runnable {
            public final m.e a;

            public e(m.e eVar) {
                this.a = eVar;
            }

            @Override
            public void run() {
                this.a.a();
            }
        }

        public l(Handler handler) {
            this.a = handler;
        }

        public long b() {
            try {
                return h.n.a.d.b.p.d.c(Environment.getExternalStorageDirectory().toString());
            } catch (Exception e2) {
                e2.printStackTrace();
                return 0L;
            }
        }

        public void a(h.e.b bVar) {
            this.b = bVar;
        }

        public boolean a() {
            return this.f13452d.get();
        }

        public void a(boolean z) {
            this.f13452d.set(z);
        }

        public void a(int i2, long j2, long j3, m.e eVar) {
            if (eVar == null) {
                return;
            }
            boolean z = false;
            this.f13452d.set(false);
            long q2 = g.f.q(i2);
            this.f13451c.set(false);
            String a = this.b.b.a();
            h.n.a.b.a.c.a b2 = h.e.c().b(a);
            if (b2 == null) {
                h.e.b bVar = this.b;
                b2 = new h.n.a.b.a.c.a(bVar.b, bVar.f13447c, bVar.f13448d, 0);
                h.e.c().a(b2);
            }
            h.n.a.b.a.c.a aVar = b2;
            aVar.e(false);
            if (q.m() != null) {
                q.m().a(aVar.z());
            }
            h.n.a.c.a$i.d.c().a(aVar.P());
            if (g.f.r(i2) && g.f.s(i2)) {
                z = true;
            }
            if (j3 > 0 && g.f.s(i2)) {
                f.c.a().a("clean_no_need_fetch_apk_size", aVar);
                a(i2, a, j3, aVar, j2, eVar);
            } else if (z) {
                f.c.a().a("clean_fetch_apk_head_switch_open", aVar);
                a(a, aVar, new C0229a(i2, a, aVar, j2, eVar));
            } else {
                f.c.a().a("clean_fetch_apk_head_switch_close", aVar);
                q2 = 0;
            }
            this.a.postDelayed(new b(aVar, eVar), q2);
        }

        private void a(String str, h.n.a.b.a.c.a aVar, m.f fVar) {
            if (fVar == null) {
                return;
            }
            h.n.a.d.b.k.a.b.a(str, new c(aVar, fVar));
        }

        public void a(int i2, String str, long j2, h.n.a.b.a.c.a aVar, long j3, m.e eVar) {
            this.f13451c.set(true);
            boolean z = false;
            if (j2 > 0) {
                JSONObject jSONObject = new JSONObject();
                try {
                    jSONObject.putOpt("apk_size", Long.valueOf(j2));
                } catch (JSONException e2) {
                    e2.printStackTrace();
                }
                long longValue = (Double.valueOf((g.f.o(i2) + 1.0d) * j2).longValue() + g.f.p(i2)) - j3;
                aVar.e(true);
                long b2 = b();
                if (b2 < longValue) {
                    a(aVar, jSONObject, longValue, b2);
                    a(aVar);
                    long b3 = b();
                    if (b3 < longValue) {
                        aVar.d(true);
                        String P = aVar.P();
                        h.n.a.c.a$i.d.c().a(P, new d(aVar, eVar, P));
                        z = a(i2, aVar, str, longValue);
                    } else {
                        aVar.j("1");
                        h.C0225h.b().a(aVar);
                        try {
                            jSONObject.putOpt("quite_clean_size", Long.valueOf(b3 - b2));
                        } catch (JSONException e3) {
                            e3.printStackTrace();
                        }
                        f.c.a().a("cleanspace_download_after_quite_clean", jSONObject, aVar);
                    }
                }
            }
            if (z) {
                return;
            }
            this.a.post(new e(eVar));
        }

        private boolean a(int i2, @NonNull h.n.a.b.a.c.a aVar, String str, long j2) {
            if (!g.f.t(i2)) {
                f.c.a().a("clean_space_switch_closed", aVar);
                return false;
            }
            f.c.a().a("cleanspace_switch_open", aVar);
            if (q.m() != null) {
                return q.m().a(i2, str, j2);
            }
            h.n.a.a.a.a.l n2 = q.n();
            if (n2 != null) {
                int a = n2.a();
                JSONObject jSONObject = new JSONObject();
                try {
                    jSONObject.putOpt("plugin_status", Integer.valueOf(a));
                } catch (JSONException e2) {
                    e2.printStackTrace();
                }
                f.c.a().a("clean_ad_plugin_status", jSONObject, aVar);
            }
            JSONObject jSONObject2 = new JSONObject();
            try {
                jSONObject2.putOpt("show_dialog_result", 3);
            } catch (JSONException e3) {
                e3.printStackTrace();
            }
            f.c.a().a("cleanspace_window_show", jSONObject2, aVar);
            return false;
        }

        private void a(h.n.a.b.a.c.a aVar) {
            long b2 = b();
            if (q.m() != null) {
                q.m().b();
            }
            h.n.a.c.a$i.c.a();
            h.n.a.c.a$i.c.b();
            if (g.f.u(aVar.J())) {
                h.n.a.c.a$i.c.a(q.a());
            }
            long b3 = b();
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.putOpt("quite_clean_size", Long.valueOf(b3 - b2));
            } catch (JSONException e2) {
                e2.printStackTrace();
            }
            f.c.a().a("clean_quite_finish", jSONObject, aVar);
        }

        private void a(h.n.a.b.a.c.a aVar, JSONObject jSONObject, long j2, long j3) {
            try {
                jSONObject.putOpt("available_space", Long.valueOf(j3));
                jSONObject.putOpt("apk_download_need_size", Long.valueOf(j2));
            } catch (JSONException e2) {
                e2.printStackTrace();
            }
            f.c.a().a("clean_space_no_enough_for_download", jSONObject, aVar);
        }
    }

    public class m implements n, g.l.a {

        public static final String f13461s = "a$m";

        public WeakReference<Context> f13463d;

        public h.n.a.a.a.e.d f13465f;

        public com.ss.android.socialbase.downloader.g.c f13466g;

        public g f13467h;

        public boolean f13469j;

        public long f13470k;

        public SoftReference<h.n.a.a.a.a.s> f13475p;

        public boolean f13476q;
        public final g.l a = new g.l(Looper.getMainLooper(), this);

        public final Map<Integer, Object> f13464e = new ConcurrentHashMap();

        public final h.n.a.d.b.e.b f13468i = new o.d(this.a);

        public long f13471l = -1;

        public h.n.a.a.a.c.d f13472m = null;

        public h.n.a.a.a.c.c f13473n = null;

        public h.n.a.a.a.c.b f13474o = null;
        public o b = new o();

        public l f13462c = new l(this.a);

        public final boolean f13477r = h.n.a.d.b.n.a.c().a("ttdownloader_callback_twice");

        public class RunnableC0230a implements Runnable {
            public RunnableC0230a() {
            }

            @Override
            public void run() {
                Iterator<h.n.a.a.a.c.e> it = o.a((Map<Integer, Object>) m.this.f13464e).iterator();
                while (it.hasNext()) {
                    it.next().b(m.this.q());
                }
            }
        }

        public class c implements e {
            public final int a;
            public final int b;

            public c(int i2, int i3) {
                this.a = i2;
                this.b = i3;
            }

            @Override
            public void a() {
                if (m.this.f13462c.a()) {
                    return;
                }
                h.n.a.d.a.e.n().a(q.a(), this.a, this.b);
            }
        }

        public class d implements e {
            public d() {
            }

            @Override
            public void a() {
                if (m.this.f13462c.a()) {
                    return;
                }
                m.this.o();
            }
        }

        public interface e {
            void a();
        }

        public interface f {
            void a(long j2);
        }

        public class g extends AsyncTask<String, Void, com.ss.android.socialbase.downloader.g.c> {
            public g() {
            }

            @Override
            public com.ss.android.socialbase.downloader.g.c doInBackground(String... strArr) {
                com.ss.android.socialbase.downloader.g.c cVar = null;
                if (strArr == null) {
                    return null;
                }
                if (strArr.length >= 1 && TextUtils.isEmpty(strArr[0])) {
                    return null;
                }
                String str = strArr[0];
                if (m.this.f13472m != null && !TextUtils.isEmpty(m.this.f13472m.n())) {
                    cVar = h.n.a.d.b.f.f.a(q.a()).a(str, m.this.f13472m.n());
                }
                return cVar == null ? h.n.a.d.a.e.n().a(q.a(), str) : cVar;
            }

            public g(m mVar, RunnableC0230a runnableC0230a) {
                this();
            }

            @Override
            public void onPostExecute(com.ss.android.socialbase.downloader.g.c cVar) {
                super.onPostExecute(cVar);
                if (isCancelled() || m.this.f13472m == null) {
                    return;
                }
                try {
                    h.c a = g.k.a(m.this.f13472m.v(), m.this.f13472m.r(), m.this.f13472m.s());
                    h.g.a().a(m.this.f13472m.r(), a.b(), h.e.c().a(cVar));
                    boolean a2 = a.a();
                    if (cVar != null && cVar.D1() != 0 && (a2 || !h.n.a.d.b.f.f.a(q.a()).a(cVar))) {
                        h.n.a.d.b.f.f.a(q.a()).k(cVar.D1());
                        if (m.this.f13466g == null || m.this.f13466g.N1() != -4) {
                            m.this.f13466g = cVar;
                            if (m.this.f13477r) {
                                h.n.a.d.b.f.f.a(q.a()).a(m.this.f13466g.D1(), m.this.f13468i, false);
                            } else {
                                h.n.a.d.b.f.f.a(q.a()).a(m.this.f13466g.D1(), m.this.f13468i);
                            }
                        } else {
                            m.this.f13466g = null;
                        }
                        m.this.b.a(m.this.f13466g, m.this.q(), o.a((Map<Integer, Object>) m.this.f13464e));
                    } else {
                        if (cVar != null && h.n.a.d.b.f.f.a(q.a()).a(cVar)) {
                            h.n.a.d.b.q.b.b().e(cVar.D1());
                            m.this.f13466g = null;
                        }
                        if (m.this.f13466g != null) {
                            h.n.a.d.b.f.f.a(q.a()).k(m.this.f13466g.D1());
                            if (m.this.f13477r) {
                                h.n.a.d.b.f.f.a(m.this.k()).a(m.this.f13466g.D1(), m.this.f13468i, false);
                            } else {
                                h.n.a.d.b.f.f.a(m.this.k()).a(m.this.f13466g.D1(), m.this.f13468i);
                            }
                        }
                        if (!a2) {
                            Iterator<h.n.a.a.a.c.e> it = o.a((Map<Integer, Object>) m.this.f13464e).iterator();
                            while (it.hasNext()) {
                                it.next().a();
                            }
                            m.this.f13466g = null;
                        } else {
                            m.this.f13466g = new c.b(m.this.f13472m.a()).a();
                            m.this.f13466g.c(-3);
                            m.this.b.a(m.this.f13466g, m.this.q(), o.a((Map<Integer, Object>) m.this.f13464e));
                        }
                    }
                    m.this.b.b(m.this.f13466g);
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
            }
        }

        @NonNull
        private h.n.a.a.a.c.c l() {
            h.n.a.a.a.c.c cVar = this.f13473n;
            return cVar == null ? new g.b().a() : cVar;
        }

        @NonNull
        private h.n.a.a.a.c.b m() {
            h.n.a.a.a.c.b bVar = this.f13474o;
            return bVar == null ? new a.b().a() : bVar;
        }

        public void n() {
            this.f13462c.a(new h.e.b(this.f13471l, this.f13472m, l(), m()));
            this.f13462c.a(0, 0L, 0L, new d());
        }

        public void o() {
            Iterator<h.n.a.a.a.c.e> it = o.a(this.f13464e).iterator();
            while (it.hasNext()) {
                it.next().a(this.f13472m, m());
            }
            int a = this.b.a(q.a(), this.f13468i);
            h.n.a.b.a.c.a a2 = a(this.f13472m, a);
            h.e.c().a(a2);
            a2.g(a);
            a2.h(System.currentTimeMillis());
            a2.i(0L);
            g.j.a(f13461s, "beginDownloadWithNewDownloader id:" + a, null);
            if (a != 0) {
                com.ss.android.socialbase.downloader.g.c cVar = this.f13466g;
                if (cVar == null) {
                    this.b.b();
                } else {
                    this.b.d(cVar);
                }
            } else {
                com.ss.android.socialbase.downloader.g.c a3 = new c.b(this.f13472m.a()).a();
                a3.c(-1);
                a(a3);
                f.c.a().a(this.f13471l, new com.ss.android.socialbase.downloader.e.a(2, "start download failed, id=0"));
                g.k.b();
            }
            if (this.b.b(c())) {
                g.j.a(f13461s, "beginDownloadWithNewDownloader onItemClick id:" + a, null);
                j();
            }
        }

        private void p() {
            g gVar = this.f13467h;
            if (gVar != null && gVar.getStatus() != AsyncTask.Status.FINISHED) {
                this.f13467h.cancel(true);
            }
            g gVar2 = new g(this, null);
            this.f13467h = gVar2;
            g.d.a(gVar2, this.f13472m.a(), this.f13472m.v());
        }

        public h.n.a.a.a.e.d q() {
            if (this.f13465f == null) {
                this.f13465f = new h.n.a.a.a.e.d();
            }
            return this.f13465f;
        }

        public class b implements h.n.a.a.a.a.q {
            public b() {
            }

            @Override
            public void a() {
                g.j.a(m.f13461s, "performButtonClickWithNewDownloader start download", null);
                m.this.n();
            }

            @Override
            public void a(String str) {
                g.j.a(m.f13461s, "performButtonClickWithNewDownloader onDenied", null);
            }
        }

        private void f(boolean z) {
            h.n.a.a.a.c.d dVar;
            g.j.a(f13461s, "performButtonClickWithNewDownloader", null);
            com.ss.android.socialbase.downloader.g.c cVar = this.f13466g;
            if (cVar != null && (cVar.N1() == -3 || h.n.a.d.b.f.f.a(q.a()).d(this.f13466g.D1()))) {
                g.j.a(f13461s, "performButtonClickWithNewDownloader continue download, status:" + this.f13466g.N1(), null);
                this.b.d(this.f13466g);
                com.ss.android.socialbase.downloader.g.c cVar2 = this.f13466g;
                if (cVar2 != null && (dVar = this.f13472m) != null) {
                    cVar2.d(dVar.m());
                }
                int N1 = this.f13466g.N1();
                int D1 = this.f13466g.D1();
                h.n.a.b.a.c.a a = h.e.c().a(this.f13466g);
                if (N1 != -4 && N1 != -2 && N1 != -1) {
                    if (s.a(N1)) {
                        this.f13462c.a(true);
                    }
                    h.n.a.d.a.e.n().a(q.a(), D1, N1);
                    s.a(a, this.f13466g, N1);
                    return;
                }
                if (a != null) {
                    a.h(System.currentTimeMillis());
                    a.i(this.f13466g.J0());
                }
                this.f13466g.e(false);
                this.f13462c.a(new h.e.b(this.f13471l, this.f13472m, l(), m()));
                this.f13462c.a(D1, this.f13466g.J0(), this.f13466g.L0(), new c(D1, N1));
                return;
            }
            if (z) {
                f.c.a().a(this.f13471l, 2);
            }
            if (g.f.c(this.f13472m) != 0) {
                n();
            } else {
                g.j.a(f13461s, "performButtonClickWithNewDownloader not start", null);
                this.b.a(new b());
            }
        }

        private boolean i() {
            return q.i().optInt("quick_app_enable_switch", 0) == 0 && j.a(this.f13472m) && j.a(this.f13466g);
        }

        private void j() {
            SoftReference<h.n.a.a.a.a.s> softReference = this.f13475p;
            if (softReference != null && softReference.get() != null) {
                this.f13475p.get().a(this.f13472m, l(), m());
                this.f13475p = null;
            } else {
                q.c().a(k(), this.f13472m, m(), l());
            }
        }

        public Context k() {
            WeakReference<Context> weakReference = this.f13463d;
            if (weakReference != null && weakReference.get() != null) {
                return this.f13463d.get();
            }
            return q.a();
        }

        public boolean c() {
            return this.f13466g != null;
        }

        @Override
        public long d() {
            return this.f13470k;
        }

        public void e() {
            this.a.post(new RunnableC0230a());
        }

        @Override
        public void g() {
            h.e.c().f(this.f13471l);
        }

        private void c(boolean z) {
            if (z) {
                f.c.a().a(this.f13471l, 1);
            }
            e(z);
        }

        private void d(boolean z) {
            f(z);
        }

        private void e(boolean z) {
            g.j.a(f13461s, "performItemClickWithNewDownloader", null);
            if (this.b.c(this.f13466g)) {
                g.j.a(f13461s, "performItemClickWithNewDownloader ButtonClick", null);
                f(z);
            } else {
                g.j.a(f13461s, "performItemClickWithNewDownloader onItemClick", null);
                j();
            }
        }

        @Override
        public m a(int i2, h.n.a.a.a.c.e eVar) {
            if (eVar != null) {
                if (q.i().optInt("back_use_softref_listener") == 1) {
                    this.f13464e.put(Integer.valueOf(i2), eVar);
                } else {
                    this.f13464e.put(Integer.valueOf(i2), new SoftReference(eVar));
                }
            }
            return this;
        }

        @Override
        public m a(h.n.a.a.a.c.d dVar) {
            if (dVar != null) {
                h.e.c().a(dVar);
                this.f13471l = dVar.d();
                this.f13472m = dVar;
                if (p.a(dVar)) {
                    ((h.n.a.b.a.a.c) dVar).a(3L);
                    h.n.a.b.a.c.a d2 = h.e.c().d(this.f13471l);
                    if (d2 != null && d2.A() != 3) {
                        d2.e(3L);
                        h.C0225h.b().a(d2);
                    }
                }
            }
            return this;
        }

        @Override
        public m b(Context context) {
            if (context != null) {
                this.f13463d = new WeakReference<>(context);
            }
            q.b(context);
            return this;
        }

        @Override
        public n a(h.n.a.a.a.a.s sVar) {
            if (sVar == null) {
                this.f13475p = null;
            } else {
                this.f13475p = new SoftReference<>(sVar);
            }
            return this;
        }

        @Override
        public void a() {
            this.f13469j = true;
            h.e.c().a(this.f13471l, l());
            h.e.c().a(this.f13471l, m());
            this.b.a(this.f13471l);
            p();
            if (q.i().optInt("enable_empty_listener", 1) == 1 && this.f13464e.get(Integer.MIN_VALUE) == null) {
                a(Integer.MIN_VALUE, new h.n.a.a.a.a.a());
            }
        }

        @Override
        public m a(h.n.a.a.a.c.b bVar) {
            this.f13474o = bVar;
            h.e.c().a(this.f13471l, m());
            return this;
        }

        @Override
        public m a(h.n.a.a.a.c.c cVar) {
            this.f13473n = cVar;
            this.f13476q = l().k() == 0;
            h.e.c().a(this.f13471l, l());
            return this;
        }

        @Override
        public boolean a(int i2) {
            if (i2 == 0) {
                this.f13464e.clear();
            } else {
                this.f13464e.remove(Integer.valueOf(i2));
            }
            boolean z = false;
            if (this.f13464e.isEmpty()) {
                this.f13469j = false;
                this.f13470k = System.currentTimeMillis();
                if (this.f13466g != null) {
                    h.n.a.d.b.f.f.a(q.a()).k(this.f13466g.D1());
                }
                g gVar = this.f13467h;
                z = true;
                if (gVar != null && gVar.getStatus() != AsyncTask.Status.FINISHED) {
                    this.f13467h.cancel(true);
                }
                this.b.a(this.f13466g);
                String str = f13461s;
                StringBuilder sb = new StringBuilder();
                sb.append("onUnbind removeCallbacksAndMessages, downloadUrl:");
                com.ss.android.socialbase.downloader.g.c cVar = this.f13466g;
                sb.append(cVar == null ? "" : cVar.G1());
                g.j.a(str, sb.toString(), null);
                this.a.removeCallbacksAndMessages(null);
                this.f13465f = null;
                this.f13466g = null;
            }
            return z;
        }

        @Override
        public boolean b() {
            return this.f13469j;
        }

        private boolean b(int i2) {
            if (!i()) {
                return false;
            }
            int i3 = -1;
            String a = this.f13472m.z().a();
            if (i2 == 1) {
                i3 = 5;
            } else if (i2 == 2) {
                i3 = 4;
            }
            f.c.a().a(this.f13471l, i2);
            boolean c2 = g.h.c(q.a(), a);
            if (c2) {
                Message obtain = Message.obtain();
                obtain.what = i3;
                obtain.obj = Long.valueOf(this.f13472m.d());
                this.a.sendMessageDelayed(obtain, j.b().a());
                j.b().a(i3, this.f13472m, this.f13473n);
            } else {
                f.c.a().a(this.f13471l, false, 0);
            }
            return c2;
        }

        public void f() {
            if (this.f13464e.size() == 0) {
                return;
            }
            Iterator<h.n.a.a.a.c.e> it = o.a(this.f13464e).iterator();
            while (it.hasNext()) {
                it.next().a();
            }
            com.ss.android.socialbase.downloader.g.c cVar = this.f13466g;
            if (cVar != null) {
                cVar.c(-4);
            }
        }

        private void b(boolean z) {
            if (this.b.a(this.f13476q) != 1) {
                d(z);
                return;
            }
            if (z) {
                f.c.a().a(this.f13471l, 1);
            }
            j();
        }

        @Override
        public void a(boolean z) {
            if (this.f13466g != null) {
                if (z) {
                    d.e b2 = h.n.a.d.a.e.n().b();
                    if (b2 != null) {
                        b2.a(this.f13466g);
                    }
                    h.n.a.d.b.f.f.a(h.n.a.d.b.f.b.g()).a(this.f13466g.D1(), true);
                    return;
                }
                Intent intent = new Intent(q.a(), (Class<?>) DownloadHandlerService.class);
                intent.setAction("android.ss.intent.action.DOWNLOAD_DELETE");
                intent.putExtra("extra_click_download_ids", this.f13466g.D1());
                q.a().startService(intent);
            }
        }

        @Override
        public void a(long j2, int i2) {
            if (i2 != 2 && i2 != 1) {
                throw new IllegalArgumentException("error actionType");
            }
            if (j2 > 0) {
                h.n.a.a.a.c.d a = h.e.c().a(j2);
                if (a != null) {
                    this.f13472m = a;
                    this.f13471l = j2;
                    this.b.a(j2);
                }
            } else {
                g.k.b();
            }
            if (this.b.a(k(), i2, this.f13476q)) {
                return;
            }
            boolean b2 = b(i2);
            if (i2 == 1) {
                if (b2) {
                    return;
                }
                g.j.a(f13461s, "handleDownload id:" + j2 + ",tryPerformItemClick:", null);
                c(true);
                return;
            }
            if (i2 == 2 && !b2) {
                g.j.a(f13461s, "handleDownload id:" + j2 + ",tryPerformButtonClick:", null);
                b(true);
            }
        }

        @Override
        public void a(Message message) {
            if (message == null || !this.f13469j) {
                return;
            }
            int i2 = message.what;
            if (i2 == 3) {
                this.f13466g = (com.ss.android.socialbase.downloader.g.c) message.obj;
                this.b.a(message, q(), this.f13464e);
                return;
            }
            if (i2 == 4) {
                if (q.l() == null || !q.l().a()) {
                    f.c.a().a(this.f13471l, false, 2);
                    b(false);
                    return;
                }
                return;
            }
            if (i2 != 5) {
                return;
            }
            if (q.l() == null || !q.l().a()) {
                f.c.a().a(this.f13471l, false, 1);
                c(false);
            }
        }

        private h.n.a.b.a.c.a a(h.n.a.a.a.c.d dVar, int i2) {
            h.n.a.b.a.c.a aVar = new h.n.a.b.a.c.a(dVar, l(), m(), i2);
            h.n.a.d.b.n.a a = h.n.a.d.b.n.a.a(i2);
            boolean z = true;
            if (a.a("download_event_opt", 1) > 1) {
                try {
                    String v = this.f13472m.v();
                    if (!TextUtils.isEmpty(v)) {
                        if (q.a().getPackageManager().getPackageInfo(v, 0) == null) {
                            z = false;
                        }
                        aVar.f(z);
                    }
                } catch (Throwable unused) {
                }
            }
            return aVar;
        }

        private void a(com.ss.android.socialbase.downloader.g.c cVar) {
            Message obtain = Message.obtain();
            obtain.what = 3;
            obtain.obj = cVar;
            this.a.sendMessage(obtain);
        }
    }

    public interface n {
        n a(int i2, h.n.a.a.a.c.e eVar);

        n a(h.n.a.a.a.a.s sVar);

        n a(h.n.a.a.a.c.b bVar);

        n a(h.n.a.a.a.c.c cVar);

        n a(h.n.a.a.a.c.d dVar);

        void a();

        void a(long j2, int i2);

        void a(boolean z);

        boolean a(int i2);

        n b(Context context);

        boolean b();

        long d();

        void g();
    }

    public class o implements g.l.a {
        public long a;
        public h.e.b b;

        public boolean f13479c = false;

        public final g.l f13480d = new g.l(Looper.getMainLooper(), this);

        public e f13481e;

        public class C0231a implements h.n.a.a.a.a.q {
            public final h.n.a.a.a.a.q a;

            public C0231a(h.n.a.a.a.a.q qVar) {
                this.a = qVar;
            }

            @Override
            public void a() {
                this.a.a();
            }

            @Override
            public void a(String str) {
                q.d().a(1, q.a(), o.this.b.b, "您已禁止使用存储权限,请授权后再下载", null, 1);
                f.c.a().b(o.this.a, 1);
                this.a.a(str);
            }
        }

        public class c implements e {
            public c() {
            }

            @Override
            public void a(com.ss.android.socialbase.downloader.g.c cVar) {
                f.c.a().a(o.this.a, 2, cVar);
            }
        }

        public static class d extends h.n.a.d.b.e.a {

            public g.l f13482c;

            public d(g.l lVar) {
                this.f13482c = lVar;
            }

            @Override
            public void a(com.ss.android.socialbase.downloader.g.c cVar) {
                a(cVar, 1);
            }

            @Override
            public void b(com.ss.android.socialbase.downloader.g.c cVar) {
                a(cVar, 2);
            }

            @Override
            public void c(com.ss.android.socialbase.downloader.g.c cVar) {
                a(cVar, 4);
            }

            @Override
            public void d(com.ss.android.socialbase.downloader.g.c cVar) {
                a(cVar, -2);
            }

            @Override
            public void e(com.ss.android.socialbase.downloader.g.c cVar) {
                a(cVar, -3);
            }

            @Override
            public void h(com.ss.android.socialbase.downloader.g.c cVar) {
                a(cVar, -4);
            }

            @Override
            public void i(com.ss.android.socialbase.downloader.g.c cVar) {
                a(cVar, 11);
            }

            @Override
            public void a(com.ss.android.socialbase.downloader.g.c cVar, com.ss.android.socialbase.downloader.e.a aVar) {
                a(cVar, -1);
            }

            private void a(com.ss.android.socialbase.downloader.g.c cVar, int i2) {
                Message obtain = Message.obtain();
                obtain.what = 3;
                obtain.obj = cVar;
                obtain.arg1 = i2;
                this.f13482c.sendMessage(obtain);
            }
        }

        public interface e {
            void a(com.ss.android.socialbase.downloader.g.c cVar);
        }

        private boolean c() {
            return d() && e();
        }

        private boolean d() {
            h.n.a.a.a.c.d dVar = this.b.b;
            return (dVar == null || TextUtils.isEmpty(dVar.v()) || TextUtils.isEmpty(this.b.b.a())) ? false : true;
        }

        private boolean e() {
            return this.b.f13448d.d();
        }

        private void f() {
            Message obtain = Message.obtain();
            obtain.what = 1;
            this.f13480d.sendMessageDelayed(obtain, 1200L);
        }

        private boolean g() {
            return g.k.a(this.b.b) && p.a(this.b.f13448d.a());
        }

        public class b implements g.i.a {
            public final h.n.a.a.a.a.q a;

            public b(h.n.a.a.a.a.q qVar) {
                this.a = qVar;
            }

            @Override
            public void a() {
                h.n.a.a.a.a.q qVar = this.a;
                if (qVar != null) {
                    qVar.a();
                }
            }

            @Override
            public void a(String str) {
                h.n.a.a.a.a.q qVar = this.a;
                if (qVar != null) {
                    qVar.a(str);
                }
            }
        }

        private boolean e(com.ss.android.socialbase.downloader.g.c cVar) {
            return f(cVar) && !g.k.a(this.b.b);
        }

        public void a(long j2) {
            this.a = j2;
            h.e.b e2 = h.e.c().e(j2);
            this.b = e2;
            if (e2.a()) {
                g.k.b();
            }
        }

        public boolean b(boolean z) {
            return !z && this.b.f13448d.b() == 1;
        }

        public boolean c(com.ss.android.socialbase.downloader.g.c cVar) {
            return e(cVar) || g();
        }

        private void b(h.n.a.a.a.a.q qVar) {
            if (!g.i.b("android.permission.WRITE_EXTERNAL_STORAGE")) {
                g.i.a(new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"}, new b(qVar));
            } else if (qVar != null) {
                qVar.a();
            }
        }

        private boolean f(com.ss.android.socialbase.downloader.g.c cVar) {
            return cVar != null && cVar.N1() == -3;
        }

        public void d(com.ss.android.socialbase.downloader.g.c cVar) {
            if (this.b.b == null || cVar == null || cVar.D1() == 0) {
                return;
            }
            int N1 = cVar.N1();
            if (N1 != -1 && N1 != -4) {
                if (p.a(this.b.b)) {
                    f.c.a().a(this.a, 2);
                }
            } else {
                f.c.a().a(this.a, 2);
            }
            switch (N1) {
                case -4:
                case -1:
                    b();
                    h.e c2 = h.e.c();
                    h.e.b bVar = this.b;
                    c2.a(new h.n.a.b.a.c.a(bVar.b, bVar.f13447c, bVar.f13448d, cVar.D1()));
                    return;
                case -3:
                    if (g.k.a(this.b.b)) {
                        g.k.b();
                        return;
                    } else {
                        f.c.a().a(this.a, 5, cVar);
                        f();
                        return;
                    }
                case -2:
                    f.c.a().a(this.a, 4, cVar);
                    return;
                case 0:
                case 6:
                default:
                    return;
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 7:
                case 8:
                    f.c.a().a(this.a, 3, cVar);
                    return;
            }
        }

        public void a(com.ss.android.socialbase.downloader.g.c cVar) {
            this.f13479c = false;
            e eVar = this.f13481e;
            if (eVar != null) {
                eVar.a(cVar);
                this.f13481e = null;
            }
        }

        public void b(com.ss.android.socialbase.downloader.g.c cVar) {
            if (!p.a(this.b.b) || this.f13479c) {
                return;
            }
            f.c.a().a("file_status", (cVar == null || !g.k.b(cVar.K1())) ? 2 : 1, this.b);
            this.f13479c = true;
        }

        public boolean a(Context context, int i2, boolean z) {
            if (g.k.a(this.b.b)) {
                h.n.a.b.a.c.a d2 = h.e.c().d(this.b.a);
                if (d2 != null) {
                    h.n.a.d.b.q.b.b().e(d2.J());
                }
                return b.C0234b.a(this.b);
            }
            if (!a(i2) || TextUtils.isEmpty(this.b.b.v()) || q.i().optInt("disable_market") == 1) {
                return false;
            }
            return b.C0234b.a(this.b, i2);
        }

        public void b() {
            if (this.f13481e == null) {
                this.f13481e = new c();
            }
        }

        @NonNull
        public static List<h.n.a.a.a.c.f> b(Map<Integer, Object> map) {
            ArrayList arrayList = new ArrayList();
            if (map != null && !map.isEmpty()) {
                for (Object obj : map.values()) {
                    if (obj instanceof h.n.a.a.a.c.f) {
                        arrayList.add((h.n.a.a.a.c.f) obj);
                    } else if (obj instanceof SoftReference) {
                        SoftReference softReference = (SoftReference) obj;
                        if (softReference.get() instanceof h.n.a.a.a.c.f) {
                            arrayList.add((h.n.a.a.a.c.f) softReference.get());
                        }
                    }
                }
            }
            return arrayList;
        }

        private boolean a(int i2) {
            return (this.b.f13448d.b() == 2 && i2 == 2) || this.b.f13448d.b() == 3;
        }

        public boolean a() {
            return g.k.a(this.b.b) && !p.a(this.b.f13448d.a());
        }

        public int a(boolean z) {
            return (a() && z) ? 1 : 0;
        }

        public void a(@NonNull h.n.a.a.a.a.q qVar) {
            if (!TextUtils.isEmpty(this.b.b.n()) && this.b.b.n().startsWith(Environment.getDataDirectory().getAbsolutePath())) {
                qVar.a();
            } else {
                b(new C0231a(qVar));
            }
        }

        public void a(Message message, h.n.a.a.a.e.d dVar, Map<Integer, Object> map) {
            if (message == null || message.what != 3) {
                return;
            }
            com.ss.android.socialbase.downloader.g.c cVar = (com.ss.android.socialbase.downloader.g.c) message.obj;
            int i2 = message.arg1;
            int i3 = 0;
            if (i2 != 1 && i2 != 6 && i2 == 2) {
                if (cVar.d0()) {
                    h.n.a.c.h a = h.n.a.c.h.a();
                    h.e.b bVar = this.b;
                    a.a(bVar.b, bVar.f13448d, bVar.f13447c);
                    cVar.h(false);
                }
                f.c.a().a(cVar);
            }
            dVar.a(cVar);
            int a2 = h.n.a.d.a.d.a(cVar.N1());
            long L0 = cVar.L0();
            if (L0 > 0) {
                i3 = (int) ((cVar.J0() * 100) / L0);
                e eVar = this.f13481e;
                if (eVar != null) {
                    eVar.a(cVar);
                    this.f13481e = null;
                }
            }
            for (h.n.a.a.a.c.e eVar2 : a(map)) {
                if (a2 != 1) {
                    if (a2 == 2) {
                        eVar2.b(dVar, i3);
                    } else if (a2 == 3) {
                        if (cVar.N1() == -4) {
                            eVar2.a();
                        } else if (cVar.N1() == -1) {
                            eVar2.a(dVar);
                        } else if (cVar.N1() == -3) {
                            if (g.k.a(this.b.b)) {
                                eVar2.b(dVar);
                            } else {
                                eVar2.c(dVar);
                            }
                        }
                    }
                } else if (cVar.N1() != 11) {
                    eVar2.a(dVar, i3);
                } else {
                    Iterator<h.n.a.a.a.c.f> it = b(map).iterator();
                    while (it.hasNext()) {
                        it.next().a(cVar);
                    }
                }
            }
        }

        public int a(Context context, h.n.a.d.b.e.b bVar) {
            if (context == null) {
                return 0;
            }
            Map<String, String> j2 = this.b.b.j();
            ArrayList arrayList = new ArrayList();
            if (j2 != null) {
                for (Map.Entry<String, String> entry : j2.entrySet()) {
                    if (entry != null) {
                        arrayList.add(new com.ss.android.socialbase.downloader.g.e(entry.getKey(), entry.getValue()));
                    }
                }
            }
            String a = g.e.a(String.valueOf(this.b.b.d()), this.b.b.c(), this.b.b.k(), String.valueOf(this.b.b.y()));
            h.n.a.d.b.n.a a2 = g.f.a(this.b.b);
            int E = this.b.b.E();
            if (this.b.b.t() || p.b(this.b.b)) {
                E = 4;
            }
            String a3 = a(a2);
            com.ss.android.socialbase.downloader.g.c h2 = h.n.a.d.b.f.f.a(q.a()).h(h.n.a.d.b.f.b.a(this.b.b.a(), a3));
            if (h2 != null && 3 == this.b.b.y()) {
                h2.h(true);
                h.n.a.d.b.p.d.a(h2);
            }
            i e2 = new i(context, this.b.b.a()).b(this.b.b.b()).a(this.b.b.h()).d(a).a(arrayList).a(this.b.b.l()).c(this.b.b.m()).b(this.b.b.o()).c(a3).i(this.b.b.w()).g(this.b.b.e()).a(this.b.b.f()).a(bVar).l(this.b.b.q() || a2.a("need_independent_process", 0) == 1).a(this.b.b.B()).b(this.b.b.A()).f(this.b.b.v()).c(1000).d(100).a(g.f.b(this.b.b)).i(true).j(true).a(a2.a("retry_count", 5)).b(a2.a("backup_url_retry_count", 0)).j(true).m(a2.a("need_head_connection", 1) == 1).d(a2.a("need_https_to_http_retry", 0) == 1).h(a2.a("need_chunk_downgrade_retry", 1) == 1).g(a2.a("need_retry_delay", 0) == 1).h(a2.d("retry_delay_time_array")).k(a2.a("need_reuse_runnable", 0) == 1).a(k.a(this.b.b.a(), this.b.b.p())).a(k.a(this.b.b.p())).e(E);
            if (!TextUtils.isEmpty(this.b.b.i())) {
                e2.e(this.b.b.i());
            } else {
                e2.e("application/vnd.android.package-archive");
            }
            h.n.a.c.a$i.a aVar = null;
            if (a2.a("clear_space_use_disk_handler", 0) == 1) {
                aVar = new h.n.a.c.a$i.a();
                e2.a(aVar);
            }
            int a4 = p.a(this.b.b, c(), e2);
            if (aVar != null) {
                aVar.a(a4);
            }
            return a4;
        }

        private String a(h.n.a.d.b.n.a aVar) {
            File externalFilesDir;
            if (!TextUtils.isEmpty(this.b.b.n())) {
                return this.b.b.n();
            }
            com.ss.android.socialbase.downloader.g.c a = h.n.a.d.a.e.n().a(q.a(), this.b.b.a());
            boolean b2 = g.i.b("android.permission.WRITE_EXTERNAL_STORAGE");
            if (a != null && !TextUtils.isEmpty(a.H1())) {
                String H1 = a.H1();
                if (b2 || H1.startsWith(Environment.getDataDirectory().getAbsolutePath())) {
                    return H1;
                }
                try {
                    File externalFilesDir2 = q.a().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
                    if (externalFilesDir2 != null) {
                        if (H1.startsWith(externalFilesDir2.getAbsolutePath())) {
                            return H1;
                        }
                    }
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
                h.n.a.d.b.f.f.a(h.n.a.d.b.f.b.g()).b(a.D1());
            }
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.putOpt("ttdownloader_code", Integer.valueOf(b2 ? 1 : 2));
            } catch (JSONException e3) {
                e3.printStackTrace();
            }
            f.c.a().a("label_external_permission", jSONObject, this.b);
            String str = null;
            try {
                str = h.n.a.d.a.d.b();
            } catch (Exception unused) {
            }
            int a2 = g.f.a(aVar);
            if (a2 == 0) {
                return str;
            }
            if (a2 == 4 || (!b2 && a2 == 2)) {
                File filesDir = q.a().getFilesDir();
                if (!filesDir.exists()) {
                    filesDir.mkdirs();
                }
                return filesDir.exists() ? filesDir.getAbsolutePath() : str;
            }
            if ((a2 != 3 && (b2 || a2 != 1)) || (externalFilesDir = q.a().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)) == null) {
                return str;
            }
            if (!externalFilesDir.exists()) {
                externalFilesDir.mkdirs();
            }
            return externalFilesDir.exists() ? externalFilesDir.getAbsolutePath() : str;
        }

        public void a(com.ss.android.socialbase.downloader.g.c cVar, h.n.a.a.a.e.d dVar, List<h.n.a.a.a.c.e> list) {
            int i2;
            if (list.isEmpty()) {
                return;
            }
            if (cVar != null && dVar != null) {
                try {
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
                if (cVar.L0() > 0) {
                    i2 = (int) ((cVar.J0() * 100) / cVar.L0());
                    int i3 = i2 >= 0 ? i2 : 0;
                    dVar.a(cVar);
                    for (h.n.a.a.a.c.e eVar : list) {
                        switch (cVar.N1()) {
                            case -4:
                            case 0:
                                if (g.k.a(this.b.b)) {
                                    dVar.b = -3;
                                    eVar.b(dVar);
                                    break;
                                } else {
                                    eVar.a();
                                    break;
                                }
                            case -3:
                                if (g.k.a(this.b.b)) {
                                    eVar.b(dVar);
                                    break;
                                } else {
                                    eVar.c(dVar);
                                    break;
                                }
                            case -2:
                                eVar.b(dVar, i3);
                                break;
                            case -1:
                                eVar.a(dVar);
                                break;
                            case 1:
                            case 2:
                            case 3:
                            case 4:
                            case 5:
                            case 7:
                            case 8:
                                eVar.a(dVar, i3);
                                break;
                            case 11:
                                if (eVar instanceof h.n.a.a.a.c.f) {
                                    ((h.n.a.a.a.c.f) eVar).a(cVar);
                                    break;
                                } else {
                                    eVar.a(dVar, i3);
                                    break;
                                }
                        }
                    }
                    return;
                }
                i2 = 0;
                if (i2 >= 0) {
                }
                dVar.a(cVar);
                while (r9.hasNext()) {
                }
                return;
            }
            Iterator<h.n.a.a.a.c.e> it = list.iterator();
            while (it.hasNext()) {
                it.next().a();
            }
        }

        @Override
        public void a(Message message) {
            h.n.a.a.a.a.b l2;
            if (message.what == 1 && (l2 = q.l()) != null && l2.a()) {
                f.c.a().a("install_window_show", this.b);
            }
        }

        @NonNull
        public static List<h.n.a.a.a.c.e> a(Map<Integer, Object> map) {
            ArrayList arrayList = new ArrayList();
            if (map != null && !map.isEmpty()) {
                for (Object obj : map.values()) {
                    if (obj instanceof h.n.a.a.a.c.e) {
                        arrayList.add((h.n.a.a.a.c.e) obj);
                    } else if (obj instanceof SoftReference) {
                        SoftReference softReference = (SoftReference) obj;
                        if (softReference.get() instanceof h.n.a.a.a.c.e) {
                            arrayList.add((h.n.a.a.a.c.e) softReference.get());
                        }
                    }
                }
            }
            return arrayList;
        }
    }

    public class p {
        public static boolean a(int i2) {
            return i2 == 0 || i2 == 1;
        }

        public static boolean a(h.n.a.a.a.c.d dVar) {
            return dVar.t() && (dVar instanceof h.n.a.b.a.a.c) && dVar.y() == 1;
        }

        public static boolean b(int i2) {
            return i2 == 2 || i2 == 1;
        }

        public static boolean b(h.n.a.a.a.c.d dVar) {
            return dVar != null && dVar.y() == 2;
        }

        public static int a(@NonNull h.n.a.a.a.c.d dVar, boolean z, i iVar) {
            if (iVar == null || TextUtils.isEmpty(iVar.C()) || iVar.B() == null) {
                return 0;
            }
            int a = h.n.a.d.a.e.n().a(iVar);
            h.n.a.d.b.n.a a2 = h.n.a.d.b.n.a.a(iVar.z());
            if (!a(iVar, a2) && dVar.k()) {
                String d2 = a2.d("download_start_toast_text");
                if (TextUtils.isEmpty(d2)) {
                    d2 = z ? "已开始下载,可在\"我的\"里查看管理" : "已开始下载";
                }
                q.d().a(2, iVar.B(), dVar, d2, null, 0);
            }
            return a;
        }

        public static boolean a(i iVar, @NonNull h.n.a.d.b.n.a aVar) {
            JSONObject jSONObject;
            if (aVar.c("show_unknown_source_on_startup")) {
                JSONArray f2 = aVar.f("anti_plans");
                int length = f2.length();
                int i2 = 0;
                while (true) {
                    if (i2 >= length) {
                        jSONObject = null;
                        break;
                    }
                    jSONObject = f2.optJSONObject(i2);
                    if (jSONObject != null && "jump_unknown_source".equals(jSONObject.optString("type"))) {
                        break;
                    }
                    i2++;
                }
                if (jSONObject != null) {
                    return h.n.a.d.a.c.a(h.n.a.d.b.f.b.g(), (Intent) null, jSONObject, new h.n.a.d.a.b());
                }
            }
            return false;
        }

        public static String a(com.ss.android.socialbase.downloader.g.c cVar) {
            if (cVar == null) {
                return null;
            }
            try {
                String c2 = cVar.c();
                if (!TextUtils.isEmpty(c2)) {
                    return new JSONObject(c2).optString("notification_jump_url", null);
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            return null;
        }
    }

    public class q {
        public static Context a;
        public static h.n.a.a.a.a.f b;

        public static h.n.a.a.a.a.c f13483c;

        public static h.n.a.a.a.a.k f13484d;

        public static h.n.a.a.a.a.g f13485e;

        public static h.n.a.a.a.a.h f13486f;

        public static h.n.a.a.a.a.i f13487g;

        public static h.n.a.a.a.e.a f13488h;

        public static h.n.a.a.a.a.b f13489i;

        public static d.i f13490j;

        public static h.n.a.a.a.a.d f13491k;

        public static h.n.a.a.a.a.e f13492l;

        public static h.n.a.a.a.a.o f13493m;

        public static h.n.a.a.a.a.j f13494n;

        public static h.n.a.a.a.a.r f13495o;

        public static h.n.a.a.a.a.n f13496p;

        public static h.n.a.a.a.a.m f13497q;

        public static h.n.a.a.a.a.l f13498r;

        public static h.n.a.a.a.d.a f13499s;

        public static class C0232a implements h.n.a.a.a.a.c {
            @Override
            public void a(@Nullable Context context, @NonNull h.n.a.a.a.c.d dVar, @Nullable h.n.a.a.a.c.b bVar, @Nullable h.n.a.a.a.c.c cVar) {
            }

            @Override
            public void a(@Nullable Context context, @NonNull h.n.a.a.a.c.d dVar, @Nullable h.n.a.a.a.c.b bVar, @Nullable h.n.a.a.a.c.c cVar, String str) {
            }
        }

        public static class b implements d.i {
            @Override
            public void a(com.ss.android.socialbase.downloader.g.c cVar, com.ss.android.socialbase.downloader.e.a aVar, int i2) {
            }
        }

        public static class c implements h.n.a.a.a.a.i {
            @Override
            public JSONObject a() {
                return new JSONObject();
            }
        }

        public static void a(Context context) {
            if (context != null && context.getApplicationContext() != null) {
                a = context.getApplicationContext();
                return;
            }
            throw new IllegalArgumentException("Context is null");
        }

        public static void b(Context context) {
            if (a != null || context == null || context.getApplicationContext() == null) {
                return;
            }
            a = context.getApplicationContext();
        }

        @NonNull
        public static h.n.a.a.a.a.c c() {
            if (f13483c == null) {
                f13483c = new C0232a();
            }
            return f13483c;
        }

        @NonNull
        public static h.n.a.a.a.a.k d() {
            if (f13484d == null) {
                f13484d = new h.n.a.c.c.a();
            }
            return f13484d;
        }

        public static h.n.a.a.a.a.g e() {
            return f13485e;
        }

        @NonNull
        public static h.n.a.a.a.a.h f() {
            if (f13486f == null) {
                f13486f = new h.n.a.c.c.b();
            }
            return f13486f;
        }

        public static d.i g() {
            if (f13490j == null) {
                f13490j = new b();
            }
            return f13490j;
        }

        public static h.n.a.a.a.a.o h() {
            return f13493m;
        }

        @NonNull
        public static JSONObject i() {
            if (f13487g == null) {
                f13487g = new c();
            }
            return (JSONObject) g.k.a((Object[]) new JSONObject[]{f13487g.a(), new JSONObject()});
        }

        @NonNull
        public static h.n.a.a.a.e.a j() {
            if (f13488h == null) {
                f13488h = new a.C0217a().a();
            }
            return f13488h;
        }

        public static h.n.a.a.a.a.m k() {
            return f13497q;
        }

        @Nullable
        public static h.n.a.a.a.a.b l() {
            return f13489i;
        }

        @Nullable
        public static h.n.a.a.a.a.n m() {
            return f13496p;
        }

        public static h.n.a.a.a.a.l n() {
            return f13498r;
        }

        public static String o() {
            return "1.9.5.1";
        }

        public static h.n.a.a.a.a.d p() {
            return f13491k;
        }

        public static h.n.a.a.a.a.e q() {
            return f13492l;
        }

        @NonNull
        public static h.n.a.a.a.d.a r() {
            if (f13499s == null) {
                f13499s = new d();
            }
            return f13499s;
        }

        public static h.n.a.a.a.a.j s() {
            return f13494n;
        }

        public static h.n.a.a.a.a.r t() {
            return f13495o;
        }

        public static boolean u() {
            return i().optInt("is_enable_start_install_again") == 1 || v();
        }

        public static boolean v() {
            return false;
        }

        public static long w() {
            long optLong = i().optLong("start_install_interval");
            return optLong == 0 ? h.f.c.y.a.f.f12555h : optLong;
        }

        public static long x() {
            long optLong = i().optLong("next_install_min_interval");
            if (optLong == 0) {
                return 10000L;
            }
            return optLong;
        }

        public static String y() {
            try {
                return Environment.getExternalStorageDirectory().getPath() + File.separator + i().optString("default_save_dir_name", "ByteDownload");
            } catch (Throwable unused) {
                return null;
            }
        }

        public static class d implements h.n.a.a.a.d.a {
            public h.n.a.c.i.a.a a = null;

            @Override
            public void a(Activity activity, int i2, String str, Drawable drawable, String str2, long j2, d.n nVar) {
                h.n.a.c.i.a.a aVar = new h.n.a.c.i.a.a(activity, i2, str, drawable, str2, j2, nVar);
                this.a = aVar;
                aVar.show();
            }

            @Override
            public void a() {
                h.n.a.c.i.a.a aVar = this.a;
                if (aVar == null || !aVar.isShowing()) {
                    return;
                }
                this.a.dismiss();
            }
        }

        public static h.n.a.a.a.a.f b() {
            return b;
        }

        public static Context a() {
            Context context = a;
            if (context != null) {
                return context;
            }
            throw new IllegalArgumentException("Context is null");
        }

        public static void a(@NonNull h.n.a.a.a.a.f fVar) {
            b = fVar;
        }

        public static void a(@NonNull h.n.a.a.a.a.k kVar) {
            f13484d = kVar;
        }

        public static void a(@NonNull h.n.a.a.a.a.g gVar) {
            f13485e = gVar;
        }

        public static void a(@NonNull h.n.a.a.a.a.h hVar) {
            f13486f = hVar;
        }

        public static void a(@NonNull h.n.a.a.a.a.i iVar) {
            f13487g = iVar;
            try {
                h.n.a.d.a.e.n().b(y());
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }

        public static void a(@NonNull h.n.a.a.a.e.a aVar) {
            f13488h = aVar;
        }

        public static void a(@NonNull h.n.a.a.a.a.b bVar) {
            f13489i = bVar;
        }

        public static void a(String str) {
            h.n.a.d.a.e.n().a(str);
        }
    }

    public class r implements h.n.a.d.b.f.q {
        @Override
        public void a(com.ss.android.socialbase.downloader.g.c cVar, int i2, int i3) {
            h.n.a.b.a.c.a a = h.e.c().a(cVar);
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.putOpt("reserve_wifi_source", Integer.valueOf(i3));
                jSONObject.putOpt("reserve_wifi_status", Integer.valueOf(i2));
            } catch (JSONException e2) {
                e2.printStackTrace();
            }
            f.c.a().a("pause_reserve_wifi", jSONObject, a);
        }
    }

    public class s {
        public static h.n.a.c.a$f.d a;

        public static class C0233a implements h.n.a.c.a$f.d {
            public final int a;
            public final h.n.a.b.a.c.a b;

            public C0233a(int i2, h.n.a.b.a.c.a aVar) {
                this.a = i2;
                this.b = aVar;
            }

            @Override
            public void a() {
                s.a((h.n.a.c.a$f.d) null);
                com.ss.android.socialbase.downloader.g.c h2 = h.n.a.d.b.f.f.a(q.a()).h(this.a);
                if (h2 != null) {
                    h2.B();
                    h.n.a.d.b.l.r.e().a(h2);
                    f.c.a().a("pause_reserve_wifi_confirm", this.b);
                }
            }

            @Override
            public void b() {
                s.a((h.n.a.c.a$f.d) null);
                com.ss.android.socialbase.downloader.g.c h2 = h.n.a.d.b.f.f.a(q.a()).h(this.a);
                if (h2 != null) {
                    h2.E();
                }
                f.c.a().a("pause_reserve_wifi_cancel", this.b);
            }
        }

        public static h.n.a.c.a$f.d a() {
            return a;
        }

        public static boolean a(int i2) {
            return i2 == 1 || i2 == 2 || i2 == 3 || i2 == 4 || i2 == 5 || i2 == 7 || i2 == 8;
        }

        public static void a(h.n.a.c.a$f.d dVar) {
            a = dVar;
        }

        public static void a(h.n.a.b.a.c.a aVar, com.ss.android.socialbase.downloader.g.c cVar, int i2) {
            if (aVar != null && cVar != null) {
                int D1 = cVar.D1();
                boolean n2 = g.f.n(D1);
                JSONObject jSONObject = new JSONObject();
                try {
                    jSONObject.putOpt("switch_status", Integer.valueOf(n2 ? 1 : 0));
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
                f.c.a().a("pause_reserve_wifi_switch_status", jSONObject, aVar);
                if (n2 && a(i2)) {
                    if (h.n.a.d.b.p.d.a(q.a())) {
                        if (cVar.u()) {
                            cVar.E();
                            f.c.a().a("pause_reserve_wifi_cancel_on_wifi", aVar);
                            return;
                        }
                        return;
                    }
                    if (cVar.v()) {
                        return;
                    }
                    a(new C0233a(D1, aVar));
                    TTDelegateActivity.b(aVar.z());
                    return;
                }
                return;
            }
            g.k.b();
        }
    }

    public a() {
        h.n.a.d.a.c.a(this);
        h.n.a.d.b.b.a.b().a(this);
    }

    @WorkerThread
    public static synchronized void b(com.ss.android.socialbase.downloader.g.c cVar, h.n.a.b.a.c.a aVar) {
        synchronized (a.class) {
            if (cVar != null && aVar != null) {
                if (aVar.B() != 1) {
                    return;
                }
                String c2 = c(cVar, aVar);
                h.e.c().b(cVar.G1(), c2);
                Map<Long, h.n.a.b.a.c.a> a = h.e.c().a(cVar.G1(), c2);
                aVar.f(System.currentTimeMillis());
                aVar.e(2);
                aVar.b(c2);
                a.put(Long.valueOf(aVar.z()), aVar);
                h.C0225h.b().a(a.values());
                b(aVar);
                h.n.a.c.h.a().a(cVar, c2);
                if ("application/vnd.android.package-archive".equals(cVar.S0())) {
                    d().a(aVar);
                    d().a(cVar, aVar);
                    if (aVar.M()) {
                        h.n.a.c.a$f.a.a().a(cVar.D1(), aVar.z(), aVar.A(), c2, cVar.F1(), aVar.E(), cVar.K1());
                    }
                    k.e.a(cVar, aVar.z(), aVar.E(), c2);
                }
                return;
            }
            g.k.b();
        }
    }

    @WorkerThread
    public void c(h.n.a.b.a.c.a aVar) {
        SystemClock.sleep(20000L);
        int i2 = 15;
        while (i2 > 0) {
            if (g.k.b(aVar)) {
                a(aVar.C());
                return;
            }
            i2--;
            if (i2 == 0) {
                return;
            } else {
                SystemClock.sleep(20000L);
            }
        }
    }

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

    @WorkerThread
    public synchronized void a(String str) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        if (!g.k.a()) {
            h.n.a.b.a.c.a a = h.e.c().a(str);
            if (a == null) {
                h.d.a().a(str);
                return;
            }
            m a2 = h.n.a.c.h.a().a(a.P());
            if (a2 != null) {
                a2.e();
            }
            if (a.K.get()) {
                return;
            }
            a(str, a);
            if (!b.C0234b.a(str, a) && a.L() == 4) {
                h.n.a.c.a$f.a.a().a(a.z());
            }
            h.n.a.c.a$f.a.a().b(str);
            com.ss.android.socialbase.downloader.g.c a3 = a(h.n.a.d.b.f.f.a(q.a()).b("application/vnd.android.package-archive"), str);
            if (a3 != null) {
                if (h.n.a.d.b.n.a.a(a3.D1()).b("no_hide_notification") != 1) {
                    h.n.a.d.b.q.b.b().a(a3.D1());
                }
                h.n.a.c.h.a().b(a3, str);
                h.n.a.c.a$i.d.a(a3);
            } else {
                h.n.a.c.h.a().b(null, str);
            }
            return;
        }
        throw new RuntimeException("handleAppInstalled in main thread.");
    }

    public static String c(@NonNull com.ss.android.socialbase.downloader.g.c cVar, @NonNull h.n.a.b.a.c.a aVar) {
        File file = new File(cVar.H1(), cVar.E1());
        String str = null;
        if (file.exists()) {
            try {
                PackageInfo packageArchiveInfo = q.a().getPackageManager().getPackageArchiveInfo(file.getAbsolutePath(), h.n.a.d.a.d.a());
                if (packageArchiveInfo != null) {
                    str = packageArchiveInfo.packageName;
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        if (!TextUtils.isEmpty(str) && !str.equals(cVar.d())) {
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.put("real_package_name", str);
                jSONObject.put("input_package_name", cVar.d());
            } catch (JSONException e3) {
                e3.printStackTrace();
            }
            f.c.a().a("embeded_ad", "package_name_error", jSONObject, aVar);
            return str;
        }
        return cVar.d();
    }

    public class g implements g.l.a {

        public static final String f13424c = "a$g";

        public static g f13425d;
        public g.l a = new g.l(Looper.getMainLooper(), this);
        public long b;

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

        public void a(@NonNull com.ss.android.socialbase.downloader.g.c cVar, long j2, long j3, String str, String str2, String str3, String str4) {
            h.b bVar = new h.b(cVar.D1(), j2, j3, str, str2, str3, str4);
            if (h.n.a.d.b.n.a.a(cVar.D1()).a("back_miui_silent_install", 1) == 0 && ((h.n.a.d.b.p.g.j() || h.n.a.d.b.p.g.k()) && h.n.a.d.b.p.i.a(q.a(), "com.miui.securitycore", "com.miui.enterprise.service.EntInstallService"))) {
                if (cVar.w1().getBoolean("extra_silent_install_succeed", false)) {
                    Message obtainMessage = this.a.obtainMessage(200, bVar);
                    obtainMessage.arg1 = 2;
                    this.a.sendMessageDelayed(obtainMessage, r1.a("check_silent_install_interval", 60000));
                    return;
                }
                h.n.a.b.a.c.a d2 = h.e.c().d(bVar.b);
                JSONObject jSONObject = new JSONObject();
                int i2 = -1;
                try {
                    jSONObject.put("ttdownloader_type", "miui_silent_install");
                    jSONObject.put("ttdownloader_message", "miui_silent_install_failed: has not started service");
                    i2 = 5;
                } catch (Exception unused) {
                }
                q.g().a(null, new com.ss.android.socialbase.downloader.e.a(i2, jSONObject.toString()), i2);
                f.c.a().a("embeded_ad", "anti_hijack_result", jSONObject, d2);
            }
            if (q.u()) {
                long currentTimeMillis = System.currentTimeMillis() - this.b;
                long w = q.w();
                if (currentTimeMillis < q.x()) {
                    long x = q.x() - currentTimeMillis;
                    w += x;
                    this.b = System.currentTimeMillis() + x;
                } else {
                    this.b = System.currentTimeMillis();
                }
                g.l lVar = this.a;
                lVar.sendMessageDelayed(lVar.obtainMessage(200, bVar), w);
            }
        }

        private void a(h.b bVar, int i2) {
            if (q.l() == null) {
                return;
            }
            if ((!q.l().a() || q.v()) && bVar != null) {
                if (2 == i2) {
                    h.n.a.b.a.c.a d2 = h.e.c().d(bVar.b);
                    JSONObject jSONObject = new JSONObject();
                    int i3 = -1;
                    try {
                        jSONObject.put("ttdownloader_type", "miui_silent_install");
                        if (g.k.d(q.a(), bVar.f13427d)) {
                            jSONObject.put("ttdownloader_message", "miui_silent_install_succeed");
                            i3 = 4;
                        } else {
                            jSONObject.put("ttdownloader_message", "miui_silent_install_failed: has started service");
                            i3 = 5;
                        }
                    } catch (Exception unused) {
                    }
                    q.g().a(null, new com.ss.android.socialbase.downloader.e.a(i3, jSONObject.toString()), i3);
                    f.c.a().a("embeded_ad", "anti_hijack_result", jSONObject, d2);
                }
                if (g.k.d(q.a(), bVar.f13427d)) {
                    f.c.a().a("delayinstall_installed", bVar.b);
                    return;
                }
                if (!g.k.a(bVar.f13430g)) {
                    f.c.a().a("delayinstall_file_lost", bVar.b);
                } else if (h.n.a.c.a$f.a.a().a(bVar.f13427d)) {
                    f.c.a().a("delayinstall_conflict_with_back_dialog", bVar.b);
                } else {
                    f.c.a().a("delayinstall_install_start", bVar.b);
                    h.n.a.d.a.e.a(q.a(), (int) bVar.a);
                }
            }
        }

        @Override
        public void a(Message message) {
            if (message.what != 200) {
                return;
            }
            a((h.b) message.obj, message.arg1);
        }
    }

    private int d(h.n.a.b.a.c.a aVar) {
        int T1;
        double a = h.n.a.d.b.n.a.a(aVar.J()).a("download_failed_finally_hours", 48.0d);
        if (a <= 0.0d) {
            return -1;
        }
        if (System.currentTimeMillis() - aVar.D() < a * 60.0d * 60.0d * 1000.0d) {
            return 1;
        }
        if (aVar.L.get()) {
            return 0;
        }
        com.ss.android.socialbase.downloader.g.c h2 = h.n.a.d.b.f.f.a(q.a()).h(aVar.J());
        if (h2 == null || (T1 = h2.T1()) == -3 || T1 == -4) {
            return -1;
        }
        if (!h.n.a.d.b.c.f.b(T1) && aVar.L.compareAndSet(false, true)) {
            try {
                JSONObject jSONObject = new JSONObject();
                a(jSONObject, h2, true);
                jSONObject.putOpt("download_status", Integer.valueOf(T1));
                jSONObject.putOpt("fail_status", Integer.valueOf(aVar.x()));
                jSONObject.putOpt("fail_msg", aVar.y());
                jSONObject.put("download_failed_times", aVar.q());
                if (h2.L0() > 0) {
                    jSONObject.put("download_percent", h2.J0() / h2.L0());
                }
                jSONObject.put("is_update_download", aVar.i() ? 1 : 2);
                f.c.a().a(aVar.N(), "download_failed_finally", jSONObject, aVar);
                h.C0225h.b().a(aVar);
                return 0;
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
        return 1;
    }

    public class j implements g.l.a {

        public static String f13449c = "a$j";

        public static volatile j f13450d;
        public g.l a = new g.l(Looper.getMainLooper(), this);
        public ConcurrentHashMap<Long, Runnable> b;

        public j() {
            this.b = null;
            this.b = new ConcurrentHashMap<>();
        }

        public static j b() {
            if (f13450d == null) {
                synchronized (j.class) {
                    if (f13450d == null) {
                        f13450d = new j();
                    }
                }
            }
            return f13450d;
        }

        @Override
        public void a(Message message) {
            if (message == null) {
                return;
            }
            boolean a = q.l() != null ? q.l().a() : false;
            Object obj = message.obj;
            long longValue = obj instanceof Long ? ((Long) obj).longValue() : 0L;
            int i2 = message.what;
            if (i2 == 4) {
                if (a) {
                    f.c.a().a(longValue, true, 2);
                    return;
                }
                return;
            }
            if (i2 == 5) {
                if (a) {
                    f.c.a().a(longValue, true, 1);
                }
            } else {
                if (i2 != 7) {
                    return;
                }
                Runnable runnable = this.b.get(Long.valueOf(longValue));
                this.b.remove(Long.valueOf(longValue));
                if (a) {
                    f.c.a().a(longValue, 1);
                    f.c.a().a(longValue, true, 1);
                } else {
                    if (runnable != null) {
                        this.a.post(runnable);
                    }
                    f.c.a().a(longValue, false, 1);
                }
            }
        }

        public void a(int i2, h.n.a.a.a.c.d dVar, h.n.a.a.a.c.c cVar) {
            g.j.a(f13449c, "sendQuickAppMsg msgWhat:" + i2, null);
            if (this.a == null) {
                return;
            }
            Message obtain = Message.obtain();
            obtain.what = i2;
            obtain.obj = Long.valueOf(dVar.d());
            this.a.sendMessageDelayed(obtain, a());
        }

        public long a() {
            return q.i().optLong("quick_app_check_internal", 1200L);
        }

        public static boolean a(h.n.a.a.a.c.d dVar) {
            return (dVar == null || dVar.z() == null || TextUtils.isEmpty(dVar.z().a())) ? false : true;
        }

        public static boolean a(com.ss.android.socialbase.downloader.g.c cVar) {
            return cVar == null || cVar.N1() == 0 || cVar.N1() == -4;
        }
    }

    @Override
    public void c() {
        a(6);
    }

    public static void b(h.n.a.b.a.c.a aVar) {
        if (aVar == null) {
            return;
        }
        String e2 = TextUtils.isEmpty(aVar.e()) ? "" : aVar.e();
        com.ss.android.socialbase.downloader.g.c h2 = h.n.a.d.b.f.f.a(q.a()).h(aVar.J());
        aVar.j("");
        h.C0225h.b().a(aVar);
        JSONObject a = a(new JSONObject(), h2, false);
        int i2 = 1;
        try {
            a.putOpt("finish_reason", e2);
            a.putOpt("finish_from_reserve_wifi", Integer.valueOf(h2.t() ? 1 : 0));
        } catch (JSONException e3) {
            e3.printStackTrace();
        }
        h.n.a.b.a.c.a a2 = h.e.c().a(h2);
        g.C0237g.a(a, h2.D1());
        try {
            a.put("download_failed_times", a2.q());
            a.put("can_show_notification", h.n.a.d.a.f.d.a() ? 1 : 2);
            if (h2.g() > 0 && h2.L0() > 0) {
                a.put("file_length_gap", h2.g() - h2.L0());
            }
            a.put("ttmd5_status", h2.W1());
            a.put("has_send_download_failed_finally", a2.L.get() ? 1 : 2);
            if (!a2.i()) {
                i2 = 2;
            }
            a.put("is_update_download", i2);
            g.C0237g.a(a2, a);
        } catch (Throwable th) {
            th.printStackTrace();
        }
        f.c.a().a(a, aVar);
    }

    public void a(com.ss.android.socialbase.downloader.g.c cVar, h.n.a.b.a.c.a aVar, int i2) {
        long max;
        if (cVar == null || aVar == null) {
            return;
        }
        a();
        long currentTimeMillis = System.currentTimeMillis();
        aVar.b(currentTimeMillis);
        aVar.g(g.k.a(Environment.getDataDirectory()));
        if (i2 != 2000) {
            max = 2000;
        } else {
            long a = h.n.a.d.b.n.a.a(cVar.D1()).a("check_install_failed_delay_time", 120000L);
            if (a < 0) {
                return;
            } else {
                max = Math.max(a, 30000L);
            }
        }
        long j2 = max;
        d dVar = new d(aVar.z(), cVar.D1(), currentTimeMillis, i2, null);
        f.e().a(dVar, j2);
        this.b = dVar;
        h.C0225h.b().a(aVar);
    }

    public void a(long j2, int i2) {
        long a = h.n.a.d.b.n.a.a(i2).a("check_install_finish_hijack_delay_time", 900000L);
        if (a < 0) {
            return;
        }
        f.e().a(new RunnableC0221a(j2), Math.max(a, h.f.c.y.a.f.f12555h));
    }

    public void a(long j2) {
        h.d.b a;
        int i2;
        try {
            h.n.a.b.a.c.a d2 = h.e.c().d(j2);
            if (d2 != null && !g.k.b(d2) && !d2.K.get()) {
                Pair<h.d.b, Integer> b2 = h.d.a().b(d2);
                if (b2 != null) {
                    a = (h.d.b) b2.first;
                    i2 = ((Integer) b2.second).intValue();
                } else {
                    a = h.d.a().a(d2);
                    i2 = -1;
                }
                if (a == null) {
                    return;
                }
                h.d.a().b(a.a);
                JSONObject jSONObject = new JSONObject();
                jSONObject.put("installed_app_name", a.f13442d);
                jSONObject.put("installed_pkg_name", a.a);
                if (i2 != -1) {
                    jSONObject.put("error_code", i2);
                    g.C0237g.a(jSONObject, d2.J());
                    h.n.a.c.i.a.c.a();
                    f.c.a().a("install_finish_hijack", jSONObject, d2);
                    return;
                }
                f.c.a().a("install_finish_may_hijack", jSONObject, d2);
            }
        } catch (Throwable th) {
            g.k.a(th);
        }
    }

    @Override
    public void b() {
        a();
        a(5);
    }

    private void b(@NonNull com.ss.android.socialbase.downloader.g.c cVar, h.n.a.d.a.b bVar) {
        h.n.a.b.a.c.a a = h.e.c().a(cVar);
        if (a == null) {
            return;
        }
        JSONObject jSONObject = new JSONObject();
        bVar.a(jSONObject);
        try {
            jSONObject.put("download_id", cVar.D1());
            jSONObject.put("name", cVar.E1());
            jSONObject.put("url", cVar.G1());
        } catch (Throwable th) {
            th.printStackTrace();
        }
        g.C0237g.a(jSONObject, cVar.D1());
        f.c.a().a("embeded_ad", "anti_hijack_result", jSONObject, a);
    }

    public void a(String str, h.n.a.b.a.c.a aVar) {
        if (aVar != null && g.k.b(aVar) && aVar.K.compareAndSet(false, true)) {
            f.c.a().a(aVar.N(), "install_finish", a(aVar, str, aVar.L() != 4 ? 3 : 4), aVar);
            h.C0225h.b().a(aVar);
        }
    }

    public static com.ss.android.socialbase.downloader.g.c a(List<com.ss.android.socialbase.downloader.g.c> list, String str) {
        if (list != null && !list.isEmpty() && !TextUtils.isEmpty(str)) {
            for (com.ss.android.socialbase.downloader.g.c cVar : list) {
                if (cVar != null) {
                    if (str.equals(cVar.d())) {
                        return cVar;
                    }
                    if (g.k.a(q.a(), cVar.K1(), str)) {
                        return cVar;
                    }
                }
            }
        }
        return null;
    }

    public static JSONObject a(JSONObject jSONObject, com.ss.android.socialbase.downloader.g.c cVar, boolean z) {
        if (jSONObject != null && cVar != null) {
            int i2 = 1;
            if (h.n.a.d.b.n.a.a(cVar.D1()).a("download_event_opt", 1) == 0) {
                return jSONObject;
            }
            try {
                jSONObject.put("download_id", cVar.D1());
                jSONObject.put("name", cVar.E1());
                jSONObject.put("url", cVar.G1());
                jSONObject.put("cur_bytes", cVar.J0());
                jSONObject.put("total_bytes", cVar.L0());
                jSONObject.put("network_quality", cVar.N0());
                jSONObject.put("current_network_quality", h.n.a.d.b.k.k.b().a().name());
                jSONObject.put("only_wifi", cVar.U1() ? 1 : 0);
                jSONObject.put("need_https_degrade", cVar.T0() ? 1 : 0);
                jSONObject.put("https_degrade_retry_used", cVar.Q1() ? 1 : 0);
                jSONObject.put("chunk_count", cVar.l1());
                jSONObject.put("retry_count", cVar.j());
                jSONObject.put("cur_retry_time", cVar.W0());
                jSONObject.put("need_retry_delay", cVar.U0() ? 1 : 0);
                jSONObject.put("backup_url_used", cVar.p() ? 1 : 0);
                jSONObject.put("head_connection_error_msg", cVar.z1() != null ? cVar.z1() : "");
                jSONObject.put("need_independent_process", cVar.C0() ? 1 : 0);
                jSONObject.put("total_retry_count", cVar.l());
                jSONObject.put("cur_retry_time_in_total", cVar.m());
                jSONObject.put("real_download_time", cVar.c0());
                jSONObject.put("first_speed_time", cVar.V1());
                jSONObject.put("all_connect_time", cVar.a());
                jSONObject.put("download_prepare_time", cVar.b());
                jSONObject.put("download_time", cVar.c0() + cVar.a() + cVar.b());
                jSONObject.put("chunk_downgrade_retry_used", cVar.U() ? 1 : 0);
                jSONObject.put("need_chunk_downgrade_retry", cVar.T() ? 1 : 0);
                jSONObject.put("failed_resume_count", cVar.p1());
                jSONObject.put("preconnect_level", cVar.v1());
                jSONObject.put("md5", cVar.f());
                jSONObject.put("expect_file_length", cVar.g());
                jSONObject.put("retry_schedule_count", cVar.s());
                jSONObject.put("rw_concurrent", cVar.F() ? 1 : 0);
                double J0 = cVar.J0() / 1048576.0d;
                double c0 = cVar.c0() / 1000.0d;
                if (J0 > 0.0d && c0 > 0.0d) {
                    double d2 = J0 / c0;
                    try {
                        jSONObject.put("download_speed", d2);
                    } catch (Exception unused) {
                    }
                    h.n.a.d.b.h.a.b(f13404c, "download speed : " + d2 + "MB/s");
                }
                try {
                    jSONObject.put("is_download_service_foreground", h.n.a.d.b.f.f.a(q.a()).m(cVar.D1()) ? 1 : 0);
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
                if (cVar.i0() != null) {
                    jSONObject.put("backup_url_count", cVar.i0().size());
                    jSONObject.put("cur_backup_url_index", cVar.P1());
                }
                jSONObject.put("clear_space_restart_times", h.n.a.c.a$i.d.c().b(cVar.G1()));
                jSONObject.put("mime_type", cVar.S0());
                if (!h.n.a.d.b.p.d.b(q.a())) {
                    i2 = 2;
                }
                jSONObject.put("network_available", i2);
                jSONObject.put("status_code", cVar.P0());
                a(jSONObject, cVar);
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
        return jSONObject;
    }

    public static JSONObject a(JSONObject jSONObject, com.ss.android.socialbase.downloader.g.c cVar) {
        if (jSONObject == null || cVar == null || h.n.a.d.b.n.a.a(cVar.D1()).a("download_event_opt", 1) == 0) {
            return jSONObject;
        }
        try {
            long a = g.k.a(Environment.getExternalStorageDirectory());
            double d2 = a;
            jSONObject.put("available_space", d2 / 1048576.0d);
            long L0 = cVar.L0();
            double d3 = L0;
            jSONObject.put("apk_size", d3 / 1048576.0d);
            if (a > 0 && L0 > 0) {
                jSONObject.put("available_space_ratio", d2 / d3);
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
        return jSONObject;
    }

    public void a(com.ss.android.socialbase.downloader.g.c cVar, h.n.a.b.a.c.a aVar) {
        if (cVar == null || aVar == null || h.n.a.d.b.n.a.a(cVar.D1()).a("install_finish_check_ttmd5", 1) == 0) {
            return;
        }
        String K1 = cVar.K1();
        if (TextUtils.isEmpty(K1)) {
            return;
        }
        f.e().b(new b(K1, aVar));
    }

    private int a(h.n.a.b.a.c.a aVar, com.ss.android.socialbase.downloader.g.c cVar, String str, JSONObject jSONObject) {
        int b2 = h.n.a.d.a.d.b(q.a(), cVar);
        int b3 = g.k.b(q.a(), str);
        if (b2 > 0 && b3 > 0 && b2 != b3) {
            return b3 > b2 ? 3011 : 3010;
        }
        if (h.n.a.d.b.n.a.a(aVar.J()).a("install_finish_check_ttmd5", 1) != 1) {
            return 3001;
        }
        String string = q.a().getSharedPreferences("sp_ttdownloader_md5", 0).getString(String.valueOf(aVar.z()), null);
        if (TextUtils.isEmpty(string) && cVar != null) {
            string = g.c.a(cVar.K1());
        }
        int a = g.c.a(string, g.c.b(str));
        try {
            jSONObject.put("ttmd5_status", a);
        } catch (Throwable unused) {
        }
        if (a == 0) {
            return 3000;
        }
        return a == 1 ? 3002 : 3001;
    }

    public synchronized void a() {
        d dVar = this.b;
        if (dVar != null) {
            dVar.b();
            this.b = null;
        }
    }

    @Override
    public void a(int i2) {
        long currentTimeMillis = System.currentTimeMillis();
        if (currentTimeMillis - this.a < 120000) {
            return;
        }
        f.e().a(new c(i2), this.a > 0 ? 2000L : 8000L);
        this.a = currentTimeMillis;
    }

    @WorkerThread
    public void a(@NonNull ConcurrentHashMap<Long, h.n.a.b.a.c.a> concurrentHashMap, int i2) {
        ArrayList arrayList = new ArrayList();
        long currentTimeMillis = System.currentTimeMillis();
        for (h.n.a.b.a.c.a aVar : concurrentHashMap.values()) {
            if (aVar.K.get()) {
                if (currentTimeMillis - aVar.D() >= h.n.a.d.b.n.a.a(aVar.J()).a("start_event_expire_hours", TbsListener.ErrorCode.STARTDOWNLOAD_9) * 60 * 60 * 1000) {
                    arrayList.add(Long.valueOf(aVar.z()));
                }
            } else if (aVar.B() == 1) {
                if (d(aVar) <= 0 && currentTimeMillis - aVar.D() >= h.n.a.d.b.n.a.a(aVar.J()).a("start_event_expire_hours", TbsListener.ErrorCode.STARTDOWNLOAD_9) * 60 * 60 * 1000) {
                    arrayList.add(Long.valueOf(aVar.z()));
                }
            } else if (aVar.B() == 2) {
                if (!aVar.l()) {
                    if (g.k.b(aVar)) {
                        if (aVar.L() == 4) {
                            i2 = aVar.L();
                        }
                        f.c.a().b(a(aVar, aVar.C(), i2), aVar);
                        arrayList.add(Long.valueOf(aVar.z()));
                        h.n.a.c.a$i.d.a(aVar);
                    } else if (currentTimeMillis - aVar.D() >= h.n.a.d.b.n.a.a(aVar.J()).a("finish_event_expire_hours", TbsListener.ErrorCode.STARTDOWNLOAD_9) * 60 * 60 * 1000) {
                        arrayList.add(Long.valueOf(aVar.z()));
                    } else if (TextUtils.isEmpty(aVar.C())) {
                        arrayList.add(Long.valueOf(aVar.z()));
                    }
                }
            } else {
                arrayList.add(Long.valueOf(aVar.z()));
            }
        }
        h.e.c().a(arrayList);
    }

    @Override
    public void a(com.ss.android.socialbase.downloader.g.c cVar, h.n.a.d.a.b bVar) {
        if (cVar == null || bVar == null || h.n.a.d.b.n.a.a(cVar.D1()).e("anti_hijack_report_config") == null) {
            return;
        }
        b(cVar, bVar);
    }

    public void a(h.n.a.b.a.c.a aVar) {
        f.e().a(new e(aVar));
    }

    private JSONObject a(h.n.a.b.a.c.a aVar, String str, int i2) {
        h.n.a.d.a.b a;
        JSONObject jSONObject = new JSONObject();
        try {
            com.ss.android.socialbase.downloader.g.c h2 = h.n.a.d.b.f.f.a(q.a()).h(aVar.J());
            jSONObject.putOpt("scene", Integer.valueOf(i2));
            g.C0237g.a(jSONObject, aVar.J());
            g.C0237g.a(aVar, jSONObject);
            jSONObject.put("is_update_download", aVar.i() ? 1 : 2);
            if (h2 != null) {
                try {
                    jSONObject.put("uninstall_resume_count", h2.r1());
                    if (aVar.v() > 0) {
                        jSONObject.put("install_time", System.currentTimeMillis() - aVar.v());
                    }
                } catch (Throwable unused) {
                }
                String string = h2.w1().getString("anti_hijack_attempt");
                if (!TextUtils.isEmpty(string) && (a = h.n.a.d.a.b.a(string)) != null) {
                    a.a(jSONObject);
                }
            }
            int a2 = a(aVar, h2, str, jSONObject);
            jSONObject.put("fail_status", a2);
            if (a2 == 3000) {
                jSONObject.put("hijack", 2);
            } else if (a2 == 3001) {
                jSONObject.put("hijack", 0);
            } else {
                jSONObject.put("hijack", 1);
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
        return jSONObject;
    }

    public void a(com.ss.android.socialbase.downloader.g.c cVar, long j2, long j3, long j4, long j5, long j6, boolean z) {
        h.n.a.b.a.c.a a = h.e.c().a(cVar);
        if (a == null) {
            g.k.b();
            return;
        }
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.putOpt("space_before", Double.valueOf(j2 / 1048576.0d));
            jSONObject.putOpt("space_cleaned", Double.valueOf((j3 - j2) / 1048576.0d));
            jSONObject.putOpt("clean_up_time_cost", Long.valueOf(j5));
            jSONObject.putOpt("is_download_restarted", Integer.valueOf(z ? 1 : 0));
            jSONObject.putOpt("byte_required", Long.valueOf(j4));
            jSONObject.putOpt("clear_sleep_time", Long.valueOf(j6));
            f.c.a().a(cVar, jSONObject);
            f.c.a().a("embeded_ad", "cleanup", jSONObject, a);
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }
}