From 788988d4e66c29c1ccfe62e1f984dafda31136c0 Mon Sep 17 00:00:00 2001 From: lankamadan Date: Thu, 17 Sep 2015 15:49:05 +0900 Subject: [PATCH] Fixed SoftAP device removal notifications - SoftAP notifications for unavailable device is avoided - Remove unnecessary file Change-Id: Ia4eb79adf5f2d767eed04f1173c1f35372076a1a Signed-off-by: lankamadan Reviewed-on: https://gerrit.iotivity.org/gerrit/2619 Tested-by: jenkins-iotivity --- .../EasySetup/app/src/main/AndroidManifest.xml | 9 ---- .../service/easysetup/core/BleConnection.java | 2 +- .../service/easysetup/core/EasySetupService.java | 35 +++++++++---- .../impl/EnrolleeDeviceBLEOnBoarding.java | 4 +- .../impl/EnrolleeDeviceWiFiOnboarding.java | 1 + .../easysetup/mediator/OnBoardEnrollee.java | 57 --------------------- .../easysetup/mediator/ip/WiFiSoftAPManager.java | 59 ++++++++++++---------- .../sdk/mediator/src/provisioninghandler.cpp | 8 ++- 8 files changed, 68 insertions(+), 107 deletions(-) mode change 100644 => 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/BleConnection.java mode change 100644 => 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceBLEOnBoarding.java delete mode 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardEnrollee.java diff --git a/service/easy-setup/sampleapp/android/EasySetup/app/src/main/AndroidManifest.xml b/service/easy-setup/sampleapp/android/EasySetup/app/src/main/AndroidManifest.xml index 07003ee..8c52513 100755 --- a/service/easy-setup/sampleapp/android/EasySetup/app/src/main/AndroidManifest.xml +++ b/service/easy-setup/sampleapp/android/EasySetup/app/src/main/AndroidManifest.xml @@ -40,15 +40,6 @@ - - - - - - - diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/BleConnection.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/BleConnection.java old mode 100644 new mode 100755 index bfb3483..8b90f80 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/BleConnection.java +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/BleConnection.java @@ -19,7 +19,7 @@ //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= package org.iotivity.service.easysetup.core; -public class BleConnection implements ConnectionInterface { +public class BleConnection implements OnBoardingConnection { private boolean mIsConnected; private String mServiceUUID; diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupService.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupService.java index e0ed145..4d5fac8 100755 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupService.java +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupService.java @@ -86,6 +86,7 @@ public class EasySetupService { */ public void finish() { + //Native Api call to reset OIC stack if(mProvisionEnrolleeInstance != null) { @@ -143,11 +144,26 @@ public class EasySetupService { * @param enrolleedevice Device to be enrolled in network */ public synchronized void stopSetup(EnrolleeDevice enrolleedevice) { - enrolleedevice.stopOnBoardingProcess(); - mEnrolleeDeviceList.remove(enrolleedevice); - - //Native Api call to stop on-going enrolling process for the enrolling device - EasySetupManager.getInstance().stopEnrolleeProvisioning(enrolleedevice.mOnBoardingConfig.getConnType().getValue()); + if(enrolleedevice.mState == EnrolleeState.DEVICE_ON_BOARDING_STATE) { + if(mEnrolleeDeviceList.contains(enrolleedevice)) { + Log.i(TAG, "stopOnBoardingProcess for enrolleedevice"); + enrolleedevice.stopOnBoardingProcess(); + mEnrolleeDeviceList.remove(enrolleedevice); + } + } + else if(enrolleedevice.mState == EnrolleeState.DEVICE_PROVISIONING_STATE) + { + if(mEnrolleeDeviceList.contains(enrolleedevice)) { + Log.i(TAG, "stopOnBoardingProcess for enrolleedevice"); + enrolleedevice.stopOnBoardingProcess(); + + Log.i(TAG, "stopEnrolleeProvisioning for enrolleedevice"); + //Native Api call to stop on-going enrolling process for the enrolling device + EasySetupManager.getInstance().stopEnrolleeProvisioning(enrolleedevice + .mOnBoardingConfig.getConnType().getValue()); + mEnrolleeDeviceList.remove(enrolleedevice); + } + } } public synchronized void getEnrolleeDevice(OnBoardingConfig connType) { @@ -164,10 +180,11 @@ public class EasySetupService { @Override public void onFinished(EnrolleeDevice enrolledevice) { - //if(mEnrolleeDeviceList.contains(enrolledevice)) { - Log.i(TAG, "onFinished() is received " + enrolledevice.isSetupSuccessful()); - mCallback.onFinished(enrolledevice); - // } + if(mEnrolleeDeviceList.contains(enrolledevice)) { + Log.i(TAG, "onFinished() is received " + enrolledevice.isSetupSuccessful()); + mCallback.onFinished(enrolledevice); + mEnrolleeDeviceList.remove(enrolledevice); + } } } diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceBLEOnBoarding.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceBLEOnBoarding.java old mode 100644 new mode 100755 index 3fb508e..1e74def --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceBLEOnBoarding.java +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceBLEOnBoarding.java @@ -23,7 +23,7 @@ import android.content.Context; import android.util.Log; import org.iotivity.service.easysetup.core.BleConnection; -import org.iotivity.service.easysetup.core.ConnectionInterface; +import org.iotivity.service.easysetup.core.OnBoardingConnection; import org.iotivity.service.easysetup.core.EnrolleeDevice; import org.iotivity.service.easysetup.core.EnrolleeState; import org.iotivity.service.easysetup.core.OnBoardingConfig; @@ -110,7 +110,7 @@ public class EnrolleeDeviceBLEOnBoarding extends EnrolleeDevice { } @Override - protected void startProvisioningProcess(ConnectionInterface conn) { + protected void startProvisioningProcess(OnBoardingConnection conn) { Log.i("start provisioning BLE", mProvConfig.getConnType() + ""); diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceWiFiOnboarding.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceWiFiOnboarding.java index e985571..e7a88e4 100755 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceWiFiOnboarding.java +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceWiFiOnboarding.java @@ -61,6 +61,7 @@ public class EnrolleeDeviceWiFiOnboarding extends EnrolleeDevice { @Override public void deviceOnBoardingStatus(EnrolleeInfo enrolleStatus) { + myTimer.cancel(); Log.d("ESSoftAPOnBoarding", "Entered"); if (mState == EnrolleeState.DEVICE_ON_BOARDING_STATE) { Log.d("ESSoftAPOnBoarding", "Device in OnBoarding State"); diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardEnrollee.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardEnrollee.java deleted file mode 100755 index e926bf2..0000000 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardEnrollee.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * *************************************************************** - *

- * Copyright 2015 Samsung Electronics All Rights Reserved. - *

- *

- *

- * 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. - *

- * **************************************************************** - */ -package org.iotivity.service.easysetup.mediator; - -import android.content.Context; -import android.net.wifi.WifiConfiguration; - - -import org.iotivity.service.easysetup.mediator.ip.WiFiSoftAPManager; - -public class OnBoardEnrollee { - WiFiSoftAPManager wifiSoftAPManager; - IOnBoardingStatus deviceScanListener; - - /** - * Constructor for OnBoardEnrollee. Constructs a new OnBoardEnrollee. - */ - public OnBoardEnrollee(Context context) { - wifiSoftAPManager = new WiFiSoftAPManager(context); - } - - public void registerOnBoardingStatusHandler( - IOnBoardingStatus deviceScanListener) { - this.deviceScanListener = deviceScanListener; - } - - public void startDeviceScan() { - wifiSoftAPManager.getClientList(this.deviceScanListener, 300); - } - - public void enableWiFiAP(WifiConfiguration netConfig, boolean enabled) { - wifiSoftAPManager.setWifiApEnabled(netConfig, true); - } - - public void disableWiFiAP() { - wifiSoftAPManager.setWifiApEnabled(null, false); - } -} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPManager.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPManager.java index f517b69..df6da82 100755 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPManager.java +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPManager.java @@ -88,14 +88,15 @@ public class WiFiSoftAPManager { * If the device entry is found in the device, as application is already notified it will * continue */ - private synchronized boolean CheckForDeviceEntryAndNotify(String ipAddr, + private boolean CheckForDeviceEntryAndNotify(String ipAddr, String macAddr, boolean isReachable) { final EnrolleeInfo result = new EnrolleeInfo(); boolean deviceAddedToList = false; if (appNotification.size() > 0) { for (EnrolleeOnBoardingInfo ipDeviceOnBoardingNotification : appNotification) { - EnrolleeOnBoardingInfo ipEnrolleeDevice = (EnrolleeOnBoardingInfo) ipDeviceOnBoardingNotification; + EnrolleeOnBoardingInfo ipEnrolleeDevice = (EnrolleeOnBoardingInfo) + ipDeviceOnBoardingNotification; boolean macAddressComparison = ipEnrolleeDevice.getHWAddr().equalsIgnoreCase( macAddr) ? true : false; @@ -119,14 +120,14 @@ public class WiFiSoftAPManager { .remove(ipDeviceOnBoardingNotification); if (isReachable) { appNotification - .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, + .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", + isReachable, false, true)); - } else { - appNotification - .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, - true, false)); + } else { + //This case will happen during the transition from connected to + // disconneted. This case need not be notified to application. + // Notifying this state will cause failure of OnBoarding } - NotifyApplication(result); return true; } @@ -137,17 +138,17 @@ public class WiFiSoftAPManager { appNotification .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, false, true)); - } else { - appNotification - .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, true, - false)); - } - result.setIpAddr(ipAddr); - result.setHWAddr(macAddr); - result.setReachable(isReachable); + result.setIpAddr(ipAddr); + result.setHWAddr(macAddr); + result.setReachable(isReachable); - NotifyApplication(result); + NotifyApplication(result); + } else { + //This case will happen for the first time device is listed, but reachability + // is false. This case need not be notified to application. Notifying this + // state will cause failure of OnBoarding + } return true; } } else { @@ -155,17 +156,17 @@ public class WiFiSoftAPManager { appNotification .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, false, true)); + result.setIpAddr(ipAddr); + result.setHWAddr(macAddr); + result.setReachable(isReachable); + + NotifyApplication(result); } else { - appNotification - .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, true, - false)); + //This case will happen for the first time device is listed, but + // reachability is false. This case need not be notified to + // application. Notifying this state will cause failure of OnBoarding } - result.setIpAddr(ipAddr); - result.setHWAddr(macAddr); - result.setReachable(isReachable); - - NotifyApplication(result); return true; } return false; @@ -255,8 +256,11 @@ public class WiFiSoftAPManager { * @param finishListener Interface called when the scan method finishes * @param reachableTimeout Reachable Timeout in miliseconds */ - public void getClientList(IOnBoardingStatus finishListener, final int reachableTimeout) { + public synchronized void getClientList(IOnBoardingStatus finishListener, final int + reachableTimeout) { this.finishListener = finishListener; + //Clearing the scan list for providing u + appNotification.clear(); Runnable runnable = new Runnable() { public void run() { Log.i(TAG, "Scanning enrolling device in the network" ); @@ -333,7 +337,8 @@ public class WiFiSoftAPManager { }; mainHandler.post(myRunnable); */ - Log.i(TAG, "Scanning is finished with result, IP : " + result.getIpAddr() + "Notifying to Application"); + Log.i(TAG, "Scanning is finished with result, IP : " + result.getIpAddr() + "Notifying " + + "to Application"); finishListener.deviceOnBoardingStatus(result); } diff --git a/service/easy-setup/sdk/mediator/src/provisioninghandler.cpp b/service/easy-setup/sdk/mediator/src/provisioninghandler.cpp index 52fc9e3..6eb681b 100755 --- a/service/easy-setup/sdk/mediator/src/provisioninghandler.cpp +++ b/service/easy-setup/sdk/mediator/src/provisioninghandler.cpp @@ -18,16 +18,20 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +#include "provisioninghandler.h" + +//Standard includes #include #include #include #include #include + +//EasySetup include files #include "ocpayload.h" -#include "provisioninghandler.h" #include "common.h" -// External includes +// External includes #include "camutex.h" #include "cathreadpool.h" #include "logger.h" -- 2.7.4