Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
DiscoveryPolicy.java
Go to the documentation of this file.
1/**
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2021 Gothel Software e.K.
4 * Copyright (c) 2021 ZAFENA AB
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25package org.direct_bt;
26
27/**
28 * Discovery policy defines the {@link BTAdapter} discovery mode after connecting a remote {@link BTDevice}:
29 * - turned-off ({@link DiscoveryPolicy#AUTO_OFF})
30 * - paused until all connected BTDevice become disconnected, effectively until {@link AdapterStatusListener#deviceDisconnected(BTDevice, HCIStatusCode, short, long)} ({@link DiscoveryPolicy#PAUSE_CONNECTED_UNTIL_DISCONNECTED}).
31 * - paused until all connected devices reach readiness inclusive optional SMP pairing (~120ms) and GATT service discovery (~700ms), effectively until {@link AdapterStatusListener#deviceReady(BTDevice, long)}. ({@link DiscoveryPolicy#PAUSE_CONNECTED_UNTIL_READY}, default)
32 * - paused until all connected devices are optionally SMP paired (~120ms), exclusive GATT service discovery (~700ms -> ~1200ms, {@link DiscoveryPolicy#PAUSE_CONNECTED_UNTIL_PAIRED})
33 * - always enabled, i.e. re-enabled if automatically turned-off by HCI host OS as soon as possible ({@link DiscoveryPolicy#ALWAYS_ON})
34 *
35 * Policy is set via {@link BTAdapter#startDiscovery(DiscoveryPolicy, boolean, short, short, byte, boolean)}.
36 *
37 * Default is {@link DiscoveryPolicy#PAUSE_CONNECTED_UNTIL_READY}, as it has been shown that continuous advertising
38 * reduces the bandwidth for the initial bring-up time including GATT service discovery considerably.
39 * Continuous advertising would increase the readiness lag of the remote device until {@link AdapterStatusListener#deviceReady(BTDevice, long)}.
40 *
41 * In case users favors faster parallel discovery of new remote devices and hence a slower readiness,
42 * {@link DiscoveryPolicy#PAUSE_CONNECTED_UNTIL_PAIRED} or even {@link DiscoveryPolicy#ALWAYS_ON} can be used.
43 *
44 * @since 2.5.0
45 */
46public enum DiscoveryPolicy {
47 /** Turn off discovery when a BTDevice gets connected and leave discovery disabled, if turned off by host system. */
48 AUTO_OFF ((byte) 0),
49 /**
50 * Pause discovery until all connected {@link BTDevice} become disconnected,
51 * effectively until {@link AdapterStatusListener#deviceDisconnected(BTDevice, HCIStatusCode, short, long)}.
52 */
54 /**
55 * Pause discovery until all connected {@link BTDevice} reach readiness inclusive optional SMP pairing (~120ms) without GATT service discovery (~700ms),
56 * effectively until {@link AdapterStatusListener#deviceReady(BTDevice, long)}. This is the default!
57 */
59 /** Pause discovery until all connected {@link BTDevice} are optionally SMP paired (~120ms) without GATT service discovery (~700ms). */
61 /** Always keep discovery enabled, i.e. re-enabled if automatically turned-off by HCI host OS as soon as possible. */
62 ALWAYS_ON ((byte) 4);
63
64 public final byte value;
65
66 /**
67 * Maps the specified integer value to a constant of {@link DiscoveryPolicy}.
68 * @param value the integer value to be mapped to a constant of this enum type.
69 * @return the corresponding constant of this enum type, using {@link #AUTO_OFF} if not supported.
70 */
71 public static DiscoveryPolicy get(final byte value) {
72 switch(value) {
73 case (byte) 1: return PAUSE_CONNECTED_UNTIL_DISCONNECTED;
74 case (byte) 2: return PAUSE_CONNECTED_UNTIL_READY;
75 case (byte) 3: return PAUSE_CONNECTED_UNTIL_PAIRED;
76 case (byte) 4: return ALWAYS_ON;
77 default: return AUTO_OFF;
78 }
79 }
80
81 DiscoveryPolicy(final byte v) {
82 value = v;
83 }
84}
Discovery policy defines the BTAdapter discovery mode after connecting a remote BTDevice:
PAUSE_CONNECTED_UNTIL_DISCONNECTED
Pause discovery until all connected BTDevice become disconnected, effectively until AdapterStatusList...
ALWAYS_ON
Always keep discovery enabled, i.e.
AUTO_OFF
Turn off discovery when a BTDevice gets connected and leave discovery disabled, if turned off by host...
PAUSE_CONNECTED_UNTIL_PAIRED
Pause discovery until all connected BTDevice are optionally SMP paired (~120ms) without GATT service ...
PAUSE_CONNECTED_UNTIL_READY
Pause discovery until all connected BTDevice reach readiness inclusive optional SMP pairing (~120ms) ...