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
bd9f6140
Commit
bd9f6140
authored
May 21, 2019
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not stop service prior to device shutdown
parent
12bc865b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
19 deletions
+30
-19
core/src/main/java/com/github/shadowsocks/bg/BaseService.kt
core/src/main/java/com/github/shadowsocks/bg/BaseService.kt
+4
-0
core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt
.../src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt
+1
-19
core/src/main/java/com/github/shadowsocks/bg/TrafficMonitor.kt
...src/main/java/com/github/shadowsocks/bg/TrafficMonitor.kt
+25
-0
No files found.
core/src/main/java/com/github/shadowsocks/bg/BaseService.kt
View file @
bd9f6140
...
@@ -76,6 +76,7 @@ object BaseService {
...
@@ -76,6 +76,7 @@ object BaseService {
var
notification
:
ServiceNotification
?
=
null
var
notification
:
ServiceNotification
?
=
null
val
closeReceiver
=
broadcastReceiver
{
_
,
intent
->
val
closeReceiver
=
broadcastReceiver
{
_
,
intent
->
when
(
intent
.
action
)
{
when
(
intent
.
action
)
{
Intent
.
ACTION_SHUTDOWN
->
service
.
persistStats
()
Action
.
RELOAD
->
service
.
forceLoad
()
Action
.
RELOAD
->
service
.
forceLoad
()
else
->
service
.
stopRunner
()
else
->
service
.
stopRunner
()
}
}
...
@@ -288,6 +289,9 @@ object BaseService {
...
@@ -288,6 +289,9 @@ object BaseService {
}
}
}
}
fun
persistStats
()
=
listOfNotNull
(
data
.
proxy
,
data
.
udpFallback
).
forEach
{
it
.
trafficMonitor
?.
persistStats
(
it
.
profile
.
id
)
}
suspend
fun
preInit
()
{
}
suspend
fun
preInit
()
{
}
suspend
fun
resolver
(
host
:
String
)
=
InetAddress
.
getAllByName
(
host
)
suspend
fun
resolver
(
host
:
String
)
=
InetAddress
.
getAllByName
(
host
)
suspend
fun
openConnection
(
url
:
URL
)
=
url
.
openConnection
()
suspend
fun
openConnection
(
url
:
URL
)
=
url
.
openConnection
()
...
...
core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt
View file @
bd9f6140
...
@@ -28,17 +28,14 @@ import com.github.shadowsocks.Core
...
@@ -28,17 +28,14 @@ import com.github.shadowsocks.Core
import
com.github.shadowsocks.acl.Acl
import
com.github.shadowsocks.acl.Acl
import
com.github.shadowsocks.acl.AclSyncer
import
com.github.shadowsocks.acl.AclSyncer
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.database.ProfileManager
import
com.github.shadowsocks.plugin.PluginConfiguration
import
com.github.shadowsocks.plugin.PluginConfiguration
import
com.github.shadowsocks.plugin.PluginManager
import
com.github.shadowsocks.plugin.PluginManager
import
com.github.shadowsocks.preference.DataStore
import
com.github.shadowsocks.preference.DataStore
import
com.github.shadowsocks.utils.DirectBoot
import
com.github.shadowsocks.utils.disconnectFromMain
import
com.github.shadowsocks.utils.disconnectFromMain
import
com.github.shadowsocks.utils.parseNumericAddress
import
com.github.shadowsocks.utils.parseNumericAddress
import
com.github.shadowsocks.utils.signaturesCompat
import
com.github.shadowsocks.utils.signaturesCompat
import
kotlinx.coroutines.*
import
kotlinx.coroutines.*
import
java.io.File
import
java.io.File
import
java.io.IOException
import
java.net.HttpURLConnection
import
java.net.HttpURLConnection
import
java.net.URL
import
java.net.URL
import
java.net.UnknownHostException
import
java.net.UnknownHostException
...
@@ -145,22 +142,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
...
@@ -145,22 +142,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
fun
shutdown
(
scope
:
CoroutineScope
)
{
fun
shutdown
(
scope
:
CoroutineScope
)
{
trafficMonitor
?.
apply
{
trafficMonitor
?.
apply
{
thread
.
shutdown
(
scope
)
thread
.
shutdown
(
scope
)
// Make sure update total traffic when stopping the runner
persistStats
(
profile
.
id
)
// Make sure update total traffic when stopping the runner
try
{
// profile may have host, etc. modified and thus a re-fetch is necessary (possible race condition)
val
profile
=
ProfileManager
.
getProfile
(
profile
.
id
)
?:
return
profile
.
tx
+=
current
.
txTotal
profile
.
rx
+=
current
.
rxTotal
ProfileManager
.
updateProfile
(
profile
)
}
catch
(
e
:
IOException
)
{
if
(!
DataStore
.
directBootAware
)
throw
e
// we should only reach here because we're in direct boot
val
profile
=
DirectBoot
.
getDeviceProfile
()
!!
.
toList
().
filterNotNull
().
single
{
it
.
id
==
profile
.
id
}
profile
.
tx
+=
current
.
txTotal
profile
.
rx
+=
current
.
rxTotal
profile
.
dirty
=
true
DirectBoot
.
update
(
profile
)
DirectBoot
.
listenForUnlock
()
}
}
}
trafficMonitor
=
null
trafficMonitor
=
null
configFile
?.
delete
()
// remove old config possibly in device storage
configFile
?.
delete
()
// remove old config possibly in device storage
...
...
core/src/main/java/com/github/shadowsocks/bg/TrafficMonitor.kt
View file @
bd9f6140
...
@@ -23,9 +23,13 @@ package com.github.shadowsocks.bg
...
@@ -23,9 +23,13 @@ package com.github.shadowsocks.bg
import
android.net.LocalSocket
import
android.net.LocalSocket
import
android.os.SystemClock
import
android.os.SystemClock
import
com.github.shadowsocks.aidl.TrafficStats
import
com.github.shadowsocks.aidl.TrafficStats
import
com.github.shadowsocks.database.ProfileManager
import
com.github.shadowsocks.net.LocalSocketListener
import
com.github.shadowsocks.net.LocalSocketListener
import
com.github.shadowsocks.preference.DataStore
import
com.github.shadowsocks.utils.DirectBoot
import
java.io.File
import
java.io.File
import
java.io.IOException
import
java.io.IOException
import
java.lang.IllegalStateException
import
java.nio.ByteBuffer
import
java.nio.ByteBuffer
import
java.nio.ByteOrder
import
java.nio.ByteOrder
...
@@ -52,6 +56,7 @@ class TrafficMonitor(statFile: File) {
...
@@ -52,6 +56,7 @@ class TrafficMonitor(statFile: File) {
var
out
=
TrafficStats
()
var
out
=
TrafficStats
()
private
var
timestampLast
=
0L
private
var
timestampLast
=
0L
private
var
dirty
=
false
private
var
dirty
=
false
private
var
persisted
=
false
fun
requestUpdate
():
Pair
<
TrafficStats
,
Boolean
>
{
fun
requestUpdate
():
Pair
<
TrafficStats
,
Boolean
>
{
val
now
=
SystemClock
.
elapsedRealtime
()
val
now
=
SystemClock
.
elapsedRealtime
()
...
@@ -79,4 +84,24 @@ class TrafficMonitor(statFile: File) {
...
@@ -79,4 +84,24 @@ class TrafficMonitor(statFile: File) {
}
}
return
Pair
(
out
,
updated
)
return
Pair
(
out
,
updated
)
}
}
fun
persistStats
(
id
:
Long
)
{
check
(!
persisted
)
{
"Double persisting?"
}
persisted
=
true
try
{
// profile may have host, etc. modified and thus a re-fetch is necessary (possible race condition)
val
profile
=
ProfileManager
.
getProfile
(
id
)
?:
return
profile
.
tx
+=
current
.
txTotal
profile
.
rx
+=
current
.
rxTotal
ProfileManager
.
updateProfile
(
profile
)
}
catch
(
e
:
IOException
)
{
if
(!
DataStore
.
directBootAware
)
throw
e
// we should only reach here because we're in direct boot
val
profile
=
DirectBoot
.
getDeviceProfile
()
!!
.
toList
().
filterNotNull
().
single
{
it
.
id
==
id
}
profile
.
tx
+=
current
.
txTotal
profile
.
rx
+=
current
.
rxTotal
profile
.
dirty
=
true
DirectBoot
.
update
(
profile
)
DirectBoot
.
listenForUnlock
()
}
}
}
}
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