Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
d2a10272
Commit
d2a10272
authored
Dec 05, 2015
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix an issue of attach/deattach service when switching NAT mode
parent
b0f3d91d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
7 deletions
+18
-7
src/main/scala/com/github/shadowsocks/ServiceBoundContext.scala
...in/scala/com/github/shadowsocks/ServiceBoundContext.scala
+11
-3
src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala
...in/scala/com/github/shadowsocks/ShadowsocksSettings.scala
+7
-4
No files found.
src/main/scala/com/github/shadowsocks/ServiceBoundContext.scala
View file @
d2a10272
...
@@ -9,7 +9,8 @@ import com.github.shadowsocks.utils.Action
...
@@ -9,7 +9,8 @@ import com.github.shadowsocks.utils.Action
* @author Mygod
* @author Mygod
*/
*/
trait
ServiceBoundContext
extends
Context
{
trait
ServiceBoundContext
extends
Context
{
val
connection
=
new
ServiceConnection
{
class
ShadowsocksServiceConnection
extends
ServiceConnection
{
override
def
onServiceConnected
(
name
:
ComponentName
,
service
:
IBinder
)
{
override
def
onServiceConnected
(
name
:
ComponentName
,
service
:
IBinder
)
{
bgService
=
IShadowsocksService
.
Stub
.
asInterface
(
service
)
bgService
=
IShadowsocksService
.
Stub
.
asInterface
(
service
)
if
(
callback
!=
null
)
try
{
if
(
callback
!=
null
)
try
{
...
@@ -37,6 +38,7 @@ trait ServiceBoundContext extends Context {
...
@@ -37,6 +38,7 @@ trait ServiceBoundContext extends Context {
def
onServiceDisconnected
()
=
()
def
onServiceDisconnected
()
=
()
private
var
callback
:
IShadowsocksServiceCallback.Stub
=
_
private
var
callback
:
IShadowsocksServiceCallback.Stub
=
_
private
var
connection
:
ShadowsocksServiceConnection
=
_
// Variables
// Variables
var
bgService
:
IShadowsocksService
=
_
var
bgService
:
IShadowsocksService
=
_
...
@@ -46,9 +48,13 @@ trait ServiceBoundContext extends Context {
...
@@ -46,9 +48,13 @@ trait ServiceBoundContext extends Context {
if
(
bgService
==
null
)
{
if
(
bgService
==
null
)
{
val
s
=
val
s
=
if
(
ShadowsocksApplication
.
isVpnEnabled
)
classOf
[
ShadowsocksVpnService
]
else
classOf
[
ShadowsocksNatService
]
if
(
ShadowsocksApplication
.
isVpnEnabled
)
classOf
[
ShadowsocksVpnService
]
else
classOf
[
ShadowsocksNatService
]
val
intent
=
new
Intent
(
this
,
s
)
val
intent
=
new
Intent
(
this
,
s
)
intent
.
setAction
(
Action
.
SERVICE
)
intent
.
setAction
(
Action
.
SERVICE
)
connection
=
new
ShadowsocksServiceConnection
()
bindService
(
intent
,
connection
,
Context
.
BIND_AUTO_CREATE
)
bindService
(
intent
,
connection
,
Context
.
BIND_AUTO_CREATE
)
startService
(
new
Intent
(
this
,
s
))
startService
(
new
Intent
(
this
,
s
))
}
}
}
}
...
@@ -62,8 +68,10 @@ trait ServiceBoundContext extends Context {
...
@@ -62,8 +68,10 @@ trait ServiceBoundContext extends Context {
case
ignored
:
RemoteException
=>
// Nothing
case
ignored
:
RemoteException
=>
// Nothing
}
}
}
}
unbindService
(
connection
)
if
(
connection
!=
null
)
{
bgService
=
null
unbindService
(
connection
)
connection
=
null
}
}
}
}
}
}
}
src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala
View file @
d2a10272
...
@@ -73,10 +73,13 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
...
@@ -73,10 +73,13 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
}
}
def
onSharedPreferenceChanged
(
sharedPreferences
:
SharedPreferences
,
key
:
String
)
=
key
match
{
def
onSharedPreferenceChanged
(
sharedPreferences
:
SharedPreferences
,
key
:
String
)
=
key
match
{
case
Key
.
isNAT
=>
if
(
ShadowsocksApplication
.
isRoot
)
activity
.
handler
.
post
(()
=>
{
case
Key
.
isNAT
=>
if
(
ShadowsocksApplication
.
isRoot
&&
activity
!=
null
)
{
activity
.
deattachService
()
activity
.
handler
.
post
(()
=>
{
activity
.
attachService
()
val
intent
=
activity
.
getIntent
})
activity
.
finish
()
startActivity
(
intent
)
})
}
case
_
=>
case
_
=>
}
}
}
}
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