Modify permissions for files in Things Manager
[platform/upstream/iotivity.git] / service / easy-setup / sdk / mediator / android / EasySetupCore / src / main / java / org / iotivity / service / easysetup / core / EasySetupService.java
index 6707ecf..e0ed145 100755 (executable)
-/**
- * ***************************************************************
- * <p>
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- * <p>
- * <p>
- * <p>
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * <p>
- * ****************************************************************
- */
-
-package org.iotivity.service.easysetup.core;
-
-import android.content.Context;
-
-import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory;
-
-import java.io.IOException;
-import java.util.ArrayList;
-
-/**
- * This is facade class, a single point of contact for Application.
- * It contains set of APIs to do easy setup of the enrolling device.
- * ON-BOARDING - This is a step to establish connectivity between the device & Mediator device.
- * PROVISION   - This is a step where the netowork's detail & credentials are given to the
- * enrolling device.
- */
-public class EasySetupService {
-
-    private static EasySetupService sInstance;
-
-    private final EasySetupStatus mCallback;
-
-    private ArrayList<EnrolleeDevice> mEnrolleeDeviceList;
-
-    private final ProvisioningCallback mProvisioningCallback;
-
-    private static Context mContext;
-
-    public EnrolleeDeviceFactory mDeviceFactory;
-
-
-    private EasySetupService(EasySetupStatus callback) {
-        mCallback = callback;
-        mProvisioningCallback = new ProvisioningCallbackImpl(mCallback);
-        mEnrolleeDeviceList = new ArrayList<EnrolleeDevice>();
-        mContext = null;
-        mDeviceFactory = null;
-    }
-
-    /**
-     * Gives a singleton instance of Easy setup service.
-     *
-     * @param callback Application needs to provide this callback to receive the status of easy
-     *                 setup process.
-     */
-
-    public synchronized static EasySetupService getInstance(Context context, EasySetupStatus
-            callback) {
-        if (sInstance == null) {
-            sInstance = new EasySetupService(callback);
-            mContext = context;
-        }
-        return sInstance;
-    }
-
-    /**
-     * Starts Easy setup process for the enrolling device.
-     *
-     * @param enrolledevice Device to be enrolled in network
-     * @throws IOException Throws exception in case of any connection error.
-     */
-
-    public synchronized void startSetup(final EnrolleeDevice enrolledevice) throws IOException {
-
-        mEnrolleeDeviceList.add(enrolledevice);
-
-        // Starts the provisioning directly if the device is already on boarded on the network.
-        if (enrolledevice.onBoarded()) {
-            enrolledevice.startProvisioning(mProvisioningCallback);
-            return;
-        }
-
-        enrolledevice.startOnBoarding(new OnBoardingCallback() {
-
-            @Override
-            public void onFinished(ConnectionInterface connection) {
-                if (connection.isConnected()) {
-                    try {
-                        Thread.sleep(15000);//Sleep for allowing thin device to start the services
-                    } catch (InterruptedException e) {
-                        e.printStackTrace();
-                    }
-
-                    // Start provisioning here
-                    enrolledevice.setConnection(connection);
-                    enrolledevice.startProvisioning(mProvisioningCallback);
-                } else {
-                    enrolledevice.mState = EnrolleeState.DEVICE_PROVISIONING_FAILED_STATE;
-                    mProvisioningCallback.onFinished(enrolledevice);
-                }
-
-            }
-
-        });
-
-    }
-
-    /**
-     * Stops on-going Easy setup process for enrolling device.
-     *
-     * @param enrolledevice Device to be enrolled in network
-     */
-    public synchronized void stopSetup(EnrolleeDevice enrolledevice) {
-        enrolledevice.stopOnBoardingProcess();
-        mEnrolleeDeviceList.remove(enrolledevice);
-    }
-
-    public synchronized void getEnrolleeDevice(OnBoardingConfig connType) {
-        mDeviceFactory = EnrolleeDeviceFactory.newInstance(mContext);
-    }
-
-    class ProvisioningCallbackImpl extends ProvisioningCallback {
-
-        private final EasySetupStatus mCallback;
-
-        ProvisioningCallbackImpl(EasySetupStatus callback) {
-            mCallback = callback;
-        }
-
-        @Override
-        public void onFinished(EnrolleeDevice enrolledevice) {
-            //if(mEnrolleeDeviceList.contains(enrolledevice)) {
-            mCallback.onFinished(enrolledevice);
-            //}
-        }
-
-    }
-
-
-}
+/**\r
+ * ***************************************************************\r
+ * <p/>\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ * <p/>\r
+ * <p/>\r
+ * <p/>\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * <p/>\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * <p/>\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * <p/>\r
+ * ****************************************************************\r
+ */\r
+\r
+package org.iotivity.service.easysetup.core;\r
+\r
+import android.content.Context;\r
+import android.util.Log;\r
+\r
+import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory;\r
+import org.iotivity.service.easysetup.mediator.EasySetupManager;\r
+import org.iotivity.service.easysetup.mediator.ProvisionEnrollee;\r
+\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+\r
+/**\r
+ * This is facade class, a single point of contact for Application.\r
+ * It contains set of APIs to do easy setup of the enrolling device.\r
+ * ON-BOARDING - This is a step to establish connectivity between the device & Mediator device.\r
+ * PROVISION   - This is a step where the netowork's detail & credentials are given to the\r
+ * enrolling device.\r
+ */\r
+public class EasySetupService {\r
+\r
+    public static String TAG = EasySetupService.class.getName();\r
+\r
+    private static EasySetupService sInstance;\r
+\r
+    private final EasySetupStatus mCallback;\r
+\r
+    private ArrayList<EnrolleeDevice> mEnrolleeDeviceList;\r
+\r
+    private final ProvisioningCallback mProvisioningCallback;\r
+\r
+    private static Context mContext;\r
+\r
+    public EnrolleeDeviceFactory mDeviceFactory;\r
+\r
+    ProvisionEnrollee mProvisionEnrolleeInstance;\r
+\r
+    private EasySetupService(EasySetupStatus callback) {\r
+        mCallback = callback;\r
+        mProvisioningCallback = new ProvisioningCallbackImpl(mCallback);\r
+        mEnrolleeDeviceList = new ArrayList<EnrolleeDevice>();\r
+        mContext = null;\r
+        mDeviceFactory = null;\r
+    }\r
+\r
+    /**\r
+     * Gives a singleton instance of Easy setup service and initialize the service\r
+     *\r
+     * @param callback Application needs to provide this callback to receive the status of easy\r
+     *                 setup process.\r
+     */\r
+\r
+    public synchronized static EasySetupService getInstance(Context context, EasySetupStatus\r
+            callback) {\r
+        if (sInstance == null) {\r
+            sInstance = new EasySetupService(callback);\r
+            mContext = context;\r
+        }\r
+        return sInstance;\r
+    }\r
+\r
+    /**\r
+     * Reset the Easy setup Service\r
+     */\r
+\r
+    public void finish() {\r
+        //Native Api call to reset OIC stack\r
+        if(mProvisionEnrolleeInstance != null)\r
+        {\r
+            mProvisionEnrolleeInstance.stopEnrolleeProvisioning(0);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Starts Easy setup process for the enrolling device.\r
+     *\r
+     * @param enrolledevice Device to be enrolled in network\r
+     * @throws IOException Throws exception in case of any connection error.\r
+     */\r
+\r
+    public synchronized void startSetup(final EnrolleeDevice enrolledevice) throws IOException {\r
+\r
+        mEnrolleeDeviceList.add(enrolledevice);\r
+\r
+        // Starts the provisioning directly if the device is already on boarded on the network.\r
+        if (enrolledevice.onBoarded()) {\r
+            enrolledevice.startProvisioning(mProvisioningCallback);\r
+            return;\r
+        }\r
+\r
+        enrolledevice.startOnBoarding(new OnBoardingCallback() {\r
+\r
+            @Override\r
+            public void onFinished(OnBoardingConnection connection) {\r
+                if (connection.isConnected()) {\r
+                    Log.i(TAG, "On boarding is successful ");\r
+                    try {\r
+                        Log.i(TAG, "waiting for 15 seconds to start provisioning");\r
+                        Thread.sleep(15000);//Sleep for allowing thin device to start the services\r
+                    } catch (InterruptedException e) {\r
+                        e.printStackTrace();\r
+                    }\r
+\r
+                    // Start provisioning here\r
+                    enrolledevice.setConnection(connection);\r
+                    enrolledevice.startProvisioning(mProvisioningCallback);\r
+                } else {\r
+                    enrolledevice.mState = EnrolleeState.DEVICE_PROVISIONING_FAILED_STATE;\r
+                    mProvisioningCallback.onFinished(enrolledevice);\r
+                }\r
+\r
+            }\r
+\r
+        });\r
+\r
+    }\r
+\r
+    /**\r
+     * Stops on-going Easy setup process for enrolling device.\r
+     *\r
+     * @param enrolleedevice Device to be enrolled in network\r
+     */\r
+    public synchronized void stopSetup(EnrolleeDevice enrolleedevice) {\r
+        enrolleedevice.stopOnBoardingProcess();\r
+        mEnrolleeDeviceList.remove(enrolleedevice);\r
+\r
+        //Native Api call to stop on-going enrolling process for the enrolling device\r
+        EasySetupManager.getInstance().stopEnrolleeProvisioning(enrolleedevice.mOnBoardingConfig.getConnType().getValue());\r
+    }\r
+\r
+    public synchronized void getEnrolleeDevice(OnBoardingConfig connType) {\r
+        mDeviceFactory = EnrolleeDeviceFactory.newInstance(mContext);\r
+    }\r
+\r
+    class ProvisioningCallbackImpl extends ProvisioningCallback {\r
+\r
+        private final EasySetupStatus mCallback;\r
+\r
+        ProvisioningCallbackImpl(EasySetupStatus callback) {\r
+            mCallback = callback;\r
+        }\r
+\r
+        @Override\r
+        public void onFinished(EnrolleeDevice enrolledevice) {\r
+            //if(mEnrolleeDeviceList.contains(enrolledevice)) {\r
+            Log.i(TAG, "onFinished() is received " + enrolledevice.isSetupSuccessful());\r
+            mCallback.onFinished(enrolledevice);\r
+            // }\r
+        }\r
+\r
+    }\r
+\r
+\r
+}\r