// Path: opfpush/src/main/java/org/onepf/opfpush/ConnectivityChangeReceiver.java
// public final class ConnectivityChangeReceiver extends BroadcastReceiver {
// 
//     @Override
//     public void onReceive(@NonNull final Context context, @NonNull final Intent intent) {
//         OPFLog.logMethod(context, OPFUtils.toString(intent));
// 
//         final Set<Pair<String, String>> retryProvidersActions = RetryManager.getInstance()
//                 .getRetryProvidersActions();
// 
//         final OPFPushHelper helper = OPFPush.getHelper();
//         for (Pair<String, String> retryProviderAction : retryProvidersActions) {
//             final String providerName = retryProviderAction.first;
//             final String action = retryProviderAction.second;
//             switch (action) {
//                 case ACTION_RETRY_REGISTER:
//                     helper.register(providerName);
//                     break;
//                 case ACTION_RETRY_UNREGISTER:
//                     helper.unregister(providerName);
//                     break;
//             }
//         }
//     }
// }
// 
// Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java
// public final class RetryBroadcastReceiver extends BroadcastReceiver {
// 
//     @Override
//     public void onReceive(@NonNull final Context context, @NonNull final Intent intent) {
//         OPFLog.logMethod(context, OPFUtils.toString(intent));
// 
//         final OPFPushHelper helper = OPFPush.getHelper();
//         if (helper.isInitDone()) {
//             OPFLog.d("Initialisation is done");
// 
//             final String action = intent.getAction();
//             final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME);
//             switch (action) {
//                 case ACTION_RETRY_REGISTER:
//                     helper.register(providerName);
//                     break;
//                 case ACTION_RETRY_UNREGISTER:
//                     helper.unregister(providerName);
//                     break;
//                 case ACTION_CHECK_REGISTERING_TIMEOUT:
//                     checkRegistering(context, helper, providerName);
//                     break;
//                 default:
//                     throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action));
//             }
//         } else {
//             OPFLog.w("OPFPush must be initialized");
//         }
//     }
// 
//     private void checkRegistering(@NonNull final Context context,
//                                   @NonNull final OPFPushHelper helper,
//                                   @NonNull final String providerName) {
//         OPFLog.logMethod(context, helper, providerName);
//         if (helper.isRegistering()) {
//             Settings.getInstance(context).saveState(State.UNREGISTERED);
//             helper.registerNextAvailableProvider(providerName);
//         }
//     }
// }
// 
// Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java
// public enum Operation {
//     REGISTER,
//     UNREGISTER
// }
// 
// Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java
// public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER";
// 
// Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java
// public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER";
// 
// Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java
// public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME";


import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Pair;
import org.onepf.opfpush.ConnectivityChangeReceiver;
import org.onepf.opfpush.RetryBroadcastReceiver;
import org.onepf.opfpush.model.Operation;
import org.onepf.opfutils.OPFChecks;
import org.onepf.opfutils.OPFLog;
import org.onepf.opfutils.exception.InitException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import static android.content.Context.ALARM_SERVICE;
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER;
import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER;
import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME;
import static org.onepf.opfpush.model.Operation.REGISTER;
import static org.onepf.opfpush.model.Operation.UNREGISTER;
        final boolean isInit = instance != null;
        if (initExpected != isInit) {
            throw new InitException(isInit);
        }
    }

    @Override
    public boolean hasTries(@NonNull final String providerName,
                            @NonNull final Operation operation) {
        return backoffManager.hasTries(providerName, operation);
    }

    @Override
    public long getTryDelay(@NonNull final String providerName,
                            @NonNull final Operation operation) {
        return backoffManager.getTryDelay(providerName, operation);
    }

    @Override
    public void reset(@NonNull final String providerName, @NonNull final Operation operation) {
        backoffManager.reset(providerName, operation);
    }

    public void postRetryRegister(@NonNull final String providerName) {
        OPFLog.logMethod(providerName);
        postRetry(providerName, REGISTER, ACTION_RETRY_REGISTER);
    }

    public void postRetryUnregister(@NonNull final String providerName) {
        OPFLog.logMethod(providerName);
// Path: opfpush/src/main/java/org/onepf/opfpush/ConnectivityChangeReceiver.java
// public final class ConnectivityChangeReceiver extends BroadcastReceiver {
// 
//     @Override
//     public void onReceive(@NonNull final Context context, @NonNull final Intent intent) {
//         OPFLog.logMethod(context, OPFUtils.toString(intent));
// 
//         final Set<Pair<String, String>> retryProvidersActions = RetryManager.getInstance()
//                 .getRetryProvidersActions();
// 
//         final OPFPushHelper helper = OPFPush.getHelper();
//         for (Pair<String, String> retryProviderAction : retryProvidersActions) {
//             final String providerName = retryProviderAction.first;
//             final String action = retryProviderAction.second;
//             switch (action) {
//                 case ACTION_RETRY_REGISTER:
//                     helper.register(providerName);
//                     break;
//                 case ACTION_RETRY_UNREGISTER:
//                     helper.unregister(providerName);
//                     break;
//             }
//         }
//     }
// }
// 
// Path: opfpush/src/main/java/org/onepf/opfpush/RetryBroadcastReceiver.java
// public final class RetryBroadcastReceiver extends BroadcastReceiver {
// 
//     @Override
//     public void onReceive(@NonNull final Context context, @NonNull final Intent intent) {
//         OPFLog.logMethod(context, OPFUtils.toString(intent));
// 
//         final OPFPushHelper helper = OPFPush.getHelper();
//         if (helper.isInitDone()) {
//             OPFLog.d("Initialisation is done");
// 
//             final String action = intent.getAction();
//             final String providerName = intent.getStringExtra(EXTRA_PROVIDER_NAME);
//             switch (action) {
//                 case ACTION_RETRY_REGISTER:
//                     helper.register(providerName);
//                     break;
//                 case ACTION_RETRY_UNREGISTER:
//                     helper.unregister(providerName);
//                     break;
//                 case ACTION_CHECK_REGISTERING_TIMEOUT:
//                     checkRegistering(context, helper, providerName);
//                     break;
//                 default:
//                     throw new IllegalStateException(String.format(Locale.US, "Unknown action '%s'.", action));
//             }
//         } else {
//             OPFLog.w("OPFPush must be initialized");
//         }
//     }
// 
//     private void checkRegistering(@NonNull final Context context,
//                                   @NonNull final OPFPushHelper helper,
//                                   @NonNull final String providerName) {
//         OPFLog.logMethod(context, helper, providerName);
//         if (helper.isRegistering()) {
//             Settings.getInstance(context).saveState(State.UNREGISTERED);
//             helper.registerNextAvailableProvider(providerName);
//         }
//     }
// }
// 
// Path: opfpush/src/main/java/org/onepf/opfpush/model/Operation.java
// public enum Operation {
//     REGISTER,
//     UNREGISTER
// }
// 
// Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java
// public static final String ACTION_RETRY_REGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_REGISTER";
// 
// Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java
// public static final String ACTION_RETRY_UNREGISTER = BuildConfig.APPLICATION_ID + "intent.RETRY_UNREGISTER";
// 
// Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java
// public static final String EXTRA_PROVIDER_NAME = "org.onepf.opfpush.intent.EXTRA_PROVIDER_NAME";


// Path: opfpush/src/main/java/org/onepf/opfpush/backoff/RetryManager.java
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Pair;
import org.onepf.opfpush.ConnectivityChangeReceiver;
import org.onepf.opfpush.RetryBroadcastReceiver;
import org.onepf.opfpush.model.Operation;
import org.onepf.opfutils.OPFChecks;
import org.onepf.opfutils.OPFLog;
import org.onepf.opfutils.exception.InitException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import static android.content.Context.ALARM_SERVICE;
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER;
import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER;
import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME;
import static org.onepf.opfpush.model.Operation.REGISTER;
import static org.onepf.opfpush.model.Operation.UNREGISTER;

        final boolean isInit = instance != null;
        if (initExpected != isInit) {
            throw new InitException(isInit);
        }
    }

    @Override
    public boolean hasTries(@NonNull final String providerName,
                            @NonNull final Operation operation) {
        return backoffManager.hasTries(providerName, operation);
    }

    @Override
    public long getTryDelay(@NonNull final String providerName,
                            @NonNull final Operation operation) {
        return backoffManager.getTryDelay(providerName, operation);
    }

    @Override
    public void reset(@NonNull final String providerName, @NonNull final Operation operation) {
        backoffManager.reset(providerName, operation);
    }

    public void postRetryRegister(@NonNull final String providerName) {
        OPFLog.logMethod(providerName);
        postRetry(providerName, REGISTER, ACTION_RETRY_REGISTER);
    }

    public void postRetryUnregister(@NonNull final String providerName) {
        OPFLog.logMethod(providerName);
        postRetry(providerName, UNREGISTER, ACTION_RETRY_UNREGISTER);