Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
briar
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Julian Dehm
briar
Commits
9515e938
Verified
Commit
9515e938
authored
Oct 11, 2018
by
akwizgran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cancel discovery after 10 seconds and try to connect.
parent
efe15df9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
9 deletions
+27
-9
AndroidBluetoothPlugin.java
...ject/bramble/plugin/bluetooth/AndroidBluetoothPlugin.java
+20
-5
AndroidBluetoothPluginFactory.java
...amble/plugin/bluetooth/AndroidBluetoothPluginFactory.java
+5
-2
KeyAgreementConstants.java
...oject/bramble/api/keyagreement/KeyAgreementConstants.java
+1
-1
AppModule.java
...c/main/java/org/briarproject/briar/android/AppModule.java
+1
-1
No files found.
bramble-android/src/main/java/org/briarproject/bramble/plugin/bluetooth/AndroidBluetoothPlugin.java
View file @
9515e938
...
...
@@ -16,6 +16,7 @@ import org.briarproject.bramble.api.plugin.PluginException;
import
org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback
;
import
org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection
;
import
org.briarproject.bramble.api.system.AndroidExecutor
;
import
org.briarproject.bramble.api.system.Clock
;
import
org.briarproject.bramble.util.AndroidUtils
;
import
java.io.Closeable
;
...
...
@@ -23,6 +24,8 @@ import java.io.IOException;
import
java.security.SecureRandom
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.UUID
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.ExecutionException
;
...
...
@@ -45,6 +48,7 @@ import static android.bluetooth.BluetoothAdapter.STATE_OFF;
import
static
android
.
bluetooth
.
BluetoothAdapter
.
STATE_ON
;
import
static
android
.
bluetooth
.
BluetoothDevice
.
ACTION_FOUND
;
import
static
android
.
bluetooth
.
BluetoothDevice
.
EXTRA_DEVICE
;
import
static
java
.
util
.
concurrent
.
TimeUnit
.
MILLISECONDS
;
import
static
java
.
util
.
logging
.
Level
.
INFO
;
import
static
java
.
util
.
logging
.
Level
.
WARNING
;
import
static
org
.
briarproject
.
bramble
.
util
.
LogUtils
.
logException
;
...
...
@@ -57,8 +61,11 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
private
static
final
Logger
LOG
=
Logger
.
getLogger
(
AndroidBluetoothPlugin
.
class
.
getName
());
private
static
final
int
MAX_DISCOVERY_MS
=
10_000
;
private
final
AndroidExecutor
androidExecutor
;
private
final
Context
appContext
;
private
final
Clock
clock
;
private
volatile
boolean
wasEnabledByUs
=
false
;
private
volatile
BluetoothStateReceiver
receiver
=
null
;
...
...
@@ -68,12 +75,13 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
AndroidBluetoothPlugin
(
BluetoothConnectionLimiter
connectionLimiter
,
Executor
ioExecutor
,
AndroidExecutor
androidExecutor
,
Context
appContext
,
SecureRandom
secureRandom
,
Backoff
backoff
,
DuplexPluginCallback
callback
,
int
maxLatency
)
{
Context
appContext
,
SecureRandom
secureRandom
,
Clock
clock
,
Backoff
backoff
,
DuplexPluginCallback
callback
,
int
maxLatency
)
{
super
(
connectionLimiter
,
ioExecutor
,
secureRandom
,
backoff
,
callback
,
maxLatency
);
this
.
androidExecutor
=
androidExecutor
;
this
.
appContext
=
appContext
;
this
.
clock
=
clock
;
}
@Override
...
...
@@ -213,7 +221,7 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
}
private
Collection
<
String
>
discoverDevices
()
{
Collection
<
String
>
addresses
=
new
ArrayList
<>();
List
<
String
>
addresses
=
new
ArrayList
<>();
BlockingQueue
<
Intent
>
intents
=
new
LinkedBlockingQueue
<>();
DiscoveryReceiver
receiver
=
new
DiscoveryReceiver
(
intents
);
IntentFilter
filter
=
new
IntentFilter
();
...
...
@@ -223,8 +231,11 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
appContext
.
registerReceiver
(
receiver
,
filter
);
try
{
if
(
adapter
.
startDiscovery
())
{
while
(
true
)
{
Intent
i
=
intents
.
take
();
long
now
=
clock
.
currentTimeMillis
();
long
end
=
now
+
MAX_DISCOVERY_MS
;
while
(
now
<
end
)
{
Intent
i
=
intents
.
poll
(
end
-
now
,
MILLISECONDS
);
if
(
i
==
null
)
break
;
String
action
=
i
.
getAction
();
if
(
ACTION_DISCOVERY_STARTED
.
equals
(
action
))
{
LOG
.
info
(
"Discovery started"
);
...
...
@@ -239,6 +250,7 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
if
(!
addresses
.
contains
(
address
))
addresses
.
add
(
address
);
}
now
=
clock
.
currentTimeMillis
();
}
}
else
{
LOG
.
info
(
"Could not start discovery"
);
...
...
@@ -247,9 +259,12 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
LOG
.
info
(
"Interrupted while discovering devices"
);
Thread
.
currentThread
().
interrupt
();
}
finally
{
LOG
.
info
(
"Cancelling discovery"
);
adapter
.
cancelDiscovery
();
appContext
.
unregisterReceiver
(
receiver
);
}
// Shuffle the addresses so we don't always try the same one first
Collections
.
shuffle
(
addresses
);
return
addresses
;
}
...
...
bramble-android/src/main/java/org/briarproject/bramble/plugin/bluetooth/AndroidBluetoothPluginFactory.java
View file @
9515e938
...
...
@@ -11,6 +11,7 @@ import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
import
org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback
;
import
org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory
;
import
org.briarproject.bramble.api.system.AndroidExecutor
;
import
org.briarproject.bramble.api.system.Clock
;
import
java.security.SecureRandom
;
import
java.util.concurrent.Executor
;
...
...
@@ -33,17 +34,19 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
private
final
Context
appContext
;
private
final
SecureRandom
secureRandom
;
private
final
EventBus
eventBus
;
private
final
Clock
clock
;
private
final
BackoffFactory
backoffFactory
;
public
AndroidBluetoothPluginFactory
(
Executor
ioExecutor
,
AndroidExecutor
androidExecutor
,
Context
appContext
,
SecureRandom
secureRandom
,
EventBus
eventBus
,
SecureRandom
secureRandom
,
EventBus
eventBus
,
Clock
clock
,
BackoffFactory
backoffFactory
)
{
this
.
ioExecutor
=
ioExecutor
;
this
.
androidExecutor
=
androidExecutor
;
this
.
appContext
=
appContext
;
this
.
secureRandom
=
secureRandom
;
this
.
eventBus
=
eventBus
;
this
.
clock
=
clock
;
this
.
backoffFactory
=
backoffFactory
;
}
...
...
@@ -65,7 +68,7 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
MAX_POLLING_INTERVAL
,
BACKOFF_BASE
);
AndroidBluetoothPlugin
plugin
=
new
AndroidBluetoothPlugin
(
connectionLimiter
,
ioExecutor
,
androidExecutor
,
appContext
,
secureRandom
,
backoff
,
callback
,
MAX_LATENCY
);
secureRandom
,
clock
,
backoff
,
callback
,
MAX_LATENCY
);
eventBus
.
addListener
(
plugin
);
return
plugin
;
}
...
...
bramble-api/src/main/java/org/briarproject/bramble/api/keyagreement/KeyAgreementConstants.java
View file @
9515e938
...
...
@@ -21,7 +21,7 @@ public interface KeyAgreementConstants {
/**
* The connection timeout in milliseconds.
*/
long
CONNECTION_TIMEOUT
=
40
*
1
000
;
long
CONNECTION_TIMEOUT
=
60_
000
;
/**
* The transport identifier for Bluetooth.
...
...
briar-android/src/main/java/org/briarproject/briar/android/AppModule.java
View file @
9515e938
...
...
@@ -107,7 +107,7 @@ public class AppModule {
Context
appContext
=
app
.
getApplicationContext
();
DuplexPluginFactory
bluetooth
=
new
AndroidBluetoothPluginFactory
(
ioExecutor
,
androidExecutor
,
appContext
,
random
,
eventBus
,
backoffFactory
);
appContext
,
random
,
eventBus
,
clock
,
backoffFactory
);
DuplexPluginFactory
tor
=
new
AndroidTorPluginFactory
(
ioExecutor
,
scheduler
,
appContext
,
networkManager
,
locationUtils
,
eventBus
,
torSocketFactory
,
backoffFactory
,
resourceProvider
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment