APKPure.apk(点击下载) / a.java


package e.w.c.e.e;

import android.content.ContentValues;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.os.Handler;
import android.os.SystemClock;
import android.text.TextUtils;
import androidx.recyclerview.widget.RecyclerView;
import androidx.work.WorkRequest;
import com.android.volley.toolbox.ImageRequest;
import com.google.android.gms.analytics.ecommerce.ProductAction;
import com.tencent.beacon.base.net.adapter.AbstractNetAdapter;
import com.tencent.raft.measure.report.ATTAReporter;
import e.w.c.e.b.k;
import e.w.c.e.e.b;
import e.w.c.e.e.e;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.Deflater;

public abstract class a {

    /* renamed from: r  reason: collision with root package name */
    public static int f11827r = 20;

    /* renamed from: a  reason: collision with root package name */
    public final String f11828a = "halley-cloud-HalleyAction";
    public AtomicInteger b = new AtomicInteger(0);
    public Handler c;
    public b d;

    /* renamed from: e  reason: collision with root package name */
    public AtomicInteger f11829e = new AtomicInteger(0);

    /* renamed from: f  reason: collision with root package name */
    public List<String> f11830f = new ArrayList();

    /* renamed from: g  reason: collision with root package name */
    public volatile boolean f11831g = false;

    /* renamed from: h  reason: collision with root package name */
    public volatile boolean f11832h = false;

    /* renamed from: i  reason: collision with root package name */
    public AtomicInteger f11833i = new AtomicInteger(0);

    /* renamed from: j  reason: collision with root package name */
    public int f11834j;

    /* renamed from: k  reason: collision with root package name */
    public int f11835k = 0;

    /* renamed from: l  reason: collision with root package name */
    public long f11836l = 0;

    /* renamed from: m  reason: collision with root package name */
    public AtomicInteger f11837m = new AtomicInteger(0);

    /* renamed from: n  reason: collision with root package name */
    public volatile boolean f11838n = false;

    /* renamed from: o  reason: collision with root package name */
    public final Runnable f11839o = new RunnableC0291a();

    /* renamed from: p  reason: collision with root package name */
    public final Runnable f11840p = new b();

    /* renamed from: q  reason: collision with root package name */
    public b.a f11841q = new c();

    /* renamed from: e.w.c.e.e.a$a  reason: collision with other inner class name */
    public class RunnableC0291a implements Runnable {
        public RunnableC0291a() {
        }

        public final void run() {
            if (a.this.f11830f.size() == 0) {
                a.this.f11837m.incrementAndGet();
                a aVar = a.this;
                String str = aVar.f11828a;
                aVar.f11837m.get();
                a.this.b(false, true);
                return;
            }
            a aVar2 = a.this;
            String str2 = aVar2.f11828a;
            a.a(aVar2, true, true);
        }
    }

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

        public final void run() {
            a aVar = a.this;
            String str = aVar.f11828a;
            a.a(aVar, false, true);
        }
    }

    public class c implements b.a {
        public c() {
        }
    }

    public abstract class d implements Runnable {
        public d(byte b2) {
        }

        public final void a(boolean z) {
            if (!z) {
                a.this.c.post(this);
            } else if (!a.this.c.postAtFrontOfQueue(this)) {
                a.this.c.post(this);
            }
        }
    }

    public final class e extends d {
        public String c;
        public boolean d;

        public e(String str, boolean z) {
            super((byte) 0);
            this.c = str;
            this.d = z;
        }

        public final void run() {
            a.this.f11833i.decrementAndGet();
            if (!TextUtils.isEmpty(this.c)) {
                Objects.requireNonNull(a.this);
                int c2 = e.v.a.c("report_new_record_num", 1, 50, 10);
                if (!this.d) {
                    String str = a.this.f11828a;
                    if (e.b("beacon").c(this.c) != -1) {
                        if (a.this.f11838n) {
                            a aVar = a.this;
                            String str2 = aVar.f11828a;
                            aVar.f11838n = false;
                            a.this.b(false, false);
                        }
                        int incrementAndGet = a.this.f11829e.incrementAndGet();
                        a aVar2 = a.this;
                        String str3 = aVar2.f11828a;
                        if (incrementAndGet >= c2) {
                            a.a(aVar2, this.d, true);
                            return;
                        }
                        return;
                    }
                    String str4 = a.this.f11828a;
                    return;
                }
                a.this.f11830f.add(this.c);
                if (a.this.f11830f.size() >= c2) {
                    a aVar3 = a.this;
                    String str5 = aVar3.f11828a;
                    aVar3.f11837m.set(1);
                    a.a(a.this, this.d, true);
                } else if (a.this.f11837m.get() == 0) {
                    a aVar4 = a.this;
                    String str6 = aVar4.f11828a;
                    aVar4.f11837m.set(1);
                    a.this.b(false, true);
                }
            }
        }
    }

    public final class f extends d {
        public g c;

        public f(g gVar) {
            super((byte) 0);
            this.c = gVar;
        }

        public final void run() {
            a.this.f11831g = false;
            Objects.requireNonNull(a.this);
            a.this.f11836l = SystemClock.elapsedRealtime();
            g gVar = this.c;
            if (gVar.f11845f) {
                a aVar = a.this;
                int i2 = aVar.f11835k;
                if (i2 > 0) {
                    aVar.f11835k = i2 - 10;
                }
                aVar.b.addAndGet(gVar.f11847h);
                g gVar2 = this.c;
                if (!gVar2.d) {
                    int size = gVar2.f11846g.size();
                    ArrayList arrayList = new ArrayList();
                    for (int i3 = 0; i3 < size; i3++) {
                        arrayList.add(Long.valueOf(this.c.f11846g.get(i3).f11852a));
                    }
                    Objects.requireNonNull(a.this);
                    e b = e.b("beacon");
                    Objects.requireNonNull(b);
                    if (arrayList.size() > 0) {
                        try {
                            SQLiteDatabase writableDatabase = b.getWritableDatabase();
                            ContentValues contentValues = new ContentValues();
                            contentValues.put("state", ProductAction.ACTION_REMOVE);
                            e.e("deleteRecords update start");
                            Iterator it = arrayList.iterator();
                            while (it.hasNext()) {
                                writableDatabase.update("halley_action_tbl", contentValues, "key=?", new String[]{String.valueOf(((Long) it.next()).longValue())});
                            }
                            e.e("deleteRecords update end");
                            Iterator it2 = arrayList.iterator();
                            while (it2.hasNext()) {
                                writableDatabase.delete("halley_action_tbl", "key=?", new String[]{String.valueOf(((Long) it2.next()).longValue())});
                            }
                            e.e("deleteRecords delete end");
                            int a2 = b.a(false, true);
                            if (a2 > 0) {
                                "remove fail, removeNum:".concat(String.valueOf(a2));
                                if (b.a(true, false) <= 0) {
                                    try {
                                        writableDatabase.execSQL("DROP TABLE IF EXISTS halley_action_tbl");
                                    } catch (SQLException unused) {
                                    }
                                    e.d(writableDatabase);
                                }
                            }
                        } catch (Exception unused2) {
                        }
                    }
                    if (a.this.f11832h) {
                        a.this.f11832h = false;
                        a aVar2 = a.this;
                        String str = aVar2.f11828a;
                        a.a(aVar2, true, this.c.f11844e);
                        return;
                    }
                }
                if (!this.c.c) {
                    SystemClock.sleep(200);
                    a aVar3 = a.this;
                    String str2 = aVar3.f11828a;
                    g gVar3 = this.c;
                    a.a(aVar3, gVar3.d, gVar3.f11844e);
                    return;
                }
                a.this.f11838n = true;
                return;
            }
            if (e.w.c.e.b.e.d) {
                a aVar4 = a.this;
                if (aVar4.f11835k > 0) {
                    int c2 = e.v.a.c("report_interval_forbid_limit", 30, 1440, 60);
                    a aVar5 = a.this;
                    int i4 = aVar5.f11835k;
                    if (i4 < c2) {
                        aVar5.f11835k = i4 * 2;
                    }
                } else {
                    aVar4.f11835k = 5;
                }
            }
            g gVar4 = this.c;
            if (gVar4.f11844e && gVar4.d) {
                int size2 = gVar4.f11846g.size();
                String str3 = a.this.f11828a;
                "CacheData has been transferred to dbData..Size:".concat(String.valueOf(size2));
                for (int i5 = 0; i5 < size2; i5++) {
                    Objects.requireNonNull(a.this);
                    e.b("beacon").c(this.c.f11846g.get(i5).b);
                }
            }
        }
    }

    public final class g extends d {
        public boolean c;
        public boolean d;

        /* renamed from: e  reason: collision with root package name */
        public boolean f11844e;

        /* renamed from: f  reason: collision with root package name */
        public boolean f11845f = false;

        /* renamed from: g  reason: collision with root package name */
        public List<e.a> f11846g;

        /* renamed from: h  reason: collision with root package name */
        public int f11847h;

        public g(boolean z, boolean z2) {
            super((byte) 0);
            this.d = z;
            this.f11844e = z2;
        }

        /* JADX WARNING: Code restructure failed: missing block: B:47:0x012a, code lost:
            if (r3 != null) goto L_0x0133;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:51:0x0131, code lost:
            if (0 == 0) goto L_0x0136;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:52:0x0133, code lost:
            r3.close();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:53:0x0136, code lost:
            r5.size();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:54:0x013f, code lost:
            if (r5.size() > e.w.c.e.e.a.f11827r) goto L_0x0148;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:55:0x0141, code lost:
            r14.c = true;
            r14.f11848i.f11838n = true;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:56:0x0148, code lost:
            r5.remove(r5.size() - 1);
         */
        /* JADX WARNING: Code restructure failed: missing block: B:57:0x0150, code lost:
            r3 = r5;
         */
        /* JADX WARNING: Removed duplicated region for block: B:35:0x00b1  */
        /* JADX WARNING: Removed duplicated region for block: B:36:0x00c0  */
        public final void run() {
            boolean z;
            this.c = false;
            a.f11827r = e.v.a.c("report_max_report_count", 10, 100, 20);
            Cursor cursor = null;
            r3 = null;
            ArrayList arrayList = null;
            if (this.d) {
                int size = a.this.f11830f.size();
                if (size != 0) {
                    ArrayList arrayList2 = new ArrayList();
                    ArrayList arrayList3 = new ArrayList();
                    int i2 = 0;
                    int i3 = 0;
                    while (i2 < size && i3 < a.f11827r) {
                        String str = a.this.f11830f.get(i2);
                        arrayList3.add(new e.a(0, str));
                        arrayList2.add(str);
                        i2++;
                        i3++;
                    }
                    for (int i4 = 0; i4 < arrayList2.size(); i4++) {
                        a.this.f11830f.remove(arrayList2.get(i4));
                    }
                    if (a.this.f11830f.size() == 0) {
                        this.c = true;
                    }
                    arrayList = arrayList3;
                }
            } else {
                int c2 = e.v.a.c("report_clear_db_num", 1, AbstractNetAdapter.READ_TIMEOUT, ImageRequest.DEFAULT_IMAGE_TIMEOUT_MS);
                Objects.requireNonNull(a.this);
                e b = e.b("beacon");
                if (b.a(true, true) > c2) {
                    try {
                        b.getWritableDatabase().delete("halley_action_tbl", null, null);
                        z = true;
                    } catch (Exception unused) {
                        if (b.a(true, true) > c2) {
                            SQLiteDatabase writableDatabase = b.getWritableDatabase();
                            try {
                                writableDatabase.execSQL("DROP TABLE IF EXISTS halley_action_tbl");
                            } catch (SQLException unused2) {
                            }
                            e.d(writableDatabase);
                        }
                    } catch (Throwable unused3) {
                    }
                    if (!z) {
                        String str2 = a.this.f11828a;
                        "!!!clearOverCount max:".concat(String.valueOf(c2));
                    } else {
                        Objects.requireNonNull(a.this);
                        e b2 = e.b("beacon");
                        int i5 = a.f11827r + 1;
                        Objects.requireNonNull(b2);
                        ArrayList arrayList4 = new ArrayList();
                        try {
                            cursor = b2.getWritableDatabase().query("halley_action_tbl", null, "state=?", new String[]{ProductAction.ACTION_ADD}, null, null, null);
                            if (cursor != null) {
                                int min = Math.min(cursor.getCount(), i5);
                                if (cursor.moveToFirst()) {
                                    int i6 = 0;
                                    do {
                                        arrayList4.add(new e.a(cursor.getLong(cursor.getColumnIndex("key")), cursor.getString(cursor.getColumnIndex("data")), cursor.getString(cursor.getColumnIndex("state"))));
                                        i6++;
                                        if (i6 >= min) {
                                            break;
                                        }
                                    } while (cursor.moveToNext());
                                }
                            }
                        } catch (Throwable th) {
                            if (0 != 0) {
                                cursor.close();
                            }
                            arrayList4.size();
                            throw th;
                        }
                    }
                }
                z = false;
                if (!z) {
                }
            }
            this.f11846g = arrayList;
            if (arrayList == null || arrayList.size() == 0) {
                a.this.f11831g = false;
                return;
            }
            StringBuilder sb = new StringBuilder();
            for (int i7 = 0; i7 < this.f11846g.size(); i7++) {
                sb.append(this.f11846g.get(i7).b);
                sb.append("\n");
            }
            String sb2 = sb.toString();
            String str3 = a.this.f11828a;
            "reportData:".concat(String.valueOf(sb2));
            if (this.d && sb2.contains("client_report_time")) {
                sb2 = sb2.replace("client_report_time", e.w.c.e.h.d.d(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
            }
            byte[] bytes = sb2.getBytes();
            int length = bytes.length;
            this.f11847h = length;
            if (bytes.length != 0) {
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                Deflater deflater = new Deflater();
                deflater.setInput(bytes);
                deflater.finish();
                byte[] bArr = new byte[RecyclerView.a0.FLAG_TMP_DETACHED];
                while (!deflater.finished()) {
                    byteArrayOutputStream.write(bArr, 0, deflater.deflate(bArr));
                }
                deflater.finish();
                deflater.end();
                bytes = byteArrayOutputStream.toByteArray();
            }
            a aVar = a.this;
            b bVar = aVar.d;
            boolean z2 = this.d;
            b.a aVar2 = aVar.f11841q;
            i iVar = (i) bVar;
            Objects.requireNonNull(iVar);
            long elapsedRealtime = SystemClock.elapsedRealtime();
            iVar.b = aVar2;
            iVar.f11849a = this;
            HashMap hashMap = new HashMap();
            hashMap.put("B-Length", String.valueOf(length));
            hashMap.put("HLReportCmd", z2 ? "realtime_speed" : "hllog");
            e.w.c.e.d.a.c a2 = e.w.c.e.d.a.c.a("https://up-hl.3g.qq.com/upreport", hashMap, bytes, 20000, e.w.c.e.h.d.k(), null);
            a2.f11799m = false;
            a2.f11805s = "event";
            try {
                e.w.c.e.b.f.a().f11754a.execute(new h(iVar, a2, elapsedRealtime));
            } catch (Throwable unused4) {
                iVar.a(false);
            }
            String str4 = a.this.f11828a;
            this.f11846g.size();
            int length2 = bytes.length;
        }
    }

    public final class h implements Runnable {
        public final /* synthetic */ e.w.c.e.d.a.c b;
        public final /* synthetic */ long c;
        public final /* synthetic */ i d;

        public h(i iVar, e.w.c.e.d.a.c cVar, long j2) {
            this.d = iVar;
            this.b = cVar;
            this.c = j2;
        }

        public final void run() {
            boolean z = false;
            try {
                e.w.c.e.d.a.f c2 = this.b.c();
                this.b.f11792j = SystemClock.elapsedRealtime() - this.c;
                this.b.b(z);
                if (c2.f11809a == 0 && c2.c == 200) {
                    z = true;
                }
            } catch (Throwable th) {
                th.printStackTrace();
            } finally {
                this.d.a(z);
            }
        }
    }

    public final class i extends b {
        public final boolean a(boolean z) {
            b.a aVar = this.b;
            Object obj = this.f11849a;
            c cVar = (c) aVar;
            Objects.requireNonNull(cVar);
            g gVar = (g) obj;
            gVar.f11845f = z;
            String str = a.this.f11828a;
            "reportUploadFinishCallback..ret:".concat(String.valueOf(z));
            new f(gVar).a(true);
            return z;
        }
    }

    public a() {
        String str;
        String str2;
        String str3;
        char[] charArray;
        Context context = e.w.c.e.c.f11776g;
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("null");
        stringBuffer.append(";Android ");
        try {
            str = Build.VERSION.RELEASE;
        } catch (Throwable th) {
            th.printStackTrace();
            str = "null";
        }
        stringBuffer.append(str);
        stringBuffer.append(",level ");
        try {
            str2 = Build.VERSION.SDK;
        } catch (Throwable th2) {
            th2.printStackTrace();
            str2 = "null";
        }
        stringBuffer.append(str2);
        c.f11850a = stringBuffer.toString();
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            String str4 = packageInfo.versionName;
            int i2 = packageInfo.versionCode;
            if (str4 != null) {
                if (str4.trim().length() > 0) {
                    str3 = str4.trim().replace('\n', ' ').replace('\r', ' ').replace("|", "%7C");
                    int i3 = 0;
                    for (char c2 : str3.toCharArray()) {
                        if (c2 == '.') {
                            i3++;
                        }
                    }
                    if (i3 < 3) {
                        str3 = str3 + "." + i2;
                    }
                    c.b = str3;
                    context.getPackageName();
                    c.c = "null";
                    c.d = "null";
                    this.c = e.v.a.e("ReportAction");
                    this.d = new i();
                    b(true, false);
                    this.f11834j = e.v.a.c("report_insert_new_record_num_limit", 5, 100, 100);
                }
            }
            str3 = String.valueOf(i2);
        } catch (Throwable unused) {
            str3 = "";
        }
        c.b = str3;
        context.getPackageName();
        c.c = "null";
        c.d = "null";
        this.c = e.v.a.e("ReportAction");
        this.d = new i();
        b(true, false);
        this.f11834j = e.v.a.c("report_insert_new_record_num_limit", 5, 100, 100);
    }

    public static void a(a aVar, boolean z, boolean z2) {
        synchronized (aVar) {
            if (!z || !z2) {
                aVar.b(false, false);
            } else {
                aVar.b(false, true);
            }
            if (!aVar.f11831g) {
                if (!z) {
                    aVar.f11829e.set(0);
                }
                if (aVar.f11836l == 0 || SystemClock.elapsedRealtime() - aVar.f11836l >= ((long) (aVar.f11835k * 60 * ImageRequest.DEFAULT_IMAGE_TIMEOUT_MS))) {
                    aVar.f11831g = true;
                    try {
                        new g(z, z2).a(true);
                    } catch (Throwable unused) {
                        aVar.f11831g = false;
                    }
                } else {
                    aVar.f11830f.clear();
                }
            } else if (z) {
                aVar.f11832h = true;
            }
        }
    }

    public final void b(boolean z, boolean z2) {
        if (z2) {
            if (this.f11837m.get() > 3) {
                this.f11837m.set(0);
            } else {
                k.a().b(this.f11839o, (long) (e.v.a.c("report_real_timer_interval", 1, 60, 5) * ImageRequest.DEFAULT_IMAGE_TIMEOUT_MS));
            }
        } else if (z) {
            k.a().b(this.f11840p, WorkRequest.MIN_BACKOFF_MILLIS);
        } else if (!this.f11838n) {
            k.a().b(this.f11840p, (long) e.v.a.c("report_timer_interval", AbstractNetAdapter.CONNECT_TIMEOUT, 600000, ATTAReporter.TIMEOUT));
        }
    }
}