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
8dcfd5a8
Commit
8dcfd5a8
authored
Dec 26, 2015
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce battery usage - prevent unnecessary notification updates
parent
ef162cd4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
9 deletions
+34
-9
src/main/scala/com/github/shadowsocks/BaseService.scala
src/main/scala/com/github/shadowsocks/BaseService.scala
+4
-2
src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
...n/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
+30
-7
No files found.
src/main/scala/com/github/shadowsocks/BaseService.scala
View file @
8dcfd5a8
...
...
@@ -86,8 +86,7 @@ trait BaseService extends Service {
if
(
callbackCount
==
0
&&
timer
==
null
)
{
val
task
=
new
TimerTask
{
def
run
{
TrafficMonitor
.
updateRate
()
updateTrafficRate
()
if
(
TrafficMonitor
.
updateRate
())
updateTrafficRate
()
}
}
timer
=
new
Timer
(
true
)
...
...
@@ -95,6 +94,9 @@ trait BaseService extends Service {
}
callbacks
.
register
(
cb
)
callbackCount
+=
1
TrafficMonitor
.
updateRate
()
cb
.
trafficUpdated
(
TrafficMonitor
.
getTxRate
,
TrafficMonitor
.
getRxRate
,
TrafficMonitor
.
getTxTotal
,
TrafficMonitor
.
getRxTotal
)
}
}
...
...
src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
View file @
8dcfd5a8
...
...
@@ -18,6 +18,7 @@ object TrafficMonitor {
var
txLast
:
Long
=
_
var
rxLast
:
Long
=
_
var
timestampLast
:
Long
=
_
@volatile
var
dirty
=
true
private
val
units
=
Array
(
"KB"
,
"MB"
,
"GB"
,
"TB"
,
"PB"
,
"EB"
,
"ZB"
,
"YB"
,
"BB"
,
"NB"
,
"DB"
,
"CB"
)
private
val
numberFormat
=
new
DecimalFormat
(
"@@@"
)
...
...
@@ -32,21 +33,42 @@ object TrafficMonitor {
else
numberFormat
.
format
(
n
)
+
' '
+
units
(
i
)
}
def
updateRate
()
{
def
updateRate
()
=
{
val
now
=
System
.
currentTimeMillis
()
val
delta
=
now
-
timestampLast
var
updated
=
false
if
(
delta
!=
0
)
{
txRate
=
(
txTotal
-
txLast
)
*
1000
/
delta
rxRate
=
(
rxTotal
-
rxLast
)
*
1000
/
delta
txLast
=
txTotal
rxLast
=
rxTotal
if
(
dirty
)
{
txRate
=
(
txTotal
-
txLast
)
*
1000
/
delta
rxRate
=
(
rxTotal
-
rxLast
)
*
1000
/
delta
txLast
=
txTotal
rxLast
=
rxTotal
dirty
=
false
updated
=
true
}
else
{
if
(
txRate
!=
0
)
{
txRate
=
0
updated
=
true
}
if
(
rxRate
!=
0
)
{
rxRate
=
0
updated
=
true
}
}
timestampLast
=
now
}
updated
}
def
update
(
tx
:
Long
,
rx
:
Long
)
{
txTotal
=
tx
rxTotal
=
rx
if
(
txTotal
!=
tx
)
{
txTotal
=
tx
dirty
=
true
}
if
(
rxTotal
!=
rx
)
{
rxTotal
=
rx
dirty
=
true
}
}
def
reset
()
{
...
...
@@ -56,6 +78,7 @@ object TrafficMonitor {
rxTotal
=
0
txLast
=
0
rxLast
=
0
dirty
=
true
}
def
getTxTotal
()
:
String
=
{
...
...
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