[IOT-2724] ES Mediator Android Sample Crash. 55/22555/5
authorSenthil Kumar G S <senthil.gs@samsung.com>
Thu, 21 Sep 2017 16:32:13 +0000 (22:02 +0530)
committerUze Choi <uzchoi@samsung.com>
Wed, 27 Sep 2017 08:25:16 +0000 (08:25 +0000)
Updated JNI file to add iotivity stack version in EnrolleeConfig representation.
Updated sample to parse wifi modes and frequencies based on the version.

Change-Id: I1580823bdf3309369eb747dca4d3ce1bc3087158
Signed-off-by: Senthil Kumar G S <senthil.gs@samsung.com>
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeConf.java
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniGetConfigurationStatusListener.cpp
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniJvm.cpp
service/easy-setup/mediator/richsdk/inc/ESRichCommon.h
service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp

index fa4cfb2..51e439c 100755 (executable)
@@ -40,15 +40,19 @@ public class EnrolleeConf
 {
     private static final String TAG = EnrolleeConf.class.getName();
     protected OcRepresentation mEasySetupRep = null;
+    protected int mSpecVersion = 0;
+
     /**
      * Constructor
      *
      * @param rep received properties in a form of OcRepresentation
+     * @param specVersion Indicates the spec version of enrollee.
      *
      */
-    public EnrolleeConf(OcRepresentation rep)
+    public EnrolleeConf(OcRepresentation rep, int specVersion)
     {
         mEasySetupRep = rep;
+        mSpecVersion = specVersion;
     }
 
     public EnrolleeConf(EnrolleeConf enrolleeConf)
@@ -165,9 +169,24 @@ public class EnrolleeConf
                     }
 
                     if (rep.hasAttribute(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIMODE)) {
-                        int modes_int[] = rep.getValue(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIMODE);
-                        for (int i = 0 ; i < modes_int.length ; ++i) {
-                            modes.add(WIFI_MODE.fromInt(modes_int[i]));
+                        // Response from OIC Server does not contain spec version in header, so assumed as 0.
+                        if(0 == mSpecVersion) {
+                            // Considering Representation as per OIC Core Spec.
+                            int modes_int[] = rep.getValue(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIMODE);
+                            for (int i = 0 ; i < modes_int.length ; ++i) {
+                                modes.add(WIFI_MODE.fromInt(modes_int[i]));
+                            }
+                        }
+                        else {
+                            // Considering Representation as per OCF 1.0 / 1.x Core Spec.
+                            String modes_str[] = rep.getValue(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIMODE);
+                            for (int i = 0 ; i < modes_str.length ; ++i) {
+                                for(WIFI_MODE mode : WIFI_MODE.values()) {
+                                    if(mode.name().contains(modes_str[i])) {
+                                       modes.add(mode);
+                                    }
+                                }
+                            }
                         }
                     }
                 } catch (OcException e) {
@@ -206,9 +225,19 @@ public class EnrolleeConf
                         return null;
                     }
 
-                    if(rep.hasAttribute(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
-                        return WIFI_FREQ.fromInt(
-                                (int)rep.getValue(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
+                    if(rep.hasAttribute(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIFREQ)) {
+                        // Response from OIC Server does not contain spec version in header, so assumed as 0.
+                        if(0 == mSpecVersion) {
+                            // Considering Representation as per OIC Core Spec.
+                            return WIFI_FREQ.fromInt(
+                                    (int)rep.getValue(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
+                        }
+                        else {
+                            // Considering Representation as per OCF 1.0 / 1.x Core Spec.
+                            String freqs[] = rep.getValue(ESConstants.OC_RSRVD_ES_SUPPORTEDWIFIFREQ);
+                            return getWiFiFreqAsEnum(freqs);
+                        }
+                    }
                 } catch (OcException e) {
                     Log.e(TAG, "getWiFiFreq is failed.");
                 }
@@ -245,6 +274,37 @@ public class EnrolleeConf
     {
         return mEasySetupRep;
     }
-}
 
+    private WIFI_FREQ getWiFiFreqAsEnum(String[] freqs)
+    {
+        WIFI_FREQ freq_res = WIFI_FREQ.WIFI_FREQ_NONE;
+        boolean b_2_4G = false;
+        boolean b_5G = false;
+        for (String freq : freqs)
+        {
+            if(freq.equals("2.4G"))
+            {
+                b_2_4G = true;
+            }
+            else if(freq.equals("5G"))
+            {
+                b_5G = true;
+            }
+        }
+
+        if(b_2_4G && b_5G) {
+            freq_res = WIFI_FREQ.WIFI_BOTH;
+        }
+        else if(b_2_4G) {
+            freq_res = WIFI_FREQ.WIFI_24G;
+        }
+        else if(b_5G) {
+            freq_res = WIFI_FREQ.WIFI_5G;
+        }
+        else {
+            freq_res = WIFI_FREQ.WIFI_FREQ_NONE;
+        }
 
+        return freq_res;
+    }
+}
index 3de688e..8205439 100644 (file)
@@ -82,8 +82,8 @@ void JniGetConfigurationStatusListener::getConfigurationStatusCallback (
 
     EnrolleeConf enrolleeConf = getConfigurationStatusCb->getEnrolleeConf();
     OCRepresentation m_ProvRep = enrolleeConf.getEasySetupRep();
-
     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);
@@ -98,8 +98,9 @@ void JniGetConfigurationStatusListener::getConfigurationStatusCallback (
         return;
     }
 
+    jint jSpecVersion = enrolleeConf.getOCFSpecVersion();
     jobject jEnrolleeConf = NULL;
-    jEnrolleeConf = env->NewObject(g_cls_EnrolleeConf, g_mid_EnrolleeConf_ctor, (jobject)jRepresentation);
+    jEnrolleeConf = env->NewObject(g_cls_EnrolleeConf, g_mid_EnrolleeConf_ctor, jRepresentation, jSpecVersion);
     if (!jEnrolleeConf) {
         ES_LOGE("JniGetConfigurationStatusListener::getConfigurationStatusCallback Unable to create the jEnrolleeConf");
         return ;
index 256c788..3e92847 100644 (file)
@@ -98,7 +98,7 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
     env->DeleteLocalRef(clazz);
 
     g_mid_EnrolleeConf_ctor = env->GetMethodID(g_cls_EnrolleeConf, "<init>",
-                                "(Lorg/iotivity/base/OcRepresentation;)V");
+                                "(Lorg/iotivity/base/OcRepresentation;I)V");
     if (!g_mid_EnrolleeConf_ctor) return JNI_ERR;
 
     // getEnrolleeStatus
index da464ce..a28833d 100644 (file)
@@ -775,11 +775,12 @@ namespace OIC
 
                         if(rep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
                         {
+                            // Response from OIC Server does not contain spec version in header, so assumed as 0.
                             if(0 == m_OCFServerVersion)
                             {
                                 OIC_LOG(DEBUG, ES_RICH_COMMON_TAG, "getWiFiModes() with OIC Spec");
 
-                                /* Considering Representation as per OIC Core Spec */
+                                // Considering Representation as per OIC Core Spec.
                                 for(auto it : rep.getValue
                                         <std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
                                 {
@@ -790,7 +791,7 @@ namespace OIC
                             {
                                 OIC_LOG(DEBUG, ES_RICH_COMMON_TAG, "getWiFiModes() with OCF Spec");
 
-                                /* Considering Representation as per OCF 1.0 / 1.x Core Spec */
+                                // Considering Representation as per OCF 1.0 / 1.x Core Spec.
                                 for(auto it : rep.getValue
                                         <std::vector<std::string>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
                                 {
@@ -829,11 +830,12 @@ namespace OIC
 
                         if(rep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
                         {
+                            // Response from OIC Server does not contain spec version in header, so assumed as 0.
                             if(0 == m_OCFServerVersion)
                             {
                                 OIC_LOG(DEBUG, ES_RICH_COMMON_TAG, "getWiFiFreq() with OIC Spec");
 
-                                /* Considering Representation as per OIC Core Spec */
+                                // Considering Representation as per OIC Core Spec.
                                 return static_cast<WIFI_FREQ>(
                                             rep.getValue<int>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
                             }
@@ -841,7 +843,7 @@ namespace OIC
                             {
                                 OIC_LOG(DEBUG, ES_RICH_COMMON_TAG, "getWiFiFreq() with OCF Spec");
 
-                                /* Considering Representation as per OCF 1.0 / 1.x Core Spec */
+                                // Considering Representation as per OCF 1.0 / 1.x Core Spec.
                                 return getWiFiFreqAsEnum(rep.getValue
                                         <std::vector<std::string>>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
                             }
index a256304..cd56f25 100644 (file)
@@ -156,7 +156,6 @@ namespace OIC
             else
             {
                 EnrolleeConf enrolleeConf(rep, version);
-
                 std::shared_ptr< GetConfigurationStatus > getConfigurationStatus = std::make_shared<
                         GetConfigurationStatus >(ESResult::ES_OK, enrolleeConf);
                 m_getConfigurationStatusCb(getConfigurationStatus);