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.service.easysetup.mediator.enums.WIFI_AUTHTYPE;
26 import org.iotivity.service.easysetup.mediator.enums.WIFI_ENCTYPE;
28 import org.iotivity.base.OcException;
29 import org.iotivity.base.OcRepresentation;
32 * This class contains device properties to be delivered to Enrollee
34 public class DeviceProp {
35 private static final String TAG = DeviceProp.class.getName();
36 protected OcRepresentation mRep = null;
42 mRep = new OcRepresentation();
45 public void setWiFiProp(String ssid, String pwd, WIFI_AUTHTYPE authtype, WIFI_ENCTYPE enctype)
57 mRep.setValue(ESConstants.OC_RSRVD_ES_SSID, ssid);
58 mRep.setValue(ESConstants.OC_RSRVD_ES_CRED, pwd);
59 mRep.setValue(ESConstants.OC_RSRVD_ES_AUTHTYPE, authtype.getValue());
60 mRep.setValue(ESConstants.OC_RSRVD_ES_ENCTYPE, enctype.getValue());
61 } catch (OcException e) {
62 Log.e(TAG, "setWiFiProp is failed.");
66 public void setDevConfProp(String language, String country, String location)
81 mRep.setValue(ESConstants.OC_RSRVD_ES_LANGUAGE, language);
82 mRep.setValue(ESConstants.OC_RSRVD_ES_COUNTRY, country);
83 mRep.setValue(ESConstants.OC_RSRVD_ES_LOCATION, location);
84 } catch (OcException e) {
85 Log.e(TAG, "setDevConfProp is failed.");
92 * @return String WiFi AP's SSID
94 public String getSsid()
103 if(mRep.hasAttribute(ESConstants.OC_RSRVD_ES_SSID))
104 return mRep.getValue(ESConstants.OC_RSRVD_ES_SSID);
106 catch (OcException e)
108 Log.e(TAG, "getSsid is failed.");
114 * Get WiFi AP's password
116 * @return String WiFi AP's password
118 public String getPassword()
127 if(mRep.hasAttribute(ESConstants.OC_RSRVD_ES_CRED))
128 return mRep.getValue(ESConstants.OC_RSRVD_ES_CRED);
130 catch (OcException e)
132 Log.e(TAG, "getPassword is failed.");
138 * Get WiFi AP's authenticate type
139 * NONE_AUTH(0), WEP(1), WPA_PSK(2), WPA2_PSK(3)
141 * @return WIFI_AUTHTYPE WiFi AP's authenticate type
143 public WIFI_AUTHTYPE getAuthType()
147 return WIFI_AUTHTYPE.NONE_AUTH;
152 if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_AUTHTYPE))
153 return WIFI_AUTHTYPE.fromInt((int)mRep.getValue(ESConstants.OC_RSRVD_ES_AUTHTYPE));
155 catch (OcException e)
157 Log.e(TAG, "getAuthType is failed.");
159 return WIFI_AUTHTYPE.NONE_AUTH;
163 * Get WiFi AP's encryption type
164 * NONE_ENC(0), WEP_64(1), WEP_128(2), TKIP(3), AES(4), TKIP_AES(5)
166 * @return WIFI_ENCTYPE WiFi AP's encryption type
168 public WIFI_ENCTYPE getEncType()
172 return WIFI_ENCTYPE.NONE_ENC;
177 if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_ENCTYPE))
178 return WIFI_ENCTYPE.fromInt((int)mRep.getValue(ESConstants.OC_RSRVD_ES_ENCTYPE));
180 catch (OcException e)
182 Log.e(TAG, "getEncType is failed.");
184 return WIFI_ENCTYPE.NONE_ENC;
188 * Get IETF language tag using ISO 639X
190 * @return String IETF language tag using ISO 639X
192 public String getLanguage()
201 if(mRep.hasAttribute(ESConstants.OC_RSRVD_ES_LANGUAGE))
202 return mRep.getValue(ESConstants.OC_RSRVD_ES_LANGUAGE);
204 catch (OcException e)
206 Log.e(TAG, "getLanguage is failed.");
212 * Get ISO Country Code (ISO 3166-1 Alpha-2)
214 * @return String ISO Country Code (ISO 3166-1 Alpha-2)
216 public String getCountry()
225 if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_COUNTRY))
226 return mRep.getValue(ESConstants.OC_RSRVD_ES_COUNTRY);
228 catch (OcException e)
230 Log.e(TAG, "getCountry is failed.");
238 * @return String location info of GPS
240 public String getLocation()
249 if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_LOCATION))
250 return mRep.getValue(ESConstants.OC_RSRVD_ES_LOCATION);
252 catch (OcException e)
254 Log.e(TAG, "getLocation is failed.");
259 public OcRepresentation toOCRepresentation()