// Path: opfpush/src/main/java/org/onepf/opfpush/model/State.java
// public enum State {
// 
//     /**
//      * Indicates that an unregistration has been completed.
//      */
//     UNREGISTERED(0),
// 
//     /**
//      * Indicates that a registration has been completed.
//      */
//     REGISTERED(2),
// 
//     /**
//      * Indicates that a registration is being performed.
//      */
//     REGISTERING(3);
// 
//     private int value;
// 
//     State(int value) {
//         this.value = value;
//     }
// 
//     public int getValue() {
//         return value;
//     }
// 
//     @Nullable
//     public static State fromValue(final int fromValue) {
//         final State[] values = values();
//         for (final State state : values) {
//             final int stateValue = state.getValue();
//             if (stateValue == fromValue) {
//                 return state;
//             }
//         }
// 
//         return null;
//     }
// }
// 
// Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java
// static final String ACTION_CHECK_REGISTERING_TIMEOUT = BuildConfig.APPLICATION_ID + "intent.CHECK_REGISTERING_TIMEOUT";
// 
// 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 static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import org.onepf.opfpush.model.State;
import org.onepf.opfutils.OPFLog;
import org.onepf.opfutils.OPFUtils;
import java.util.Locale;
import static org.onepf.opfpush.OPFConstants.ACTION_CHECK_REGISTERING_TIMEOUT;
import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER;
import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER;

        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()) {
// Path: opfpush/src/main/java/org/onepf/opfpush/model/State.java
// public enum State {
// 
//     /**
//      * Indicates that an unregistration has been completed.
//      */
//     UNREGISTERED(0),
// 
//     /**
//      * Indicates that a registration has been completed.
//      */
//     REGISTERED(2),
// 
//     /**
//      * Indicates that a registration is being performed.
//      */
//     REGISTERING(3);
// 
//     private int value;
// 
//     State(int value) {
//         this.value = value;
//     }
// 
//     public int getValue() {
//         return value;
//     }
// 
//     @Nullable
//     public static State fromValue(final int fromValue) {
//         final State[] values = values();
//         for (final State state : values) {
//             final int stateValue = state.getValue();
//             if (stateValue == fromValue) {
//                 return state;
//             }
//         }
// 
//         return null;
//     }
// }
// 
// Path: opfpush/src/main/java/org/onepf/opfpush/OPFConstants.java
// static final String ACTION_CHECK_REGISTERING_TIMEOUT = BuildConfig.APPLICATION_ID + "intent.CHECK_REGISTERING_TIMEOUT";
// 
// 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/RetryBroadcastReceiver.java
import static org.onepf.opfpush.OPFConstants.EXTRA_PROVIDER_NAME;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import org.onepf.opfpush.model.State;
import org.onepf.opfutils.OPFLog;
import org.onepf.opfutils.OPFUtils;
import java.util.Locale;
import static org.onepf.opfpush.OPFConstants.ACTION_CHECK_REGISTERING_TIMEOUT;
import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_REGISTER;
import static org.onepf.opfpush.OPFConstants.ACTION_RETRY_UNREGISTER;


        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);