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
394860a8
Commit
394860a8
authored
Jul 01, 2013
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix traffic stats
parent
a7b2bd57
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
33 deletions
+57
-33
project/Build.scala
project/Build.scala
+2
-2
src/main/res/values/strings.xml
src/main/res/values/strings.xml
+2
-0
src/main/res/xml/pref_feature.xml
src/main/res/xml/pref_feature.xml
+6
-0
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+2
-2
src/main/scala/com/github/shadowsocks/ShadowsocksService.scala
...ain/scala/com/github/shadowsocks/ShadowsocksService.scala
+36
-27
src/main/scala/com/github/shadowsocks/Utils.scala
src/main/scala/com/github/shadowsocks/Utils.scala
+9
-2
No files found.
project/Build.scala
View file @
394860a8
...
...
@@ -5,8 +5,8 @@ import sbtandroid._
import
sbtandroid.AndroidKeys._
object
App
{
val
version
=
"1.7.
0
"
val
versionCode
=
3
7
val
version
=
"1.7.
1
"
val
versionCode
=
3
8
}
object
General
{
...
...
src/main/res/values/strings.xml
View file @
394860a8
...
...
@@ -40,6 +40,8 @@
<string
name=
"bypass_apps_summary"
>
Enable this option to bypass selected apps
</string>
<string
name=
"auto_connect"
>
Auto Connect
</string>
<string
name=
"auto_connect_summary"
>
Enable Shadowsocks on startup
</string>
<string
name=
"traffic_stat"
>
Traffic Stats
</string>
<string
name=
"traffic_stat_summary"
>
Show traffic stats on notification bar
</string>
<!-- notification category -->
<string
name=
"forward_success"
>
Shadowsocks started.
</string>
...
...
src/main/res/xml/pref_feature.xml
View file @
394860a8
...
...
@@ -28,6 +28,12 @@
android:title=
"@string/proxied_apps"
>
<intent
android:action=
"com.github.shadowsocks.AppManager"
/>
</Preference>
<CheckBoxPreference
android:key=
"isTrafficStat"
android:defaultValue=
"true"
android:summary=
"@string/traffic_stat_summary"
android:title=
"@string/traffic_stat"
>
</CheckBoxPreference>
<CheckBoxPreference
android:key=
"isAutoConnect"
android:summary=
"@string/auto_connect_summary"
...
...
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
394860a8
...
...
@@ -136,7 +136,7 @@ object Shadowsocks {
if
(
pref
!=
null
)
{
val
status
=
getActivity
.
getSharedPreferences
(
Key
.
status
,
Context
.
MODE_PRIVATE
)
val
isRoot
=
status
.
getBoolean
(
Key
.
isRoot
,
false
)
if
(
Seq
(
Key
.
isAutoConnect
,
Key
.
isGlobalProxy
,
if
(
Seq
(
Key
.
isAutoConnect
,
Key
.
isGlobalProxy
,
Key
.
isTrafficStat
,
Key
.
isBypassApps
,
Key
.
proxyedApps
).
contains
(
name
))
{
pref
.
setEnabled
(
enabled
&&
isRoot
)
}
else
{
...
...
@@ -506,7 +506,7 @@ class Shadowsocks
for
(
name
<-
Shadowsocks
.
FEATRUE_PREFS
)
{
val
pref
=
findPreference
(
name
)
if
(
pref
!=
null
)
{
if
(
Seq
(
Key
.
isAutoConnect
,
Key
.
isGlobalProxy
,
if
(
Seq
(
Key
.
isAutoConnect
,
Key
.
isGlobalProxy
,
Key
.
isTrafficStat
,
Key
.
isBypassApps
,
Key
.
proxyedApps
).
contains
(
name
))
{
pref
.
setEnabled
(
enabled
&&
isRoot
)
}
else
{
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksService.scala
View file @
394860a8
...
...
@@ -105,7 +105,7 @@ class ShadowsocksService extends Service {
private
var
last
:
TrafficStat
=
null
private
var
lastTxRate
=
0
private
var
lastRxRate
=
0
private
va
l
timer
=
new
Timer
(
true
)
private
va
r
timer
:
Timer
=
null
private
val
TIMER_INTERVAL
=
1
private
def
changeState
(
s
:
Int
)
{
...
...
@@ -193,6 +193,32 @@ class ShadowsocksService extends Service {
config
=
Extra
.
get
(
intent
)
if
(
config
.
isTrafficStat
)
{
// initialize timer
val
task
=
new
TimerTask
{
def
run
()
{
val
now
=
new
TrafficStat
(
TrafficStats
.
getTotalTxBytes
,
TrafficStats
.
getTotalRxBytes
,
java
.
lang
.
System
.
currentTimeMillis
())
val
txRate
=
((
now
.
tx
-
last
.
tx
)
/
1024
/
TIMER_INTERVAL
).
toInt
val
rxRate
=
((
now
.
rx
-
last
.
rx
)
/
1024
/
TIMER_INTERVAL
).
toInt
last
=
now
if
(
lastTxRate
==
txRate
&&
lastRxRate
==
rxRate
)
{
return
}
else
{
lastTxRate
=
txRate
lastRxRate
=
rxRate
}
if
(
state
==
State
.
CONNECTED
)
{
notifyForegroundAlert
(
getString
(
R
.
string
.
forward_success
),
getString
(
R
.
string
.
service_status
).
format
(
txRate
,
rxRate
),
txRate
+
rxRate
)
}
}
}
last
=
new
TrafficStat
(
TrafficStats
.
getTotalTxBytes
,
TrafficStats
.
getTotalRxBytes
,
java
.
lang
.
System
.
currentTimeMillis
())
timer
=
new
Timer
(
true
)
timer
.
schedule
(
task
,
TIMER_INTERVAL
*
1000
,
TIMER_INTERVAL
*
1000
)
}
spawn
{
killProcesses
()
...
...
@@ -308,7 +334,9 @@ class ShadowsocksService extends Service {
bitmap
.
getHeight
-
(
bitmap
.
getHeight
-
bounds
.
height
())
/
2
,
paint
)
builder
.
setLargeIcon
(
bitmap
)
if
(
rate
<
1000
)
{
if
(
rate
==
0
)
{
builder
.
setSmallIcon
(
R
.
drawable
.
ic_stat_shadowsocks
)
}
else
if
(
rate
<
1000
)
{
builder
.
setSmallIcon
(
R
.
drawable
.
ic_stat_speed
,
rate
)
}
else
if
(
rate
<=
10000
)
{
val
mb
=
rate
/
100
-
10
+
1000
...
...
@@ -390,38 +418,19 @@ class ShadowsocksService extends Service {
}
}
registerReceiver
(
receiver
,
filter
)
// initialize timer
val
task
=
new
TimerTask
{
def
run
()
{
val
now
=
new
TrafficStat
(
TrafficStats
.
getUidTxBytes
(
getApplicationInfo
.
uid
),
TrafficStats
.
getUidRxBytes
(
getApplicationInfo
.
uid
),
java
.
lang
.
System
.
currentTimeMillis
())
val
txRate
=
((
now
.
tx
-
last
.
tx
)
/
1024
/
TIMER_INTERVAL
).
toInt
val
rxRate
=
((
now
.
rx
-
last
.
rx
)
/
1024
/
TIMER_INTERVAL
).
toInt
last
=
now
if
(
lastTxRate
==
txRate
&&
lastRxRate
==
rxRate
)
{
return
}
else
{
lastTxRate
=
txRate
lastRxRate
=
rxRate
}
if
(
state
==
State
.
CONNECTED
)
{
notifyForegroundAlert
(
getString
(
R
.
string
.
forward_success
),
getString
(
R
.
string
.
service_status
).
format
(
txRate
,
rxRate
),
txRate
+
rxRate
)
}
}
}
last
=
new
TrafficStat
(
TrafficStats
.
getUidTxBytes
(
getApplicationInfo
.
uid
),
TrafficStats
.
getUidRxBytes
(
getApplicationInfo
.
uid
),
java
.
lang
.
System
.
currentTimeMillis
())
timer
.
schedule
(
task
,
TIMER_INTERVAL
*
1000
,
TIMER_INTERVAL
*
1000
)
}
/** Called when the activity is closed. */
override
def
onDestroy
()
{
// reset timer
if
(
timer
!=
null
)
{
timer
.
cancel
()
timer
=
null
}
// clean up context
changeState
(
State
.
STOPPED
)
timer
.
cancel
()
EasyTracker
.
getTracker
.
setStartSession
(
false
)
EasyTracker
.
getTracker
.
sendEvent
(
TAG
,
"stop"
,
getVersionName
,
0L
)
stopForegroundCompat
(
1
)
...
...
src/main/scala/com/github/shadowsocks/Utils.scala
View file @
394860a8
...
...
@@ -104,7 +104,7 @@ object Config {
}
}
case
class
Config
(
isGlobalProxy
:
Boolean
,
isGFWList
:
Boolean
,
isBypassApps
:
Boolean
,
case
class
Config
(
isGlobalProxy
:
Boolean
,
isGFWList
:
Boolean
,
isBypassApps
:
Boolean
,
isTrafficStat
:
Boolean
,
var
proxy
:
String
,
sitekey
:
String
,
encMethod
:
String
,
remotePort
:
Int
,
localPort
:
Int
,
proxiedAppString
:
String
)
...
...
@@ -121,6 +121,7 @@ object Key {
val
isGlobalProxy
=
"isGlobalProxy"
val
isGFWList
=
"isGFWList"
val
isBypassApps
=
"isBypassApps"
val
isTrafficStat
=
"isTrafficStat"
val
proxy
=
"proxy"
val
sitekey
=
"sitekey"
...
...
@@ -152,6 +153,7 @@ object Extra {
edit
.
putBoolean
(
Key
.
isGlobalProxy
,
config
.
isGlobalProxy
)
edit
.
putBoolean
(
Key
.
isGFWList
,
config
.
isGFWList
)
edit
.
putBoolean
(
Key
.
isBypassApps
,
config
.
isBypassApps
)
edit
.
putBoolean
(
Key
.
isTrafficStat
,
config
.
isTrafficStat
)
edit
.
putString
(
Key
.
proxy
,
config
.
proxy
)
edit
.
putString
(
Key
.
sitekey
,
config
.
sitekey
)
...
...
@@ -166,6 +168,8 @@ object Extra {
val
isGlobalProxy
=
intent
.
getBooleanExtra
(
Key
.
isGlobalProxy
,
false
)
val
isGFWList
=
intent
.
getBooleanExtra
(
Key
.
isGFWList
,
false
)
val
isBypassApps
=
intent
.
getBooleanExtra
(
Key
.
isBypassApps
,
false
)
val
isTrafficStat
=
intent
.
getBooleanExtra
(
Key
.
isTrafficStat
,
false
)
val
proxy
=
intent
.
getStringExtra
(
Key
.
proxy
)
val
sitekey
=
intent
.
getStringExtra
(
Key
.
sitekey
)
val
encMethod
=
intent
.
getStringExtra
(
Key
.
encMethod
)
...
...
@@ -173,7 +177,7 @@ object Extra {
val
localPort
=
intent
.
getIntExtra
(
Key
.
localPort
,
1984
)
val
proxiedString
=
intent
.
getStringExtra
(
Key
.
proxied
)
new
Config
(
isGlobalProxy
,
isGFWList
,
isBypassApps
,
proxy
,
sitekey
,
encMethod
,
remotePort
,
new
Config
(
isGlobalProxy
,
isGFWList
,
isBypassApps
,
isTrafficStat
,
proxy
,
sitekey
,
encMethod
,
remotePort
,
localPort
,
proxiedString
)
}
...
...
@@ -181,6 +185,8 @@ object Extra {
val
isGlobalProxy
=
settings
.
getBoolean
(
Key
.
isGlobalProxy
,
false
)
val
isGFWList
=
settings
.
getBoolean
(
Key
.
isGFWList
,
false
)
val
isBypassApps
=
settings
.
getBoolean
(
Key
.
isBypassApps
,
false
)
val
isTrafficStat
=
settings
.
getBoolean
(
Key
.
isTrafficStat
,
false
)
val
proxy
=
settings
.
getString
(
Key
.
proxy
,
"127.0.0.1"
)
match
{
case
"198.199.101.152"
=>
if
(!
BuildConfig
.
DEBUG
)
"ss.maxcdn.info"
else
"198.199.101.152"
case
s
:
String
=>
s
...
...
@@ -207,6 +213,7 @@ object Extra {
intent
.
putExtra
(
Key
.
isGlobalProxy
,
isGlobalProxy
)
intent
.
putExtra
(
Key
.
isGFWList
,
isGFWList
)
intent
.
putExtra
(
Key
.
isBypassApps
,
isBypassApps
)
intent
.
putExtra
(
Key
.
isTrafficStat
,
isTrafficStat
)
intent
.
putExtra
(
Key
.
proxy
,
proxy
)
intent
.
putExtra
(
Key
.
sitekey
,
sitekey
)
...
...
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