Imported Upstream version 1.2.0
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / android / EasySetupCore / src / main / java / org / iotivity / service / easysetup / mediator / RemoteEnrollee.java
1 /**
2  * ***************************************************************
3  *
4  * Copyright 2016 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
24 package org.iotivity.service.easysetup.mediator;
25
26 import android.util.Log;
27
28 import org.iotivity.base.OcRepresentation;
29
30 /**
31  * This class represents Remote Enrollee device instance. What operations the class provides:
32  * 1) Ownership transfer for enabling secured communication between Mediator and Enrollee
33  * devices.
34  * 2) Provision WiFi AP information used for which Enrollee is going to connect to the AP
35  * 3) Provision Device confiruation setting, i.e. language, country, and etc
36  * 4) Provision Cloud information used for which Enrollee is going to register to the cloud
37  */
38 public class RemoteEnrollee{
39
40     public static final String TAG = RemoteEnrollee.class.getName();
41     private long m_nativeHandle;
42
43     private native void nativeGetStatus(GetStatusCallback callback);
44     private native void nativeGetConfiguration(GetConfigurationCallback callback);
45     private native void nativeProvisionSecurity(SecurityProvisioningCallback callback);
46     private native void nativeProvisionDeviceProperties(OcRepresentation deviceProp,
47                                                         DevicePropProvisioningCallback callback);
48     private native void nativeProvisionCloudProperties(OcRepresentation cloudProp, String cloudID,
49                                                        int CredID, CloudPropProvisioningCallback callback);
50
51     /* constructor will be invoked from the native layer */
52     private RemoteEnrollee(long nativeHandle){
53         this.m_nativeHandle = nativeHandle;
54     }
55
56     /**
57      * Get an Enrollee's status which includes a provisioning status and last error code
58      *
59      * @param callback will give the requested status
60      *
61      * @throws ESException If some errors happen in this function
62      *
63      * @see GetStatusCallback
64      */
65     public void getStatus(GetStatusCallback callback) throws ESException
66     {
67         if(callback != null)
68         {
69             nativeGetStatus(callback);
70             return;
71         }
72         Log.d(TAG, "GetStatusCallback is null ");
73     }
74
75     /**
76      * Get an Enrollee's configuration which includes WiFi supported frequency and device name
77      *
78      * @param callback will give the requested configuration
79      *
80      * @throws ESException If some errors happen in this function
81      *
82      * @see GetConfigurationCallback
83      */
84     public void getConfiguration(GetConfigurationCallback callback)
85                                                         throws ESException
86     {
87         if(callback != null)
88         {
89             nativeGetConfiguration(callback);
90             return;
91         }
92         Log.d(TAG, "GetConfigurationCallback is null ");
93     }
94
95     /**
96      * Do security provisioning such as ownership tranfer to Enrollee.
97      *
98      * @param callback will give the result if the security provisioning succeeds or fails for some reasons
99      *
100      * @throws ESException If some errors happen in this function
101      *
102      * @see SecurityProvisioningCallback
103      */
104     public void provisionSecurity(SecurityProvisioningCallback callback)
105                                                         throws ESException
106     {
107         if(callback != null)
108         {
109             nativeProvisionSecurity(callback);
110             return;
111         }
112         Log.d(TAG, "SecurityProvisioningCallback is null ");
113     }
114
115     /**
116      * Provision WiFi AP information and device configuration to Enrollee
117      * 1. WiFi AP information includes a SSID, password, auth type, and encryption type.
118      * 2. Device configuration includes a language (IETF language tags) and country (ISO 3166-1 Alpha-2)
119      *
120      * @param deviceProp a data structure storing the above information to be delivered
121      * @param callback will give the result if the provisioning succeeds or fails
122      *
123      * @throws ESException If some errors happen in this function
124      *
125      * @see DeviceProp
126      * @see DevicePropProvisioningCallback
127      */
128     public void provisionDeviceProperties(DeviceProp deviceProp,
129                     DevicePropProvisioningCallback callback) throws ESException{
130         if(callback != null)
131         {
132             nativeProvisionDeviceProperties(deviceProp.toOCRepresentation(),
133                                                 callback);
134             return;
135         }
136         Log.d(TAG, "DevicePropProvisioningCallback is null ");
137     }
138
139     /**
140      * Provision Cloud information to Enrollee, which includes Auth code, auth provider,
141      * Cloud interface server URL, and etc.
142      * In this function, Discovery for the Enrollee will happen again in a given network.
143      * Because, this function is expected to call *AFTER* the Enrollee disconnects its Soft AP
144      * and successfully connects to the certain WiFi AP. In that case, Mediator should discover
145      * the Enrollee with a certain Device ID in the network.
146      *
147      * @param cloudProp a data structure storing the above information to be delivered
148      * @param callback will give the result if the provisioning succeeds or fails
149      *
150      * @throws ESException If some errors happen in this function
151      *
152      * @see CloudProp
153      * @see CloudPropProvisioningCallback
154      */
155     public void provisionCloudProperties(CloudProp cloudProp,
156                     CloudPropProvisioningCallback callback) throws ESException{
157         if(callback != null)
158         {
159             nativeProvisionCloudProperties(cloudProp.toOCRepresentation(),
160                                             cloudProp.getCloudID(),
161                                             cloudProp.getCredID(),
162                                             callback);
163             return;
164         }
165         Log.d(TAG, "CloudPropProvisioningCallback is null ");
166     }
167 }