package org.iotivity.service.easysetup.mediator;
+import android.util.Log;
+
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcRepresentation;
+
/**
* This class contains cloud server properties to be delivered to Enrollee
*/
public class CloudProp {
-
- private final String mAuthCode;
- private final String mAuthProvider;
- private final String mCiServer;
+ private static final String TAG = CloudProp.class.getName();
+ protected OcRepresentation mRep;
/**
* Constructor
- *
- * @param authCode Authcode issued by OAuth 2.0 protocol compatible account server
- * @param authProvider Auth provider which issued the auth code
- * @param ciServer Cloud interface server that Enrollee is going to be registered
*/
- public CloudProp(String authCode, String authProvider, String ciServer) {
- mAuthCode = authCode;
- mAuthProvider = authProvider;
- mCiServer = ciServer;
+ public CloudProp() {
+ mRep = new OcRepresentation();
+ }
+
+ public void setCloudProp(String authCode, String authProvider, String ciServer)
+ {
+ try {
+ mRep.setValue(ESConstants.OC_RSRVD_ES_AUTHCODE, authCode);
+ mRep.setValue(ESConstants.OC_RSRVD_ES_AUTHPROVIDER, authProvider);
+ mRep.setValue(ESConstants.OC_RSRVD_ES_CISERVER, ciServer);
+ } catch (OcException e) {
+ Log.e(TAG, "setCloudProp is failed.");
+ }
}
/**
* This method returns the authCode used for the first registration to IoTivity cloud
* @return AuthCode for sign-up to IoTivity cloud
*/
- public String getAuthCode() {
- return mAuthCode;
+ public String getAuthCode()
+ {
+ try {
+ if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_AUTHCODE))
+ return mRep.getValue(ESConstants.OC_RSRVD_ES_AUTHCODE);
+ } catch (OcException e) {
+ Log.e(TAG, "getAuthCode is failed.");
+ }
+ return new String("");
}
/**
* This method returns the auth provider which issued the given AuthCode
* @return Auth provider which issued the given AuthCode
*/
- public String getAuthProvider() {
- return mAuthProvider;
+ public String getAuthProvider()
+ {
+ try {
+ if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_AUTHPROVIDER))
+ return mRep.getValue(ESConstants.OC_RSRVD_ES_AUTHPROVIDER);
+ } catch (OcException e) {
+ Log.e(TAG, "getAuthProvider is failed.");
+ }
+ return new String("");
}
/**
* This method returns the Cloud Interface server's URL to be registered
* @return CI server's URL to be registered
*/
- public String getCiServer() {
- return mCiServer;
+ public String getCiServer()
+ {
+ try {
+ if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_CISERVER))
+ return mRep.getValue(ESConstants.OC_RSRVD_ES_CISERVER);
+ } catch (OcException e) {
+ Log.e(TAG, "getCiServer is failed.");
+ }
+ return new String("");
+ }
+
+ public OcRepresentation toOCRepresentation()
+ {
+ return mRep;
}
}
package org.iotivity.service.easysetup.mediator;
+import android.util.Log;
+
import org.iotivity.service.easysetup.mediator.enums.WIFI_AUTHTYPE;
import org.iotivity.service.easysetup.mediator.enums.WIFI_ENCTYPE;
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcRepresentation;
+
/**
* This class contains device properties to be delivered to Enrollee
*/
public class DeviceProp {
-
- private final String mSsid;
- private final String mPwd;
- private final WIFI_AUTHTYPE mAuthType;
- private final WIFI_ENCTYPE mEncType;
- private final String mLanguage;
- private final String mCountry;
+ private static final String TAG = DeviceProp.class.getName();
+ protected OcRepresentation mRep;
/**
* Constructor
- *
- * @param ssid WiFi AP's SSID
- * @param pwd WiFi AP's password
- * @param authType WiFi AP's authenticate type
- * @param encType WiFi AP's encryption type
- * @param language IETF language tag using ISO 639X
- * @param country ISO Country Code (ISO 3166-1 Alpha-2)
*/
- public DeviceProp(String ssid, String pwd, WIFI_AUTHTYPE authType, WIFI_ENCTYPE encType,
- String language, String country)
+ public DeviceProp() {
+ mRep = new OcRepresentation();
+ }
+
+ public void setWiFiProp(String ssid, String pwd, WIFI_AUTHTYPE authtype, WIFI_ENCTYPE enctype)
{
- mSsid = ssid;
- mPwd = pwd;
- mAuthType = authType;
- mEncType = encType;
- mLanguage = language;
- mCountry = country;
+ try
+ {
+ mRep.setValue(ESConstants.OC_RSRVD_ES_SSID, ssid);
+ mRep.setValue(ESConstants.OC_RSRVD_ES_CRED, pwd);
+ mRep.setValue(ESConstants.OC_RSRVD_ES_AUTHTYPE, authtype.getValue());
+ mRep.setValue(ESConstants.OC_RSRVD_ES_ENCTYPE, enctype.getValue());
+ } catch (OcException e) {
+ Log.e(TAG, "setWiFiProp is failed.");
+ }
+ }
+
+ public void setDevConfProp(String language, String country)
+ {
+ try {
+ mRep.setValue(ESConstants.OC_RSRVD_ES_LANGUAGE, language);
+ mRep.setValue(ESConstants.OC_RSRVD_ES_COUNTRY, country);
+ } catch (OcException e) {
+ Log.e(TAG, "setDevConfProp is failed.");
+ }
}
/**
*/
public String getSsid()
{
- return mSsid;
+ try {
+ if(mRep.hasAttribute(ESConstants.OC_RSRVD_ES_SSID))
+ return mRep.getValue(ESConstants.OC_RSRVD_ES_SSID);
+ } catch (OcException e) {
+ Log.e(TAG, "getSsid is failed.");
+ }
+ return new String("");
}
/**
*
* @return String WiFi AP's password
*/
- public String getPwd()
+ public String getPassword()
{
- return mPwd;
+ try {
+ if(mRep.hasAttribute(ESConstants.OC_RSRVD_ES_CRED))
+ return mRep.getValue(ESConstants.OC_RSRVD_ES_CRED);
+ } catch (OcException e) {
+ Log.e(TAG, "getPassword is failed.");
+ }
+ return new String("");
}
/**
*/
public WIFI_AUTHTYPE getAuthType()
{
- return mAuthType;
+ try {
+ if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_AUTHTYPE))
+ return WIFI_AUTHTYPE.fromInt((int)mRep.getValue(ESConstants.OC_RSRVD_ES_AUTHTYPE));
+ } catch (OcException e) {
+ Log.e(TAG, "getAuthType is failed.");
+ }
+ return WIFI_AUTHTYPE.NONE_AUTH;
}
/**
*/
public WIFI_ENCTYPE getEncType()
{
- return mEncType;
+ try {
+ if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_ENCTYPE))
+ return WIFI_ENCTYPE.fromInt((int)mRep.getValue(ESConstants.OC_RSRVD_ES_ENCTYPE));
+ } catch (OcException e) {
+ Log.e(TAG, "getEncType is failed.");
+ }
+ return WIFI_ENCTYPE.NONE_ENC;
}
/**
*/
public String getLanguage()
{
- return mLanguage;
+ try {
+ if(mRep.hasAttribute(ESConstants.OC_RSRVD_ES_LANGUAGE))
+ return mRep.getValue(ESConstants.OC_RSRVD_ES_LANGUAGE);
+ } catch (OcException e) {
+ Log.e(TAG, "getLanguage is failed.");
+ }
+ return new String("");
}
/**
*/
public String getCountry()
{
- return mCountry;
+ try {
+ if (mRep.hasAttribute(ESConstants.OC_RSRVD_ES_COUNTRY))
+ return mRep.getValue(ESConstants.OC_RSRVD_ES_COUNTRY);
+ } catch (OcException e) {
+ Log.e(TAG, "getCountry is failed.");
+ }
+ return new String("");
+ }
+
+ public OcRepresentation toOCRepresentation()
+ {
+ return mRep;
}
}
--- /dev/null
+package org.iotivity.service.easysetup.mediator;
+
+/**
+ * Created by jhha85 on 7/27/16.
+ */
+public class ESConstants {
+
+ public static final String OC_RSRVD_ES_PROVSTATUS = "ps";
+ public static final String OC_RSRVD_ES_LAST_ERRORCODE = "lec";
+ public static final String OC_RSRVD_ES_LINKS = "links";
+ public static final String OC_RSRVD_ES_SUPPORTEDWIFIMODE = "swmt";
+ public static final String OC_RSRVD_ES_SUPPORTEDWIFIFREQ = "swf";
+ public static final String OC_RSRVD_ES_SSID = "tnn";
+ public static final String OC_RSRVD_ES_CRED = "cd";
+ public static final String OC_RSRVD_ES_AUTHTYPE = "wat";
+ public static final String OC_RSRVD_ES_ENCTYPE = "wet";
+ public static final String OC_RSRVD_ES_AUTHCODE = "ac";
+ public static final String OC_RSRVD_ES_AUTHPROVIDER = "apn";
+ public static final String OC_RSRVD_ES_CISERVER = "cis";
+ public static final String OC_RSRVD_ES_SERVERID = "sid";
+ public static final String OC_RSRVD_ES_DEVNAME = "dn";
+ public static final String OC_RSRVD_ES_LANGUAGE = "lang";
+ public static final String OC_RSRVD_ES_COUNTRY = "ctry";
+
+/**
+* Easysetup defined resoruce types and uris
+*/
+ public static final String OC_RSRVD_ES_RES_TYPE_PROV = "ocf.wk.prov";
+ public static final String OC_RSRVD_ES_URI_PROV = "/ProvisioningResURI";
+ public static final String OC_RSRVD_ES_RES_TYPE_WIFI = "ocf.wk.wifi";
+ public static final String OC_RSRVD_ES_URI_WIFI = "/WiFiProvisioningResURI";
+ public static final String OC_RSRVD_ES_RES_TYPE_CLOUDSERVER = "ocf.wk.cloudserver";
+ public static final String OC_RSRVD_ES_URI_CLOUDSERVER = "/CloudServerProvisioningResURI";
+ public static final String OC_RSRVD_ES_RES_TYPE_DEVCONF = "ocf.wk.devconf";
+ public static final String OC_RSRVD_ES_URI_DEVCONF = "/DevConfProvisioningResURI";
+
+}
package org.iotivity.service.easysetup.mediator;
+import android.util.Log;
+
+import org.iotivity.base.OcException;
+import org.iotivity.base.OcRepresentation;
+import org.iotivity.service.easysetup.mediator.ESConstants;
import org.iotivity.service.easysetup.mediator.enums.WIFI_FREQ;
import org.iotivity.service.easysetup.mediator.enums.WIFI_MODE;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
/**
* This class stores Enrollee's configuration including WiFi and Device configuration
*/
public class EnrolleeConf
{
- private final DeviceConfig mDevConf;
- private final WiFiConfig mWiFiConf;
- private final boolean mCloudable;
-
+ private static final String TAG = EnrolleeConf.class.getName();
+ private OcRepresentation mProvRep = null, mWiFiRep = null, mDevConfRep = null, mCloudRep = null;
/**
* Constructor
*
- * @param devConf
- * device name, language, and country
- * @param wifiConf
- * supported WiFi modes and frequency
- * @param cloudable
- * a preference if Enrollee is supposed to be registered to Cloud
+ * @param rep received properties in a form of OcRepresentation
+ *
*/
- public EnrolleeConf(DeviceConfig devConf, WiFiConfig wifiConf, boolean cloudable)
+ public EnrolleeConf(OcRepresentation rep)
{
- mDevConf = devConf;
- mWiFiConf = wifiConf;
- mCloudable = cloudable;
+ mProvRep = rep;
+
+ List<OcRepresentation> children = rep.getChildren();
+
+ for (OcRepresentation child : children) {
+ List<String> rts = child.getResourceTypes();
+
+ if(child.getUri().indexOf(ESConstants.OC_RSRVD_ES_URI_WIFI) != -1)
+ {
+ mWiFiRep = child;
+ }
+ else if(child.getUri().indexOf(ESConstants.OC_RSRVD_ES_URI_DEVCONF) != -1)
+ {
+ mDevConfRep = child;
+ }
+ else if(child.getUri().indexOf(ESConstants.OC_RSRVD_ES_URI_CLOUDSERVER) != -1)
+ {
+ mCloudRep = child;
+ }
+ }
}
/**
- * Get device configuration
- *
- * @return DeviceConfig
- * device name, language, and country
+ * Get Device Name property in DevConf resource
*
- * @see DeviceConfig
+ * @return deviceName
*/
- public DeviceConfig getDeviceConfig()
+ public String getDeviceName()
{
- return mDevConf;
+ try
+ {
+ if(mDevConfRep != null && mDevConfRep.hasAttribute(ESConstants.OC_RSRVD_ES_DEVNAME)) {
+ return (String) mDevConfRep.getValue(ESConstants.OC_RSRVD_ES_DEVNAME);
+ }
+ } catch (OcException e) {
+ Log.e(TAG, "getWiFiModes is failed.");
+ }
+ return new String("");
}
/**
- * Get WiFi configuration
+ * Get Supported WiFi Modes property in WiFi resource
*
- * @return WiFiConfig
- * supported WiFi modes and frequency
+ * @return a list of WiFi modes
+ */
+ public ArrayList<WIFI_MODE> getWiFiModes()
+ {
+ ArrayList<WIFI_MODE> modes = new ArrayList<WIFI_MODE>();
+ try {
+ if (mWiFiRep != null && mWiFiRep.hasAttribute(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIMODE)) {
+ int modes_int[] = mWiFiRep.getValue(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIMODE);
+ for (int i = 0 ; i < modes_int.length ; ++i) {
+ modes.add(WIFI_MODE.fromInt(modes_int[i]));
+ }
+ }
+ } catch (OcException e) {
+ Log.e(TAG, "getWiFiModes is failed.");
+ }
+ return modes;
+ }
+
+ /**
+ * Get Supported WiFi frequency property in WiFi resource
*
- * @see WiFiConfig
+ * @return WiFi frequency
*/
- public WiFiConfig getWiFiConfig()
+ public WIFI_FREQ getWiFiFreq()
{
- return mWiFiConf;
+ try{
+ if(mWiFiRep != null && mWiFiRep.hasAttribute(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
+ return WIFI_FREQ.fromInt(
+ (int)mWiFiRep.getValue(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
+ } catch (OcException e) {
+ Log.e(TAG, "getWiFiFreq is failed.");
+ }
+ return WIFI_FREQ.WIFI_FREQ_NONE;
}
/**
- * Get a preference of cloud registration of Enrollee
+ * To check if Enrollee can access to cloud. To decide its preference, we check if a cloudserver
+ * resource is registered on Enrollee.
*
- * @return true if Enrollee is supposed to be registered to Cloud
+ * @return boolean
*/
- public boolean isCloudable()
+ public boolean isCloudAccessible()
{
- return mCloudable;
+ if(mCloudRep != null && mCloudRep.getUri().indexOf(ESConstants.OC_RSRVD_ES_URI_CLOUDSERVER) != -1)
+ return true;
+
+ return false;
}
}
import android.util.Log;
+import org.iotivity.base.OcRepresentation;
+
/**
* This class represents Remote Enrollee device instance. What operations the class provides:
* 1) Ownership transfer for enabling secured communication between Mediator and Enrollee
private native void nativeGetConfiguration(GetConfigurationCallback callback);
private native void nativeProvisionSecurity(SecurityProvisioningCallback callback);
- private native void nativeProvisionDeviceProperties(String ssid, String pwd, int authType, int encType,
- String language, String country, DevicePropProvisioningCallback callback);
- private native void nativeProvisionCloudProperties(String authCode, String autoProvider,
- String ciServer, CloudPropProvisioningCallback callback);
+ private native void nativeProvisionDeviceProperties(OcRepresentation deviceProp,
+ DevicePropProvisioningCallback callback);
+ private native void nativeProvisionCloudProperties(OcRepresentation cloudProp,
+ CloudPropProvisioningCallback callback);
/* constructor will be invoked from the native layer */
private RemoteEnrollee(long nativeHandle){
* 1. WiFi AP information includes a SSID, password, auth type, and encryption type.
* 2. Device configuration includes a language (IETF language tags) and country (ISO 3166-1 Alpha-2)
*
- * @param devProp a data structure storing the above information to be delivered
+ * @param deviceProp a data structure storing the above information to be delivered
* @param callback will give the result if the provisioning succeeds or fails
*
* @throws ESException If some errors happen in this function
{
if(callback != null)
{
- nativeProvisionDeviceProperties(deviceProp.getSsid(), deviceProp.getPwd(),
- deviceProp.getAuthType().getValue(), deviceProp.getEncType().getValue(),
- deviceProp.getLanguage(), deviceProp.getCountry(), callback);
+ nativeProvisionDeviceProperties(deviceProp.toOCRepresentation(), callback);
return;
}
Log.d(TAG, "DevicePropProvisioningCallback is null ");
public void provisionCloudProperties(CloudProp cloudProp, CloudPropProvisioningCallback callback) throws ESException{
if(callback != null)
{
- nativeProvisionCloudProperties(cloudProp.getAuthCode(), cloudProp.getAuthProvider(),
- cloudProp.getCiServer(), callback);
+ nativeProvisionCloudProperties(cloudProp.toOCRepresentation(), callback);
return;
}
Log.d(TAG, "CloudPropProvisioningCallback is null ");
{
WIFI_24G(0),
WIFI_5G(1),
- WIFI_BOTH(2);
+ WIFI_BOTH(2),
+ WIFI_FREQ_NONE(999);
private int value;
JniCloudPropProvisioningStatusListener::~JniCloudPropProvisioningStatusListener()
{
- LOGI("~JniCloudPropProvisioningStatusListener()");
+ ES_LOGI("~JniCloudPropProvisioningStatusListener()");
if (m_jwListener)
{
jint ret;
cloudPropProvisioningStatus)
{
- LOGI("JniCloudPropProvisioningStatusListener::onCloudPropProvisioningStatus enter");
+ ES_LOGI("JniCloudPropProvisioningStatusListener::onCloudPropProvisioningStatus enter");
jint ret;
JNIEnv *env = GetESJNIEnv(ret);
(jint)esResult,
(jint)cloudProvisionState);
- LOGI("JniCloudPropProvisioningStatus::onCloudPropProvisioningStatus - %d, %d", esResult, cloudProvisionState);
+ ES_LOGI("JniCloudPropProvisioningStatus::onCloudPropProvisioningStatus - %d, %d", esResult, cloudProvisionState);
if (!jCloudPropProvisioningStatus)
{
- LOGE("JniCloudPropProvisioningStatus::onCloudPropProvisioningStatus Unable to create the java object");
+ ES_LOGE("JniCloudPropProvisioningStatus::onCloudPropProvisioningStatus Unable to create the java object");
return ;
}
if (env->ExceptionCheck())
{
- LOGE("Java exception is thrown");
+ ES_LOGE("Java exception is thrown");
if(needRemoveListener)
checkExAndRemoveListener(env);
if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
JniDevicePropProvisioningStatusListener::~JniDevicePropProvisioningStatusListener()
{
- LOGI("~JniDevicePropProvisioningStatusListener()");
+ ES_LOGI("~JniDevicePropProvisioningStatusListener()");
if (m_jwListener)
{
jint ret;
devicePropProvStatusCb)
{
- LOGI("JniDevicePropProvisioningStatusListener::onDevicePropProvisioningStatusCallback enter");
+ ES_LOGI("JniDevicePropProvisioningStatusListener::onDevicePropProvisioningStatusCallback enter");
jint ret;
JNIEnv *env = GetESJNIEnv(ret);
g_mid_DevicePropProvisioningStatus_ctor,
(jint)nativeESResult);
- LOGI("JniDevicePropProvisioningStatus::onDevicePropProvisioningStatus - %d", nativeESResult);
+ ES_LOGI("JniDevicePropProvisioningStatus::onDevicePropProvisioningStatus - %d", nativeESResult);
if (!jDevicePropProvisioningStatus)
{
- LOGE("JniDevicePropProvisioningStatus::onDevicePropProvisioningStatus Unable to create the java object");
+ ES_LOGE("JniDevicePropProvisioningStatus::onDevicePropProvisioningStatus Unable to create the java object");
return ;
}
if (env->ExceptionCheck())
{
- LOGE("Java exception is thrown");
+ ES_LOGE("Java exception is thrown");
checkExAndRemoveListener(env);
if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
return;
#include "octypes.h"
#include "ESRichCommon.h"
-#include "JniOcPlatform.h"
#include "JniOcResource.h"
#include "JniEasySetup.h"
Java_org_iotivity_service_easysetup_mediator_EasySetup_nativeCreateRemoteEnrollee
(JNIEnv *env, jobject thiz, jobject jResource)
{
- LOGI("JniEasySetup::nativeCreateRemoteEnrollee enter");
+ ES_LOGI("JniEasySetup::nativeCreateRemoteEnrollee enter");
std::shared_ptr<RemoteEnrollee> nativeRemoteEnrollee;
jobject jRemoteEnrollee;
if (!jniOcResource)
{
- LOGE("JniEasySetup::nativeCreateRemoteEnrollee getJniOcResourcePtr returns nullptr.");
+ ES_LOGE("JniEasySetup::nativeCreateRemoteEnrollee getJniOcResourcePtr returns nullptr.");
return nullptr;
}
jRemoteEnrollee = env->NewObject(g_cls_RemoteEnrollee, g_mid_RemoteEnrollee_ctor);
if (!jRemoteEnrollee)
{
- LOGE("JniEasySetup::nativeCreateRemoteEnrollee Unable to create the java object");
+ ES_LOGE("JniEasySetup::nativeCreateRemoteEnrollee Unable to create the java object");
return NULL;
}
JniRemoteEnrollee *jniRemoteEnrollee = new JniRemoteEnrollee(nativeRemoteEnrollee);
}
catch (ESBadRequestException exception)
{
- LOGE("JniEasySetup::nativeCreateRemoteEnrollee Unable to create the Native EnrolleeDevice");
+ ES_LOGE("JniEasySetup::nativeCreateRemoteEnrollee Unable to create the Native EnrolleeDevice");
//throw the exception to java layer
throwESException( env, exception.what());
}
- LOGI("JniEasySetup::nativeCreateRemoteEnrollee exit");
+ ES_LOGI("JniEasySetup::nativeCreateRemoteEnrollee exit");
return jRemoteEnrollee;
}
refPair.second++;
it->second = refPair;
m_listenerMap.insert(*it);
- LOGD("OnEventListener: ref. count is incremented");
+ ES_LOGD("OnEventListener: ref. count is incremented");
break;
}
}
}
else
{
- LOGD("OnEventListener: Failed to create global listener ref.");
+ ES_LOGD("OnEventListener: Failed to create global listener ref.");
delete onEventListener;
}
- LOGD("OnEventListener: new listener");
+ ES_LOGD("OnEventListener: new listener");
}
m_mapMutex.unlock();
return onEventListener;
refPair.second--;
it->second = refPair;
m_listenerMap.insert(*it);
- LOGI("OnEventListener: ref. count is decremented");
+ ES_LOGI("OnEventListener: ref. count is decremented");
}
else
{
delete listener;
m_listenerMap.erase(it);
- LOGI("OnEventListener is removed");
+ ES_LOGI("OnEventListener is removed");
}
break;
}
env->NewStringUTF(reason.c_str()));
if (!ex)
{
- LOGI("throwException : jobject is NULL");
+ ES_LOGI("throwException : jobject is NULL");
}
env->Throw((jthrowable)ex);
}
#include "JniGetConfigurationStatusListener.h"
#include "JniRemoteEnrollee.h"
+using namespace OC;
using namespace OIC::Service;
JniGetConfigurationStatusListener::JniGetConfigurationStatusListener(JNIEnv *env, jobject jListener,
JniGetConfigurationStatusListener::~JniGetConfigurationStatusListener()
{
- LOGI("~JniGetConfigurationStatusListener()");
+ ES_LOGI("~JniGetConfigurationStatusListener()");
if (m_jwListener)
{
jint ret;
void JniGetConfigurationStatusListener::getConfigurationStatusCallback (
std::shared_ptr<GetConfigurationStatus> getConfigurationStatusCb)
{
- LOGI("JniGetConfigurationStatusListener::provisioiningStatusCallback enter");
+ ES_LOGI("JniGetConfigurationStatusListener::provisioiningStatusCallback enter");
jint ret;
JNIEnv *env = GetESJNIEnv(ret);
return;
}
- const EnrolleeConf enrolleeConf = getConfigurationStatusCb->getEnrolleeConf();
- DeviceConfig devConf = enrolleeConf.getDevConf();
- WiFiConfig wifiConf = enrolleeConf.getWiFiConf();
-
- jobject jDevConf = NULL;
- jDevConf = env->NewObject(g_cls_DeviceConfig,
- g_mid_DeviceConfig_ctor,
- (jstring)env->NewStringUTF(devConf.name.c_str()),
- (jstring)env->NewStringUTF(devConf.language.c_str()),
- (jstring)env->NewStringUTF(devConf.country.c_str()));
- if (!jDevConf) {
- LOGE("JniGetConfigurationStatusListener::getConfigurationStatusCallback Unable to create the jDevConf");
- return ;
- }
-
- jclass clazz = env->FindClass("java/util/ArrayList");
- jobject wifiModes = env->NewObject(clazz, env->GetMethodID(clazz, "<init>", "()V"));
- jmethodID arraylist_add = env->GetMethodID(clazz, "add", "(Ljava/lang/Object;)Z");
+ EnrolleeConf enrolleeConf = getConfigurationStatusCb->getEnrolleeConf();
+ OCRepresentation m_ProvRep = enrolleeConf.getProvResRep();
- for (int n=0; n<wifiConf.modes.size(); n++)
+ OCRepresentation* rep = new OCRepresentation(m_ProvRep);
+ jlong handle = reinterpret_cast<jlong>(rep);
+ jobject jRepresentation = env->NewObject(g_cls_OcRepresentation, g_mid_OcRepresentation_N_ctor_bool,
+ handle, true);
+ if (!jRepresentation)
{
- jobject value = env->NewObject(g_cls_Integer,
- g_mid_Integer_ctor,
- convertNativeWifiModeToInt(static_cast<WIFI_MODE>(wifiConf.modes[n])));
- env->CallBooleanMethod(wifiModes, arraylist_add, value);
- }
- if (!wifiModes) {
- LOGE("JniGetConfigurationStatusListener::getConfigurationStatusCallback Unable to create the wifiModes");
- return ;
- }
-
-
- jobject jWiFiConf = NULL;
- jWiFiConf = env->NewObject(g_cls_WiFiConfig,
- g_mid_WiFiConfig_ctor,
- (jobject)wifiModes,
- (jint)convertNativeWifiFreqToInt(wifiConf.freq));
- if (!jWiFiConf) {
- LOGE("JniGetConfigurationStatusListener::getConfigurationStatusCallback Unable to create the jWiFiConf");
- return ;
+ delete rep;
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+ return;
}
jobject jEnrolleeConf = NULL;
- jEnrolleeConf = env->NewObject(g_cls_EnrolleeConf,
- g_mid_EnrolleeConf_ctor,
- (jobject)jDevConf,
- (jobject)jWiFiConf,
- (jboolean)enrolleeConf.isCloudable());
+ jEnrolleeConf = env->NewObject(g_cls_EnrolleeConf, g_mid_EnrolleeConf_ctor, (jobject)jRepresentation);
if (!jEnrolleeConf) {
- LOGE("JniGetConfigurationStatusListener::getConfigurationStatusCallback Unable to create the jEnrolleeConf");
+ ES_LOGE("JniGetConfigurationStatusListener::getConfigurationStatusCallback Unable to create the jEnrolleeConf");
return ;
}
if (!jgetConfigurationStatus)
{
- LOGE("JniGetConfigurationStatusListener::getConfigurationStatusCallback Unable to create the java object");
+ ES_LOGE("JniGetConfigurationStatusListener::getConfigurationStatusCallback Unable to create the java object");
return ;
}
if (env->ExceptionCheck())
{
- LOGE("Java exception is thrown");
+ ES_LOGE("Java exception is thrown");
checkExAndRemoveListener(env);
if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
return;
#include <jni.h>
+#include "OCPlatform.h"
#include "RemoteEnrollee.h"
#include "ESRichCommon.h"
jclass g_cls_DevicePropProvisioningStatus = NULL;
jclass g_cls_CloudPropProvisioningStatus = NULL;
jclass g_cls_Integer = NULL;
+jclass g_cls_OcRepresentation = NULL;
jmethodID g_mid_RemoteEnrollee_ctor = NULL;
jmethodID g_mid_ESException_ctor = NULL;
jmethodID g_mid_DevicePropProvisioningStatus_ctor = NULL;
jmethodID g_mid_CloudPropProvisioningStatus_ctor = NULL;
jmethodID g_mid_Integer_ctor = NULL;
+jmethodID g_mid_OcRepresentation_N_ctor_bool = NULL;
// JNI OnLoad
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
{
- LOGI("JNI_OnLoad");
+ ES_LOGI("JNI_OnLoad");
JNIEnv *env;
g_jvm = vm;
if (g_jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
{
- LOGE("Failed to get the environment using GetEnv()");
+ ES_LOGE("Failed to get the environment using GetEnv()");
return JNI_ERR;
}
env->DeleteLocalRef(clazz);
g_mid_EnrolleeConf_ctor = env->GetMethodID(g_cls_EnrolleeConf, "<init>",
- "(Lorg/iotivity/service/easysetup/mediator/DeviceConfig;Lorg/iotivity/service/easysetup/mediator/WiFiConfig;Z)V");
+ "(Lorg/iotivity/base/OcRepresentation;)V");
if (!g_mid_EnrolleeConf_ctor) return JNI_ERR;
// getConfigurationStatus
"(I)V");
if (!g_mid_Integer_ctor) return JNI_ERR;
+ //OcRepresentation
+ clazz = env->FindClass("org/iotivity/base/OcRepresentation");
+ if (!clazz) return JNI_ERR;
+ g_cls_OcRepresentation = (jclass)env->NewGlobalRef(clazz);
+ env->DeleteLocalRef(clazz);
+
+ g_mid_OcRepresentation_N_ctor_bool = env->GetMethodID(g_cls_OcRepresentation, "<init>", "(JZ)V");
+ if (!g_mid_OcRepresentation_N_ctor_bool) return JNI_ERR;
+
return JNI_CURRENT_VERSION;
}
//JNI OnUnload
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
{
- LOGI("JNI_OnUnload");
+ ES_LOGI("JNI_OnUnload");
JNIEnv *env;
if (g_jvm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK)
{
- LOGE("Failed to get the environment using GetEnv()");
+ ES_LOGE("Failed to get the environment using GetEnv()");
return;
}
env->DeleteGlobalRef(g_cls_RemoteEnrollee);
#define ESTAG "ES-JNI"
#define JNI_CURRENT_VERSION JNI_VERSION_1_6
-#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, ESTAG, __VA_ARGS__)
-#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, ESTAG, __VA_ARGS__)
-#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, ESTAG, __VA_ARGS__)
+#define ES_LOGI(...) __android_log_print(ANDROID_LOG_INFO, ESTAG, __VA_ARGS__)
+#define ES_LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, ESTAG, __VA_ARGS__)
+#define ES_LOGE(...) __android_log_print(ANDROID_LOG_ERROR, ESTAG, __VA_ARGS__)
extern JavaVM *g_jvm;
extern jclass g_cls_DevicePropProvisioningStatus;
extern jclass g_cls_CloudPropProvisioningStatus;
extern jclass g_cls_Integer;
+extern jclass g_cls_OcRepresentation;
extern jmethodID g_mid_RemoteEnrollee_ctor;
extern jmethodID g_mid_ESException_ctor;
extern jmethodID g_mid_DevicePropProvisioningStatus_ctor;
extern jmethodID g_mid_CloudPropProvisioningStatus_ctor;
extern jmethodID g_mid_Integer_ctor;
+extern jmethodID g_mid_OcRepresentation_N_ctor_bool;
typedef void(*RemoveListenerCallback)(JNIEnv *env, jobject jListener);
case JNI_EDETACHED:
if (g_jvm->AttachCurrentThread(&env, NULL) < 0)
{
- LOGE("Failed to get the environment");
+ ES_LOGE("Failed to get the environment");
return nullptr;
}
else
}
case JNI_EVERSION:
- LOGE("JNI version not supported");
+ ES_LOGE("JNI version not supported");
default:
- LOGE("Failed to get the environment");
+ ES_LOGE("Failed to get the environment");
return nullptr;
}
}
#include "JniRemoteEnrollee.h"
+#include "JniOcRepresentation.h"
+
using namespace OIC::Service;
JniRemoteEnrollee::JniRemoteEnrollee(std::shared_ptr<RemoteEnrollee> remoteEnrollee)
JniRemoteEnrollee::~JniRemoteEnrollee()
{
- LOGD("JniRemoteEnrollee::~JniRemoteEnrollee()");
+ ES_LOGD("JniRemoteEnrollee::~JniRemoteEnrollee()");
m_sharedResource = NULL;
jint envRet;
JniRemoteEnrollee *remoteEnrollee = ESGetHandle<JniRemoteEnrollee>(env, thiz);
if (env->ExceptionCheck())
{
- LOGE("getJniRemoteEnrollee :: Failed to get native handle from RemoteEnrollee object");
+ ES_LOGE("getJniRemoteEnrollee :: Failed to get native handle from RemoteEnrollee object");
}
if (!remoteEnrollee)
{
- LOGE("getJniRemoteEnrollee :: no resource");
+ ES_LOGE("getJniRemoteEnrollee :: no resource");
}
return remoteEnrollee;
}
}
catch (ESBadRequestException exception)
{
- LOGE("JNI getConfiguration :: Exception occured");
+ ES_LOGE("JNI getConfiguration :: Exception occured");
//throw the exception to java
throwESException( env, exception.what());
}
}
catch (ESBadRequestException exception)
{
- LOGE("JNI provisionSecurity :: Exception occured");
+ ES_LOGE("JNI provisionSecurity :: Exception occured");
//throw the exception to java
throwESException( env, exception.what());
}
}
-void JniRemoteEnrollee::provisionDeviceProperties(JNIEnv *env, jstring jssid, jstring jpwd, jint jauthType,
- jint jencType, jstring jlanguage, jstring jcountry, jobject jListener)
+void JniRemoteEnrollee::provisionDeviceProperties(JNIEnv *env, jobject jRepresentation, jobject jListener)
{
- DeviceProp prop;
-
- prop.WIFI.ssid = env->GetStringUTFChars(jssid, NULL);
- prop.WIFI.pwd = env->GetStringUTFChars(jpwd, NULL);
- prop.WIFI.authtype = getWifiAuthTypeFromInt(jauthType);
- prop.WIFI.enctype = getWifiEncTypeFromInt(jencType);
- prop.Device.language = env->GetStringUTFChars(jlanguage, NULL);
- prop.Device.country = env->GetStringUTFChars(jcountry, NULL);
+ OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
+ if (!representation)
+ {
+ return;
+ }
+ DeviceProp deviceProp(*representation);
JniDevicePropProvisioningStatusListener *onDevicePropProvStatusReceived =
addStatusListener<JniDevicePropProvisioningStatusListener>(env, jListener);
try
{
- m_sharedResource->provisionDeviceProperties(prop, devicePropProvStatusCallback);
+ m_sharedResource->provisionDeviceProperties(deviceProp, devicePropProvStatusCallback);
}
catch (ESBadRequestException exception)
{
- LOGE("JNI provisionDeviceProperties :: Exception occured");
+ ES_LOGE("JNI provisionDeviceProperties :: Exception occured");
//throw the exception to java
throwESException( env, exception.what());
}
}
-void JniRemoteEnrollee::provisionCloudProperties(JNIEnv *env, jstring jauthCode, jstring jauthProvider,
- jstring jciServer, jobject jListener)
+void JniRemoteEnrollee::provisionCloudProperties(JNIEnv *env, jobject jRepresentation, jobject jListener)
{
- CloudProp prop;
-
- prop.authCode = env->GetStringUTFChars(jauthCode, NULL);
- prop.authProvider = env->GetStringUTFChars(jauthProvider, NULL);
- prop.ciServer = env->GetStringUTFChars(jciServer, NULL);
+ OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation);
+ if (!representation)
+ {
+ return;
+ }
+ CloudProp cloudProp(*representation);
JniCloudPropProvisioningStatusListener *onCloudPropProvisioningStatusReceived =
addStatusListener<JniCloudPropProvisioningStatusListener>(env, jListener);
try
{
- m_sharedResource->provisionCloudProperties(prop, cloudPropProvStatusCallback);
+ m_sharedResource->provisionCloudProperties(cloudProp, cloudPropProvStatusCallback);
}
catch (ESBadRequestException exception)
{
- LOGE("JNI startProvisioning :: Exception occured");
+ ES_LOGE("JNI startProvisioning :: Exception occured");
//throw the exception to java
throwESException(env, exception.what());
}
Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeGetConfiguration
(JNIEnv *env, jobject jClass, jobject jListener)
{
- LOGD("nativegetConfiguration Enter");
+ ES_LOGD("nativegetConfiguration Enter");
JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
remoteEnrollee->getConfiguration(env, jListener);
- LOGD("nativegetConfiguration Exit");
+ ES_LOGD("nativegetConfiguration Exit");
}
JNIEXPORT void JNICALL
Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeProvisionSecurity
(JNIEnv *env, jobject jClass, jobject jListener)
{
- LOGD("nativeStartSecurityProvision Enter");
+ ES_LOGD("nativeStartSecurityProvision Enter");
JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
remoteEnrollee->provisionSecurity(env, jListener);
- LOGD("nativeStartSecurityProvision Exit");
+ ES_LOGD("nativeStartSecurityProvision Exit");
}
JNIEXPORT void JNICALL
Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeProvisionDeviceProperties
-(JNIEnv *env, jobject jClass, jstring jssid, jstring jpwd, jint jauthType,
- jint jencType, jstring jlanguage, jstring jcountry, jobject jListener)
+(JNIEnv *env, jobject jClass, jobject jRepresentation, jobject jListener)
{
- LOGD("nativeProvisionDeviceProperties Enter");
+ ES_LOGD("nativeProvisionDeviceProperties Enter");
JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
- remoteEnrollee->provisionDeviceProperties(env, jssid, jpwd, jauthType, jencType,
- jlanguage, jcountry, jListener);
+ remoteEnrollee->provisionDeviceProperties(env, jRepresentation, jListener);
- LOGD("nativeProvisionDeviceProperties Exit");
+ ES_LOGD("nativeProvisionDeviceProperties Exit");
}
JNIEXPORT void JNICALL
Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeProvisionCloudProperties
-(JNIEnv *env, jobject jClass, jstring authCode, jstring authProvider,
- jstring ciServer, jobject jListener)
+(JNIEnv *env, jobject jClass, jobject jRepresentation, jobject jListener)
{
- LOGD("nativeprovisionCloudProperties Enter");
+ ES_LOGD("nativeprovisionCloudProperties Enter");
JniRemoteEnrollee *remoteEnrollee = JniRemoteEnrollee::getJniRemoteEnrollee(env, jClass);
- remoteEnrollee->provisionCloudProperties(env, authCode, authProvider, ciServer, jListener);
+ remoteEnrollee->provisionCloudProperties(env, jRepresentation, jListener);
- LOGD("nativeprovisionCloudProperties Exit");
+ ES_LOGD("nativeprovisionCloudProperties Exit");
}
\ No newline at end of file
// ***** JNI APIs internally call the APIs of this class ***** //
void getConfiguration(JNIEnv *env, jobject jListener);
void provisionSecurity(JNIEnv *env, jobject jListener);
- void provisionDeviceProperties(JNIEnv *env, jstring jssid, jstring jpwd, jint jauthType,
- jint jencType, jstring jlanguage, jstring jcountry, jobject jListener);
- void provisionCloudProperties(JNIEnv *env, jstring authCode, jstring authProvider,
- jstring ciServer, jobject jListener);
+
+ void provisionDeviceProperties(JNIEnv *env, jobject jRepresentation, jobject jListener);
+ void provisionCloudProperties(JNIEnv *env, jobject jRepresentation, jobject jListener);
static JniRemoteEnrollee *getJniRemoteEnrollee(JNIEnv *env, jobject thiz);
*/
JNIEXPORT void JNICALL
Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeProvisionDeviceProperties
-(JNIEnv *env, jobject jClass, jstring jssid, jstring jpwd, jint jauthType,
- jint jencType, jstring jlanguage, jstring jcountry, jobject jListener);
+(JNIEnv *env, jobject jClass, jobject jRepresentation, jobject jListener);
/**
* API for starting the cloud provisioning process.
*/
JNIEXPORT void JNICALL
Java_org_iotivity_service_easysetup_mediator_RemoteEnrollee_nativeProvisionCloudProperties
-(JNIEnv *env, jobject jClass, jstring authCode, jstring authProvider,
- jstring ciServer, jobject jListener);
+(JNIEnv *env, jobject jClass, jobject jRepresentation, jobject jListener);
#ifdef __cplusplus
}
JniSecurityStatusListener::~JniSecurityStatusListener()
{
- LOGI("~JniSecurityStatusListener()");
+ ES_LOGI("~JniSecurityStatusListener()");
if (m_jwListener)
{
jint ret;
std::shared_ptr<SecProvisioningStatus> secProvisioningStatus)
{
- LOGI("JniSecurityStatusListener::secProvisionStatusCallback enter");
+ ES_LOGI("JniSecurityStatusListener::secProvisionStatusCallback enter");
jint ret;
JNIEnv *env = GetESJNIEnv(ret);
//create the java object
jobject jSecurityProvisioningStatus = NULL;
jSecurityProvisioningStatus = env->NewObject(g_cls_SecurityProvisioningStatus,
- g_mid_SecurityProvisioningStatus_ctor,
- (jint)esResult,
- env->NewStringUTF(secProvisioningStatus->getDeviceUUID().c_str()));
+ g_mid_SecurityProvisioningStatus_ctor,
+ (jint)esResult,
+ env->NewStringUTF(secProvisioningStatus->getDeviceUUID().c_str()));
- LOGE("JniSecurityStatusListener::onSecurityProvisioningStatus UUID : %s", secProvisioningStatus->getDeviceUUID().c_str());
+ ES_LOGE("JniSecurityStatusListener::onSecurityProvisioningStatus UUID : %s",
+ secProvisioningStatus->getDeviceUUID().c_str());
if (!jSecurityProvisioningStatus)
{
- LOGE("JniSecurityStatusListener::onSecurityProvisioningStatus Unable to create the java object");
+ ES_LOGE("JniSecurityStatusListener::onSecurityProvisioningStatus Unable to create the java object");
return ;
}
if (env->ExceptionCheck())
{
- LOGE("Java exception is thrown");
+ ES_LOGE("Java exception is thrown");
checkExAndRemoveListener(env);
if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread();
return;
if(getConfigurationStatus.getESResult() == ESResult.ES_OK) {
final EnrolleeConf enrolleeConf = getConfigurationStatus.getEnrolleeConf();
- final DeviceConfig devConf = enrolleeConf.getDeviceConfig();
- final WiFiConfig netInfo = enrolleeConf.getWiFiConfig();
runOnUiThread(new Runnable() {
@Override
public void run() {
mGetconfigurationStateText.setText("Success");
- mDevNameText.setText(devConf.getName());
- mLanguageText.setText(devConf.getLanguage());
- mCountryText.setText(devConf.getCountry());
- setWifiModes(netInfo.getWifiModes());
- setWifiFreq(netInfo.getWifiFreq());
+ mDevNameText.setText(enrolleeConf.getDeviceName());
+ setWifiModes(enrolleeConf.getWiFiModes());
+ setWifiFreq(enrolleeConf.getWiFiFreq());
- if(enrolleeConf.isCloudable()) {
+ if(enrolleeConf.isCloudAccessible()) {
mCloudAccessableText.setText("TRUE");
}
else {
String inputLanguage = mInputLanguageText.getText().toString();
String inputCountry = mInputCountryText.getText().toString();
- DeviceProp deviceProp =
- new DeviceProp(enrollerSSID, enrollerPW, authType, encType,
- inputLanguage, inputCountry);
+ DeviceProp deviceProp = new DeviceProp();
+ deviceProp.setWiFiProp(enrollerSSID, enrollerPW, authType, encType);
+ deviceProp.setDevConfProp(inputLanguage, inputCountry);
mRemoteEnrollee.provisionDeviceProperties(deviceProp, new DevicePropProvisioningCallback() {
@Override
String authProvider = mAuthProviderText.getText().toString();
String ciserver = mCIServerText.getText().toString();
- CloudProp cloudProp =
- new CloudProp(authCode, authProvider, ciserver);
+ CloudProp cloudProp = new CloudProp();
+ cloudProp.setCloudProp(authCode, authProvider, ciserver);
mRemoteEnrollee.provisionCloudProperties(cloudProp, new CloudPropProvisioningCallback() {
@Override