1 /******************************************************************
\r
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
19 ******************************************************************/
\r
21 package org.iotivity.ca;
\r
23 import android.content.BroadcastReceiver;
\r
24 import android.content.Context;
\r
25 import android.content.Intent;
\r
26 import android.content.IntentFilter;
\r
27 import android.net.ConnectivityManager;
\r
28 import android.net.NetworkInfo;
\r
29 import android.net.wifi.WifiManager;
\r
31 public class CaIpInterface {
\r
32 private static Context mContext;
\r
34 private CaIpInterface(Context context) {
\r
36 registerIpStateReceiver();
\r
39 private void registerIpStateReceiver() {
\r
40 IntentFilter intentFilter = new IntentFilter();
\r
41 intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
\r
42 intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
\r
44 mContext.registerReceiver(mReceiver, intentFilter);
\r
47 private static BroadcastReceiver mReceiver = new BroadcastReceiver() {
\r
49 public void onReceive(Context context, Intent intent) {
\r
50 if (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
\r
51 WifiManager.WIFI_STATE_UNKNOWN) == WifiManager.WIFI_STATE_DISABLED) {
\r
52 caIpStateDisabled();
\r
53 } else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
\r
54 ConnectivityManager manager = (ConnectivityManager)
\r
55 mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
\r
56 NetworkInfo nwInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
\r
58 if(nwInfo.isConnected()) {
\r
65 private native static void caIpStateEnabled();
\r
67 private native static void caIpStateDisabled();
\r