From: Madan Lanka Date: Tue, 14 Jul 2015 10:27:37 +0000 (-0400) Subject: Android OnBoarding code modifications to handle multiple transports X-Git-Tag: 1.0.0-RC1^2~27^2~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bff4714132826649ce07b8ecad114a577afd2717;p=contrib%2Fiotivity.git Android OnBoarding code modifications to handle multiple transports 1) Used factory pattern to support Enrollee Device on different transports 2) Defined new classes to handle provisioing information of different transports 3) Modified OnBoarding logic to handle onBoarding of Enrollee Devices and provisioning steps in a generic way Change-Id: I958ee0d44415eecde44de98e977795819d8e55d7 Signed-off-by: Madan Lanka Reviewed-on: https://gerrit.iotivity.org/gerrit/1645 Reviewed-by: Uze Choi Tested-by: Uze Choi --- diff --git a/service/easy-setup/readme.txt b/service/easy-setup/readme.txt index 61202ef..6affd2e 100644 --- a/service/easy-setup/readme.txt +++ b/service/easy-setup/readme.txt @@ -1,15 +1,15 @@ Steps to build and deploy Easysetup Mediator in Android platform -1) Compilation +1) Compilation using Scons 0) Prerequisite exports for Android export ANDROID_HOME= export ANDROID_NDK= a) In the IoTivity root source folder execute scons TARGET_OS=android TARGET_ARCH=armeabi TARGET_TRANSPORT=IP RELEASE=0 - b) Step (a) will generate cross compiled base libraries and places them in the folder - /out/android/armeabi/debug + b) If the project is setup correctly, you should see a BUILD SUCCESSFUL message on the terminal + You should see the .aar files generated inside of '/android/android_api/base/build/outputs/aar' directory. The .aar files contain jni directory and also a .jar file c) Now navigate to the Easysetup NDK folder /service/easy-setup/sdk/android @@ -19,28 +19,41 @@ Steps to build and deploy Easysetup Mediator in Android platform e) Step (d) will generate cross compiled Easysetup JNI .so files in the following folder - - -2) Execution +2) Compilation using Android Studio 0) Prerequisite for running the Android application - Install Android SDK and ADK in eclipse using the Android SDK manager + Install Android Studio and use the Android SDK manager to update the Android API to 21 - a) Import following projects to the Eclipse using the "Import->Android->Existing Android Code Into Workspace" + a) Import following projects to the Studio using the "File->New->Import Project" - service\easy-setup\sdk\android\EasySetupCore - service\easy-setup\sampleapp\android\EasySetup - - b) Drag and drop the following .so files in to the EasySetup->libs->armeabi folder - - libca-interface.so - - libconnectivity_abstraction.so - - libeasysetup-jni.so [Easy Setup file] - - libESSDK.so [Easy Setup file] - - libgnustl_shared.so - - liboc_logger.so - - liboc.so - - libocstack-jni.so - - liboctbstack.so - c) Run "Easy Setup" as an Android application + + b) EasySetupCore is dependent on the .aar files generated in 1.b + 1) To add an .aar file to the 'EasySetupCore' project, + a.Right click on EasySetup->New->Module->Import .JAR or .AAR Package + b.Select the .aar file(iotivity-armeabi-base-*.aar) from the location in steps 1.b + c.Right click on EasySetup->Open Module Settings + d.Select each sample app module under 'Modules'->Dependencies->Add->Module Dependency + + c) Build EasySetupCore project using "Android Studio->Build->Make Module "easySetupCore" + If the project is setup correctly, you should see a BUILD SUCCESSFUL in the Android Studio Gradle Build terminal + You should see the .aar file generated inside of + 'iotivity\service\easy-setup\sdk\mediator\android\easySetupCore\build\outputs\aar' + + d) EasySetup application is also dependent on the .so files generated in 1.d step + 1) Drag and drop the following .so files in to the EasySetup\app\src\main\jniLibs\armeabi folder + - libeasysetup-jni.so [Easy Setup file] + + e) EasySetup is also dependent on the .aar files generated in 1.b and 2.c steps + 1) To add an .aar file to the 'EasySetup' project, + a.Right click on EasySetup->New->Module->Import .JAR or .AAR Package + b.Select the .aar file from the location in steps 1.b and 2.b above + c.Right click on EasySetup->Open Module Settings + d.Select each sample app module under 'Modules'->Dependencies->Add->Module Dependency + e.The .aar files (easySetupCore-*.aar & iotivity-armeabi-base-*.aar) selected in step 2.c.1.b above should be present. Select it. + + + e) Run "Easy Setup" as an Android application Folder structure iotivity/ diff --git a/service/easy-setup/sampleapp/android/EasySetup/app/app.iml b/service/easy-setup/sampleapp/android/EasySetup/app/app.iml index e08d4b5..b14367f 100644 --- a/service/easy-setup/sampleapp/android/EasySetup/app/app.iml +++ b/service/easy-setup/sampleapp/android/EasySetup/app/app.iml @@ -1,5 +1,5 @@ - + @@ -69,8 +69,8 @@ - - + + diff --git a/service/easy-setup/sampleapp/android/EasySetup/app/src/main/AndroidManifest.xml b/service/easy-setup/sampleapp/android/EasySetup/app/src/main/AndroidManifest.xml index e65794b..d3e74dd 100644 --- a/service/easy-setup/sampleapp/android/EasySetup/app/src/main/AndroidManifest.xml +++ b/service/easy-setup/sampleapp/android/EasySetup/app/src/main/AndroidManifest.xml @@ -33,40 +33,6 @@ - - - - - - - - - - diff --git a/service/easy-setup/sampleapp/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/MainActivity.java b/service/easy-setup/sampleapp/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/MainActivity.java index 5d87d6a..3b785e5 100644 --- a/service/easy-setup/sampleapp/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/MainActivity.java +++ b/service/easy-setup/sampleapp/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/MainActivity.java @@ -27,11 +27,15 @@ import org.iotivity.base.OcPlatform; import org.iotivity.base.PlatformConfig; import org.iotivity.base.QualityOfService; import org.iotivity.base.ServiceType; -import org.iotivity.service.easysetup.mediator.EnrolleeInfo; +import org.iotivity.service.easysetup.mediator.common.EnrolleeDevice; import org.iotivity.service.easysetup.mediator.IOnBoardingStatus; import org.iotivity.service.easysetup.mediator.IProvisioningListener; import org.iotivity.service.easysetup.mediator.OnBoardEnrollee; import org.iotivity.service.easysetup.mediator.ProvisionEnrollee; +import org.iotivity.base.OcConnectivityType; +import org.iotivity.service.easysetup.mediator.ip.IPEnrolleeDevice; +import org.iotivity.service.easysetup.mediator.ip.IPProvisioningInfo; +import org.iotivity.service.easysetup.mediator.ip.WiFiSoftAPOnBoardingConfig; import android.app.Activity; import android.content.Intent; @@ -58,7 +62,7 @@ public class MainActivity extends Activity implements IProvisioningListener, static int easySetupCount = 0; static final int REQUEST_IMAGE_CAPTURE = 1; ImageView imageView; - EnrolleeInfo connectedDevice; + EnrolleeDevice connectedDevice; OnBoardEnrollee onBoardingHandlerInstance; ProvisionEnrollee provisionEnrolleInstance; @@ -71,7 +75,7 @@ public class MainActivity extends Activity implements IProvisioningListener, textView1 = (TextView) findViewById(R.id.textView1); // OnBoarding Process - onBoardingHandlerInstance = new OnBoardEnrollee(this); + onBoardingHandlerInstance = new OnBoardEnrollee(this, OcConnectivityType.IPV4); onBoardingHandlerInstance.registerOnBoardingStatusHandler(this); // Get intent, action and MIME type @@ -79,14 +83,6 @@ public class MainActivity extends Activity implements IProvisioningListener, String action = intent.getAction(); String type = intent.getType(); - if (Intent.ACTION_SEND.equals(action) && type != null) { - if ("text/plain".equals(type)) { - handleSendText(intent); // Handle text being sent - } - } else { - // Handle other intents, such as being started from the home screen - } - addListenerForStartAP(); addListenerForStopAP(); addListenerOnProvisioning(); @@ -96,7 +92,7 @@ public class MainActivity extends Activity implements IProvisioningListener, myTimer2.schedule(new TimerTask() { @Override public void run() { - onBoardingHandlerInstance.startDeviceScan(); + onBoardingHandlerInstance.startDeviceScan(300); } }, 0, 2000); @@ -106,7 +102,7 @@ public class MainActivity extends Activity implements IProvisioningListener, super.onDestroy(); if(provisionEnrolleInstance != null) { - provisionEnrolleInstance.stopEnrolleeProvisioning(0); + provisionEnrolleInstance.stopEnrolleeProvisioning(OcConnectivityType.IPV4); } onBoardingHandlerInstance.disableWiFiAP(); finish(); @@ -133,16 +129,17 @@ public class MainActivity extends Activity implements IProvisioningListener, public void run() { // TODO Auto-generated method stub Toast toast = null; + IPEnrolleeDevice ipEnrolleeDevice = (IPEnrolleeDevice)connectedDevice; if (statuscode == 0) { toast = Toast.makeText(getApplicationContext(), - connectedDevice.getIpAddr() + ipEnrolleeDevice.getIpAddr() + " - is Provisioned", Toast.LENGTH_LONG); Log.i("EasyConnect", "Provisioned statuscode-" + statuscode); } else { toast = Toast.makeText(getApplicationContext(), - connectedDevice.getIpAddr() + ipEnrolleeDevice.getIpAddr() + " - is NOT Provisioned", Toast.LENGTH_LONG); Log.i("EasyConnect", "Not Provisioned statuscode-" @@ -157,45 +154,9 @@ public class MainActivity extends Activity implements IProvisioningListener, } } - void handleSendText(Intent intent) { - String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); - if (sharedText != null) { - // Update UI to reflect text being shared - WifiConfiguration netConfig = new WifiConfiguration(); - netConfig.SSID = "EasyConnect"; - netConfig.allowedAuthAlgorithms - .set(WifiConfiguration.AuthAlgorithm.OPEN); - // netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); - // netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); - netConfig.allowedKeyManagement - .set(WifiConfiguration.KeyMgmt.WPA_PSK); - netConfig.preSharedKey = "EasyConnect"; - // netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); - // netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); - // netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); - // netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); - onBoardingHandlerInstance.enableWiFiAP(netConfig, true); - - Toast.makeText(getApplicationContext(), - "QR Code Captured. Starting Wi-Fi Access Point!", - Toast.LENGTH_LONG).show(); - - myTimer = new Timer(); - myTimer.schedule(new TimerTask() { - @Override - public void run() { - scan(); - scanCount++; - Log.i("EasyConnect", "Scan Count -" + scanCount); - } - - }, 0, 5000); - } - } - private void scan() { onBoardingHandlerInstance.registerOnBoardingStatusHandler(this); - onBoardingHandlerInstance.startDeviceScan(); + onBoardingHandlerInstance.startDeviceScan(300); } public void addListenerForStartAP() { @@ -204,20 +165,19 @@ public class MainActivity extends Activity implements IProvisioningListener, button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { + WiFiSoftAPOnBoardingConfig transportConfig = new WiFiSoftAPOnBoardingConfig(); + WifiConfiguration netConfig = new WifiConfiguration(); netConfig.SSID = "EasySetup123"; netConfig.allowedAuthAlgorithms .set(WifiConfiguration.AuthAlgorithm.OPEN); - // netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); - // netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); netConfig.allowedKeyManagement .set(WifiConfiguration.KeyMgmt.WPA_PSK); netConfig.preSharedKey = "EasySetup123"; - // netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); - // netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); - // netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); - // netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); - onBoardingHandlerInstance.enableWiFiAP(netConfig, true); + + transportConfig.setConnectivityType(OcConnectivityType.IPV4); + transportConfig.setNetConfig(netConfig); + onBoardingHandlerInstance.enableNetwork(transportConfig, true); } }); } @@ -239,13 +199,20 @@ public class MainActivity extends Activity implements IProvisioningListener, button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { + IPEnrolleeDevice ipEnrolleeDevice = (IPEnrolleeDevice)connectedDevice; + IPProvisioningInfo ipProvisioningInfo = new IPProvisioningInfo(); + + ipProvisioningInfo.setConnectivityType(OcConnectivityType.IPV4); + ipProvisioningInfo.setIpAddress(ipEnrolleeDevice.getIpAddr()); + ipProvisioningInfo.setNetSSID("EasySetup123"); + ipProvisioningInfo.setNetPWD("EasySetup123"); + provisionEnrolleInstance.provisionEnrollee( - connectedDevice.getIpAddr(), "EasySetup123", - "EasySetup123", 0); + ipProvisioningInfo, OcConnectivityType.IPV4); easySetupCount++; Log.i("EasyConnect", "easy Setup Count-" + easySetupCount); Log.i("EasyConnect", - "IP Address-" + connectedDevice.getIpAddr()); + "IP Address-" + ipProvisioningInfo.getIpAddress()); } }); @@ -277,58 +244,59 @@ public class MainActivity extends Activity implements IProvisioningListener, } @Override - public void deviceOnBoardingStatus(EnrolleeInfo enrolleStatus) { + public void deviceOnBoardingStatus(EnrolleeDevice enrolleeDevice) { // TODO Auto-generated method stub // TODO Auto-generated method stub - if (enrolleStatus != null && enrolleStatus.getIpAddr() != null) { - String finalResult = "Easy Connect : "; + if(enrolleeDevice.getConnectivityType() == OcConnectivityType.IPV4) { + IPEnrolleeDevice ipEnrolleeDevice = (IPEnrolleeDevice)enrolleeDevice; + if (ipEnrolleeDevice.getIpAddr() != null) { + String finalResult = "Easy Connect : "; + if (ipEnrolleeDevice.isReachable()) { + finalResult = "Device OnBoarded" + "[" + + ipEnrolleeDevice.getIpAddr() + "]"; + + /* + * easySetupInstance.StartEasySetup(enrolleStatus.getIpAddr()) ; + * easySetupCount++; Log.i("EasyConnect", + * "easy Setup Count-"+easySetupCount); Log.i("EasyConnect", + * "IP Address-"+enrolleStatus.getIpAddr()); + */ + connectedDevice = ipEnrolleeDevice; + + // Only after onboarding is successful, provisioning is performed + provisionEnrolleInstance = new ProvisionEnrollee(this); + provisionEnrolleInstance.registerProvisioningHandler(this); + + } else { + finalResult = "Device Removed" + "[" + + ipEnrolleeDevice.getIpAddr() + "]"; + } - if (enrolleStatus.isReachable()) { - finalResult = "Device OnBoarded" + "[" - + enrolleStatus.getIpAddr() + "]"; + textView1.setText(""); + textView1.append("Clients: \n"); + textView1.append("####################\n"); + textView1.append("IP Address : " + ipEnrolleeDevice.getIpAddr() + + "\n"); + textView1.append("HW Address : " + ipEnrolleeDevice.getHWAddr() + + "\n"); + textView1.append("Is OnBoarded : " + ipEnrolleeDevice.isReachable() + + "\n"); + + Toast.makeText(getApplicationContext(), finalResult, + Toast.LENGTH_LONG).show(); /* - * easySetupInstance.StartEasySetup(enrolleStatus.getIpAddr()) ; + * myTimer2 = new Timer(); myTimer2.schedule(new TimerTask() { + * + * @Override public void run() { + * easySetupInstance.StartEasySetup(enrolleStatus.getIpAddr()); * easySetupCount++; Log.i("EasyConnect", * "easy Setup Count-"+easySetupCount); Log.i("EasyConnect", - * "IP Address-"+enrolleStatus.getIpAddr()); + * "IP Address-"+enrolleStatus.getIpAddr()); } + * + * }, 0, 10000); */ - connectedDevice = enrolleStatus; - - // Only after onboarding is successful, provisioning is performed - provisionEnrolleInstance = new ProvisionEnrollee(this); - provisionEnrolleInstance.registerProvisioningHandler(this); - - } else { - finalResult = "Device Removed" + "[" - + enrolleStatus.getIpAddr() + "]"; } - - textView1.setText(""); - textView1.append("Clients: \n"); - textView1.append("####################\n"); - textView1.append("IP Address : " + enrolleStatus.getIpAddr() - + "\n"); - textView1.append("Device : " + enrolleStatus.getDevice() + "\n"); - textView1.append("HW Address : " + enrolleStatus.getHWAddr() - + "\n"); - textView1.append("Is OnBoarded : " + enrolleStatus.isReachable() - + "\n"); - - Toast.makeText(getApplicationContext(), finalResult, - Toast.LENGTH_LONG).show(); - - /* - * myTimer2 = new Timer(); myTimer2.schedule(new TimerTask() { - * - * @Override public void run() { - * easySetupInstance.StartEasySetup(enrolleStatus.getIpAddr()); - * easySetupCount++; Log.i("EasyConnect", - * "easy Setup Count-"+easySetupCount); Log.i("EasyConnect", - * "IP Address-"+enrolleStatus.getIpAddr()); } - * - * }, 0, 10000); - */ } } diff --git a/service/easy-setup/sampleapp/android/EasySetup/app/src/main/res/layout/capture.xml b/service/easy-setup/sampleapp/android/EasySetup/app/src/main/res/layout/capture.xml deleted file mode 100644 index e348ab0..0000000 --- a/service/easy-setup/sampleapp/android/EasySetup/app/src/main/res/layout/capture.xml +++ /dev/null @@ -1,184 +0,0 @@ - - - - - - - - - - - -