Merge branch 'master' into extended-easysetup
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / android / EasySetupCore / src / main / java / org / iotivity / service / easysetup / mediator / EasySetup.java
1 /**
2  * ***************************************************************
3  *
4  * Copyright 2017 Samsung Electronics All Rights Reserved.
5  * 
6  *
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  * ****************************************************************
21  */
22
23 package org.iotivity.service.easysetup.mediator;
24
25 import android.content.Context;
26 import android.util.Log;
27
28 import java.io.IOException;
29 import java.util.ArrayList;
30
31 /**
32  * <To be modified>
33  * This is facade class, a single point of contact for Application.
34  * It contains set of APIs to do easy setup of the enrolling device.
35  * ON-BOARDING - This is a step to establish connectivity between the device & Mediator device.
36  * PROVISION   - This is a step where the netowork's detail & credentials are given to the
37  * enrolling device.
38  */
39 public class EasySetup {
40
41     private static final String TAG = EasySetup.class.getName();
42
43     private static EasySetup sInstance;
44
45     private static Context mContext;
46
47     private ArrayList<RemoteEnrollee> mRemoteEnrolleeList;
48
49     protected RemoteEnrollee mRemoteEnrollee;
50
51     //function to call the native nativeCreateRemoteEnrollee
52     private native RemoteEnrollee nativeCreateRemoteEnrollee();
53
54     static {
55         // Load Easy Setup JNI interface
56         System.loadLibrary("ESMediatorRich");
57         System.loadLibrary("easysetup-jni");
58     }
59
60     private EasySetup() {
61         mRemoteEnrolleeList = new ArrayList<RemoteEnrollee>();
62         mContext = null;
63     }
64
65     /**
66      * Gives a singleton instance of Easy setup and initialize the easy setup
67      */
68     public synchronized static EasySetup getInstance(Context context) {
69         if (sInstance == null) {
70             sInstance = new EasySetup();
71             mContext = context;
72         }
73         return sInstance;
74     }
75
76     /**
77      * API to create a new RemoteEnrollee instance
78      */
79     public synchronized RemoteEnrollee createRemoteEnrollee()
80     {
81         // native call
82         mRemoteEnrollee = nativeCreateRemoteEnrollee();
83         mRemoteEnrolleeList.add(mRemoteEnrollee);
84         return mRemoteEnrollee;
85     }
86
87     /**
88      * Reset the Easy setup
89      */
90     public void finish() {
91         //Call the stop Provisioning
92         //for (RemoteEnrollee remoteEnrollee : mRemoteEnrolleeList)
93         //    remoteEnrollee.stopProvisioningProcess();
94         }
95 }