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 public static final String PROV_RESOURCE_TYPE = "ocf.wk.prov";
44 private static EasySetup sInstance;
46 private static Context mContext;
48 private ArrayList<RemoteEnrollee> mRemoteEnrolleeList;
50 protected RemoteEnrollee mRemoteEnrollee;
52 // function to call the native nativeCreateRemoteEnrollee
53 private native RemoteEnrollee nativeCreateRemoteEnrollee(OcResource enrolleeResource);
55 // Load Easy Setup JNI interface
58 System.loadLibrary("ocprovision");
59 } catch (UnsatisfiedLinkError e) {
60 Log.i(TAG, "ocprovision library does not exist. (Unsecure mode)");
63 System.loadLibrary("ocstack-jni");
64 System.loadLibrary("ESMediatorRich");
65 System.loadLibrary("easysetup-jni");
69 mRemoteEnrolleeList = new ArrayList<RemoteEnrollee>();
74 * Gives a singleton instance of Easy setup and initialize the easy setup
76 public synchronized static EasySetup getInstance(Context context) {
77 if (sInstance == null) {
78 sInstance = new EasySetup();
85 * This API is used for creating a remote Enrollee instance
87 * @param enrolleeResource an OCResource object corresponding to enrollee resource
88 * discovered in a network. The OcResource object can be obtained by calling
89 * OcPlatform.findResource() API. What resource you have to discover with
90 * the OcPlatform.findResource() API is a "provisioning" resource with a certain
91 * resource type, i.e. ocf.wk.prov
93 * @return Pointer to RemoteEnrollee instance
95 public synchronized RemoteEnrollee createRemoteEnrollee(OcResource enrolleeResource)
98 if(!enrolleeResource.getResourceTypes().contains(PROV_RESOURCE_TYPE)
99 || !enrolleeResource.getResourceInterfaces().contains(OcPlatform.BATCH_INTERFACE))
101 Log.e(TAG, "Validation check for OcResource is failed.");
104 mRemoteEnrollee = nativeCreateRemoteEnrollee(enrolleeResource);
105 mRemoteEnrolleeList.add(mRemoteEnrollee);
106 return mRemoteEnrollee;