/*
- * Copyright (C) 2012-2013 Tobias Brunner
+ * Copyright (C) 2012-2015 Tobias Brunner
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
this->connectivity_cb.cb = cb;
this->connectivity_cb.data = data;
}
- androidjni_detach_thread();
}
+ androidjni_detach_thread();
}
this->mutex->unlock(this->mutex);
}
this->mutex->unlock(this->mutex);
}
+METHOD(network_manager_t, is_connected, bool,
+ private_network_manager_t *this)
+{
+ JNIEnv *env;
+ jmethodID method_id;
+ bool connected = FALSE;
+
+ androidjni_attach_thread(&env);
+ method_id = (*env)->GetMethodID(env, this->cls, "isConnected", "()Z");
+ if (!method_id)
+ {
+ androidjni_exception_occurred(env);
+ }
+ else
+ {
+ connected = (*env)->CallBooleanMethod(env, this->obj, method_id);
+ connected = !androidjni_exception_occurred(env) && connected;
+ }
+ androidjni_detach_thread();
+ return connected;
+}
+
METHOD(network_manager_t, destroy, void,
private_network_manager_t *this)
{
.public = {
.add_connectivity_cb = _add_connectivity_cb,
.remove_connectivity_cb = _remove_connectivity_cb,
+ .is_connected = _is_connected,
.destroy = _destroy,
},
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
/*
- * Copyright (C) 2012-2013 Tobias Brunner
+ * Copyright (C) 2012-2015 Tobias Brunner
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
void (*remove_connectivity_cb)(network_manager_t *this,
connectivity_cb_t cb);
+ /**
+ * Check whether we currently have connectivity
+ *
+ * @return TRUE if currently connected
+ */
+ bool (*is_connected)(network_manager_t *this);
+
/**
* Destroy a network_manager_t instance
*/
/*
- * Copyright (C) 2012-2013 Tobias Brunner
+ * Copyright (C) 2012-2015 Tobias Brunner
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
mContext.unregisterReceiver(this);
}
+ public boolean isConnected()
+ {
+ ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo info = null;
+ if (cm != null)
+ {
+ info = cm.getActiveNetworkInfo();
+ }
+ return info != null && info.isConnected();
+ }
+
@Override
public void onReceive(Context context, Intent intent)
{
- ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
- NetworkInfo info = cm.getActiveNetworkInfo();
- networkChanged(info == null || !info.isConnected());
+ networkChanged(!isConnected());
}
/**