package com.tencent.mm.booter;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.google.android.gms.common.util.CrashUtils.ErrorDialogData;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.kernel.a;
import com.tencent.mm.kernel.k;
import com.tencent.mm.network.aa;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.af;
import com.tencent.mm.sdk.platformtools.al;

@k
public class MMReceivers$AlarmReceiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
        AppMethodBeat.i(57767);
        if (context == null || intent == null) {
            AppMethodBeat.o(57767);
            return;
        }
        if (!a.Mz().getBoolean("keepaliveserviceswitch", false)) {
            ab.i("MicroMsg.AlarmReceiver", "onReceive() MMHandlerThread() publish PushKeepAliveEvent");
            al.n(new 1(this), 10000);
        }
        boolean booleanExtra = intent.getBooleanExtra("MMBoot_Bump", false);
        ab.i("MicroMsg.AlarmReceiver", "[ALARM NOTIFICATION] bump:".concat(String.valueOf(booleanExtra)));
        if (booleanExtra) {
            bp(context);
            AppMethodBeat.o(57767);
            return;
        }
        if (!b.c(context, "alarm", true)) {
            bs(context);
            ab.dot();
        }
        AppMethodBeat.o(57767);
    }

    public static void bp(Context context) {
        long j = 30000;
        AppMethodBeat.i(57768);
        long dov = af.dov();
        ab.d("MicroMsg.AlarmReceiver", "bumper comes, next=".concat(String.valueOf(dov)));
        if (dov > 1860000) {
            AppMethodBeat.o(57768);
            return;
        }
        if (dov >= 30000) {
            j = dov;
        }
        a(j, context);
        AppMethodBeat.o(57768);
    }

    private static void a(long j, Context context) {
        AppMethodBeat.i(57769);
        ab.w("MicroMsg.AlarmReceiver", "reset bumper, interval=".concat(String.valueOf(j)));
        AlarmManager alarmManager = (AlarmManager) context.getSystemService("alarm");
        if (alarmManager == null) {
            ab.e("MicroMsg.AlarmReceiver", "keep bumper failed, null am");
            AppMethodBeat.o(57769);
            return;
        }
        alarmManager.set(0, System.currentTimeMillis() + j, PendingIntent.getBroadcast(context, 1, new Intent(context, MMReceivers$AlarmReceiver.class).putExtra("MMBoot_Bump", true), ErrorDialogData.BINDER_CRASH));
        AppMethodBeat.o(57769);
    }

    public static void bq(Context context) {
        AppMethodBeat.i(57770);
        AlarmManager alarmManager = (AlarmManager) context.getSystemService("alarm");
        if (alarmManager == null) {
            ab.e("MicroMsg.AlarmReceiver", "stop bumper failed, null am");
            AppMethodBeat.o(57770);
            return;
        }
        PendingIntent broadcast = PendingIntent.getBroadcast(context, 1, new Intent(context, MMReceivers$AlarmReceiver.class).putExtra("MMBoot_Bump", true), ErrorDialogData.DYNAMITE_CRASH);
        if (broadcast != null) {
            alarmManager.cancel(broadcast);
            broadcast.cancel();
        }
        AppMethodBeat.o(57770);
    }

    public static void br(Context context) {
        AppMethodBeat.i(57771);
        ab.w("MicroMsg.AlarmReceiver", "keep awaker");
        AlarmManager alarmManager = (AlarmManager) context.getSystemService("alarm");
        if (alarmManager == null) {
            ab.e("MicroMsg.AlarmReceiver", "keep awaker failed, null am");
            AppMethodBeat.o(57771);
            return;
        }
        int i = aa.anj() ? 300000 : 900000;
        alarmManager.setRepeating(0, System.currentTimeMillis() + ((long) i), (long) i, PendingIntent.getBroadcast(context, 0, new Intent(context, MMReceivers$AlarmReceiver.class), ErrorDialogData.BINDER_CRASH));
        AppMethodBeat.o(57771);
    }

    public static void bs(Context context) {
        AppMethodBeat.i(57772);
        ab.w("MicroMsg.AlarmReceiver", "stop awaker");
        AlarmManager alarmManager = (AlarmManager) context.getSystemService("alarm");
        if (alarmManager == null) {
            ab.e("MicroMsg.AlarmReceiver", "keep awaker failed, null am");
            AppMethodBeat.o(57772);
            return;
        }
        PendingIntent broadcast = PendingIntent.getBroadcast(context, 0, new Intent(context, MMReceivers$AlarmReceiver.class), ErrorDialogData.DYNAMITE_CRASH);
        if (broadcast != null) {
            alarmManager.cancel(broadcast);
            broadcast.cancel();
        }
        AppMethodBeat.o(57772);
    }
}
