package org.msf.records.diagnostics;

import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;

/**
 * A {@link HealthCheck} that checks whether the current device is connected
 * to a wifi network.
 */
public class WifiHealthCheck extends HealthCheck {

    private static final IntentFilter sWifiStateChangedIntentFilter =
            getIntentFilter();

    private final WifiManager mWifiManager;
    private final ConnectivityManager mConnectivityManager;
    private final WifiChangeBroadcastReceiver mWifiStateChangedReceiver;

    protected WifiHealthCheck(Application application) {
        super(application);

        mWifiManager = (WifiManager) application.getSystemService(Context.WIFI_SERVICE);
        mConnectivityManager =
                (ConnectivityManager) application.getSystemService(Context.CONNECTIVITY_SERVICE);
        mWifiStateChangedReceiver = new WifiChangeBroadcastReceiver();
    }

    @Override
    protected void startImpl() {
        mApplication.registerReceiver(mWifiStateChangedReceiver, sWifiStateChangedIntentFilter);

        checkWifiState();
    }

    @Override
    protected void stopImpl() {
        mApplication.unregisterReceiver(mWifiStateChangedReceiver);
    }

    private static IntentFilter getIntentFilter() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);

        return intentFilter;
    }

    private void checkWifiState() {
        int wifiState = mWifiManager.getWifiState();
        if (wifiState != WifiManager.WIFI_STATE_ENABLING
                && wifiState != WifiManager.WIFI_STATE_ENABLED) {
            reportIssue(HealthIssue.WIFI_DISABLED);
        } else {
            resolveIssue(HealthIssue.WIFI_DISABLED);
            NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo();
            if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
                reportIssue(HealthIssue.WIFI_NOT_CONNECTED);
            } else {
                resolveAllIssues();
            }
        }
    }

    private class WifiChangeBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            checkWifiState();
        }
    }

    public boolean isApiUnavailable() {
        // We will get an event that lets us update the set of active issues whenever
        // the wifi state changes, so we can be confident that the API is definitely
        // unavailable whenever either of the wifi-related issues is active.
        return mActiveIssues.contains(HealthIssue.WIFI_NOT_CONNECTED) ||
                mActiveIssues.contains(HealthIssue.WIFI_DISABLED);
    }
}

@@ -2570,24 +2570,38 @@
    %7D%0A    %7D%0A%0A
+    @Override%0A
     public b
@@ -2945,19 +2945,16 @@
 NNECTED)
- %7C%7C
 %0A       
@@ -2961,16 +2961,19 @@
         
+ %7C%7C
  mActive

Fix lint issue.