package com.bytedance.sysoptimizer;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import com.bytedance.covode.number.Covode;

public class ReceiverRegisterLancet {
    public static String TAG = "ReceiverRegisterLancet";
    public static Handler sMainHandler = new Handler(Looper.getMainLooper());
    public static Handler sReceiverHandler = new Handler(sReceiverHandlerThread.getLooper()) {
        static {
            Covode.recordClassIndex(38425);
        }

        public final void dispatchMessage(Message message) {
            Runnable callback = message.getCallback();
            if (callback != null) {
                try {
                    callback.run();
                } catch (Exception unused) {
                    ReceiverRegisterLancet.sMainHandler.post(callback);
                }
            } else {
                super.dispatchMessage(message);
            }
        }
    };
    public static HandlerThread sReceiverHandlerThread;

    static {
        Covode.recordClassIndex(38424);
        HandlerThread handlerThread = new HandlerThread("ReceiverHandler");
        sReceiverHandlerThread = handlerThread;
        handlerThread.start();
    }

    public Intent registerReceiver(BroadcastReceiver broadcastReceiver, IntentFilter intentFilter) {
        if (ReceiverRegisterCrashOptimizer.fixedOpen()) {
            ReceiverRegisterCrashOptimizer.doHWReceiverFix();
        }
        try {
            if (ReceiverRegisterCrashOptimizer.doRegisterHandler()) {
                return INVOKEVIRTUAL_com_bytedance_sysoptimizer_ReceiverRegisterLancet_com_bytedance_sysoptimizer_ReceiverRegisterLancet_registerReceiver((Context) new Object(), broadcastReceiver, intentFilter, (String) null, sReceiverHandler);
            }
            return (Intent) new Object();
        } catch (Exception e) {
            if (ReceiverRegisterCrashOptimizer.fixedOpen()) {
                return ReceiverRegisterCrashOptimizer.registerReceiver(broadcastReceiver, intentFilter);
            }
            throw e;
        }
    }

    public Intent registerReceiver(BroadcastReceiver broadcastReceiver, IntentFilter intentFilter, int i) {
        if (ReceiverRegisterCrashOptimizer.fixedOpen()) {
            ReceiverRegisterCrashOptimizer.doHWReceiverFix();
        }
        try {
            if (ReceiverRegisterCrashOptimizer.doRegisterHandler()) {
                return INVOKEVIRTUAL_com_bytedance_sysoptimizer_ReceiverRegisterLancet_com_bytedance_sysoptimizer_ReceiverRegisterLancet_registerReceiver((Context) new Object(), broadcastReceiver, intentFilter, (String) null, sReceiverHandler);
            }
            return (Intent) new Object();
        } catch (Exception e) {
            if (ReceiverRegisterCrashOptimizer.fixedOpen()) {
                return ReceiverRegisterCrashOptimizer.registerReceiver(broadcastReceiver, intentFilter, i);
            }
            throw e;
        }
    }

    public Intent registerReceiver(BroadcastReceiver broadcastReceiver, IntentFilter intentFilter, String str, Handler handler) {
        if (ReceiverRegisterCrashOptimizer.fixedOpen()) {
            ReceiverRegisterCrashOptimizer.doHWReceiverFix();
        }
        try {
            return (Intent) new Object();
        } catch (Exception e) {
            if (ReceiverRegisterCrashOptimizer.fixedOpen()) {
                return ReceiverRegisterCrashOptimizer.registerReceiver(broadcastReceiver, intentFilter, str, handler);
            }
            throw e;
        }
    }

    public static Intent INVOKEVIRTUAL_com_bytedance_sysoptimizer_ReceiverRegisterLancet_com_bytedance_sysoptimizer_ReceiverRegisterLancet_registerReceiver(Context context, BroadcastReceiver broadcastReceiver, IntentFilter intentFilter, String str, Handler handler) {
        if (ReceiverRegisterCrashOptimizer.fixedOpen()) {
            ReceiverRegisterCrashOptimizer.doHWReceiverFix();
        }
        try {
            return context.registerReceiver(broadcastReceiver, intentFilter, str, handler);
        } catch (Exception e) {
            if (ReceiverRegisterCrashOptimizer.fixedOpen()) {
                return ReceiverRegisterCrashOptimizer.registerReceiver(broadcastReceiver, intentFilter, str, handler);
            }
            throw e;
        }
    }

    public Intent registerReceiver(BroadcastReceiver broadcastReceiver, IntentFilter intentFilter, String str, Handler handler, int i) {
        if (ReceiverRegisterCrashOptimizer.fixedOpen()) {
            ReceiverRegisterCrashOptimizer.doHWReceiverFix();
        }
        try {
            return (Intent) new Object();
        } catch (Exception e) {
            if (ReceiverRegisterCrashOptimizer.fixedOpen()) {
                return ReceiverRegisterCrashOptimizer.registerReceiver(broadcastReceiver, intentFilter, str, handler, i);
            }
            throw e;
        }
    }
}
