1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 package org.iotivity.service.easysetup.mediator;
22 import android.net.wifi.WifiConfiguration;
23 import android.test.AndroidTestCase;
24 import android.util.Log;
26 import java.io.IOException;
28 public class EasySetupStatusTest extends AndroidTestCase {
31 public void testStartSetupWithWiFiOnboarding() {
33 EasySetupService mService;
34 EnrolleeDevice mDevice;
35 EnrolleeDeviceFactory mFactory;
37 final Object lock = new Object();
40 /* Create Easy Setup service */
41 mService = EasySetupService.getInstance(getContext(), new EasySetupStatus() {
42 EnrolleeState old_state = null;
45 public void onFinished(EnrolleeDevice enrolledevice) {
47 //countDownLatch.countDown();
48 Utility.toNotify(lock);
50 if (enrolledevice.isSetupSuccessful()) {
52 if (enrolledevice.mOnBoardingConfig.getConnType() == WiFiOnBoardingConfig.ConnType.WiFi) {
53 IpOnBoardingConnection conn = (IpOnBoardingConnection) enrolledevice.getConnection();
54 String ip = conn.getIp();
55 if (ip == null || ip.isEmpty()) {
59 String mac = conn.getHardwareAddress();
60 if (mac == null || mac.isEmpty()) {
64 // Device configured successfully
74 public void onProgress(EnrolleeDevice enrolleeDevice) {
75 EnrolleeState state = enrolleeDevice.mState;
78 case DEVICE_INIT_STATE:
79 Log.d("enrollee state", "DEVICE_INIT_STATE");
82 case DEVICE_ON_BOARDING_STATE:
83 if (old_state == null)
85 else assertTrue(false);
86 old_state = EnrolleeState.DEVICE_ON_BOARDING_STATE;
87 Log.d("enrollee state", "DEVICE_ON_BOARDING_STATE");
90 case DEVICE_ON_BOARDED_STATE:
91 if (old_state == EnrolleeState.DEVICE_ON_BOARDING_STATE)
93 else assertTrue(false);
94 old_state = EnrolleeState.DEVICE_ON_BOARDED_STATE;
95 Log.d("enrollee state", "DEVICE_ON_BOARDED_STATE");
98 case DEVICE_PROVISIONING_STATE:
99 if (old_state == EnrolleeState.DEVICE_ON_BOARDED_STATE)
101 else assertTrue(false);
102 old_state = EnrolleeState.DEVICE_PROVISIONING_STATE;
103 Log.d("enrollee state", "DEVICE_PROVISIONING_STATE");
106 case DEVICE_PROVISIONED_STATE:
107 if (old_state == EnrolleeState.DEVICE_PROVISIONING_STATE)
109 else assertTrue(false);
110 Log.d("enrollee state", "DEVICE_PROVISIONING_SUCCESS_STATE");
114 Log.d("enrollee state", "unknown state");
123 /* Create On boarding configuration */
124 WiFiOnBoardingConfig mWiFiOnBoardingConfig = new WiFiOnBoardingConfig();
125 mWiFiOnBoardingConfig.setSSId("EasySetup123");
126 mWiFiOnBoardingConfig.setSharedKey("EasySetup123");
127 mWiFiOnBoardingConfig.setAuthAlgo(WifiConfiguration.AuthAlgorithm.OPEN);
128 mWiFiOnBoardingConfig.setKms(WifiConfiguration.KeyMgmt.WPA_PSK);
130 /* Create provisioning configuration */
131 WiFiProvConfig mWiFiProvConfig = new WiFiProvConfig("hub2.4G", "11112222");
133 /* Create enrolling device factory instance */
134 mFactory = EnrolleeDeviceFactory.newInstance(getContext());
136 /* Create enrolling device */
137 mDevice = mFactory.newEnrolleeDevice(mWiFiOnBoardingConfig, mWiFiProvConfig);
140 mService.startSetup(mDevice);
141 } catch (IOException e) {
146 Utility.toWait(lock);
148 Log.i("EasySetupTest", "Lock is released");
150 IpOnBoardingConnection conn = (IpOnBoardingConnection) mDevice.getConnection();
152 Log.i("EasySetupTest", "Ip" + conn.getIp());
153 Log.i("EasySetupTest", "MAC" + conn.getHardwareAddress());
155 // Device configured successfully
157 } catch (Exception e) {