Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / easy-setup / mediator / richsdk / android / EasySetupCore / src / main / java / org / iotivity / service / easysetup / mediator / EnrolleeDevice.java
1 /**
2  * ***************************************************************
3  * <p/>
4  * Copyright 2015 Samsung Electronics All Rights Reserved.
5  * <p/>
6  * <p/>
7  * <p/>
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  * <p/>
12  * http://www.apache.org/licenses/LICENSE-2.0
13  * <p/>
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  * <p/>
20  * ****************************************************************
21  */
22
23 package org.iotivity.service.easysetup.mediator;
24
25 /**
26  * This is an abstract class represents the device being provisioned into the network. The
27  * device being enrolled or provisioned into the network is called Enrollee.
28  * Application has to extend this class and provide implementation of abstract methods according
29  * to the ON-BOARDING & PROVISION connectivity i.e. WiFi etc.
30  */
31
32 public abstract class EnrolleeDevice {
33
34     protected EnrolleeState mState;
35     private EnrolleeSetupError mError;
36
37     OnBoardingConnection mConnection;
38     final ProvisioningConfig mProvConfig;
39     final OnBoardingConfig mOnBoardingConfig;
40
41     protected OnBoardingCallback mOnBoardingCallback;
42     protected ProvisioningCallback mProvisioningCallback;
43     protected RemoteEnrollee mRemoteEnrollee;
44
45     /**
46      * @param onBoardingConfig Contains details about the connectivity to be established between
47      *                         the Enrollee device & Mediator device in order to perform
48      *                         on-boarding
49      * @param provConfig       Contains details about the network to which Enrollee device is
50      *                         going to connect.
51      */
52     protected EnrolleeDevice(OnBoardingConfig onBoardingConfig, ProvisioningConfig provConfig) {
53         mProvConfig = provConfig;
54         mOnBoardingConfig = onBoardingConfig;
55     }
56
57     /**
58      * Application has to implement it according to the on boarding connectivity the device is
59      * having.
60      * This method will be called back during the easy setup process.
61      */
62     protected abstract void startOnBoardingProcess();
63
64     /**
65      * This method is called back during the easy setup process if Application cancels the setup.
66      * Easy setup service checks the state of device and calls this function accordingly.
67      * Application has to provide implementation for this method to cancel the on boarding step.
68      */
69     protected abstract void stopOnBoardingProcess();
70
71     /**
72      * Application has to implement it according to the type of the network device is going to
73      * connect or provisioned.
74      * This method will be called back once on-boarding of the device is successful.
75      *
76      * @param conn Contains detail about the network established between the Enrollee device &
77      *             Mediator device. Its implementation vary according to the connectivity type.
78      */
79     protected abstract void startProvisioningProcess(OnBoardingConnection conn);
80
81     /**
82      * Application has to implement it according to the type of the network device is going to
83      * connect or provisioned.
84      * This method will stop the provisioning process if it is in progress
85      *
86      */
87     protected abstract void stopProvisioningProcess();
88
89     /**
90      * Once on boarding is successful concrete Enrollee class would call this method and set the
91      * Connection.
92      *
93      * @param conn Connectivity between Enrollee device & Mediator device.
94      */
95     protected void setConnection(OnBoardingConnection conn) {
96         mConnection = conn;
97     }
98
99     /**
100      * This method returns the OnBoardingConnection object depending on the connection type
101      *
102      * @return onBoardingConnection object
103      */
104     public OnBoardingConnection getConnection() {
105         return mConnection;
106     }
107
108
109     /**
110      * This method is called back by Easy setup service if on boarding needs to be done.
111      *
112      * @param onBoardingCallback This is called back once the on boarding is completed.
113      */
114     void startOnBoarding(OnBoardingCallback onBoardingCallback) {
115         mOnBoardingCallback = onBoardingCallback;
116         startOnBoardingProcess();
117     }
118
119     /**
120      * This method is called back by Easy setup service once on boarding is successful
121      *
122      * @param provisioningCallback This is called back once the provisioning process is completed
123      */
124     void startProvisioning(ProvisioningCallback provisioningCallback) {
125         mProvisioningCallback = provisioningCallback;
126         startProvisioningProcess(mConnection);
127     }
128
129     /**
130      * This method is used to check easy setup status
131      *
132      * @return true if successful or false
133      */
134
135     public boolean isSetupSuccessful() {
136         return (mState == EnrolleeState.DEVICE_PROVISIONED_STATE) ? true : false;
137     }
138
139     /**
140      * sets error occured during easy setup process
141      */
142     protected void setError(EnrolleeSetupError error) {
143         mError = error;
144     }
145
146     /**
147      * Returns error occured during easy setup process
148      *
149      * @return True EnrolleeSetupError object
150      */
151     public EnrolleeSetupError getError() {
152         return mError;
153     }
154
155     /**
156      * Gives the state of the device being enrolled during the easy setup process.
157      *
158      * @return Returns EnrolleeState object
159      */
160     public EnrolleeState getState() {
161         return mState;
162     }
163
164     /**
165      * This method is used to know if the device is on boarded or not
166      *
167      * @return True if on-boarded successfully or False
168      */
169
170     protected boolean onBoarded() {
171         return (mState == EnrolleeState.DEVICE_ON_BOARDED_STATE) ? true : false;
172     }
173 }