2 * ***************************************************************
4 * Copyright 2017 Samsung Electronics All Rights Reserved.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 * ****************************************************************
23 package org.iotivity.service.easysetup.mediator;
25 import android.content.Context;
26 import android.util.Log;
28 import org.iotivity.base.OcConnectivityType;
29 import org.iotivity.base.OcResource;
30 import org.iotivity.base.OcPlatform;
32 import java.util.ArrayList;
33 import java.util.EnumSet;
34 import java.util.List;
37 * This provides an API to instanciate a new RemoteEnrollee object correspondent to Enrollee
40 public class EasySetup {
42 private static final String TAG = EasySetup.class.getName();
43 private static EasySetup sInstance;
45 private static Context mContext;
47 private ArrayList<RemoteEnrollee> mRemoteEnrolleeList;
49 protected RemoteEnrollee mRemoteEnrollee;
51 // function to call the native nativeCreateRemoteEnrollee
52 private native RemoteEnrollee nativeCreateRemoteEnrollee(OcResource enrolleeResource);
54 // Load Easy Setup JNI interface
57 System.loadLibrary("ocprovision");
58 } catch (UnsatisfiedLinkError e) {
59 Log.i(TAG, "ocprovision library does not exist. (Unsecure mode)");
62 System.loadLibrary("ocstack-jni");
63 System.loadLibrary("ESMediatorRich");
64 System.loadLibrary("easysetup-jni");
68 mRemoteEnrolleeList = new ArrayList<RemoteEnrollee>();
73 * Gives a singleton instance of Easy setup and initialize the easy setup
75 public synchronized static EasySetup getInstance(Context context) {
76 if (sInstance == null) {
77 sInstance = new EasySetup();
84 * This API is used for creating a remote Enrollee instance
86 * @param enrolleeResource an OCResource object corresponding to enrollee resource
87 * discovered in a network. The OcResource object can be obtained by calling
88 * OcPlatform.findResource() API. What resource you have to discover with
89 * the OcPlatform.findResource() API is a "provisioning" resource with a certain
90 * resource type, i.e. oic.wk.prov
92 * @return Pointer to RemoteEnrollee instance
94 public synchronized RemoteEnrollee createRemoteEnrollee(OcResource enrolleeResource)
96 mRemoteEnrollee = nativeCreateRemoteEnrollee(enrolleeResource);
98 if(mRemoteEnrollee != null)
100 mRemoteEnrolleeList.add(mRemoteEnrollee);
101 return mRemoteEnrollee;