Add EasySetup class and Update RemoteEnrollee class for Android Mediator
[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  * This is facade class, a single point of contact for Application.
33  * It contains set of APIs to do easy setup of the enrolling device.
34  * ON-BOARDING - This is a step to establish connectivity between the device & Mediator device.
35  * PROVISION   - This is a step where the netowork's detail & credentials are given to the
36  * enrolling device.
37  */
38 public class EasySetup {
39
40     private static final String TAG = EasySetup.class.getName();
41
42     private static EasySetup sInstance;
43
44     //private final EasySetupStatus mCallback;
45
46     //private ArrayList<EnrolleeDevice> mEnrolleeDeviceList;
47
48     //private final ProvisioningCallback mProvisioningCallback;
49
50     private static Context mContext;
51
52         private ArrayList<RemoteEnrollee> mRemoteEnrolleeList;
53
54     protected RemoteEnrollee mRemoteEnrollee;
55
56     //function to call the native createEnrolleeDevice
57     private native RemoteEnrollee nativeCreateRemoteEnrollee();
58
59     static {
60         // Load Easy Setup JNI interface
61         System.loadLibrary("ESMediatorRich");
62         System.loadLibrary("easysetup-jni");
63     }
64
65     private EasySetup() {
66         //mCallback = callback;
67         //mProvisioningCallback = new ProvisioningCallbackImpl(mCallback);
68         //mEnrolleeDeviceList = new ArrayList<EnrolleeDevice>();
69         mContext = null;
70     }
71
72     /**
73      * Gives a singleton instance of Easy setup service and initialize the service
74      *
75      * @param callback Application needs to provide this callback to receive the status of easy
76      *                 setup process.
77      */
78
79     public synchronized static EasySetup getInstance(Context context) {
80         if (sInstance == null) {
81             sInstance = new EasySetup();
82             mContext = context;
83         }
84         return sInstance;
85     }
86
87         public synchronized RemoteEnrollee createRemoteEnrollee()
88         {
89                 // native call
90                 mRemoteEnrollee = nativeCreateRemoteEnrollee();
91
92                 mRemoteEnrolleeList.add(mRemoteEnrollee);
93
94         return mRemoteEnrollee;
95         }
96
97     /**
98      * Reset the Easy setup Service
99      */
100
101     public void finish() {
102             //Call the stop Provisioning
103             //for (EnrolleeDevice enrolleeDevice : mEnrolleeDeviceList) {
104             //    enrolleeDevice.stopProvisioningProcess();
105         //}
106     }   
107 }