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 org.iotivity.base.OcException;
26 import org.iotivity.base.OcConnectivityType;
28 class BluetoothDevice {}
30 public class CaInterface {
33 private static volatile boolean isConnectionManagerInitialized = false;
34 private static volatile boolean isBtPairingInitialized = false;
36 public static void initialize() {}
39 * Method start connection manager service.
40 * this method has to be called before other API call.
41 * @param context application context
42 * @param onConnectionManagerStateListener connection state callback listener
44 public synchronized static void startManagerService(
45 OnConnectionManagerStateListener onConnectionManagerStateListener) {
46 if (!isConnectionManagerInitialized) {
47 CaInterface.caManagerInitialize(onConnectionManagerStateListener);
48 isConnectionManagerInitialized = true;
53 * Method stop connection manager service.
54 * this method must be called, when Application is destroied.
56 public synchronized static void stopManagerService() {
57 if (isConnectionManagerInitialized) {
58 CaInterface.caManagerTerminate();
59 isConnectionManagerInitialized = false;
64 * Method set device information for Auto-Connection.
65 * this method has to be called before FindResource is called.
66 * @param address LE address of scanned bluetooth device.
68 public synchronized static void setAutoConnectionDevice(String address)
70 CaInterface.initCheckForConnectionManager();
71 CaInterface.caManagerSetAutoConnectionDeviceInfo(address);
75 * Method unset device information for Auto-Connection.
76 * @param address LE address of scanned bluetooth device.
78 public synchronized static void unsetAutoConnectionDevice(String address)
80 CaInterface.initCheckForConnectionManager();
81 CaInterface.caManagerUnsetAutoConnectionDeviceInfo(address);
85 * Interface for connection manager state listener.
86 * Event listeners are notified asynchronously.
88 public interface OnConnectionManagerStateListener {
89 public void onAdapterStateChanged(OcConnectivityType type, boolean enabled);
90 public void onConnectionStateChanged(OcConnectivityType type, String address,
94 private static void initCheckForConnectionManager() {
95 if (!isConnectionManagerInitialized) {
96 throw new IllegalStateException("ConnectionManager must be started by making "
97 + "a call to CaInterface.startManagerService before any other API "
98 + "calls are permitted");
102 private static void caManagerInitialize(
103 OnConnectionManagerStateListener onConnectionManagerStateListener) {}
104 private static void caManagerTerminate() {}
105 private static void caManagerSetAutoConnectionDeviceInfo(String address) {}
106 private static void caManagerUnsetAutoConnectionDeviceInfo(String address) {}
109 * start bluetooth pairing service.
110 * @param context application context
112 public synchronized static void startBtPairingService(
113 OnBtDeviceFoundListener listener) {
114 if (!isBtPairingInitialized) {
116 CaInterface.caBtPairingInitialize(listener);
118 isBtPairingInitialized = true;
123 * stop bluetooth pairing service.
125 public synchronized static void stopBtPairingService() {
126 if (isBtPairingInitialized) {
127 CaInterface.caBtPairingTerminate();
129 isBtPairingInitialized = false;
134 * start bluetooth device scan.
136 public synchronized static void startScan()
138 CaInterface.initCheckForBtPairingUtil();
139 CaInterface.caBtPairingStartScan();
143 * stop bluetooth device scan.
145 public synchronized static void stopScan()
147 CaInterface.initCheckForBtPairingUtil();
148 CaInterface.caBtPairingStopScan();
154 public synchronized static void createBond(BluetoothDevice device)
156 CaInterface.initCheckForBtPairingUtil();
157 CaInterface.caBtPairingCreateBond(device);
160 public interface OnBtDeviceFoundListener {
161 public void onBtDeviceFound(BluetoothDevice device) throws OcException;
164 private static void initCheckForBtPairingUtil() {
165 if (!isBtPairingInitialized) {
166 throw new IllegalStateException("BT pairing Util must be started by making "
167 + "a call to CaInterface.startBtPairingService before any other API "
168 + "calls are permitted");
172 private static void caBtPairingInitialize(
173 OnBtDeviceFoundListener listener) {}
174 private static void caBtPairingTerminate() {}
175 private static void caBtPairingStartScan() {}
176 private static void caBtPairingStopScan() {}
177 private static void caBtPairingCreateBond(BluetoothDevice device) {}