replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / android / android_api / base / src / main / java / org / iotivity / base / OcProvisioning.java
1 /*
2  *******************************************************************
3  *
4  * Copyright 2015 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 package org.iotivity.base;
24
25 import java.util.List;
26 import java.util.Arrays;
27 import java.util.Map;
28 import java.util.EnumSet;
29
30 /**
31  * OcProvisionig represents functions corresponding to the provisioing of
32  * resources.
33  */
34 public class OcProvisioning {
35
36     /**
37      * Method to Intialize Provisioning Manager.This will load the provisioning
38      * Manager's persistent database.
39      *
40      * @param dbPath     dbPath file path of the sqlite3 db.
41      * @throws OcException
42      */
43     public static native void provisionInit(String dbPath) throws OcException;
44
45     /**
46      * Method to Discover un-owned devices in its subnet.Un-owned devices need
47      * to be owned by calling ownershipTransferCBdata.
48      *
49      * @param timeout     Timeout in sec.Time to listen for responses before
50      *                    returining the Array.
51      * @return            Array of OcSecureResource class objects.
52      * @throws OcException
53      */
54     public  static List<OcSecureResource> discoverUnownedDevices(int timeout) throws OcException {
55         return Arrays.asList(OcProvisioning.discoverUnownedDevices1(timeout));
56     }
57     private static native OcSecureResource[] discoverUnownedDevices1(int timeout) throws OcException;
58
59     /**
60      * Method to Discover owned devices in its subnet.
61      *
62      * @param timeout     Timeout in sec.Time to listen for responses before
63      *                    returining the Array.
64      * @return            Array of OcSecureResource class objects.
65      * @throws OcException
66      */
67     public static List<OcSecureResource> discoverOwnedDevices(int timeout) throws OcException {
68         return Arrays.asList(OcProvisioning.discoverOwnedDevices1(timeout));
69     }
70     private static native OcSecureResource[] discoverOwnedDevices1(int timeout) throws OcException;
71
72     /**
73      *  API for registering Ownership transfer methods for a particular
74      *  transfer Type
75      *
76      * @param type     OxmType ownership transfer type.
77      * @throws OcException
78      */
79     public static void SetownershipTransferCBdata(OxmType type,
80             PinCallbackListener pinCallbackListener) throws OcException
81     {
82         OcProvisioning.ownershipTransferCBdata(type.getValue(), pinCallbackListener);
83     }
84
85     private  static native void ownershipTransferCBdata(int oxmType,  PinCallbackListener pinCallbackListener);
86
87     public static interface PinCallbackListener {
88         public String pinCallbackListener();
89     }
90
91     /**
92      * Server API to set Callback for Displaying stack generated PIN.
93      *
94      * @param DisplayPinListener Pin callback Listener to be registered.
95      * @throws OcException
96      */
97     public static native void setDisplayPinListener(DisplayPinListener displayPinListener)
98         throws OcException;
99
100     public static interface DisplayPinListener {
101         public void displayPinListener(String Pin);
102     }
103
104     /**
105      * API to Set callback for displaying verifNum in verified Just-Works.
106      *
107      *@param DisplayNumListener callback Listener to be registered for
108                                             displaying VerifyNUm.
109      *@throws OcException
110      */
111     public static native void setDisplayNumListener(
112             DisplayNumListener displayNumListener) throws OcException;
113
114     public static interface DisplayNumListener {
115         public int displayNumListener(String verifyNum);
116     }
117
118     /**
119      * API to unregister DisplayNumListener Listener
120      *
121      *@return  0 on success, 1 on failure
122      *@throws OcException
123      */
124     public static native int unsetDisplayNumListener() throws OcException;
125
126     /**
127      * API to Set callback for getting user confirmation in verified
128      * Just-Works
129      *
130      *@param ConfirmNumListener callback Listener to be registered for getting user confirmation.
131      *@throws OcException
132      */
133     public static native void setConfirmNumListener(ConfirmNumListener
134             confirmNumListener) throws OcException;
135
136     public static interface ConfirmNumListener {
137         public int confirmNumListener();
138     }
139
140     /**
141      * API to unregister ConfirmMutualVerifyNum Listener
142      *
143      *@return  0 on success, 1 on failure
144      *@throws OcException
145      */
146     public static native int unsetConfirmNumListener() throws OcException;
147
148     /**
149      * API to set options for Mutual Verified Just-works
150      * Default is  for both screen PIN display and get user confirmation.
151      *
152      */
153     public static int setMVJustWorksOptions(EnumSet<MVJustWorksOptionMask> optionMask) throws OcException {
154
155         int optionMaskInt = 0;
156
157         for (MVJustWorksOptionMask ops : MVJustWorksOptionMask.values()) {
158             if (optionMask.contains(ops))
159                 optionMaskInt |= ops.getValue();
160         }
161         return setMVJustWorksOptions0(optionMaskInt);
162     }
163
164     private static native int setMVJustWorksOptions0(int optionsMask) throws OcException;
165
166     /**
167      * Method to get Array of owned and un-owned devices in the current subnet.
168      *
169      * @param timeout    timeout in sec for the API to return.
170      * @retrun           Array of OcSecureResource class objects.
171      *                   be provisioned.
172      * @throws OcException
173      */
174     public static List<OcSecureResource> getDeviceStatusList(int timeout) throws OcException {
175         return Arrays.asList(OcProvisioning.getDeviceStatusList1(timeout));
176     }
177     private static native OcSecureResource[] getDeviceStatusList1(int timeout) throws OcException;
178
179     /**
180      *  Method to save the Trust certificate chain to SVR.
181      *
182      *  @param byte[]            trustCertChain
183      *  @param EncodingType                          encodingType
184      *  @throws OcException
185      */
186     public static int saveTrustCertChain(byte[] trustCertChain, EncodingType encodingType) throws OcException {
187         return saveTrustCertChain1(trustCertChain,encodingType.getValue());
188     }
189     private static native int saveTrustCertChain1(byte[] trustCertChain, int encodingType)
190         throws OcException;
191
192     /**
193      *  Method to save pin type.
194      *
195      *  @param pinSize Byte Len of Random pin.
196      *  @param pinType Enumset of pin, see PinType for enums
197      *  @throws OcException
198      */
199     public static int setPinType(int pinSize, EnumSet<PinType>  pinType) throws OcException {
200
201         int pinTypeInt = 0;
202
203         for (PinType ops : PinType.values()) {
204             if (pinType.contains(ops))
205                 pinTypeInt |= ops.getValue();
206         }
207         return setPinType0(pinSize, pinTypeInt);
208     }
209     private static native int setPinType0(int pinSize, int pinType) throws OcException;
210
211     /**
212      *  Method to save the seed value to generate device UUID
213      *
214      *  @param seed   buffer of seed value
215      *  @throws OcException
216      */
217     public static int setDeviceIdSeed(byte[] seed) throws OcException {
218         return setDeviceIdSeed1(seed);
219     }
220     private static native int setDeviceIdSeed1(byte[] seed)
221         throws OcException;
222     
223     /**
224      * API to save ACL, having multiple ACE's
225      *
226      *@param acl object
227      *@throws OcException
228      */
229     public static native void saveACL(Object acl) throws OcException;
230
231     /**
232      * API to do self ownership transfer.
233      *
234      *@throws OcException
235      */
236     public static native void doSelfOwnershiptransfer() throws OcException;
237 }