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
c8f68e1a
Commit
c8f68e1a
authored
Jun 20, 2013
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refine context clean up
parent
d0ca6667
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
46 deletions
+47
-46
src/main/scala/com/github/shadowsocks/ShadowsocksService.scala
...ain/scala/com/github/shadowsocks/ShadowsocksService.scala
+47
-46
No files found.
src/main/scala/com/github/shadowsocks/ShadowsocksService.scala
View file @
c8f68e1a
...
@@ -60,6 +60,7 @@ import java.util.{TimerTask, Timer}
...
@@ -60,6 +60,7 @@ import java.util.{TimerTask, Timer}
import
android.net.TrafficStats
import
android.net.TrafficStats
import
android.graphics._
import
android.graphics._
import
scala.Some
import
scala.Some
import
scala.concurrent.ops._
case
class
TrafficStat
(
tx
:
Long
,
rx
:
Long
,
timestamp
:
Long
)
case
class
TrafficStat
(
tx
:
Long
,
rx
:
Long
,
timestamp
:
Long
)
...
@@ -169,18 +170,16 @@ class ShadowsocksService extends Service {
...
@@ -169,18 +170,16 @@ class ShadowsocksService extends Service {
}
}
def
startShadowsocksDaemon
()
{
def
startShadowsocksDaemon
()
{
new
Thread
{
spawn
{
override
def
run
()
{
val
cmd
:
String
=
(
BASE
+
val
cmd
:
String
=
(
BASE
+
"shadowsocks -s \"%s\" -p \"%d\" -l \"%d\" -k \"%s\" -m \"%s\" -f "
+
"shadowsocks -s \"%s\" -p \"%d\" -l \"%d\" -k \"%s\" -m \"%s\" -f "
+
BASE
+
BASE
+
"shadowsocks.pid"
)
"shadowsocks.pid"
)
.
format
(
config
.
proxy
,
config
.
remotePort
,
config
.
localPort
,
config
.
sitekey
,
.
format
(
config
.
proxy
,
config
.
remotePort
,
config
.
localPort
,
config
.
sitekey
,
config
.
encMethod
)
config
.
encMethod
)
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
)
if
(
BuildConfig
.
DEBUG
)
Log
.
d
(
TAG
,
cmd
)
System
.
exec
(
cmd
)
System
.
exec
(
cmd
)
}
}
}.
start
()
}
}
def
startDnsDaemon
()
{
def
startDnsDaemon
()
{
...
@@ -211,38 +210,36 @@ class ShadowsocksService extends Service {
...
@@ -211,38 +210,36 @@ class ShadowsocksService extends Service {
config
=
Extra
.
get
(
intent
)
config
=
Extra
.
get
(
intent
)
new
Thread
(
new
Runnable
{
def
run
()
{
killProcesses
()
spawn
{
killProcesses
()
var
resolved
:
Boolean
=
false
if
(!
InetAddressUtils
.
isIPv4Address
(
config
.
proxy
)
&&
var
resolved
:
Boolean
=
false
!
InetAddressUtils
.
isIPv6Address
(
config
.
proxy
))
{
if
(!
InetAddressUtils
.
isIPv4Address
(
config
.
proxy
)
&&
Utils
.
resolve
(
config
.
proxy
,
enableIPv6
=
true
)
match
{
!
InetAddressUtils
.
isIPv6Address
(
config
.
proxy
))
{
case
Some
(
a
)
=>
Utils
.
resolve
(
config
.
proxy
,
enableIPv6
=
true
)
match
{
config
.
proxy
=
a
case
Some
(
a
)
=>
resolved
=
true
config
.
proxy
=
a
case
None
=>
resolved
=
false
resolved
=
true
}
case
None
=>
resolved
=
false
}
else
{
resolved
=
true
}
}
}
else
{
resolved
=
true
}
hasRedirectSupport
=
Utils
.
getHasRedirectSupport
hasRedirectSupport
=
Utils
.
getHasRedirectSupport
if
(
resolved
&&
handleConnection
)
{
if
(
resolved
&&
handleConnection
)
{
notifyForegroundAlert
(
getString
(
R
.
string
.
forward_success
),
notifyForegroundAlert
(
getString
(
R
.
string
.
forward_success
),
getString
(
R
.
string
.
service_running
))
getString
(
R
.
string
.
service_running
))
handler
.
sendEmptyMessageDelayed
(
MSG_CONNECT_SUCCESS
,
500
)
handler
.
sendEmptyMessageDelayed
(
MSG_CONNECT_SUCCESS
,
500
)
}
else
{
}
else
{
notifyAlert
(
getString
(
R
.
string
.
forward_fail
),
getString
(
R
.
string
.
service_failed
))
notifyAlert
(
getString
(
R
.
string
.
forward_fail
),
getString
(
R
.
string
.
service_failed
))
stopSelf
()
stopSelf
()
handler
.
sendEmptyMessageDelayed
(
MSG_CONNECT_FAIL
,
500
)
handler
.
sendEmptyMessageDelayed
(
MSG_CONNECT_FAIL
,
500
)
}
handler
.
sendEmptyMessageDelayed
(
MSG_CONNECT_FINISH
,
500
)
}
}
}).
start
()
handler
.
sendEmptyMessageDelayed
(
MSG_CONNECT_FINISH
,
500
)
}
}
}
def
startRedsocksDaemon
()
{
def
startRedsocksDaemon
()
{
...
@@ -433,32 +430,36 @@ class ShadowsocksService extends Service {
...
@@ -433,32 +430,36 @@ class ShadowsocksService extends Service {
/** Called when the activity is closed. */
/** Called when the activity is closed. */
override
def
onDestroy
()
{
override
def
onDestroy
()
{
// clean up context
changeState
(
State
.
STOPPED
)
changeState
(
State
.
STOPPED
)
timer
.
cancel
()
timer
.
cancel
()
EasyTracker
.
getTracker
.
setStartSession
(
false
)
EasyTracker
.
getTracker
.
setStartSession
(
false
)
EasyTracker
.
getTracker
.
sendEvent
(
TAG
,
"stop"
,
getVersionName
,
0L
)
EasyTracker
.
getTracker
.
sendEvent
(
TAG
,
"stop"
,
getVersionName
,
0L
)
stopForegroundCompat
(
1
)
stopForegroundCompat
(
1
)
new
Thread
{
override
def
run
()
{
killProcesses
()
}
}.
start
()
if
(
receiver
!=
null
)
{
if
(
receiver
!=
null
)
{
unregisterReceiver
(
receiver
)
unregisterReceiver
(
receiver
)
receiver
=
null
receiver
=
null
}
}
// reset NAT
Utils
.
runRootCommand
(
Utils
.
getIptables
+
" -t nat -F OUTPUT"
)
spawn
{
killProcesses
()
}
super
.
onDestroy
()
super
.
onDestroy
()
}
}
def
killProcesses
()
{
def
killProcesses
()
{
Utils
.
runRootCommand
(
Utils
.
getIptables
+
" -t nat -F OUTPUT"
)
val
sb
=
new
StringBuilder
val
sb
=
new
StringBuilder
sb
++=
"kill -9 `cat /data/data/com.github.shadowsocks/redsocks.pid`"
++=
"\n"
sb
++=
"kill -9 `cat /data/data/com.github.shadowsocks/redsocks.pid`"
++=
"\n"
sb
++=
"killall -9 redsocks"
++=
"\n"
sb
++=
"killall -9 redsocks"
++=
"\n"
Utils
.
runRootCommand
(
sb
.
toString
())
Utils
.
runRootCommand
(
sb
.
toString
())
sb
.
clear
()
sb
.
clear
()
if
(!
waitForProcess
(
"pdnsd"
))
{
if
(!
waitForProcess
(
"pdnsd"
))
{
sb
++=
"kill -9 `cat /data/data/com.github.shadowsocks/pdnsd.pid`"
++=
"\n"
sb
++=
"kill -9 `cat /data/data/com.github.shadowsocks/pdnsd.pid`"
++=
"\n"
sb
++=
"killall -9 pdnsd"
++=
"\n"
sb
++=
"killall -9 pdnsd"
++=
"\n"
...
...
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