* ***************************************************************
*
* Copyright 2017 Samsung Electronics All Rights Reserved.
- *
+ *
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
import android.content.Context;
import android.util.Log;
-import java.io.IOException;
+import org.iotivity.base.OcConnectivityType;
+import org.iotivity.base.OcResource;
+import org.iotivity.base.OcPlatform;
+
import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.List;
/**
- * 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.
+ * This provides an API to instanciate a new RemoteEnrollee object correspondent to Enrollee
+ * Device to be setup.
*/
public class EasySetup {
private static final String TAG = EasySetup.class.getName();
-
private static EasySetup sInstance;
- //private final EasySetupStatus mCallback;
-
- //private ArrayList<EnrolleeDevice> mEnrolleeDeviceList;
-
- //private final ProvisioningCallback mProvisioningCallback;
-
private static Context mContext;
- private ArrayList<RemoteEnrollee> mRemoteEnrolleeList;
+ private ArrayList<RemoteEnrollee> mRemoteEnrolleeList;
protected RemoteEnrollee mRemoteEnrollee;
- //function to call the native createEnrolleeDevice
- private native RemoteEnrollee nativeCreateRemoteEnrollee();
-
+ // function to call the native nativeCreateRemoteEnrollee
+ private native RemoteEnrollee nativeCreateRemoteEnrollee(OcResource enrolleeResource);
static {
// Load Easy Setup JNI interface
+ try
+ {
+ System.loadLibrary("ocprovision");
+ } catch (UnsatisfiedLinkError e) {
+ Log.i(TAG, "ocprovision library does not exist. (Unsecure mode)");
+ }
+
+ System.loadLibrary("ocstack-jni");
System.loadLibrary("ESMediatorRich");
System.loadLibrary("easysetup-jni");
}
private EasySetup() {
- //mCallback = callback;
- //mProvisioningCallback = new ProvisioningCallbackImpl(mCallback);
- //mEnrolleeDeviceList = new ArrayList<EnrolleeDevice>();
+ mRemoteEnrolleeList = new ArrayList<RemoteEnrollee>();
mContext = null;
}
/**
- * Gives a singleton instance of Easy setup service and initialize the service
- *
- * @param callback Application needs to provide this callback to receive the status of easy
- * setup process.
+ * Gives a singleton instance of Easy setup and initialize the easy setup
*/
-
public synchronized static EasySetup getInstance(Context context) {
if (sInstance == null) {
sInstance = new EasySetup();
return sInstance;
}
- public synchronized RemoteEnrollee createRemoteEnrollee()
- {
- // native call
- mRemoteEnrollee = nativeCreateRemoteEnrollee();
-
- mRemoteEnrolleeList.add(mRemoteEnrollee);
-
- return mRemoteEnrollee;
- }
-
- /**
- * Reset the Easy setup Service
+ /**
+ * This API is used for creating a remote Enrollee instance
+ *
+ * @param enrolleeResource an OCResource object corresponding to enrollee resource
+ * discovered in a network. The OcResource object can be obtained by calling
+ * OcPlatform.findResource() API. What resource you have to discover with
+ * the OcPlatform.findResource() API is a "provisioning" resource with a certain
+ * resource type, i.e. oic.r.easysetup
+ *
+ * @return Pointer to RemoteEnrollee instance
*/
-
- public void finish() {
- //Call the stop Provisioning
- //for (EnrolleeDevice enrolleeDevice : mEnrolleeDeviceList) {
- // enrolleeDevice.stopProvisioningProcess();
- //}
- }
+ public synchronized RemoteEnrollee createRemoteEnrollee(OcResource enrolleeResource)
+ {
+ mRemoteEnrollee = nativeCreateRemoteEnrollee(enrolleeResource);
+
+ if(mRemoteEnrollee != null)
+ {
+ mRemoteEnrolleeList.add(mRemoteEnrollee);
+ return mRemoteEnrollee;
+ }
+ return null;
+ }
}