Clean up some SonarQube warnings (trailing whitespace, etc).
[platform/upstream/iotivity.git] / android / android_api / base / src / main / java / org / iotivity / ca / CaWiFiInterface.java
1 /*
2  * //******************************************************************
3  * //
4  * // Copyright 2015 Intel Corporation.
5  * //
6  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7  * //
8  * // Licensed under the Apache License, Version 2.0 (the "License");
9  * // you may not use this file except in compliance with the License.
10  * // You may obtain a copy of the License at
11  * //
12  * //      http://www.apache.org/licenses/LICENSE-2.0
13  * //
14  * // Unless required by applicable law or agreed to in writing, software
15  * // distributed under the License is distributed on an "AS IS" BASIS,
16  * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * // See the License for the specific language governing permissions and
18  * // limitations under the License.
19  * //
20  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22
23 package org.iotivity.ca;
24
25 import android.content.BroadcastReceiver;
26 import android.content.Context;
27 import android.content.Intent;
28 import android.content.IntentFilter;
29 import android.net.ConnectivityManager;
30 import android.net.NetworkInfo;
31 import android.net.wifi.WifiManager;
32
33 public class CaWiFiInterface {
34
35     private static Context mContext;
36
37     private CaWiFiInterface(Context context) {
38         mContext = context;
39         registerWiFiStateReceiver();
40     }
41
42     private void registerWiFiStateReceiver() {
43         IntentFilter intentFilter = new IntentFilter();
44         intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
45         intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
46
47         mContext.registerReceiver(mReceiver, intentFilter);
48     }
49
50     private static BroadcastReceiver mReceiver = new BroadcastReceiver() {
51
52         @Override
53         public void onReceive(Context context, Intent intent) {
54             if (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
55                     WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_DISABLED) {
56                 CAWiFiStateDisabled();
57             } else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
58                 ConnectivityManager manager = (ConnectivityManager)
59                         mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
60                 NetworkInfo nwInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
61
62                 if (nwInfo.isConnected()) {
63                     CAWiFiStateEnabled();
64                 }
65             }
66         }
67     };
68
69     private native static void CAWiFiStateEnabled();
70
71     private native static void CAWiFiStateDisabled();
72 }