diff --git a/Ant-Manager/AndroidManifest.xml b/Ant-Manager/AndroidManifest.xml index 4a0a6880..f1851b1c 100755 --- a/Ant-Manager/AndroidManifest.xml +++ b/Ant-Manager/AndroidManifest.xml @@ -55,8 +55,8 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="fill_parent" + android:layout_height="match_parent" + + tools:context="com.ant.graphtest.MainActivity"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Ant-Manager/res/layout/activity_sensor_viewer.xml b/Ant-Manager/res/layout/activity_sensor_viewer.xml index 5738805c..d56e1eb8 100644 --- a/Ant-Manager/res/layout/activity_sensor_viewer.xml +++ b/Ant-Manager/res/layout/activity_sensor_viewer.xml @@ -20,20 +20,19 @@ android:orientation="vertical"> + android:layout_marginLeft="0dp" /> @@ -44,15 +43,14 @@ android:orientation="vertical" > - * - * 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. - */ - -import android.os.Bundle; -import android.view.MenuItem; - -import com.ant.ant_manager.R; - -public class BasicSensorViewerActivity extends SensorViewerActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - setContentView(R.layout.activity_sensor_viewer); - super.onCreate(savedInstanceState); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - return super.onOptionsItemSelected(item); - } - - @Override - public void onResume() { - super.onResume(); - } - - @Override - public void onBackPressed() { - super.onBackPressed(); - } - - @Override - public void onPause() { - super.onPause(); - } - - @Override - public void onMessageFromTarget(String listenerName, String message) { - // Not implemented - } -} \ No newline at end of file diff --git a/Ant-Manager/src/com/ant/ant_manager/view/MotionClassifierActivity.java b/Ant-Manager/src/com/ant/ant_manager/view/MotionClassifierActivity.java index f4560703..7fc6b8cf 100644 --- a/Ant-Manager/src/com/ant/ant_manager/view/MotionClassifierActivity.java +++ b/Ant-Manager/src/com/ant/ant_manager/view/MotionClassifierActivity.java @@ -17,32 +17,157 @@ * limitations under the License. */ +import android.annotation.SuppressLint; +import android.app.ActionBar; +import android.app.Activity; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.ServiceConnection; +import android.graphics.Color; import android.os.Bundle; +import android.os.Handler; +import android.os.IBinder; +import android.util.Log; import android.view.MenuItem; import android.widget.TextView; import com.ant.ant_manager.R; +import com.ant.ant_manager.controller.ANTControllerBroadcastReceiver; +import com.ant.ant_manager.controller.ANTControllerService; +import com.jjoe64.graphview.GraphView; +import com.jjoe64.graphview.series.DataPoint; +import com.jjoe64.graphview.series.LineGraphSeries; + +import java.util.ArrayList; + +public class MotionClassifierActivity extends Activity { + // ANTControllerService + private ANTControllerService mControllerServiceStub = null; + private PrivateControllerBroadcastReceiver mControllerBroadcastReceiver; + + // Intent + public static final String INTENT_KEY_APP_ID = "appId"; + + private int mAppId; + + private final Handler mHandler = new Handler(); + + private Runnable mTimer2; + + private LineGraphSeries mSeries2; + private double graph2LastXValue = 5d; + + ArrayList mSensorDataList = new ArrayList<>(); + int numSensors = 3; + String[] mSensorNameList = {"Accelerometer X", "Accelerometer Y", "Accelerometer Z"}; + int[] mSensorGraphViewList = {R.id.accXGraphView, R.id.accYGraphView, R.id.accZGraphView}; + int[] mSensorTextViewList = {R.id.accXTextView, R.id.accYTextView, R.id.accZTextView}; + int[] mSensorGraphLineColor = {Color.RED, Color.BLUE, Color.WHITE}; + + private final String TAG = "SensorViewer"; + private boolean mIsUIReady = false; + + protected void initializeSensorDataList() { + for (int i = 0; i < numSensors; i++) { + String sensorName = this.mSensorNameList[i]; + GraphView sensorGraphView = (GraphView) findViewById(this.mSensorGraphViewList[i]); + TextView sensorTextView = (TextView) findViewById(this.mSensorTextViewList[i]); + SensorData newSensorData = new SensorData(-20, 20, sensorName, sensorGraphView, + sensorTextView); + this.mSensorDataList.add(newSensorData); + newSensorData.setGraphLineColor(this.mSensorGraphLineColor[i]); + } + } -public class MotionClassifierActivity extends SensorViewerActivity { @Override protected void onCreate(Bundle savedInstanceState) { - setContentView(R.layout.activity_motion_classifier); super.onCreate(savedInstanceState); + setContentView(R.layout.activity_motion_classifier); + + // Parameters + Intent intent = this.getIntent(); + this.mAppId = intent.getIntExtra(INTENT_KEY_APP_ID, -1); + if (this.mAppId < 0) { + Log.e(TAG, "Invalid application id!"); + this.finish(); + } + + ActionBar actionBar = getActionBar(); + actionBar.setTitle("Motion Classifier"); + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setLogo(R.drawable.motionclassifier); + actionBar.setDisplayUseLogoEnabled(true); + + this.initializeSensorDataList(); } @Override protected void onDestroy() { super.onDestroy(); + + // Terminate JavaScript SensorViewer App + this.mControllerServiceStub.terminateAppOneWay(this.mAppId); + + // Disconnect Controller Service + this.disconnectControllerService(); } @Override public boolean onOptionsItemSelected(MenuItem item) { - return super.onOptionsItemSelected(item); + switch (item.getItemId()) { + case android.R.id.home: + this.finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + public void onSensorViewerMessage(String message) { + String[] tokens = message.split("\\s+"); + if (tokens.length < 4) { + Log.e(TAG, "# of tokens is too small! : " + message); + return; + } + + if (this.mIsUIReady) { + String classified = tokens[0]; + TextView classifiedTextView = (TextView) findViewById(R.id.textViewClassified); + classifiedTextView.setText(classified); + for (int i = 0; i < this.numSensors; i++) { + Double sensorValue = Double.parseDouble(tokens[i + 1]); + SensorData sensorData = this.mSensorDataList.get(i); + sensorData.setCurrentValue(sensorValue); + sensorData.setEnabled(true); + } + } } @Override public void onResume() { super.onResume(); + + connectControllerService(); + + mTimer2 = new Runnable() { + @Override + public void run() { + graph2LastXValue += 1d; + for (int i = 0; i < numSensors; i++) { + SensorData sensorData = mSensorDataList.get(i); + Double sensorValue = sensorData.getCurrentValue(); + sensorData.appendData(new DataPoint(graph2LastXValue, sensorValue), true, + sensorData.getMax()); + } + mHandler.postDelayed(this, 200); + } + + }; + mHandler.postDelayed(mTimer2, 1000); + + this.mIsUIReady = true; } @Override @@ -53,13 +178,143 @@ public void onBackPressed() { @Override public void onPause() { super.onPause(); + mControllerServiceStub.terminateAppOneWay(this.mAppId); + mHandler.removeCallbacks(mTimer2); + this.mIsUIReady = false; } - @Override - public void onMessageFromTarget(String listenerName, String message) { - if (listenerName.compareTo("motionclassifier") == 0) { - TextView textViewClassified = (TextView) this.findViewById(R.id.textViewClassified); - textViewClassified.setText("Result: " + message); + private void connectControllerService() { + Intent serviceIntent = new Intent(this, ANTControllerService.class); + this.bindService(serviceIntent, this.mControllerServiceConnection, Context + .BIND_AUTO_CREATE); + } + + private void disconnectControllerService() { + if (this.mControllerServiceConnection != null) + this.unbindService(this.mControllerServiceConnection); + if (this.mControllerBroadcastReceiver != null) + this.unregisterReceiver(this.mControllerBroadcastReceiver); + } + + private ServiceConnection mControllerServiceConnection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName componentName, IBinder inputBinder) { + ANTControllerService.ControllerBinder serviceBinder = (ANTControllerService + .ControllerBinder) inputBinder; + mControllerServiceStub = serviceBinder.getService(); + + // Set BroadcastReceiver + IntentFilter broadcastIntentFilter = new IntentFilter(); + broadcastIntentFilter.addAction(ANTControllerBroadcastReceiver.ACTION); + mControllerBroadcastReceiver = new PrivateControllerBroadcastReceiver(); + registerReceiver(mControllerBroadcastReceiver, broadcastIntentFilter); + + // Initialize connection with camera viewer + mControllerServiceStub.launchAppOneWay(mAppId); + } + + @Override + public void onServiceDisconnected(ComponentName componentName) { + Log.d(TAG, "onServiceDisconnected()"); + unregisterReceiver(mControllerBroadcastReceiver); + mControllerServiceStub = null; + } + }; + + class PrivateControllerBroadcastReceiver extends ANTControllerBroadcastReceiver { + PrivateControllerBroadcastReceiver() { + this.setOnReceivedSensorDataListener(new OnReceivedDataFromTarget() { + @Override + public void onReceivedDataFromTarget(String listenerName, String data) { + Log.d(TAG, "Message coming for " + listenerName + ": " + data); + if (listenerName.compareToIgnoreCase("motionclassifier") == 0) { + onSensorViewerMessage(data); + } + } + }); + } + } + + class SensorData { + private int mMin; + private int mMax; + private double mCurrentValue; + private String mSensorName; + + private GraphView mGraphView; + private TextView mTextView; + + private LineGraphSeries mLineGraphSeries; + private int mUniqueColor; + private boolean mIsEnabled = false; + + SensorData(int min, int max, String sensorName, GraphView graphView, TextView textView) { + this.mMin = min; + this.mMax = max; + this.mGraphView = graphView; + this.mCurrentValue = 0.0; + this.mSensorName = sensorName; + this.mTextView = textView; + this.mTextView.setText(sensorName + "(Loading...)"); + mLineGraphSeries = new LineGraphSeries(); + + graphView.addSeries(mLineGraphSeries); + graphView.getViewport().setXAxisBoundsManual(false); + graphView.getViewport().setYAxisBoundsManual(true); + graphView.getViewport().setMinY(min); + graphView.getViewport().setMaxY(max); + + mLineGraphSeries.setThickness(5); + } + + void setCurrentValue(double newValue) { + this.mCurrentValue = newValue; + } + + double getCurrentValue() { + return this.mCurrentValue; + } + + void appendData(DataPoint dataPoint, boolean scrollToEnd, int maxDataPoints) { + mLineGraphSeries.appendData(dataPoint, scrollToEnd, maxDataPoints); + } + + int getMax() { + return this.mMax; + } + + String getSensorName() { + return this.mSensorName; + } + + void setTextViewColor(int color) { + mTextView.setTextColor(color); + } + + void setGraphLineColor(int color) { + this.mUniqueColor = color; + this.updateView(); + } + + void setEnabled(boolean isEnabled) { + this.mIsEnabled = isEnabled; + this.updateView(); + } + + private void updateView() { + runOnUiThread(new Runnable() { + @SuppressLint("SetTextI18n") + @Override + public void run() { + if (mIsEnabled) { + mLineGraphSeries.setColor(mUniqueColor); + mTextView.setText(getSensorName()); + } else { + mLineGraphSeries.setColor(Color.GRAY); + mTextView.setText(getSensorName() + " (Loading...)"); + } + } + }); } } } \ No newline at end of file diff --git a/Ant-Manager/src/com/ant/ant_manager/view/SensorViewerActivity.java b/Ant-Manager/src/com/ant/ant_manager/view/SensorViewerActivity.java index 3af2a187..412d5406 100644 --- a/Ant-Manager/src/com/ant/ant_manager/view/SensorViewerActivity.java +++ b/Ant-Manager/src/com/ant/ant_manager/view/SensorViewerActivity.java @@ -43,9 +43,7 @@ import java.util.ArrayList; -import static com.ant.ant_manager.R.drawable.sensor; - -abstract public class SensorViewerActivity extends Activity { +public class SensorViewerActivity extends Activity { // ANTControllerService private ANTControllerService mControllerServiceStub = null; private PrivateControllerBroadcastReceiver mControllerBroadcastReceiver; @@ -66,10 +64,12 @@ abstract public class SensorViewerActivity extends Activity { int numSensors = 7; String[] mSensorNameList = {"Touch", "Accelerometer", "Motion", "Sound", "Light", "Vibration", "Temperature"}; - int[] mSensorGraphViewList = {R.id.graph1, R.id.graph2, R.id.graph3, R.id.graph4, R.id - .graph5, R.id.graph6, R.id.graph7}; - int[] mSensorTextViewList = {R.id.textView11, R.id.textView22, R.id.textView33, R.id - .textView4, R.id.textView5, R.id.textView6, R.id.textView7}; + int[] mSensorGraphViewList = {R.id.touchSensorGraphView, R.id.accSensorGraphView, R.id + .motionSensorGraphView, R.id.soundSensorGraphView, R.id.lightSensorGraphView, R.id + .vibSensorGraphView, R.id.tempSensorGraphView}; + int[] mSensorTextViewList = {R.id.touchSensorTextView, R.id.accSensorTextView, R.id + .motionSensorTextView, R.id.soundSensorTextView, R.id.lightSensorTextView, R.id + .vibSensorTextView, R.id.tempSensorTextView}; int[] mSensorGraphLineColor = {Color.RED, Color.BLUE, Color.WHITE, Color.YELLOW, Color.WHITE, Color.BLUE, Color.YELLOW}; @@ -91,6 +91,7 @@ protected void initializeSensorDataList() { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setContentView(R.layout.activity_sensor_viewer); // Parameters Intent intent = this.getIntent(); @@ -103,7 +104,7 @@ protected void onCreate(Bundle savedInstanceState) { ActionBar actionBar = getActionBar(); actionBar.setTitle("Sensor Viewer"); actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setLogo(sensor); + actionBar.setLogo(R.drawable.sensor); actionBar.setDisplayUseLogoEnabled(true); this.initializeSensorDataList(); @@ -131,8 +132,6 @@ public boolean onOptionsItemSelected(MenuItem item) { } } - abstract public void onMessageFromTarget(String listenerName, String message); - public void onSensorViewerMessage(String message) { String[] tokens = message.split("\\s+"); if (tokens.length < 7) { @@ -235,12 +234,10 @@ class PrivateControllerBroadcastReceiver extends ANTControllerBroadcastReceiver this.setOnReceivedSensorDataListener(new OnReceivedDataFromTarget() { @Override public void onReceivedDataFromTarget(String listenerName, String data) { - Log.d(TAG, "Message coming for " + listenerName + ": " + data + " " + - listenerName.compareTo("sensorviewer") + "!!!"); + Log.d(TAG, "Message coming for " + listenerName + ": " + data); if (listenerName.compareToIgnoreCase("sensorviewer") == 0) { onSensorViewerMessage(data); } - onMessageFromTarget(listenerName, data); } }); } @@ -266,7 +263,7 @@ class SensorData { this.mCurrentValue = 0.0; this.mSensorName = sensorName; this.mTextView = textView; - this.mTextView.setText(sensorName + "(Disconnected)"); + this.mTextView.setText(sensorName + "(Loading...)"); mLineGraphSeries = new LineGraphSeries(); graphView.addSeries(mLineGraphSeries); @@ -322,7 +319,7 @@ public void run() { mTextView.setText(getSensorName()); } else { mLineGraphSeries.setColor(Color.GRAY); - mTextView.setText(getSensorName() + " (Disconnected)"); + mTextView.setText(getSensorName() + " (Loading...)"); } } }); diff --git a/Ant-Manager/src/com/ant/ant_manager/view/main/SensorViewerMainIcon.java b/Ant-Manager/src/com/ant/ant_manager/view/main/SensorViewerMainIcon.java index 99714d8e..1c83f179 100644 --- a/Ant-Manager/src/com/ant/ant_manager/view/main/SensorViewerMainIcon.java +++ b/Ant-Manager/src/com/ant/ant_manager/view/main/SensorViewerMainIcon.java @@ -5,8 +5,8 @@ import android.widget.Toast; import com.ant.ant_manager.R; -import com.ant.ant_manager.view.BasicSensorViewerActivity; import com.ant.ant_manager.view.MainActivity; +import com.ant.ant_manager.view.SensorViewerActivity; /* Copyright (c) 2017 SKKU ESLAB, and contributors. All rights reserved. * @@ -40,8 +40,8 @@ public void onClick() { "connected", Toast.LENGTH_SHORT).show(); return; } - Intent intent = new Intent(this.mOwnerActivity, BasicSensorViewerActivity.class); - intent.putExtra(BasicSensorViewerActivity.INTENT_KEY_APP_ID, this.mAppId); + Intent intent = new Intent(this.mOwnerActivity, SensorViewerActivity.class); + intent.putExtra(SensorViewerActivity.INTENT_KEY_APP_ID, this.mAppId); mOwnerActivity.startActivity(intent); } diff --git a/Ant-Manager/src/com/ant/cmfw/devicecontrollers/wifidirect/WifiDirectDeviceController.java b/Ant-Manager/src/com/ant/cmfw/devicecontrollers/wifidirect/WifiDirectDeviceController.java index 731a2cb1..9cb36522 100644 --- a/Ant-Manager/src/com/ant/cmfw/devicecontrollers/wifidirect/WifiDirectDeviceController.java +++ b/Ant-Manager/src/com/ant/cmfw/devicecontrollers/wifidirect/WifiDirectDeviceController.java @@ -24,6 +24,8 @@ import android.content.Intent; import android.content.IntentFilter; import android.net.NetworkInfo; +import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiManager; import android.net.wifi.WpsInfo; import android.net.wifi.p2p.WifiP2pConfig; import android.net.wifi.p2p.WifiP2pDevice; @@ -32,6 +34,7 @@ import android.util.Log; import java.util.ArrayList; +import java.util.List; public class WifiDirectDeviceController { static private String TAG = "WFDController"; @@ -84,14 +87,45 @@ private class ConnectProcedure { private Integer mConnectingResultListenerLock = 0; private boolean mIsConnecting = false; + private boolean mIsWifiDirectMode = true; + public void start(WifiDirectConnectingResultListener connectingResultListener) { this.mConnectingResultListener = connectingResultListener; - this.discoverPeers(); + if (mIsWifiDirectMode) { + this.discoverPeers(); + } else { + this.connectWiFiAP(); + } + } + + public void connectWiFiAP() { + String networkSSID = "DIRECT-CS-ANT"; + String networkPass = "12345670"; + + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.SSID = "\"" + networkSSID + "\""; + wifiConfig.preSharedKey = "\"" + networkPass + "\""; + + WifiManager wifiManager = (WifiManager) mService.getApplicationContext() + .getSystemService(Context.WIFI_SERVICE); + wifiManager.addNetwork(wifiConfig); + + List foundConfigs = wifiManager.getConfiguredNetworks(); + for (WifiConfiguration foundConfig : foundConfigs) { + if (foundConfig.SSID != null & foundConfig.SSID.equals("\"" + networkSSID + "\"")) { + wifiManager.disconnect(); + wifiManager.enableNetwork(foundConfig.networkId, true); + wifiManager.reconnect(); + this.onSuccess(); + break; + } + } + this.onFail(); } + // Step 1. Discover peers private void discoverPeers() { - // Step 1. Discover peers IntentFilter wifiP2PIntentFilter; wifiP2PIntentFilter = new IntentFilter(); wifiP2PIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); @@ -122,8 +156,8 @@ public void onReceive(Context context, Intent intent) { } } + // Step 2. Request peer list private void onPeerChanged() { - // Step 2. Request peer list Log.d(TAG, "Request peer list"); mWifiP2pManager.requestPeers(mWifiP2pManagerChannel, new WifiDirectPeerListListener()); } @@ -135,9 +169,10 @@ public void onPeersAvailable(WifiP2pDeviceList peerDeviceList) { } } + // Step 3. Check the given peer list private void onPeerListReceived(WifiP2pDeviceList peerDeviceList) { - // Prevent duplicated connection tries - if(this.mIsConnecting) { + // Step 3-1. Drop duplicated connection tries + if (this.mIsConnecting) { return; } else { Log.d(TAG, "Peer List Received"); @@ -151,16 +186,15 @@ private void onPeerListReceived(WifiP2pDeviceList peerDeviceList) { return; } - // Step 3. Check if there is peer device that we want + // Step 3-2. Check if there is peer device that we want for (WifiP2pDevice peerDevice : peerDeviceList.getDeviceList()) { if (peerDevice.deviceName.compareTo(mWifiDirectName) == 0) { - Log.d(TAG, "Found Wi-fi Direct device: " + mWifiDirectName + " / " + - peerDevice.deviceAddress); + Log.d(TAG, "Found Wi-fi peer device: name=" + mWifiDirectName + " / address=" + + peerDevice.deviceAddress + " / status=" + peerDevice.status); if (peerDevice.status == WifiP2pDevice.AVAILABLE || peerDevice.status == WifiP2pDevice.CONNECTED || peerDevice.status == WifiP2pDevice.INVITED) { Log.d(TAG, "Connecting Wi-fi Direct device: " + mWifiDirectName); requestConnection(peerDevice); - mWifiP2pManager.stopPeerDiscovery(mWifiP2pManagerChannel, null); } else { Log.d(TAG, "Not yet initiated: " + mWifiDirectName + " / " + peerDevice .status); @@ -173,15 +207,14 @@ private void onPeerListReceived(WifiP2pDeviceList peerDeviceList) { this.mIsConnecting = false; } + // Step 4. Request for connecting to the peer device private void requestConnection(WifiP2pDevice peerDevice) { - final WifiP2pDevice kPeerDevice = peerDevice; - // Step 4. Request for connecting to the peer device WifiP2pConfig wifiP2pConfig = new WifiP2pConfig(); - wifiP2pConfig.deviceAddress = kPeerDevice.deviceAddress; - if (kPeerDevice.wpsPbcSupported()) { + wifiP2pConfig.deviceAddress = peerDevice.deviceAddress; + if (peerDevice.wpsPbcSupported()) { wifiP2pConfig.wps.setup = WpsInfo.PBC; Log.d(TAG, "WPS: PBC"); - } else if (kPeerDevice.wpsKeypadSupported()) { + } else if (peerDevice.wpsKeypadSupported()) { wifiP2pConfig.wps.setup = WpsInfo.KEYPAD; wifiP2pConfig.wps.pin = "12345670"; Log.d(TAG, "WPS:KeyPad"); @@ -190,7 +223,10 @@ private void requestConnection(WifiP2pDevice peerDevice) { Log.d(TAG, "WPS:Display"); } - Log.d(TAG, "Request to connect Wi-fi connection"); + // Start to watch Bluetooth device's status + mState.startToWatchDeviceState(); + + Log.d(TAG, "Request to connect Wi-fi Direct connection"); mWifiP2pManager.connect(mWifiP2pManagerChannel, wifiP2pConfig, new WifiP2pManager .ActionListener() { @Override @@ -198,6 +234,7 @@ public void onSuccess() { new Thread() { @Override public void run() { + Log.d(TAG, "Wi-fi Direct Connection Success"); ConnectProcedure.this.onSuccess(); } }.start(); @@ -205,7 +242,7 @@ public void run() { @Override public void onFailure(int reason) { - onFail(); + Log.d(TAG, "Wi-fi Direct Connection Fail"); } }); } @@ -249,7 +286,7 @@ public void transitToConnected() { this.mIsConnected = true; // Start to watch Bluetooth device's status - this.startToWatchDeviceState(); + //this.startToWatchDeviceState(); // Notify Wi-fi direct device connection event to listeners for (WifiDirectDeviceStateListener listener : this.mDeviceStateListeners) { @@ -269,7 +306,7 @@ public void transitToDisconnected() { } } - private void startToWatchDeviceState() { + public void startToWatchDeviceState() { IntentFilter filter = new IntentFilter(); filter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); this.mWifiDirectDeviceStatusReceiver = new WifiDirectDeviceStatusReceiver(); @@ -291,9 +328,13 @@ public void onReceive(Context context, Intent intent) { if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.compareTo(action) == 0) { NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra (WifiP2pManager.EXTRA_NETWORK_INFO); - if (!networkInfo.isConnectedOrConnecting() || !networkInfo.isAvailable()) { - transitToDisconnected(); - } + Log.d(TAG, "Wi-fi Direct state change listener: Android-side state=" + + networkInfo.getState()); +// if (!networkInfo.isConnectedOrConnecting() || !networkInfo.isAvailable()) { +// Log.d(TAG, "Transit wi-fi direct state to disconnected: Android-side " + +// "state=" + networkInfo.getState()); +// transitToDisconnected(); +// } } } } diff --git a/Ant-Manager/src/com/ant/cmfw/service/CommChannelService.java b/Ant-Manager/src/com/ant/cmfw/service/CommChannelService.java index 02075a80..8f724d98 100644 --- a/Ant-Manager/src/com/ant/cmfw/service/CommChannelService.java +++ b/Ant-Manager/src/com/ant/cmfw/service/CommChannelService.java @@ -412,7 +412,7 @@ public void onConnectingWifiDirectDeviceFail() { private void openLargeDataPort() { // (Enable Largedata) Step 3. Open largedata port - int kSleepMillisecs = 500; + int kSleepMillisecs = 1000; int kMaxTries = 10; boolean isOpeningSuccess = false; int tries = 0; @@ -451,7 +451,7 @@ private void onSuccess() { } private void onFail() { - disableLargeDataMode(); + //disableLargeDataMode(); } } @@ -501,7 +501,7 @@ public void run() { Log.d(TAG, "No users detected for large data port over " + kThresholdMillisecs + " ms."); - disableLargeDataMode(); + //disableLargeDataMode(); } }