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
dec098fb
Commit
dec098fb
authored
Dec 18, 2014
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refine the lock screen receiver
parent
000d03ad
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
10 deletions
+51
-10
src/main/scala/com/github/shadowsocks/BaseService.scala
src/main/scala/com/github/shadowsocks/BaseService.scala
+8
-2
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
.../scala/com/github/shadowsocks/ShadowsocksNatService.scala
+42
-7
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
.../scala/com/github/shadowsocks/ShadowsocksVpnService.scala
+1
-1
No files found.
src/main/scala/com/github/shadowsocks/BaseService.scala
View file @
dec098fb
...
...
@@ -49,8 +49,8 @@ import android.content.Context
trait
BaseService
{
@volatile
var
state
=
State
.
INIT
@volatile
var
callbackCount
=
0
@volatile
private
var
state
=
State
.
INIT
@volatile
private
var
callbackCount
=
0
final
val
callbacks
=
new
RemoteCallbackList
[
IShadowsocksServiceCallback
]
...
...
@@ -100,6 +100,12 @@ trait BaseService {
def
getTag
:
String
def
getContext
:
Context
def
getCallbackCount
()
:
Int
=
{
callbackCount
}
def
getState
()
:
Int
=
{
state
}
def
changeState
(
s
:
Int
)
{
changeState
(
s
,
null
)
}
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
View file @
dec098fb
...
...
@@ -43,7 +43,7 @@ import java.io.File
import
java.lang.reflect.
{
InvocationTargetException
,
Method
}
import
java.util.Locale
import
android.app.
{
Notification
,
NotificationManager
,
PendingIntent
,
Service
}
import
android.app.
_
import
android.content._
import
android.content.pm.
{
PackageInfo
,
PackageManager
}
import
android.net.
{
Network
,
ConnectivityManager
}
...
...
@@ -75,6 +75,7 @@ class ShadowsocksNatService extends Service with BaseService {
private
val
mStartForegroundArgs
=
new
Array
[
AnyRef
](
2
)
private
val
mStopForegroundArgs
=
new
Array
[
AnyRef
](
1
)
var
lockReceiver
:
BroadcastReceiver
=
null
var
closeReceiver
:
BroadcastReceiver
=
null
var
connReceiver
:
BroadcastReceiver
=
null
var
notificationManager
:
NotificationManager
=
null
...
...
@@ -327,7 +328,7 @@ class ShadowsocksNatService extends Service with BaseService {
}
}
def
notifyForegroundAlert
(
title
:
String
,
info
:
String
)
{
def
notifyForegroundAlert
(
title
:
String
,
info
:
String
,
visible
:
Boolean
)
{
val
openIntent
=
new
Intent
(
this
,
classOf
[
Shadowsocks
])
openIntent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_REORDER_TO_FRONT
)
val
contentIntent
=
PendingIntent
.
getActivity
(
this
,
0
,
openIntent
,
0
)
...
...
@@ -344,7 +345,11 @@ class ShadowsocksNatService extends Service with BaseService {
.
setSmallIcon
(
R
.
drawable
.
ic_stat_shadowsocks
)
.
addAction
(
android
.
R
.
drawable
.
ic_menu_close_clear_cancel
,
getString
(
R
.
string
.
stop
),
actionIntent
)
.
setPriority
(
NotificationCompat
.
PRIORITY_MIN
)
if
(
visible
)
builder
.
setPriority
(
NotificationCompat
.
PRIORITY_MAX
)
else
builder
.
setPriority
(
NotificationCompat
.
PRIORITY_MIN
)
startForegroundCompat
(
1
,
builder
.
build
)
}
...
...
@@ -500,13 +505,39 @@ class ShadowsocksNatService extends Service with BaseService {
filter
.
addAction
(
Intent
.
ACTION_SHUTDOWN
)
filter
.
addAction
(
Action
.
CLOSE
)
closeReceiver
=
new
BroadcastReceiver
()
{
def
onReceive
(
p1
:
Context
,
p2
:
Intent
)
{
Toast
.
makeText
(
p1
,
R
.
string
.
stopping
,
Toast
.
LENGTH_SHORT
).
show
()
def
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
Toast
.
makeText
(
context
,
R
.
string
.
stopping
,
Toast
.
LENGTH_SHORT
).
show
()
stopRunner
()
}
}
registerReceiver
(
closeReceiver
,
filter
)
val
screenFilter
=
new
IntentFilter
()
screenFilter
.
addAction
(
Intent
.
ACTION_SCREEN_ON
)
screenFilter
.
addAction
(
Intent
.
ACTION_SCREEN_OFF
)
screenFilter
.
addAction
(
Intent
.
ACTION_USER_PRESENT
)
lockReceiver
=
new
BroadcastReceiver
()
{
def
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
if
(
getState
==
State
.
CONNECTED
)
{
val
action
=
intent
.
getAction
if
(
action
==
Intent
.
ACTION_SCREEN_OFF
)
{
notifyForegroundAlert
(
getString
(
R
.
string
.
forward_success
),
getString
(
R
.
string
.
service_running
).
formatLocal
(
Locale
.
ENGLISH
,
config
.
profileName
),
false
)
}
else
if
(
action
==
Intent
.
ACTION_SCREEN_ON
)
{
val
keyGuard
=
getSystemService
(
Context
.
KEYGUARD_SERVICE
).
asInstanceOf
[
KeyguardManager
]
if
(!
keyGuard
.
inKeyguardRestrictedInputMode
)
{
notifyForegroundAlert
(
getString
(
R
.
string
.
forward_success
),
getString
(
R
.
string
.
service_running
).
formatLocal
(
Locale
.
ENGLISH
,
config
.
profileName
),
true
)
}
}
else
if
(
action
==
Intent
.
ACTION_USER_PRESENT
)
{
notifyForegroundAlert
(
getString
(
R
.
string
.
forward_success
),
getString
(
R
.
string
.
service_running
).
formatLocal
(
Locale
.
ENGLISH
,
config
.
profileName
),
true
)
}
}
}
}
registerReceiver
(
lockReceiver
,
screenFilter
)
// send event
application
.
tracker
.
send
(
new
HitBuilders
.
EventBuilder
()
.
setCategory
(
TAG
)
...
...
@@ -554,7 +585,7 @@ class ShadowsocksNatService extends Service with BaseService {
flushDns
()
notifyForegroundAlert
(
getString
(
R
.
string
.
forward_success
),
getString
(
R
.
string
.
service_running
).
formatLocal
(
Locale
.
ENGLISH
,
config
.
profileName
))
getString
(
R
.
string
.
service_running
).
formatLocal
(
Locale
.
ENGLISH
,
config
.
profileName
)
,
true
)
changeState
(
State
.
CONNECTED
)
}
else
{
changeState
(
State
.
STOPPED
,
getString
(
R
.
string
.
service_failed
))
...
...
@@ -574,6 +605,10 @@ class ShadowsocksNatService extends Service with BaseService {
unregisterReceiver
(
closeReceiver
)
closeReceiver
=
null
}
if
(
lockReceiver
!=
null
)
{
unregisterReceiver
(
lockReceiver
)
lockReceiver
=
null
}
// send event
application
.
tracker
.
send
(
new
HitBuilders
.
EventBuilder
()
...
...
@@ -586,7 +621,7 @@ class ShadowsocksNatService extends Service with BaseService {
killProcesses
()
// stop the service if no callback registered
if
(
c
allbackCount
==
0
)
{
if
(
getC
allbackCount
==
0
)
{
stopSelf
()
}
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
View file @
dec098fb
...
...
@@ -479,7 +479,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
}
// stop the service if no callback registered
if
(
c
allbackCount
==
0
)
{
if
(
getC
allbackCount
==
0
)
{
stopSelf
()
}
...
...
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