// Path: app/src/main/java/io/github/mobodev/heartbeatfixerforgcm/utils/DeviceUtils.java
// public class DeviceUtils {
//     private DeviceUtils() {}
// 
//     public static boolean hasHoneycomb() {
//         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
//     }
// 
//     public static boolean hasKitkat() {
//         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
//     }
// 
//     public static boolean hasLollipop() {
//         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
//     }
// }


import android.annotation.TargetApi;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.preference.PreferenceManager;
import android.text.format.DateFormat;
import android.util.Log;
import io.github.mobodev.heartbeatfixerforgcm.utils.DeviceUtils;
            return;
        }
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) {
            if (!fromNetworkStateChange || sNetworkState != NetworkState.CONNECTED) {
                sNetworkState = NetworkState.CONNECTED;
                int intervalMillis;
                if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                    intervalMillis = getHeartbeatIntervalMillisForWifi(context);
                } else {
                    intervalMillis = getHeartbeatIntervalMillisForMobile(context);
                }
                setNextHeartbeatRequest(context, intervalMillis);
            }
        } else {
            if (!fromNetworkStateChange || sNetworkState != NetworkState.DISCONNECTED) {
                sNetworkState = NetworkState.DISCONNECTED;
                cancelHeartbeatRequest(context);
            }
        }
    }

    @TargetApi(Build.VERSION_CODES.KITKAT)
    private static void setNextHeartbeatRequest(Context context, int intervalMillis) {
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        long triggerAtMillis = System.currentTimeMillis() + intervalMillis;
        Log.d(TAG, "setNextHeartbeatRequest at: " + DateFormat.format("yyyy-MM-dd hh:mm:ss", triggerAtMillis));
        PendingIntent broadcastPendingIntent = getBroadcastPendingIntent(context);
        int rtcWakeup = AlarmManager.RTC_WAKEUP;
// Path: app/src/main/java/io/github/mobodev/heartbeatfixerforgcm/utils/DeviceUtils.java
// public class DeviceUtils {
//     private DeviceUtils() {}
// 
//     public static boolean hasHoneycomb() {
//         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
//     }
// 
//     public static boolean hasKitkat() {
//         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
//     }
// 
//     public static boolean hasLollipop() {
//         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
//     }
// }


// Path: app/src/main/java/io/github/mobodev/heartbeatfixerforgcm/HeartbeatFixerUtils.java
import android.annotation.TargetApi;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.preference.PreferenceManager;
import android.text.format.DateFormat;
import android.util.Log;
import io.github.mobodev.heartbeatfixerforgcm.utils.DeviceUtils;

            return;
        }
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) {
            if (!fromNetworkStateChange || sNetworkState != NetworkState.CONNECTED) {
                sNetworkState = NetworkState.CONNECTED;
                int intervalMillis;
                if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                    intervalMillis = getHeartbeatIntervalMillisForWifi(context);
                } else {
                    intervalMillis = getHeartbeatIntervalMillisForMobile(context);
                }
                setNextHeartbeatRequest(context, intervalMillis);
            }
        } else {
            if (!fromNetworkStateChange || sNetworkState != NetworkState.DISCONNECTED) {
                sNetworkState = NetworkState.DISCONNECTED;
                cancelHeartbeatRequest(context);
            }
        }
    }

    @TargetApi(Build.VERSION_CODES.KITKAT)
    private static void setNextHeartbeatRequest(Context context, int intervalMillis) {
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        long triggerAtMillis = System.currentTimeMillis() + intervalMillis;
        Log.d(TAG, "setNextHeartbeatRequest at: " + DateFormat.format("yyyy-MM-dd hh:mm:ss", triggerAtMillis));
        PendingIntent broadcastPendingIntent = getBroadcastPendingIntent(context);
        int rtcWakeup = AlarmManager.RTC_WAKEUP;
        if (DeviceUtils.hasKitkat()) {