CB-6521: Remove development branch

This commit is contained in:
Ian Clelland 2014-04-25 14:09:47 -04:00
parent e0d3ae00b7
commit 10da2b5fea
20 changed files with 2 additions and 2040 deletions

202
LICENSE
View File

@ -1,202 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

5
NOTICE
View File

@ -1,5 +0,0 @@
Apache Cordova
Copyright 2012 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).

View File

@ -20,3 +20,5 @@
# org.apache.cordova.network-information
Plugin documentation: [doc/index.md](doc/index.md)
This is `dev` - the deprecated development branch of this plugin; development of this plugin has moved to the `master` branch

View File

@ -1,55 +0,0 @@
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
-->
# Release Notes
### 0.2.1 (Sept 5, 2013)
* CB-4432 copyright notice change
### 0.2.3 (Sept 25, 2013)
* CB-4889 bumping&resetting version
* [windows8] commandProxy was moved
* CB-4889 renaming org.apache.cordova.core.network-information to org.apache.cordova.network-information
* removed duplicate comment line from plugin.xml
* added Network APIs for FirefoxOS
* Rename CHANGELOG.md -> RELEASENOTES.md
* [CB-4752] Incremented plugin version on dev branch.
### 0.2.4 (Oct 28, 2013)
* CB-5128: add repo + issue tag to plugin.xml for network information plugin
* [CB-4915] Incremented plugin version on dev branch.
### 0.2.5 (Dec 4, 2013)
* [ubuntu] specify policy_group
* add ubuntu platform
* Added amazon-fireos platform. Change to use amazon-fireos as the platform if user agent string contains 'cordova-amazon-fireos'
### 0.2.6 (Jan 02, 2014)
* CB-5658 Add doc/index.md for netinfo plugin
### 0.2.7 (Feb 05, 2014)
* Initial implementation of Tizen plugin.
### 0.2.8 (Apr 17, 2014)
* CB-6342: [iOS] iOS reports a cellular connection even when in Airplane mode
* CB-6422: [windows8] use cordova/exec/proxy
* CB-6460: Update license headers
* CB-6465: Add license headers to Tizen code
* Add NOTICE file

View File

@ -1,190 +0,0 @@
<!---
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# org.apache.cordova.network-information
This plugin provides an implementation of an old version of the
[Network Information API](http://www.w3.org/TR/2011/WD-netinfo-api-20110607/).
It provides information about the device's cellular and
wifi connection, and whether the device has an internet connection.
## Installation
cordova plugin add org.apache.cordova.network-information
## Supported Platforms
- Amazon Fire OS
- Android
- BlackBerry 10
- iOS
- Windows Phone 7 and 8
- Tizen
- Windows 8
# Connection
> The `connection` object, exposed via `navigator.connection`, provides information about the device's cellular and wifi connection.
## Properties
- connection.type
## Constants
- Connection.UNKNOWN
- Connection.ETHERNET
- Connection.WIFI
- Connection.CELL_2G
- Connection.CELL_3G
- Connection.CELL_4G
- Connection.CELL
- Connection.NONE
## connection.type
This property offers a fast way to determine the device's network
connection state, and type of connection.
### Quick Example
function checkConnection() {
var networkState = navigator.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';
alert('Connection type: ' + states[networkState]);
}
checkConnection();
### API Change
Until Cordova 2.3.0, the `Connection` object was accessed via
`navigator.network.connection`, after which it was changed to
`navigator.connection` to match the W3C specification. It's still
available at its original location, but is deprecated and will
eventually be removed.
### iOS Quirks
- iOS can't detect the type of cellular network connection.
- `navigator.connection.type` is set to `Connection.CELL` for all cellular data.
### Windows Phone Quirks
- When running in the emulator, always detects `navigator.connection.type` as `Connection.UNKNOWN`.
- Windows Phone can't detect the type of cellular network connection.
- `navigator.connection.type` is set to `Connection.CELL` for all cellular data.
### Tizen Quirks
- Tizen can only detect a WiFi or cellular connection.
- `navigator.connection.type` is set to `Connection.CELL_2G` for all cellular data.
# Network-related Events
## offline
The event fires when an application goes offline, and the device is
not connected to the Internet.
document.addEventListener("offline", yourCallbackFunction, false);
### Details
The `offline` event fires when a previously connected device loses a
network connection so that an application can no longer access the
Internet. It relies on the same information as the Connection API,
and fires when the `connection.type` changes from `NONE` to any other
value.
Applications typically should use `document.addEventListener` to
attach an event listener once the `deviceready` event fires.
### Quick Example
document.addEventListener("offline", onOffline, false);
function onOffline() {
// Handle the offline event
}
### iOS Quirks
During initial startup, the first offline event (if applicable) takes at least a second to fire.
### Windows Phone 7 Quirks
When running in the Emulator, the `connection.status` is always unknown, so this event does _not_ fire.
### Windows Phone 8 Quirks
The Emulator reports the connection type as `Cellular`, which does not change, so the event does _not_ fire.
## online
This event fires when an application goes online, and the device
becomes connected to the Internet.
document.addEventListener("online", yourCallbackFunction, false);
### Details
The `online` event fires when a previously unconnected device receives
a network connection to allow an application access to the Internet.
It relies on the same information as the Connection API, and fires
when the value of `connection.type` becomes `NONE`.
Applications typically should use `document.addEventListener` to
attach an event listener once the `deviceready` event fires.
### Quick Example
document.addEventListener("online", onOnline, false);
function onOnline() {
// Handle the online event
}
### iOS Quirks
During initial startup, the first `online` event (if applicable) takes
at least a second to fire, prior to which `connection.type` is
`UNKNOWN`.
### Windows Phone 7 Quirks
When running in the Emulator, the `connection.status` is always unknown, so this event does _not_ fire.
### Windows Phone 8 Quirks
The Emulator reports the connection type as `Cellular`, which does not change, so events does _not_ fire.

View File

@ -1,164 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="org.apache.cordova.network-information"
version="0.2.9-dev">
<name>Network Information</name>
<description>Cordova Network Information Plugin</description>
<license>Apache 2.0</license>
<keywords>cordova,network,information</keywords>
<repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git</repo>
<issue>https://issues.apache.org/jira/browse/CB/component/12320640</issue>
<js-module src="www/network.js" name="network">
<clobbers target="navigator.connection" />
<clobbers target="navigator.network.connection" />
</js-module>
<js-module src="www/Connection.js" name="Connection">
<clobbers target="Connection" />
</js-module>
<!-- firefoxos -->
<platform name="firefoxos">
<config-file target="config.xml" parent="/*">
<feature name="Network">
<param name="firefoxos-package" value="Network" />
</feature>
</config-file>
<js-module src="src/firefoxos/NetworkProxy.js" name="NetworkProxy">
<runs />
</js-module>
</platform>
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="NetworkStatus">
<param name="android-package" value="org.apache.cordova.networkinformation.NetworkManager"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</config-file>
<source-file src="src/android/NetworkManager.java" target-dir="src/org/apache/cordova/networkinformation" />
</platform>
<!-- amazon-fireos -->
<platform name="amazon-fireos">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="NetworkStatus">
<param name="android-package" value="org.apache.cordova.networkinformation.NetworkManager"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</config-file>
<source-file src="src/android/NetworkManager.java" target-dir="src/org/apache/cordova/networkinformation" />
</platform>
<!-- ubuntu -->
<platform name="ubuntu">
<config-file target="config.xml" parent="/*">
<feature name="Camera">
<param policy_group="connectivity" policy_version="1" />
</feature>
</config-file>
<header-file src="src/ubuntu/network_information.h" />
<source-file src="src/ubuntu/network_information.cpp" />
</platform>
<!-- ios -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="NetworkStatus">
<param name="ios-package" value="CDVConnection" />
</feature>
</config-file>
<header-file src="src/ios/CDVConnection.h" />
<source-file src="src/ios/CDVConnection.m" />
<header-file src="src/ios/CDVReachability.h" />
<source-file src="src/ios/CDVReachability.m" />
<framework src="SystemConfiguration.framework" weak="true" />
</platform>
<!-- blackberry10 -->
<platform name="blackberry10">
<source-file src="src/blackberry10/index.js" target-dir="NetworkStatus" />
<config-file target="www/config.xml" parent="/widget">
<feature name="NetworkStatus" value="NetworkStatus"/>
</config-file>
</platform>
<!-- wp7 -->
<platform name="wp7">
<config-file target="config.xml" parent="/*">
<feature name="NetworkStatus">
<param name="wp-package" value="NetworkStatus"/>
</feature>
</config-file>
<config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
<Capability Name="ID_CAP_NETWORKING" />
</config-file>
<source-file src="src/wp/NetworkStatus.cs" />
</platform>
<!-- wp8 -->
<platform name="wp8">
<config-file target="config.xml" parent="/*">
<feature name="NetworkStatus">
<param name="wp-package" value="NetworkStatus"/>
</feature>
</config-file>
<config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
<Capability Name="ID_CAP_NETWORKING" />
</config-file>
<source-file src="src/wp/NetworkStatus.cs" />
</platform>
<!-- windows8 -->
<platform name="windows8">
<js-module src="src/windows8/NetworkInfoProxy.js" name="NetworkInfoProxy">
<merges target="" />
</js-module>
</platform>
<!-- tizen -->
<platform name="tizen">
<js-module src="src/tizen/NetworkProxy.js" name="NetworkProxy">
<runs />
</js-module>
</platform>
</plugin>

View File

@ -1,249 +0,0 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package org.apache.cordova.networkinformation;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
public class NetworkManager extends CordovaPlugin {
public static int NOT_REACHABLE = 0;
public static int REACHABLE_VIA_CARRIER_DATA_NETWORK = 1;
public static int REACHABLE_VIA_WIFI_NETWORK = 2;
public static final String WIFI = "wifi";
public static final String WIMAX = "wimax";
// mobile
public static final String MOBILE = "mobile";
// 2G network types
public static final String GSM = "gsm";
public static final String GPRS = "gprs";
public static final String EDGE = "edge";
// 3G network types
public static final String CDMA = "cdma";
public static final String UMTS = "umts";
public static final String HSPA = "hspa";
public static final String HSUPA = "hsupa";
public static final String HSDPA = "hsdpa";
public static final String ONEXRTT = "1xrtt";
public static final String EHRPD = "ehrpd";
// 4G network types
public static final String LTE = "lte";
public static final String UMB = "umb";
public static final String HSPA_PLUS = "hspa+";
// return type
public static final String TYPE_UNKNOWN = "unknown";
public static final String TYPE_ETHERNET = "ethernet";
public static final String TYPE_WIFI = "wifi";
public static final String TYPE_2G = "2g";
public static final String TYPE_3G = "3g";
public static final String TYPE_4G = "4g";
public static final String TYPE_NONE = "none";
private static final String LOG_TAG = "NetworkManager";
private CallbackContext connectionCallbackContext;
private boolean registered = false;
ConnectivityManager sockMan;
BroadcastReceiver receiver;
private String lastStatus = "";
/**
* Constructor.
*/
public NetworkManager() {
this.receiver = null;
}
/**
* Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param cordova The context of the main Activity.
* @param webView The CordovaWebView Cordova is running in.
*/
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
this.sockMan = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
this.connectionCallbackContext = null;
// We need to listen to connectivity events to update navigator.connection
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
if (this.receiver == null) {
this.receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// (The null check is for the ARM Emulator, please use Intel Emulator for better results)
if(NetworkManager.this.webView != null)
updateConnectionInfo(sockMan.getActiveNetworkInfo());
}
};
cordova.getActivity().registerReceiver(this.receiver, intentFilter);
this.registered = true;
}
}
/**
* Executes the request and returns PluginResult.
*
* @param action The action to execute.
* @param args JSONArry of arguments for the plugin.
* @param callbackContext The callback id used when calling back into JavaScript.
* @return True if the action was valid, false otherwise.
*/
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
if (action.equals("getConnectionInfo")) {
this.connectionCallbackContext = callbackContext;
NetworkInfo info = sockMan.getActiveNetworkInfo();
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, this.getConnectionInfo(info));
pluginResult.setKeepCallback(true);
callbackContext.sendPluginResult(pluginResult);
return true;
}
return false;
}
/**
* Stop network receiver.
*/
public void onDestroy() {
if (this.receiver != null && this.registered) {
try {
this.cordova.getActivity().unregisterReceiver(this.receiver);
this.registered = false;
} catch (Exception e) {
Log.e(LOG_TAG, "Error unregistering network receiver: " + e.getMessage(), e);
}
}
}
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------
/**
* Updates the JavaScript side whenever the connection changes
*
* @param info the current active network info
* @return
*/
private void updateConnectionInfo(NetworkInfo info) {
// send update to javascript "navigator.network.connection"
// Jellybean sends its own info
String thisStatus = this.getConnectionInfo(info);
if(!thisStatus.equals(lastStatus))
{
sendUpdate(thisStatus);
lastStatus = thisStatus;
}
}
/**
* Get the latest network connection information
*
* @param info the current active network info
* @return a JSONObject that represents the network info
*/
private String getConnectionInfo(NetworkInfo info) {
String type = TYPE_NONE;
if (info != null) {
// If we are not connected to any network set type to none
if (!info.isConnected()) {
type = TYPE_NONE;
}
else {
type = getType(info);
}
}
Log.d("CordovaNetworkManager", "Connection Type: " + type);
return type;
}
/**
* Create a new plugin result and send it back to JavaScript
*
* @param connection the network info to set as navigator.connection
*/
private void sendUpdate(String type) {
if (connectionCallbackContext != null) {
PluginResult result = new PluginResult(PluginResult.Status.OK, type);
result.setKeepCallback(true);
connectionCallbackContext.sendPluginResult(result);
}
webView.postMessage("networkconnection", type);
}
/**
* Determine the type of connection
*
* @param info the network info so we can determine connection type.
* @return the type of mobile network we are on
*/
private String getType(NetworkInfo info) {
if (info != null) {
String type = info.getTypeName();
if (type.toLowerCase().equals(WIFI)) {
return TYPE_WIFI;
}
else if (type.toLowerCase().equals(MOBILE)) {
type = info.getSubtypeName();
if (type.toLowerCase().equals(GSM) ||
type.toLowerCase().equals(GPRS) ||
type.toLowerCase().equals(EDGE)) {
return TYPE_2G;
}
else if (type.toLowerCase().startsWith(CDMA) ||
type.toLowerCase().equals(UMTS) ||
type.toLowerCase().equals(ONEXRTT) ||
type.toLowerCase().equals(EHRPD) ||
type.toLowerCase().equals(HSUPA) ||
type.toLowerCase().equals(HSDPA) ||
type.toLowerCase().equals(HSPA)) {
return TYPE_3G;
}
else if (type.toLowerCase().equals(LTE) ||
type.toLowerCase().equals(UMB) ||
type.toLowerCase().equals(HSPA_PLUS)) {
return TYPE_4G;
}
}
}
else {
return TYPE_NONE;
}
return TYPE_UNKNOWN;
}
}

View File

@ -1,64 +0,0 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
//map from BB10 to cordova connection types:
//https://github.com/apache/cordova-js/blob/master/lib/common/plugin/Connection.js
function mapConnectionType(con) {
switch (con.type) {
case 'wired':
return 'ethernet';
case 'wifi':
return 'wifi';
case 'none':
return 'none';
case 'cellular':
switch (con.technology) {
case 'edge':
case 'gsm':
return '2g';
case 'evdo':
return '3g';
case 'umts':
return '3g';
case 'lte':
return '4g';
}
return "cellular";
}
return 'unknown';
}
function currentConnectionType() {
try {
//possible for webplatform to throw pps exception
return mapConnectionType(window.qnx.webplatform.device.activeConnection || { type : 'none' });
}
catch (e) {
return 'unknown';
}
}
module.exports = {
getConnectionInfo: function (success, fail, args, env) {
var result = new PluginResult(args, env);
result.ok(currentConnectionType());
}
};

View File

@ -1,60 +0,0 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
/*
Network API overview: http://dvcs.w3.org/hg/dap/raw-file/tip/network-api/Overview.html
*/
var cordova = require('cordova');
module.exports = {
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
getConnectionInfo: function (win, fail, args) {
/*
bandwidth of type double, readonly
The user agent must set the value of the bandwidth attribute to:
0 if the user is currently offline;
Infinity if the bandwidth is unknown;
an estimation of the current bandwidth in MB/s (Megabytes per seconds) available for communication with the browsing context active document's domain.
*/
win(connection.bandwidth);
},
isMetered: function (win, fail, args) {
/*
readonly attribute boolean metered
A connection is metered when the user's connection is subject to a limitation from his Internet Service Provider strong enough to request web applications to be careful with the bandwidth usage.
What is a metered connection is voluntarily left to the user agent to judge. It would not be possible to give an exhaustive list of limitations considered strong enough to flag the connection as metered and even if doable, some limitations can be considered strong or weak depending on the context.
Examples of metered connections are mobile connections with a small bandwidth quota or connections with a pay-per use plan.
The user agent MUST set the value of the metered attribute to true if the connection with the browsing context active document's domain is metered and false otherwise. If the implementation is not able to know the status of the connection or if the user is offline, the value MUST be set to false.
If unable to know if a connection is metered, a user agent could ask the user about the status of his current connection.
*/
win(connection.metered);
}
};
require("cordova/firefoxos/commandProxy").add("Network", module.exports);

View File

@ -1,34 +0,0 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
#import <Foundation/Foundation.h>
#import <Cordova/CDVPlugin.h>
#import "CDVReachability.h"
@interface CDVConnection : CDVPlugin {
NSString* type;
NSString* _callbackId;
CDVReachability* internetReach;
}
@property (copy) NSString* connectionType;
@property (strong) CDVReachability* internetReach;
@end

View File

@ -1,131 +0,0 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
#import "CDVConnection.h"
#import "CDVReachability.h"
@interface CDVConnection (PrivateMethods)
- (void)updateOnlineStatus;
- (void)sendPluginResult;
@end
@implementation CDVConnection
@synthesize connectionType, internetReach;
- (void)getConnectionInfo:(CDVInvokedUrlCommand*)command
{
_callbackId = command.callbackId;
[self sendPluginResult];
}
- (void)sendPluginResult
{
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:self.connectionType];
[result setKeepCallbackAsBool:YES];
[self.commandDelegate sendPluginResult:result callbackId:_callbackId];
}
- (NSString*)w3cConnectionTypeFor:(CDVReachability*)reachability
{
NetworkStatus networkStatus = [reachability currentReachabilityStatus];
switch (networkStatus) {
case NotReachable:
return @"none";
case ReachableViaWWAN:
{
BOOL isConnectionRequired = [reachability connectionRequired];
if (isConnectionRequired) {
return @"none";
} else {
return @"cellular";
}
}
case ReachableViaWiFi:
return @"wifi";
default:
return @"unknown";
}
}
- (BOOL)isCellularConnection:(NSString*)theConnectionType
{
return [theConnectionType isEqualToString:@"2g"] ||
[theConnectionType isEqualToString:@"3g"] ||
[theConnectionType isEqualToString:@"4g"] ||
[theConnectionType isEqualToString:@"cellular"];
}
- (void)updateReachability:(CDVReachability*)reachability
{
if (reachability) {
// check whether the connection type has changed
NSString* newConnectionType = [self w3cConnectionTypeFor:reachability];
if ([newConnectionType isEqualToString:self.connectionType]) { // the same as before, remove dupes
return;
} else {
self.connectionType = [self w3cConnectionTypeFor:reachability];
}
}
[self sendPluginResult];
}
- (void)updateConnectionType:(NSNotification*)note
{
CDVReachability* curReach = [note object];
if ((curReach != nil) && [curReach isKindOfClass:[CDVReachability class]]) {
[self updateReachability:curReach];
}
}
- (void)onPause
{
[self.internetReach stopNotifier];
}
- (void)onResume
{
[self.internetReach startNotifier];
[self updateReachability:self.internetReach];
}
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView
{
self = [super initWithWebView:theWebView];
if (self) {
self.connectionType = @"none";
self.internetReach = [CDVReachability reachabilityForInternetConnection];
self.connectionType = [self w3cConnectionTypeFor:self.internetReach];
[self.internetReach startNotifier];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateConnectionType:)
name:kReachabilityChangedNotification object:nil];
if (&UIApplicationDidEnterBackgroundNotification && &UIApplicationWillEnterForegroundNotification) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onPause) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResume) name:UIApplicationWillEnterForegroundNotification object:nil];
}
}
return self;
}
@end

View File

@ -1,85 +0,0 @@
/*
File: Reachability.h
Abstract: Basic demonstration of how to use the SystemConfiguration Reachability APIs.
Version: 2.2
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software
constitutes acceptance of these terms. If you do not agree with these terms,
please do not use, install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and subject
to these terms, Apple grants you a personal, non-exclusive license, under
Apple's copyrights in this original Apple software (the "Apple Software"), to
use, reproduce, modify and redistribute the Apple Software, with or without
modifications, in source and/or binary forms; provided that if you redistribute
the Apple Software in its entirety and without modifications, you must retain
this notice and the following text and disclaimers in all such redistributions
of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may be used
to endorse or promote products derived from the Apple Software without specific
prior written permission from Apple. Except as expressly stated in this notice,
no other rights or licenses, express or implied, are granted by Apple herein,
including but not limited to any patent rights that may be infringed by your
derivative works or by other works in which the Apple Software may be
incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2010 Apple Inc. All Rights Reserved.
*/
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <netinet/in.h>
typedef enum {
NotReachable = 0,
ReachableViaWWAN, // this value has been swapped with ReachableViaWiFi for Cordova backwards compat. reasons
ReachableViaWiFi // this value has been swapped with ReachableViaWWAN for Cordova backwards compat. reasons
} NetworkStatus;
#define kReachabilityChangedNotification @"kNetworkReachabilityChangedNotification"
@interface CDVReachability : NSObject
{
BOOL localWiFiRef;
SCNetworkReachabilityRef reachabilityRef;
}
// reachabilityWithHostName- Use to check the reachability of a particular host name.
+ (CDVReachability*)reachabilityWithHostName:(NSString*)hostName;
// reachabilityWithAddress- Use to check the reachability of a particular IP address.
+ (CDVReachability*)reachabilityWithAddress:(const struct sockaddr_in*)hostAddress;
// reachabilityForInternetConnection- checks whether the default route is available.
// Should be used by applications that do not connect to a particular host
+ (CDVReachability*)reachabilityForInternetConnection;
// reachabilityForLocalWiFi- checks whether a local wifi connection is available.
+ (CDVReachability*)reachabilityForLocalWiFi;
// Start listening for reachability notifications on the current run loop
- (BOOL)startNotifier;
- (void)stopNotifier;
- (NetworkStatus)currentReachabilityStatus;
// WWAN may be available, but not active until a connection has been established.
// WiFi may require a connection for VPN on Demand.
- (BOOL)connectionRequired;
@end

View File

@ -1,260 +0,0 @@
/*
File: Reachability.m
Abstract: Basic demonstration of how to use the SystemConfiguration Reachability APIs.
Version: 2.2
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software
constitutes acceptance of these terms. If you do not agree with these terms,
please do not use, install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and subject
to these terms, Apple grants you a personal, non-exclusive license, under
Apple's copyrights in this original Apple software (the "Apple Software"), to
use, reproduce, modify and redistribute the Apple Software, with or without
modifications, in source and/or binary forms; provided that if you redistribute
the Apple Software in its entirety and without modifications, you must retain
this notice and the following text and disclaimers in all such redistributions
of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may be used
to endorse or promote products derived from the Apple Software without specific
prior written permission from Apple. Except as expressly stated in this notice,
no other rights or licenses, express or implied, are granted by Apple herein,
including but not limited to any patent rights that may be infringed by your
derivative works or by other works in which the Apple Software may be
incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2010 Apple Inc. All Rights Reserved.
*/
#import <sys/socket.h>
#import <netinet/in.h>
#import <netinet6/in6.h>
#import <arpa/inet.h>
#import <ifaddrs.h>
#import <netdb.h>
#import <CoreFoundation/CoreFoundation.h>
#import "CDVReachability.h"
#define kShouldPrintReachabilityFlags 0
static void CDVPrintReachabilityFlags(SCNetworkReachabilityFlags flags, const char* comment)
{
#if kShouldPrintReachabilityFlags
NSLog(@"Reachability Flag Status: %c%c %c%c%c%c%c%c%c %s\n",
(flags & kSCNetworkReachabilityFlagsIsWWAN) ? 'W' : '-',
(flags & kSCNetworkReachabilityFlagsReachable) ? 'R' : '-',
(flags & kSCNetworkReachabilityFlagsTransientConnection) ? 't' : '-',
(flags & kSCNetworkReachabilityFlagsConnectionRequired) ? 'c' : '-',
(flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) ? 'C' : '-',
(flags & kSCNetworkReachabilityFlagsInterventionRequired) ? 'i' : '-',
(flags & kSCNetworkReachabilityFlagsConnectionOnDemand) ? 'D' : '-',
(flags & kSCNetworkReachabilityFlagsIsLocalAddress) ? 'l' : '-',
(flags & kSCNetworkReachabilityFlagsIsDirect) ? 'd' : '-',
comment
);
#endif
}
@implementation CDVReachability
static void CDVReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info)
{
#pragma unused (target, flags)
// NSCAssert(info != NULL, @"info was NULL in ReachabilityCallback");
// NSCAssert([(NSObject*) info isKindOfClass: [Reachability class]], @"info was wrong class in ReachabilityCallback");
// Converted the asserts above to conditionals, with safe return from the function
if (info == NULL) {
NSLog(@"info was NULL in ReachabilityCallback");
return;
}
if (![(__bridge NSObject*)info isKindOfClass :[CDVReachability class]]) {
NSLog(@"info was wrong class in ReachabilityCallback");
return;
}
// We're on the main RunLoop, so an NSAutoreleasePool is not necessary, but is added defensively
// in case someon uses the Reachability object in a different thread.
@autoreleasepool {
CDVReachability* noteObject = (__bridge CDVReachability*)info;
// Post a notification to notify the client that the network reachability changed.
[[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityChangedNotification object:noteObject];
}
}
- (BOOL)startNotifier
{
BOOL retVal = NO;
SCNetworkReachabilityContext context = {0, (__bridge void*)(self), NULL, NULL, NULL};
if (SCNetworkReachabilitySetCallback(reachabilityRef, CDVReachabilityCallback, &context)) {
if (SCNetworkReachabilityScheduleWithRunLoop(reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) {
retVal = YES;
}
}
return retVal;
}
- (void)stopNotifier
{
if (reachabilityRef != NULL) {
SCNetworkReachabilityUnscheduleFromRunLoop(reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
}
}
- (void)dealloc
{
[self stopNotifier];
if (reachabilityRef != NULL) {
CFRelease(reachabilityRef);
}
}
+ (CDVReachability*)reachabilityWithHostName:(NSString*)hostName;
{
CDVReachability* retVal = NULL;
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, [hostName UTF8String]);
if (reachability != NULL) {
retVal = [[self alloc] init];
if (retVal != NULL) {
retVal->reachabilityRef = reachability;
retVal->localWiFiRef = NO;
}
}
return retVal;
}
+ (CDVReachability*)reachabilityWithAddress:(const struct sockaddr_in*)hostAddress;
{
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)hostAddress);
CDVReachability* retVal = NULL;
if (reachability != NULL) {
retVal = [[self alloc] init];
if (retVal != NULL) {
retVal->reachabilityRef = reachability;
retVal->localWiFiRef = NO;
}
}
return retVal;
}
+ (CDVReachability*)reachabilityForInternetConnection;
{
struct sockaddr_in zeroAddress;
bzero(&zeroAddress, sizeof(zeroAddress));
zeroAddress.sin_len = sizeof(zeroAddress);
zeroAddress.sin_family = AF_INET;
return [self reachabilityWithAddress:&zeroAddress];
}
+ (CDVReachability*)reachabilityForLocalWiFi;
{
struct sockaddr_in localWifiAddress;
bzero(&localWifiAddress, sizeof(localWifiAddress));
localWifiAddress.sin_len = sizeof(localWifiAddress);
localWifiAddress.sin_family = AF_INET;
// IN_LINKLOCALNETNUM is defined in <netinet/in.h> as 169.254.0.0
localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM);
CDVReachability* retVal = [self reachabilityWithAddress:&localWifiAddress];
if (retVal != NULL) {
retVal->localWiFiRef = YES;
}
return retVal;
}
#pragma mark Network Flag Handling
- (NetworkStatus)localWiFiStatusForFlags:(SCNetworkReachabilityFlags)flags
{
CDVPrintReachabilityFlags(flags, "localWiFiStatusForFlags");
BOOL retVal = NotReachable;
if ((flags & kSCNetworkReachabilityFlagsReachable) && (flags & kSCNetworkReachabilityFlagsIsDirect)) {
retVal = ReachableViaWiFi;
}
return retVal;
}
- (NetworkStatus)networkStatusForFlags:(SCNetworkReachabilityFlags)flags
{
CDVPrintReachabilityFlags(flags, "networkStatusForFlags");
if ((flags & kSCNetworkReachabilityFlagsReachable) == 0) {
// if target host is not reachable
return NotReachable;
}
NetworkStatus retVal = NotReachable;
if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0) {
// if target host is reachable and no connection is required
// then we'll assume (for now) that your on Wi-Fi
retVal = ReachableViaWiFi;
}
if ((((flags & kSCNetworkReachabilityFlagsConnectionOnDemand) != 0) ||
((flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0))) {
// ... and the connection is on-demand (or on-traffic) if the
// calling application is using the CFSocketStream or higher APIs
if ((flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0) {
// ... and no [user] intervention is needed
retVal = ReachableViaWiFi;
}
}
if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) {
// ... but WWAN connections are OK if the calling application
// is using the CFNetwork (CFSocketStream?) APIs.
retVal = ReachableViaWWAN;
}
return retVal;
}
- (BOOL)connectionRequired;
{
NSAssert(reachabilityRef != NULL, @"connectionRequired called with NULL reachabilityRef");
SCNetworkReachabilityFlags flags;
if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) {
return flags & kSCNetworkReachabilityFlagsConnectionRequired;
}
return NO;
}
- (NetworkStatus)currentReachabilityStatus
{
NSAssert(reachabilityRef != NULL, @"currentNetworkStatus called with NULL reachabilityRef");
NetworkStatus retVal = NotReachable;
SCNetworkReachabilityFlags flags;
if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) {
if (localWiFiRef) {
retVal = [self localWiFiStatusForFlags:flags];
} else {
retVal = [self networkStatusForFlags:flags];
}
}
return retVal;
}
@end

View File

@ -1,92 +0,0 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
var cordova = require('cordova');
var Connection = require('./Connection');
module.exports = {
getConnectionInfo: function(successCallback, errorCallback) {
var cncType = Connection.NONE;
var infoCount = 0;
var deviceCapabilities = null;
var timerId = 0;
var timeout = 300;
function connectionCB() {
if (timerId !== null) {
clearTimeout(timerId);
timerId = null;
}
infoCount++;
if (infoCount > 1) {
if (successCallback) {
successCallback(cncType);
}
}
}
function errorCB(error) {
console.log("Error: " + error.code + "," + error.name + "," + error.message);
if (errorCallback) {
errorCallback();
}
}
function wifiSuccessCB(wifi) {
if ((wifi.status === "ON") && (wifi.ipAddress.length !== 0)) {
cncType = Connection.WIFI;
}
connectionCB();
}
function cellularSuccessCB(cell) {
if ((cncType === Connection.NONE) && (cell.status === "ON") && (cell.ipAddress.length !== 0)) {
cncType = Connection.CELL_2G;
}
connectionCB();
}
deviceCapabilities = tizen.systeminfo.getCapabilities();
timerId = setTimeout(function() {
timerId = null;
infoCount = 1;
connectionCB();
}, timeout);
if (deviceCapabilities.wifi) {
tizen.systeminfo.getPropertyValue("WIFI_NETWORK", wifiSuccessCB, errorCB);
}
if (deviceCapabilities.telephony) {
tizen.systeminfo.getPropertyValue("CELLULAR_NETWORK", cellularSuccessCB, errorCB);
}
}
};
require("cordova/tizen/commandProxy").add("NetworkStatus", module.exports);

View File

@ -1,63 +0,0 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "network_information.h"
void NetworkInformation::getConnectionInfo(int scId, int ecId) {
Q_UNUSED(ecId);
QString result;
QNetworkInfo::NetworkMode networkMode = m_systemNetworkInfo.currentNetworkMode();
QNetworkInfo::NetworkStatus networkStatus = m_systemNetworkInfo.networkStatus(networkMode, 0);
QNetworkInfo::CellDataTechnology cellDataTechnology = m_systemNetworkInfo.currentCellDataTechnology(0);
if (networkStatus == QNetworkInfo::NoNetworkAvailable)
result = "Connection.NONE";
switch (networkMode) {
case QNetworkInfo::WimaxMode:
case QNetworkInfo::WlanMode:
result = "Connection.WIFI";
break;
case QNetworkInfo::EthernetMode:
result = "Connection.ETHERNET";
break;
case QNetworkInfo::LteMode:
result = "Connection.CELL_4G";
break;
case QNetworkInfo::GsmMode:
case QNetworkInfo::CdmaMode:
case QNetworkInfo::TdscdmaMode:
case QNetworkInfo::WcdmaMode:
switch (cellDataTechnology) {
case QNetworkInfo::UmtsDataTechnology:
case QNetworkInfo::HspaDataTechnology:
result = "Connection.CELL_3G";
break;
case QNetworkInfo::EdgeDataTechnology:
case QNetworkInfo::GprsDataTechnology:
result = "Connection.CELL_2G";
break;
case QNetworkInfo::UnknownDataTechnology:
result = "Connection.UNKNOWN";
break;
}
case QNetworkInfo::BluetoothMode:
case QNetworkInfo::UnknownMode:
result = "Connection.UNKNOWN";
break;
}
this->callback(scId, result);
}

View File

@ -1,47 +0,0 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NETWORK_INFORMATION_H
#define NETWORK_INFORMATION_H
#include <cplugin.h>
#include <QtSystemInfo>
#include <QtCore>
class NetworkInformation: public CPlugin {
Q_OBJECT
public:
explicit NetworkInformation(Cordova *cordova): CPlugin(cordova) {}
virtual const QString fullName() override {
return NetworkInformation::fullID();
}
virtual const QString shortName() override {
return "Connection";
}
static const QString fullID() {
return "NetworkStatus";
}
public slots:
void getConnectionInfo(int scId, int ecId);
private:
QNetworkInfo m_systemNetworkInfo;
};
#endif

View File

@ -1,87 +0,0 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
/*global Windows:true */
var cordova = require('cordova');
var Connection = require('./Connection');
module.exports = {
getConnectionInfo:function(win,fail,args)
{
console.log("NetworkStatusProxy::getConnectionInfo");
var winNetConn = Windows.Networking.Connectivity;
var networkInfo = winNetConn.NetworkInformation;
var networkCostInfo = winNetConn.NetworkCostType;
var networkConnectivityInfo = winNetConn.NetworkConnectivityLevel;
var networkAuthenticationInfo = winNetConn.NetworkAuthenticationType;
var networkEncryptionInfo = winNetConn.NetworkEncryptionType;
var connectionType;
var profile = Windows.Networking.Connectivity.NetworkInformation.getInternetConnectionProfile();
if(profile) {
var conLevel = profile.getNetworkConnectivityLevel();
var interfaceType = profile.networkAdapter.ianaInterfaceType;
if (conLevel == Windows.Networking.Connectivity.NetworkConnectivityLevel.none) {
connectionType = Connection.NONE;
}
else {
switch (interfaceType) {
case 71:
connectionType = Connection.WIFI;
break;
case 6:
connectionType = Connection.ETHERNET;
break;
case 243: // (3GPP WWAN) // Fallthrough is intentional
case 244: // (3GPP2 WWAN)
connectionType = Connection.CELL_3G;
break;
default:
connectionType = Connection.UNKNOWN;
break;
}
}
}
// FYI
//Connection.UNKNOWN 'Unknown connection';
//Connection.ETHERNET 'Ethernet connection';
//Connection.WIFI 'WiFi connection';
//Connection.CELL_2G 'Cell 2G connection';
//Connection.CELL_3G 'Cell 3G connection';
//Connection.CELL_4G 'Cell 4G connection';
//Connection.NONE 'No network connection';
setTimeout(function () {
if (connectionType) {
win(connectionType);
} else {
win(Connection.NONE);
}
},0);
}
};
require("cordova/exec/proxy").add("NetworkStatus",module.exports);

View File

@ -1,129 +0,0 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System;
using System.Diagnostics;
using System.Net;
using System.Net.NetworkInformation;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Net.NetworkInformation;
namespace WPCordovaClassLib.Cordova.Commands
{
// http://msdn.microsoft.com/en-us/library/microsoft.phone.net.networkinformation(v=VS.92).aspx
// http://msdn.microsoft.com/en-us/library/microsoft.phone.net.networkinformation.devicenetworkinformation(v=VS.92).aspx
public class NetworkStatus : BaseCommand
{
const string UNKNOWN = "unknown";
const string ETHERNET = "ethernet";
const string WIFI = "wifi";
const string CELL_2G = "2g";
const string CELL_3G = "3g";
const string CELL_4G = "4g";
const string NONE = "none";
const string CELL = "cellular";
private bool HasCallback = false;
public NetworkStatus()
{
DeviceNetworkInformation.NetworkAvailabilityChanged += new EventHandler<NetworkNotificationEventArgs>(ChangeDetected);
}
public override void OnResume(object sender, Microsoft.Phone.Shell.ActivatedEventArgs e)
{
this.getConnectionInfo("");
}
public void getConnectionInfo(string empty)
{
HasCallback = true;
updateConnectionType(checkConnectionType());
}
private string checkConnectionType()
{
if (DeviceNetworkInformation.IsNetworkAvailable)
{
if (DeviceNetworkInformation.IsWiFiEnabled)
{
return WIFI;
}
else
{
return DeviceNetworkInformation.IsCellularDataEnabled ? CELL : UNKNOWN;
}
}
return NONE;
}
private string checkConnectionType(NetworkInterfaceSubType type)
{
switch (type)
{
case NetworkInterfaceSubType.Cellular_1XRTT: //cell
case NetworkInterfaceSubType.Cellular_GPRS: //cell
return CELL;
case NetworkInterfaceSubType.Cellular_EDGE: //2
return CELL_2G;
case NetworkInterfaceSubType.Cellular_3G:
case NetworkInterfaceSubType.Cellular_EVDO: //3
case NetworkInterfaceSubType.Cellular_EVDV: //3
case NetworkInterfaceSubType.Cellular_HSPA: //3
return CELL_3G;
case NetworkInterfaceSubType.WiFi:
return WIFI;
case NetworkInterfaceSubType.Unknown:
case NetworkInterfaceSubType.Desktop_PassThru:
default:
return UNKNOWN;
}
}
void ChangeDetected(object sender, NetworkNotificationEventArgs e)
{
switch (e.NotificationType)
{
case NetworkNotificationType.InterfaceConnected:
updateConnectionType(checkConnectionType(e.NetworkInterface.InterfaceSubtype));
break;
case NetworkNotificationType.InterfaceDisconnected:
updateConnectionType(NONE);
break;
default:
break;
}
}
private void updateConnectionType(string type)
{
// This should also implicitly fire offline/online events as that is handled on the JS side
if (this.HasCallback)
{
PluginResult result = new PluginResult(PluginResult.Status.OK, type);
result.KeepCallback = true;
DispatchCommandResult(result);
}
}
}
}

View File

@ -1,34 +0,0 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
/**
* Network status
*/
module.exports = {
UNKNOWN: "unknown",
ETHERNET: "ethernet",
WIFI: "wifi",
CELL_2G: "2g",
CELL_3G: "3g",
CELL_4G: "4g",
CELL:"cellular",
NONE: "none"
};

View File

@ -1,89 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
var exec = require('cordova/exec'),
cordova = require('cordova'),
channel = require('cordova/channel'),
utils = require('cordova/utils');
// Link the onLine property with the Cordova-supplied network info.
// This works because we clobber the naviagtor object with our own
// object in bootstrap.js.
if (typeof navigator != 'undefined') {
utils.defineGetter(navigator, 'onLine', function() {
return this.connection.type != 'none';
});
}
function NetworkConnection() {
this.type = 'unknown';
}
/**
* Get connection info
*
* @param {Function} successCallback The function to call when the Connection data is available
* @param {Function} errorCallback The function to call when there is an error getting the Connection data. (OPTIONAL)
*/
NetworkConnection.prototype.getInfo = function(successCallback, errorCallback) {
exec(successCallback, errorCallback, "NetworkStatus", "getConnectionInfo", []);
};
var me = new NetworkConnection();
var timerId = null;
var timeout = 500;
channel.createSticky('onCordovaConnectionReady');
channel.waitForInitialization('onCordovaConnectionReady');
channel.onCordovaReady.subscribe(function() {
me.getInfo(function(info) {
me.type = info;
if (info === "none") {
// set a timer if still offline at the end of timer send the offline event
timerId = setTimeout(function(){
cordova.fireDocumentEvent("offline");
timerId = null;
}, timeout);
} else {
// If there is a current offline event pending clear it
if (timerId !== null) {
clearTimeout(timerId);
timerId = null;
}
cordova.fireDocumentEvent("online");
}
// should only fire this once
if (channel.onCordovaConnectionReady.state !== 2) {
channel.onCordovaConnectionReady.fire();
}
},
function (e) {
// If we can't get the network info we should still tell Cordova
// to fire the deviceready event.
if (channel.onCordovaConnectionReady.state !== 2) {
channel.onCordovaConnectionReady.fire();
}
console.log("Error initializing Network Connection: " + e);
});
});
module.exports = me;