Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / android / android_api / base / src / main / java / org / iotivity / base / OcSecureResource.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.EnumSet;
27 import java.util.Map;
28
29 public class OcSecureResource {
30
31     private OcSecureResource(long nativeHandle) {
32         this.mNativeHandle = nativeHandle;
33     }
34
35     /**
36      *  Method to Start Ownership Transfer of an un-owned device.
37      *
38      *  @param DoOwnershipTransferListener  Callback function, which will be called after
39      *                                      completion of ownership Transfer.
40      *  @throws OcException
41      */
42     public native void doOwnershipTransfer(DoOwnershipTransferListener doOwnershipTransferListener)
43         throws OcException;
44
45     /**
46      *  Method removes device credential from all devices in subnet
47      *
48      *  @param timeout
49      *  @param RemoveDeviceListener         Callback function, which will be called after
50      *                                      completion of removing device.
51      *  @throws OcException
52      */
53     public native void removeDevice(int timeout,  RemoveDeviceListener removeDeviceListener)
54         throws OcException;
55
56     /**
57      *  Method removes the credential & relationship between the two devices.
58      *
59      *  @param jobject                      Second device
60      *  @param UnlinkDevicesListener        Callback function, which will be called after
61      *                                      completion of removing device.
62      *  @throws OcException
63      */
64     public native void unlinkDevices(Object device2, UnlinkDevicesListener unlinkDevicesListener)
65         throws OcException;
66
67     /**
68      *  Method removes the credential & relationship between the two devices.
69      *
70      *  @param EnumSet<CredType>            OR'ed Cred Types
71      *  @param KeySize                          keySize
72      *  @param Object                       Second device
73      *  @param ProvisionCredentialsListener Callback function, which will be called after
74      *                                      completion of removing device.
75      *  @throws OcException
76      */
77     public void provisionCredentials(EnumSet<CredType> credTypeSet, KeySize keysize, Object device2,
78             ProvisionCredentialsListener provisionCredentialsListener) throws OcException {
79         int credTypeInt = 0;
80
81         for (CredType credType : CredType.values()) {
82             if (credTypeSet.contains(credType))
83                 credTypeInt |= credType.getValue();
84         }
85         this.provisionCredentials1(credTypeInt, keysize.getValue(),
86                 device2, provisionCredentialsListener);
87     }
88     private native void provisionCredentials1(int type, int keySize, Object device2,
89             ProvisionCredentialsListener provisionCredentialsListener)
90         throws OcException;
91
92     /**
93      *  Method send ACL information to resource.
94      *
95      *  @param jobject                      Acl
96      *  @param ProvisionAclListener         Callback function, which will be called after
97      *                                      completion of removing device.
98      *  @throws OcException
99      */
100     public native void provisionACL(Object acl, ProvisionAclListener provisionACLListener)
101         throws OcException;
102
103
104     /**
105      *  Method provisions credentials between two devices and ACLs for the devices who
106      *  act as a server.
107      *
108      *  @param EnumSet<CredType>            OR'ed Cred Types
109      *  @param KeySize                      keySize
110      *  @param Object                       First acl
111      *  @param Object                       Second device
112      *  @param Object                       Second acl
113      *  @param ProvisionPairwiseDevicesListener Callback function, which will be called after
114      *                                      completion of removing device.
115      *  @throws OcException
116      */
117     public void provisionPairwiseDevices(EnumSet<CredType> credTypeSet, KeySize keysize, Object acl1,
118             Object device2, Object acl2,
119             ProvisionPairwiseDevicesListener provisionPairwiseDevicesListener) throws OcException {
120         int credTypeInt = 0;
121
122         for (CredType credType : CredType.values()) {
123             if (credTypeSet.contains(credType))
124                 credTypeInt |= credType.getValue();
125         }
126         this.provisionPairwiseDevices1(credTypeInt, keysize.getValue(), acl1, device2,
127                 acl2, provisionPairwiseDevicesListener);
128     }
129     private native void provisionPairwiseDevices1(int type, int keySize, Object acl1,
130             Object device2, Object acl2,
131             ProvisionPairwiseDevicesListener provisionPairwiseDevicesListener) throws OcException;
132
133     /**
134      * doOwnershipTransferListener can be registered with doOwnershipTransfer
135      * call.
136      * Listener notified asynchronously.
137      */
138     public interface DoOwnershipTransferListener {
139         public void doOwnershipTransferListener(List<ProvisionResult> provisionResultList,
140                 int hasError);
141     }
142
143     /**
144      * removeDeviceListener can be registered with removeDeviceListener
145      * call.
146      * Listener notified asynchronously.
147      */
148     public interface RemoveDeviceListener {
149         public void removeDeviceListener(List<ProvisionResult> provisionResultList,
150                 int hasError);
151     }
152
153     /**
154      * unlinkDevicesListener can be registered with unlinkDevicesListener
155      * call.
156      * Listener notified asynchronously.
157      */
158     public interface UnlinkDevicesListener {
159         public void unlinkDevicesListener(List<ProvisionResult> provisionResultList,
160                 int hasError);
161     }
162
163     /**
164      * provisionCredentialsListener can be registered with provisionCredentialsListener
165      * call.
166      * Listener notified asynchronously.
167      */
168     public interface ProvisionCredentialsListener {
169         public void provisionCredentialsListener(List<ProvisionResult> provisionResultList,
170                 int hasError);
171     }
172
173     /**
174      * provisionAclListener can be registered with provisionAclListener
175      * call.
176      * Listener notified asynchronously.
177      */
178     public interface ProvisionAclListener {
179         public void provisionAclListener(List<ProvisionResult> provisionResultList,
180                 int hasError);
181     }
182
183     /**
184      * provisionPairwiseDevicesListener can be registered with provisionPairwiseDevicesListener
185      * call.
186      * Listener notified asynchronously.
187      */
188     public interface ProvisionPairwiseDevicesListener {
189         public void provisionPairwiseDevicesListener(List<ProvisionResult> provisionResultList,
190                 int hasError);
191     }
192
193     /** Method to get List of device ID of devices linked with invoking device.
194      *
195      *  @return Sring List  List of device id's of linked devices.
196      */
197      public native List<String> getLinkedDevices();
198
199      /**
200       * Method to get IP address of sercure discovered device.
201       * @return Stringified IP address.
202       */
203     public native String getIpAddr();
204
205     /**
206      * Method to get device id of a device.
207      * @return  Device ID of the selected device.
208      */
209     public native String getDeviceID();
210
211     /**
212      * Method to get device status (ON/OFF) of a device.
213      * @return      ON/OFF
214      */
215
216     public DeviceStatus getDeviceStatus() throws OcException {
217         return DeviceStatus.convertDeviceStatus(this.deviceStatus());
218     }
219     public native int deviceStatus() throws OcException;
220
221     /**
222      * Method to get device  ownership (OWNED/UNOWNED) status.
223      * @return      OWNED/UNOWNED
224      */
225
226     public OwnedStatus getOwnedStatus() throws OcException {
227         return  OwnedStatus.convertOwnedStatus(this.ownedStatus());
228     }
229     public native int ownedStatus() throws OcException;
230
231     @Override
232     protected void finalize() throws Throwable {
233         super.finalize();
234         dispose();
235     }
236
237     private native void dispose();
238
239     private long mNativeHandle;
240 }