package epson.server.utils;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.Message;
import epson.print.Util.EPLog;
import epson.print.Util.Utils;

public class NetworkConnectivityListener {
    public static final int CREATE_DIALOG = 1;
    private static final int DOWNLOAD_FINISH = 4;
    /* access modifiers changed from: private */
    public boolean isOnline;
    /* access modifiers changed from: private */
    public Handler mActivityHandler;
    private Context mContext;
    private boolean mListening;
    private ConnectivityBroadcastReceiver mReceiver = new ConnectivityBroadcastReceiver();

    public NetworkConnectivityListener(Handler handler) {
        this.mActivityHandler = handler;
    }

    private class ConnectivityBroadcastReceiver extends BroadcastReceiver {
        private ConnectivityBroadcastReceiver() {
        }

        public void onReceive(Context context, Intent intent) {
            if (Utils.getInstance().isNetworkAvailable(context)) {
                boolean unused = NetworkConnectivityListener.this.isOnline = true;
                EPLog.m307e("ConnectivityBroadcastReceiver:  ", "===========OKKKKKKKKKKKKKKKKKKKK");
                return;
            }
            boolean unused2 = NetworkConnectivityListener.this.isOnline = false;
            cancelDownload();
            EPLog.m307e("ConnectivityBroadcastReceiver:  ", "============FALSEEEEEEEEEEEEEEEEE");
        }

        private void cancelDownload() {
            NetworkConnectivityListener.this.mActivityHandler.sendEmptyMessage(4);
            Message message = new Message();
            message.what = 1;
            message.arg1 = 1;
            NetworkConnectivityListener.this.mActivityHandler.sendMessage(message);
            NetworkConnectivityListener.this.stopListening();
        }
    }

    public synchronized void startListening(Context context) {
        if (!this.mListening) {
            this.mContext = context;
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
            context.registerReceiver(this.mReceiver, intentFilter);
            this.mListening = true;
        }
    }

    public synchronized void stopListening() {
        if (this.mListening) {
            this.mContext.unregisterReceiver(this.mReceiver);
            this.mContext = null;
            this.mListening = false;
        }
    }

    public boolean getIsOnline() {
        return this.isOnline;
    }
}
