QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685

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


package com.tencent.mtt.browser.push.service;

import MTT.AndroidDeviceToken;
import MTT.Command;
import MTT.DoNotifyReportReq;
import MTT.DoNotifyReportRsp;
import MTT.FeedBackData;
import MTT.MsgFeedBackInfo;
import MTT.NotifyReportInfo;
import MTT.PushAckReq;
import MTT.PushData;
import MTT.PushReq;
import MTT.SocketReportReq;
import MTT.TipsMsg;
import MTT.UserInfoReportReq;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.os.SystemClock;
import android.text.TextUtils;
import androidx.core.app.NotificationCompat;
import com.huawei.hms.framework.common.ContainerUtils;
import com.taf.JceStruct;
import com.taf.JceUtil;
import com.tencent.common.category.db.DBHelper;
import com.tencent.common.http.Apn;
import com.tencent.common.http.MttInputStream;
import com.tencent.common.http.MttRequestBase;
import com.tencent.common.http.MttResponse;
import com.tencent.common.manifest.EventEmiter;
import com.tencent.common.manifest.EventMessage;
import com.tencent.common.threadpool.BrowserExecutorSupplier;
import com.tencent.common.utils.ByteUtils;
import com.tencent.common.utils.FileUtils;
import com.tencent.common.utils.StringUtils;
import com.tencent.common.utils.TEACoding;
import com.tencent.common.wup.IWUPRequestCallBack;
import com.tencent.common.wup.WUPRequestBase;
import com.tencent.common.wup.WUPResponseBase;
import com.tencent.common.wup.WUPTaskProxy;
import com.tencent.connect.common.Constants;
import com.tencent.imsdk.BaseConstants;
import com.tencent.map.geolocation.util.DateUtils;
import com.tencent.mtt.ContextHolder;
import com.tencent.mtt.base.account.facade.IUserServiceExtension;
import com.tencent.mtt.base.network.ConnectionConfiguration;
import com.tencent.mtt.base.network.ConnectionListener;
import com.tencent.mtt.base.network.Packet;
import com.tencent.mtt.base.network.PacketWriteObserver;
import com.tencent.mtt.base.network.StreamConnection;
import com.tencent.mtt.base.stat.StatManager;
import com.tencent.mtt.base.stat.utils.PlatformStatUtils;
import com.tencent.mtt.base.task.NetworkTask;
import com.tencent.mtt.base.utils.Base64Utils;
import com.tencent.mtt.base.utils.DeviceUtilsF;
import com.tencent.mtt.base.wup.GUIDManager;
import com.tencent.mtt.base.wup.WUPRequest;
import com.tencent.mtt.browser.engine.AppBroadcastObserver;
import com.tencent.mtt.browser.engine.AppBroadcastReceiver;
import com.tencent.mtt.browser.facade.TWPushInfo;
import com.tencent.mtt.browser.homepage.appdata.facade.IAppCenterManager;
import com.tencent.mtt.browser.push.QBAutoStartHelper;
import com.tencent.mtt.browser.push.RawPushData;
import com.tencent.mtt.browser.push.external.account.JobschedulService;
import com.tencent.mtt.browser.push.external.account.SyncService;
import com.tencent.mtt.browser.push.pushchannel.PushPermissionUtils;
import com.tencent.mtt.browser.push.pushchannel.PushSdkChannelManager;
import com.tencent.mtt.browser.push.service.IPushRemoteService;
import com.tencent.mtt.browser.push.service.PushRemoteService;
import com.tencent.mtt.browser.push.ui.NewServiceManager;
import com.tencent.mtt.browser.push.ui.PushFunnelStatUtils;
import com.tencent.mtt.browser.push.utils.PushSettingsUtil;
import com.tencent.mtt.multiproc.QBSharedPreferences;
import com.tencent.mtt.operation.event.EventLog;
import com.tencent.mtt.twsdk.qbinfo.QIMEIUtils;
import com.tencent.mtt.twsdk.qbinfo.QUAUtils;
import com.tencent.mtt.twsdk.qbinfo.TWSettingManager;
import com.tencent.rmp.operation.stat.OperationStat;
import java.io.Closeable;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import tmsdk.common.gourd.vine.IMessageCenter;

public class PushEngine implements Handler.Callback, AppBroadcastObserver, ServiceProcessListener {
    protected PushRespProcessor g;
    IPushMessageListener h;
    PushServerConfigs k;
    private int s;
    private byte t;
    private PushPacketWriteObserver u;
    private boolean v;
    private boolean w;
    private long x;
    private long y;

    static final byte[] f44040a = {60, 64, 51, MttRequestBase.REQUEST_APK_DETECT, 84, MttRequestBase.REQUEST_WUP, 53, 48, IAppCenterManager.TYPE_REQUEST_FASTLINK_CANSHOW, MttRequestBase.REQUEST_URL_CONNECTION, 126, 123, 57, 50, IAppCenterManager.TYPE_ONLY_REPORT_USER_ACTION, MttRequestBase.REQUEST_HTTP_UPLOAD};
    private static byte o = 1;

    static SharedPreferences f44041b = QBSharedPreferences.getDirectSharedPreferences(ContextHolder.getAppContext(), "push_settings", 0);

    static SharedPreferences.Editor f44042c = f44041b.edit();
    private static PushEngine I = null;
    private static boolean J = false;

    public boolean f44043d = false;
    byte[] e = null;
    private byte[] p = null;
    private int q = 270;
    StreamConnection f = null;
    private ConnectionListener r = null;
    public boolean i = false;
    volatile int j = 2;
    private boolean z = true;
    private boolean A = false;
    private long B = 0;
    private int C = 0;
    private long D = 0;
    private boolean E = false;
    private boolean F = true;
    boolean l = false;
    Handler m = new Handler(Looper.getMainLooper(), this);
    Handler n = new Handler(BrowserExecutorSupplier.getLooperForRunShortTime(), this);
    private IBinder G = new MyBinder();
    private IPushRemoteService.Stub H = null;
    private TWPushInfo K = new TWPushInfo();
    private boolean L = false;

    class MyBinder extends IPushRemoteService.Stub {
        MyBinder() {
        }

        @Override
        public RawPushData a(int i) throws RemoteException {
            if (PushEngine.this.H != null) {
                return PushEngine.this.H.a(i);
            }
            return null;
        }

        @Override
        public void a() throws RemoteException {
            PushEngine.this.y();
        }

        @Override
        public void a(int i, int i2) throws RemoteException {
            if (PushEngine.this.H != null) {
                PushEngine.this.H.a(i, i2);
            }
        }

        @Override
        public void a(int i, int i2, byte b2, String str) throws RemoteException {
            PushEngine.this.a(i, i2, b2, str);
        }

        @Override
        public void a(int i, int i2, int i3, int i4, int i5, byte b2, String str, boolean z, String str2) {
            PushStatManager.a().a(i, i2, i3, i4, i5, b2, str, z, str2);
        }

        @Override
        public void a(int i, int i2, boolean z, int i3, String str, String str2, String str3, String str4, String str5, String str6) throws RemoteException {
            if (PushEngine.this.H != null) {
                PushEngine.this.H.a(i, i2, z, i3, str, str2, str3, str4, str5, str6);
            }
        }

        @Override
        public void a(int i, boolean z) throws RemoteException {
            if (PushEngine.this.H != null) {
                PushEngine.this.H.a(i, z);
            }
            if (i == 0) {
                PushEngine.this.v();
            }
            if (PushEngine.this.j == i) {
                return;
            }
            if (!z) {
                if (i == 0) {
                    i = 3;
                } else if (i == 2 && PushEngine.this.h != null) {
                    try {
                        i = PushEngine.this.h.a();
                    } catch (Exception unused) {
                    }
                }
            }
            PushEngine pushEngine = PushEngine.this;
            pushEngine.j = i;
            if (pushEngine.j != 0 && PushEngine.this.j != 3) {
                if (PushEngine.this.j == 2) {
                    PushEngine.this.n.sendEmptyMessage(8);
                    return;
                }
                return;
            }
            PushEngine.this.i = false;
            PushSdkChannelManager.a().a(NewServiceManager.a(), PushEngine.this.K);
            PushSdkChannelManager.a().b();
            StatManager.b().c("AWNWF51_PUSH-Channel-" + PushSdkChannelManager.d() + "-ACTIVE");
            PushEngine.this.n.obtainMessage(2).sendToTarget();
        }

        @Override
        public void a(IPushMessageListener iPushMessageListener) throws RemoteException {
            PushEngine.this.a(iPushMessageListener);
            if (PushEngine.this.H != null) {
                PushEngine.this.H.a(iPushMessageListener);
            }
        }

        @Override
        public void a(List<String> list) throws RemoteException {
            PushEngine.this.k.a(list);
        }

        @Override
        public void a(int[] iArr, int[] iArr2, byte[] bArr, String[] strArr) throws RemoteException {
            PushEngine.this.a(iArr, iArr2, bArr, strArr);
        }

        @Override
        public boolean a(String str) throws RemoteException {
            Message obtainMessage = PushEngine.this.n.obtainMessage(14);
            obtainMessage.getData().putString("direct_url", str);
            obtainMessage.sendToTarget();
            return true;
        }

        @Override
        public boolean a(byte[] bArr) throws RemoteException {
            if (Arrays.equals(PushEngine.this.e, bArr)) {
                return false;
            }
            GUIDManager.a().a(bArr);
            PushEngine pushEngine = PushEngine.this;
            pushEngine.e = bArr;
            pushEngine.n.obtainMessage(7, 99, 0).sendToTarget();
            return true;
        }

        @Override
        public RawPushData b(int i) throws RemoteException {
            if (PushEngine.this.H != null) {
                return PushEngine.this.H.b(i);
            }
            return null;
        }

        @Override
        public void b() throws RemoteException {
            PushEngine.this.n.sendEmptyMessage(4);
        }

        @Override
        public void b(int i, int i2) throws RemoteException {
            if (PushEngine.this.H != null) {
                PushEngine.this.H.b(i, i2);
            }
        }

        @Override
        public boolean b(String str) throws RemoteException {
            if (PushEngine.this.H != null) {
                return PushEngine.this.H.b(str);
            }
            return false;
        }

        @Override
        public List<RawPushData> c(int i) throws RemoteException {
            if (PushEngine.this.H != null) {
                return PushEngine.this.H.c(i);
            }
            return null;
        }

        @Override
        public void c() throws RemoteException {
        }

        @Override
        public void c(String str) throws RemoteException {
            PushEngine.this.b(str);
        }

        @Override
        public Bundle d() throws RemoteException {
            if (PushEngine.this.H == null) {
                return null;
            }
            PushEngine.this.H.d();
            return null;
        }

        @Override
        public void d(int i) throws RemoteException {
            if (PushEngine.this.H != null) {
                PushEngine.this.H.d(i);
            }
        }

        @Override
        public void d(String str) throws RemoteException {
            if (PushEngine.this.H != null) {
                PushEngine.this.H.d(str);
            }
        }

        @Override
        public boolean e() {
            return PushEngine.this.r();
        }
    }

    public class MyConnectionListener implements ConnectionListener {
        MyConnectionListener() {
        }

        @Override
        public void a() {
        }

        @Override
        public void a(Exception exc) {
            if (Apn.isNetworkAvailable()) {
                PushEngine.this.n.sendMessageDelayed(PushEngine.this.n.obtainMessage(1, 3, 0), 1000L);
            }
        }
    }

    public class PushPacketStatData {

        int f44052a;

        long f44053b;

        PushPacketStatData() {
        }
    }

    public class PushPacketWriteObserver implements PacketWriteObserver {
        PushPacketWriteObserver() {
        }

        private boolean a(int i) {
            return i == 1 || i == 0;
        }

        @Override
        public void a(Packet packet, Exception exc) {
            if (packet == null || packet.c() == null) {
                return;
            }
            PushPacketStatData pushPacketStatData = (PushPacketStatData) packet.c();
            if (a(pushPacketStatData.f44052a)) {
                PushEventReporter.a();
                PushEventReporter.a(pushPacketStatData.f44053b);
                PushEventReporter.a(PushEventReporter.f(PushEngine.this.f.b()));
                PushEventReporter.b(String.valueOf(PushEngine.this.f.c()));
                PushEventReporter.a(4);
                PushEventReporter.c(Apn.getApnName(Apn.getApnTypeS()));
                PushEventReporter.a(PushEngine.this.f.f32645b);
                PushEventReporter.d(PushEngine.this.f.f32644a);
                int b2 = PushEventReporter.b(exc);
                PushEventReporter.a(exc);
                PushEventReporter.b((int) (System.currentTimeMillis() - pushPacketStatData.f44053b));
                PushEventReporter.c(b2);
            }
        }

        @Override
        public void b(Packet packet) {
            if (packet == null || packet.c() == null) {
                return;
            }
            PushPacketStatData pushPacketStatData = (PushPacketStatData) packet.c();
            if (a(pushPacketStatData.f44052a)) {
                PushEventReporter.a();
                PushEventReporter.a(pushPacketStatData.f44053b);
                PushEventReporter.a(PushEventReporter.f(PushEngine.this.f.b()));
                PushEventReporter.b(String.valueOf(PushEngine.this.f.c()));
                PushEventReporter.a(4);
                PushEventReporter.c(Apn.getApnName(Apn.getApnTypeS()));
                PushEventReporter.a(PushEngine.this.f.f32645b);
                PushEventReporter.d(PushEngine.this.f.f32644a);
                PushEventReporter.b((int) (System.currentTimeMillis() - pushPacketStatData.f44053b));
                PushEventReporter.c(0);
            }
        }
    }

    private PushEngine() {
        PlatformStatUtils.a("PUSH_MANI_SDK_START_" + PushSdkChannelManager.d());
        try {
            z();
        } catch (Throwable unused) {
            PushFunnelStatUtils.a("2", 1, IUserServiceExtension.SERVICE_TYPE_SHOPPING, false);
        }
        this.m.sendEmptyMessage(10000);
        if (PushRemoteServiceBase.a() == null) {
            this.n.sendEmptyMessage(25);
        }
    }

    private byte[] A() {
        if (this.p == null) {
            this.p = B();
        }
        return this.p;
    }

    private byte[] B() {
        String string = f44041b.getString("pref_cookie", null);
        if (TextUtils.isEmpty(string)) {
            return null;
        }
        return Base64Utils.a(string, 0);
    }

    private boolean C() {
        return !QUAUtils.c().f79953a.equals(f44041b.getString("pref_version", ""));
    }

    private void D() {
        PushServerConfigs pushServerConfigs = this.k;
        if (pushServerConfigs != null) {
            pushServerConfigs.g();
        }
        this.v = false;
    }

    private void E() {
        new NetworkTask("www.qq.com", new NetworkTask.NetworkTaskCallback() {
            @Override
            public void onTaskFailed(MttRequestBase mttRequestBase, int i) {
                PushEventReporter.e("No Network");
                PushEventReporter.c(7);
            }

            @Override
            public void onTaskSuccess(MttRequestBase mttRequestBase, MttResponse mttResponse) {
            }
        }).d();
    }

    private void F() {
        long j = this.q * 1000;
        long elapsedRealtime = SystemClock.elapsedRealtime();
        long elapsedRealtime2 = SystemClock.elapsedRealtime() + j;
        long j2 = this.y;
        if (j2 <= elapsedRealtime || Math.abs(j2 - elapsedRealtime2) >= 1000) {
            a(ContextHolder.getAppContext(), j);
            this.y = elapsedRealtime2;
        }
    }

    private byte[] G() {
        if (this.e == null) {
            this.e = ServiceProcessManager.a().b();
        }
        return this.e;
    }

    private boolean H() {
        return d(G());
    }

    private String I() {
        String string = QBSharedPreferences.getSharedPreferences(ContextHolder.getAppContext(), "push_settings", 0).getString("pref_qua", "");
        if (!TextUtils.isEmpty(string)) {
            return string;
        }
        try {
            return QUAUtils.b();
        } catch (Exception unused) {
            return "";
        }
    }

    private String J() {
        String str;
        int indexOf;
        String I2 = I();
        if (!StringUtils.b(I2) && (indexOf = I2.indexOf(95)) != -1) {
            return I2.substring(0, indexOf);
        }
        try {
            String[] split = QUAUtils.c().f79953a.split("\\.");
            str = String.valueOf((Integer.parseInt(split[0]) * 10) + Integer.parseInt(split[1]));
        } catch (Exception unused) {
            str = "0";
        }
        return "ADRQBX" + str;
    }

    private String K() {
        String string = f44041b.getString("pref_qua2", "");
        return !StringUtils.b(string) ? string : QUAUtils.a();
    }

    private String L() {
        String K = K();
        String str = new String("");
        if (TextUtils.isEmpty(K)) {
            return str;
        }
        String[] split = K.split(ContainerUtils.FIELD_DELIMITER);
        if (split == null || split.length == 0) {
            return "";
        }
        String str2 = str;
        for (String str3 : split) {
            if (str3.startsWith("PR=") || str3.startsWith("PL=") || str3.startsWith("CO=") || str3.startsWith("PPVN=")) {
                str2 = str2 + str3 + ContainerUtils.FIELD_DELIMITER;
            }
        }
        return !TextUtils.isEmpty(str2) ? str2.substring(0, str2.length() - 1) : str2;
    }

    private byte M() {
        if (Apn.isWifiMode()) {
            return (byte) 1;
        }
        if (Apn.is2GMode()) {
            return (byte) 2;
        }
        if (Apn.is3GMode()) {
            return (byte) 3;
        }
        return Apn.is4GMode() ? (byte) 4 : (byte) 0;
    }

    public void N() {
        Intent intent;
        if (QBAutoStartHelper.a()) {
            Context appContext = ContextHolder.getAppContext();
            SyncService.a(appContext);
            if (!DeviceUtilsF.i() || DeviceUtilsF.K() >= 24) {
                if (DeviceUtilsF.K() <= 24) {
                    intent = new Intent(appContext, (Class<?>) PushRemoteService.InnerService.class);
                }
                if (DeviceUtilsF.K() >= 21 && !DeviceUtilsF.aF) {
                    try {
                        JobInfo.Builder builder = new JobInfo.Builder(1, new ComponentName(ContextHolder.getAppContext(), (Class<?>) JobschedulService.class));
                        builder.setPersisted(true);
                        builder.setPeriodic(1200000L);
                        ((JobScheduler) appContext.getSystemService("jobscheduler")).schedule(builder.build());
                    } catch (Throwable unused) {
                    }
                }
                if (DeviceUtilsF.aF || DeviceUtilsF.K() < 21) {
                }
                try {
                    ((JobScheduler) appContext.getSystemService("jobscheduler")).cancel(1);
                    return;
                } catch (Throwable unused2) {
                    return;
                }
            }
            intent = new Intent(appContext, (Class<?>) PushRemoteService.InnerService.class);
            appContext.startService(intent);
            if (DeviceUtilsF.K() >= 21) {
                JobInfo.Builder builder2 = new JobInfo.Builder(1, new ComponentName(ContextHolder.getAppContext(), (Class<?>) JobschedulService.class));
                builder2.setPersisted(true);
                builder2.setPeriodic(1200000L);
                ((JobScheduler) appContext.getSystemService("jobscheduler")).schedule(builder2.build());
            }
            if (DeviceUtilsF.aF) {
            }
        }
    }

    private Command a(int i, byte[] bArr) {
        Command command = new Command();
        command.shCmdId = (short) i;
        command.vCmdBody = new TEACoding(f44040a).a(bArr);
        byte b2 = o;
        o = (byte) (b2 + 1);
        command.cReqId = b2;
        if (o < 0) {
            o = (byte) 0;
        }
        return command;
    }

    private Command a(PushReq pushReq) {
        this.t = pushReq.cReqFlag;
        return a(3, JceUtil.jce2Bytes(pushReq));
    }

    public static void a(Context context, long j) {
        a(context, j, false);
    }

    public static void a(Context context, long j, boolean z) {
        Intent intent = new Intent(context, (Class<?>) PushEventReciever.class);
        intent.setAction("com.tencent.mtt.service.ACTION_HEARTBEAT");
        intent.putExtra("com.tencent.mtt.activatedBySDK", z);
        long currentTimeMillis = System.currentTimeMillis() + j;
        intent.putExtra("com.tencent.mtt.hb_delay", j);
        intent.putExtra("com.tencent.mtt.hb_expect_time", currentTimeMillis);
        PendingIntent broadcast = PendingIntent.getBroadcast(context, 0, intent, 268435456);
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(NotificationCompat.CATEGORY_ALARM);
        try {
            if (DeviceUtilsF.K() >= 19) {
                alarmManager.setWindow(0, currentTimeMillis, 0L, broadcast);
            } else if (DeviceUtilsF.K() >= 23) {
                alarmManager.setExactAndAllowWhileIdle(0, currentTimeMillis, broadcast);
            } else {
                alarmManager.set(0, currentTimeMillis, broadcast);
            }
        } catch (Exception unused) {
        }
        b(context, currentTimeMillis);
    }

    public static boolean a() {
        return I != null;
    }

    private boolean a(byte[] bArr, int i) {
        if (this.f == null || bArr == null) {
            return false;
        }
        Packet packet = new Packet(bArr);
        PushPacketStatData pushPacketStatData = new PushPacketStatData();
        pushPacketStatData.f44053b = System.currentTimeMillis();
        pushPacketStatData.f44052a = i;
        packet.a(pushPacketStatData);
        boolean d2 = this.f.d(packet);
        PushTrafficStats.b(r(), bArr.length);
        return d2;
    }

    private byte[] a(JceStruct jceStruct) {
        byte[] jce2Bytes = JceUtil.jce2Bytes(jceStruct);
        if (jce2Bytes.length + 2 > 32767) {
            return null;
        }
        int length = (short) (jce2Bytes.length + 2);
        byte[] bArr = new byte[length];
        ByteUtils.word2Byte(bArr, 0, length);
        System.arraycopy(jce2Bytes, 0, bArr, 2, jce2Bytes.length);
        return bArr;
    }

    private byte[] a(ArrayList<MsgFeedBackInfo> arrayList) {
        Command a2;
        if (arrayList.isEmpty()) {
            return null;
        }
        if (u()) {
            a2 = a(9, JceUtil.jce2Bytes(new PushAckReq(arrayList)));
        } else {
            ArrayList arrayList2 = new ArrayList();
            Iterator<MsgFeedBackInfo> it = arrayList.iterator();
            while (it.hasNext()) {
                arrayList2.add(new FeedBackData((byte) 1, JceUtil.jce2Bytes(it.next())));
            }
            String a3 = TWSettingManager.a().a("push_dataVer", (String) null);
            a2 = a(new PushReq(G(), null, 0L, s(), M(), arrayList2, null, (byte) 5, a3 == null ? null : ByteUtils.hexStringToByte(a3), null, q(), null, "", "", "", "", PushSettingsUtil.a()));
        }
        if (a2 == null) {
            return null;
        }
        return a(a2);
    }

    public static long b(Context context) {
        return f44041b.getLong("pref_hb", 0L);
    }

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

    private static void b(Context context, long j) {
        try {
            f44042c.putLong("pref_hb", j).apply();
        } catch (Throwable unused) {
        }
    }

    private void b(byte[] bArr) {
        try {
            f44042c.putString("pref_cookie", bArr == null ? "" : Base64Utils.b(this.p, 0)).apply();
        } catch (Throwable unused) {
        }
    }

    private byte[] b(boolean z, byte b2) {
        Command c2;
        try {
            if (H() || (c2 = c(true, b2)) == null) {
                return null;
            }
            return a(c2);
        } catch (Exception unused) {
            return null;
        }
    }

    private Command c(boolean z, byte b2) {
        byte[] bArr;
        byte[] bArr2;
        byte[] bArr3;
        String a2;
        String I2 = z ? I() : J();
        String K = z ? K() : L();
        int s = s();
        String str = null;
        String str2 = !TWSettingManager.a().a("key_enable_qua_2", true) ? null : K;
        String str3 = !TWSettingManager.a().a("key_enable_qua", false) ? null : I2;
        try {
            String a3 = TWSettingManager.a().a("push_dataVer", (String) null);
            bArr = a3 == null ? null : ByteUtils.hexStringToByte(a3);
            try {
                bArr2 = G();
                try {
                    bArr3 = A();
                    try {
                        str = q();
                    } catch (Throwable unused) {
                    }
                } catch (Throwable unused2) {
                    bArr3 = null;
                }
            } catch (Throwable unused3) {
                bArr2 = null;
                bArr3 = bArr2;
                byte[] bArr4 = bArr;
                byte[] bArr5 = bArr3;
                String str4 = str;
                byte[] bArr6 = bArr2;
                StatManager.b().c("CYPUSHGETQIMEI");
                String a4 = DeviceUtilsF.a(ContextHolder.getAppContext());
                a2 = QIMEIUtils.a();
                if (TextUtils.isEmpty(a2)) {
                }
                return a(new PushReq(bArr6, str3, 0L, s, M(), null, bArr5, b2, bArr4, null, str4, str2, "", a4, a2, PushStartReasonManager.a().b(), PushSettingsUtil.a()));
            }
        } catch (Throwable unused4) {
            bArr = null;
            bArr2 = null;
        }
        byte[] bArr42 = bArr;
        byte[] bArr52 = bArr3;
        String str42 = str;
        byte[] bArr62 = bArr2;
        StatManager.b().c("CYPUSHGETQIMEI");
        String a42 = DeviceUtilsF.a(ContextHolder.getAppContext());
        a2 = QIMEIUtils.a();
        if (TextUtils.isEmpty(a2)) {
            StatManager.b().c("CYPUSHGETQIMEINULL");
        }
        return a(new PushReq(bArr62, str3, 0L, s, M(), null, bArr52, b2, bArr42, null, str42, str2, "", a42, a2, PushStartReasonManager.a().b(), PushSettingsUtil.a()));
    }

    public static void c(final String str) {
        if (J || str == null) {
            PushFunnelStatUtils.a("5", 3, "1027", false);
            return;
        }
        StatManager.b().c("AWNWF51_PUSH-Channel-" + PushSdkChannelManager.d() + "-wupreport");
        int c2 = PushSdkChannelManager.c();
        if (c2 == -1) {
            PushFunnelStatUtils.a("5", 3, "1037", false);
            return;
        }
        AndroidDeviceToken androidDeviceToken = new AndroidDeviceToken(c2, str.getBytes());
        NotifyReportInfo notifyReportInfo = TextUtils.isEmpty(str) ? new NotifyReportInfo((short) 5, JceUtil.jce2Bytes(androidDeviceToken), false) : new NotifyReportInfo((short) 4, JceUtil.jce2Bytes(androidDeviceToken), false);
        DoNotifyReportReq doNotifyReportReq = new DoNotifyReportReq();
        doNotifyReportReq.sGuid = GUIDManager.a().f();
        doNotifyReportReq.sQua = QUAUtils.a();
        doNotifyReportReq.vReportInfo = new ArrayList<>();
        doNotifyReportReq.vReportInfo.add(notifyReportInfo);
        doNotifyReportReq.bTAP = true;
        WUPRequest wUPRequest = new WUPRequest("NotifyReport", "doNotifyReport");
        wUPRequest.put("stReq", doNotifyReportReq);
        wUPRequest.setRequestCallBack(new IWUPRequestCallBack() {
            @Override
            public void onWUPTaskFail(WUPRequestBase wUPRequestBase) {
                PushFunnelStatUtils.a("5", 4, "1038", false);
                StatManager.b().c("AWNWF51_PUSH-Channel-" + PushSdkChannelManager.d() + "-wupreport-e3");
                EventLog.a("PushSdk", "wup方式上传token", "响应失败", "WUPTaskFail", "allenhan", -1);
            }

            @Override
            public void onWUPTaskSuccess(WUPRequestBase wUPRequestBase, WUPResponseBase wUPResponseBase) {
                Integer returnCode = wUPResponseBase.getReturnCode();
                if (returnCode == null || returnCode.intValue() != 0) {
                    PushFunnelStatUtils.a("5", 5, "1039", false);
                    StatManager.b().c("AWNWF51_PUSH-Channel-" + PushSdkChannelManager.d() + "-wupreport-e2");
                    return;
                }
                Object obj = wUPResponseBase.get("stRsp");
                if (obj == null || !(obj instanceof DoNotifyReportRsp)) {
                    return;
                }
                DoNotifyReportRsp doNotifyReportRsp = (DoNotifyReportRsp) obj;
                int i = -100;
                try {
                    i = doNotifyReportRsp.mRet.get((short) 3).intValue();
                } catch (Exception unused) {
                }
                if (i < 0) {
                    PushFunnelStatUtils.a("5", 6, "1040", false);
                    StatManager.b().c("AWNWF51_PUSH-Channel-" + PushSdkChannelManager.d() + "-wupreport-e1");
                    EventLog.a("PushSdk", "wup方式上传token", "响应失败", "ret:" + i + " " + doNotifyReportRsp.mRet.size(), "allenhan");
                    return;
                }
                boolean unused2 = PushEngine.J = true;
                EventLog.a("PushSdk", "wup方式上传token", "响应成功", "ret:" + i, "allenhan");
                PushFunnelStatUtils.a("5", 8, "1032", true);
                if (TextUtils.isEmpty(str)) {
                    PushFunnelStatUtils.a(Constants.VIA_SHARE_TYPE_INFO, 1, "1033", false);
                    return;
                }
                StatManager.b().c("AWNWF51_PUSH-Channel-" + PushSdkChannelManager.d() + "-wupreport-ok");
                PushFunnelStatUtils.a(Constants.VIA_SHARE_TYPE_INFO, 2, "1034", true);
            }
        });
        WUPTaskProxy.send(wUPRequest);
        EventLog.a("PushSdk", "wup方式上传token", "发送上传请求", "guid:" + doNotifyReportReq.sGuid + "token: " + str, "allenhan");
    }

    private void c(byte[] bArr) {
        if (bArr == null) {
            return;
        }
        String b2 = this.k.b();
        if (TextUtils.isEmpty(b2)) {
            return;
        }
        try {
            NetworkTask networkTask = new NetworkTask(b2, new NetworkTask.NetworkTaskCallback() {
                @Override
                public void onTaskFailed(MttRequestBase mttRequestBase, int i) {
                }

                @Override
                public void onTaskSuccess(MttRequestBase mttRequestBase, MttResponse mttResponse) {
                    MttInputStream mttInputStream;
                    if (200 == mttResponse.getStatusCode().intValue()) {
                        try {
                            int contentLength = (int) mttResponse.getContentLength();
                            mttInputStream = mttResponse.getInputStream();
                            try {
                                mttInputStream.skip(2L);
                                int i = contentLength - 2;
                                byte[] bArr2 = new byte[i];
                                for (int i2 = 0; i2 < i; i2 += mttInputStream.read(bArr2, i2, i - i2)) {
                                }
                                PushEngine.this.w = true;
                                PushEngine.this.g.a(new Packet(bArr2));
                            } catch (Exception unused) {
                            } catch (Throwable th) {
                                th = th;
                                FileUtils.a((Closeable) mttInputStream);
                                FileUtils.a((Closeable) null);
                                throw th;
                            }
                        } catch (Exception unused2) {
                            mttInputStream = null;
                        } catch (Throwable th2) {
                            th = th2;
                            mttInputStream = null;
                        }
                        FileUtils.a((Closeable) mttInputStream);
                        FileUtils.a((Closeable) null);
                    }
                }
            });
            networkTask.b("Content-Type", "application/x-www-form-urlencoded");
            networkTask.b("Content-Length", Integer.toString(bArr.length));
            networkTask.a(bArr);
            networkTask.a(20000);
            networkTask.b(20000);
            networkTask.d();
        } catch (Exception unused) {
        }
    }

    public static boolean c(Context context) {
        long j = f44041b.getLong("pref_first_time", 0L);
        long currentTimeMillis = System.currentTimeMillis();
        if (j != 0) {
            return currentTimeMillis - j > DBHelper.RECORD_EXPIRE_TIME;
        }
        try {
            f44042c.putLong("pref_first_time", currentTimeMillis).apply();
        } catch (Throwable unused) {
        }
        return false;
    }

    private void d(String str) {
        StatManager b2;
        StringBuilder sb;
        String str2;
        String str3;
        int i;
        String str4;
        String str5;
        String str6;
        if (str == null) {
            PushFunnelStatUtils.a("5", 4, "1028", false);
            return;
        }
        StatManager.b().c("AWNWF51_PUSH-Channel-" + PushSdkChannelManager.d() + "-report2");
        if (TextUtils.isEmpty(str)) {
            StatManager.b().c("AWNWF51_PUSH-Channel-" + PushSdkChannelManager.d() + "-report2-e");
        }
        StreamConnection streamConnection = this.f;
        if (streamConnection == null || !streamConnection.f()) {
            EventLog.a("PushSdk", "上传token", "no connnection retry after 1s", "", "normanchen", -1);
            this.n.sendMessageDelayed(this.n.obtainMessage(24, str), 1000L);
            return;
        }
        int c2 = PushSdkChannelManager.c();
        if (c2 == -1) {
            PushFunnelStatUtils.a("5", 6, "1030", false);
            return;
        }
        AndroidDeviceToken androidDeviceToken = new AndroidDeviceToken(c2, str.getBytes());
        NotifyReportInfo notifyReportInfo = TextUtils.isEmpty(str) ? new NotifyReportInfo((short) 5, JceUtil.jce2Bytes(androidDeviceToken), false) : new NotifyReportInfo((short) 4, JceUtil.jce2Bytes(androidDeviceToken), false);
        ArrayList arrayList = new ArrayList();
        arrayList.add(notifyReportInfo);
        boolean a2 = a(a(a(5, JceUtil.jce2Bytes(new UserInfoReportReq(G(), arrayList, this.K.g, DeviceUtilsF.a(ContextHolder.getAppContext()), QIMEIUtils.a())))), -1);
        StatManager.b().c("AWNWF51_PUSH-Channel-" + PushSdkChannelManager.d() + "-report3");
        if (a2) {
            PushFunnelStatUtils.a("5", 8, "1032", true);
            if (TextUtils.isEmpty(str)) {
                PushFunnelStatUtils.a(Constants.VIA_SHARE_TYPE_INFO, 1, "1033", false);
                b2 = StatManager.b();
                sb = new StringBuilder();
                sb.append("AWNWF51_PUSH-Channel-");
                sb.append(PushSdkChannelManager.d());
                str2 = "-report3-e";
            } else {
                PushFunnelStatUtils.a(Constants.VIA_SHARE_TYPE_INFO, 2, "1034", true);
                b2 = StatManager.b();
                sb = new StringBuilder();
                sb.append("AWNWF51_PUSH-Channel-");
                sb.append(PushSdkChannelManager.d());
                str2 = "-report3-ok";
            }
        } else {
            PushFunnelStatUtils.a("5", 7, "1031", false);
            b2 = StatManager.b();
            sb = new StringBuilder();
            sb.append("AWNWF51_PUSH-Channel-");
            sb.append(PushSdkChannelManager.d());
            str2 = "-report3-e1";
        }
        sb.append(str2);
        b2.c(sb.toString());
        if (TextUtils.isEmpty(str)) {
            str3 = "doReportMiRegId:" + str + "    \r\nsdkType:  " + PushSdkChannelManager.a(c2);
            i = -1;
            str4 = "PushSdk";
            str5 = "上传token";
            str6 = "上传空token";
        } else {
            PlatformStatUtils.a("PUSH_MANI_SDK_UPLOAD_SUCC_" + PushSdkChannelManager.d());
            str3 = "URL: doReportMiRegId:" + str + "    \r\nsdkType:  " + PushSdkChannelManager.a(c2);
            i = -1;
            str4 = "PushSdk";
            str5 = "上传token";
            str6 = "上传成功";
        }
        EventLog.a(str4, str5, str6, str3, "normanchen", i);
    }

    private static boolean d(byte[] bArr) {
        if (bArr == null) {
            return true;
        }
        for (byte b2 : bArr) {
            if (b2 != 0) {
                return false;
            }
        }
        return true;
    }

    public static String q() {
        NetworkInfo activeNetworkInfo = Apn.getActiveNetworkInfo(false);
        int i = -1;
        String str = null;
        if (activeNetworkInfo != null) {
            try {
                i = activeNetworkInfo.getType();
                str = activeNetworkInfo.getExtraInfo();
            } catch (Exception unused) {
                return null;
            }
        }
        return i == 1 ? Apn.APN_WIFI : (str == null || str.length() <= 10) ? str : str.substring(0, 10);
    }

    private void z() {
        EventEmiter.getDefault().emit(new EventMessage("PushEngine.PushInit", this.K));
        AppBroadcastReceiver.a().a(ContextHolder.getAppContext());
        AppBroadcastReceiver.a().a(this);
        this.k = new PushServerConfigs(this);
        this.g = new PushRespProcessor(this);
        this.u = new PushPacketWriteObserver();
        if (C()) {
            f44042c.putString("pref_qua", "");
            f44042c.putString("pref_qua2", "");
            try {
                f44042c.apply();
            } catch (Throwable unused) {
            }
        }
        this.n.post(new Runnable() {
            @Override
            public void run() {
                try {
                    String str = ContextHolder.getAppContext().getPackageManager().getPackageInfo(ContextHolder.getAppContext().getPackageName(), 0).versionName;
                    if (TextUtils.isEmpty(str) || str.equalsIgnoreCase(PushEngine.f44041b.getString("pref_versionName", ""))) {
                        return;
                    }
                    PushEngine.f44042c.putString("pref_versionName", str);
                    PushEngine.f44042c.putString("pref_location", "");
                    PushEngine.f44042c.apply();
                } catch (Throwable unused2) {
                }
            }
        });
        if (this.z) {
            this.n.obtainMessage(13).sendToTarget();
        }
        this.n.postDelayed(new Runnable() {
            @Override
            public void run() {
                PushEngine.this.x();
                PushEngine.this.n.obtainMessage(16).sendToTarget();
                PushSdkChannelManager.a().a(NewServiceManager.a(), PushEngine.this.K);
                PushSdkChannelManager.a().b();
                StatManager.b().c("AWNWF51_PUSH-Channel-" + PushSdkChannelManager.d() + "-onCreate");
            }
        }, 1000L);
        this.n.postDelayed(new Runnable() {
            @Override
            public void run() {
                PushEngine.this.N();
                try {
                    EventEmiter.getDefault().emit(new EventMessage("com.tencent.mtt.browser.push.event.POST_CREATE"));
                } catch (Throwable unused2) {
                }
            }
        }, 1000L);
    }

    void a(byte b2) {
        NetworkInfo activeNetworkInfo;
        byte b3;
        boolean z;
        String str;
        String str2;
        int i;
        String str3;
        String str4;
        if (H() || this.i || (activeNetworkInfo = Apn.getActiveNetworkInfo(false)) == null || !activeNetworkInfo.isAvailable()) {
            return;
        }
        if (this.f == null) {
            this.f = new StreamConnection();
            this.f.a(this.g);
            this.f.a(this.u);
        }
        if (this.f.f() && this.s != activeNetworkInfo.getType()) {
            EventLog.a("Push(ip list)", "网路类型:" + this.s, "断开当前连接", "新网络类型:" + activeNetworkInfo.getType(), "normanchen", 1);
            this.f.h();
        }
        if (!this.f.f()) {
            String string = f44041b.getString("pref_version", null);
            EventLog.a("Push(ip list)", "网路类型:" + this.s, "lastVersion:" + string, "新网络类型:" + activeNetworkInfo.getType(), "normanchen", 1);
            if (string == null) {
                z = true;
                b3 = 97;
            } else if (QUAUtils.c().f79953a.equals(string)) {
                b3 = b2;
                z = false;
            } else {
                z = true;
                b3 = 98;
            }
            PushServerConfigs pushServerConfigs = this.k;
            if (pushServerConfigs == null) {
                return;
            }
            if (pushServerConfigs != null && !pushServerConfigs.e()) {
                if (this.v) {
                    return;
                }
                c(b(z, b3));
                return;
            }
            ConnectionConfiguration a2 = this.k.a();
            if (a2 == null) {
                return;
            }
            PushEventReporter.a();
            long currentTimeMillis = System.currentTimeMillis();
            PushEventReporter.a(currentTimeMillis);
            PushEventReporter.a(a2.a());
            PushEventReporter.b(String.valueOf(a2.b()));
            this.f.f32645b = this.k.d();
            PushEventReporter.a(this.f.f32645b && this.k.f());
            this.f.f32644a = this.k.c();
            PushEventReporter.d(this.f.f32644a);
            PushEventReporter.a(1);
            PushEventReporter.c(Apn.getApnName(Apn.getApnType()));
            EventLog.a("Push(ip list)", "网路类型:" + activeNetworkInfo.getType(), "当前ip", a2.a() + com.xiaomi.mipush.sdk.Constants.COLON_SEPARATOR + a2.b(), "normanchen", 1);
            long j = this.B;
            if (j != 0) {
                PushEventReporter.b(j);
                PushEventReporter.d(-1);
                this.B = 0L;
            }
            try {
                this.f.a(a2);
                this.f.j();
                this.s = activeNetworkInfo.getType();
                if (this.r == null) {
                    this.r = new MyConnectionListener();
                }
                this.f.a(this.r);
                a(270);
                this.v = true;
                this.w = false;
                this.A = false;
                PushEventReporter.c(0);
                EventLog.a("Push(ip list)", "网路类型:" + activeNetworkInfo.getType(), "连接成功", a2.a() + com.xiaomi.mipush.sdk.Constants.COLON_SEPARATOR + a2.b(), "normanchen", 1);
            } catch (IOException e) {
                int b4 = PushEventReporter.b(e);
                PushEventReporter.a(e);
                PushEventReporter.c(b4);
                if (this.k.d() && this.k.f()) {
                    E();
                }
                this.n.sendMessageDelayed(this.n.obtainMessage(1, 3, 0), 1000L);
                str = "网路类型:" + activeNetworkInfo.getType();
                str2 = a2.a() + com.xiaomi.mipush.sdk.Constants.COLON_SEPARATOR + a2.b();
                i = -1;
                str3 = "Push(ip list)";
                str4 = "连接失败1";
                EventLog.a(str3, str, str4, str2, "normanchen", i);
                PushEventReporter.b((int) (System.currentTimeMillis() - currentTimeMillis));
                if (this.f.f()) {
                }
                this.n.removeMessages(6);
            } catch (Exception e2) {
                int b5 = PushEventReporter.b(e2);
                PushEventReporter.a(e2);
                PushEventReporter.c(b5);
                if (this.k.d() && this.k.f()) {
                    E();
                }
                str = "网路类型:" + activeNetworkInfo.getType();
                str2 = a2.a() + com.xiaomi.mipush.sdk.Constants.COLON_SEPARATOR + a2.b();
                i = -1;
                str3 = "Push(ip list)";
                str4 = "连接失败2";
                EventLog.a(str3, str, str4, str2, "normanchen", i);
                PushEventReporter.b((int) (System.currentTimeMillis() - currentTimeMillis));
                if (this.f.f()) {
                }
                this.n.removeMessages(6);
            }
            PushEventReporter.b((int) (System.currentTimeMillis() - currentTimeMillis));
            if (this.f.f()) {
                a(z, b3);
            }
        } else if (b2 == 99 || b2 == 100) {
            n();
        }
        this.n.removeMessages(6);
    }

    public void a(int i) {
        if (i < 30 || i > 86400000 || this.q == i) {
            return;
        }
        this.q = i;
        F();
    }

    public void a(int i, int i2, byte b2, String str) {
        ArrayList arrayList = new ArrayList(1);
        arrayList.add(new MsgFeedBackInfo(i, i2, b2, str));
        this.n.obtainMessage(5, 0, 3, arrayList).sendToTarget();
    }

    public void a(Context context) {
        Intent intent = new Intent(context, (Class<?>) PushEventReciever.class);
        intent.setAction("com.tencent.mtt.service.ACTION_HEARTBEAT");
        intent.putExtra("com.tencent.mtt.activatedBySDK", false);
        try {
            ((AlarmManager) context.getSystemService(NotificationCompat.CATEGORY_ALARM)).cancel(PendingIntent.getBroadcast(context, 0, intent, 268435456));
        } catch (Exception unused) {
        }
    }

    public void a(Intent intent) {
        Message obtainMessage = this.n.obtainMessage(2);
        obtainMessage.arg1 = intent.getBooleanExtra("com.tencent.mtt.activatedBySDK", false) ? 1 : 0;
        obtainMessage.sendToTarget();
        if (this.z) {
            this.n.obtainMessage(13).sendToTarget();
        }
        this.z = false;
    }

    void a(IPushMessageListener iPushMessageListener) {
        this.h = iPushMessageListener;
    }

    public void a(IPushRemoteService.Stub stub) {
        this.H = stub;
    }

    void a(String str) {
        SocketReportReq socketReportReq = new SocketReportReq();
        socketReportReq.sURL = str;
        byte[] a2 = a(a(11, JceUtil.jce2Bytes(socketReportReq)));
        if (a2 != null) {
            a(a2, 3);
            F();
        }
    }

    public void a(ArrayList<PushData> arrayList, boolean z) {
        Message obtainMessage;
        int size = arrayList.size();
        ArrayList arrayList2 = new ArrayList(size);
        for (int i = 0; i < size; i++) {
            PushData pushData = arrayList.get(i);
            if (pushData.cNeedFeedBack == 1) {
                arrayList2.add(new MsgFeedBackInfo(pushData.iAppId, pushData.iMsgId, (byte) 0, pushData.sExtraInfo));
            }
        }
        if (!arrayList2.isEmpty()) {
            obtainMessage = this.n.obtainMessage(5, !z ? 1 : 0, 3, arrayList2);
        } else if (z) {
            return;
        } else {
            obtainMessage = this.n.obtainMessage(6);
        }
        obtainMessage.sendToTarget();
    }

    void a(ArrayList<MsgFeedBackInfo> arrayList, boolean z, int i) {
        byte[] a2;
        if (arrayList == null || (a2 = a(arrayList)) == null) {
            return;
        }
        if (this.w) {
            c(a2);
            return;
        }
        try {
            if (!this.f.f()) {
                this.f.j();
            }
            a(a2, 2);
        } catch (Exception unused) {
            int i2 = i - 1;
            if (i2 > 0) {
                this.n.sendMessageDelayed(this.n.obtainMessage(5, z ? 1 : 0, i2, arrayList), BaseConstants.DEFAULT_MSG_TIMEOUT);
            }
        }
        if (z) {
            try {
                EventLog.a("Push(ip list)", "网路类型:" + this.s, "断开连接", "closeConnection", "allenhan", 1);
                k();
            } catch (Exception unused2) {
            }
        }
    }

    void a(boolean z) {
        if (!PushSettingsUtil.b("key_push_day_first_heartbeat")) {
            PushSettingsUtil.a("key_push_day_first_heartbeat");
        }
        F();
        D();
        this.l = false;
        if (Apn.isNetworkAvailable()) {
            long elapsedRealtime = SystemClock.elapsedRealtime();
            if (elapsedRealtime - this.x < BaseConstants.DEFAULT_MSG_TIMEOUT) {
                return;
            }
            this.x = elapsedRealtime;
            if (!u()) {
                a(z ? MttRequestBase.REQUEST_NORMAL : (byte) 0);
            } else if (this.A) {
                EventLog.a("Push(ip list)", "网路类型:" + this.s, "尝试重连", "ShortHeartBeatNotConfirmed for long time send MSG_RECONNECT. ", "allenhan", 1);
                this.n.sendMessage(this.n.obtainMessage(7, 1, 0));
                this.A = false;
            } else {
                n();
            }
            try {
                PushStatManager.a().c();
            } catch (Throwable unused) {
            }
        } else {
            a(270);
            PushEventReporter.b();
        }
        try {
            m();
        } catch (Throwable unused2) {
        }
    }

    void a(boolean z, byte b2) {
        if (!PushSettingsUtil.b("key_push_day_first_heartbeat")) {
            PushSettingsUtil.a("key_push_day_first_heartbeat");
        }
        byte[] b3 = b(z, b2);
        if (b3 != null) {
            a(b3, 1);
            EventLog.a("Push(ip list)", "网路类型:" + this.s, "发送长心跳", "needQua:" + z + ", type:" + ((int) b2), "allenhan", 1);
            if (z) {
                try {
                    f44042c.putString("pref_version", QUAUtils.c().f79953a).apply();
                } catch (Throwable unused) {
                }
            }
            F();
        }
    }

    public void a(byte[] bArr) {
        this.p = bArr;
        b(bArr);
    }

    public void a(int[] iArr, int[] iArr2, byte[] bArr, String[] strArr) {
        int length = iArr.length;
        ArrayList arrayList = new ArrayList(length);
        for (int i = 0; i < length; i++) {
            arrayList.add(new MsgFeedBackInfo(iArr[i], iArr2[i], bArr[i], strArr[i]));
        }
        this.n.obtainMessage(5, 0, 3, arrayList).sendToTarget();
    }

    public synchronized boolean a(int i, List<RawPushData> list) {
        try {
            if (this.h != null) {
                return this.h.a(i, list);
            }
        } catch (DeadObjectException unused) {
            this.j = 2;
            this.h = null;
        } catch (Throwable unused2) {
        }
        return false;
    }

    public synchronized boolean a(RawPushData rawPushData) {
        try {
        } catch (DeadObjectException unused) {
            this.j = 2;
            this.h = null;
            if (rawPushData != null) {
                EventLog.a("PushTips", "aID[" + rawPushData.mAppId + "]/mID[" + rawPushData.mMsgId + "]", "分发消息到主进程失败", "服务异常", "normanchen", -1);
            }
        } catch (Throwable unused2) {
        }
        if (this.h == null) {
            if (rawPushData != null) {
                EventLog.a("PushTips", "aID[" + rawPushData.mAppId + "]/mID[" + rawPushData.mMsgId + "]", "分发消息到主进程失败", "主进程未启动", "normanchen", -1);
            }
            return false;
        }
        boolean a2 = this.h.a(rawPushData);
        if (rawPushData != null) {
            EventLog.a("PushTips", "aID[" + rawPushData.mAppId + "]/mID[" + rawPushData.mMsgId + "]", "分发消息到主进程", "", "normanchen");
        }
        return a2;
    }

    public synchronized boolean a(RawPushData rawPushData, TipsMsg tipsMsg) {
        try {
            try {
            } catch (DeadObjectException unused) {
                if (rawPushData != null && tipsMsg != null) {
                    OperationStat.a(2, rawPushData.mAppId + "_" + tipsMsg.iMsgId, -1, 101, 0);
                }
                this.j = 2;
                this.h = null;
            }
        } catch (Throwable unused2) {
            if (rawPushData != null && tipsMsg != null) {
                OperationStat.a(2, rawPushData.mAppId + "_" + tipsMsg.iMsgId, -1, 102, 0);
            }
        }
        if (this.h != null) {
            return this.h.a(rawPushData);
        }
        OperationStat.a(2, rawPushData.mAppId + "_" + tipsMsg.iMsgId, -1, 103, 0);
        return false;
    }

    void b(byte b2) {
        if (b2 == 1) {
            PushEventReporter.c();
        }
        StreamConnection streamConnection = this.f;
        if (streamConnection != null) {
            streamConnection.h();
            EventLog.a("Push(ip list)", "网路类型:" + this.s, "断开连接", "doRececonnect: " + ((int) b2), "allenhan", 1);
        }
        a(b2);
    }

    @Override
    public void b(int i) {
        this.e = ServiceProcessManager.a().b();
        this.n.obtainMessage(2).sendToTarget();
    }

    public void b(Intent intent) {
        if (!H()) {
            this.n.obtainMessage(2).sendToTarget();
            this.n.obtainMessage(13).sendToTarget();
        } else {
            ServiceProcessManager a2 = ServiceProcessManager.a();
            a2.a(this);
            a2.c();
        }
    }

    public void b(String str) {
        SharedPreferences sharedPreferences = QBSharedPreferences.getSharedPreferences(ContextHolder.getAppContext(), "push_settings", 0);
        long j = sharedPreferences.getLong("pref_regid_report_time", 0L);
        long currentTimeMillis = System.currentTimeMillis();
        Date date = new Date(j);
        Date date2 = new Date(currentTimeMillis);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        String format = simpleDateFormat.format(date);
        if (!TextUtils.equals(format, simpleDateFormat.format(date2)) || TWSettingManager.a().a("PUSH_DISABLE_TOKEN_INTERVAL", false)) {
            boolean isEmpty = TextUtils.isEmpty(str);
            SharedPreferences.Editor edit = sharedPreferences.edit();
            (isEmpty ? edit.putLong("pref_regid_report_time", 0L) : edit.putLong("pref_regid_report_time", currentTimeMillis)).apply();
        } else {
            if (!TextUtils.equals(this.K.g, "KB") || this.L) {
                PushFunnelStatUtils.a("5", 3, "1027", false);
                EventLog.a("PushSdk", "上传token", "上传频控 last:" + format, "earlli");
                return;
            }
            if (!TextUtils.isEmpty(str)) {
                this.L = true;
            }
        }
        this.n.obtainMessage(24, str).sendToTarget();
    }

    public void c() {
    }

    void c(int i) {
        long j = f44041b.getLong("pref_hb", 0L) - System.currentTimeMillis();
        if (j > 0) {
            a(ContextHolder.getAppContext(), j, false);
            return;
        }
        Message obtainMessage = this.n.obtainMessage(2);
        obtainMessage.arg1 = 0;
        obtainMessage.sendToTarget();
    }

    public void c(Intent intent) {
        if (!H()) {
            this.n.obtainMessage(15).sendToTarget();
            this.n.obtainMessage(13).sendToTarget();
        } else {
            ServiceProcessManager a2 = ServiceProcessManager.a();
            a2.a(this);
            a2.c();
        }
    }

    void d() {
        PushServerConfigs pushServerConfigs;
        StreamConnection streamConnection = this.f;
        if (streamConnection == null || (pushServerConfigs = this.k) == null) {
            return;
        }
        streamConnection.f32644a = pushServerConfigs.c();
    }

    public void d(Intent intent) {
        byte[] byteArrayExtra = intent.getByteArrayExtra("guid");
        if (!d(byteArrayExtra)) {
            this.e = byteArrayExtra;
        }
        String stringExtra = intent.getStringExtra("qua");
        if (!TextUtils.isEmpty(stringExtra)) {
            try {
                f44042c.putString("pref_qua", stringExtra).apply();
            } catch (Throwable unused) {
            }
        }
        String stringExtra2 = intent.getStringExtra("qua2");
        if (!TextUtils.isEmpty(stringExtra2)) {
            try {
                f44042c.putString("pref_qua2", stringExtra2).apply();
            } catch (Throwable unused2) {
            }
        }
        boolean booleanExtra = intent.getBooleanExtra("light", false);
        this.j = booleanExtra ? 3 : 0;
        this.n.obtainMessage(1, booleanExtra ? 100 : 99, 0).sendToTarget();
        this.n.obtainMessage(13).sendToTarget();
    }

    public SharedPreferences e() {
        return f44041b;
    }

    public void e(Intent intent) {
        EventEmiter.getDefault().emit(new EventMessage("com.tencent.mtt.Push.doTest", intent));
    }

    public void f() {
        this.n.obtainMessage(12).sendToTarget();
    }

    public void g() {
        PushEventReporter.f();
        this.n.obtainMessage(7, 0, 0).sendToTarget();
    }

    public void h() {
        if (this.l) {
            return;
        }
        this.n.obtainMessage(3, 1, this.t).sendToTarget();
        this.l = true;
    }

    @Override
    public boolean handleMessage(Message message) {
        byte b2;
        int i = message.what;
        if (i == 12) {
            d();
        } else if (i != 10000) {
            if (i != 14) {
                if (i != 15) {
                    switch (i) {
                        case 1:
                            b2 = (byte) message.arg1;
                            a(b2);
                            break;
                        case 2:
                            a(message.arg1 == 1);
                            break;
                        case 3:
                            boolean z = message.arg1 == 1;
                            b2 = (byte) message.arg2;
                            if (u()) {
                                a(z, b2);
                                break;
                            }
                            a(b2);
                            break;
                        case 4:
                            if (u()) {
                                n();
                                break;
                            }
                            break;
                        case 5:
                            a((ArrayList<MsgFeedBackInfo>) message.obj, message.arg1 != 0, message.arg2);
                            break;
                        case 6:
                            k();
                            break;
                        case 7:
                            b((byte) message.arg1);
                            break;
                        case 8:
                            l();
                            break;
                        default:
                            switch (i) {
                                case 24:
                                    d((String) message.obj);
                                    break;
                                case 25:
                                    try {
                                        Intent intent = new Intent(ContextHolder.getAppContext(), (Class<?>) PushRemoteService.class);
                                        intent.setAction("com.tencent.mtt.service.ACTION_DEFAULT");
                                        ContextHolder.getAppContext().startService(intent);
                                        break;
                                    } catch (Throwable unused) {
                                        break;
                                    }
                                case 26:
                                    this.i = false;
                                    break;
                            }
                    }
                } else {
                    c(1);
                }
            } else if (u()) {
                a(message.getData().getString("direct_url"));
            }
            a((byte) 0);
        }
        return false;
    }

    public void i() {
        this.n.sendEmptyMessage(6);
    }

    public void j() {
        if (Apn.isNetworkAvailable()) {
            this.q = 270;
            NetworkInfo activeNetworkInfo = Apn.getActiveNetworkInfo(false);
            StreamConnection streamConnection = this.f;
            if (streamConnection == null || !streamConnection.f() || (activeNetworkInfo != null && this.s != activeNetworkInfo.getType())) {
                this.n.sendEmptyMessage(2);
            }
            this.n.obtainMessage(13).sendToTarget();
        }
        this.n.obtainMessage(16).sendToTarget();
    }

    void k() {
        int i = Calendar.getInstance().get(11);
        if (i < 1 || i >= 7) {
            this.n.sendEmptyMessageDelayed(26, DateUtils.ONE_HOUR);
        } else {
            this.n.sendEmptyMessageDelayed(26, (7 - i) * 60 * 60 * 1000);
        }
        this.i = true;
        StreamConnection streamConnection = this.f;
        if (streamConnection != null) {
            streamConnection.h();
            EventLog.a("Push(ip list)", "网路类型:" + this.s, "断开连接", "doDisconnect", "allenhan", 1);
        }
    }

    void l() {
        if (!QBAutoStartHelper.a()) {
            StreamConnection streamConnection = this.f;
            if (streamConnection != null && streamConnection.f()) {
                n();
            }
            i();
            a(ContextHolder.getAppContext());
            return;
        }
        StreamConnection streamConnection2 = this.f;
        if (streamConnection2 != null && streamConnection2.f()) {
            n();
        } else {
            if (this.j != 2) {
                return;
            }
            F();
        }
    }

    void m() {
        EventEmiter.getDefault().emit(new EventMessage("PushEngine.onHeartBeat"));
    }

    void n() {
        if (!PushSettingsUtil.b("key_push_day_first_heartbeat")) {
            PushSettingsUtil.a("key_push_day_first_heartbeat");
        }
        int s = s();
        byte[] bArr = new byte[2];
        ByteUtils.word2Byte(bArr, 0, (short) (65280 | s));
        a(bArr, 0);
        EventLog.a("Push(ip list)", "网路类型:" + this.s, "发送短心跳", "state:" + s, "allenhan", 1);
        this.n.removeMessages(7);
        this.n.sendMessageDelayed(this.n.obtainMessage(7, 1, 0), 45000L);
        this.A = true;
        EventLog.a("Push(ip list)", "网路类型:" + this.s, "尝试45000ms后重连", "ShortHeartBeatNotConfirmed for long time send MSG_RECONNECT. ", "allenhan", 1);
    }

    public void o() {
        long currentTimeMillis = System.currentTimeMillis();
        long j = this.D;
        if (j == 0 || currentTimeMillis - j > 86400000) {
            StatManager.b().f();
            PushEventReporter.g();
            this.D = currentTimeMillis;
        }
    }

    @Override
    public void onBroadcastReceiver(Intent intent) {
        if (intent != null && IMessageCenter.MSG_SYS_CONNECTIVITY_ACTION.equals(intent.getAction()) && DeviceUtilsF.K() >= 24) {
            PushStatReceiver.a(ContextHolder.getAppContext());
        }
    }

    public void p() {
        EventLog.a("Push(ip list)", "网路类型:" + this.s, "收到响应,删除重连消息", "responseReceived", "allenhan", 1);
        this.A = false;
        this.n.removeMessages(7);
        PushMessageCache.a().b();
    }

    public boolean r() {
        return this.j == 3 || this.j == 0;
    }

    public int s() {
        if (this.j == 3) {
            return this.j;
        }
        this.j = t();
        return this.j;
    }

    int t() {
        try {
            if (this.h != null) {
                int a2 = this.h.a();
                if (a2 == -1) {
                    return 1;
                }
                return a2;
            }
            if (this.j == 0 || this.j == 1) {
                this.j = 2;
            }
            return this.j;
        } catch (Throwable unused) {
            return 2;
        }
    }

    public boolean u() {
        StreamConnection streamConnection = this.f;
        return streamConnection != null && streamConnection.f();
    }

    void v() {
        StatManager b2;
        StringBuilder sb;
        String str;
        if (PushSettingsUtil.b("push_notification_state")) {
            return;
        }
        PushSettingsUtil.a("push_notification_state");
        if (PushPermissionUtils.a(ContextHolder.getAppContext())) {
            b2 = StatManager.b();
            sb = new StringBuilder();
            str = "CTPU004_";
        } else {
            b2 = StatManager.b();
            sb = new StringBuilder();
            str = "CTPU005_";
        }
        sb.append(str);
        sb.append(DeviceUtilsF.ak());
        sb.append(com.xiaomi.mipush.sdk.Constants.ACCEPT_TIME_SEPARATOR_SERVER);
        sb.append(DeviceUtilsF.K());
        b2.a(sb.toString(), 1, false);
    }

    public IBinder w() {
        return this.G;
    }

    void x() {
        try {
            long b2 = b(ContextHolder.getAppContext());
            long currentTimeMillis = System.currentTimeMillis() - b2;
            if (b2 > 0 && currentTimeMillis > com.xiaomi.mipush.sdk.Constants.ASSEMBLE_PUSH_NETWORK_INTERVAL) {
                this.B = currentTimeMillis / 1000;
            }
            Date date = new Date(System.currentTimeMillis());
            this.C = (date.getHours() * 60) + date.getMinutes();
            long currentTimeMillis2 = System.currentTimeMillis();
            long elapsedRealtime = SystemClock.elapsedRealtime();
            long j = currentTimeMillis2 - elapsedRealtime;
            long b3 = TWSettingManager.a().b("key_service_last_start_time", 0L);
            if (b3 != 0 && j > b3 && elapsedRealtime > 270000) {
                PushEventReporter.e();
            }
            TWSettingManager.a().a("key_service_last_start_time", currentTimeMillis2);
        } catch (Exception unused) {
        }
    }

    public void y() {
        this.n.obtainMessage(3, 0, 4).sendToTarget();
    }
}