Modify permissions for files in Things Manager
[platform/upstream/iotivity.git] / service / easy-setup / sdk / mediator / android / EasySetupCore / src / main / java / org / iotivity / service / easysetup / core / EnrolleeDevice.java
1 /**\r
2  * ***************************************************************\r
3  * <p/>\r
4  * Copyright 2015 Samsung Electronics All Rights Reserved.\r
5  * <p/>\r
6  * <p/>\r
7  * <p/>\r
8  * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * you may not use this file except in compliance with the License.\r
10  * You may obtain a copy of the License at\r
11  * <p/>\r
12  * http://www.apache.org/licenses/LICENSE-2.0\r
13  * <p/>\r
14  * Unless required by applicable law or agreed to in writing, software\r
15  * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * See the License for the specific language governing permissions and\r
18  * limitations under the License.\r
19  * <p/>\r
20  * ****************************************************************\r
21  */\r
22 \r
23 package org.iotivity.service.easysetup.core;\r
24 \r
25 /**\r
26  * This is an abstract class represents the device being provisioned into the network. The\r
27  * device being enrolled or provisioned into the network is called Enrollee.\r
28  * Application has to extend this class and provide implementation of abstract methods according\r
29  * to the ON-BOARDING & PROVISION connectivity i.e. WiFi, BLE, BT etc. the device is having.\r
30  */\r
31 \r
32 public abstract class EnrolleeDevice {\r
33 \r
34     protected EnrolleeState mState;\r
35     private EnrolleeSetupError mError;\r
36 \r
37     protected OnBoardingConnection mConnection;\r
38     protected final ProvisioningConfig mProvConfig;\r
39     protected final OnBoardingConfig mOnBoardingConfig;\r
40 \r
41     protected OnBoardingCallback mOnBoardingCallback;\r
42     protected ProvisioningCallback mProvisioningCallback;\r
43 \r
44     /**\r
45      * @param onBoardingConfig Contains details about the connectivity to be established between\r
46      *                         the Enrollee device & Mediator device in order to perform\r
47      *                         on-boarding\r
48      * @param provConfig       Contains details about the network to which Enrollee device is\r
49      *                         going to connect.\r
50      */\r
51     protected EnrolleeDevice(OnBoardingConfig onBoardingConfig, ProvisioningConfig provConfig) {\r
52         mProvConfig = provConfig;\r
53         mOnBoardingConfig = onBoardingConfig;\r
54     }\r
55 \r
56     /**\r
57      * Application has to implement it according to the on boarding connectivity the device is\r
58      * having.\r
59      * This method will be called back during the easy setup process.\r
60      */\r
61     protected abstract void startOnBoardingProcess();\r
62 \r
63     /**\r
64      * This method is called back during the easy setup process if Application cancels the setup.\r
65      * Easy setup service checks the state of device and calls this function accordingly.\r
66      * Application has to provide implementation for this method to cancel the on boarding step.\r
67      */\r
68     protected abstract void stopOnBoardingProcess();\r
69 \r
70     /**\r
71      * Application has to implement it according to the type of the network device is going to\r
72      * connect or provisioned.\r
73      * This method will be called back once on-boarding of the device is successful.\r
74      *\r
75      * @param conn Contains detail about the network established between the Enrollee device &\r
76      *             Mediator device. Its implementation vary according to the connectivity type.\r
77      */\r
78     protected abstract void startProvisioningProcess(OnBoardingConnection conn);\r
79 \r
80     /**\r
81      * Once on boarding is successful concrete Enrollee class would call this method and set the\r
82      * Connection.\r
83      *\r
84      * @param conn Connectivity between Enrollee device & Mediator device.\r
85      */\r
86     public void setConnection(OnBoardingConnection conn) {\r
87         mConnection = conn;\r
88     }\r
89 \r
90     public OnBoardingConnection getConnection() { return mConnection;}\r
91 \r
92 \r
93     /**\r
94      * This method is called back by Easy setup service if on boarding needs to be done.\r
95      *\r
96      * @param onBoardingCallback This is called back once the on boarding is completed.\r
97      */\r
98     void startOnBoarding(OnBoardingCallback onBoardingCallback) {\r
99         mOnBoardingCallback = onBoardingCallback;\r
100         startOnBoardingProcess();\r
101     }\r
102 \r
103     /**\r
104      * This method is called back by Easy setup service once on boarding is successful\r
105      *\r
106      * @param provisioningCallback This is called back once the provisioning process is completed\r
107      */\r
108     void startProvisioning(ProvisioningCallback provisioningCallback) {\r
109         mProvisioningCallback = provisioningCallback;\r
110         startProvisioningProcess(mConnection);\r
111     }\r
112 \r
113     /**\r
114      * This method is used to check easy setup status\r
115      *\r
116      * @return true if successful or false\r
117      */\r
118 \r
119     public boolean isSetupSuccessful() {\r
120         return (mState == EnrolleeState.DEVICE_PROVISIONING_SUCCESS_STATE) ? true : false;\r
121     }\r
122 \r
123     /**\r
124      * Returns error occured during easy setup process\r
125      *\r
126      * @return True EnrolleeSetupError object\r
127      */\r
128     public EnrolleeSetupError getError() {\r
129         return mError;\r
130     }\r
131 \r
132     /**\r
133      * Gives the state of the device being enrolled during the easy setup process.\r
134      *\r
135      * @return Returns EnrolleeState object\r
136      */\r
137     public EnrolleeState getState() {\r
138         return mState;\r
139     }\r
140 \r
141     /**\r
142      * This method is used to know if the device is on boarded or not\r
143      *\r
144      * @return True if on-boarded successfully or False\r
145      */\r
146 \r
147     public boolean onBoarded() {\r
148         return (mState == EnrolleeState.DEVICE_PROVISIONING_STATE) ? true : false;\r
149     }\r
150 \r
151 \r
152 \r
153 }\r