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
ff23bae6
Commit
ff23bae6
authored
Nov 21, 2015
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #424
parent
e636b9f7
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
8 deletions
+46
-8
src/main/aidl/com/github/shadowsocks/aidl/Config.java
src/main/aidl/com/github/shadowsocks/aidl/Config.java
+6
-1
src/main/scala/com/github/shadowsocks/BaseService.scala
src/main/scala/com/github/shadowsocks/BaseService.scala
+21
-1
src/main/scala/com/github/shadowsocks/database/ProfileManager.scala
...cala/com/github/shadowsocks/database/ProfileManager.scala
+7
-3
src/main/scala/com/github/shadowsocks/utils/ConfigUtils.scala
...main/scala/com/github/shadowsocks/utils/ConfigUtils.scala
+4
-2
src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
...n/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
+6
-0
src/main/scala/com/github/shadowsocks/utils/TrafficMonitorThread.scala
...a/com/github/shadowsocks/utils/TrafficMonitorThread.scala
+2
-1
No files found.
src/main/aidl/com/github/shadowsocks/aidl/Config.java
View file @
ff23bae6
...
@@ -22,6 +22,8 @@ public class Config implements Parcelable {
...
@@ -22,6 +22,8 @@ public class Config implements Parcelable {
public
int
remotePort
=
1984
;
public
int
remotePort
=
1984
;
public
int
localPort
=
1080
;
public
int
localPort
=
1080
;
public
int
profileId
=
0
;
public
static
final
Parcelable
.
Creator
<
Config
>
CREATOR
=
new
Parcelable
.
Creator
<
Config
>()
{
public
static
final
Parcelable
.
Creator
<
Config
>
CREATOR
=
new
Parcelable
.
Creator
<
Config
>()
{
public
Config
createFromParcel
(
Parcel
in
)
{
public
Config
createFromParcel
(
Parcel
in
)
{
return
new
Config
(
in
);
return
new
Config
(
in
);
...
@@ -34,7 +36,7 @@ public class Config implements Parcelable {
...
@@ -34,7 +36,7 @@ public class Config implements Parcelable {
public
Config
(
boolean
isProxyApps
,
boolean
isBypassApps
,
public
Config
(
boolean
isProxyApps
,
boolean
isBypassApps
,
boolean
isUdpDns
,
boolean
isAuth
,
boolean
isIpv6
,
String
profileName
,
String
proxy
,
String
sitekey
,
boolean
isUdpDns
,
boolean
isAuth
,
boolean
isIpv6
,
String
profileName
,
String
proxy
,
String
sitekey
,
String
encMethod
,
String
proxiedAppString
,
String
route
,
int
remotePort
,
int
localPort
)
{
String
encMethod
,
String
proxiedAppString
,
String
route
,
int
remotePort
,
int
localPort
,
int
profileId
)
{
this
.
isProxyApps
=
isProxyApps
;
this
.
isProxyApps
=
isProxyApps
;
this
.
isBypassApps
=
isBypassApps
;
this
.
isBypassApps
=
isBypassApps
;
this
.
isUdpDns
=
isUdpDns
;
this
.
isUdpDns
=
isUdpDns
;
...
@@ -48,6 +50,7 @@ public class Config implements Parcelable {
...
@@ -48,6 +50,7 @@ public class Config implements Parcelable {
this
.
route
=
route
;
this
.
route
=
route
;
this
.
remotePort
=
remotePort
;
this
.
remotePort
=
remotePort
;
this
.
localPort
=
localPort
;
this
.
localPort
=
localPort
;
this
.
profileId
=
profileId
;
}
}
private
Config
(
Parcel
in
)
{
private
Config
(
Parcel
in
)
{
...
@@ -68,6 +71,7 @@ public class Config implements Parcelable {
...
@@ -68,6 +71,7 @@ public class Config implements Parcelable {
route
=
in
.
readString
();
route
=
in
.
readString
();
remotePort
=
in
.
readInt
();
remotePort
=
in
.
readInt
();
localPort
=
in
.
readInt
();
localPort
=
in
.
readInt
();
profileId
=
in
.
readInt
();
}
}
@Override
public
int
describeContents
()
{
@Override
public
int
describeContents
()
{
...
@@ -88,5 +92,6 @@ public class Config implements Parcelable {
...
@@ -88,5 +92,6 @@ public class Config implements Parcelable {
out
.
writeString
(
route
);
out
.
writeString
(
route
);
out
.
writeInt
(
remotePort
);
out
.
writeInt
(
remotePort
);
out
.
writeInt
(
localPort
);
out
.
writeInt
(
localPort
);
out
.
writeInt
(
profileId
);
}
}
}
}
src/main/scala/com/github/shadowsocks/BaseService.scala
View file @
ff23bae6
...
@@ -44,6 +44,9 @@ import java.util.{Timer, TimerTask}
...
@@ -44,6 +44,9 @@ import java.util.{Timer, TimerTask}
import
android.app.Notification
import
android.app.Notification
import
android.content.Context
import
android.content.Context
import
android.os.
{
Handler
,
RemoteCallbackList
}
import
android.os.
{
Handler
,
RemoteCallbackList
}
import
android.util.Log
import
com.github.shadowsocks.database.
{
Profile
,
ProfileManager
}
import
com.github.shadowsocks.aidl.
{
Config
,
IShadowsocksService
,
IShadowsocksServiceCallback
}
import
com.github.shadowsocks.aidl.
{
Config
,
IShadowsocksService
,
IShadowsocksServiceCallback
}
import
com.github.shadowsocks.utils.
{
State
,
TrafficMonitor
,
TrafficMonitorThread
}
import
com.github.shadowsocks.utils.
{
State
,
TrafficMonitor
,
TrafficMonitorThread
}
...
@@ -127,6 +130,23 @@ trait BaseService {
...
@@ -127,6 +130,23 @@ trait BaseService {
}
}
}
}
def
updateTrafficTotal
(
tx
:
Long
,
rx
:
Long
)
{
val
handler
=
new
Handler
(
getContext
.
getMainLooper
)
handler
.
post
(()
=>
{
if
(
config
!=
null
)
{
ShadowsocksApplication
.
profileManager
.
getProfile
(
config
.
profileId
)
match
{
case
Some
(
profile
)
=>
{
profile
.
tx
+=
tx
;
profile
.
rx
+=
rx
;
Log
.
d
(
"test"
,
profile
.
tx
+
" "
+
profile
.
rx
)
ShadowsocksApplication
.
profileManager
.
updateProfile
(
profile
)
}
case
None
=>
// Ignore
}
}
})
}
def
clearChildProcessStream
()
def
clearChildProcessStream
()
def
stopBackgroundService
()
def
stopBackgroundService
()
def
getServiceMode
:
Int
def
getServiceMode
:
Int
...
@@ -143,7 +163,7 @@ trait BaseService {
...
@@ -143,7 +163,7 @@ trait BaseService {
changeState
(
s
,
null
)
changeState
(
s
,
null
)
}
}
def
updateTraffic
(
txRate
:
String
,
rxRate
:
String
,
txTotal
:
String
,
rxTotal
:
String
)
{
def
updateTraffic
Rate
(
txRate
:
String
,
rxRate
:
String
,
txTotal
:
String
,
rxTotal
:
String
)
{
val
handler
=
new
Handler
(
getContext
.
getMainLooper
)
val
handler
=
new
Handler
(
getContext
.
getMainLooper
)
handler
.
post
(()
=>
{
handler
.
post
(()
=>
{
if
(
callbackCount
>
0
)
{
if
(
callbackCount
>
0
)
{
...
...
src/main/scala/com/github/shadowsocks/database/ProfileManager.scala
View file @
ff23bae6
...
@@ -79,7 +79,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
...
@@ -79,7 +79,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
true
true
}
catch
{
}
catch
{
case
ex
:
Exception
=>
case
ex
:
Exception
=>
Log
.
e
(
Shadowsocks
.
TAG
,
"
add
Profile"
,
ex
)
Log
.
e
(
Shadowsocks
.
TAG
,
"
update
Profile"
,
ex
)
false
false
}
}
}
}
...
@@ -149,9 +149,13 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
...
@@ -149,9 +149,13 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
}
}
private
def
loadFromPreferences
:
Profile
=
{
private
def
loadFromPreferences
:
Profile
=
{
val
profile
=
new
Profile
()
profile
.
id
=
settings
.
getInt
(
Key
.
profileId
,
-
1
)
val
id
=
settings
.
getInt
(
Key
.
profileId
,
-
1
)
val
profile
:
Profile
=
getProfile
(
id
)
match
{
case
Some
(
p
)
=>
p
case
_
=>
new
Profile
()
}
profile
.
proxyApps
=
settings
.
getBoolean
(
Key
.
isProxyApps
,
false
)
profile
.
proxyApps
=
settings
.
getBoolean
(
Key
.
isProxyApps
,
false
)
profile
.
bypass
=
settings
.
getBoolean
(
Key
.
isBypassApps
,
false
)
profile
.
bypass
=
settings
.
getBoolean
(
Key
.
isBypassApps
,
false
)
...
...
src/main/scala/com/github/shadowsocks/utils/ConfigUtils.scala
View file @
ff23bae6
...
@@ -239,7 +239,7 @@ object ConfigUtils {
...
@@ -239,7 +239,7 @@ object ConfigUtils {
val
method
=
proxy
(
3
).
trim
val
method
=
proxy
(
3
).
trim
new
Config
(
config
.
isProxyApps
,
config
.
isBypassApps
,
config
.
isUdpDns
,
config
.
isAuth
,
config
.
isIpv6
,
new
Config
(
config
.
isProxyApps
,
config
.
isBypassApps
,
config
.
isUdpDns
,
config
.
isAuth
,
config
.
isIpv6
,
config
.
profileName
,
host
,
password
,
method
,
config
.
proxiedAppString
,
config
.
route
,
port
,
config
.
localPort
)
config
.
profileName
,
host
,
password
,
method
,
config
.
proxiedAppString
,
config
.
route
,
port
,
config
.
localPort
,
0
)
}
}
def
load
(
settings
:
SharedPreferences
)
:
Config
=
{
def
load
(
settings
:
SharedPreferences
)
:
Config
=
{
...
@@ -259,7 +259,9 @@ object ConfigUtils {
...
@@ -259,7 +259,9 @@ object ConfigUtils {
val
localPort
=
settings
.
getInt
(
Key
.
localPort
,
1984
)
val
localPort
=
settings
.
getInt
(
Key
.
localPort
,
1984
)
val
proxiedAppString
=
settings
.
getString
(
Key
.
proxied
,
""
)
val
proxiedAppString
=
settings
.
getString
(
Key
.
proxied
,
""
)
val
profileId
=
settings
.
getInt
(
Key
.
profileId
,
-
1
)
new
Config
(
isProxyApps
,
isBypassApps
,
isUdpDns
,
isAuth
,
isIpv6
,
profileName
,
proxy
,
sitekey
,
encMethod
,
new
Config
(
isProxyApps
,
isBypassApps
,
isUdpDns
,
isAuth
,
isIpv6
,
profileName
,
proxy
,
sitekey
,
encMethod
,
proxiedAppString
,
route
,
remotePort
,
localPort
)
proxiedAppString
,
route
,
remotePort
,
localPort
,
profileId
)
}
}
}
}
src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
View file @
ff23bae6
...
@@ -18,6 +18,10 @@ object TrafficMonitor {
...
@@ -18,6 +18,10 @@ object TrafficMonitor {
var
txTotal
:
Long
=
0
var
txTotal
:
Long
=
0
var
rxTotal
:
Long
=
0
var
rxTotal
:
Long
=
0
// Kilo bytes for the last query
var
txLast
:
Long
=
0
var
rxLast
:
Long
=
0
def
getTraffic
(
tx
:
Long
,
rx
:
Long
)
:
Traffic
=
{
def
getTraffic
(
tx
:
Long
,
rx
:
Long
)
:
Traffic
=
{
new
Traffic
(
tx
,
rx
,
System
.
currentTimeMillis
())
new
Traffic
(
tx
,
rx
,
System
.
currentTimeMillis
())
}
}
...
@@ -42,6 +46,8 @@ object TrafficMonitor {
...
@@ -42,6 +46,8 @@ object TrafficMonitor {
txRate
=
(
now
.
tx
-
last
.
tx
)
*
1000
/
delta
txRate
=
(
now
.
tx
-
last
.
tx
)
*
1000
/
delta
rxRate
=
(
now
.
rx
-
last
.
rx
)
*
1000
/
delta
rxRate
=
(
now
.
rx
-
last
.
rx
)
*
1000
/
delta
}
}
txLast
=
now
.
tx
-
last
.
tx
rxLast
=
now
.
rx
-
last
.
rx
txTotal
+=
now
.
tx
-
last
.
tx
txTotal
+=
now
.
tx
-
last
.
tx
rxTotal
+=
now
.
rx
-
last
.
rx
rxTotal
+=
now
.
rx
-
last
.
rx
last
=
now
last
=
now
...
...
src/main/scala/com/github/shadowsocks/utils/TrafficMonitorThread.scala
View file @
ff23bae6
...
@@ -108,8 +108,9 @@ class TrafficMonitorThread(service: BaseService) extends Thread {
...
@@ -108,8 +108,9 @@ class TrafficMonitorThread(service: BaseService) extends Thread {
val
stat
=
new
String
(
array
,
"UTF-8"
).
split
(
"\\|"
)
val
stat
=
new
String
(
array
,
"UTF-8"
).
split
(
"\\|"
)
if
(
stat
.
length
==
2
)
{
if
(
stat
.
length
==
2
)
{
TrafficMonitor
.
update
(
stat
(
0
).
toLong
,
stat
(
1
).
toLong
)
TrafficMonitor
.
update
(
stat
(
0
).
toLong
,
stat
(
1
).
toLong
)
service
.
updateTraffic
(
TrafficMonitor
.
getTxRate
,
TrafficMonitor
.
getRxRate
,
service
.
updateTraffic
Rate
(
TrafficMonitor
.
getTxRate
,
TrafficMonitor
.
getRxRate
,
TrafficMonitor
.
getTxTotal
,
TrafficMonitor
.
getRxTotal
)
TrafficMonitor
.
getTxTotal
,
TrafficMonitor
.
getRxTotal
)
service
.
updateTrafficTotal
(
TrafficMonitor
.
txLast
,
TrafficMonitor
.
rxLast
)
}
}
output
.
write
(
0
)
output
.
write
(
0
)
...
...
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