Android Ui is modified & removed ProvisionEnrollee
authorHemant Mahsky <h.mahsky@samsung.com>
Wed, 9 Sep 2015 16:10:31 +0000 (21:40 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Thu, 10 Sep 2015 11:27:49 +0000 (11:27 +0000)
Change-Id: Id9fb85e01988fa8ce72e4afbf57e5eea16eafc1f
Signed-off-by: Hemant Mahsky <h.mahsky@samsung.com>
Fixed Android Application UI crash issue

Change-Id: Id9fb85e01988fa8ce72e4afbf57e5eea16eafc1f
Signed-off-by: Hemant Mahsky <h.mahsky@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2431
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/easy-setup/sampleapp/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/MainActivity.java
service/easy-setup/sampleapp/android/EasySetup/app/src/main/res/layout/activity_main.xml
service/easy-setup/sampleapp/android/EasySetup/app/src/main/res/values/strings.xml
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/core/EnrolleeDevice.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/IpOnBoardingConnection.java [moved from service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/IpConnection.java with 87% similarity]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingCallback.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingConfig.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingConnection.java [moved from service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ConnectionInterface.java with 88% similarity]
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/impl/WiFiOnBoardingConfig.java

index f0b90c1..2cb8b8d 100755 (executable)
@@ -31,26 +31,44 @@ import org.iotivity.service.easysetup.core.EnrolleeState;
 import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory;\r
 import org.iotivity.service.easysetup.impl.WiFiOnBoardingConfig;\r
 import org.iotivity.service.easysetup.impl.WiFiProvConfig;\r
-import org.iotivity.service.easysetup.mediator.ProvisionEnrollee;\r
+//import org.iotivity.service.easysetup.mediator.EasySetupManager;\r
 \r
 import android.app.Activity;\r
 import android.content.Intent;\r
 import android.graphics.Bitmap;\r
 import android.net.wifi.WifiConfiguration;\r
 import android.os.Bundle;\r
+import android.os.Handler;\r
+import android.os.Message;\r
 import android.view.View;\r
 import android.view.View.OnClickListener;\r
 import android.widget.Button;\r
+import android.widget.EditText;\r
 import android.widget.ImageView;\r
+import android.widget.ProgressBar;\r
 import android.widget.TextView;\r
 import android.widget.Toast;\r
 \r
 public class MainActivity extends Activity {\r
-    TextView textView1;\r
+\r
+\r
+    /*Status to update the UI */\r
+    public static final int SUCCESS = 0;\r
+    public static final int FAILED = 1;\r
+    public static final int STATE_CHANGED = 2;\r
+\r
+    private boolean mRunningStatus = false;\r
 \r
     static final int REQUEST_IMAGE_CAPTURE = 1;\r
     ImageView imageView;\r
-    ProvisionEnrollee provisionEnrolleInstance;\r
+\r
+    EditText mSsidText;\r
+    EditText mPassText;\r
+    TextView mResultTextView;\r
+    ProgressBar mProgressbar;\r
+    Button mStartButton;\r
+    Button mStopButton;\r
+    Handler mHandler = new ThreadHandler();\r
 \r
     /**\r
      * Objects to be instantiated by the programmer\r
@@ -66,38 +84,30 @@ public class MainActivity extends Activity {
         super.onCreate(savedInstanceState);\r
         setContentView(R.layout.activity_main);\r
 \r
-        textView1 = (TextView) findViewById(R.id.textView1);\r
+        /* Initialize widgets to get user input for target network's SSID & password*/\r
+        mSsidText = (EditText) findViewById(R.id.ssid);\r
+        mPassText = (EditText) findViewById(R.id.password);\r
+        mResultTextView = (TextView) findViewById(R.id.status);\r
+        mProgressbar = (ProgressBar) findViewById(R.id.progressBar);\r
 \r
-        // Provisioning Process - This instantiation  will be removed in the next version\r
-        provisionEnrolleInstance = new ProvisionEnrollee(this);\r
-        /* Invocation of APIs using the Easy Setup SDK APIs */\r
 \r
-        /* Create Easy Setup Service instance*/\r
+       /* Create Easy Setup Service instance*/\r
         mEasySetupService = EasySetupService.getInstance(getApplicationContext(),\r
                 new EasySetupStatus() {\r
 \r
                     @Override\r
-                    public void onFinished(EnrolleeDevice enrolledevice) {\r
-                        final String msg = enrolledevice.isSetupSuccessful() ?\r
-                                "Device configured successfully" : "Device configuration failed";\r
-                        runOnUiThread(new Runnable() {\r
-                            @Override\r
-                            public void run() {\r
-                                Toast.makeText(getApplicationContext(),\r
-                                        msg, Toast.LENGTH_SHORT).show();\r
-                            }\r
-                        });\r
+                    public void onFinished(final EnrolleeDevice enrolledevice) {\r
+                        mRunningStatus = false;\r
+                        if (enrolledevice.isSetupSuccessful()) {\r
+                            mHandler.sendEmptyMessage(SUCCESS);\r
+                        } else {\r
+                            mHandler.sendEmptyMessage(FAILED);\r
+                        }\r
                     }\r
 \r
                     @Override\r
                     public void onProgress(EnrolleeState state) {\r
-                        runOnUiThread(new Runnable() {\r
-                            @Override\r
-                            public void run() {\r
-                                Toast.makeText(getApplicationContext(),\r
-                                        "Device state changed", Toast.LENGTH_SHORT).show();\r
-                            }\r
-                        });\r
+                        mHandler.sendEmptyMessage(STATE_CHANGED);\r
                     }\r
 \r
                 });\r
@@ -127,23 +137,46 @@ public class MainActivity extends Activity {
         mWiFiOnBoardingConfig.setSharedKey("EasySetup123");\r
         mWiFiOnBoardingConfig.setAuthAlgo(WifiConfiguration.AuthAlgorithm.OPEN);\r
         mWiFiOnBoardingConfig.setKms(WifiConfiguration.KeyMgmt.WPA_PSK);\r
+\r
+        // Updating the UI with default credentials\r
+        mSsidText.setText("EasySetup123");\r
+        mPassText.setText("EasySetup123");\r
+\r
         return mWiFiOnBoardingConfig;\r
     }\r
 \r
 \r
     public void onDestroy() {\r
         super.onDestroy();\r
-        provisionEnrolleInstance.stopEnrolleeProvisioning(0);\r
+        /*Reset the Easy setup process*/\r
+        mEasySetupService.finish();\r
     }\r
 \r
     public void addListenerForStartAP() {\r
-        Button button = (Button) findViewById(R.id.button1);\r
+        mStartButton = (Button) findViewById(R.id.startSetup);\r
 \r
-        button.setOnClickListener(new OnClickListener() {\r
+        mStartButton.setOnClickListener(new OnClickListener() {\r
             @Override\r
             public void onClick(View arg0) {\r
                 try {\r
+\r
+                    mRunningStatus = true;\r
+                    mProgressbar.setVisibility(View.VISIBLE);\r
+                    mProgressbar.setIndeterminate(true);\r
+                    mStartButton.setEnabled(false);\r
+                    mResultTextView.setText(R.string.running);\r
+\r
+                    String ssid = mSsidText.getText().toString();\r
+                    String password = mPassText.getText().toString();\r
+\r
+                    mWiFiOnBoardingConfig.setSSId(ssid);\r
+                    mWiFiOnBoardingConfig.setSharedKey(password);\r
+\r
                     mEasySetupService.startSetup(mDevice);\r
+\r
+                    mStopButton.setEnabled(true);\r
+\r
+\r
                 } catch (IOException e) {\r
                     e.printStackTrace();\r
                 }\r
@@ -153,11 +186,17 @@ public class MainActivity extends Activity {
     }\r
 \r
     public void addListenerForStopAP() {\r
-        Button button = (Button) findViewById(R.id.stopapbutton);\r
+        mStopButton = (Button) findViewById(R.id.stopSetup);\r
 \r
-        button.setOnClickListener(new OnClickListener() {\r
+        mStopButton.setOnClickListener(new OnClickListener() {\r
             @Override\r
             public void onClick(View arg0) {\r
+                mRunningStatus = false;\r
+                mStartButton.setEnabled(true);\r
+                mStopButton.setEnabled(false);\r
+                mResultTextView.setText(R.string.stopped);\r
+                mProgressbar.setIndeterminate(false);\r
+                mProgressbar.setVisibility(View.INVISIBLE);\r
                 mEasySetupService.stopSetup(mDevice);\r
             }\r
         });\r
@@ -171,4 +210,48 @@ public class MainActivity extends Activity {
             imageView.setImageBitmap(imageBitmap);\r
         }\r
     }\r
+\r
+    class ThreadHandler extends Handler {\r
+        @Override\r
+        public void handleMessage(Message msg) {\r
+\r
+            // Returns if Test is stopped, this has to be handled in EasySetupService\r
+            if (!mRunningStatus) return;\r
+\r
+            switch (msg.what) {\r
+                case SUCCESS: {\r
+\r
+                    mProgressbar.setIndeterminate(false);\r
+                    mStopButton.setEnabled(false);\r
+                    mStartButton.setEnabled(true);\r
+                    mProgressbar.setVisibility(View.INVISIBLE);\r
+                    String resultMsg = "Device configured successfully";\r
+                    mResultTextView.setText(R.string.success);\r
+                    Toast.makeText(getApplicationContext(), resultMsg, Toast.LENGTH_SHORT).show();\r
+                    break;\r
+                }\r
+                case FAILED: {\r
+\r
+                    mProgressbar.setIndeterminate(false);\r
+                    mStopButton.setEnabled(false);\r
+                    mStartButton.setEnabled(true);\r
+                    mProgressbar.setVisibility(View.INVISIBLE);\r
+                    String resultMsg = "Device configuration failed";\r
+                    mResultTextView.setText(R.string.failed);\r
+                    Toast.makeText(getApplicationContext(), resultMsg, Toast.LENGTH_SHORT).show();\r
+                    break;\r
+                }\r
+\r
+                case STATE_CHANGED: {\r
+                    String resultMsg = "Device state changed";\r
+                    Toast.makeText(getApplicationContext(), resultMsg, Toast.LENGTH_SHORT).show();\r
+                    break;\r
+                }\r
+\r
+            }\r
+\r
+\r
+        }\r
+    }\r
+\r
 }\r
index 2f7737e..4261ae9 100644 (file)
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
-    xmlns:tools="http://schemas.android.com/tools"\r
-    android:layout_width="match_parent"\r
-    android:layout_height="match_parent"\r
-    android:background="@drawable/background"\r
-    android:paddingBottom="@dimen/activity_vertical_margin"\r
-    android:paddingLeft="@dimen/activity_horizontal_margin"\r
-    android:paddingRight="@dimen/activity_horizontal_margin"\r
-    android:paddingTop="@dimen/activity_vertical_margin"\r
-    tools:context="org.iotivity.service.easysetup.mediator.MainActivity" >\r
-\r
-    <Button\r
-        android:id="@+id/button1"\r
-        android:layout_width="wrap_content"\r
-        android:layout_height="wrap_content"\r
-        android:layout_alignParentTop="true"\r
-        android:layout_centerHorizontal="true"\r
-        android:layout_margin="10dp"\r
-        android:layout_marginTop="20dp"\r
-        android:elegantTextHeight="true"\r
-        android:text="@string/start_soft_ap"\r
-        android:textAllCaps="false"\r
-        android:textSize="18sp" />\r
-\r
-    <Button\r
-        android:id="@+id/button2"\r
-        android:layout_width="wrap_content"\r
-        android:layout_height="wrap_content"\r
-        android:layout_alignParentBottom="true"\r
-        android:layout_centerHorizontal="true"\r
-        android:layout_marginBottom="72dp"\r
-        android:elegantTextHeight="true"\r
-        android:text="@string/provision_device"\r
-        android:textAllCaps="false"\r
-        android:textSize="18sp" />\r
-\r
-    <Button\r
-        android:id="@+id/stopapbutton"\r
-        android:layout_width="wrap_content"\r
-        android:layout_height="wrap_content"\r
-        android:layout_below="@+id/button1"\r
-        android:layout_centerHorizontal="true"\r
-        android:layout_margin="10dp"\r
-        android:elegantTextHeight="true"\r
-        android:text="@string/stop_soft_ap"\r
-        android:textAllCaps="false"\r
-        android:textSize="18sp" />\r
-\r
-    <TextView\r
-        android:id="@+id/textView1"\r
-        android:layout_width="wrap_content"\r
-        android:layout_height="wrap_content"\r
-        android:layout_alignLeft="@+id/TextView01"\r
-        android:layout_below="@+id/stopapbutton"\r
-        android:layout_marginTop="43dp"\r
-        android:text="@string/textview1"\r
-        android:textColor="#ffffff"\r
-        android:textSize="15sp" />\r
-\r
-    <TextView\r
-        android:id="@+id/TextView01"\r
-        android:layout_width="wrap_content"\r
-        android:layout_height="wrap_content"\r
-        android:layout_alignLeft="@+id/button2"\r
-        android:layout_below="@+id/stopapbutton"\r
-        android:layout_marginTop="16dp"\r
-        android:text="@string/textview2"\r
-        android:textColor="#ffffff"\r
-        android:textSize="20sp" />\r
-\r
-</RelativeLayout>
\ No newline at end of file
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="@drawable/background"
+    android:orientation="vertical"
+    android:paddingBottom="@dimen/activity_vertical_margin"
+    android:paddingLeft="@dimen/activity_horizontal_margin"
+    android:paddingRight="@dimen/activity_horizontal_margin"
+    android:paddingTop="@dimen/activity_vertical_margin"
+    tools:context="org.iotivity.service.easysetup.mediator.MainActivity">
+
+
+    <ProgressBar
+        android:id="@+id/progressBar"
+        style="?android:attr/progressBarStyleHorizontal"
+        android:layout_width="350dp"
+        android:layout_height="wrap_content"
+        android:visibility="invisible" />
+
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:layout_marginTop="20dp"
+        android:orientation="horizontal">
+
+
+        <TextView
+            android:id="@+id/lablestatus"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="8dp"
+            android:layout_marginRight="20dp"
+            android:elegantTextHeight="true"
+            android:text="@string/test_status"
+            android:textSize="20sp" />
+
+        <TextView
+            android:id="@+id/status"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="10dp"
+            android:layout_marginRight="30dp"
+            android:layout_marginTop="5dp"
+            android:text="@string/not_started"
+            android:textColor="@android:color/background_light"
+            android:textSize="30dp" />
+
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerHorizontal="true"
+        android:layout_gravity="center"
+        android:layout_marginTop="50dp"
+        android:orientation="vertical">
+
+        <TextView
+            android:id="@+id/textView"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="Enter SSID" />
+
+
+        <EditText
+            android:id="@+id/ssid"
+            android:layout_width="250dp"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal" />
+
+
+        <TextView
+            android:id="@+id/textView2"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="10dp"
+            android:text="Enter Password" />
+
+
+        <EditText
+            android:id="@+id/password"
+            android:layout_width="250dp"
+            android:layout_height="wrap_content"
+
+            android:layout_gravity="center_horizontal" />
+
+    </LinearLayout>
+
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerHorizontal="true"
+        android:layout_gravity="center"
+        android:layout_marginTop="20dp"
+        android:orientation="horizontal">
+
+        <Button
+            android:id="@+id/startSetup"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignParentTop="true"
+            android:layout_centerHorizontal="true"
+            android:layout_margin="10dp"
+            android:layout_marginTop="20dp"
+            android:elegantTextHeight="true"
+            android:text="@string/startSetup"
+            android:textAllCaps="false"
+            android:textSize="18sp" />
+
+        <Button
+            android:id="@+id/stopSetup"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_below="@+id/startSetup"
+            android:layout_centerHorizontal="true"
+            android:layout_margin="10dp"
+            android:elegantTextHeight="true"
+            android:text="@string/stopSetup"
+            android:textAllCaps="false"
+            android:textSize="18sp"
+            android:enabled="false"/>
+
+    </LinearLayout>
+
+
+</LinearLayout>
\ No newline at end of file
index 94af49e..832b7b4 100644 (file)
@@ -9,4 +9,16 @@
        <string name="start_soft_ap">Start Wi-Fi Soft AP</string>
        <string name="stop_soft_ap">Stop Soft AP</string>  
     <string name="provision_device">Provision Connected Device</string>
+
+    <string name="startSetup">Start Setup</string>
+    <string name="stopSetup">Stop Setup</string>
+    <string name="SSID">SSID</string>
+    <string name="Password">Password</string>
+    <string name="success">Successful</string>
+    <string name="failed">Failed</string>
+    <string name="not_started">Not started</string>
+    <string name="test_status">Status</string>
+    <string name="running">Running</string>
+    <string name="stopped">Stopped</string>
+
 </resources>
index 6707ecf..52f34ed 100755 (executable)
-/**
- * ***************************************************************
- * <p>
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- * <p>
- * <p>
- * <p>
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.
- * <p>
- * ****************************************************************
- */
-
-package org.iotivity.service.easysetup.core;
-
-import android.content.Context;
-
-import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory;
-
-import java.io.IOException;
-import java.util.ArrayList;
-
-/**
- * This is facade class, a single point of contact for Application.
- * It contains set of APIs to do easy setup of the enrolling device.
- * ON-BOARDING - This is a step to establish connectivity between the device & Mediator device.
- * PROVISION   - This is a step where the netowork's detail & credentials are given to the
- * enrolling device.
- */
-public class EasySetupService {
-
-    private static EasySetupService sInstance;
-
-    private final EasySetupStatus mCallback;
-
-    private ArrayList<EnrolleeDevice> mEnrolleeDeviceList;
-
-    private final ProvisioningCallback mProvisioningCallback;
-
-    private static Context mContext;
-
-    public EnrolleeDeviceFactory mDeviceFactory;
-
-
-    private EasySetupService(EasySetupStatus callback) {
-        mCallback = callback;
-        mProvisioningCallback = new ProvisioningCallbackImpl(mCallback);
-        mEnrolleeDeviceList = new ArrayList<EnrolleeDevice>();
-        mContext = null;
-        mDeviceFactory = null;
-    }
-
-    /**
-     * Gives a singleton instance of Easy setup service.
-     *
-     * @param callback Application needs to provide this callback to receive the status of easy
-     *                 setup process.
-     */
-
-    public synchronized static EasySetupService getInstance(Context context, EasySetupStatus
-            callback) {
-        if (sInstance == null) {
-            sInstance = new EasySetupService(callback);
-            mContext = context;
-        }
-        return sInstance;
-    }
-
-    /**
-     * Starts Easy setup process for the enrolling device.
-     *
-     * @param enrolledevice Device to be enrolled in network
-     * @throws IOException Throws exception in case of any connection error.
-     */
-
-    public synchronized void startSetup(final EnrolleeDevice enrolledevice) throws IOException {
-
-        mEnrolleeDeviceList.add(enrolledevice);
-
-        // Starts the provisioning directly if the device is already on boarded on the network.
-        if (enrolledevice.onBoarded()) {
-            enrolledevice.startProvisioning(mProvisioningCallback);
-            return;
-        }
-
-        enrolledevice.startOnBoarding(new OnBoardingCallback() {
-
-            @Override
-            public void onFinished(ConnectionInterface connection) {
-                if (connection.isConnected()) {
-                    try {
-                        Thread.sleep(15000);//Sleep for allowing thin device to start the services
-                    } catch (InterruptedException e) {
-                        e.printStackTrace();
-                    }
-
-                    // Start provisioning here
-                    enrolledevice.setConnection(connection);
-                    enrolledevice.startProvisioning(mProvisioningCallback);
-                } else {
-                    enrolledevice.mState = EnrolleeState.DEVICE_PROVISIONING_FAILED_STATE;
-                    mProvisioningCallback.onFinished(enrolledevice);
-                }
-
-            }
-
-        });
-
-    }
-
-    /**
-     * Stops on-going Easy setup process for enrolling device.
-     *
-     * @param enrolledevice Device to be enrolled in network
-     */
-    public synchronized void stopSetup(EnrolleeDevice enrolledevice) {
-        enrolledevice.stopOnBoardingProcess();
-        mEnrolleeDeviceList.remove(enrolledevice);
-    }
-
-    public synchronized void getEnrolleeDevice(OnBoardingConfig connType) {
-        mDeviceFactory = EnrolleeDeviceFactory.newInstance(mContext);
-    }
-
-    class ProvisioningCallbackImpl extends ProvisioningCallback {
-
-        private final EasySetupStatus mCallback;
-
-        ProvisioningCallbackImpl(EasySetupStatus callback) {
-            mCallback = callback;
-        }
-
-        @Override
-        public void onFinished(EnrolleeDevice enrolledevice) {
-            //if(mEnrolleeDeviceList.contains(enrolledevice)) {
-            mCallback.onFinished(enrolledevice);
-            //}
-        }
-
-    }
-
-
-}
+/**\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
+\r
+package org.iotivity.service.easysetup.core;\r
+\r
+import android.content.Context;\r
+\r
+import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory;\r
+import org.iotivity.service.easysetup.mediator.EasySetupManager;\r
+\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+\r
+/**\r
+ * This is facade class, a single point of contact for Application.\r
+ * It contains set of APIs to do easy setup of the enrolling device.\r
+ * ON-BOARDING - This is a step to establish connectivity between the device & Mediator device.\r
+ * PROVISION   - This is a step where the netowork's detail & credentials are given to the\r
+ * enrolling device.\r
+ */\r
+public class EasySetupService {\r
+\r
+    private static EasySetupService sInstance;\r
+\r
+    private final EasySetupStatus mCallback;\r
+\r
+    private ArrayList<EnrolleeDevice> mEnrolleeDeviceList;\r
+\r
+    private final ProvisioningCallback mProvisioningCallback;\r
+\r
+    private static Context mContext;\r
+\r
+    public EnrolleeDeviceFactory mDeviceFactory;\r
+\r
+    private EasySetupService(EasySetupStatus callback) {\r
+        mCallback = callback;\r
+        mProvisioningCallback = new ProvisioningCallbackImpl(mCallback);\r
+        mEnrolleeDeviceList = new ArrayList<EnrolleeDevice>();\r
+        mContext = null;\r
+        mDeviceFactory = null;\r
+\r
+        //Native Api call to initialize the OIC stack\r
+        EasySetupManager.getInstance().initEasySetup();\r
+    }\r
+\r
+    /**\r
+     * Gives a singleton instance of Easy setup service and initialize the service\r
+     *\r
+     * @param callback Application needs to provide this callback to receive the status of easy\r
+     *                 setup process.\r
+     */\r
+\r
+    public synchronized static EasySetupService getInstance(Context context, EasySetupStatus\r
+            callback) {\r
+        if (sInstance == null) {\r
+            sInstance = new EasySetupService(callback);\r
+            mContext = context;\r
+        }\r
+        return sInstance;\r
+    }\r
+\r
+    /**\r
+     * Reset the Easy setup Service\r
+     */\r
+\r
+    public void finish() {\r
+        //Native Api call to reset OIC stack\r
+        EasySetupManager.getInstance().terminateEasySetup();\r
+    }\r
+\r
+    /**\r
+     * Starts Easy setup process for the enrolling device.\r
+     *\r
+     * @param enrolledevice Device to be enrolled in network\r
+     * @throws IOException Throws exception in case of any connection error.\r
+     */\r
+\r
+    public synchronized void startSetup(final EnrolleeDevice enrolledevice) throws IOException {\r
+\r
+        mEnrolleeDeviceList.add(enrolledevice);\r
+\r
+        // Starts the provisioning directly if the device is already on boarded on the network.\r
+        if (enrolledevice.onBoarded()) {\r
+            enrolledevice.startProvisioning(mProvisioningCallback);\r
+            return;\r
+        }\r
+\r
+        enrolledevice.startOnBoarding(new OnBoardingCallback() {\r
+\r
+            @Override\r
+            public void onFinished(OnBoardingConnection connection) {\r
+                if (connection.isConnected()) {\r
+                    try {\r
+                        Thread.sleep(15000);//Sleep for allowing thin device to start the services\r
+                    } catch (InterruptedException e) {\r
+                        e.printStackTrace();\r
+                    }\r
+\r
+                    // Start provisioning here\r
+                    enrolledevice.setConnection(connection);\r
+                    enrolledevice.startProvisioning(mProvisioningCallback);\r
+                } else {\r
+                    enrolledevice.mState = EnrolleeState.DEVICE_PROVISIONING_FAILED_STATE;\r
+                    mProvisioningCallback.onFinished(enrolledevice);\r
+                }\r
+\r
+            }\r
+\r
+        });\r
+\r
+    }\r
+\r
+    /**\r
+     * Stops on-going Easy setup process for enrolling device.\r
+     *\r
+     * @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
+    }\r
+\r
+    public synchronized void getEnrolleeDevice(OnBoardingConfig connType) {\r
+        mDeviceFactory = EnrolleeDeviceFactory.newInstance(mContext);\r
+    }\r
+\r
+    class ProvisioningCallbackImpl extends ProvisioningCallback {\r
+\r
+        private final EasySetupStatus mCallback;\r
+\r
+        ProvisioningCallbackImpl(EasySetupStatus callback) {\r
+            mCallback = callback;\r
+        }\r
+\r
+        @Override\r
+        public void onFinished(EnrolleeDevice enrolledevice) {\r
+            //if(mEnrolleeDeviceList.contains(enrolledevice)) {\r
+            mCallback.onFinished(enrolledevice);\r
+            //}\r
+        }\r
+\r
+    }\r
+\r
+\r
+}\r
index 5a7c823..be915c2 100755 (executable)
-/**
- * ***************************************************************
- * <p>
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- * <p>
- * <p>
- * <p>
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.
- * <p>
- * ****************************************************************
- */
-
-package org.iotivity.service.easysetup.core;
-
-/**
- * This is an abstract class represents the device being provisioned into the network. The
- * device being enrolled or provisioned into the network is called Enrollee.
- * Application has to extend this class and provide implementation of abstract methods according
- * to the ON-BOARDING & PROVISION connectivity i.e. WiFi, BLE, BT etc. the device is having.
- */
-
-public abstract class EnrolleeDevice {
-
-    protected EnrolleeState mState;
-    private EnrolleeSetupError mError;
-
-    protected ConnectionInterface mConnection;
-    protected final ProvisioningConfig mProvConfig;
-    protected final OnBoardingConfig mOnBoardingConfig;
-
-    protected OnBoardingCallback mOnBoardingCallback;
-    protected ProvisioningCallback mProvisioningCallback;
-
-    /**
-     * @param onBoardingConfig Contains details about the connectivity to be established between
-     *                         the Enrollee device & Mediator device in order to perform
-     *                         on-boarding
-     * @param provConfig       Contains details about the network to which Enrollee device is
-     *                         going to connect.
-     */
-    protected EnrolleeDevice(OnBoardingConfig onBoardingConfig, ProvisioningConfig provConfig) {
-        mProvConfig = provConfig;
-        mOnBoardingConfig = onBoardingConfig;
-    }
-
-    /**
-     * Application has to implement it according to the on boarding connectivity the device is
-     * having.
-     * This method will be called back during the easy setup process.
-     */
-    protected abstract void startOnBoardingProcess();
-
-    /**
-     * This method is called back during the easy setup process if Application cancels the setup.
-     * Easy setup service checks the state of device and calls this function accordingly.
-     * Application has to provide implementation for this method to cancel the on boarding step.
-     */
-    protected abstract void stopOnBoardingProcess();
-
-    /**
-     * Application has to implement it according to the type of the network device is going to
-     * connect or provisioned.
-     * This method will be called back once on-boarding of the device is successful.
-     *
-     * @param conn Contains detail about the network established between the Enrollee device &
-     *             Mediator device. Its implementation vary according to the connectivity type.
-     */
-    protected abstract void startProvisioningProcess(ConnectionInterface conn);
-
-    /**
-     * Once on boarding is successful concrete Enrollee class would call this method and set the
-     * Connection.
-     *
-     * @param conn Connectivity between Enrollee device & Mediator device.
-     */
-    public void setConnection(ConnectionInterface conn) {
-        mConnection = conn;
-    }
-
-
-    /**
-     * This method is called back by Easy setup service if on boarding needs to be done.
-     *
-     * @param onBoardingCallback This is called back once the on boarding is completed.
-     */
-    void startOnBoarding(OnBoardingCallback onBoardingCallback) {
-        mOnBoardingCallback = onBoardingCallback;
-        startOnBoardingProcess();
-    }
-
-    /**
-     * This method is called back by Easy setup service once on boarding is successful
-     *
-     * @param provisioningCallback This is called back once the provisioning process is completed
-     */
-    void startProvisioning(ProvisioningCallback provisioningCallback) {
-        mProvisioningCallback = provisioningCallback;
-        startProvisioningProcess(mConnection);
-    }
-
-    /**
-     * This method is used to check easy setup status
-     *
-     * @return true if successful or false
-     */
-
-    public boolean isSetupSuccessful() {
-        return (mState == EnrolleeState.DEVICE_PROVISIONING_SUCCESS_STATE) ? true : false;
-    }
-
-    /**
-     * Returns error occured during easy setup process
-     *
-     * @return True EnrolleeSetupError object
-     */
-    public EnrolleeSetupError getError() {
-        return mError;
-    }
-
-    /**
-     * Gives the state of the device being enrolled during the easy setup process.
-     *
-     * @return Returns EnrolleeState object
-     */
-    public EnrolleeState getState() {
-        return mState;
-    }
-
-    /**
-     * This method is used to know if the device is on boarded or not
-     *
-     * @return True if on-boarded successfully or False
-     */
-
-    public boolean onBoarded() {
-        return (mState == EnrolleeState.DEVICE_PROVISIONING_STATE) ? true : false;
-    }
-
-}
+/**\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
+\r
+package org.iotivity.service.easysetup.core;\r
+\r
+/**\r
+ * This is an abstract class represents the device being provisioned into the network. The\r
+ * device being enrolled or provisioned into the network is called Enrollee.\r
+ * Application has to extend this class and provide implementation of abstract methods according\r
+ * to the ON-BOARDING & PROVISION connectivity i.e. WiFi, BLE, BT etc. the device is having.\r
+ */\r
+\r
+public abstract class EnrolleeDevice {\r
+\r
+    protected EnrolleeState mState;\r
+    private EnrolleeSetupError mError;\r
+\r
+    protected OnBoardingConnection mConnection;\r
+    protected final ProvisioningConfig mProvConfig;\r
+    protected final OnBoardingConfig mOnBoardingConfig;\r
+\r
+    protected OnBoardingCallback mOnBoardingCallback;\r
+    protected ProvisioningCallback mProvisioningCallback;\r
+\r
+    /**\r
+     * @param onBoardingConfig Contains details about the connectivity to be established between\r
+     *                         the Enrollee device & Mediator device in order to perform\r
+     *                         on-boarding\r
+     * @param provConfig       Contains details about the network to which Enrollee device is\r
+     *                         going to connect.\r
+     */\r
+    protected EnrolleeDevice(OnBoardingConfig onBoardingConfig, ProvisioningConfig provConfig) {\r
+        mProvConfig = provConfig;\r
+        mOnBoardingConfig = onBoardingConfig;\r
+    }\r
+\r
+    /**\r
+     * Application has to implement it according to the on boarding connectivity the device is\r
+     * having.\r
+     * This method will be called back during the easy setup process.\r
+     */\r
+    protected abstract void startOnBoardingProcess();\r
+\r
+    /**\r
+     * This method is called back during the easy setup process if Application cancels the setup.\r
+     * Easy setup service checks the state of device and calls this function accordingly.\r
+     * Application has to provide implementation for this method to cancel the on boarding step.\r
+     */\r
+    protected abstract void stopOnBoardingProcess();\r
+\r
+    /**\r
+     * Application has to implement it according to the type of the network device is going to\r
+     * connect or provisioned.\r
+     * This method will be called back once on-boarding of the device is successful.\r
+     *\r
+     * @param conn Contains detail about the network established between the Enrollee device &\r
+     *             Mediator device. Its implementation vary according to the connectivity type.\r
+     */\r
+    protected abstract void startProvisioningProcess(OnBoardingConnection conn);\r
+\r
+    /**\r
+     * Once on boarding is successful concrete Enrollee class would call this method and set the\r
+     * Connection.\r
+     *\r
+     * @param conn Connectivity between Enrollee device & Mediator device.\r
+     */\r
+    public void setConnection(OnBoardingConnection conn) {\r
+        mConnection = conn;\r
+    }\r
+\r
+\r
+    /**\r
+     * This method is called back by Easy setup service if on boarding needs to be done.\r
+     *\r
+     * @param onBoardingCallback This is called back once the on boarding is completed.\r
+     */\r
+    void startOnBoarding(OnBoardingCallback onBoardingCallback) {\r
+        mOnBoardingCallback = onBoardingCallback;\r
+        startOnBoardingProcess();\r
+    }\r
+\r
+    /**\r
+     * This method is called back by Easy setup service once on boarding is successful\r
+     *\r
+     * @param provisioningCallback This is called back once the provisioning process is completed\r
+     */\r
+    void startProvisioning(ProvisioningCallback provisioningCallback) {\r
+        mProvisioningCallback = provisioningCallback;\r
+        startProvisioningProcess(mConnection);\r
+    }\r
+\r
+    /**\r
+     * This method is used to check easy setup status\r
+     *\r
+     * @return true if successful or false\r
+     */\r
+\r
+    public boolean isSetupSuccessful() {\r
+        return (mState == EnrolleeState.DEVICE_PROVISIONING_SUCCESS_STATE) ? true : false;\r
+    }\r
+\r
+    /**\r
+     * Returns error occured during easy setup process\r
+     *\r
+     * @return True EnrolleeSetupError object\r
+     */\r
+    public EnrolleeSetupError getError() {\r
+        return mError;\r
+    }\r
+\r
+    /**\r
+     * Gives the state of the device being enrolled during the easy setup process.\r
+     *\r
+     * @return Returns EnrolleeState object\r
+     */\r
+    public EnrolleeState getState() {\r
+        return mState;\r
+    }\r
+\r
+    /**\r
+     * This method is used to know if the device is on boarded or not\r
+     *\r
+     * @return True if on-boarded successfully or False\r
+     */\r
+\r
+    public boolean onBoarded() {\r
+        return (mState == EnrolleeState.DEVICE_PROVISIONING_STATE) ? true : false;\r
+    }\r
+\r
+}\r
@@ -1,57 +1,57 @@
-/**
- * ***************************************************************
- * <p>
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- * <p>
- * <p>
- * <p>
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.
- * <p>
- * ****************************************************************
- */
-
-package org.iotivity.service.easysetup.core;
-
-public class IpConnection implements ConnectionInterface {
-
-    private boolean mIsConnected;
-    private String mIp;
-
-    public void setConnectivity(boolean connected) {
-        mIsConnected = connected;
-    }
-
-    public void setIp(String ip) {
-        mIp = ip;
-    }
-
-    public String getIp() {
-        return mIp;
-    }
-
-    @Override
-    public String getDesc() {
-        return "Description";
-    }
-
-    @Override
-    public boolean isConnected() {
-        return mIsConnected;
-    }
-
-    @Override
-    public Object getConnection() {
-        return this;
-    }
-
-}
+/**\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
+\r
+package org.iotivity.service.easysetup.core;\r
+\r
+public class IpOnBoardingConnection implements OnBoardingConnection {\r
+\r
+    private boolean mIsConnected;\r
+    private String mIp;\r
+\r
+    public void setConnectivity(boolean connected) {\r
+        mIsConnected = connected;\r
+    }\r
+\r
+    public void setIp(String ip) {\r
+        mIp = ip;\r
+    }\r
+\r
+    public String getIp() {\r
+        return mIp;\r
+    }\r
+\r
+    @Override\r
+    public String getDesc() {\r
+        return "Description";\r
+    }\r
+\r
+    @Override\r
+    public boolean isConnected() {\r
+        return mIsConnected;\r
+    }\r
+\r
+    @Override\r
+    public Object getConnection() {\r
+        return this;\r
+    }\r
+\r
+}\r
index 3fa2ced..5712722 100644 (file)
@@ -1,27 +1,27 @@
-/**
- * ***************************************************************
- * <p>
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- * <p>
- * <p>
- * <p>
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.
- * <p>
- * ****************************************************************
- */
-
-package org.iotivity.service.easysetup.core;
-
-public abstract class OnBoardingCallback {
-    public abstract void onFinished(ConnectionInterface connection);
-}
+/**\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
+\r
+package org.iotivity.service.easysetup.core;\r
+\r
+public abstract class OnBoardingCallback {\r
+    public abstract void onFinished(OnBoardingConnection connection);\r
+}\r
index 24978e7..2852f9e 100755 (executable)
@@ -1,55 +1,67 @@
-/**
- * ***************************************************************
- * <p>
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- * <p>
- * <p>
- * <p>
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.
- * <p>
- * ****************************************************************
- */
-
-package org.iotivity.service.easysetup.core;
-
-/**
- * It contains configuration details about the connectivity type between the Enrollee device &
- * Mediator device in order to perform on-boarding.
- */
-
-public interface OnBoardingConfig {
-
-    /**
-     * It provides constants for connectivity types used for on-boarding Enrollee device
-     */
-    public static enum ConnType {
-        WiFi,
-        BLE,
-    }
-
-    /**
-     * Gives configuration object specific to the on-boarding connectivity of the enrolling device.
-     *
-     * @return instance object of configuration according to connectivity type
-     */
-    public Object getConfig();
-
-    /**
-     * Gives connectivity type of on-boarding device
-     *
-     * @return on-boarding connectivity type
-     */
-    public ConnType getConnType();
-
-
-}
+/**\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
+\r
+package org.iotivity.service.easysetup.core;\r
+\r
+/**\r
+ * It contains configuration details about the connectivity type between the Enrollee device &\r
+ * Mediator device in order to perform on-boarding.\r
+ */\r
+\r
+public interface OnBoardingConfig {\r
+\r
+    /**\r
+     * It provides constants for connectivity types used for on-boarding Enrollee device\r
+     */\r
+    public static enum ConnType {\r
+        // Note : Enum Ids should matched with Native Ids\r
+        WiFi(0),\r
+        BLE(1);\r
+\r
+        private int mConnType;\r
+\r
+        ConnType(int connType) {\r
+            mConnType = connType;\r
+        }\r
+\r
+        public int getValue() {\r
+            return mConnType;\r
+        }\r
+\r
+    }\r
+\r
+    /**\r
+     * Gives configuration object specific to the on-boarding connectivity of the enrolling device.\r
+     *\r
+     * @return instance object of configuration according to connectivity type\r
+     */\r
+    public Object getConfig();\r
+\r
+    /**\r
+     * Gives connectivity type of on-boarding device\r
+     *\r
+     * @return on-boarding connectivity type\r
+     */\r
+    public ConnType getConnType();\r
+\r
+\r
+}\r
@@ -1,35 +1,35 @@
-/**
- * ***************************************************************
- * <p>
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- * <p>
- * <p>
- * <p>
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.
- * <p>
- * ****************************************************************
- */
-package org.iotivity.service.easysetup.core;
-
-public interface ConnectionInterface {
-
-
-    // Get the implementation of the Connection
-    public Object getConnection();
-
-    // Any general description on the connectivity.
-    public String getDesc();
-
-    public boolean isConnected();
-
-}
+/**\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.core;\r
+\r
+public interface OnBoardingConnection {\r
+\r
+\r
+    // Get the implementation of the Connection\r
+    public Object getConnection();\r
+\r
+    // Any general description on the connectivity.\r
+    public String getDesc();\r
+\r
+    public boolean isConnected();\r
+\r
+}\r
index 9b70913..3dffae9 100755 (executable)
-/**
- * ***************************************************************
- * <p>
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- * <p>
- * <p>
- * <p>
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.
- * <p>
- * ****************************************************************
- */
-
-package org.iotivity.service.easysetup.impl;
-
-import java.util.Timer;
-import java.util.TimerTask;
-
-import org.iotivity.service.easysetup.core.ConnectionInterface;
-import org.iotivity.service.easysetup.core.EnrolleeDevice;
-import org.iotivity.service.easysetup.core.EnrolleeState;
-import org.iotivity.service.easysetup.core.IpConnection;
-import org.iotivity.service.easysetup.core.OnBoardingConfig;
-import org.iotivity.service.easysetup.core.ProvisioningConfig;
-import org.iotivity.service.easysetup.mediator.EasySetupCallbackHandler;
-import org.iotivity.service.easysetup.mediator.EasySetupManager;
-import org.iotivity.service.easysetup.mediator.EnrolleeInfo;
-import org.iotivity.service.easysetup.mediator.IOnBoardingStatus;
-import org.iotivity.service.easysetup.mediator.IProvisioningListener;
-import org.iotivity.service.easysetup.mediator.ProvisionEnrollee;
-import org.iotivity.service.easysetup.mediator.ip.WiFiSoftAPManager;
-
-import android.content.Context;
-import android.net.wifi.WifiConfiguration;
-import android.util.Log;
-import android.widget.Toast;
-
-/**
- * This is a ready to use class for Enrollee device having Soft AP as on-boarding connectivity.
- */
-public class EnrolleeDeviceWiFiOnboarding extends EnrolleeDevice {
-
-    public static final String TAG = EnrolleeDeviceWiFiOnboarding.class.getName();
-
-    final Context mContext;
-    final WiFiSoftAPManager mWifiSoftAPManager;
-    EnrolleeInfo connectedDevice;
-    private EasySetupManager easySetupManagerNativeInstance;
-    ProvisionEnrollee provisionEnrolleInstance;
-
-    IOnBoardingStatus deviceScanListener = new IOnBoardingStatus() {
-
-        @Override
-        public void deviceOnBoardingStatus(EnrolleeInfo enrolleStatus) {
-            Log.d("ESSoftAPOnBoarding", "Entered");
-            if (enrolleStatus != null && enrolleStatus.getIpAddr() != null) {
-                String finalResult = "Easy Connect : ";
-
-                if (enrolleStatus.isReachable()) {
-                    finalResult = "Device OnBoarded" + "["
-                            + enrolleStatus.getIpAddr() + "]";
-
-                    connectedDevice = enrolleStatus;
-                    IpConnection conn = new IpConnection();
-                    conn.setConnectivity(true);
-                    conn.setIp(connectedDevice.getIpAddr());
-                    Log.d("ESSoftAPOnBoarding", "Entered");
-                    mOnBoardingCallback.onFinished(conn);
-                    return;
-
-                }
-            }
-
-            IpConnection conn = new IpConnection();
-            conn.setConnectivity(false);
-            mOnBoardingCallback.onFinished(conn);
-        }
-    };
-
-
-    protected EnrolleeDeviceWiFiOnboarding(Context context, OnBoardingConfig onBoardingConfig, ProvisioningConfig provConfig) {
-        super(onBoardingConfig, provConfig);
-        mContext = context;
-        mWifiSoftAPManager = new WiFiSoftAPManager(mContext);
-    }
-
-    @Override
-    protected void startOnBoardingProcess() {
-        Log.i(TAG, "Starging on boarding process");
-
-        //1. Create Soft AP
-        boolean status = mWifiSoftAPManager.setWifiApEnabled((WifiConfiguration) mOnBoardingConfig.getConfig(), true);
-
-        Log.i(TAG, "Soft AP is created with status " + status);
-
-        Timer myTimer;
-        myTimer = new Timer();
-        myTimer.schedule(new TimerTask() {
-            @Override
-            public void run() {
-                // Below function to be called after 5 seconds
-                mWifiSoftAPManager.getClientList(deviceScanListener, 300);
-            }
-
-        }, 0, 5000);
-    }
-
-    protected void stopOnBoardingProcess() {
-        Log.i(TAG, "Stopping on boarding process");
-        boolean status = mWifiSoftAPManager.setWifiApEnabled(null, false);
-        Log.i(TAG, "Soft AP is disabled with status " + status);
-    }
-
-    @Override
-    protected void startProvisioningProcess(ConnectionInterface conn) {
-
-        if (mProvConfig.getConnType() == ProvisioningConfig.ConnType.WiFi) {
-
-            provisionEnrolleInstance = new ProvisionEnrollee(mContext);
-            provisionEnrolleInstance.registerProvisioningHandler(new IProvisioningListener() {
-                @Override
-                public void onFinishProvisioning(int statuscode) {
-                    mState = (statuscode == 0) ? EnrolleeState.DEVICE_PROVISIONING_SUCCESS_STATE : EnrolleeState.DEVICE_PROVISIONING_FAILED_STATE;
-                    mProvisioningCallback.onFinished(EnrolleeDeviceWiFiOnboarding.this);
-                }
-            });
-
-            IpConnection connection = (IpConnection) conn;
-            WiFiProvConfig wifiProvConfig = (WiFiProvConfig) mProvConfig;
-            easySetupManagerNativeInstance = EasySetupManager.getInstance();
-            easySetupManagerNativeInstance.initEasySetup();
-            easySetupManagerNativeInstance.provisionEnrollee(connection.getIp(), wifiProvConfig.getSsId(), wifiProvConfig.getPassword(), 0 /*In base code '0' is hard coded*/);
-
-        }
-
-    }
-
-
-}
+/**\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
+\r
+package org.iotivity.service.easysetup.impl;\r
+\r
+import java.util.Timer;\r
+import java.util.TimerTask;\r
+\r
+import org.iotivity.service.easysetup.core.OnBoardingConnection;\r
+import org.iotivity.service.easysetup.core.EnrolleeDevice;\r
+import org.iotivity.service.easysetup.core.EnrolleeState;\r
+import org.iotivity.service.easysetup.core.IpOnBoardingConnection;\r
+import org.iotivity.service.easysetup.core.OnBoardingConfig;\r
+import org.iotivity.service.easysetup.core.ProvisioningConfig;\r
+import org.iotivity.service.easysetup.mediator.EasySetupManager;\r
+import org.iotivity.service.easysetup.mediator.EnrolleeInfo;\r
+import org.iotivity.service.easysetup.mediator.IOnBoardingStatus;\r
+import org.iotivity.service.easysetup.mediator.IProvisioningListener;\r
+import org.iotivity.service.easysetup.mediator.ProvisionEnrollee;\r
+import org.iotivity.service.easysetup.mediator.ip.WiFiSoftAPManager;\r
+\r
+import android.content.Context;\r
+import android.net.wifi.WifiConfiguration;\r
+import android.util.Log;\r
+\r
+/**\r
+ * This is a ready to use class for Enrollee device having Soft AP as on-boarding connectivity.\r
+ */\r
+public class EnrolleeDeviceWiFiOnboarding extends EnrolleeDevice {\r
+\r
+    public static final String TAG = EnrolleeDeviceWiFiOnboarding.class.getName();\r
+\r
+    final Context mContext;\r
+    final WiFiSoftAPManager mWifiSoftAPManager;\r
+    EnrolleeInfo connectedDevice;\r
+    private EasySetupManager easySetupManagerNativeInstance;\r
+    ProvisionEnrollee provisionEnrolleInstance;\r
+\r
+    // Native Api to start provisioning process after successful on-boarding on Wifi AP.\r
+    // Library is already loaded while constructing EasySetupService\r
+    private native void ProvisionEnrollee(String ipAddress, String netSSID,\r
+                                          String netPWD, int connectivityType);\r
+\r
+    IOnBoardingStatus deviceScanListener = new IOnBoardingStatus() {\r
+\r
+        @Override\r
+        public void deviceOnBoardingStatus(EnrolleeInfo enrolleStatus) {\r
+            Log.d("ESSoftAPOnBoarding", "Entered");\r
+            if (enrolleStatus != null && enrolleStatus.getIpAddr() != null) {\r
+                String finalResult = "Easy Connect : ";\r
+\r
+                if (enrolleStatus.isReachable()) {\r
+                    finalResult = "Device OnBoarded" + "["\r
+                            + enrolleStatus.getIpAddr() + "]";\r
+\r
+                    connectedDevice = enrolleStatus;\r
+                    IpOnBoardingConnection conn = new IpOnBoardingConnection();\r
+                    conn.setConnectivity(true);\r
+                    conn.setIp(connectedDevice.getIpAddr());\r
+                    Log.d("ESSoftAPOnBoarding", "Entered");\r
+                    mOnBoardingCallback.onFinished(conn);\r
+                    return;\r
+\r
+                }\r
+            }\r
+\r
+            IpOnBoardingConnection conn = new IpOnBoardingConnection();\r
+            conn.setConnectivity(false);\r
+            mOnBoardingCallback.onFinished(conn);\r
+        }\r
+    };\r
+\r
+\r
+    protected EnrolleeDeviceWiFiOnboarding(Context context, OnBoardingConfig onBoardingConfig, ProvisioningConfig provConfig) {\r
+        super(onBoardingConfig, provConfig);\r
+        mContext = context;\r
+        mWifiSoftAPManager = new WiFiSoftAPManager(mContext);\r
+    }\r
+\r
+    @Override\r
+    protected void startOnBoardingProcess() {\r
+        Log.i(TAG, "Starging on boarding process");\r
+\r
+        //1. Create Soft AP\r
+        boolean status = mWifiSoftAPManager.setWifiApEnabled((WifiConfiguration) mOnBoardingConfig.getConfig(), true);\r
+\r
+        Log.i(TAG, "Soft AP is created with status " + status);\r
+\r
+        Timer myTimer;\r
+        myTimer = new Timer();\r
+        myTimer.schedule(new TimerTask() {\r
+            @Override\r
+            public void run() {\r
+                // Below function to be called after 5 seconds\r
+                mWifiSoftAPManager.getClientList(deviceScanListener, 300);\r
+            }\r
+\r
+        }, 0, 5000);\r
+    }\r
+\r
+    protected void stopOnBoardingProcess() {\r
+        Log.i(TAG, "Stopping on boarding process");\r
+        boolean status = mWifiSoftAPManager.setWifiApEnabled(null, false);\r
+        Log.i(TAG, "Soft AP is disabled with status " + status);\r
+    }\r
+\r
+    @Override\r
+    protected void startProvisioningProcess(OnBoardingConnection conn) {\r
+\r
+        if (mProvConfig.getConnType() == ProvisioningConfig.ConnType.WiFi) {\r
+\r
+            provisionEnrolleInstance = new ProvisionEnrollee(mContext);\r
+            provisionEnrolleInstance.registerProvisioningHandler(new IProvisioningListener() {\r
+                @Override\r
+                public void onFinishProvisioning(int statuscode) {\r
+                    mState = (statuscode == 0) ? EnrolleeState.DEVICE_PROVISIONING_SUCCESS_STATE : EnrolleeState.DEVICE_PROVISIONING_FAILED_STATE;\r
+                    mProvisioningCallback.onFinished(EnrolleeDeviceWiFiOnboarding.this);\r
+                }\r
+            });\r
+\r
+            IpOnBoardingConnection connection = (IpOnBoardingConnection) conn;\r
+            WiFiProvConfig wifiProvConfig = (WiFiProvConfig) mProvConfig;\r
+\r
+            // Native Api call to start provisioning of the enrolling device\r
+            EasySetupManager.getInstance().provisionEnrollee(connection.getIp(), wifiProvConfig.getSsId(), wifiProvConfig.getPassword(), mOnBoardingConfig.getConnType().getValue());\r
+\r
+        }\r
+\r
+    }\r
+\r
+\r
+}\r
index 4d55218..73637d8 100755 (executable)
@@ -1,66 +1,66 @@
-/**
- * ***************************************************************
- * <p>
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- * <p>
- * <p>
- * <p>
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.
- * <p>
- * ****************************************************************
- */
-
-package org.iotivity.service.easysetup.impl;
-
-import org.iotivity.service.easysetup.core.IpConnection;
-import org.iotivity.service.easysetup.core.OnBoardingConfig;
-
-import android.net.wifi.WifiConfiguration;
-
-/**
- * This class contains on boarding configuration information for Soft AP on boarding connectivity.
- * It implements OnBoardingConfig interface & provide implementation for WiFi Soft AP connectivity.
- */
-
-public class WiFiOnBoardingConfig implements OnBoardingConfig {
-
-    private final WifiConfiguration config = new WifiConfiguration();
-    private final ConnType mConnType = OnBoardingConfig.ConnType.WiFi;
-    private IpConnection mConnection;
-
-    @Override
-    public Object getConfig() {
-        return config;
-    }
-
-    public void setSSId(String ssid) {
-        config.SSID = ssid;
-    }
-
-    public void setSharedKey(String sharedKey) {
-        config.preSharedKey = sharedKey;
-    }
-
-    public void setAuthAlgo(int aurthAlgo) {
-        config.allowedAuthAlgorithms.set(aurthAlgo);
-    }
-
-    public void setKms(int kms) {
-        config.allowedKeyManagement.set(kms);
-    }
-
-    @Override
-    public ConnType getConnType() {
-        return mConnType;
-    }
-}
+/**\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
+\r
+package org.iotivity.service.easysetup.impl;\r
+\r
+import org.iotivity.service.easysetup.core.IpOnBoardingConnection;\r
+import org.iotivity.service.easysetup.core.OnBoardingConfig;\r
+\r
+import android.net.wifi.WifiConfiguration;\r
+\r
+/**\r
+ * This class contains on boarding configuration information for Soft AP on boarding connectivity.\r
+ * It implements OnBoardingConfig interface & provide implementation for WiFi Soft AP connectivity.\r
+ */\r
+\r
+public class WiFiOnBoardingConfig implements OnBoardingConfig {\r
+\r
+    private final WifiConfiguration config = new WifiConfiguration();\r
+    private final ConnType mConnType = OnBoardingConfig.ConnType.WiFi;\r
+    private IpOnBoardingConnection mConnection;\r
+\r
+    @Override\r
+    public Object getConfig() {\r
+        return config;\r
+    }\r
+\r
+    public void setSSId(String ssid) {\r
+        config.SSID = ssid;\r
+    }\r
+\r
+    public void setSharedKey(String sharedKey) {\r
+        config.preSharedKey = sharedKey;\r
+    }\r
+\r
+    public void setAuthAlgo(int aurthAlgo) {\r
+        config.allowedAuthAlgorithms.set(aurthAlgo);\r
+    }\r
+\r
+    public void setKms(int kms) {\r
+        config.allowedKeyManagement.set(kms);\r
+    }\r
+\r
+    @Override\r
+    public ConnType getConnType() {\r
+        return mConnType;\r
+    }\r
+}\r