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
c878d4da
Commit
c878d4da
authored
May 24, 2016
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix DeathRecipient leaking bug
parent
9be24d74
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
26 deletions
+16
-26
src/main/scala/com/github/shadowsocks/ServiceBoundContext.scala
...in/scala/com/github/shadowsocks/ServiceBoundContext.scala
+10
-2
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+6
-0
src/main/scala/com/github/shadowsocks/ShadowsocksDeathRecipient.scala
...la/com/github/shadowsocks/ShadowsocksDeathRecipient.scala
+0
-24
No files found.
src/main/scala/com/github/shadowsocks/ServiceBoundContext.scala
View file @
c878d4da
...
@@ -9,10 +9,11 @@ import com.github.shadowsocks.ShadowsocksApplication.app
...
@@ -9,10 +9,11 @@ import com.github.shadowsocks.ShadowsocksApplication.app
/**
/**
* @author Mygod
* @author Mygod
*/
*/
trait
ServiceBoundContext
extends
Context
{
trait
ServiceBoundContext
extends
Context
with
IBinder
.
DeathRecipient
{
class
ShadowsocksServiceConnection
extends
ServiceConnection
{
class
ShadowsocksServiceConnection
extends
ServiceConnection
{
override
def
onServiceConnected
(
name
:
ComponentName
,
service
:
IBinder
)
{
override
def
onServiceConnected
(
name
:
ComponentName
,
service
:
IBinder
)
{
service
.
linkToDeath
(
new
ShadowsocksDeathRecipient
(
ServiceBoundContext
.
this
),
0
)
binder
=
service
service
.
linkToDeath
(
ServiceBoundContext
.
this
,
0
)
bgService
=
IShadowsocksService
.
Stub
.
asInterface
(
service
)
bgService
=
IShadowsocksService
.
Stub
.
asInterface
(
service
)
registerCallback
registerCallback
ServiceBoundContext
.
this
.
onServiceConnected
()
ServiceBoundContext
.
this
.
onServiceConnected
()
...
@@ -21,6 +22,7 @@ trait ServiceBoundContext extends Context {
...
@@ -21,6 +22,7 @@ trait ServiceBoundContext extends Context {
unregisterCallback
unregisterCallback
ServiceBoundContext
.
this
.
onServiceDisconnected
()
ServiceBoundContext
.
this
.
onServiceDisconnected
()
bgService
=
null
bgService
=
null
binder
=
null
}
}
}
}
...
@@ -40,12 +42,14 @@ trait ServiceBoundContext extends Context {
...
@@ -40,12 +42,14 @@ trait ServiceBoundContext extends Context {
def
onServiceConnected
()
=
()
def
onServiceConnected
()
=
()
def
onServiceDisconnected
()
=
()
def
onServiceDisconnected
()
=
()
override
def
binderDied
=
()
private
var
callback
:
IShadowsocksServiceCallback.Stub
=
_
private
var
callback
:
IShadowsocksServiceCallback.Stub
=
_
private
var
connection
:
ShadowsocksServiceConnection
=
_
private
var
connection
:
ShadowsocksServiceConnection
=
_
private
var
callbackRegistered
:
Boolean
=
_
private
var
callbackRegistered
:
Boolean
=
_
// Variables
// Variables
var
binder
:
IBinder
=
_
var
bgService
:
IShadowsocksService
=
_
var
bgService
:
IShadowsocksService
=
_
def
attachService
(
callback
:
IShadowsocksServiceCallback.Stub
=
null
)
{
def
attachService
(
callback
:
IShadowsocksServiceCallback.Stub
=
null
)
{
...
@@ -70,6 +74,10 @@ trait ServiceBoundContext extends Context {
...
@@ -70,6 +74,10 @@ trait ServiceBoundContext extends Context {
unbindService
(
connection
)
unbindService
(
connection
)
connection
=
null
connection
=
null
}
}
if
(
binder
!=
null
)
{
binder
.
unlinkToDeath
(
this
,
0
)
binder
=
null
}
bgService
=
null
bgService
=
null
}
}
}
}
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
c878d4da
...
@@ -214,6 +214,12 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
...
@@ -214,6 +214,12 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
if
(
fab
!=
null
)
fab
.
setEnabled
(
false
)
if
(
fab
!=
null
)
fab
.
setEnabled
(
false
)
}
}
override
def
binderDied
{
detachService
crashRecovery
attachService
}
private
var
testCount
:
Int
=
_
private
var
testCount
:
Int
=
_
private
lazy
val
stat
=
findViewById
(
R
.
id
.
stat
)
private
lazy
val
stat
=
findViewById
(
R
.
id
.
stat
)
private
var
connectionTestText
:
TextView
=
_
private
var
connectionTestText
:
TextView
=
_
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksDeathRecipient.scala
deleted
100644 → 0
View file @
9be24d74
package
com.github.shadowsocks
import
android.os.IBinder
import
android.util.Log
/**
* @author chentaov5@gmail.com
*/
class
ShadowsocksDeathRecipient
(
val
mContext
:
ServiceBoundContext
)
extends
IBinder
.
DeathRecipient
{
val
TAG
=
"ShadowsocksDeathRecipient"
override
def
binderDied
()
:
Unit
=
{
Log
.
d
(
TAG
,
"[ShadowsocksDeathRecipient] binder died."
)
mContext
match
{
case
ss
:
Shadowsocks
=>
ss
.
detachService
ss
.
crashRecovery
ss
.
attachService
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