1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 package org.iotivity.ca;
23 import android.content.BroadcastReceiver;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.content.IntentFilter;
27 import android.net.ConnectivityManager;
28 import android.net.NetworkInfo;
29 import android.net.wifi.WifiManager;
31 public class CaIpInterface {
32 private static Context mContext;
34 private CaIpInterface(Context context) {
36 registerIpStateReceiver();
39 private void registerIpStateReceiver() {
40 IntentFilter intentFilter = new IntentFilter();
41 intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
42 intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
44 mContext.registerReceiver(mReceiver, intentFilter);
47 public static void destroyIpInterface() {
48 mContext.unregisterReceiver(mReceiver);
51 private static BroadcastReceiver mReceiver = new BroadcastReceiver() {
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) {
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);
62 if(nwInfo.isConnected()) {
69 private native static void caIpStateEnabled();
71 private native static void caIpStateDisabled();