From b1f0394074a3e2a7c609ca374ec515b51933caa4 Mon Sep 17 00:00:00 2001 From: lankamadan Date: Tue, 8 Sep 2015 22:16:47 +0900 Subject: [PATCH] Refactoring of EasySetup Android implementation Updated Android Java code to support SoftAP and BLE OnBoarding methods Change-Id: I6e66f979c1b7c61dd87c0448f43e6b0d33e433f3 Signed-off-by: lankamadan Reviewed-on: https://gerrit.iotivity.org/gerrit/2406 Tested-by: jenkins-iotivity --- .../sampleapp/android/EasySetup/app/app.iml | 96 ------ .../iotivity/service/easysetup/MainActivity.java | 372 ++++++++++++--------- .../easysetup/core/ConnectionInterface.java | 14 + .../service/easysetup/core/EasySetupService.java | 105 ++++++ .../service/easysetup/core/EasySetupStatus.java | 8 + .../service/easysetup/core/EnrolleeDevice.java | 60 ++++ .../service/easysetup/core/EnrolleeSetupError.java | 6 + .../service/easysetup/core/EnrolleeState.java | 34 ++ .../service/easysetup/core/IpConnection.java | 38 +++ .../service/easysetup/core/OnBoardingCallback.java | 5 + .../service/easysetup/core/OnBoardingConfig.java | 16 + .../easysetup/core/ProvisioningCallback.java | 5 + .../service/easysetup/core/ProvisioningConfig.java | 14 + .../easysetup/impl/EnrolleeDeviceFactory.java | 34 ++ .../impl/EnrolleeDeviceWiFiOnboarding.java | 156 +++++++++ .../easysetup/impl/WiFiOnBoardingConfig.java | 55 +++ .../service/easysetup/impl/WiFiProvConfig.java | 39 +++ .../mediator/EasySetupCallbackHandler.java | 4 +- .../easysetup/mediator/EasySetupManager.java | 26 +- .../IPEnrolleeDevice.java => EnrolleeInfo.java} | 27 +- .../easysetup/mediator/EnrolleeOnBoardingInfo.java | 36 +- .../easysetup/mediator/IOnBoardingStatus.java | 12 +- .../easysetup/mediator/OnBoardEnrollee.java | 35 +- .../easysetup/mediator/ProvisionEnrollee.java | 35 +- .../easysetup/mediator/common/EnrolleeDevice.java | 48 --- .../mediator/common/EnrolleeDeviceFactory.java | 42 --- .../mediator/common/OnBoardingConfig.java | 43 --- .../mediator/common/ProvisioningInfo.java | 42 --- .../easysetup/mediator/ip/IPProvisioningInfo.java | 55 --- .../easysetup/mediator/ip/WiFiSoftAPManager.java | 33 +- .../mediator/ip/WiFiSoftAPOnBoardingConfig.java | 42 --- 31 files changed, 911 insertions(+), 626 deletions(-) delete mode 100644 service/easy-setup/sampleapp/android/EasySetup/app/app.iml mode change 100644 => 100755 service/easy-setup/sampleapp/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/MainActivity.java create mode 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ConnectionInterface.java create mode 100644 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupService.java create mode 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupStatus.java create mode 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeDevice.java create mode 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeSetupError.java create mode 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeState.java create mode 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/IpConnection.java create mode 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingCallback.java create mode 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingConfig.java create mode 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ProvisioningCallback.java create mode 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ProvisioningConfig.java create mode 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceFactory.java create mode 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceWiFiOnboarding.java create mode 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/WiFiOnBoardingConfig.java create mode 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/WiFiProvConfig.java rename service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/{ip/IPEnrolleeDevice.java => EnrolleeInfo.java} (71%) mode change 100644 => 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IOnBoardingStatus.java mode change 100644 => 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ProvisionEnrollee.java delete mode 100644 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/common/EnrolleeDevice.java delete mode 100644 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/common/EnrolleeDeviceFactory.java delete mode 100644 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/common/OnBoardingConfig.java delete mode 100644 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/common/ProvisioningInfo.java delete mode 100644 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/IPProvisioningInfo.java mode change 100644 => 100755 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPManager.java delete mode 100644 service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPOnBoardingConfig.java diff --git a/service/easy-setup/sampleapp/android/EasySetup/app/app.iml b/service/easy-setup/sampleapp/android/EasySetup/app/app.iml deleted file mode 100644 index b14367f..0000000 --- a/service/easy-setup/sampleapp/android/EasySetup/app/app.iml +++ /dev/null @@ -1,96 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file 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 old mode 100644 new mode 100755 index a173356..75c67c5 --- 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 @@ -1,48 +1,23 @@ -/****************************************************************** - * - * 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; -import java.util.Timer; -import java.util.TimerTask; - -import org.iotivity.base.ModeType; -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.common.EnrolleeDevice; -import org.iotivity.service.easysetup.mediator.IOnBoardingStatus; -import org.iotivity.service.easysetup.mediator.IProvisioningListener; -import org.iotivity.service.easysetup.mediator.OnBoardEnrollee; +import java.io.IOException; + +import org.iotivity.service.easysetup.core.EasySetupService; +import org.iotivity.service.easysetup.core.EasySetupStatus; +import org.iotivity.service.easysetup.core.EnrolleeDevice; +import org.iotivity.service.easysetup.core.EnrolleeState; +import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory; +import org.iotivity.service.easysetup.impl.EnrolleeDeviceWiFiOnboarding; +import org.iotivity.service.easysetup.impl.WiFiOnBoardingConfig; +import org.iotivity.service.easysetup.impl.WiFiProvConfig; +import org.iotivity.service.easysetup.mediator.EnrolleeInfo; 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; import android.graphics.Bitmap; import android.net.wifi.WifiConfiguration; import android.os.Bundle; -import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; @@ -51,22 +26,78 @@ import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; -public class MainActivity extends Activity implements IProvisioningListener, - IOnBoardingStatus { - String devicesConnected; +public class MainActivity extends Activity { TextView textView1; - private Timer myTimer; - private Timer myTimer2; - static int scanCount = 0; - static int easySetupCount = 0; static final int REQUEST_IMAGE_CAPTURE = 1; ImageView imageView; - EnrolleeDevice connectedDevice; - - OnBoardEnrollee onBoardingHandlerInstance; ProvisionEnrollee provisionEnrolleInstance; + /****Start new API implementation */ + WiFiProvConfig mWiFiProvConfig; + WiFiOnBoardingConfig mWiFiOnBoardingConfig; + EasySetupService mEasySetupService ; + EnrolleeDeviceFactory mDeviceFactory; + EnrolleeDevice mDevice; + + /* IOnBoardingStatus deviceScanListener = new IOnBoardingStatus() { + + @Override + public void deviceOnBoardingStatus(EnrolleeInfo enrolleStatus) { + // TODO Auto-generated method stub + // TODO Auto-generated method stub + 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; + } 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); + + } + } + }; + */ + + + /* End new API implementation*/ + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -75,37 +106,103 @@ public class MainActivity extends Activity implements IProvisioningListener, textView1 = (TextView) findViewById(R.id.textView1); // OnBoarding Process - onBoardingHandlerInstance = new OnBoardEnrollee(this, OcConnectivityType.CT_IP_USE_V4); - onBoardingHandlerInstance.registerOnBoardingStatusHandler(this); + // onBoardingHandlerInstance = new OnBoardEnrollee(this); + + //onBoardingHandlerInstance.registerOnBoardingStatusHandler(this); - // Get intent, action and MIME type + // Provisioning Process + provisionEnrolleInstance = new ProvisionEnrollee(this); + // provisionEnrolleInstance.registerProvisioningHandler(this); + + /* // Get intent, action and MIME type Intent intent = getIntent(); 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(); - initOICStack(); myTimer2 = new Timer(); myTimer2.schedule(new TimerTask() { @Override public void run() { - onBoardingHandlerInstance.startDeviceScan(300); + //onBoardingHandlerInstance.startDeviceScan(); + mWifiSoftAPManager.getClientList(false, deviceScanListener); + } + + }, 0, 2000);*/ + + + /* Start new API implementation */ + + mEasySetupService = EasySetupService.getInstance(getApplicationContext(), new EasySetupStatus() { + + @Override + public void onFinished(EnrolleeDevice enrolledevice) { + final String msg = enrolledevice.isSetupSuccessful()? "Device configured successfully" : "Device configuration failed" ; + runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show(); + } + }); } - }, 0, 2000); + @Override + public void onProgress(EnrolleeState state) { + runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(getApplicationContext(), "Device state changed", Toast.LENGTH_SHORT).show(); + } + }); + } + + }); + + mDeviceFactory = EnrolleeDeviceFactory.newInstance(getApplicationContext()); + + mDevice = mDeviceFactory.newEnrolleeDevice(getOnBoardingWifiConfig(), getEnrollerWifiConfig()); + + addListenerForStartAP(); + addListenerForStopAP(); + + /* End new API implementation */ + + } + + public WiFiProvConfig getEnrollerWifiConfig() { + mWiFiProvConfig = new WiFiProvConfig("EasySetup123", "EasySetup123"); + return mWiFiProvConfig; + } + + public WiFiOnBoardingConfig getOnBoardingWifiConfig() { + //TODO : Check proper configuration + mWiFiOnBoardingConfig = new WiFiOnBoardingConfig(); + mWiFiOnBoardingConfig.setSSId("EasySetup123"); + mWiFiOnBoardingConfig.setSharedKey("EasySetup123"); + mWiFiOnBoardingConfig.setAuthAlgo(WifiConfiguration.AuthAlgorithm.OPEN); + mWiFiOnBoardingConfig.setKms(WifiConfiguration.KeyMgmt.WPA_PSK); + return mWiFiOnBoardingConfig; } + public void onDestroy() { super.onDestroy(); - if(provisionEnrolleInstance != null) - { - provisionEnrolleInstance.stopEnrolleeProvisioning(OcConnectivityType.CT_IP_USE_V4); - } - onBoardingHandlerInstance.disableWiFiAP(); - finish(); + provisionEnrolleInstance.stopEnrolleeProvisioning(0); + //onBoardingHandlerInstance.disableWiFiAP(); + // mWifiSoftAPManager.setWifiApEnabled(null, false); + + //finish(); } @Override @@ -119,7 +216,7 @@ public class MainActivity extends Activity implements IProvisioningListener, return true; } - @Override +/* @Override public void onFinishProvisioning(final int statuscode) { // TODO Auto-generated method stub try { @@ -129,17 +226,16 @@ 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(), - ipEnrolleeDevice.getIpAddr() + connectedDevice.getIpAddr() + " - is Provisioned", Toast.LENGTH_LONG); Log.i("EasyConnect", "Provisioned statuscode-" + statuscode); } else { toast = Toast.makeText(getApplicationContext(), - ipEnrolleeDevice.getIpAddr() + connectedDevice.getIpAddr() + " - is NOT Provisioned", Toast.LENGTH_LONG); Log.i("EasyConnect", "Not Provisioned statuscode-" @@ -152,12 +248,44 @@ public class MainActivity extends Activity implements IProvisioningListener, } catch (final Exception ex) { Log.i("---", "Exception in thread"); } - } + }*/ - private void scan() { - onBoardingHandlerInstance.registerOnBoardingStatusHandler(this); - onBoardingHandlerInstance.startDeviceScan(300); - } +/* void handleSendText(Intent intent) { + String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT); + if (sharedText != null) { + + WifiConfiguration netConfig = new WifiConfiguration(); + netConfig.SSID = "DLNA_LISMORE1"; + netConfig.allowedAuthAlgorithms + .set(WifiConfiguration.AuthAlgorithm.OPEN); + netConfig.allowedKeyManagement + .set(WifiConfiguration.KeyMgmt.WPA_PSK); + netConfig.preSharedKey = "dlna@010203"; + + mWifiSoftAPManager.setWifiApEnabled((WifiConfiguration)getOnBoardingWifiConfig().getConfig(), 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); + mWifiSoftAPManager.getClientList(false, deviceScanListener); + //onBoardingHandlerInstance.startDeviceScan(); + }*/ public void addListenerForStartAP() { Button button = (Button) findViewById(R.id.button1); @@ -165,19 +293,12 @@ 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.allowedKeyManagement - .set(WifiConfiguration.KeyMgmt.WPA_PSK); - netConfig.preSharedKey = "EasySetup123"; - - transportConfig.setConnectivityType(OcConnectivityType.CT_IP_USE_V4); - transportConfig.setNetConfig(netConfig); - onBoardingHandlerInstance.enableNetwork(transportConfig, true); + try { + mEasySetupService.startSetup(mDevice); + } catch (IOException e) { + e.printStackTrace(); + } + } }); } @@ -188,35 +309,28 @@ public class MainActivity extends Activity implements IProvisioningListener, button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { - onBoardingHandlerInstance.disableWiFiAP(); + mEasySetupService.stopSetup(mDevice); } }); } - public void addListenerOnProvisioning() { +/* public void addListenerOnProvisioning() { Button button = (Button) findViewById(R.id.button2); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { - IPEnrolleeDevice ipEnrolleeDevice = (IPEnrolleeDevice)connectedDevice; - IPProvisioningInfo ipProvisioningInfo = new IPProvisioningInfo(); - - ipProvisioningInfo.setConnectivityType(OcConnectivityType.CT_IP_USE_V4); - ipProvisioningInfo.setIpAddress(ipEnrolleeDevice.getIpAddr()); - ipProvisioningInfo.setNetSSID("EasySetup123"); - ipProvisioningInfo.setNetPWD("EasySetup123"); - provisionEnrolleInstance.provisionEnrollee( - ipProvisioningInfo, OcConnectivityType.CT_IP_USE_V4); + connectedDevice.getIpAddr(), "NewAccessPoint", + "NewAccessPoint", 0); easySetupCount++; Log.i("EasyConnect", "easy Setup Count-" + easySetupCount); Log.i("EasyConnect", - "IP Address-" + ipProvisioningInfo.getIpAddress()); + "IP Address-" + connectedDevice.getIpAddr()); } }); - } + }*/ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { @@ -227,77 +341,5 @@ public class MainActivity extends Activity implements IProvisioningListener, } } - /** - * configure OIC platform and call findResource - */ - private void initOICStack() { - //create platform config - PlatformConfig cfg = new PlatformConfig( - this, - ServiceType.IN_PROC, - ModeType.CLIENT, - "0.0.0.0", // bind to all available interfaces - 0, - QualityOfService.LOW); - OcPlatform.Configure(cfg); - Log.i("EasyConnect","OcPlatform Configure is invoked"); - } - - @Override - public void deviceOnBoardingStatus(EnrolleeDevice enrolleeDevice) { - // TODO Auto-generated method stub - // TODO Auto-generated method stub - if(enrolleeDevice.getConnectivityType() == OcConnectivityType.CT_IP_USE_V4) { - 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() + "]"; - } - - 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(); - - /* - * 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/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ConnectionInterface.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ConnectionInterface.java new file mode 100755 index 0000000..1354538 --- /dev/null +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ConnectionInterface.java @@ -0,0 +1,14 @@ +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(); + +} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupService.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupService.java new file mode 100644 index 0000000..a07b54f --- /dev/null +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupService.java @@ -0,0 +1,105 @@ +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 ArrayListmEnrolleeDeviceList; + + private final ProvisioningCallback mProvisioningCallback; + + private static Context mContext; + + public EnrolleeDeviceFactory mDeviceFactory; + + + private EasySetupService(EasySetupStatus callback) { + mCallback = callback; + mProvisioningCallback = new ProvisioningCallbackImpl(mCallback); + mEnrolleeDeviceList = new ArrayList (); + 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); + //} + } + + } + + +} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupStatus.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupStatus.java new file mode 100755 index 0000000..f77db29 --- /dev/null +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupStatus.java @@ -0,0 +1,8 @@ +package org.iotivity.service.easysetup.core; + +public interface EasySetupStatus { + + public void onFinished(EnrolleeDevice enrolledevice); + public void onProgress(EnrolleeState state); + +} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeDevice.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeDevice.java new file mode 100755 index 0000000..9962b59 --- /dev/null +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeDevice.java @@ -0,0 +1,60 @@ +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; + } + +} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeSetupError.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeSetupError.java new file mode 100755 index 0000000..93b4b08 --- /dev/null +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeSetupError.java @@ -0,0 +1,6 @@ +package org.iotivity.service.easysetup.core; + +public enum EnrolleeSetupError { + DEVICE_SETUP_SUCCESSFUL, + DEVICE_SETUP_FAILED, +} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeState.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeState.java new file mode 100755 index 0000000..b20f5f2 --- /dev/null +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeState.java @@ -0,0 +1,34 @@ +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, + + + +} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/IpConnection.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/IpConnection.java new file mode 100755 index 0000000..480bbac --- /dev/null +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/IpConnection.java @@ -0,0 +1,38 @@ +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; + } + +} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingCallback.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingCallback.java new file mode 100755 index 0000000..cf9fc76 --- /dev/null +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingCallback.java @@ -0,0 +1,5 @@ +package org.iotivity.service.easysetup.core; + +public abstract class OnBoardingCallback { + public abstract void onFinished(ConnectionInterface connection) ; +} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingConfig.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingConfig.java new file mode 100755 index 0000000..e6279ee --- /dev/null +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingConfig.java @@ -0,0 +1,16 @@ +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); + +} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ProvisioningCallback.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ProvisioningCallback.java new file mode 100755 index 0000000..2a8847f --- /dev/null +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ProvisioningCallback.java @@ -0,0 +1,5 @@ +package org.iotivity.service.easysetup.core; + +public abstract class ProvisioningCallback { + public abstract void onFinished(EnrolleeDevice enrolledevice) ; +} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ProvisioningConfig.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ProvisioningConfig.java new file mode 100755 index 0000000..8cb52d1 --- /dev/null +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ProvisioningConfig.java @@ -0,0 +1,14 @@ +package org.iotivity.service.easysetup.core; + + +public interface ProvisioningConfig { + + public static enum ConnType { + WiFi, + BT + } + + Object getConfig(); + ConnType getConnType(); + +} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceFactory.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceFactory.java new file mode 100755 index 0000000..8f6b78e --- /dev/null +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceFactory.java @@ -0,0 +1,34 @@ +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; + } + +} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceWiFiOnboarding.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceWiFiOnboarding.java new file mode 100755 index 0000000..cf22da2 --- /dev/null +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceWiFiOnboarding.java @@ -0,0 +1,156 @@ +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*/); + + } + + } + + + +} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/WiFiOnBoardingConfig.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/WiFiOnBoardingConfig.java new file mode 100755 index 0000000..ed450b6 --- /dev/null +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/WiFiOnBoardingConfig.java @@ -0,0 +1,55 @@ +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; + } + + +} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/WiFiProvConfig.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/WiFiProvConfig.java new file mode 100755 index 0000000..723dcbc --- /dev/null +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/WiFiProvConfig.java @@ -0,0 +1,39 @@ +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; + } + +} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupCallbackHandler.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupCallbackHandler.java index 2137f60..1b61069 100644 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupCallbackHandler.java +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupCallbackHandler.java @@ -36,7 +36,9 @@ public class EasySetupCallbackHandler { public void ProvisioningStatusCallBack(int statuscode) { // TODO Auto-generated method stub - Log.d(TAG, "onFinishProvisioning(). statuscode - " + statuscode); + Log.d(TAG, + "onFinishProvisioning() inside Android Java application. statuscode - " + + statuscode); if (this.provisioningListener != null) { this.provisioningListener.ProvisioningStatusCallBack(statuscode); } else { diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupManager.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupManager.java index b65f785..0319f79 100644 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupManager.java +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupManager.java @@ -21,15 +21,34 @@ package org.iotivity.service.easysetup.mediator; import android.content.Context; +//import org.iotivity.ca.CaInterface; + public class EasySetupManager { private native void InitEasySetup(); + private native void TerminateEasySetup(); + + // TODO : "OcConnectivityType connectivityType" has to be passed as the + // second parameter for PerformEasySetup + // instead of integer private native void ProvisionEnrollee(String ipAddress, String netSSID, String netPWD, int connectivityType); + private native void StopEnrolleeProvisioning(int connectivityType); + + public static native void initialize(Context context); + private static EasySetupManager easySetupManagerInterfaceObj = null; private Context appContext = null; + static { + // Load Easy Setup JNI interface + System.loadLibrary("gnustl_shared"); + System.loadLibrary("octbstack"); + System.loadLibrary("connectivity_abstraction"); + System.loadLibrary("easysetup-jni"); + } + private EasySetupManager() { } @@ -47,7 +66,12 @@ public class EasySetupManager { return easySetupManagerInterfaceObj; } + public void setApplicationContext(Context context) { + appContext = context; + } + public void initEasySetup() { + // CaInterface.initialize(appContext); InitEasySetup(); } @@ -55,7 +79,7 @@ public class EasySetupManager { TerminateEasySetup(); } - public void provisionIPEnrollee(String ipAddress, String netSSID, + public void provisionEnrollee(String ipAddress, String netSSID, String netPWD, int connectivityType) { ProvisionEnrollee(ipAddress, netSSID, netPWD, connectivityType); diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/IPEnrolleeDevice.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeInfo.java similarity index 71% rename from service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/IPEnrolleeDevice.java rename to service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeInfo.java index 4ecb10d..a00758e 100644 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/IPEnrolleeDevice.java +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeInfo.java @@ -18,16 +18,14 @@ * ******************************************************************/ -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; @@ -44,4 +42,21 @@ public class IPEnrolleeDevice extends EnrolleeDevice { 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 diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeOnBoardingInfo.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeOnBoardingInfo.java index fa7e8b4..161b7fb 100644 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeOnBoardingInfo.java +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeOnBoardingInfo.java @@ -19,30 +19,48 @@ ******************************************************************/ 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() { diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IOnBoardingStatus.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IOnBoardingStatus.java old mode 100644 new mode 100755 index a7bc24d..403721d --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IOnBoardingStatus.java +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IOnBoardingStatus.java @@ -19,18 +19,20 @@ ******************************************************************/ 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); } diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardEnrollee.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardEnrollee.java index 882e284..0add977 100644 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardEnrollee.java +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardEnrollee.java @@ -20,25 +20,20 @@ package org.iotivity.service.easysetup.mediator; import android.content.Context; - -import org.iotivity.base.OcConnectivityType; -import org.iotivity.service.easysetup.mediator.common.OnBoardingConfig; +import android.net.wifi.WifiConfiguration; import org.iotivity.service.easysetup.mediator.ip.WiFiSoftAPManager; -import org.iotivity.service.easysetup.mediator.ip.WiFiSoftAPOnBoardingConfig; + +import android.widget.Toast; public class OnBoardEnrollee { WiFiSoftAPManager wifiSoftAPManager; IOnBoardingStatus deviceScanListener; - OcConnectivityType selectedConnectivityType; /** - * Constructor for OnBoardEnrollee. + * Constructor for OnBoardEnrollee. Constructs a new OnBoardEnrollee. */ - public OnBoardEnrollee(Context context, OcConnectivityType connectivityType) { - if(connectivityType == OcConnectivityType.CT_IP_USE_V4) { - wifiSoftAPManager = new WiFiSoftAPManager(context); - } - this.selectedConnectivityType = connectivityType; + public OnBoardEnrollee(Context context) { + wifiSoftAPManager = new WiFiSoftAPManager(context); } public void registerOnBoardingStatusHandler( @@ -46,23 +41,15 @@ public class OnBoardEnrollee { this.deviceScanListener = deviceScanListener; } - public void startDeviceScan(final int reachableTimeout) { - if(selectedConnectivityType == OcConnectivityType.CT_IP_USE_V4) { - wifiSoftAPManager.getClientList(this.deviceScanListener, reachableTimeout); - } + public void startDeviceScan() { + wifiSoftAPManager.getClientList(this.deviceScanListener, 300); } - public void enableNetwork(OnBoardingConfig transportConfig, boolean enabled) { - if(selectedConnectivityType == OcConnectivityType.CT_IP_USE_V4) { - wifiSoftAPManager.setWifiApEnabled( - ((WiFiSoftAPOnBoardingConfig)transportConfig).getNetConfig(), - true); - } + public void enableWiFiAP(WifiConfiguration netConfig, boolean enabled) { + wifiSoftAPManager.setWifiApEnabled(netConfig, true); } public void disableWiFiAP() { - if(selectedConnectivityType == OcConnectivityType.CT_IP_USE_V4) { - wifiSoftAPManager.setWifiApEnabled(null, false); - } + wifiSoftAPManager.setWifiApEnabled(null, false); } } diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ProvisionEnrollee.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ProvisionEnrollee.java old mode 100644 new mode 100755 index 26d4215..ce68f53 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ProvisionEnrollee.java +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ProvisionEnrollee.java @@ -3,51 +3,36 @@ package org.iotivity.service.easysetup.mediator; import android.content.Context; import android.util.Log; -import org.iotivity.base.OcConnectivityType; -import org.iotivity.service.easysetup.mediator.common.ProvisioningInfo; -import org.iotivity.service.easysetup.mediator.ip.IPProvisioningInfo; - public class ProvisionEnrollee { private static final String TAG = "ProvisionEnrollee"; + private Context appContext = null; private EasySetupManager easySetupManagerNativeInstance = null; private IProvisioningListener provisioningListener; - static { - // Load Easy Setup JNI interface - System.loadLibrary("gnustl_shared"); - System.loadLibrary("octbstack"); - System.loadLibrary("connectivity_abstraction"); - System.loadLibrary("easysetup-jni"); - } /** * Constructor for ProvisionEnrollee. Constructs a new ProvisionEnrollee. */ public ProvisionEnrollee(Context context) { + appContext = context; easySetupManagerNativeInstance = EasySetupManager.getInstance(); + easySetupManagerNativeInstance.initEasySetup(); } - + @Override protected void finalize() throws Throwable { super.finalize(); easySetupManagerNativeInstance.terminateEasySetup(); } - public void provisionEnrollee(ProvisioningInfo provisioningInfo, - OcConnectivityType connectivityType) { - if(connectivityType == OcConnectivityType.CT_IP_USE_V4) - { - easySetupManagerNativeInstance.initEasySetup(); - easySetupManagerNativeInstance.provisionIPEnrollee( - ((IPProvisioningInfo)provisioningInfo).getIpAddress(), - ((IPProvisioningInfo)provisioningInfo).getNetSSID(), - ((IPProvisioningInfo)provisioningInfo).getNetPWD(), - OcConnectivityType.CT_IP_USE_V4.getValue()); - } + public void provisionEnrollee(String ipAddress, String netSSID, + String netPWD, int connectivityType) { + easySetupManagerNativeInstance.provisionEnrollee(ipAddress, netSSID, + netPWD, connectivityType); } - public void stopEnrolleeProvisioning(OcConnectivityType connectivityType) { + public void stopEnrolleeProvisioning(int connectivityType) { easySetupManagerNativeInstance - .stopEnrolleeProvisioning(OcConnectivityType.CT_IP_USE_V4.getValue()); + .stopEnrolleeProvisioning(connectivityType); } public void ProvisioningStatusCallBack(int statuscode) { diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/common/EnrolleeDevice.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/common/EnrolleeDevice.java deleted file mode 100644 index d76c37f..0000000 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/common/EnrolleeDevice.java +++ /dev/null @@ -1,48 +0,0 @@ -/****************************************************************** - * - * 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; - } -} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/common/EnrolleeDeviceFactory.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/common/EnrolleeDeviceFactory.java deleted file mode 100644 index 808906f..0000000 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/common/EnrolleeDeviceFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************** - * - * 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; - } -} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/common/OnBoardingConfig.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/common/OnBoardingConfig.java deleted file mode 100644 index 7e65c42..0000000 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/common/OnBoardingConfig.java +++ /dev/null @@ -1,43 +0,0 @@ -/****************************************************************** - * - * 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; - } -} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/common/ProvisioningInfo.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/common/ProvisioningInfo.java deleted file mode 100644 index b22d47f..0000000 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/common/ProvisioningInfo.java +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************** - * - * 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; - } -} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/IPProvisioningInfo.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/IPProvisioningInfo.java deleted file mode 100644 index 140c179..0000000 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/IPProvisioningInfo.java +++ /dev/null @@ -1,55 +0,0 @@ -/****************************************************************** - * - * 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; - } -} diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPManager.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPManager.java old mode 100644 new mode 100755 index 74d7238..beeb705 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPManager.java +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPManager.java @@ -32,8 +32,7 @@ import android.net.wifi.WifiManager; 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; @@ -91,15 +90,12 @@ public class WiFiSoftAPManager { 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; @@ -123,11 +119,11 @@ public class WiFiSoftAPManager { .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)); } @@ -137,17 +133,13 @@ public class WiFiSoftAPManager { } } 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)); } @@ -159,17 +151,13 @@ public class WiFiSoftAPManager { 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)); } @@ -284,6 +272,7 @@ public class WiFiSoftAPManager { // 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 @@ -334,7 +323,7 @@ public class WiFiSoftAPManager { 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() { diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPOnBoardingConfig.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPOnBoardingConfig.java deleted file mode 100644 index bae89a0..0000000 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ip/WiFiSoftAPOnBoardingConfig.java +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************** - * - * 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; - } -} -- 2.7.4