2 * ***************************************************************
4 * Copyright 2016 Samsung Electronics All Rights Reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * ****************************************************************
21 package org.iotivity.service.easysetup.mediator;
23 import android.util.Log;
25 import org.iotivity.base.OcException;
26 import org.iotivity.base.OcRepresentation;
27 import org.iotivity.service.easysetup.mediator.ESConstants;
28 import org.iotivity.service.easysetup.mediator.enums.WIFI_FREQ;
29 import org.iotivity.service.easysetup.mediator.enums.WIFI_MODE;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.List;
36 * This class stores Enrollee's configuration including WiFi and Device configuration
37 * including supported WiFi frequency and device name
39 public class EnrolleeConf
41 private static final String TAG = EnrolleeConf.class.getName();
42 protected OcRepresentation mEasySetupRep = null;
46 * @param rep received properties in a form of OcRepresentation
49 public EnrolleeConf(OcRepresentation rep)
54 public EnrolleeConf(EnrolleeConf enrolleeConf)
56 mEasySetupRep = enrolleeConf.getEasySetupRep();
60 * Get Device Name property in DevConf resource
64 public String getDeviceName()
66 if(mEasySetupRep == null)
71 List<OcRepresentation> children = mEasySetupRep.getChildren();
73 for (OcRepresentation child : children) {
74 if(child.getUri().indexOf(ESConstants.OC_RSRVD_ES_URI_DEVCONF) != -1)
79 if(child.hasAttribute(ESConstants.OC_RSRVD_REPRESENTATION))
81 rep = (OcRepresentation)child.getValue(ESConstants.OC_RSRVD_REPRESENTATION);
88 if(rep.hasAttribute(ESConstants.OC_RSRVD_ES_DEVNAME)) {
89 return (String) rep.getValue(ESConstants.OC_RSRVD_ES_DEVNAME);
91 } catch (OcException e) {
92 Log.e(TAG, "getWiFiModes is failed.");
100 * Get Model Number property in DevConf resource
102 * @return modelNumber
104 public String getModelNumber()
106 if(mEasySetupRep == null)
111 List<OcRepresentation> children = mEasySetupRep.getChildren();
113 for (OcRepresentation child : children) {
114 if(child.getUri().indexOf(ESConstants.OC_RSRVD_ES_URI_DEVCONF) != -1)
118 OcRepresentation rep;
119 if(child.hasAttribute(ESConstants.OC_RSRVD_REPRESENTATION))
121 rep = (OcRepresentation)child.getValue(ESConstants.OC_RSRVD_REPRESENTATION);
128 if(rep.hasAttribute(ESConstants.OC_RSRVD_ES_MODELNUMBER)) {
129 return (String) rep.getValue(ESConstants.OC_RSRVD_ES_MODELNUMBER);
131 } catch (OcException e) {
132 Log.e(TAG, "getModelNumber is failed.");
140 * Get Supported WiFi Modes property in WiFi resource
142 * @return a list of WiFi modes
144 public ArrayList<WIFI_MODE> getWiFiModes()
146 if(mEasySetupRep == null)
151 List<OcRepresentation> children = mEasySetupRep.getChildren();
152 ArrayList<WIFI_MODE> modes = new ArrayList<WIFI_MODE>();
153 for (OcRepresentation child : children) {
154 if(child.getUri().indexOf(ESConstants.OC_RSRVD_ES_URI_WIFICONF) != -1)
157 OcRepresentation rep;
158 if(child.hasAttribute(ESConstants.OC_RSRVD_REPRESENTATION))
160 rep = (OcRepresentation)child.getValue(ESConstants.OC_RSRVD_REPRESENTATION);
167 if (rep.hasAttribute(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIMODE)) {
168 int modes_int[] = rep.getValue(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIMODE);
169 for (int i = 0 ; i < modes_int.length ; ++i) {
170 modes.add(WIFI_MODE.fromInt(modes_int[i]));
173 } catch (OcException e) {
174 Log.e(TAG, "getWiFiModes is failed.");
182 * Get Supported WiFi frequency property in WiFi resource
184 * @return WiFi frequency
186 public WIFI_FREQ getWiFiFreq()
188 if(mEasySetupRep == null)
190 return WIFI_FREQ.WIFI_FREQ_NONE;
193 List<OcRepresentation> children = mEasySetupRep.getChildren();
195 for (OcRepresentation child : children) {
196 if(child.getUri().indexOf(ESConstants.OC_RSRVD_ES_URI_WIFICONF) != -1)
199 OcRepresentation rep;
200 if(child.hasAttribute(ESConstants.OC_RSRVD_REPRESENTATION))
202 rep = (OcRepresentation)child.getValue(ESConstants.OC_RSRVD_REPRESENTATION);
209 if(rep.hasAttribute(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
210 return WIFI_FREQ.fromInt(
211 (int)rep.getValue(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
212 } catch (OcException e) {
213 Log.e(TAG, "getWiFiFreq is failed.");
221 * To check if Enrollee can access to cloud. To decide its preference, we check if a cloudserver
222 * resource is registered on Enrollee.
226 public boolean isCloudAccessible()
228 if(mEasySetupRep == null)
233 List<OcRepresentation> children = mEasySetupRep.getChildren();
235 for (OcRepresentation child : children) {
236 if(child.getUri().indexOf(ESConstants.OC_RSRVD_ES_URI_COAPCLOUDCONF) != -1)
244 public OcRepresentation getEasySetupRep()
246 return mEasySetupRep;