From 2c526aeeaacdfdf4767b5503cb516a2dc8c13046 Mon Sep 17 00:00:00 2001 From: Raphael Kubo da Costa Date: Thu, 5 Nov 2015 13:58:20 +0100 Subject: [PATCH] Revert "Wifi Direct Experimental API initial contribution" This reverts commit ef2dad6c381e35eb5424c8d789a6d2b60704a54b. Reason: breaks org.xwalk.runtime.client.embedded.test.PauseResumeTest#testPauseAndResume. E/AndroidRuntime( 9436): FATAL EXCEPTION: main E/AndroidRuntime( 9436): java.lang.RuntimeException: Unable to resume activity {org.xwalk.runtime.client.embedded.shell/org.xwalk.runtime.client.embedded.shell.XWalkRuntimeClientEmbeddedShellActivity}: java.lang.NullPointerException E/AndroidRuntime( 9436): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2974) E/AndroidRuntime( 9436): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3003) E/AndroidRuntime( 9436): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1408) E/AndroidRuntime( 9436): at android.os.Handler.dispatchMessage(Handler.java:108) E/AndroidRuntime( 9436): at android.os.Looper.loop(Looper.java:152) E/AndroidRuntime( 9436): at android.app.ActivityThread.main(ActivityThread.java:5691) E/AndroidRuntime( 9436): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 9436): at java.lang.reflect.Method.invoke(Method.java:511) E/AndroidRuntime( 9436): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) E/AndroidRuntime( 9436): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) E/AndroidRuntime( 9436): at dalvik.system.NativeStart.main(Native Method) E/AndroidRuntime( 9436): Caused by: java.lang.NullPointerException E/AndroidRuntime( 9436): at android.app.ActivityManagerProxy.registerReceiver(ActivityManagerNative.java:2150) E/AndroidRuntime( 9436): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1517) E/AndroidRuntime( 9436): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1485) E/AndroidRuntime( 9436): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1479) E/AndroidRuntime( 9436): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:448) E/AndroidRuntime( 9436): at org.xwalk.core.internal.extension.api.wifidirect.WifiDirect.onActivityStateChange(WifiDirect.java:343) E/AndroidRuntime( 9436): at org.xwalk.core.internal.extension.XWalkExtensionWithActivityStateListener$XWalkActivityStateListener.onActivityStateChange(XWalkExtensionWithActivityStateListener.java:33) E/AndroidRuntime( 9436): at org.chromium.base.ApplicationStatus.onStateChange(ApplicationStatus.java:203) E/AndroidRuntime( 9436): at org.chromium.base.ApplicationStatus.access$100(ApplicationStatus.java:24) E/AndroidRuntime( 9436): at org.chromium.base.ApplicationStatus$2.onActivityResumed(ApplicationStatus.java:149) E/AndroidRuntime( 9436): at android.app.Application.dispatchActivityResumed(Application.java:174) E/AndroidRuntime( 9436): at android.app.Activity.onResume(Activity.java:1092) E/AndroidRuntime( 9436): at org.xwalk.core.XWalkActivity.onResume(XWalkActivity.java:130) E/AndroidRuntime( 9436): at org.xwalk.app.XWalkRuntimeActivityBase.onResume(XWalkRuntimeActivityBase.java:67) E/AndroidRuntime( 9436): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1185) E/AndroidRuntime( 9436): at android.app.Activity.performResume(Activity.java:5207) E/AndroidRuntime( 9436): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2964) E/AndroidRuntime( 9436): ... 10 more W/ActivityManager( 2186): Error in app org.xwalk.runtime.client.embedded.shell running instrumentation ComponentInfo{org.xwalk.runtime.client.embedded.test/android.test.InstrumentationTestRunner}: W/ActivityManager( 2186): java.lang.NullPointerException W/ActivityManager( 2186): java.lang.NullPointerException: Unable to resume activity {org.xwalk.runtime.client.embedded.shell/org.xwalk.runtime.client.embedded.shell.XWalkRuntimeClientEmbeddedShellActivity}: java.lang.NullPointerException --- app/android/app_template/AndroidManifest.xml | 2 - .../AndroidManifest.xml | 2 - .../runtime_client_shell/AndroidManifest.xml | 2 - app/tools/android/handle_permissions.py | 7 +- app/tools/android/make_apk_test.py | 3 +- build/android/generate_xwalk_core_library.py | 3 +- experimental/wifidirect/OWNERS | 1 - experimental/wifidirect/wifidirect_api.js | 227 ----------- .../src/org/xwalk/core/XWalkActivity.java | 2 - .../core/src/org/xwalk/core/XWalkUpdater.java | 2 - .../extension/BuiltinXWalkExtensions.java | 13 - .../extension/api/wifidirect/WifiDirect.java | 363 ------------------ .../android/core_shell/AndroidManifest.xml | 2 - xwalk_android.gypi | 2 - xwalk_android_tests.gypi | 4 - 15 files changed, 3 insertions(+), 632 deletions(-) delete mode 100644 experimental/wifidirect/OWNERS delete mode 100644 experimental/wifidirect/wifidirect_api.js delete mode 100644 runtime/android/core_internal/src/org/xwalk/core/internal/extension/api/wifidirect/WifiDirect.java diff --git a/app/android/app_template/AndroidManifest.xml b/app/android/app_template/AndroidManifest.xml index c6cfc89e20..33c8e4e02a 100644 --- a/app/android/app_template/AndroidManifest.xml +++ b/app/android/app_template/AndroidManifest.xml @@ -26,9 +26,7 @@ - - diff --git a/app/android/runtime_client_embedded_shell/AndroidManifest.xml b/app/android/runtime_client_embedded_shell/AndroidManifest.xml index c611db3f10..1383f656a8 100644 --- a/app/android/runtime_client_embedded_shell/AndroidManifest.xml +++ b/app/android/runtime_client_embedded_shell/AndroidManifest.xml @@ -31,9 +31,7 @@ - - diff --git a/app/android/runtime_client_shell/AndroidManifest.xml b/app/android/runtime_client_shell/AndroidManifest.xml index a57a0d8c26..5d6d5700d8 100644 --- a/app/android/runtime_client_shell/AndroidManifest.xml +++ b/app/android/runtime_client_shell/AndroidManifest.xml @@ -31,9 +31,7 @@ - - diff --git a/app/tools/android/handle_permissions.py b/app/tools/android/handle_permissions.py index d5d6ab3ca1..78b02a6e94 100755 --- a/app/tools/android/handle_permissions.py +++ b/app/tools/android/handle_permissions.py @@ -42,12 +42,7 @@ 'presentation': [], 'rawsockets': [], 'screenorientation': [], - 'vibration': ['android.permission.VIBRATE'], - 'wifidirect': ['android.permission.ACCESS_WIFI_STATE', - 'android.permission.CHANGE_WIFI_STATE', - 'android.permission.CHANGE_NETWORK_STATE', - 'android.permission.INTERNET', - 'android.permission.ACCESS_NETWORK_STATE'] + 'vibration': ['android.permission.VIBRATE'] } diff --git a/app/tools/android/make_apk_test.py b/app/tools/android/make_apk_test.py index 2351c06782..3f914db70b 100755 --- a/app/tools/android/make_apk_test.py +++ b/app/tools/android/make_apk_test.py @@ -235,8 +235,7 @@ def checkApk(self, apk_path, arch, keystore_path=None): # 'snapshot_blob.bin', 'device_capabilities_api.js', 'launch_screen_api.js', - 'presentation_api.js', - 'wifidirect_api.js'] + 'presentation_api.js'] for res_file in embedded_related_files: self.assertTrue(out.find(res_file) != -1) if arch == 'x86': diff --git a/build/android/generate_xwalk_core_library.py b/build/android/generate_xwalk_core_library.py index a804d40649..a3d383376a 100755 --- a/build/android/generate_xwalk_core_library.py +++ b/build/android/generate_xwalk_core_library.py @@ -85,8 +85,7 @@ def CopyJSBindingFiles(project_source, out_project_dir): 'xwalk/runtime/android/core_internal/src/org/xwalk/core/' + 'internal/extension/api/device_capabilities/device_capabilities_api.js', 'xwalk/runtime/android/core_internal/src/org/xwalk/core/' - + 'internal/extension/api/messaging/messaging_api.js', - 'xwalk/experimental/wifidirect/wifidirect_api.js' + + 'internal/extension/api/messaging/messaging_api.js' ] # Copy JS binding file to assets/jsapi folder. diff --git a/experimental/wifidirect/OWNERS b/experimental/wifidirect/OWNERS deleted file mode 100644 index 2805c82ad4..0000000000 --- a/experimental/wifidirect/OWNERS +++ /dev/null @@ -1 +0,0 @@ -aleksandar.stojiljkovic@intel.com diff --git a/experimental/wifidirect/wifidirect_api.js b/experimental/wifidirect/wifidirect_api.js deleted file mode 100644 index f05be4a53c..0000000000 --- a/experimental/wifidirect/wifidirect_api.js +++ /dev/null @@ -1,227 +0,0 @@ -// Copyright (c) 2015 Intel Corporation. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -var g_next_async_call_id = 0; -var g_async_calls = []; -var g_listeners = []; - -var WIFI_STATE_CHANGED_EVENT = 'wifistatechanged'; -var PEERS_CHANGED_EVENT = 'peerschanged'; -var CONNECTION_CHANGED_EVENT = 'connectionchanged'; -var THIS_DEVICE_CHANGED_EVENT = 'thisdevicechanged'; -var DISCOVERY_STOPPED_EVENT = 'discoverystoppedevent'; - -function AsyncCall(resolve, reject) { - this.resolve = resolve; - this.reject = reject; -} - -function createPromise(msg) { - var promise = new Promise(function(resolve, reject) { - g_async_calls[g_next_async_call_id] = new AsyncCall(resolve, reject); - }); - msg.asyncCallId = g_next_async_call_id; - extension.postMessage(JSON.stringify(msg)); - ++g_next_async_call_id; - return promise; -} - -exports.init = function() { - var msg = { - 'cmd': 'init' - }; - return createPromise(msg); -}; - -exports.discoverPeers = function() { - var msg = { - 'cmd': 'discoverPeers' - }; - return createPromise(msg); -}; - -exports.stopDiscovery = function() { - var msg = { - 'cmd': 'stopPeerDiscovery' - }; - return createPromise(msg); -}; - -exports.getPeers = function() { - var msg = { - 'cmd': 'getPeers' - }; - return createPromise(msg); -}; - -exports.getConnectionInfo = function() { - var msg = { - 'cmd': 'getConnectionInfo' - }; - return createPromise(msg); -}; - -exports.ConnectionMethod = { - PBC : "pbc", - Display : "display", - Label : "label", - Keyboard : "keyboard" -}; - -exports.connect = function(device) { - var msg = { - 'cmd': 'connect', - 'data': device, - 'method' : "pbc" - }; - return createPromise(msg); -}; - -exports.cancelConnect = function() { - var msg = { - 'cmd': 'cancelConnect' - }; - return createPromise(msg); -}; - -exports.disconnect = function() { - var msg = { - 'cmd': 'disconnect' - }; - return createPromise(msg); -}; - -function Device(data) { - this.MAC = data.MAC; - this.name = data.name; - this.type = data.type; - this.status = data.status; -} - -function _addEventListener(isOn, eventName, callback) { - if (typeof eventName !== 'string') { - console.warn("Invalid parameters of eventName!"); - return -1; - } - - if (!isOn && (typeof callback !== 'function')) { - console.warn("Invalid parameters of callback!"); - return -1; - } - - if (isOn && (typeof callback !== null) && (typeof callback !== 'function')) { - console.warn("Invalid parameters of callback!"); - return -1; - } - - var listener = { - 'eventName': eventName, - 'callback': callback - }; - - var listener_id; - - if (isOn) { - switch(listener.eventName) { - case PEERS_CHANGED_EVENT: - g_listeners[0] = listener; - listener_id = 0; - break; - case PEERS_CHANGED_EVENT: - g_listeners[1] = listener; - listener_id = 1; - break; - case CONNECTION_CHANGED_EVENT: - g_listeners[2] = listener; - listener_id = 2; - break; - case THIS_DEVICE_CHANGED_EVENT: - g_listeners[3] = listener; - listener_id = 3; - break; - case DISCOVERY_STOPPED_EVENT: - g_listeners[4] = listener; - listener_id = 4; - break; - default: - console.warn("Invalid event name!"); - break; - } - } else { - listener_id = g_next_async_call_id; - g_next_async_call_id += 1; - g_listeners[listener_id] = listener; - } - return listener_id; -} - -Object.defineProperty(exports, 'onwifistatechanged', { - set: function(callback) { - _addEventListener(true, WIFI_STATE_CHANGED_EVENT, callback); - } -}); - -Object.defineProperty(exports, 'onpeerschanged', { - set: function(callback) { - _addEventListener(true, PEERS_CHANGED_EVENT, callback); - } -}); - -Object.defineProperty(exports, 'onconnectionchanged', { - set: function(callback) { - _addEventListener(true, CONNECTION_CHANGED_EVENT, callback); - } -}); - -Object.defineProperty(exports, 'onthisdevicechanged', { - set: function(callback) { - _addEventListener(true, THIS_DEVICE_CHANGED_EVENT, callback); - } -}); - -Object.defineProperty(exports, 'ondiscoverystopped', { - set: function(callback) { - _addEventListener(true, DISCOVERY_STOPPED_EVENT, callback); - } -}); - -exports.addEventListener = function(eventName, callback) { - return _addEventListener(false, eventName, callback); -} - -function handleEvent(msg) { - for (var id in g_listeners) { - if (g_listeners[id]['eventName'] === msg.eventName && g_listeners[id]['callback']) { - g_listeners[id]['callback'](msg.data); - } - } -} - -function handlePromise(msgObj) { - if (msgObj.data.error) { - g_async_calls[msgObj.asyncCallId].reject(msgObj.data.error); - } else { - g_async_calls[msgObj.asyncCallId].resolve(msgObj.data); - } - - delete g_async_calls[msgObj.asyncCallId]; -} - -extension.setMessageListener(function(json) { - var _msg = JSON.parse(json); - switch (_msg.eventName) { - case WIFI_STATE_CHANGED_EVENT: - case PEERS_CHANGED_EVENT: - case CONNECTION_CHANGED_EVENT: - case THIS_DEVICE_CHANGED_EVENT: - case DISCOVERY_STOPPED_EVENT: - { - handleEvent(_msg); - return; - } - default: - break; - } - handlePromise(_msg); -}); \ No newline at end of file diff --git a/runtime/android/core/src/org/xwalk/core/XWalkActivity.java b/runtime/android/core/src/org/xwalk/core/XWalkActivity.java index 852c65dd69..c6aa29010c 100644 --- a/runtime/android/core/src/org/xwalk/core/XWalkActivity.java +++ b/runtime/android/core/src/org/xwalk/core/XWalkActivity.java @@ -77,9 +77,7 @@ * *
  * <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- * <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
  * <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
- * <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
  * <uses-permission android:name="android.permission.INTERNET" />
  * <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  * 
diff --git a/runtime/android/core/src/org/xwalk/core/XWalkUpdater.java b/runtime/android/core/src/org/xwalk/core/XWalkUpdater.java index eb6d139426..a5fd896e5f 100644 --- a/runtime/android/core/src/org/xwalk/core/XWalkUpdater.java +++ b/runtime/android/core/src/org/xwalk/core/XWalkUpdater.java @@ -100,9 +100,7 @@ * *
  * <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- * <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
  * <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
- * <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
  * <uses-permission android:name="android.permission.INTERNET" />
  * <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  * 
diff --git a/runtime/android/core_internal/src/org/xwalk/core/internal/extension/BuiltinXWalkExtensions.java b/runtime/android/core_internal/src/org/xwalk/core/internal/extension/BuiltinXWalkExtensions.java index 1fa758257f..d3a0305938 100644 --- a/runtime/android/core_internal/src/org/xwalk/core/internal/extension/BuiltinXWalkExtensions.java +++ b/runtime/android/core_internal/src/org/xwalk/core/internal/extension/BuiltinXWalkExtensions.java @@ -15,7 +15,6 @@ import org.xwalk.core.internal.extension.api.launchscreen.LaunchScreenExtension; import org.xwalk.core.internal.extension.api.messaging.Messaging; import org.xwalk.core.internal.extension.api.presentation.PresentationExtension; -import org.xwalk.core.internal.extension.api.wifidirect.WifiDirect; import android.app.Activity; import android.content.Context; @@ -90,18 +89,6 @@ public static void load(Context context, Activity activity) { Log.w(TAG, "Failed to read JS API file: " + Messaging.JS_API_PATH); } } - - { - String jsApiContent = ""; - try { - jsApiContent = getExtensionJSFileContent( - context, WifiDirect.JS_API_PATH, true); - sBuiltinExtensions.put(WifiDirect.JS_API_PATH, - new WifiDirect(jsApiContent, activity)); - } catch(IOException e) { - Log.w(TAG, "Failed to read JS API file: " + WifiDirect.JS_API_PATH); - } - } } diff --git a/runtime/android/core_internal/src/org/xwalk/core/internal/extension/api/wifidirect/WifiDirect.java b/runtime/android/core_internal/src/org/xwalk/core/internal/extension/api/wifidirect/WifiDirect.java deleted file mode 100644 index 6302637499..0000000000 --- a/runtime/android/core_internal/src/org/xwalk/core/internal/extension/api/wifidirect/WifiDirect.java +++ /dev/null @@ -1,363 +0,0 @@ -// Copyright (c) 2015 Intel Corporation. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package org.xwalk.core.internal.extension.api.wifidirect; - -import android.app.Activity; -import android.content.Context; -import android.content.BroadcastReceiver; -import android.content.Intent; -import android.content.IntentFilter; -import android.net.NetworkInfo; -import android.net.wifi.p2p.WifiP2pConfig; -import android.net.wifi.p2p.WifiP2pDevice; -import android.net.wifi.p2p.WifiP2pDeviceList; -import android.net.wifi.p2p.WifiP2pInfo; -import android.net.wifi.p2p.WifiP2pManager; -import android.net.wifi.p2p.WifiP2pManager.ActionListener; -import android.net.wifi.p2p.WifiP2pManager.Channel; -import android.net.wifi.p2p.WifiP2pManager.ChannelListener; -import android.net.wifi.p2p.WifiP2pManager.ConnectionInfoListener; -import android.net.wifi.p2p.WifiP2pManager.PeerListListener; -import android.net.wifi.p2p.WifiP2pManager.GroupInfoListener; -import android.net.wifi.p2p.WifiP2pGroup; -import android.net.wifi.p2p.WifiP2pManager.Channel; -import android.net.wifi.p2p.WifiP2pManager; -import android.net.wifi.WpsInfo; -import android.util.Log; - -import org.chromium.base.ActivityState; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import org.xwalk.core.internal.extension.XWalkExtensionWithActivityStateListener; - -public class WifiDirect extends XWalkExtensionWithActivityStateListener { - public static final String JS_API_PATH = "jsapi/wifidirect_api.js"; - - private static final String TAG = "WifiDirect"; - private static final String NAME = "xwalk.experimental.wifidirect"; - - // Tags: - private static final String TAG_ASYNC_CALL_ID = "asyncCallId"; - private static final String TAG_CMD = "cmd"; - private static final String TAG_CONNECTED = "connected"; - private static final String TAG_DATA = "data"; - private static final String TAG_ENABLED = "enabled"; - private static final String TAG_ERROR = "error"; - private static final String TAG_ERROR_CODE = "errorCode"; - private static final String TAG_EVENT_NAME = "eventName"; - private static final String TAG_FALSE = "false"; - private static final String TAG_GROUP_FORMED = "groupFormed"; - private static final String TAG_IS_SERVER = "isServer"; - private static final String TAG_MAC = "MAC"; - private static final String TAG_MESSAGE = "message"; - private static final String TAG_NAME = "name"; - private static final String TAG_SERVER_IP = "serverIP"; - private static final String TAG_STATUS = "status"; - private static final String TAG_TRUE = "true"; - private static final String TAG_TYPE = "type"; - - // Commands: - private static final String CMD_CANCEL_CONNECT = "cancelConnect"; - private static final String CMD_CONNECT = "connect"; - private static final String CMD_DISCONNECT = "disconnect"; - private static final String CMD_DISCOVER_PEERS = "discoverPeers"; - private static final String CMD_GET_CONNECTION_INFO = "getConnectionInfo"; - private static final String CMD_GET_PEERS = "getPeers"; - private static final String CMD_INIT = "init"; - - // Events: - private static final String EVENT_CONNECTION_CHANGED = "connectionchanged"; - private static final String EVENT_DISCOVERY_STOPPED = "discoverystoppedevent"; - private static final String EVENT_PEERS_CHANGED = "peerschanged"; - private static final String EVENT_THIS_DEVICE_CHANGED = "thisdevicechanged"; - private static final String EVENT_WIFI_STATE_CHANGED = "wifistatechanged"; - - // States: - private static final String STATE_AVAILABLE = "available"; - private static final String STATE_CONNECTED = "connected"; - private static final String STATE_FAILED = "failed"; - private static final String STATE_INVITED = "invited"; - private static final String STATE_UNAVAILABLE = "unavailable"; - - // Errors: - private static final String ERROR_P2P_UNSUPPORTED = "WifiP2pManager.P2P_UNSUPPORTED"; - private static final String ERROR_NO_SERVICE_REQUESTS = "WifiP2pManager.NO_SERVICE_REQUESTS"; - private static final String ERROR_BUSY = "WifiP2pManager.BUSY"; - private static final String ERROR_DEFAULT = "WifiP2pManager.ERROR"; - - // Error messages: - private static final String ERROR_INVALID_CALL_NO_DATA_MSG = "Error: Invalid connect API call - data === null"; - private static final String ERROR_GENERAL_ERROR_MSG_STEM = "Android WiFi Direct error: "; - private static final String ERROR_REASON_CODE_STEM = "WifiP2pManager reasonCode: "; - - private WifiP2pManager mManager = null; - private Channel mChannel = null; - private BroadcastReceiver mReceiver = null; - private IntentFilter mIntentFilter; - private boolean mReceiverRegistered = false; - private Activity mActivity = null; - - public WifiDirect(String jsApiContent, Activity activity) { - super(NAME, jsApiContent, activity); - mActivity = activity; - } - - private WifiP2pManager.ActionListener createCallActionListener(final int instanceID, final JSONObject jsonOutput) { - return new WifiP2pManager.ActionListener() { - @Override - public void onSuccess() { - try { - jsonOutput.put(TAG_DATA, true); - } catch (JSONException e) { - printErrorMessage(e); - } - WifiDirect.this.postMessage(instanceID, jsonOutput.toString()); - } - - @Override - public void onFailure(int reasonCode) { - setError(jsonOutput, "", reasonCode); - WifiDirect.this.postMessage(instanceID, jsonOutput.toString()); - } - }; - } - - private void disconnect(final int instanceID, final JSONObject jsonOutput) { - if (mManager != null && mChannel != null) { - mManager.requestGroupInfo(mChannel, new GroupInfoListener() { - @Override - public void onGroupInfoAvailable(WifiP2pGroup group) { - if (group != null) { - mManager.removeGroup(mChannel, createCallActionListener(instanceID, jsonOutput)); - } - } - }); - } - } - - private void handleMessage(final int instanceID, String message) { - try { - JSONObject jsonInput = new JSONObject(message); - String cmd = jsonInput.getString(TAG_CMD); - final String asyncCallId = jsonInput.getString(TAG_ASYNC_CALL_ID); - - final JSONObject jsonOutput = new JSONObject(); - jsonOutput.put(TAG_ASYNC_CALL_ID, asyncCallId); - if (cmd.equals(CMD_DISCOVER_PEERS)) { - mManager.discoverPeers(mChannel, createCallActionListener(instanceID, jsonOutput)); - } else if (cmd.equals(CMD_GET_PEERS)) { - mManager.requestPeers(mChannel, new WifiP2pManager.PeerListListener() { - @Override - public void onPeersAvailable(WifiP2pDeviceList peers) { - try { - jsonOutput.put(TAG_DATA, convertListToJSON(peers)); - } catch (JSONException e) { - printErrorMessage(e); - } - WifiDirect.this.postMessage(instanceID, jsonOutput.toString()); - } - }); - } else if (cmd.equals(CMD_INIT)) { - jsonOutput.put(TAG_DATA, init()); - this.postMessage(instanceID, jsonOutput.toString()); - } else if (cmd.equals(CMD_GET_CONNECTION_INFO)) { - mManager.requestConnectionInfo(mChannel, new ConnectionInfoListener() { - @Override - public void onConnectionInfoAvailable(WifiP2pInfo info) { - try { - JSONObject data = new JSONObject(); - jsonOutput.put(TAG_DATA, data); - data.put(TAG_GROUP_FORMED, info.groupFormed); - if (info.groupFormed) { - data.put(TAG_IS_SERVER, info.isGroupOwner); - data.put(TAG_SERVER_IP, info.isGroupOwner ? "" : info.groupOwnerAddress.toString().replace("/", "")); - } - WifiDirect.this.postMessage(instanceID, jsonOutput.toString()); - } catch (JSONException e) { - printErrorMessage(e); - } - } - }); - } else if (cmd.equals(CMD_CONNECT)) { - JSONObject dev = jsonInput.getJSONObject(TAG_DATA); - if (dev == null) { - setError(jsonOutput, ERROR_INVALID_CALL_NO_DATA_MSG, 0); - WifiDirect.this.postMessage(instanceID, jsonOutput.toString()); - } else { - WifiP2pConfig config = new WifiP2pConfig(); - config.deviceAddress = dev.getString(TAG_MAC); - config.wps.setup = WpsInfo.PBC; - mManager.connect(mChannel, config, createCallActionListener(instanceID, jsonOutput)); - } - } else if (cmd.equals(CMD_CANCEL_CONNECT)) { - mManager.cancelConnect(mChannel, createCallActionListener(instanceID, jsonOutput)); - } else if (cmd.equals(CMD_DISCONNECT)) { - disconnect(instanceID, jsonOutput); - } - } catch (JSONException e) { - printErrorMessage(e); - } - } - - private JSONObject setEventData(JSONObject out, String eventName) throws JSONException { - out.put(TAG_EVENT_NAME, eventName); - JSONObject data = new JSONObject(); - out.put(TAG_DATA, data); - return data; - } - - private boolean init() { - if (mActivity == null) - return false; - mManager = (WifiP2pManager) mActivity.getSystemService(Context.WIFI_P2P_SERVICE); - mChannel = (Channel) mManager.initialize(mActivity, mActivity.getMainLooper(), null); - mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - JSONObject out = new JSONObject(); - try { - if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) { - setEventData(out, EVENT_WIFI_STATE_CHANGED).put(TAG_ENABLED, - (intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1) == WifiP2pManager.WIFI_P2P_STATE_ENABLED) ? - TAG_TRUE : TAG_FALSE); - } else if (WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) { - setEventData(out, EVENT_PEERS_CHANGED); - } else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) { - NetworkInfo networkInfo = (NetworkInfo) intent - .getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO); - setEventData(out, EVENT_CONNECTION_CHANGED).put(TAG_CONNECTED, networkInfo.isConnected()); - } else if (WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(action)) { - // Respond to this device's wifi state changing - WifiP2pDevice dev = (WifiP2pDevice)intent.getParcelableExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE); - convertDeviceToJSON(setEventData(out, EVENT_THIS_DEVICE_CHANGED), dev); - } else if (WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION.equals(action)) { - if (intent.getIntExtra(WifiP2pManager.EXTRA_DISCOVERY_STATE, -1) != WifiP2pManager.WIFI_P2P_DISCOVERY_STOPPED) - return; - setEventData(out, EVENT_DISCOVERY_STOPPED); - } - WifiDirect.this.broadcastMessage(out.toString()); - } catch (JSONException e) { - WifiDirect.this.printErrorMessage(e); - } - } - }; - //To define the filter in the BroadcastReceiver - mIntentFilter = new IntentFilter(); - mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); - mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); - mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); - mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); - mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION); - if (!mReceiverRegistered) { - mActivity.registerReceiver(mReceiver, mIntentFilter); - mReceiverRegistered = true; - } - return true; - } - - private String convertStateToString(int state) { - switch (state) { - case WifiP2pDevice.AVAILABLE: - return STATE_AVAILABLE; - case WifiP2pDevice.CONNECTED: - return STATE_CONNECTED; - case WifiP2pDevice.FAILED: - return STATE_FAILED; - case WifiP2pDevice.INVITED: - return STATE_INVITED; - case WifiP2pDevice.UNAVAILABLE: - return STATE_UNAVAILABLE; - default: - return ""; - } - } - - private void convertDeviceToJSON(JSONObject ob, WifiP2pDevice peer) throws JSONException { - ob.put(TAG_MAC, peer.deviceAddress); - ob.put(TAG_NAME, peer.deviceName); - ob.put(TAG_TYPE, peer.primaryDeviceType); - ob.put(TAG_STATUS, convertStateToString(peer.status)); - } - - private JSONArray convertListToJSON(WifiP2pDeviceList peers) throws JSONException { - JSONArray arr = new JSONArray(); - for (WifiP2pDevice peer : peers.getDeviceList()) { - JSONObject ob = new JSONObject(); - convertDeviceToJSON(ob, peer); - arr.put(ob); - } - return arr; - } - - protected void printErrorMessage(JSONException e) { - Log.e(TAG, e.toString()); - } - - private String convertReasonCodeToString(int reasonCode) { - switch(reasonCode) { - case WifiP2pManager.BUSY: - return ERROR_BUSY; - case WifiP2pManager.ERROR: - return ERROR_DEFAULT; - case WifiP2pManager.NO_SERVICE_REQUESTS: - return ERROR_NO_SERVICE_REQUESTS; - case WifiP2pManager.P2P_UNSUPPORTED: - return ERROR_P2P_UNSUPPORTED; - default: - return ERROR_REASON_CODE_STEM + reasonCode; - } - } - - protected void setError(JSONObject out, String errorMessage, int reasonCode) { - JSONObject data = new JSONObject(); - JSONObject error = new JSONObject(); - try { - out.put(TAG_DATA, data); - error.put(TAG_MESSAGE, errorMessage.isEmpty() ? ERROR_GENERAL_ERROR_MSG_STEM + convertReasonCodeToString(reasonCode) : errorMessage); - error.put(TAG_ERROR_CODE, reasonCode); - data.put(TAG_ERROR, error); - } catch (JSONException e) { - Log.e(TAG, e.toString()); - } - } - - @Override - public void onMessage(int instanceID, String message) { - if (!message.isEmpty()) { - handleMessage(instanceID, message); - } - } - - @Override - public void onActivityStateChange(Activity activity, int newState) { - switch (newState) { - case ActivityState.RESUMED: - mActivity = activity; - if (!mReceiverRegistered) { - mActivity.registerReceiver(mReceiver, mIntentFilter); - mReceiverRegistered = true; - } - break; - case ActivityState.PAUSED: - if (mReceiverRegistered) { - mActivity.unregisterReceiver(mReceiver); - mReceiverRegistered = false; - } - mActivity = null; - break; - default: - break; - } - } - - @Override - public String onSyncMessage(int instanceID, String message) { - return null; - } -} diff --git a/runtime/android/core_shell/AndroidManifest.xml b/runtime/android/core_shell/AndroidManifest.xml index 2009e0f7b1..415c8e12f8 100644 --- a/runtime/android/core_shell/AndroidManifest.xml +++ b/runtime/android/core_shell/AndroidManifest.xml @@ -34,9 +34,7 @@ - - diff --git a/xwalk_android.gypi b/xwalk_android.gypi index ccfd347941..cc7ef7ff14 100644 --- a/xwalk_android.gypi +++ b/xwalk_android.gypi @@ -232,7 +232,6 @@ '<(PRODUCT_DIR)/xwalk_runtime_lib/assets/jsapi/launch_screen_api.js', '<(PRODUCT_DIR)/xwalk_runtime_lib/assets/jsapi/messaging_api.js', '<(PRODUCT_DIR)/xwalk_runtime_lib/assets/jsapi/presentation_api.js', - '<(PRODUCT_DIR)/xwalk_runtime_lib/assets/jsapi/wifidirect_api.js', '<(PRODUCT_DIR)/xwalk_runtime_lib/assets/xwalk.pak', ], 'conditions': [ @@ -291,7 +290,6 @@ 'files': [ 'experimental/launch_screen/launch_screen_api.js', 'experimental/presentation/presentation_api.js', - 'experimental/wifidirect/wifidirect_api.js', 'runtime/android/core_internal/src/org/xwalk/core/internal/extension/api/contacts/contacts_api.js', 'runtime/android/core_internal/src/org/xwalk/core/internal/extension/api/device_capabilities/device_capabilities_api.js', 'runtime/android/core_internal/src/org/xwalk/core/internal/extension/api/messaging/messaging_api.js', diff --git a/xwalk_android_tests.gypi b/xwalk_android_tests.gypi index 5cab3d42e3..27ba4f9d9c 100644 --- a/xwalk_android_tests.gypi +++ b/xwalk_android_tests.gypi @@ -56,7 +56,6 @@ '<(PRODUCT_DIR)/xwalk_xwview/assets/jsapi/launch_screen_api.js', '<(PRODUCT_DIR)/xwalk_xwview/assets/jsapi/messaging_api.js', '<(PRODUCT_DIR)/xwalk_xwview/assets/jsapi/presentation_api.js', - '<(PRODUCT_DIR)/xwalk_xwview/assets/jsapi/wifidirect_api.js', ], 'conditions': [ ['icu_use_data_file_flag==1', { @@ -86,7 +85,6 @@ 'runtime/android/core_internal/src/org/xwalk/core/internal/extension/api/contacts/contacts_api.js', 'runtime/android/core_internal/src/org/xwalk/core/internal/extension/api/device_capabilities/device_capabilities_api.js', 'runtime/android/core_internal/src/org/xwalk/core/internal/extension/api/messaging/messaging_api.js', - 'experimental/wifidirect/wifidirect_api.js', ], }, ], @@ -342,7 +340,6 @@ '<(PRODUCT_DIR)/runtime_client_embedded_shell/assets/jsapi/launch_screen_api.js', '<(PRODUCT_DIR)/runtime_client_embedded_shell/assets/jsapi/messaging_api.js', '<(PRODUCT_DIR)/runtime_client_embedded_shell/assets/jsapi/presentation_api.js', - '<(PRODUCT_DIR)/runtime_client_embedded_shell/assets/jsapi/wifidirect_api.js', '<(PRODUCT_DIR)/runtime_client_embedded_shell/assets/manifest.json', '<(PRODUCT_DIR)/runtime_client_embedded_shell/assets/myextension/myextension.js', '<(PRODUCT_DIR)/runtime_client_embedded_shell/assets/sampapp-icon-helloworld.png', @@ -386,7 +383,6 @@ 'files': [ 'experimental/launch_screen/launch_screen_api.js', 'experimental/presentation/presentation_api.js', - 'experimental/wifidirect/wifidirect_api.js', 'runtime/android/core_internal/src/org/xwalk/core/internal/extension/api/contacts/contacts_api.js', 'runtime/android/core_internal/src/org/xwalk/core/internal/extension/api/device_capabilities/device_capabilities_api.js', 'runtime/android/core_internal/src/org/xwalk/core/internal/extension/api/messaging/messaging_api.js',