+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="EasySetup" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
- <component name="FacetManager">
- <facet type="android-gradle" name="Android-Gradle">
- <configuration>
- <option name="GRADLE_PROJECT_PATH" value=":app" />
- </configuration>
- </facet>
- <facet type="android" name="Android">
- <configuration>
- <option name="SELECTED_BUILD_VARIANT" value="debug" />
- <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
- <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
- <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
- <option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
- <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
- <option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
- <option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugAndroidTestSources" />
- <option name="ALLOW_USER_CONFIGURATION" value="false" />
- <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
- <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
- <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
- <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
- </configuration>
- </facet>
- </component>
- <component name="NewModuleRootManager" inherit-compiler-output="false">
- <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
- <output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
- <exclude-output />
- <content url="file://$MODULE_DIR$">
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/EasySetup/easySetupCore-debug/unspecified/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/EasySetup/iotivity-armeabi-base-debug/unspecified/jars" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
- <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
- <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
- </content>
- <orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
- <orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="module" module-name="easySetupCore-debug" exported="" />
- <orderEntry type="module" module-name="iotivity-armeabi-base-debug" exported="" />
- <orderEntry type="library" exported="" name="easySetupCore-debug-unspecified" level="project" />
- <orderEntry type="library" exported="" name="iotivity-armeabi-base-debug-unspecified" level="project" />
- </component>
-</module>
\ No newline at end of file
-/******************************************************************\r
- *\r
- * Copyright 2015 Samsung Electronics All Rights Reserved.\r
- *\r
- *\r
- *\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
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\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
- *\r
- ******************************************************************/\r
package org.iotivity.service.easysetup;\r
\r
-import java.util.Timer;\r
-import java.util.TimerTask;\r
-\r
-import org.iotivity.base.ModeType;\r
-import org.iotivity.base.OcPlatform;\r
-import org.iotivity.base.PlatformConfig;\r
-import org.iotivity.base.QualityOfService;\r
-import org.iotivity.base.ServiceType;\r
-import org.iotivity.service.easysetup.mediator.common.EnrolleeDevice;\r
-import org.iotivity.service.easysetup.mediator.IOnBoardingStatus;\r
-import org.iotivity.service.easysetup.mediator.IProvisioningListener;\r
-import org.iotivity.service.easysetup.mediator.OnBoardEnrollee;\r
+import java.io.IOException;\r
+\r
+import org.iotivity.service.easysetup.core.EasySetupService;\r
+import org.iotivity.service.easysetup.core.EasySetupStatus;\r
+import org.iotivity.service.easysetup.core.EnrolleeDevice;\r
+import org.iotivity.service.easysetup.core.EnrolleeState;\r
+import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory;\r
+import org.iotivity.service.easysetup.impl.EnrolleeDeviceWiFiOnboarding;\r
+import org.iotivity.service.easysetup.impl.WiFiOnBoardingConfig;\r
+import org.iotivity.service.easysetup.impl.WiFiProvConfig;\r
+import org.iotivity.service.easysetup.mediator.EnrolleeInfo;\r
import org.iotivity.service.easysetup.mediator.ProvisionEnrollee;\r
-import org.iotivity.base.OcConnectivityType;\r
-import org.iotivity.service.easysetup.mediator.ip.IPEnrolleeDevice;\r
-import org.iotivity.service.easysetup.mediator.ip.IPProvisioningInfo;\r
-import org.iotivity.service.easysetup.mediator.ip.WiFiSoftAPOnBoardingConfig;\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.util.Log;\r
import android.view.Menu;\r
import android.view.View;\r
import android.view.View.OnClickListener;\r
import android.widget.TextView;\r
import android.widget.Toast;\r
\r
-public class MainActivity extends Activity implements IProvisioningListener,\r
- IOnBoardingStatus {\r
- String devicesConnected;\r
+public class MainActivity extends Activity {\r
TextView textView1;\r
\r
- private Timer myTimer;\r
- private Timer myTimer2;\r
- static int scanCount = 0;\r
- static int easySetupCount = 0;\r
static final int REQUEST_IMAGE_CAPTURE = 1;\r
ImageView imageView;\r
- EnrolleeDevice connectedDevice;\r
-\r
- OnBoardEnrollee onBoardingHandlerInstance;\r
ProvisionEnrollee provisionEnrolleInstance;\r
\r
+ /****Start new API implementation */\r
+ WiFiProvConfig mWiFiProvConfig;\r
+ WiFiOnBoardingConfig mWiFiOnBoardingConfig;\r
+ EasySetupService mEasySetupService ;\r
+ EnrolleeDeviceFactory mDeviceFactory;\r
+ EnrolleeDevice mDevice;\r
+\r
+ /* IOnBoardingStatus deviceScanListener = new IOnBoardingStatus() {\r
+\r
+ @Override\r
+ public void deviceOnBoardingStatus(EnrolleeInfo enrolleStatus) {\r
+ // TODO Auto-generated method stub\r
+ // TODO Auto-generated method stub\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
+\r
+ * easySetupInstance.StartEasySetup(enrolleStatus.getIpAddr()) ;\r
+ * easySetupCount++; Log.i("EasyConnect",\r
+ * "easy Setup Count-"+easySetupCount); Log.i("EasyConnect",\r
+ * "IP Address-"+enrolleStatus.getIpAddr());\r
+\r
+ connectedDevice = enrolleStatus;\r
+ } else {\r
+ finalResult = "Device Removed" + "["\r
+ + enrolleStatus.getIpAddr() + "]";\r
+ }\r
+\r
+ textView1.setText("");\r
+ textView1.append("Clients: \n");\r
+ textView1.append("####################\n");\r
+ textView1.append("IP Address : " + enrolleStatus.getIpAddr()\r
+ + "\n");\r
+ textView1.append("Device : " + enrolleStatus.getDevice() + "\n");\r
+ textView1.append("HW Address : " + enrolleStatus.getHWAddr()\r
+ + "\n");\r
+ textView1.append("Is OnBoarded : " + enrolleStatus.isReachable()\r
+ + "\n");\r
+\r
+ Toast.makeText(getApplicationContext(), finalResult,\r
+ Toast.LENGTH_LONG).show();\r
+\r
+\r
+ * myTimer2 = new Timer(); myTimer2.schedule(new TimerTask() {\r
+ *\r
+ * @Override public void run() {\r
+ * easySetupInstance.StartEasySetup(enrolleStatus.getIpAddr());\r
+ * easySetupCount++; Log.i("EasyConnect",\r
+ * "easy Setup Count-"+easySetupCount); Log.i("EasyConnect",\r
+ * "IP Address-"+enrolleStatus.getIpAddr()); }\r
+ *\r
+ * }, 0, 10000);\r
+\r
+ }\r
+ }\r
+ };\r
+ */\r
+\r
+\r
+ /* End new API implementation*/\r
+\r
@Override\r
protected void onCreate(Bundle savedInstanceState) {\r
super.onCreate(savedInstanceState);\r
textView1 = (TextView) findViewById(R.id.textView1);\r
\r
// OnBoarding Process\r
- onBoardingHandlerInstance = new OnBoardEnrollee(this, OcConnectivityType.CT_IP_USE_V4);\r
- onBoardingHandlerInstance.registerOnBoardingStatusHandler(this);\r
+ // onBoardingHandlerInstance = new OnBoardEnrollee(this);\r
+\r
+ //onBoardingHandlerInstance.registerOnBoardingStatusHandler(this);\r
\r
- // Get intent, action and MIME type\r
+ // Provisioning Process\r
+ provisionEnrolleInstance = new ProvisionEnrollee(this);\r
+ // provisionEnrolleInstance.registerProvisioningHandler(this);\r
+\r
+ /* // Get intent, action and MIME type\r
Intent intent = getIntent();\r
String action = intent.getAction();\r
String type = intent.getType();\r
\r
+ if (Intent.ACTION_SEND.equals(action) && type != null) {\r
+ if ("text/plain".equals(type)) {\r
+ handleSendText(intent); // Handle text being sent\r
+ }\r
+ } else {\r
+ // Handle other intents, such as being started from the home screen\r
+ }\r
+\r
addListenerForStartAP();\r
addListenerForStopAP();\r
addListenerOnProvisioning();\r
- initOICStack();\r
\r
myTimer2 = new Timer();\r
myTimer2.schedule(new TimerTask() {\r
@Override\r
public void run() {\r
- onBoardingHandlerInstance.startDeviceScan(300);\r
+ //onBoardingHandlerInstance.startDeviceScan();\r
+ mWifiSoftAPManager.getClientList(false, deviceScanListener);\r
+ }\r
+\r
+ }, 0, 2000);*/\r
+\r
+\r
+ /* Start new API implementation */\r
+\r
+ mEasySetupService = EasySetupService.getInstance(getApplicationContext(), new EasySetupStatus() {\r
+\r
+ @Override\r
+ public void onFinished(EnrolleeDevice enrolledevice) {\r
+ final String msg = enrolledevice.isSetupSuccessful()? "Device configured successfully" : "Device configuration failed" ;\r
+ runOnUiThread(new Runnable() {\r
+ @Override\r
+ public void run() {\r
+ Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();\r
+ }\r
+ });\r
}\r
\r
- }, 0, 2000);\r
+ @Override\r
+ public void onProgress(EnrolleeState state) {\r
+ runOnUiThread(new Runnable() {\r
+ @Override\r
+ public void run() {\r
+ Toast.makeText(getApplicationContext(), "Device state changed", Toast.LENGTH_SHORT).show();\r
+ }\r
+ });\r
+ }\r
+\r
+ });\r
+\r
+ mDeviceFactory = EnrolleeDeviceFactory.newInstance(getApplicationContext());\r
+\r
+ mDevice = mDeviceFactory.newEnrolleeDevice(getOnBoardingWifiConfig(), getEnrollerWifiConfig());\r
+\r
+ addListenerForStartAP();\r
+ addListenerForStopAP();\r
+\r
+ /* End new API implementation */\r
+\r
+ }\r
+\r
+ public WiFiProvConfig getEnrollerWifiConfig() {\r
+ mWiFiProvConfig = new WiFiProvConfig("EasySetup123", "EasySetup123");\r
+ return mWiFiProvConfig;\r
+ }\r
+\r
+ public WiFiOnBoardingConfig getOnBoardingWifiConfig() {\r
+ //TODO : Check proper configuration\r
+ mWiFiOnBoardingConfig = new WiFiOnBoardingConfig();\r
+ mWiFiOnBoardingConfig.setSSId("EasySetup123");\r
+ mWiFiOnBoardingConfig.setSharedKey("EasySetup123");\r
+ mWiFiOnBoardingConfig.setAuthAlgo(WifiConfiguration.AuthAlgorithm.OPEN);\r
+ mWiFiOnBoardingConfig.setKms(WifiConfiguration.KeyMgmt.WPA_PSK);\r
+ return mWiFiOnBoardingConfig;\r
}\r
\r
+\r
public void onDestroy() {\r
super.onDestroy();\r
- if(provisionEnrolleInstance != null)\r
- {\r
- provisionEnrolleInstance.stopEnrolleeProvisioning(OcConnectivityType.CT_IP_USE_V4);\r
- }\r
- onBoardingHandlerInstance.disableWiFiAP();\r
- finish();\r
+ provisionEnrolleInstance.stopEnrolleeProvisioning(0);\r
+ //onBoardingHandlerInstance.disableWiFiAP();\r
+ // mWifiSoftAPManager.setWifiApEnabled(null, false);\r
+\r
+ //finish();\r
}\r
\r
@Override\r
return true;\r
}\r
\r
- @Override\r
+/* @Override\r
public void onFinishProvisioning(final int statuscode) {\r
// TODO Auto-generated method stub\r
try {\r
public void run() {\r
// TODO Auto-generated method stub\r
Toast toast = null;\r
- IPEnrolleeDevice ipEnrolleeDevice = (IPEnrolleeDevice)connectedDevice;\r
if (statuscode == 0) {\r
toast = Toast.makeText(getApplicationContext(),\r
- ipEnrolleeDevice.getIpAddr()\r
+ connectedDevice.getIpAddr()\r
+ " - is Provisioned",\r
Toast.LENGTH_LONG);\r
Log.i("EasyConnect", "Provisioned statuscode-"\r
+ statuscode);\r
} else {\r
toast = Toast.makeText(getApplicationContext(),\r
- ipEnrolleeDevice.getIpAddr()\r
+ connectedDevice.getIpAddr()\r
+ " - is NOT Provisioned",\r
Toast.LENGTH_LONG);\r
Log.i("EasyConnect", "Not Provisioned statuscode-"\r
} catch (final Exception ex) {\r
Log.i("---", "Exception in thread");\r
}\r
- }\r
+ }*/\r
\r
- private void scan() {\r
- onBoardingHandlerInstance.registerOnBoardingStatusHandler(this);\r
- onBoardingHandlerInstance.startDeviceScan(300);\r
- }\r
+/* void handleSendText(Intent intent) {\r
+ String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);\r
+ if (sharedText != null) {\r
+\r
+ WifiConfiguration netConfig = new WifiConfiguration();\r
+ netConfig.SSID = "DLNA_LISMORE1";\r
+ netConfig.allowedAuthAlgorithms\r
+ .set(WifiConfiguration.AuthAlgorithm.OPEN);\r
+ netConfig.allowedKeyManagement\r
+ .set(WifiConfiguration.KeyMgmt.WPA_PSK);\r
+ netConfig.preSharedKey = "dlna@010203";\r
+\r
+ mWifiSoftAPManager.setWifiApEnabled((WifiConfiguration)getOnBoardingWifiConfig().getConfig(), true);\r
+\r
+ Toast.makeText(getApplicationContext(),\r
+ "QR Code Captured. Starting Wi-Fi Access Point!",\r
+ Toast.LENGTH_LONG).show();\r
+\r
+ myTimer = new Timer();\r
+ myTimer.schedule(new TimerTask() {\r
+ @Override\r
+ public void run() {\r
+ scan();\r
+ scanCount++;\r
+ Log.i("EasyConnect", "Scan Count -" + scanCount);\r
+ }\r
+\r
+ }, 0, 5000);\r
+ }\r
+ }*/\r
+\r
+/* private void scan() {\r
+ //onBoardingHandlerInstance.registerOnBoardingStatusHandler(this);\r
+ mWifiSoftAPManager.getClientList(false, deviceScanListener);\r
+ //onBoardingHandlerInstance.startDeviceScan();\r
+ }*/\r
\r
public void addListenerForStartAP() {\r
Button button = (Button) findViewById(R.id.button1);\r
button.setOnClickListener(new OnClickListener() {\r
@Override\r
public void onClick(View arg0) {\r
- WiFiSoftAPOnBoardingConfig transportConfig = new WiFiSoftAPOnBoardingConfig();\r
-\r
- WifiConfiguration netConfig = new WifiConfiguration();\r
- netConfig.SSID = "EasySetup123";\r
- netConfig.allowedAuthAlgorithms\r
- .set(WifiConfiguration.AuthAlgorithm.OPEN);\r
- netConfig.allowedKeyManagement\r
- .set(WifiConfiguration.KeyMgmt.WPA_PSK);\r
- netConfig.preSharedKey = "EasySetup123";\r
-\r
- transportConfig.setConnectivityType(OcConnectivityType.CT_IP_USE_V4);\r
- transportConfig.setNetConfig(netConfig);\r
- onBoardingHandlerInstance.enableNetwork(transportConfig, true);\r
+ try {\r
+ mEasySetupService.startSetup(mDevice);\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ }\r
+\r
}\r
});\r
}\r
button.setOnClickListener(new OnClickListener() {\r
@Override\r
public void onClick(View arg0) {\r
- onBoardingHandlerInstance.disableWiFiAP();\r
+ mEasySetupService.stopSetup(mDevice);\r
}\r
});\r
}\r
\r
- public void addListenerOnProvisioning() {\r
+/* public void addListenerOnProvisioning() {\r
Button button = (Button) findViewById(R.id.button2);\r
\r
button.setOnClickListener(new OnClickListener() {\r
@Override\r
public void onClick(View arg0) {\r
- IPEnrolleeDevice ipEnrolleeDevice = (IPEnrolleeDevice)connectedDevice;\r
- IPProvisioningInfo ipProvisioningInfo = new IPProvisioningInfo();\r
-\r
- ipProvisioningInfo.setConnectivityType(OcConnectivityType.CT_IP_USE_V4);\r
- ipProvisioningInfo.setIpAddress(ipEnrolleeDevice.getIpAddr());\r
- ipProvisioningInfo.setNetSSID("EasySetup123");\r
- ipProvisioningInfo.setNetPWD("EasySetup123");\r
-\r
provisionEnrolleInstance.provisionEnrollee(\r
- ipProvisioningInfo, OcConnectivityType.CT_IP_USE_V4);\r
+ connectedDevice.getIpAddr(), "NewAccessPoint",\r
+ "NewAccessPoint", 0);\r
easySetupCount++;\r
Log.i("EasyConnect", "easy Setup Count-" + easySetupCount);\r
Log.i("EasyConnect",\r
- "IP Address-" + ipProvisioningInfo.getIpAddress());\r
+ "IP Address-" + connectedDevice.getIpAddr());\r
}\r
});\r
\r
- }\r
+ }*/\r
\r
@Override\r
protected void onActivityResult(int requestCode, int resultCode, Intent data) {\r
}\r
}\r
\r
- /**\r
- * configure OIC platform and call findResource\r
- */\r
- private void initOICStack() {\r
- //create platform config\r
- PlatformConfig cfg = new PlatformConfig(\r
- this,\r
- ServiceType.IN_PROC,\r
- ModeType.CLIENT,\r
- "0.0.0.0", // bind to all available interfaces\r
- 0,\r
- QualityOfService.LOW);\r
- OcPlatform.Configure(cfg);\r
- Log.i("EasyConnect","OcPlatform Configure is invoked");\r
- }\r
-\r
- @Override\r
- public void deviceOnBoardingStatus(EnrolleeDevice enrolleeDevice) {\r
- // TODO Auto-generated method stub\r
- // TODO Auto-generated method stub\r
- if(enrolleeDevice.getConnectivityType() == OcConnectivityType.CT_IP_USE_V4) {\r
- IPEnrolleeDevice ipEnrolleeDevice = (IPEnrolleeDevice)enrolleeDevice;\r
- if (ipEnrolleeDevice.getIpAddr() != null) {\r
- String finalResult = "Easy Connect : ";\r
- if (ipEnrolleeDevice.isReachable()) {\r
- finalResult = "Device OnBoarded" + "["\r
- + ipEnrolleeDevice.getIpAddr() + "]";\r
-\r
- /*\r
- * easySetupInstance.StartEasySetup(enrolleStatus.getIpAddr()) ;\r
- * easySetupCount++; Log.i("EasyConnect",\r
- * "easy Setup Count-"+easySetupCount); Log.i("EasyConnect",\r
- * "IP Address-"+enrolleStatus.getIpAddr());\r
- */\r
- connectedDevice = ipEnrolleeDevice;\r
-\r
- // Only after onboarding is successful, provisioning is performed\r
- provisionEnrolleInstance = new ProvisionEnrollee(this);\r
- provisionEnrolleInstance.registerProvisioningHandler(this);\r
-\r
- } else {\r
- finalResult = "Device Removed" + "["\r
- + ipEnrolleeDevice.getIpAddr() + "]";\r
- }\r
-\r
- textView1.setText("");\r
- textView1.append("Clients: \n");\r
- textView1.append("####################\n");\r
- textView1.append("IP Address : " + ipEnrolleeDevice.getIpAddr()\r
- + "\n");\r
- textView1.append("HW Address : " + ipEnrolleeDevice.getHWAddr()\r
- + "\n");\r
- textView1.append("Is OnBoarded : " + ipEnrolleeDevice.isReachable()\r
- + "\n");\r
-\r
- Toast.makeText(getApplicationContext(), finalResult,\r
- Toast.LENGTH_LONG).show();\r
-\r
- /*\r
- * myTimer2 = new Timer(); myTimer2.schedule(new TimerTask() {\r
- *\r
- * @Override public void run() {\r
- * easySetupInstance.StartEasySetup(enrolleStatus.getIpAddr());\r
- * easySetupCount++; Log.i("EasyConnect",\r
- * "easy Setup Count-"+easySetupCount); Log.i("EasyConnect",\r
- * "IP Address-"+enrolleStatus.getIpAddr()); }\r
- *\r
- * }, 0, 10000);\r
- */\r
- }\r
- }\r
- }\r
\r
}\r
--- /dev/null
+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();
+
+}
--- /dev/null
+package org.iotivity.service.easysetup.core;
+
+import android.content.Context;
+import android.util.Log;
+
+import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+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;
+ }
+
+ // TODO : Implement singleton method
+ public synchronized static EasySetupService getInstance(Context context, EasySetupStatus callback) {
+ if(sInstance == null) {
+ sInstance = new EasySetupService(callback);
+ mContext = context;
+ }
+ return sInstance ;
+ }
+
+ 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);
+ }
+
+ }
+
+ });
+
+ }
+
+ 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);
+ //}
+ }
+
+ }
+
+
+}
--- /dev/null
+package org.iotivity.service.easysetup.core;
+
+public interface EasySetupStatus {
+
+ public void onFinished(EnrolleeDevice enrolledevice);
+ public void onProgress(EnrolleeState state);
+
+}
--- /dev/null
+package org.iotivity.service.easysetup.core;
+
+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;
+
+ protected EnrolleeDevice(OnBoardingConfig onBoardingConfig, ProvisioningConfig provConfig) {
+ mProvConfig = provConfig;
+ mOnBoardingConfig = onBoardingConfig;
+ }
+
+
+ // Application can override this API to provide their own implementation for on boarding.
+ protected abstract void startOnBoardingProcess();
+ protected abstract void stopOnBoardingProcess();
+
+ protected abstract void startProvisioningProcess(ConnectionInterface conn);
+
+ public void setConnection(ConnectionInterface conn) {
+ mConnection = conn;
+ }
+
+ // Not accessible by the Application
+ void startOnBoarding(OnBoardingCallback onBoardingCallback){
+ mOnBoardingCallback = onBoardingCallback;
+ startOnBoardingProcess();
+ }
+
+ // Not accessible by the Application
+ void startProvisioning(ProvisioningCallback provisioningCallback){
+ mProvisioningCallback = provisioningCallback;
+ startProvisioningProcess(mConnection);
+ }
+
+
+ public boolean isSetupSuccessful(){
+ return (mState == EnrolleeState.DEVICE_PROVISIONING_SUCCESS_STATE) ? true : false;
+ }
+
+ public EnrolleeSetupError getError() {
+ return mError;
+ }
+
+ public EnrolleeState getState() {
+ return mState;
+ }
+
+ public boolean onBoarded(){
+ return ( mState == EnrolleeState.DEVICE_PROVISIONING_STATE ) ? true : false;
+ }
+
+}
--- /dev/null
+package org.iotivity.service.easysetup.core;
+
+public enum EnrolleeSetupError {
+ DEVICE_SETUP_SUCCESSFUL,
+ DEVICE_SETUP_FAILED,
+}
--- /dev/null
+package org.iotivity.service.easysetup.core;
+
+
+/**
+ *
+ * The device being enrolled into the network will fall into any of the below mentioned states
+ *
+ */
+
+public enum EnrolleeState {
+
+ // Device will be there in this state by default
+ DEVICE_ON_BOARDING_STATE,
+
+ // Device will move to this state once the on boarding is done
+ DEVICE_PROVISIONING_STATE,
+
+ // Device will move to this state after successful provisioning into the network
+ DEVICE_PROVISIONING_SUCCESS_STATE,
+
+ // Device is not able to provisioned
+ DEVICE_PROVISIONING_FAILED_STATE,
+
+ // The below state is arbitrary one, any time device can come into this state
+ //Device will move to this state if the ownership transfer initiated by the Application
+ DEVICE_OWNERSHIP_TRANSFER_STATE,
+
+ // The below state is arbitrary one, any time device can come into this state
+ // Device will move to this state once the Application factory reset the device
+ DEVICE_FACTORY_RESET_STATE,
+
+
+
+}
--- /dev/null
+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() {
+ // TODO Auto-generated method stub
+ return "Description";
+ }
+
+ @Override
+ public boolean isConnected() {
+ // TODO Auto-generated method stub
+ return mIsConnected;
+ }
+
+ @Override
+ public Object getConnection() {
+ // TODO Auto-generated method stub
+ return this;
+ }
+
+}
--- /dev/null
+package org.iotivity.service.easysetup.core;
+
+public abstract class OnBoardingCallback {
+ public abstract void onFinished(ConnectionInterface connection) ;
+}
--- /dev/null
+package org.iotivity.service.easysetup.core;
+
+
+public interface OnBoardingConfig {
+
+ public static enum ConnType {
+ WiFi,
+ BLE,
+ }
+
+ public Object getConfig();
+ public ConnType getConnType();
+ public ConnectionInterface getConnection();
+ public void setConnection(ConnectionInterface conn);
+
+}
--- /dev/null
+package org.iotivity.service.easysetup.core;
+
+public abstract class ProvisioningCallback {
+ public abstract void onFinished(EnrolleeDevice enrolledevice) ;
+}
--- /dev/null
+package org.iotivity.service.easysetup.core;
+
+
+public interface ProvisioningConfig {
+
+ public static enum ConnType {
+ WiFi,
+ BT
+ }
+
+ Object getConfig();
+ ConnType getConnType();
+
+}
--- /dev/null
+package org.iotivity.service.easysetup.impl;
+
+import org.iotivity.service.easysetup.core.EnrolleeDevice;
+import org.iotivity.service.easysetup.core.OnBoardingConfig;
+import org.iotivity.service.easysetup.core.ProvisioningConfig;
+
+import android.content.Context;
+
+public class EnrolleeDeviceFactory {
+
+ Context mContext;
+
+ public static EnrolleeDeviceFactory newInstance(Context context) {
+ return new EnrolleeDeviceFactory(context);
+ }
+
+ private EnrolleeDeviceFactory (Context context) {
+ mContext = context;
+ }
+
+ public EnrolleeDevice newEnrolleeDevice(OnBoardingConfig onboardingConfig, ProvisioningConfig provConfig){
+
+ EnrolleeDevice enrolleeDevice;
+
+ if (onboardingConfig.getConnType()== OnBoardingConfig.ConnType.WiFi) {
+ enrolleeDevice = new EnrolleeDeviceWiFiOnboarding(mContext, onboardingConfig, provConfig);
+ }else {
+ throw new IllegalArgumentException("OnBoarding configuration is not supported");
+ }
+
+ return enrolleeDevice;
+ }
+
+}
--- /dev/null
+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;
+
+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() + "]";
+
+ /*
+ * easySetupInstance.StartEasySetup(enrolleStatus.getIpAddr()) ;
+ * easySetupCount++; Log.i("EasyConnect",
+ * "easy Setup Count-"+easySetupCount); Log.i("EasyConnect",
+ * "IP Address-"+enrolleStatus.getIpAddr());
+ */
+ connectedDevice = enrolleStatus;
+ IpConnection conn = new IpConnection();
+ conn.setConnectivity(true);
+ conn.setIp(connectedDevice.getIpAddr());
+ Log.d("ESSoftAPOnBoarding", "Entered");
+ mOnBoardingCallback.onFinished(conn);
+ return;
+
+ }
+
+/* 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();*/
+
+
+ }
+
+ 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() {
+ // TODO Auto-generated method stub
+
+ //2. Get call back once enrolling device connect to the Soft AP
+ //3. fetch the IP assigned to enrolling device
+ //4. Call below steps
+
+ 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*/);
+
+ }
+
+ }
+
+
+
+}
--- /dev/null
+package org.iotivity.service.easysetup.impl;
+
+import org.iotivity.service.easysetup.core.ConnectionInterface;
+import org.iotivity.service.easysetup.core.IpConnection;
+import org.iotivity.service.easysetup.core.OnBoardingConfig;
+
+import android.net.wifi.WifiConfiguration;
+
+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() {
+ // TODO Auto-generated method stub
+ 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() {
+ // TODO Auto-generated method stub
+ return mConnType;
+ }
+
+ @Override
+ public ConnectionInterface getConnection() {
+ // TODO Auto-generated method stub
+ return mConnection;
+ }
+
+ @Override
+ public void setConnection(ConnectionInterface conn) {
+ mConnection = (IpConnection)conn;
+ }
+
+
+}
--- /dev/null
+package org.iotivity.service.easysetup.impl;
+
+import org.iotivity.service.easysetup.core.ProvisioningConfig;
+import org.iotivity.service.easysetup.mediator.EnrolleeInfo;
+
+import android.net.wifi.WifiConfiguration;
+
+public class WiFiProvConfig implements ProvisioningConfig{
+
+ private final ConnType mConnType = ProvisioningConfig.ConnType.WiFi;
+
+ private final String mSsId;
+ private final String mPassword;
+
+ public WiFiProvConfig(String ssid, String pass) {
+ mSsId = ssid;
+ mPassword = pass;
+ }
+
+ @Override
+ public Object getConfig() {
+ return this;
+ }
+
+ @Override
+ public ConnType getConnType() {
+ // TODO Auto-generated method stub
+ return mConnType;
+ }
+
+ public String getSsId() {
+ return mSsId;
+ }
+
+ public String getPassword() {
+ return mPassword;
+ }
+
+}
\r
public void ProvisioningStatusCallBack(int statuscode) {\r
// TODO Auto-generated method stub\r
- Log.d(TAG, "onFinishProvisioning(). statuscode - " + statuscode);\r
+ Log.d(TAG,\r
+ "onFinishProvisioning() inside Android Java application. statuscode - "\r
+ + statuscode);\r
if (this.provisioningListener != null) {\r
this.provisioningListener.ProvisioningStatusCallBack(statuscode);\r
} else {\r
\r
import android.content.Context;\r
\r
+//import org.iotivity.ca.CaInterface;\r
+\r
public class EasySetupManager {\r
private native void InitEasySetup();\r
+\r
private native void TerminateEasySetup();\r
+\r
+ // TODO : "OcConnectivityType connectivityType" has to be passed as the\r
+ // second parameter for PerformEasySetup\r
+ // instead of integer\r
private native void ProvisionEnrollee(String ipAddress, String netSSID,\r
String netPWD, int connectivityType);\r
+\r
private native void StopEnrolleeProvisioning(int connectivityType);\r
+\r
+ public static native void initialize(Context context);\r
+\r
private static EasySetupManager easySetupManagerInterfaceObj = null;\r
private Context appContext = null;\r
\r
+ static {\r
+ // Load Easy Setup JNI interface\r
+ System.loadLibrary("gnustl_shared");\r
+ System.loadLibrary("octbstack");\r
+ System.loadLibrary("connectivity_abstraction");\r
+ System.loadLibrary("easysetup-jni");\r
+ }\r
+\r
private EasySetupManager() {\r
\r
}\r
return easySetupManagerInterfaceObj;\r
}\r
\r
+ public void setApplicationContext(Context context) {\r
+ appContext = context;\r
+ }\r
+\r
public void initEasySetup() {\r
+ // CaInterface.initialize(appContext);\r
InitEasySetup();\r
}\r
\r
TerminateEasySetup();\r
}\r
\r
- public void provisionIPEnrollee(String ipAddress, String netSSID,\r
+ public void provisionEnrollee(String ipAddress, String netSSID,\r
String netPWD, int connectivityType) {\r
\r
ProvisionEnrollee(ipAddress, netSSID, netPWD, connectivityType);\r
*
******************************************************************/
-package org.iotivity.service.easysetup.mediator.ip;
+package org.iotivity.service.easysetup.mediator;
-import org.iotivity.service.easysetup.mediator.common.EnrolleeDevice;
+public class EnrolleeInfo {
-/*
-* IPEnrolleeDevice is a subclass of EnrolleeDevice for creating EnrolleeDevice for WiFi transport.
-*/
-public class IPEnrolleeDevice extends EnrolleeDevice {
private String IpAddr;
private String HWAddr;
+ private String Device;
+ private boolean isReachable;
public String getIpAddr() {
return IpAddr;
public void setHWAddr(String hWAddr) {
HWAddr = hWAddr;
}
+
+ public String getDevice() {
+ return Device;
+ }
+
+ public void setDevice(String device) {
+ Device = device;
+ }
+
+ public boolean isReachable() {
+ return isReachable;
+ }
+
+ public void setReachable(boolean isReachable) {
+ this.isReachable = isReachable;
+ }
+
}
\ No newline at end of file
******************************************************************/
package org.iotivity.service.easysetup.mediator;
-import org.iotivity.service.easysetup.mediator.common.EnrolleeDevice;
-
public class EnrolleeOnBoardingInfo {
- private EnrolleeDevice enrolleeDevice;
+ private String IpAddr;
+ private String HWAddr;
+ private String Device;
private boolean isReachable;
private boolean isAdditionNotified;
private boolean isRemovalNotified;
- public EnrolleeOnBoardingInfo(EnrolleeDevice enrolleeDevice,
+ public EnrolleeOnBoardingInfo(String ipAddr, String hWAddr, String device,
boolean isReachable, boolean isRemovalNotified,
boolean isAdditionNotified) {
- this.enrolleeDevice = enrolleeDevice;
+ this.IpAddr = ipAddr;
+ this.HWAddr = hWAddr;
+ this.Device = device;
this.isReachable = isReachable;
this.isRemovalNotified = isRemovalNotified;
this.isAdditionNotified = isAdditionNotified;
}
- public void setEnrolleeDevice(EnrolleeDevice enrolleeDevice) {
- this.enrolleeDevice = enrolleeDevice;
+ public String getIpAddr() {
+ return IpAddr;
+ }
+
+ public void setIpAddr(String ipAddr) {
+ IpAddr = ipAddr;
+ }
+
+ public String getHWAddr() {
+ return HWAddr;
+ }
+
+ public void setHWAddr(String hWAddr) {
+ HWAddr = hWAddr;
+ }
+
+ public String getDevice() {
+ return Device;
}
- public EnrolleeDevice getEnrolleeDevice() {
- return this.enrolleeDevice;
+ public void setDevice(String device) {
+ Device = device;
}
public boolean isReachable() {
******************************************************************/
package org.iotivity.service.easysetup.mediator;
-import org.iotivity.service.easysetup.mediator.common.EnrolleeDevice;
+import java.util.ArrayList;
+
+import org.iotivity.service.easysetup.mediator.EnrolleeInfo;
public interface IOnBoardingStatus {
/**
* Interface called when the scan method finishes. Network operations should
* not execute on UI thread
- *
- * @param enrolleeDevice
- * of {@link EnrolleeDevice}
+ *
+ * @param clients
+ * of {@link EnrolleeInfo}
*/
- public void deviceOnBoardingStatus(EnrolleeDevice enrolleeDevice);
+ public void deviceOnBoardingStatus(EnrolleeInfo clients);
}
package org.iotivity.service.easysetup.mediator;\r
\r
import android.content.Context;\r
-\r
-import org.iotivity.base.OcConnectivityType;\r
-import org.iotivity.service.easysetup.mediator.common.OnBoardingConfig;\r
+import android.net.wifi.WifiConfiguration;\r
import org.iotivity.service.easysetup.mediator.ip.WiFiSoftAPManager;\r
-import org.iotivity.service.easysetup.mediator.ip.WiFiSoftAPOnBoardingConfig;\r
+\r
+import android.widget.Toast;\r
\r
public class OnBoardEnrollee {\r
WiFiSoftAPManager wifiSoftAPManager;\r
IOnBoardingStatus deviceScanListener;\r
- OcConnectivityType selectedConnectivityType;\r
\r
/**\r
- * Constructor for OnBoardEnrollee.\r
+ * Constructor for OnBoardEnrollee. Constructs a new OnBoardEnrollee.\r
*/\r
- public OnBoardEnrollee(Context context, OcConnectivityType connectivityType) {\r
- if(connectivityType == OcConnectivityType.CT_IP_USE_V4) {\r
- wifiSoftAPManager = new WiFiSoftAPManager(context);\r
- }\r
- this.selectedConnectivityType = connectivityType;\r
+ public OnBoardEnrollee(Context context) {\r
+ wifiSoftAPManager = new WiFiSoftAPManager(context);\r
}\r
\r
public void registerOnBoardingStatusHandler(\r
this.deviceScanListener = deviceScanListener;\r
}\r
\r
- public void startDeviceScan(final int reachableTimeout) {\r
- if(selectedConnectivityType == OcConnectivityType.CT_IP_USE_V4) {\r
- wifiSoftAPManager.getClientList(this.deviceScanListener, reachableTimeout);\r
- }\r
+ public void startDeviceScan() {\r
+ wifiSoftAPManager.getClientList(this.deviceScanListener, 300);\r
}\r
\r
- public void enableNetwork(OnBoardingConfig transportConfig, boolean enabled) {\r
- if(selectedConnectivityType == OcConnectivityType.CT_IP_USE_V4) {\r
- wifiSoftAPManager.setWifiApEnabled(\r
- ((WiFiSoftAPOnBoardingConfig)transportConfig).getNetConfig(),\r
- true);\r
- }\r
+ public void enableWiFiAP(WifiConfiguration netConfig, boolean enabled) {\r
+ wifiSoftAPManager.setWifiApEnabled(netConfig, true);\r
}\r
\r
public void disableWiFiAP() {\r
- if(selectedConnectivityType == OcConnectivityType.CT_IP_USE_V4) {\r
- wifiSoftAPManager.setWifiApEnabled(null, false);\r
- }\r
+ wifiSoftAPManager.setWifiApEnabled(null, false);\r
}\r
}\r
import android.content.Context;\r
import android.util.Log;\r
\r
-import org.iotivity.base.OcConnectivityType;\r
-import org.iotivity.service.easysetup.mediator.common.ProvisioningInfo;\r
-import org.iotivity.service.easysetup.mediator.ip.IPProvisioningInfo;\r
-\r
public class ProvisionEnrollee {\r
private static final String TAG = "ProvisionEnrollee";\r
+ private Context appContext = null;\r
private EasySetupManager easySetupManagerNativeInstance = null;\r
private IProvisioningListener provisioningListener;\r
\r
- static {\r
- // Load Easy Setup JNI interface\r
- System.loadLibrary("gnustl_shared");\r
- System.loadLibrary("octbstack");\r
- System.loadLibrary("connectivity_abstraction");\r
- System.loadLibrary("easysetup-jni");\r
- }\r
/**\r
* Constructor for ProvisionEnrollee. Constructs a new ProvisionEnrollee.\r
*/\r
public ProvisionEnrollee(Context context) {\r
+ appContext = context;\r
easySetupManagerNativeInstance = EasySetupManager.getInstance();\r
+ easySetupManagerNativeInstance.initEasySetup();\r
}\r
- \r
+\r
@Override\r
protected void finalize() throws Throwable {\r
super.finalize();\r
easySetupManagerNativeInstance.terminateEasySetup();\r
}\r
\r
- public void provisionEnrollee(ProvisioningInfo provisioningInfo,\r
- OcConnectivityType connectivityType) {\r
- if(connectivityType == OcConnectivityType.CT_IP_USE_V4)\r
- {\r
- easySetupManagerNativeInstance.initEasySetup();\r
- easySetupManagerNativeInstance.provisionIPEnrollee(\r
- ((IPProvisioningInfo)provisioningInfo).getIpAddress(),\r
- ((IPProvisioningInfo)provisioningInfo).getNetSSID(),\r
- ((IPProvisioningInfo)provisioningInfo).getNetPWD(),\r
- OcConnectivityType.CT_IP_USE_V4.getValue());\r
- }\r
+ public void provisionEnrollee(String ipAddress, String netSSID,\r
+ String netPWD, int connectivityType) {\r
+ easySetupManagerNativeInstance.provisionEnrollee(ipAddress, netSSID,\r
+ netPWD, connectivityType);\r
}\r
\r
- public void stopEnrolleeProvisioning(OcConnectivityType connectivityType) {\r
+ public void stopEnrolleeProvisioning(int connectivityType) {\r
easySetupManagerNativeInstance\r
- .stopEnrolleeProvisioning(OcConnectivityType.CT_IP_USE_V4.getValue());\r
+ .stopEnrolleeProvisioning(connectivityType);\r
}\r
\r
public void ProvisioningStatusCallBack(int statuscode) {\r
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-package org.iotivity.service.easysetup.mediator.common;
-
-import org.iotivity.base.OcConnectivityType;
-
-/*
-* EnrolleeDevice is a super class for handling Enrollees on different transports.
-* All the transport specific Enrollee Devices inherit from this base class and provide the
-* transport specific implementation in the transport specific subclasses.
-*/
-public class EnrolleeDevice {
- private OcConnectivityType connectivityType;
- private boolean isReachable;
-
- public boolean isReachable() {
- return isReachable;
- }
-
- public void setReachable(boolean isReachable) {
- this.isReachable = isReachable;
- }
-
- public OcConnectivityType getConnectivityType() {
- return connectivityType;
- }
-
- public void setConnectivityType(OcConnectivityType connectivityType) {
- this.connectivityType = connectivityType;
- }
-}
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-package org.iotivity.service.easysetup.mediator.common;
-
-import org.iotivity.base.OcConnectivityType;
-import org.iotivity.service.easysetup.mediator.ip.IPEnrolleeDevice;
-
-/*
-* EnrolleeDeviceFactory is a factory class which instantiates a respective transport specific
-* EnrolleeDevice class.
-* This class will be used during the OnBoarding Phase to create a transport specific Enrollee Device
-* after the device is OnBoarded successfully
-* The transport specific instantiation of Enrollee Device will be used in all subsequent operations
-* after OnBoarding
-*/
-public class EnrolleeDeviceFactory {
- public static EnrolleeDevice getDevice(OcConnectivityType connectivityType)
- {
- if(connectivityType == OcConnectivityType.CT_IP_USE_V4)
- {
- return new IPEnrolleeDevice();
- }
- return null;
- }
-}
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-package org.iotivity.service.easysetup.mediator.common;
-
-import org.iotivity.base.OcConnectivityType;
-
-/*
-* OnBoardingConfig is a super class for handling different types of transport configurations.
-* OnBoardingConfig will be used during the OnBoarding phase to provide the transport details for
-* OnBoarding Enrollees
-* Transport specific subclasses will be inheriting from OnBoardingConfig to represent transport
-* specific implementations of OnBoardingConfig.
-* The base class provides the connecitivity type information which is needed for dynamic casting of
-* subclasses at runtime.
-*/
-public class OnBoardingConfig {
- private OcConnectivityType connectivityType;
-
- public OcConnectivityType getConnectivityType() {
- return connectivityType;
- }
-
- public void setConnectivityType(OcConnectivityType connectivityType) {
- this.connectivityType = connectivityType;
- }
-}
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-package org.iotivity.service.easysetup.mediator.common;
-
-import org.iotivity.base.OcConnectivityType;
-
-/*
-* ProvisioningInfo is a super class for handling different types of transport provisioning
-* informations.
-* Different Connectivities have different types of provisioning information. This base class holds
-* the common information that is related to all the subclasses.
-* Transport specific provisioning information will be available with the subclasses of
-* ProvisioningInfo
-*/
-public class ProvisioningInfo {
- private OcConnectivityType connectivityType;
-
- public OcConnectivityType getConnectivityType() {
- return connectivityType;
- }
-
- public void setConnectivityType(OcConnectivityType connectivityType) {
- this.connectivityType = connectivityType;
- }
-}
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-package org.iotivity.service.easysetup.mediator.ip;
-
-import org.iotivity.service.easysetup.mediator.common.ProvisioningInfo;
-
-/*
-* IPProvisioningInfo is a sub class for handling IP transport provisioning information.
-*/
-public class IPProvisioningInfo extends ProvisioningInfo {
- private String ipAddress;
- private String netSSID;
- private String netPWD;
-
- public String getIpAddress() {
- return ipAddress;
- }
-
- public void setIpAddress(String ipAddress) {
- this.ipAddress = ipAddress;
- }
-
- public String getNetSSID() {
- return netSSID;
- }
-
- public void setNetSSID(String netSSID) {
- this.netSSID = netSSID;
- }
-
- public String getNetPWD() {
- return netPWD;
- }
-
- public void setNetPWD(String netPWD) {
- this.netPWD = netPWD;
- }
-}
import android.os.Handler;
import android.util.Log;
-import org.iotivity.base.OcConnectivityType;
-import org.iotivity.service.easysetup.mediator.common.EnrolleeDeviceFactory;
+import org.iotivity.service.easysetup.mediator.EnrolleeInfo;
import org.iotivity.service.easysetup.mediator.EnrolleeOnBoardingInfo;
import org.iotivity.service.easysetup.mediator.IOnBoardingStatus;
private synchronized boolean CheckForDeviceEntryAndNotify(String ipAddr,
String macAddr, boolean isReachable)
{
- final IPEnrolleeDevice result = new IPEnrolleeDevice();
+ final EnrolleeInfo result = new EnrolleeInfo();
boolean deviceAddedToList = false;
- result.setConnectivityType(OcConnectivityType.CT_IP_USE_V4);
-
if (appNotification.size() > 0) {
for (EnrolleeOnBoardingInfo ipDeviceOnBoardingNotification : appNotification) {
- IPEnrolleeDevice ipEnrolleeDevice = (IPEnrolleeDevice)ipDeviceOnBoardingNotification
- .getEnrolleeDevice();
+ EnrolleeOnBoardingInfo ipEnrolleeDevice = (EnrolleeOnBoardingInfo)ipDeviceOnBoardingNotification;
boolean macAddressComparison = ipEnrolleeDevice.getHWAddr().equalsIgnoreCase(
macAddr) ? true : false;
.remove(ipDeviceOnBoardingNotification);
if (isReachable) {
appNotification
- .add(new EnrolleeOnBoardingInfo(ipEnrolleeDevice, isReachable,
+ .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable,
false, true));
} else {
appNotification
- .add(new EnrolleeOnBoardingInfo(ipEnrolleeDevice, isReachable,
+ .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable,
true, false));
}
}
}
if (!deviceAddedToList) {
- IPEnrolleeDevice ipEnrolleeDevice = (IPEnrolleeDevice) EnrolleeDeviceFactory.getDevice(
- OcConnectivityType.CT_IP_USE_V4);
- ipEnrolleeDevice.setIpAddr(ipAddr);
- ipEnrolleeDevice.setHWAddr(macAddr);
if (isReachable) {
appNotification
- .add(new EnrolleeOnBoardingInfo(ipEnrolleeDevice, isReachable, false,
+ .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, false,
true));
} else {
appNotification
- .add(new EnrolleeOnBoardingInfo(ipEnrolleeDevice, isReachable, true,
+ .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, true,
false));
}
return true;
}
} else {
- IPEnrolleeDevice ipEnrolleeDevice = (IPEnrolleeDevice)EnrolleeDeviceFactory.getDevice(
- OcConnectivityType.CT_IP_USE_V4);
- ipEnrolleeDevice.setIpAddr(ipAddr);
- ipEnrolleeDevice.setHWAddr(macAddr);
if (isReachable) {
appNotification
- .add(new EnrolleeOnBoardingInfo(ipEnrolleeDevice, isReachable, false,
+ .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, false,
true));
} else {
appNotification
- .add(new EnrolleeOnBoardingInfo(ipEnrolleeDevice, isReachable, true,
+ .add(new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, true,
false));
}
// it is maintained in the file "/proc/net/arp"
bufferedReader = new BufferedReader(new FileReader("/proc/net/arp"));
String line;
+
while ((line = bufferedReader.readLine()) != null) {
//ARP entries are splitted using Regex for getting the IP and MAC Address
// info
mythread.start();
}
- void NotifyApplication(final IPEnrolleeDevice result) {
+ void NotifyApplication(final EnrolleeInfo result) {
// Get a handler that can be used to post to the main thread
Handler mainHandler = new Handler(context.getMainLooper());
Runnable myRunnable = new Runnable() {
+++ /dev/null
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-package org.iotivity.service.easysetup.mediator.ip;
-
-import android.net.wifi.WifiConfiguration;
-import org.iotivity.service.easysetup.mediator.common.OnBoardingConfig;
-
-/*
-* WiFiSoftAPOnBoardingConfig is a sub class for handling WiFi SoftAP transport configurations.
-* WiFiSoftAPOnBoardingConfig will be used during the OnBoarding phase to provide the
-* WiFi Soft AP transport details for OnBoarding Enrollee's
-* The base class OnBoardingConfig provides the connecitivity type information which is needed
-* for dynamic casting of subclasses at runtime.
-*/
-public class WiFiSoftAPOnBoardingConfig extends OnBoardingConfig {
- private WifiConfiguration netConfig;
-
- public WifiConfiguration getNetConfig() {
- return netConfig;
- }
-
- public void setNetConfig(WifiConfiguration netConfig) {
- this.netConfig = netConfig;
- }
-}