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
5e0d5232
Commit
5e0d5232
authored
Nov 24, 2015
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add traffic to notification
parent
118aa127
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
23 deletions
+37
-23
src/main/res/values/strings.xml
src/main/res/values/strings.xml
+1
-0
src/main/scala/com/github/shadowsocks/BaseService.scala
src/main/scala/com/github/shadowsocks/BaseService.scala
+1
-1
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+1
-1
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
.../scala/com/github/shadowsocks/ShadowsocksNatService.scala
+1
-1
src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala
...cala/com/github/shadowsocks/ShadowsocksNotification.scala
+32
-19
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
.../scala/com/github/shadowsocks/ShadowsocksVpnService.scala
+1
-1
No files found.
src/main/res/values/strings.xml
View file @
5e0d5232
...
...
@@ -15,6 +15,7 @@
<string
name=
"stat"
>
Network Traffic
</string>
<string
name=
"stat_summary"
>
Sent: \t\t\t\t\t%3$s\t↑\t%1$s/s\nReceived: \t%4$s\t↓\t%2$s/s
</string>
<string
name=
"stat_profiles"
>
\n%1$s↑\t%2$s↓
</string>
<string
name=
"traffic_summary"
>
%1$s/s↑\t%2$s/s↓
</string>
<plurals
name=
"bytes"
>
<item
quantity=
"one"
>
Byte
</item>
<item
quantity=
"other"
>
Bytes
</item>
...
...
src/main/scala/com/github/shadowsocks/BaseService.scala
View file @
5e0d5232
...
...
@@ -58,7 +58,7 @@ trait BaseService extends Service {
final
val
callbacks
=
new
RemoteCallbackList
[
IShadowsocksServiceCallback
]
protected
val
binder
=
new
IShadowsocksService
.
Stub
{
val
binder
=
new
IShadowsocksService
.
Stub
{
override
def
getMode
:
Int
=
{
getServiceMode
}
...
...
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
5e0d5232
...
...
@@ -346,7 +346,7 @@ class Shadowsocks
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
layout_main
)
// Initialize
action
bar
// Initialize
Tool
bar
val
toolbar
=
findViewById
(
R
.
id
.
toolbar
).
asInstanceOf
[
Toolbar
]
toolbar
.
setTitle
(
getString
(
R
.
string
.
screen_name
))
toolbar
.
setTitleTextAppearance
(
toolbar
.
getContext
,
R
.
style
.
Toolbar_Logo
)
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
View file @
5e0d5232
...
...
@@ -453,8 +453,8 @@ class ShadowsocksNatService extends BaseService {
// Set DNS
flushDns
()
notification
=
new
ShadowsocksNotification
(
this
,
config
.
profileName
,
true
)
changeState
(
State
.
CONNECTED
)
notification
=
new
ShadowsocksNotification
(
this
,
config
.
profileName
,
true
)
}
else
{
changeState
(
State
.
STOPPED
,
getString
(
R
.
string
.
service_failed
))
stopRunner
()
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksNotification.scala
View file @
5e0d5232
...
...
@@ -7,54 +7,66 @@ import android.content.{BroadcastReceiver, Context, Intent, IntentFilter}
import
android.support.v4.app.NotificationCompat
import
android.support.v4.app.NotificationCompat.BigTextStyle
import
android.support.v4.content.ContextCompat
import
com.github.shadowsocks.aidl.IShadowsocksServiceCallback.Stub
import
com.github.shadowsocks.utils.
{
Action
,
State
,
Utils
}
/**
* @author Mygod
*/
class
ShadowsocksNotification
(
private
val
service
:
BaseService
,
profileName
:
String
,
visible
:
Boolean
=
false
)
{
class
ShadowsocksNotification
(
private
val
service
:
BaseService
,
profileName
:
String
,
visible
:
Boolean
=
false
,
private
val
showTraffic
:
Boolean
=
true
)
{
private
lazy
val
keyGuard
=
service
.
getSystemService
(
Context
.
KEYGUARD_SERVICE
).
asInstanceOf
[
KeyguardManager
]
private
lazy
val
callback
=
new
Stub
{
override
def
stateChanged
(
state
:
Int
,
msg
:
String
)
=
()
// ignore
override
def
trafficUpdated
(
txRate
:
String
,
rxRate
:
String
,
txTotal
:
String
,
rxTotal
:
String
)
{
builder
.
setContentText
(
service
.
getString
(
R
.
string
.
traffic_summary
).
formatLocal
(
Locale
.
ENGLISH
,
txRate
,
rxRate
))
style
.
bigText
(
service
.
getString
(
R
.
string
.
stat_summary
)
.
formatLocal
(
Locale
.
ENGLISH
,
txRate
,
rxRate
,
txTotal
,
rxTotal
))
show
()
}
}
private
var
lockReceiver
:
BroadcastReceiver
=
_
private
val
builder
=
new
NotificationCompat
.
Builder
(
service
)
.
setWhen
(
0
)
.
setColor
(
ContextCompat
.
getColor
(
service
,
R
.
color
.
material_accent_500
))
.
setTicker
(
service
.
getString
(
R
.
string
.
forward_success
))
.
setContentTitle
(
service
.
getString
(
R
.
string
.
app_name
))
.
setContentText
(
service
.
getString
(
R
.
string
.
service_running
).
formatLocal
(
Locale
.
ENGLISH
,
profileName
))
.
setContentTitle
(
service
.
getString
(
R
.
string
.
app_name
)
+
": "
+
profileName
)
.
setContentIntent
(
PendingIntent
.
getActivity
(
service
,
0
,
new
Intent
(
service
,
classOf
[
Shadowsocks
])
.
setFlags
(
Intent
.
FLAG_ACTIVITY_REORDER_TO_FRONT
),
0
))
.
setSmallIcon
(
R
.
drawable
.
ic_stat_shadowsocks
)
.
addAction
(
android
.
R
.
drawable
.
ic_menu_close_clear_cancel
,
service
.
getString
(
R
.
string
.
stop
),
PendingIntent
.
getBroadcast
(
service
,
0
,
new
Intent
(
Action
.
CLOSE
),
0
))
private
val
style
=
new
BigTextStyle
(
builder
)
if
(
visible
&&
Utils
.
isLollipopOrAbove
)
{
private
lazy
val
style
=
new
BigTextStyle
(
builder
)
private
val
showOnUnlock
=
visible
&&
Utils
.
isLollipopOrAbove
if
(
showOnUnlock
||
showTraffic
)
{
update
(
Intent
.
ACTION_USER_PRESENT
)
lockReceiver
=
(
context
:
Context
,
intent
:
Intent
)
=>
update
(
intent
.
getAction
)
val
screenFilter
=
new
IntentFilter
()
screenFilter
.
addAction
(
Intent
.
ACTION_SCREEN_ON
)
screenFilter
.
addAction
(
Intent
.
ACTION_SCREEN_OFF
)
screenFilter
.
addAction
(
Intent
.
ACTION_USER_PRESENT
)
lockReceiver
=
(
context
:
Context
,
intent
:
Intent
)
=>
if
(
service
.
getState
==
State
.
CONNECTED
)
{
val
action
=
intent
.
getAction
if
(
action
==
Intent
.
ACTION_SCREEN_OFF
)
{
setVisible
(
false
).
show
()
}
else
if
(
action
==
Intent
.
ACTION_SCREEN_ON
)
{
if
(!
keyGuard
.
inKeyguardRestrictedInputMode
)
{
setVisible
(
true
).
show
()
}
}
else
if
(
action
==
Intent
.
ACTION_USER_PRESENT
)
{
setVisible
(
true
).
show
()
}
}
service
.
registerReceiver
(
lockReceiver
,
screenFilter
)
}
else
setVisible
(
visible
).
show
()
private
def
update
(
action
:
String
)
=
if
(
service
.
getState
==
State
.
CONNECTED
)
{
if
(
action
==
Intent
.
ACTION_SCREEN_OFF
)
{
if
(
showOnUnlock
)
setVisible
(
false
)
if
(
showTraffic
)
service
.
binder
.
unregisterCallback
(
callback
)
}
else
if
(
action
==
Intent
.
ACTION_USER_PRESENT
||
action
==
Intent
.
ACTION_SCREEN_ON
&&
!
keyGuard
.
inKeyguardRestrictedInputMode
)
{
setVisible
(
showOnUnlock
)
if
(
showTraffic
)
service
.
binder
.
registerCallback
(
callback
)
}
show
()
}
setVisible
(
visible
).
show
()
def
setVisible
(
visible
:
Boolean
)
=
{
builder
.
setPriority
(
if
(
visible
)
NotificationCompat
.
PRIORITY_DEFAULT
else
NotificationCompat
.
PRIORITY_MIN
)
this
}
def
notification
=
style
.
build
()
def
notification
=
if
(
showTraffic
)
style
.
build
()
else
builder
.
build
()
def
show
()
=
service
.
startForeground
(
1
,
notification
)
def
destroy
()
=
{
...
...
@@ -62,6 +74,7 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str
service
.
unregisterReceiver
(
lockReceiver
)
lockReceiver
=
null
}
if
(
showTraffic
)
service
.
binder
.
unregisterCallback
(
callback
)
service
.
stopForeground
(
true
)
}
}
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
View file @
5e0d5232
...
...
@@ -247,8 +247,8 @@ class ShadowsocksVpnService extends VpnService with BaseService {
}
if
(
resolved
&&
handleConnection
)
{
notification
=
new
ShadowsocksNotification
(
this
,
config
.
profileName
)
changeState
(
State
.
CONNECTED
)
notification
=
new
ShadowsocksNotification
(
this
,
config
.
profileName
)
}
else
{
changeState
(
State
.
STOPPED
,
getString
(
R
.
string
.
service_failed
))
stopRunner
()
...
...
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