}\r
\r
@Override\r
- public void onProgress(EnrolleeState state) {\r
+ public void onProgress(EnrolleeDevice enrolleeDevice) {\r
Log.i("MainActivity", "onProgress() is received ");\r
mHandler.sendEmptyMessage(STATE_CHANGED);\r
}\r
}\r
\r
@Override\r
- public void onProgress(EnrolleeState state) {\r
+ public void onProgress(EnrolleeDevice enrolleeDevice) {\r
\r
}\r
});\r
}\r
\r
@Override\r
- public void onProgress(EnrolleeState state) {\r
+ public void onProgress(EnrolleeDevice enrolleeDevice) {\r
\r
}\r
});\r
}\r
\r
@Override\r
- public void onProgress(EnrolleeState state) {\r
- // TODO\r
+ public void onProgress(EnrolleeDevice enrolleeDevice) {\r
+ // Handled in EasySetupStatusTest\r
}\r
});\r
\r
\r
Log.i("EasySetupTest", "Lock is released");\r
\r
- if(! mDevice.isSetupSuccessful()) {\r
+ if (!mDevice.isSetupSuccessful()) {\r
assertTrue(false);\r
return;\r
}\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.core;
+
+import android.net.wifi.WifiConfiguration;
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+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 java.io.IOException;
+
+public class EasySetupStatusTest extends AndroidTestCase {
+
+
+ public void testStartSetupWithWiFiOnboarding() {
+
+ EasySetupService mService;
+ EnrolleeDevice mDevice;
+ EnrolleeDeviceFactory mFactory;
+
+ final Object lock = new Object();
+
+
+ /* Create Easy Setup service */
+ mService = EasySetupService.getInstance(getContext(), new EasySetupStatus() {
+ EnrolleeState old_state = null;
+
+ @Override
+ public void onFinished(EnrolleeDevice enrolledevice) {
+
+ //countDownLatch.countDown();
+ Utility.toNotify(lock);
+
+ if (enrolledevice.isSetupSuccessful()) {
+
+ if (enrolledevice.mOnBoardingConfig.getConnType() == WiFiOnBoardingConfig.ConnType.WiFi) {
+ IpOnBoardingConnection conn = (IpOnBoardingConnection) enrolledevice.getConnection();
+ String ip = conn.getIp();
+ if (ip == null || ip.isEmpty()) {
+ assertTrue(false);
+ return;
+ }
+ String mac = conn.getHardwareAddress();
+ if (mac == null || mac.isEmpty()) {
+ assertTrue(false);
+ return;
+ }
+ // Device configured successfully
+ assertTrue(true);
+ }
+
+ } else {
+ assertTrue(false);
+ }
+ }
+
+ @Override
+ public void onProgress(EnrolleeDevice enrolleeDevice) {
+ EnrolleeState state = enrolleeDevice.mState;
+ // TODO
+ switch (state) {
+ case DEVICE_INIT_STATE:
+ Log.d("enrollee state", "DEVICE_INIT_STATE");
+ assertTrue(false);
+ break;
+ case DEVICE_ON_BOARDING_STATE:
+ if (old_state == null)
+ assertTrue(true);
+ else assertTrue(false);
+ old_state = EnrolleeState.DEVICE_ON_BOARDING_STATE;
+ Log.d("enrollee state", "DEVICE_ON_BOARDING_STATE");
+ break;
+
+ case DEVICE_ON_BOARDED_STATE:
+ if (old_state == EnrolleeState.DEVICE_ON_BOARDING_STATE)
+ assertTrue(true);
+ else assertTrue(false);
+ old_state = EnrolleeState.DEVICE_ON_BOARDED_STATE;
+ Log.d("enrollee state", "DEVICE_ON_BOARDED_STATE");
+ break;
+
+ case DEVICE_PROVISIONING_STATE:
+ if (old_state == EnrolleeState.DEVICE_ON_BOARDED_STATE)
+ assertTrue(true);
+ else assertTrue(false);
+ old_state = EnrolleeState.DEVICE_PROVISIONING_STATE;
+ Log.d("enrollee state", "DEVICE_PROVISIONING_STATE");
+ break;
+
+ case DEVICE_PROVISIONED_STATE:
+ if (old_state == EnrolleeState.DEVICE_PROVISIONING_STATE)
+ assertTrue(true);
+ else assertTrue(false);
+ Log.d("enrollee state", "DEVICE_PROVISIONING_SUCCESS_STATE");
+ break;
+
+ default:
+ Log.d("enrollee state", "unknown state");
+ assertTrue(false);
+ break;
+ }
+
+ }
+ });
+
+
+ /* Create On boarding configuration */
+ WiFiOnBoardingConfig mWiFiOnBoardingConfig = new WiFiOnBoardingConfig();
+ mWiFiOnBoardingConfig.setSSId("EasySetup123");
+ mWiFiOnBoardingConfig.setSharedKey("EasySetup123");
+ mWiFiOnBoardingConfig.setAuthAlgo(WifiConfiguration.AuthAlgorithm.OPEN);
+ mWiFiOnBoardingConfig.setKms(WifiConfiguration.KeyMgmt.WPA_PSK);
+
+ /* Create provisioning configuration */
+ WiFiProvConfig mWiFiProvConfig = new WiFiProvConfig("hub2.4G", "11112222");
+
+ /* Create enrolling device factory instance */
+ mFactory = EnrolleeDeviceFactory.newInstance(getContext());
+
+ /* Create enrolling device */
+ mDevice = mFactory.newEnrolleeDevice(mWiFiOnBoardingConfig, mWiFiProvConfig);
+
+ try {
+ mService.startSetup(mDevice);
+ } catch (IOException e) {
+ }
+
+ try {
+
+ Utility.toWait(lock);
+
+ Log.i("EasySetupTest", "Lock is released");
+
+ IpOnBoardingConnection conn = (IpOnBoardingConnection) mDevice.getConnection();
+
+ Log.i("EasySetupTest", "Ip" + conn.getIp());
+ Log.i("EasySetupTest", "MAC" + conn.getHardwareAddress());
+
+ // Device configured successfully
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+}
\ No newline at end of file
import android.content.Context;\r
import android.util.Log;\r
\r
-import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory;\r
import org.iotivity.service.easysetup.mediator.EasySetupManager;\r
import org.iotivity.service.easysetup.mediator.ProvisionEnrollee;\r
\r
*/\r
public class EasySetupService {\r
\r
- public static final String TAG = EasySetupService.class.getName();\r
+ private static final String TAG = EasySetupService.class.getName();\r
\r
private static EasySetupService sInstance;\r
\r
\r
private static Context mContext;\r
\r
- public EnrolleeDeviceFactory mDeviceFactory;\r
\r
ProvisionEnrollee mProvisionEnrolleeInstance;\r
\r
mProvisioningCallback = new ProvisioningCallbackImpl(mCallback);\r
mEnrolleeDeviceList = new ArrayList<EnrolleeDevice>();\r
mContext = null;\r
- mDeviceFactory = null;\r
+\r
}\r
\r
/**\r
enrolledevice.startProvisioning(mProvisioningCallback);\r
return;\r
}\r
+ enrolledevice.mState = EnrolleeState.DEVICE_ON_BOARDING_STATE;\r
\r
+ mCallback.onProgress(enrolledevice);\r
enrolledevice.startOnBoarding(new OnBoardingCallback() {\r
\r
@Override\r
if (connection.isConnected()) {\r
Log.i(TAG, "On boarding is successful ");\r
// Start provisioning here\r
+ enrolledevice.mState = EnrolleeState.DEVICE_ON_BOARDED_STATE;\r
+ mCallback.onProgress(enrolledevice);\r
enrolledevice.setConnection(connection);\r
enrolledevice.startProvisioning(mProvisioningCallback);\r
} else {\r
- enrolledevice.mState = EnrolleeState.DEVICE_PROVISIONING_FAILED_STATE;\r
+ enrolledevice.mState = EnrolleeState.DEVICE_INIT_STATE;\r
mProvisioningCallback.onFinished(enrolledevice);\r
}\r
\r
* @param enrolleedevice Device to be enrolled in network\r
*/\r
public synchronized void stopSetup(EnrolleeDevice enrolleedevice) {\r
- if (enrolleedevice.mState == EnrolleeState.DEVICE_ON_BOARDING_STATE) {\r
- if (mEnrolleeDeviceList.contains(enrolleedevice)) {\r
+ if (mEnrolleeDeviceList.contains(enrolleedevice)) {\r
+ enrolleedevice.mState = EnrolleeState.DEVICE_INIT_STATE;\r
+ mCallback.onProgress(enrolleedevice);\r
+ if (enrolleedevice.mState == EnrolleeState.DEVICE_ON_BOARDING_STATE) {\r
Log.i(TAG, "stopOnBoardingProcess for enrolleedevice");\r
enrolleedevice.stopOnBoardingProcess();\r
mEnrolleeDeviceList.remove(enrolleedevice);\r
- }\r
- } else if (enrolleedevice.mState == EnrolleeState.DEVICE_PROVISIONING_STATE) {\r
- if (mEnrolleeDeviceList.contains(enrolleedevice)) {\r
+ } else if (enrolleedevice.mState == EnrolleeState.DEVICE_PROVISIONING_STATE) {\r
Log.i(TAG, "stopOnBoardingProcess for enrolleedevice");\r
enrolleedevice.stopOnBoardingProcess();\r
-\r
Log.i(TAG, "stopEnrolleeProvisioning for enrolleedevice");\r
//Native Api call to stop on-going enrolling process for the enrolling device\r
EasySetupManager.getInstance().stopEnrolleeProvisioning(enrolleedevice\r
.mOnBoardingConfig.getConnType().getValue());\r
mEnrolleeDeviceList.remove(enrolleedevice);\r
+\r
}\r
}\r
}\r
\r
- public synchronized void getEnrolleeDevice(OnBoardingConfig connType) {\r
- mDeviceFactory = EnrolleeDeviceFactory.newInstance(mContext);\r
- }\r
-\r
class ProvisioningCallbackImpl extends ProvisioningCallback {\r
\r
private final EasySetupStatus mCallback;\r
}\r
}\r
\r
- }\r
+ @Override\r
+ public void onProgress(EnrolleeDevice enrolledevice) {\r
+ mCallback.onProgress(enrolledevice);\r
+ }\r
\r
\r
-}\r
+ }\r
+}
\ No newline at end of file
* setup process This method is called on worker thread, UI operations to be
* executed on main / Ui Thread.
*
- * @param state Gives state of the device changed during easy setup process
+ * @param enrolleeDevice Gives state of the device changed during easy setup process
*/
- public void onProgress(EnrolleeState state);
+ public void onProgress(EnrolleeDevice enrolleeDevice);
}
*\r
* @param conn Connectivity between Enrollee device & Mediator device.\r
*/\r
- public void setConnection(OnBoardingConnection conn) {\r
+ protected void setConnection(OnBoardingConnection conn) {\r
mConnection = conn;\r
}\r
\r
+ /**\r
+ * This method returns the OnBoardingConnection object depending on the connection type\r
+ *\r
+ * @return onBoardingConnection object\r
+ */\r
public OnBoardingConnection getConnection() {\r
return mConnection;\r
}\r
*/\r
\r
public boolean isSetupSuccessful() {\r
- return (mState == EnrolleeState.DEVICE_PROVISIONING_SUCCESS_STATE) ? true : false;\r
+ return (mState == EnrolleeState.DEVICE_PROVISIONED_STATE) ? true : false;\r
}\r
\r
/**\r
* sets error occured during easy setup process\r
*/\r
- public void setError(EnrolleeSetupError error) {\r
+ protected void setError(EnrolleeSetupError error) {\r
mError = error;\r
}\r
\r
* @return True if on-boarded successfully or False\r
*/\r
\r
- public boolean onBoarded() {\r
+ protected boolean onBoarded() {\r
return (mState == EnrolleeState.DEVICE_PROVISIONING_STATE) ? true : false;\r
}\r
\r
/**
* Device will move to this state after successful on-boarding of the device
*/
+ DEVICE_ON_BOARDED_STATE,
+
+ /**
+ * Device will move to this state once the on boarding begins
+ */
DEVICE_ON_BOARDING_STATE,
/**
/**
* Easy setup process is successful.
*/
- DEVICE_PROVISIONING_SUCCESS_STATE,
+ DEVICE_PROVISIONED_STATE,
/**
- * Device is not able to provisioned.
- * Easy setup process failed to enrolled the device in the network
+ * This 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_PROVISIONING_FAILED_STATE,
+ DEVICE_OWNERSHIP_TRANSFERRING_STATE,
/**
* This 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 will move to this state if the ownership transfer is completed
*/
- DEVICE_OWNERSHIP_TRANSFER_STATE,
+ DEVICE_OWNERSHIP_TRANSFERRED_STATE,
+
/**
* This state is arbitrary one, any time device can come into this state
*/\r
package org.iotivity.service.easysetup.core;\r
\r
+/**\r
+ * This interface contains the connection details of the enrollee device\r
+ */\r
public interface OnBoardingConnection {\r
\r
-\r
- // Get the implementation of the Connection\r
+ /**\r
+ * This method returns the implementation of the Connection\r
+ *\r
+ * @return implementation\r
+ */\r
public Object getConnection();\r
\r
- // Any general description on the connectivity.\r
+ /**\r
+ * This method returns description on the connectivity.\r
+ *\r
+ * @return description\r
+ */\r
public String getDesc();\r
\r
+ /**\r
+ * This method is used to know if the device is connected or not\r
+ *\r
+ * @return True if connected or False\r
+ */\r
public boolean isConnected();\r
\r
}\r
public abstract class ProvisioningCallback {
public abstract void onFinished(EnrolleeDevice enrolledevice);
+ public abstract void onProgress(EnrolleeDevice enrolledevice);
}
\r
@Override\r
protected void startProvisioningProcess(OnBoardingConnection conn) {\r
- mState = EnrolleeState.DEVICE_PROVISIONING_STATE;\r
-\r
try {\r
Log.i(TAG, "waiting for 15 seconds to start provisioning");\r
Thread.sleep(15000);//Sleep for allowing thin device to start the services\r
e.printStackTrace();\r
}\r
\r
-\r
+ mState = EnrolleeState.DEVICE_PROVISIONING_STATE;\r
+ mProvisioningCallback.onProgress(this);\r
+ final EnrolleeDevice device = this;\r
if (mProvConfig.getConnType() == ProvisioningConfig.ConnType.WiFi) {\r
\r
provisionEnrolleInstance = new ProvisionEnrollee(mContext);\r
public void onFinishProvisioning(int statuscode) {\r
\r
Log.i(TAG, "Provisioning is finished with status code " + statuscode);\r
- mState = (statuscode == 0) ? EnrolleeState.DEVICE_PROVISIONING_SUCCESS_STATE\r
- : EnrolleeState.DEVICE_PROVISIONING_FAILED_STATE;\r
+ mState = (statuscode == 0) ? EnrolleeState.DEVICE_PROVISIONED_STATE\r
+ : EnrolleeState.DEVICE_INIT_STATE;\r
stopOnBoardingProcess();\r
+ mProvisioningCallback.onProgress(device);\r
mProvisioningCallback.onFinished(EnrolleeDeviceWiFiOnboarding.this);\r
}\r
});\r
return mConnType;
}
+ /**
+ * This method returns the SSID of the Target WIFI network
+ * @return SSID of Target Network
+ */
public String getSsId() {
return mSsId;
}
+ /**
+ * This method returns the password of the Target WIFI network
+ * @return password of Target Network
+ */
public String getPassword() {
return mPassword;
}