Merge branch 'master' into easysetup
[iotivity.git] / service / easy-setup / sampleapp / mediator / android / EasySetup / app / src / main / java / org / iotivity / service / easysetup / MainActivity.java
index b11876e..2cbd6e5 100755 (executable)
@@ -79,7 +79,7 @@ public class MainActivity extends Activity {
     public static final int FAILED        = 1;\r
     public static final int STATE_CHANGED = 2;\r
 \r
-    public static final String OIC_CLIENT_JSON_DB_FILE =  "oic_svr_db_client.json";\r
+    public static final String OIC_CLIENT_JSON_DB_FILE =  "oic_svr_db_client.dat";\r
     public static final String OIC_SQL_DB_FILE =  "PDM.db";\r
 \r
     private static final int BUFFER_SIZE = 1024;\r
@@ -235,7 +235,16 @@ public class MainActivity extends Activity {
             @Override\r
             public void onClick(View v) {\r
                 filePath = getFilesDir().getPath() + "/";\r
-                isSecurityEnabled = true;\r
+
+                if (isSecurityEnabled) {\r
+                    isSecurityEnabled = false;\r
+                    mEnableSecurity.setChecked(false);\r
+                }\r
+                else {\r
+                    isSecurityEnabled = true;\r
+                    mEnableSecurity.setChecked(true);\r
+                }\r
+
                 //copy json when application runs first time\r
                 SharedPreferences wmbPreference = PreferenceManager.getDefaultSharedPreferences\r
                         (getApplicationContext());\r
@@ -284,11 +293,13 @@ public class MainActivity extends Activity {
                 "0.0.0.0", // bind to all available interfaces\r
                 0,\r
                 QualityOfService.LOW, filePath + OIC_CLIENT_JSON_DB_FILE);\r
-        OcPlatform.Configure(cfg);\r
         try {\r
             /*\r
              * Initialize DataBase\r
              */\r
+\r
+            OcPlatform.Configure(cfg);\r
+\r
             String sqlDbPath = getFilesDir().getAbsolutePath().replace("files", "databases") +\r
                     File.separator;\r
             File file = new File(sqlDbPath);\r
@@ -304,6 +315,15 @@ public class MainActivity extends Activity {
         } catch (OcException e) {\r
             logMessage(TAG + "provisionInit error: " + e.getMessage());\r
             Log.e(TAG, e.getMessage());\r
+        } catch (UnsatisfiedLinkError e) {\r
+\r
+           // Note : Easy setup is built with SECURED = 0, but user still selects Security feature\r
+           // while running the Mediator App it couldn't find "libocprovision.so".\r
+           // As per the programmer guide, security feature should be invoked only if build is done with SECURED = 1.\r
+            Log.e(TAG, " Easy setup is built with secured  = 0, but executed with security feature");\r
+            Toast.makeText(this,"Security is not enabled [Easy setup is built with SECURED = 0]",\r
+                                                                   Toast.LENGTH_LONG).show();\r
+            mEnableSecurity.setChecked(false);\r
         }\r
     }\r
     /**\r