2 * //******************************************************************
4 * // Copyright 2015 Intel Corporation.
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
12 * // http://www.apache.org/licenses/LICENSE-2.0
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.
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 package org.iotivity.ca;
25 import android.content.Context;
26 import android.app.Activity;
27 import org.iotivity.base.OcException;
28 import org.iotivity.base.OcConnectivityType;
30 public class CaInterface {
32 System.loadLibrary("connectivity_abstraction");
33 System.loadLibrary("ca-interface");
35 private static volatile boolean isConnectionManagerInitialized = false;
37 public static native void initialize(Activity activity, Context context);
40 * Method start connection manager service.
41 * this method has to be called before other API call.
42 * @param context application context
43 * @param onConnectionManagerStateListener connection state callback listener
45 public synchronized static void startManagerService(Context context,
46 OnConnectionManagerStateListener onConnectionManagerStateListener) {
47 if (!isConnectionManagerInitialized) {
48 CaInterface.caManagerInitialize(context, onConnectionManagerStateListener);
49 isConnectionManagerInitialized = true;
54 * Method stop connection manager service.
55 * this method must be called, when Application is destroied.
57 public synchronized static void stopManagerService() {
58 if (isConnectionManagerInitialized) {
59 CaInterface.caManagerTerminate();
60 isConnectionManagerInitialized = false;
65 * Method set device information for Auto-Connection.
66 * this method has to be called before FindResource is called.
67 * @param address LE address of scanned bluetooth device.
69 public synchronized static void setAutoConnectionDevice(String address)
71 CaInterface.initCheckForConnectionManager();
72 CaInterface.caManagerSetAutoConnectionDeviceInfo(address);
76 * Method unset device information for Auto-Connection.
77 * @param address LE address of scanned bluetooth device.
79 public synchronized static void unsetAutoConnectionDevice(String address)
81 CaInterface.initCheckForConnectionManager();
82 CaInterface.caManagerUnsetAutoConnectionDeviceInfo(address);
86 * Interface for connection manager state listener.
87 * Event listeners are notified asynchronously.
89 public interface OnConnectionManagerStateListener {
90 public void onAdapterStateChanged(OcConnectivityType type, boolean enabled);
91 public void onConnectionStateChanged(OcConnectivityType type, String address,
95 private static void initCheckForConnectionManager() {
96 if (!isConnectionManagerInitialized) {
97 throw new IllegalStateException("ConnectionManager must be started by making "
98 + "a call to CaInterface.startManagerService before any other API "
99 + "calls are permitted");
103 private static native void caManagerInitialize(Context context,
104 OnConnectionManagerStateListener onConnectionManagerStateListener);
105 private static native void caManagerTerminate();
106 private static native void caManagerSetAutoConnectionDeviceInfo(String address);
107 private static native void caManagerUnsetAutoConnectionDeviceInfo(String address);