Modified android mediator UI for BLE onBoarding
authorVinil Jain <vinil.gj@samsung.com>
Wed, 23 Sep 2015 04:44:41 +0000 (10:14 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Wed, 23 Sep 2015 07:46:08 +0000 (07:46 +0000)
Change-Id: I9e8fe6d3a3b3e49d3e16881b38d9e6683a1844da
Signed-off-by: Vinil Jain <vinil.gj@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2973
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/BLEActivity.java
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/layout/activity_ble.xml
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/BleConnection.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceBLEOnBoarding.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ble/BLEManager.java
service/easy-setup/sdk/mediator/android/jni/jni_easy_setup.cpp
service/easy-setup/sdk/mediator/src/ble_provisioning.cpp

index 4ccbb42..be40bac 100644 (file)
 // limitations under the License.
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
 package org.iotivity.service.easysetup;
 
-import android.app.Activity;
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothManager;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.widget.Toast;
+import java.io.IOException;
 
+import org.iotivity.service.easysetup.core.BleConnection;
 import org.iotivity.service.easysetup.core.EasySetupService;
 import org.iotivity.service.easysetup.core.EasySetupStatus;
 import org.iotivity.service.easysetup.core.EnrolleeDevice;
@@ -38,11 +31,50 @@ import org.iotivity.service.easysetup.impl.BLEOnBoardingConfig;
 import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory;
 import org.iotivity.service.easysetup.impl.WiFiProvConfig;
 
-import java.io.IOException;
+import android.app.Activity;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+import android.widget.Toast;
 
 public class BLEActivity extends Activity {
+
+
+    /*Status to update the UI */
+    public static final int SUCCESS = 0;
+    public static final int FAILED = 1;
+    public static final int STATE_CHANGED = 2;
+
+    EditText mEnrolleeSsidText;
+    EditText mmEnrolleePasswordPassText;
+
+
+    TextView mDeviceNameTextView;
+    TextView mDeviceMacTextView;
+    TextView mDeviceUuidTextView;
+
+    TextView mResultTextView;
+    ProgressBar mProgressbar;
+    Button mStartButton;
+    Button mStopButton;
+    Handler mHandler = new ThreadHandler();
+
+    /**
+     * Objects to be instantiated by the programmer
+     */
     WiFiProvConfig mWiFiProvConfig;
-    BLEOnBoardingConfig bleOnBoardingConfig;
+    BLEOnBoardingConfig mBleOnBoardingConfig;
     EasySetupService mEasySetupService;
     EnrolleeDeviceFactory mDeviceFactory;
     EnrolleeDevice mDevice;
@@ -54,59 +86,132 @@ public class BLEActivity extends Activity {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_ble);
 
-        mDeviceFactory = EnrolleeDeviceFactory.newInstance(getApplicationContext());
+        /* Initialize widgets to get user input for target network's SSID & password*/
+        mEnrolleeSsidText = (EditText) findViewById(R.id.enrolleeSsid);
+        mmEnrolleePasswordPassText = (EditText) findViewById(R.id.enrolleePass);
+        mDeviceNameTextView = (TextView) findViewById(R.id.devicename);
+        mDeviceMacTextView = (TextView) findViewById(R.id.hardAddr);
+        mDeviceUuidTextView = (TextView) findViewById(R.id.uuid);
+        mResultTextView = (TextView) findViewById(R.id.status);
+        mProgressbar = (ProgressBar) findViewById(R.id.progressBar);
+        mStartButton = (Button) findViewById(R.id.startSetup);
+        mStopButton = (Button) findViewById(R.id.stopSetup);
 
-        mDevice = mDeviceFactory.newEnrolleeDevice(getOnBoardingWifiConfig(), getEnrollerWifiConfig());
+        //default SSID and password
+        mEnrolleeSsidText.setText("hub2.4G");
+        mmEnrolleePasswordPassText.setText("11112222");
+
+       /* Create Easy Setup Service instance*/
+        mEasySetupService = EasySetupService.getInstance(getApplicationContext(),
+                new EasySetupStatus() {
 
-        EasySetupStatus easySetupStatus = new EasySetupStatus() {
-            @Override
-            public void onFinished(EnrolleeDevice enrolleeDevice) {
-                final String msg = mDevice.isSetupSuccessful() ? "Device configured successfully" : "Device configuration failed";
-                runOnUiThread(new Runnable() {
                     @Override
-                    public void run() {
-                        Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
+                    public void onFinished(final EnrolleeDevice enrolledevice) {
+                        Log.i("BleActivity", "onFinished() is received " + enrolledevice
+                                .isSetupSuccessful());
+                        if (enrolledevice.isSetupSuccessful()) {
+                            mHandler.sendEmptyMessage(SUCCESS);
+                        } else {
+                            mHandler.sendEmptyMessage(FAILED);
+                        }
                     }
-                });
 
-            }
-
-            @Override
-            public void onProgress(EnrolleeState enrolleeState) {
-                runOnUiThread(new Runnable() {
                     @Override
-                    public void run() {
-                        Toast.makeText(getApplicationContext(), "Device state changed", Toast.LENGTH_SHORT).show();
+                    public void onProgress(EnrolleeState state) {
+                        Log.i("MainActivity", "onProgress() is received ");
+                        mHandler.sendEmptyMessage(STATE_CHANGED);
                     }
+
                 });
 
+        /* Create EnrolleeDevice Factory instance*/
+        mDeviceFactory = EnrolleeDeviceFactory.newInstance(getApplicationContext());
+
+        addListnerforStartES();
+        addListenerForStopES();
 
+
+    }
+
+    public void addListnerforStartES() {
+
+        mStartButton.setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                mProgressbar.setVisibility(View.VISIBLE);
+                mProgressbar.setIndeterminate(true);
+                mStartButton.setEnabled(false);
+                mResultTextView.setText(R.string.running);
+                mStopButton.setEnabled(true);
+                start();
             }
-        };
-        mEasySetupService = EasySetupService.getInstance(getApplicationContext(), easySetupStatus);
-        start();
+        });
     }
 
+    public void addListenerForStopES() {
+        mStopButton = (Button) findViewById(R.id.stopSetup);
+
+        mStopButton.setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View arg0) {
+                mStartButton.setEnabled(true);
+                mStopButton.setEnabled(false);
+                mResultTextView.setText(R.string.stopped);
+                mProgressbar.setIndeterminate(false);
+                mProgressbar.setVisibility(View.INVISIBLE);
+                mEasySetupService.stopSetup(mDevice);
+            }
+        });
+    }
+
+
     public WiFiProvConfig getEnrollerWifiConfig() {
-        // SET the wifi credentials here
-        mWiFiProvConfig = new WiFiProvConfig("linksysy", "12345678");
+        /* Provide the credentials for the Mediator Soft AP to be connected by Enrollee*/
+        mWiFiProvConfig = new WiFiProvConfig(mEnrolleeSsidText.getText().toString(),
+                mmEnrolleePasswordPassText.getText().toString());
         return mWiFiProvConfig;
     }
 
     public BLEOnBoardingConfig getOnBoardingWifiConfig() {
         // Set the uuid of the OIC device here
-        bleOnBoardingConfig = new BLEOnBoardingConfig();
-        bleOnBoardingConfig.setUuid("ade3d529-c784-4f63-a987-eb69f70ee816");
+        mBleOnBoardingConfig = new BLEOnBoardingConfig();
+        /*
+        set the uuid of the OIC-device, so that the Easysetup API can find the device
+         */
+        mBleOnBoardingConfig.setUuid("ade3d529-c784-4f63-a987-eb69f70ee816");
 
-        return bleOnBoardingConfig;
+        return mBleOnBoardingConfig;
     }
 
 
-    @Override
-    public boolean onCreateOptionsMenu(Menu menu) {
-        // Inflate the menu; this adds items to the action bar if it is present.
-        getMenuInflater().inflate(R.menu.menu_ble, menu);
-        return true;
+    public void onDestroy() {
+        super.onDestroy();
+        /*Reset the Easy setup process*/
+        if (mEasySetupService != null) {
+            mEasySetupService.finish();
+        }
+    }
+
+    public void start() {
+        //This function starts the bluetooth adpater so that the easysetup can start scanning for BLE devices
+        final BluetoothManager bluetoothManager =
+                (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
+        BluetoothAdapter mBluetoothAdapter = bluetoothManager.getAdapter();
+
+        if (!mBluetoothAdapter.isEnabled()) {
+            //Bluetooth is disabled, enable it
+            Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
+            startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
+        } else try {
+            //IF bluetooth is directly enabled it will directly start the setup of enrollee devices
+
+                    /* Create a device using Factory instance*/
+            mDevice = mDeviceFactory.newEnrolleeDevice(getOnBoardingWifiConfig(),
+                    getEnrollerWifiConfig());
+            mEasySetupService.startSetup(mDevice);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
     }
 
     @Override
@@ -115,10 +220,12 @@ public class BLEActivity extends Activity {
         if (requestCode == REQUEST_ENABLE_BT && resultCode == Activity.RESULT_CANCELED) {
             Log.e("error bluetooth", "Bluetooth not enabled..Try again");
             Toast.makeText(BLEActivity.this, "Bluetooth not enabled..Try again", Toast.LENGTH_SHORT).show();
-            finish();
             return;
         } else try {
             //bluetooth is  enabled, now start the setup of enrollee devices
+                    /* Create a device using Factory instance*/
+            mDevice = mDeviceFactory.newEnrolleeDevice(getOnBoardingWifiConfig(),
+                    getEnrollerWifiConfig());
             mEasySetupService.startSetup(mDevice);
         } catch (IOException e) {
             e.printStackTrace();
@@ -126,36 +233,52 @@ public class BLEActivity extends Activity {
         super.onActivityResult(requestCode, resultCode, data);
     }
 
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-        // Handle action bar item clicks here. The action bar will
-        // automatically handle clicks on the Home/Up button, so long
-        // as you specify a parent activity in AndroidManifest.xml.
-        int id = item.getItemId();
-
-        //noinspection SimplifiableIfStatement
-        if (id == R.id.action_settings) {
-            return true;
-        }
 
-        return super.onOptionsItemSelected(item);
-    }
+    class ThreadHandler extends Handler {
+        @Override
+        public void handleMessage(Message msg) {
+
+            switch (msg.what) {
+                case SUCCESS: {
+
+                    mProgressbar.setIndeterminate(false);
+                    mStopButton.setEnabled(false);
+                    mStartButton.setEnabled(true);
+                    mProgressbar.setVisibility(View.INVISIBLE);
+                    String resultMsg = "Device configured successfully";
+                    mResultTextView.setText(R.string.success);
+
+                    /* Update device information on the Ui */
+                    BleConnection connection = (BleConnection) mDevice
+                            .getConnection();
+                    mDeviceNameTextView.setText(connection.getmDeviceName());
+                    mDeviceMacTextView.setText(connection.getMacaddress());
+                    mDeviceUuidTextView.setText(connection.getmServiceUUID());
+                    Toast.makeText(getApplicationContext(), resultMsg, Toast.LENGTH_SHORT).show();
+                    break;
+                }
+                case FAILED: {
+
+                    mProgressbar.setIndeterminate(false);
+                    mStopButton.setEnabled(false);
+                    mStartButton.setEnabled(true);
+                    mProgressbar.setVisibility(View.INVISIBLE);
+                    String resultMsg = "Device configuration failed";
+                    mResultTextView.setText(R.string.failed);
+                    Toast.makeText(getApplicationContext(), resultMsg, Toast.LENGTH_SHORT).show();
+                    break;
+                }
+
+                case STATE_CHANGED: {
+                    String resultMsg = "Device state changed";
+                    Toast.makeText(getApplicationContext(), resultMsg, Toast.LENGTH_SHORT).show();
+                    break;
+                }
+
+            }
 
-    public void start() {
-        //This function starts the bluetooth adpater so that the easysetup can start scanning for BLE devices
-        final BluetoothManager bluetoothManager =
-                (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
-        BluetoothAdapter mBluetoothAdapter = bluetoothManager.getAdapter();
 
-        if (!mBluetoothAdapter.isEnabled()) {
-            //Bluetooth is disabled, enable it
-            Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
-            startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
-        } else try {
-            //IF bluetooth is directly enabled it will directly start the setup of enrollee devices
-            mEasySetupService.startSetup(mDevice);
-        } catch (IOException e) {
-            e.printStackTrace();
         }
     }
+
 }
index 033f9bc..c60ab01 100644 (file)
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<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.BLEActivity">
 
+
+    <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="5dp"
+        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="15sp" />
+
+        <TextView
+            android:id="@+id/status"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="10dp"
+            android:layout_marginRight="30dp"
+            android:text="@string/not_started"
+            android:textColor="@android:color/background_light"
+            android:textSize="20dp" />
+
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerHorizontal="true"
+        android:layout_gravity="center"
+        android:layout_marginTop="10dp"
+        android:orientation="vertical">
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="Enter Enroller's SSID" />
+
+
+        <EditText
+            android:id="@+id/enrolleeSsid"
+            android:layout_width="250dp"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal" />
+
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="10dp"
+            android:text="Enter Enroller's Password" />
+
+
+        <EditText
+            android:id="@+id/enrolleePass"
+            android:layout_width="250dp"
+            android:layout_height="wrap_content"
+
+            android:layout_gravity="center_horizontal" />
+
+    </LinearLayout>
+
+
     <TextView
-        android:id="@+id/textView_ble"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:text="hello_world" />
+        android:layout_gravity="center_horizontal"
+        android:layout_marginTop="5dp"
+        android:text="Device information"
+        android:textAppearance="?android:attr/textAppearanceMedium" />
+
+    <RelativeLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerHorizontal="true"
+        android:layout_gravity="center"
+        android:layout_marginTop="10dp"
+        android:orientation="vertical">
+
+        <TextView
+            android:id="@+id/devicenamelabel"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal"
+            android:text="Device Name:"
+            android:textAppearance="?android:attr/textAppearanceSmall" />
+
+        <TextView
+            android:id="@+id/devicename"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal"
+            android:layout_toRightOf="@id/devicenamelabel"
+            android:text="@string/not_available"
+
+            android:textAppearance="?android:attr/textAppearanceSmall" />
+
+        <TextView
+            android:id="@+id/uuidLable"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/devicenamelabel"
+            android:layout_gravity="center_horizontal"
+            android:text="UUID:"
+            android:textAppearance="?android:attr/textAppearanceSmall" />
+
+        <TextView
+            android:id="@+id/uuid"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/devicename"
+            android:layout_gravity="center_horizontal"
+            android:layout_toRightOf="@id/uuidLable"
+            android:text="@string/not_available"
+
+            android:textAppearance="?android:attr/textAppearanceSmall" />
+
+
+        <TextView
+            android:id="@+id/hardAddrLable"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/uuidLable"
+            android:layout_gravity="center_horizontal"
+            android:text="MAC Address:"
+            android:textAppearance="?android:attr/textAppearanceSmall" />
+
+        <TextView
+            android:id="@+id/hardAddr"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/uuid"
+            android:layout_gravity="center_horizontal"
+            android:layout_toRightOf="@id/hardAddrLable"
+            android:text="@string/not_available"
+            android:textAppearance="?android:attr/textAppearanceSmall" />
+
+
+    </RelativeLayout>
+
+
+    <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:enabled="false"
+            android:text="@string/stopSetup"
+            android:textAllCaps="false"
+            android:textSize="18sp" />
+
+    </LinearLayout>
 
-</RelativeLayout>
+</LinearLayout>
\ No newline at end of file
index 8b90f80..eca0b18 100755 (executable)
@@ -24,6 +24,7 @@ public class BleConnection implements OnBoardingConnection {
     private boolean mIsConnected;
     private String mServiceUUID;
     private String macaddress;
+    private String mDeviceName;
 
     public void setConnectivity(boolean connected) {
         mIsConnected = connected;
@@ -60,4 +61,11 @@ public class BleConnection implements OnBoardingConnection {
         return this;
     }
 
+    public String getmDeviceName() {
+        return mDeviceName;
+    }
+
+    public void setmDeviceName(String mDeviceName) {
+        this.mDeviceName = mDeviceName;
+    }
 }
index b97580c..406ee0e 100755 (executable)
@@ -67,6 +67,8 @@ public class EnrolleeDeviceBLEOnBoarding extends EnrolleeDevice {
                     BleConnection conn = new BleConnection();
                     conn.setMacaddress(connectedDevice.getHWAddr());
                     conn.setConnectivity(true);
+                    conn.setmServiceUUID(connectedDevice.getIpAddr());
+                    conn.setmDeviceName(connectedDevice.getDevice());
                     Log.d("ESBLEOnBoarding", "Entered" + ":" + finalResult);
                     mOnBoardingCallback.onFinished(conn);
                     return;
@@ -94,7 +96,7 @@ public class EnrolleeDeviceBLEOnBoarding extends EnrolleeDevice {
         Log.i(TAG, "Starging on boarding process");
 
         boolean status = bleManager.setupBluetooth();
-
+        mState = EnrolleeState.DEVICE_ON_BOARDING_STATE;
         Log.i(TAG, "Bluetooth started with status " + status);
         if (status) {
             Log.i(TAG, "Scanning available BLE devices");
@@ -107,7 +109,8 @@ public class EnrolleeDeviceBLEOnBoarding extends EnrolleeDevice {
     @Override
     protected void stopOnBoardingProcess() {
 
-        bleManager.stopscan();
+        if (bleManager != null)
+            bleManager.stopscan();
 
     }
 
@@ -116,7 +119,7 @@ public class EnrolleeDeviceBLEOnBoarding extends EnrolleeDevice {
 
         Log.i("start provisioning BLE", mProvConfig.getConnType() + "");
 
-
+        mState = EnrolleeState.DEVICE_PROVISIONING_STATE;
         provisionEnrolleInstance = new ProvisionEnrollee(mContext);
         provisionEnrolleInstance.registerProvisioningHandler(new IProvisioningListener() {
             @Override
index 6244192..b8495e4 100644 (file)
@@ -90,15 +90,16 @@ public class BLEManager {
 
                 @Override
                 public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
-                    Log.d("device found", device.getAddress());
+                    Log.d("device found", device.getName() + device.getAddress());
                     bleOnBoardingConfig.setMacaddress(device.getAddress());
                     {
                         stopscan();
                         EnrolleeInfo result = new EnrolleeInfo();
                         result.setReachable(true);
+                        result.setDevice(device.getName());
+                        result.setIpAddr(bleOnBoardingConfig.getUuid().toString());
                         result.setHWAddr(bleOnBoardingConfig.getMacaddress());
                         NotifyApplication(result);
-
                     }
                 }
             };
index c365461..ffc2b0d 100644 (file)
 #include "jni_easy_setup_jvm.h"
 #include "prov_adapter.h"
 
-void JNIProvisioningStatusCallback(ProvisioningInfo * provInfo) {
+void JNIProvisioningStatusCallback(ProvisioningInfo * provInfo)
+{
     JNIEnv *env = EasySetupJVM::getEnv();
-    if (env == NULL) {
+    if (env == NULL)
+    {
         LOGE("JNIProvisioningStatusCallback : Getting JNIEnv failed");
         return;
     }
 
     // Get EasySetupHandler class reference
     jclass easysetupCallbacks = GetJClass(EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH);
-    if (NULL == easysetupCallbacks) {
+    if (NULL == easysetupCallbacks)
+    {
         LOGE("JNIProvisioningStatusCallback : GetJClass easysetupCallbacks failed");
         EasySetupJVM::releaseEnv();
         return;
@@ -40,7 +43,8 @@ void JNIProvisioningStatusCallback(ProvisioningInfo * provInfo) {
 
     // Get the easysetupCallback class instance
     jobject jobjectCallback = GetJObjectInstance(EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH);
-    if (NULL == jobjectCallback) {
+    if (NULL == jobjectCallback)
+    {
         LOGE("getInstance( %s) failed!", EASY_SETUP_SERVICE_CALLBACK_NATIVE_API_CLASS_PATH);
         EasySetupJVM::releaseEnv();
         return;
@@ -48,30 +52,36 @@ void JNIProvisioningStatusCallback(ProvisioningInfo * provInfo) {
 
     // Get onResourceCallback method reference
     jmethodID method_id = env->GetMethodID(easysetupCallbacks, "ProvisioningStatusCallBack",
-                                           METHOD_PROVISIONING_STATUS_INTEGER_CALLBACK);
-    if (NULL == method_id) {
+            METHOD_PROVISIONING_STATUS_INTEGER_CALLBACK);
+    if (NULL == method_id)
+    {
         LOGE("JNIProvisioningStatusCallback: onResourceCallback : GetMethodID failed");
         EasySetupJVM::releaseEnv();
         return;
     }
 
-    if ((env)->ExceptionCheck()) {
+    if ((env)->ExceptionCheck())
+    {
         LOGE("JNIProvisioningStatusCallback : ExceptionCheck failed");
         EasySetupJVM::releaseEnv();
         return;
     }
 
-    if (NULL == method_id) {
+    if (NULL == method_id)
+    {
         LOGI("JNI method_id is NULL");
     }
-    else {
+    else
+    {
         LOGI("JNI method_id is VALID");
 
         jint result;
-        if (provInfo->provStatus == DEVICE_PROVISIONED) {
+        if (provInfo->provStatus == DEVICE_PROVISIONED)
+        {
             result = 0;
         }
-        else {
+        else
+        {
             result = -1;
         }
 
@@ -83,119 +93,121 @@ void JNIProvisioningStatusCallback(ProvisioningInfo * provInfo) {
 
 JNIEXPORT void JNICALL
 JNIInitEasySetup(JNIEnv
-*env,
-jobject thisObj
+        *env,
+        jobject thisObj
 )
 {
-LOGI("JNI JNIInitEasySetup: Enter");
+    LOGI("JNI JNIInitEasySetup: Enter");
 
-InitEasySetupManager();
+    InitEasySetupManager();
 
-RegisterProvisioningStausCallback(JNIProvisioningStatusCallback);
+    RegisterProvisioningStausCallback(JNIProvisioningStatusCallback);
 }
 
 JNIEXPORT void JNICALL
 JNITerminateEasySetup(JNIEnv
-*env,
-jobject thisObj
+        *env,
+        jobject thisObj
 )
 {
-LOGI("JNI JNITerminateEasySetup: Enter");
+    LOGI("JNI JNITerminateEasySetup: Enter");
 
-TerminateEasySetupManager();
+    TerminateEasySetupManager();
 
 }
 
 JNIEXPORT void JNICALL
 JNIProvisionEnrollee(JNIEnv
-*env,
-jobject thisObj,
+        *env,
+        jobject thisObj,
         jstring
-jIPAddress,
-jstring jNetSSID,
+        jIPAddress,
+        jstring jNetSSID,
         jstring
-jNetPWD,
-jint jConnectivityType
+        jNetPWD,
+        jint jConnectivityType
 )
 {
-LOGI("JNI JNIProvisionEnrollee: Enter");
+    LOGI("JNI JNIProvisionEnrollee: Enter");
 
-if (!jIPAddress)
-{
-LOGE("JNI JNIProvisionEnrollee : jIPAddress is NULL!");
-return;
-}
+    if (!jIPAddress)
+    {
+        LOGE("JNI JNIProvisionEnrollee : jIPAddress is NULL!");
+        return;
+    }
 
-const char *ipAddress = env->GetStringUTFChars(jIPAddress, NULL);
-if (NULL == ipAddress)
-{
-LOGE("JNI JNIProvisionEnrollee : Failed to convert jstring to char string!");
-}
+    const char *ipAddress = env->GetStringUTFChars(jIPAddress, NULL);
+    if (NULL == ipAddress)
+    {
+        LOGE("JNI JNIProvisionEnrollee : Failed to convert jstring to char string!");
+    }
 
-LOGI("JNI JNIProvisionEnrollee : ipAddress is : %s",ipAddress);
+    LOGI("JNI JNIProvisionEnrollee : ipAddress is : %s",ipAddress);
 
-const char *netSSID = env->GetStringUTFChars(jNetSSID, NULL);
-if (NULL == netSSID)
-{
-LOGE("JNI JNIProvisionEnrollee : Failed to convert jstring to char string!");
-}
+    const char *netSSID = env->GetStringUTFChars(jNetSSID, NULL);
+    if (NULL == netSSID)
+    {
+        LOGE("JNI JNIProvisionEnrollee : Failed to convert jstring to char string!");
+    }
 
-LOGI("JNI JNIProvisionEnrollee : netSSID is : %s",netSSID);
+    LOGI("JNI JNIProvisionEnrollee : netSSID is : %s",netSSID);
 
-const char *netPWD = env->GetStringUTFChars(jNetPWD, NULL);
-if (NULL == netPWD)
-{
-LOGE("JNI JNIProvisionEnrollee : Failed to convert jstring to char string!");
-}
+    const char *netPWD = env->GetStringUTFChars(jNetPWD, NULL);
+    if (NULL == netPWD)
+    {
+        LOGE("JNI JNIProvisionEnrollee : Failed to convert jstring to char string!");
+    }
 
-LOGI("JNI JNIProvisionEnrollee : netPWD is : %s",netPWD);
-
-OCConnectivityType connecitivityType;
-EnrolleeNWProvInfo_t netInfo =
-        {0};
-strncpy(netInfo
-.netAddressInfo.WIFI.ipAddress, ipAddress, IPV4_ADDR_SIZE-1);
-strncpy(netInfo
-.netAddressInfo.WIFI.ssid, netSSID, NET_WIFI_SSID_SIZE-1);
-strncpy(netInfo
-.netAddressInfo.WIFI.pwd, netPWD, NET_WIFI_PWD_SIZE-1);
-netInfo.
-connType = (OCConnectivityType) jConnectivityType;
-
-if(netInfo.connType==CT_ADAPTER_GATT_BTLE)
-{
+    LOGI("JNI JNIProvisionEnrollee : netPWD is : %s",netPWD);
 
-strncpy(netInfo
-.netAddressInfo.LE.leMacAddress,ipAddress,NET_MACADDR_SIZE-1);
-LOGI("MAC set=%s",netInfo.netAddressInfo.LE.leMacAddress);
+    OCConnectivityType connecitivityType;
+    EnrolleeNWProvInfo_t netInfo =
+    {   0};
 
-}
-netInfo.
-isSecured = true;
+    netInfo.
+    connType = (OCConnectivityType) jConnectivityType;
+
+    if(netInfo.connType==CT_ADAPTER_GATT_BTLE)
+    {
+
+        strncpy(netInfo
+                .netAddressInfo.LE.leMacAddress,ipAddress,NET_MACADDR_SIZE-1);
+        LOGI("MAC set=%s",netInfo.netAddressInfo.LE.leMacAddress);
+
+    }
+    else strncpy(netInfo.netAddressInfo.WIFI.ipAddress, ipAddress, IPV4_ADDR_SIZE-1);
+
+    strncpy(netInfo
+            .netAddressInfo.WIFI.ssid, netSSID, NET_WIFI_SSID_SIZE-1);
+    strncpy(netInfo
+            .netAddressInfo.WIFI.pwd, netPWD, NET_WIFI_PWD_SIZE-1);
+
+    netInfo.
+    isSecured = true;
 
-ProvisionEnrollee(&netInfo);
+    ProvisionEnrollee(&netInfo);
 
-return;
+    return;
 }
 
 JNIEXPORT void JNICALL
 JNIStopEnrolleeProvisioning(JNIEnv
-*env,
-jobject thisObj,
+        *env,
+        jobject thisObj,
         jint
-jConnectivityType)
+        jConnectivityType)
 {
-LOGI("JNI Stop Easy Setup: Entering");
+    LOGI("JNI Stop Easy Setup: Entering");
 
-OCConnectivityType connecitivityType = OCConnectivityType::CT_DEFAULT;
+    OCConnectivityType connecitivityType = OCConnectivityType::CT_DEFAULT;
 
-if(jConnectivityType == 0)
-{
-connecitivityType = OCConnectivityType::CT_ADAPTER_IP;
-}
+    if(jConnectivityType == 0)
+    {
+        connecitivityType = OCConnectivityType::CT_ADAPTER_IP;
+    }
 
-StopEnrolleeProvisioning(connecitivityType);
+    StopEnrolleeProvisioning(connecitivityType);
 
-return;
+    return;
 }
 
index 6280f35..31bed85 100644 (file)
@@ -184,8 +184,8 @@ OCStackApplicationResult ProvisionEnrolleeResponse(void *ctx, OCDoHandle handle,
 
 OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char *query, const char *resUri,
                                 OCDevAddr *destination) {
-    OIC_LOG_V(INFO, TAG, "Sleeping for 2 seconds");
-    sleep(2);
+    OIC_LOG_V(INFO, TAG, "Sleeping for 6 seconds");
+    sleep(6);//sleep added to avoid BLE packet drop
     OIC_LOG_V(INFO, TAG, "\n\nExecuting ProvisionEnrollee%s", __func__);
 
     OCRepPayload *payload = OCRepPayloadCreate();