android: Apply configured server port
[strongswan.git] / src / frontends / android / src / org / strongswan / android / logic / NetworkManager.java
1 /*
2 * Copyright (C) 2012-2013 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 package org.strongswan.android.logic;
17
18 import android.content.BroadcastReceiver;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.content.IntentFilter;
22 import android.net.ConnectivityManager;
23 import android.net.NetworkInfo;
24
25 public class NetworkManager extends BroadcastReceiver
26 {
27 private final Context mContext;
28 private boolean mRegistered;
29
30 public NetworkManager(Context context)
31 {
32 mContext = context;
33 }
34
35 public void Register()
36 {
37 mContext.registerReceiver(this, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
38 }
39
40 public void Unregister()
41 {
42 mContext.unregisterReceiver(this);
43 }
44
45 @Override
46 public void onReceive(Context context, Intent intent)
47 {
48 ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
49 NetworkInfo info = cm.getActiveNetworkInfo();
50 networkChanged(info == null || !info.isConnected());
51 }
52
53 /**
54 * Notify the native parts about a network change
55 *
56 * @param disconnected true if no connection is available at the moment
57 */
58 public native void networkChanged(boolean disconnected);
59 }