Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Dehm
briar
Commits
b2062693
Verified
Commit
b2062693
authored
7 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
AP state change event races with address appearing.
parent
8e9fc3b3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bramble-android/src/main/java/org/briarproject/bramble/plugin/tcp/AndroidLanTcpPlugin.java
+19
-7
19 additions, 7 deletions
.../briarproject/bramble/plugin/tcp/AndroidLanTcpPlugin.java
with
19 additions
and
7 deletions
bramble-android/src/main/java/org/briarproject/bramble/plugin/tcp/AndroidLanTcpPlugin.java
+
19
−
7
View file @
b2062693
...
@@ -29,6 +29,7 @@ import static android.content.Context.CONNECTIVITY_SERVICE;
...
@@ -29,6 +29,7 @@ import static android.content.Context.CONNECTIVITY_SERVICE;
import
static
android
.
content
.
Context
.
WIFI_SERVICE
;
import
static
android
.
content
.
Context
.
WIFI_SERVICE
;
import
static
android
.
net
.
ConnectivityManager
.
CONNECTIVITY_ACTION
;
import
static
android
.
net
.
ConnectivityManager
.
CONNECTIVITY_ACTION
;
import
static
android
.
net
.
ConnectivityManager
.
TYPE_WIFI
;
import
static
android
.
net
.
ConnectivityManager
.
TYPE_WIFI
;
import
static
android
.
net
.
wifi
.
WifiManager
.
EXTRA_WIFI_STATE
;
import
static
android
.
os
.
Build
.
VERSION
.
SDK_INT
;
import
static
android
.
os
.
Build
.
VERSION
.
SDK_INT
;
import
static
java
.
util
.
Collections
.
emptyList
;
import
static
java
.
util
.
Collections
.
emptyList
;
import
static
java
.
util
.
Collections
.
singletonList
;
import
static
java
.
util
.
Collections
.
singletonList
;
...
@@ -36,11 +37,15 @@ import static java.util.Collections.singletonList;
...
@@ -36,11 +37,15 @@ import static java.util.Collections.singletonList;
@NotNullByDefault
@NotNullByDefault
class
AndroidLanTcpPlugin
extends
LanTcpPlugin
{
class
AndroidLanTcpPlugin
extends
LanTcpPlugin
{
private
static
final
String
WIFI_AP_STATE_ACTION
=
// See android.net.wifi.WifiManager
private
static
final
String
WIFI_AP_STATE_CHANGED_ACTION
=
"android.net.wifi.WIFI_AP_STATE_CHANGED"
;
"android.net.wifi.WIFI_AP_STATE_CHANGED"
;
private
static
final
int
WIFI_AP_STATE_ENABLED
=
13
;
private
static
final
byte
[]
WIFI_AP_ADDRESS_BYTES
=
private
static
final
byte
[]
WIFI_AP_ADDRESS_BYTES
=
{(
byte
)
192
,
(
byte
)
168
,
43
,
1
};
{(
byte
)
192
,
(
byte
)
168
,
43
,
1
};
private
static
final
InetAddress
WIFI_AP_ADDRESS
;
private
static
final
InetAddress
WIFI_AP_ADDRESS
;
private
static
final
Logger
LOG
=
private
static
final
Logger
LOG
=
Logger
.
getLogger
(
AndroidLanTcpPlugin
.
class
.
getName
());
Logger
.
getLogger
(
AndroidLanTcpPlugin
.
class
.
getName
());
...
@@ -84,7 +89,7 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
...
@@ -84,7 +89,7 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
networkStateReceiver
=
new
NetworkStateReceiver
();
networkStateReceiver
=
new
NetworkStateReceiver
();
IntentFilter
filter
=
new
IntentFilter
();
IntentFilter
filter
=
new
IntentFilter
();
filter
.
addAction
(
CONNECTIVITY_ACTION
);
filter
.
addAction
(
CONNECTIVITY_ACTION
);
filter
.
addAction
(
WIFI_AP_STATE_ACTION
);
filter
.
addAction
(
WIFI_AP_STATE_
CHANGED_
ACTION
);
appContext
.
registerReceiver
(
networkStateReceiver
,
filter
);
appContext
.
registerReceiver
(
networkStateReceiver
,
filter
);
}
}
...
@@ -149,11 +154,9 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
...
@@ -149,11 +154,9 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
public
void
onReceive
(
Context
ctx
,
Intent
i
)
{
public
void
onReceive
(
Context
ctx
,
Intent
i
)
{
if
(!
running
)
return
;
if
(!
running
)
return
;
Collection
<
InetAddress
>
addrs
=
getLocalIpAddresses
();
Collection
<
InetAddress
>
addrs
=
getLocalIpAddresses
();
if
(
addrs
.
isEmpty
())
{
// The state change may be broadcast before the AP address is
LOG
.
info
(
"Not connected to wifi"
);
// visible, so check the intent as well as the local addresses
socketFactory
=
SocketFactory
.
getDefault
();
if
(
isApEnabledEvent
(
i
)
||
addrs
.
contains
(
WIFI_AP_ADDRESS
))
{
tryToClose
(
socket
);
}
else
if
(
addrs
.
contains
(
WIFI_AP_ADDRESS
))
{
LOG
.
info
(
"Providing wifi hotspot"
);
LOG
.
info
(
"Providing wifi hotspot"
);
// There's no corresponding Network object and thus no way
// There's no corresponding Network object and thus no way
// to get a suitable socket factory, so we won't be able to
// to get a suitable socket factory, so we won't be able to
...
@@ -161,11 +164,20 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
...
@@ -161,11 +164,20 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
// has internet access
// has internet access
socketFactory
=
SocketFactory
.
getDefault
();
socketFactory
=
SocketFactory
.
getDefault
();
if
(
socket
==
null
||
socket
.
isClosed
())
bind
();
if
(
socket
==
null
||
socket
.
isClosed
())
bind
();
}
else
if
(
addrs
.
isEmpty
())
{
LOG
.
info
(
"Not connected to wifi"
);
socketFactory
=
SocketFactory
.
getDefault
();
tryToClose
(
socket
);
}
else
{
}
else
{
LOG
.
info
(
"Connected to wifi"
);
LOG
.
info
(
"Connected to wifi"
);
socketFactory
=
getSocketFactory
();
socketFactory
=
getSocketFactory
();
if
(
socket
==
null
||
socket
.
isClosed
())
bind
();
if
(
socket
==
null
||
socket
.
isClosed
())
bind
();
}
}
}
}
private
boolean
isApEnabledEvent
(
Intent
i
)
{
return
WIFI_AP_STATE_CHANGED_ACTION
.
equals
(
i
.
getAction
())
&&
i
.
getIntExtra
(
EXTRA_WIFI_STATE
,
0
)
==
WIFI_AP_STATE_ENABLED
;
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment