Updated mediator android application for secure mode.
authorSenthil Kumar G S <senthil.gs@samsung.com>
Fri, 19 May 2017 15:11:10 +0000 (20:41 +0530)
committerUze Choi <uzchoi@samsung.com>
Sat, 20 May 2017 03:52:57 +0000 (03:52 +0000)
In secure mode, mediator should send requests to the secure endpoint
of the easy-setup resource. Updated the sample to handle the same.

Change-Id: I5a27f06bcf2f8698d58e2b79049d7b342e303599
Signed-off-by: Senthil Kumar G S <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20153
Reviewed-by: Jihun Ha <jihun.ha@samsung.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/assets/oic_svr_db_client.dat
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/EasysetupActivity.java

index 025c39b..08a76e2 100644 (file)
Binary files a/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/assets/oic_svr_db_client.dat and b/service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/assets/oic_svr_db_client.dat differ
index 5cadbcb..0ef8f42 100755 (executable)
@@ -88,9 +88,9 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.EnumSet;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 
-
 public class EasysetupActivity extends Activity
                                 implements OcPlatform.OnPresenceListener,
                                            OcResource.OnObserveListener{
@@ -422,6 +422,31 @@ public class EasysetupActivity extends Activity
                             Log.d(TAG,"URI of the resource: " + resourceUri);
                             Log.d(TAG,"Host address of the resource: " + hostAddress);
 
+                            if(mSecurityMode.isChecked())
+                            {
+                                // Change the host of the resource to secure endpoint.
+                                List<String> endpoints = ocResource.getAllHosts();
+                                if(null != endpoints || 0 == endpoints.size())
+                                {
+                                    Log.d(TAG, "Endpoints of the resource: " + endpoints);
+                                    Iterator<String> itr = endpoints.iterator();
+                                    while(itr.hasNext())
+                                    {
+                                        String endpoint = itr.next();
+                                        if(null != endpoint && endpoint.contains("coaps://"))
+                                        {
+                                            String retval = ocResource.setHost(endpoint);
+                                            Log.d(TAG, "Found coaps endpoint: setHost() returned " + retval);
+                                            break;
+                                        }
+                                    }
+                                }
+                                else
+                                {
+                                    Log.d(TAG, "No endpoints found");
+                                }
+                            }
+
                             mRemoteEnrollee = mEasySetup.createRemoteEnrollee(ocResource);
 
                             if(mRemoteEnrollee == null) {