Fixed SoftAP device removal notifications
authorlankamadan <lanka.madan@samsung.com>
Thu, 17 Sep 2015 06:49:05 +0000 (15:49 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Fri, 18 Sep 2015 02:24:42 +0000 (02:24 +0000)
- SoftAP notifications for unavailable device is avoided
- Remove unnecessary file

Change-Id: Ia4eb79adf5f2d767eed04f1173c1f35372076a1a
Signed-off-by: lankamadan <lanka.madan@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2619
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
service/easy-setup/sampleapp/android/EasySetup/app/src/main/AndroidManifest.xml
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/BleConnection.java [changed mode: 0644->0755]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupService.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceBLEOnBoarding.java [changed mode: 0644->0755]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceWiFiOnboarding.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardEnrollee.java [deleted file]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPManager.java
service/easy-setup/sdk/mediator/src/provisioninghandler.cpp

index 07003ee..8c52513 100755 (executable)
                 <data android:mimeType="text/plain" />
             </intent-filter>
         </activity>
-        <activity
-            android:name=".BLEActivity"
-            >
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
-        </activity>
     </application>
 
 </manifest>
old mode 100644 (file)
new mode 100755 (executable)
index bfb3483..8b90f80
@@ -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;
index e0ed145..4d5fac8 100755 (executable)
@@ -86,6 +86,7 @@ public class EasySetupService {
      */\r
 \r
     public void finish() {\r
+\r
         //Native Api call to reset OIC stack\r
         if(mProvisionEnrolleeInstance != null)\r
         {\r
@@ -143,11 +144,26 @@ public class EasySetupService {
      * @param enrolleedevice Device to be enrolled in network\r
      */\r
     public synchronized void stopSetup(EnrolleeDevice enrolleedevice) {\r
-        enrolleedevice.stopOnBoardingProcess();\r
-        mEnrolleeDeviceList.remove(enrolleedevice);\r
-\r
-        //Native Api call to stop on-going enrolling process for the enrolling device\r
-        EasySetupManager.getInstance().stopEnrolleeProvisioning(enrolleedevice.mOnBoardingConfig.getConnType().getValue());\r
+        if(enrolleedevice.mState == EnrolleeState.DEVICE_ON_BOARDING_STATE) {\r
+            if(mEnrolleeDeviceList.contains(enrolleedevice)) {\r
+                Log.i(TAG, "stopOnBoardingProcess for enrolleedevice");\r
+                enrolleedevice.stopOnBoardingProcess();\r
+                mEnrolleeDeviceList.remove(enrolleedevice);\r
+            }\r
+        }\r
+        else if(enrolleedevice.mState == EnrolleeState.DEVICE_PROVISIONING_STATE)\r
+        {\r
+            if(mEnrolleeDeviceList.contains(enrolleedevice)) {\r
+                Log.i(TAG, "stopOnBoardingProcess for enrolleedevice");\r
+                enrolleedevice.stopOnBoardingProcess();\r
+\r
+                Log.i(TAG, "stopEnrolleeProvisioning for enrolleedevice");\r
+                //Native Api call to stop on-going enrolling process for the enrolling device\r
+                EasySetupManager.getInstance().stopEnrolleeProvisioning(enrolleedevice\r
+                        .mOnBoardingConfig.getConnType().getValue());\r
+                mEnrolleeDeviceList.remove(enrolleedevice);\r
+            }\r
+        }\r
     }\r
 \r
     public synchronized void getEnrolleeDevice(OnBoardingConfig connType) {\r
@@ -164,10 +180,11 @@ public class EasySetupService {
 \r
         @Override\r
         public void onFinished(EnrolleeDevice enrolledevice) {\r
-            //if(mEnrolleeDeviceList.contains(enrolledevice)) {\r
-            Log.i(TAG, "onFinished() is received " + enrolledevice.isSetupSuccessful());\r
-            mCallback.onFinished(enrolledevice);\r
-            // }\r
+            if(mEnrolleeDeviceList.contains(enrolledevice)) {\r
+                Log.i(TAG, "onFinished() is received " + enrolledevice.isSetupSuccessful());\r
+                mCallback.onFinished(enrolledevice);\r
+                mEnrolleeDeviceList.remove(enrolledevice);\r
+            }\r
         }\r
 \r
     }\r
old mode 100644 (file)
new mode 100755 (executable)
index 3fb508e..1e74def
@@ -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() + "");
 
index e985571..e7a88e4 100755 (executable)
@@ -61,6 +61,7 @@ public class EnrolleeDeviceWiFiOnboarding extends EnrolleeDevice {
 \r
         @Override\r
         public void deviceOnBoardingStatus(EnrolleeInfo enrolleStatus) {\r
+            myTimer.cancel();\r
             Log.d("ESSoftAPOnBoarding", "Entered");\r
             if (mState == EnrolleeState.DEVICE_ON_BOARDING_STATE) {\r
                 Log.d("ESSoftAPOnBoarding", "Device in OnBoarding State");\r
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 (executable)
index e926bf2..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/**\r
- * ***************************************************************\r
- * <p>\r
- * Copyright 2015 Samsung Electronics All Rights Reserved.\r
- * <p>\r
- * <p>\r
- * <p>\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * <p>\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * <p>\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * <p>\r
- * ****************************************************************\r
- */\r
-package org.iotivity.service.easysetup.mediator;\r
-\r
-import android.content.Context;\r
-import android.net.wifi.WifiConfiguration;\r
-\r
-\r
-import org.iotivity.service.easysetup.mediator.ip.WiFiSoftAPManager;\r
-\r
-public class OnBoardEnrollee {\r
-    WiFiSoftAPManager wifiSoftAPManager;\r
-    IOnBoardingStatus deviceScanListener;\r
-\r
-    /**\r
-     * Constructor for OnBoardEnrollee. Constructs a new OnBoardEnrollee.\r
-     */\r
-    public OnBoardEnrollee(Context context) {\r
-        wifiSoftAPManager = new WiFiSoftAPManager(context);\r
-    }\r
-\r
-    public void registerOnBoardingStatusHandler(\r
-            IOnBoardingStatus deviceScanListener) {\r
-        this.deviceScanListener = deviceScanListener;\r
-    }\r
-\r
-    public void startDeviceScan() {\r
-        wifiSoftAPManager.getClientList(this.deviceScanListener, 300);\r
-    }\r
-\r
-    public void enableWiFiAP(WifiConfiguration netConfig, boolean enabled) {\r
-        wifiSoftAPManager.setWifiApEnabled(netConfig, true);\r
-    }\r
-\r
-    public void disableWiFiAP() {\r
-        wifiSoftAPManager.setWifiApEnabled(null, false);\r
-    }\r
-}\r
index f517b69..df6da82 100755 (executable)
@@ -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);
 
     }
index 52fc9e3..6eb681b 100755 (executable)
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+#include "provisioninghandler.h"
+
+//Standard includes
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <signal.h>
 #include <unistd.h>
+
+//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"