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
ee48c077
Commit
ee48c077
authored
Mar 12, 2016
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Automatic service restart
parent
8fd8514c
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
74 additions
and
103 deletions
+74
-103
src/main/aidl/com/github/shadowsocks/aidl/IShadowsocksService.aidl
...aidl/com/github/shadowsocks/aidl/IShadowsocksService.aidl
+1
-2
src/main/scala/com/github/shadowsocks/BaseService.scala
src/main/scala/com/github/shadowsocks/BaseService.scala
+35
-14
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+20
-22
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
.../scala/com/github/shadowsocks/ShadowsocksNatService.scala
+0
-18
src/main/scala/com/github/shadowsocks/ShadowsocksQuickSwitchActivity.scala
...m/github/shadowsocks/ShadowsocksQuickSwitchActivity.scala
+3
-7
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
...la/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
+2
-2
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala
...ala/com/github/shadowsocks/ShadowsocksRunnerService.scala
+2
-2
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
.../scala/com/github/shadowsocks/ShadowsocksVpnService.scala
+0
-18
src/main/scala/com/github/shadowsocks/ShadowsocksVpnThread.scala
...n/scala/com/github/shadowsocks/ShadowsocksVpnThread.scala
+1
-1
src/main/scala/com/github/shadowsocks/TaskerReceiver.scala
src/main/scala/com/github/shadowsocks/TaskerReceiver.scala
+1
-7
src/main/scala/com/github/shadowsocks/utils/Constants.scala
src/main/scala/com/github/shadowsocks/utils/Constants.scala
+2
-2
src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
...n/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
+0
-2
src/main/scala/com/github/shadowsocks/utils/Utils.scala
src/main/scala/com/github/shadowsocks/utils/Utils.scala
+7
-6
No files found.
src/main/aidl/com/github/shadowsocks/aidl/IShadowsocksService.aidl
View file @
ee48c077
...
@@ -10,6 +10,5 @@ interface IShadowsocksService {
...
@@ -10,6 +10,5 @@ interface IShadowsocksService {
oneway
void
registerCallback
(
IShadowsocksServiceCallback
cb
);
oneway
void
registerCallback
(
IShadowsocksServiceCallback
cb
);
oneway
void
unregisterCallback
(
IShadowsocksServiceCallback
cb
);
oneway
void
unregisterCallback
(
IShadowsocksServiceCallback
cb
);
oneway
void
start
(
in
Config
config
);
oneway
void
use
(
in
Config
config
);
oneway
void
stop
();
}
}
src/main/scala/com/github/shadowsocks/BaseService.scala
View file @
ee48c077
...
@@ -42,10 +42,12 @@ package com.github.shadowsocks
...
@@ -42,10 +42,12 @@ package com.github.shadowsocks
import
java.util.
{
Timer
,
TimerTask
}
import
java.util.
{
Timer
,
TimerTask
}
import
android.app.Service
import
android.app.Service
import
android.content.
{
Intent
,
Context
}
import
android.content.
{
BroadcastReceiver
,
Context
,
Intent
,
IntentFilter
}
import
android.os.
{
Handler
,
RemoteCallbackList
}
import
android.os.
{
Handler
,
RemoteCallbackList
}
import
android.util.Log
import
android.widget.Toast
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.
_
trait
BaseService
extends
Service
{
trait
BaseService
extends
Service
{
...
@@ -57,6 +59,13 @@ trait BaseService extends Service {
...
@@ -57,6 +59,13 @@ trait BaseService extends Service {
final
val
callbacks
=
new
RemoteCallbackList
[
IShadowsocksServiceCallback
]
final
val
callbacks
=
new
RemoteCallbackList
[
IShadowsocksServiceCallback
]
var
callbacksCount
:
Int
=
_
var
callbacksCount
:
Int
=
_
lazy
val
handler
=
new
Handler
(
getContext
.
getMainLooper
)
private
val
closeReceiver
:
BroadcastReceiver
=
(
context
:
Context
,
intent
:
Intent
)
=>
{
Toast
.
makeText
(
context
,
R
.
string
.
stopping
,
Toast
.
LENGTH_SHORT
).
show
()
stopRunner
()
}
var
closeReceiverRegistered
:
Boolean
=
_
val
binder
=
new
IShadowsocksService
.
Stub
{
val
binder
=
new
IShadowsocksService
.
Stub
{
override
def
getMode
:
Int
=
{
override
def
getMode
:
Int
=
{
...
@@ -94,17 +103,15 @@ trait BaseService extends Service {
...
@@ -94,17 +103,15 @@ trait BaseService extends Service {
}
}
}
}
override
def
stop
()
{
override
def
use
(
config
:
Config
)
=
synchronized
(
state
match
{
if
(
state
==
State
.
CONNECTED
)
{
case
State
.
STOPPED
=>
if
(
config
!=
null
)
startRunner
(
config
)
case
State
.
CONNECTED
=>
if
(
config
==
null
)
stopRunner
()
else
if
(
config
.
profileId
!=
BaseService
.
this
.
config
.
profileId
)
{
stopRunner
()
stopRunner
()
}
}
override
def
start
(
config
:
Config
)
{
if
(
state
==
State
.
STOPPED
)
{
startRunner
(
config
)
startRunner
(
config
)
}
}
}
case
_
=>
Log
.
w
(
BaseService
.
this
.
getClass
.
getSimpleName
,
"Illegal state when invoking use: "
+
state
)
})
}
}
def
startRunner
(
config
:
Config
)
{
def
startRunner
(
config
:
Config
)
{
...
@@ -114,9 +121,24 @@ trait BaseService extends Service {
...
@@ -114,9 +121,24 @@ trait BaseService extends Service {
TrafficMonitor
.
reset
()
TrafficMonitor
.
reset
()
trafficMonitorThread
=
new
TrafficMonitorThread
(
getApplicationContext
)
trafficMonitorThread
=
new
TrafficMonitorThread
(
getApplicationContext
)
trafficMonitorThread
.
start
()
trafficMonitorThread
.
start
()
if
(!
closeReceiverRegistered
)
{
// register close receiver
val
filter
=
new
IntentFilter
()
filter
.
addAction
(
Intent
.
ACTION_SHUTDOWN
)
filter
.
addAction
(
Action
.
CLOSE
)
registerReceiver
(
closeReceiver
,
filter
)
closeReceiverRegistered
=
true
}
}
}
def
stopRunner
()
{
def
stopRunner
()
{
// clean up recevier
if
(
closeReceiverRegistered
)
{
unregisterReceiver
(
closeReceiver
)
closeReceiverRegistered
=
false
}
// Make sure update total traffic when stopping the runner
// Make sure update total traffic when stopping the runner
updateTrafficTotal
(
TrafficMonitor
.
txTotal
,
TrafficMonitor
.
rxTotal
)
updateTrafficTotal
(
TrafficMonitor
.
txTotal
,
TrafficMonitor
.
rxTotal
)
...
@@ -158,7 +180,6 @@ trait BaseService extends Service {
...
@@ -158,7 +180,6 @@ trait BaseService extends Service {
}
}
def
updateTrafficRate
()
{
def
updateTrafficRate
()
{
val
handler
=
new
Handler
(
getContext
.
getMainLooper
)
handler
.
post
(()
=>
{
handler
.
post
(()
=>
{
if
(
callbacksCount
>
0
)
{
if
(
callbacksCount
>
0
)
{
val
txRate
=
TrafficMonitor
.
txRate
val
txRate
=
TrafficMonitor
.
txRate
...
...
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
ee48c077
...
@@ -328,7 +328,7 @@ class Shadowsocks
...
@@ -328,7 +328,7 @@ class Shadowsocks
handler
.
post
(()
=>
onActivityResult
(
Shadowsocks
.
REQUEST_CONNECT
,
Activity
.
RESULT_OK
,
null
))
handler
.
post
(()
=>
onActivityResult
(
Shadowsocks
.
REQUEST_CONNECT
,
Activity
.
RESULT_OK
,
null
))
}
}
}
else
{
}
else
{
service
Start
()
service
Load
()
}
}
}
}
}
}
...
@@ -369,21 +369,6 @@ class Shadowsocks
...
@@ -369,21 +369,6 @@ class Shadowsocks
handler
.
post
(()
=>
attachService
)
handler
.
post
(()
=>
attachService
)
}
}
def
reloadProfile
()
{
currentProfile
=
ShadowsocksApplication
.
currentProfile
match
{
case
Some
(
profile
)
=>
profile
// updated
case
None
=>
// removed
ShadowsocksApplication
.
profileManager
.
getFirstProfile
match
{
case
Some
(
first
)
=>
ShadowsocksApplication
.
switchProfile
(
first
.
id
)
case
None
=>
ShadowsocksApplication
.
profileManager
.
createDefault
()
}
}
updatePreferenceScreen
()
serviceStop
()
}
protected
override
def
onPause
()
{
protected
override
def
onPause
()
{
super
.
onPause
()
super
.
onPause
()
ShadowsocksApplication
.
profileManager
.
save
ShadowsocksApplication
.
profileManager
.
save
...
@@ -434,7 +419,20 @@ class Shadowsocks
...
@@ -434,7 +419,20 @@ class Shadowsocks
ConfigUtils
.
refresh
(
this
)
ConfigUtils
.
refresh
(
this
)
// Check if current profile changed
// Check if current profile changed
if
(
ShadowsocksApplication
.
profileId
!=
currentProfile
.
id
)
reloadProfile
()
if
(
ShadowsocksApplication
.
profileId
!=
currentProfile
.
id
)
{
currentProfile
=
ShadowsocksApplication
.
currentProfile
match
{
case
Some
(
profile
)
=>
profile
// updated
case
None
=>
// removed
ShadowsocksApplication
.
profileManager
.
getFirstProfile
match
{
case
Some
(
first
)
=>
ShadowsocksApplication
.
switchProfile
(
first
.
id
)
case
None
=>
ShadowsocksApplication
.
profileManager
.
createDefault
()
}
}
updatePreferenceScreen
()
if
(
serviceStarted
)
serviceLoad
()
}
updateState
()
updateState
()
}
}
...
@@ -485,7 +483,7 @@ class Shadowsocks
...
@@ -485,7 +483,7 @@ class Shadowsocks
}
}
def
recovery
()
{
def
recovery
()
{
serviceStop
()
if
(
serviceStarted
)
serviceStop
()
val
h
=
showProgress
(
R
.
string
.
recovering
)
val
h
=
showProgress
(
R
.
string
.
recovering
)
ThrowableFuture
{
ThrowableFuture
{
reset
()
reset
()
...
@@ -504,14 +502,14 @@ class Shadowsocks
...
@@ -504,14 +502,14 @@ class Shadowsocks
override
def
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
)
=
resultCode
match
{
override
def
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
)
=
resultCode
match
{
case
Activity
.
RESULT_OK
=>
case
Activity
.
RESULT_OK
=>
service
Start
()
service
Load
()
case
_
=>
case
_
=>
cancelStart
()
cancelStart
()
Log
.
e
(
Shadowsocks
.
TAG
,
"Failed to start VpnService"
)
Log
.
e
(
Shadowsocks
.
TAG
,
"Failed to start VpnService"
)
}
}
def
serviceStop
()
{
def
serviceStop
()
{
if
(
bgService
!=
null
)
bgService
.
stop
(
)
if
(
bgService
!=
null
)
bgService
.
use
(
null
)
}
}
def
checkText
(
key
:
String
)
:
Boolean
=
{
def
checkText
(
key
:
String
)
:
Boolean
=
{
...
@@ -522,8 +520,8 @@ class Shadowsocks
...
@@ -522,8 +520,8 @@ class Shadowsocks
}
}
/** Called when connect button is clicked. */
/** Called when connect button is clicked. */
def
service
Start
()
{
def
service
Load
()
{
bgService
.
start
(
ConfigUtils
.
load
(
ShadowsocksApplication
.
settings
))
bgService
.
use
(
ConfigUtils
.
load
(
ShadowsocksApplication
.
settings
))
if
(
ShadowsocksApplication
.
isVpnEnabled
)
{
if
(
ShadowsocksApplication
.
isVpnEnabled
)
{
changeSwitch
(
checked
=
false
)
changeSwitch
(
checked
=
false
)
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
View file @
ee48c077
...
@@ -49,7 +49,6 @@ import android.content.pm.{PackageInfo, PackageManager}
...
@@ -49,7 +49,6 @@ import android.content.pm.{PackageInfo, PackageManager}
import
android.net.
{
ConnectivityManager
,
Network
}
import
android.net.
{
ConnectivityManager
,
Network
}
import
android.os._
import
android.os._
import
android.util.
{
Log
,
SparseArray
}
import
android.util.
{
Log
,
SparseArray
}
import
android.widget.Toast
import
com.github.shadowsocks.aidl.Config
import
com.github.shadowsocks.aidl.Config
import
com.github.shadowsocks.utils._
import
com.github.shadowsocks.utils._
...
@@ -65,7 +64,6 @@ class ShadowsocksNatService extends BaseService {
...
@@ -65,7 +64,6 @@ class ShadowsocksNatService extends BaseService {
"-j DNAT --to-destination 127.0.0.1:8123"
"-j DNAT --to-destination 127.0.0.1:8123"
private
var
notification
:
ShadowsocksNotification
=
_
private
var
notification
:
ShadowsocksNotification
=
_
var
closeReceiver
:
BroadcastReceiver
=
_
var
connReceiver
:
BroadcastReceiver
=
_
var
connReceiver
:
BroadcastReceiver
=
_
val
myUid
=
android
.
os
.
Process
.
myUid
()
val
myUid
=
android
.
os
.
Process
.
myUid
()
...
@@ -386,16 +384,6 @@ class ShadowsocksNatService extends BaseService {
...
@@ -386,16 +384,6 @@ class ShadowsocksNatService extends BaseService {
}
}
super
.
startRunner
(
config
)
super
.
startRunner
(
config
)
// register close receiver
val
filter
=
new
IntentFilter
()
filter
.
addAction
(
Intent
.
ACTION_SHUTDOWN
)
filter
.
addAction
(
Action
.
CLOSE
)
closeReceiver
=
(
context
:
Context
,
intent
:
Intent
)
=>
{
Toast
.
makeText
(
context
,
R
.
string
.
stopping
,
Toast
.
LENGTH_SHORT
).
show
()
stopRunner
()
}
registerReceiver
(
closeReceiver
,
filter
)
ShadowsocksApplication
.
track
(
TAG
,
"start"
)
ShadowsocksApplication
.
track
(
TAG
,
"start"
)
changeState
(
State
.
CONNECTING
)
changeState
(
State
.
CONNECTING
)
...
@@ -450,12 +438,6 @@ class ShadowsocksNatService extends BaseService {
...
@@ -450,12 +438,6 @@ class ShadowsocksNatService extends BaseService {
// channge the state
// channge the state
changeState
(
State
.
STOPPING
)
changeState
(
State
.
STOPPING
)
// clean up recevier
if
(
closeReceiver
!=
null
)
{
unregisterReceiver
(
closeReceiver
)
closeReceiver
=
null
}
if
(
notification
!=
null
)
notification
.
destroy
()
if
(
notification
!=
null
)
notification
.
destroy
()
ShadowsocksApplication
.
track
(
TAG
,
"stop"
)
ShadowsocksApplication
.
track
(
TAG
,
"stop"
)
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksQuickSwitchActivity.scala
View file @
ee48c077
package
com.github.shadowsocks
package
com.github.shadowsocks
import
android.content.res.Resources
import
android.content.res.Resources
import
android.os.
{
Handler
,
Build
,
Bundle
}
import
android.os.
{
Build
,
Bundle
}
import
android.support.v7.app.AppCompatActivity
import
android.support.v7.app.AppCompatActivity
import
android.support.v7.widget.
{
Toolbar
,
DefaultItemAnimator
,
LinearLayoutManager
,
RecyclerView
}
import
android.support.v7.widget.
{
DefaultItemAnimator
,
LinearLayoutManager
,
RecyclerView
,
Toolbar
}
import
android.view.
{
LayoutInflater
,
View
,
ViewGroup
}
import
android.view.
{
LayoutInflater
,
View
,
ViewGroup
}
import
android.widget.CheckedTextView
import
android.widget.CheckedTextView
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.database.Profile
...
@@ -31,12 +31,8 @@ class ShadowsocksQuickSwitchActivity extends AppCompatActivity {
...
@@ -31,12 +31,8 @@ class ShadowsocksQuickSwitchActivity extends AppCompatActivity {
}
}
def
onClick
(
v
:
View
)
{
def
onClick
(
v
:
View
)
{
Utils
.
stopSsService
(
ShadowsocksQuickSwitchActivity
.
this
)
ShadowsocksApplication
.
switchProfile
(
item
.
id
)
ShadowsocksApplication
.
switchProfile
(
item
.
id
)
val
handler
=
new
Handler
(
ShadowsocksQuickSwitchActivity
.
this
.
getMainLooper
)
handler
.
postDelayed
(()
=>
{
Utils
.
startSsService
(
ShadowsocksQuickSwitchActivity
.
this
)
Utils
.
startSsService
(
ShadowsocksQuickSwitchActivity
.
this
)
},
3000
)
finish
finish
}
}
}
}
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
View file @
ee48c077
...
@@ -65,7 +65,7 @@ class ShadowsocksRunnerActivity extends Activity with ServiceBoundContext {
...
@@ -65,7 +65,7 @@ class ShadowsocksRunnerActivity extends Activity with ServiceBoundContext {
onActivityResult
(
Shadowsocks
.
REQUEST_CONNECT
,
Activity
.
RESULT_OK
,
null
)
onActivityResult
(
Shadowsocks
.
REQUEST_CONNECT
,
Activity
.
RESULT_OK
,
null
)
}
}
}
else
{
}
else
{
bgService
.
start
(
ConfigUtils
.
load
(
ShadowsocksApplication
.
settings
))
bgService
.
use
(
ConfigUtils
.
load
(
ShadowsocksApplication
.
settings
))
finish
()
finish
()
}
}
}
}
...
@@ -101,7 +101,7 @@ class ShadowsocksRunnerActivity extends Activity with ServiceBoundContext {
...
@@ -101,7 +101,7 @@ class ShadowsocksRunnerActivity extends Activity with ServiceBoundContext {
resultCode
match
{
resultCode
match
{
case
Activity
.
RESULT_OK
=>
case
Activity
.
RESULT_OK
=>
if
(
bgService
!=
null
)
{
if
(
bgService
!=
null
)
{
bgService
.
start
(
ConfigUtils
.
load
(
ShadowsocksApplication
.
settings
))
bgService
.
use
(
ConfigUtils
.
load
(
ShadowsocksApplication
.
settings
))
}
}
case
_
=>
case
_
=>
Log
.
e
(
Shadowsocks
.
TAG
,
"Failed to start VpnService"
)
Log
.
e
(
Shadowsocks
.
TAG
,
"Failed to start VpnService"
)
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala
View file @
ee48c077
...
@@ -61,11 +61,11 @@ class ShadowsocksRunnerService extends Service with ServiceBoundContext {
...
@@ -61,11 +61,11 @@ class ShadowsocksRunnerService extends Service with ServiceBoundContext {
val
intent
=
VpnService
.
prepare
(
ShadowsocksRunnerService
.
this
)
val
intent
=
VpnService
.
prepare
(
ShadowsocksRunnerService
.
this
)
if
(
intent
==
null
)
{
if
(
intent
==
null
)
{
if
(
bgService
!=
null
)
{
if
(
bgService
!=
null
)
{
bgService
.
start
(
ConfigUtils
.
load
(
ShadowsocksApplication
.
settings
))
bgService
.
use
(
ConfigUtils
.
load
(
ShadowsocksApplication
.
settings
))
}
}
}
}
}
else
{
}
else
{
bgService
.
start
(
ConfigUtils
.
load
(
ShadowsocksApplication
.
settings
))
bgService
.
use
(
ConfigUtils
.
load
(
ShadowsocksApplication
.
settings
))
}
}
stopSelf
()
stopSelf
()
}
}
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
View file @
ee48c077
...
@@ -49,7 +49,6 @@ import android.content.pm.{PackageInfo, PackageManager}
...
@@ -49,7 +49,6 @@ import android.content.pm.{PackageInfo, PackageManager}
import
android.net.VpnService
import
android.net.VpnService
import
android.os._
import
android.os._
import
android.util.Log
import
android.util.Log
import
android.widget.Toast
import
com.github.shadowsocks.aidl.Config
import
com.github.shadowsocks.aidl.Config
import
com.github.shadowsocks.utils._
import
com.github.shadowsocks.utils._
import
org.apache.commons.net.util.SubnetUtils
import
org.apache.commons.net.util.SubnetUtils
...
@@ -64,7 +63,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
...
@@ -64,7 +63,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
var
conn
:
ParcelFileDescriptor
=
_
var
conn
:
ParcelFileDescriptor
=
_
var
vpnThread
:
ShadowsocksVpnThread
=
_
var
vpnThread
:
ShadowsocksVpnThread
=
_
private
var
notification
:
ShadowsocksNotification
=
_
private
var
notification
:
ShadowsocksNotification
=
_
var
closeReceiver
:
BroadcastReceiver
=
_
var
sslocalProcess
:
Process
=
_
var
sslocalProcess
:
Process
=
_
var
sstunnelProcess
:
Process
=
_
var
sstunnelProcess
:
Process
=
_
...
@@ -134,12 +132,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
...
@@ -134,12 +132,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
conn
=
null
conn
=
null
}
}
// clean up recevier
if
(
closeReceiver
!=
null
)
{
unregisterReceiver
(
closeReceiver
)
closeReceiver
=
null
}
super
.
stopRunner
()
super
.
stopRunner
()
}
}
...
@@ -181,16 +173,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
...
@@ -181,16 +173,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
vpnThread
=
new
ShadowsocksVpnThread
(
this
)
vpnThread
=
new
ShadowsocksVpnThread
(
this
)
vpnThread
.
start
()
vpnThread
.
start
()
// register close receiver
val
filter
=
new
IntentFilter
()
filter
.
addAction
(
Intent
.
ACTION_SHUTDOWN
)
filter
.
addAction
(
Action
.
CLOSE
)
closeReceiver
=
(
context
:
Context
,
intent
:
Intent
)
=>
{
Toast
.
makeText
(
context
,
R
.
string
.
stopping
,
Toast
.
LENGTH_SHORT
).
show
()
stopRunner
()
}
registerReceiver
(
closeReceiver
,
filter
)
// ensure the VPNService is prepared
// ensure the VPNService is prepared
if
(
VpnService
.
prepare
(
this
)
!=
null
)
{
if
(
VpnService
.
prepare
(
this
)
!=
null
)
{
val
i
=
new
Intent
(
this
,
classOf
[
ShadowsocksRunnerActivity
])
val
i
=
new
Intent
(
this
,
classOf
[
ShadowsocksRunnerActivity
])
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksVpnThread.scala
View file @
ee48c077
src/main/scala/com/github/shadowsocks/TaskerReceiver.scala
View file @
ee48c077
...
@@ -39,7 +39,6 @@
...
@@ -39,7 +39,6 @@
package
com.github.shadowsocks
package
com.github.shadowsocks
import
android.content.
{
BroadcastReceiver
,
Context
,
Intent
}
import
android.content.
{
BroadcastReceiver
,
Context
,
Intent
}
import
android.os.Handler
import
com.github.shadowsocks.helper.TaskerSettings
import
com.github.shadowsocks.helper.TaskerSettings
import
com.github.shadowsocks.utils.Utils
import
com.github.shadowsocks.utils.Utils
...
@@ -51,15 +50,10 @@ class TaskerReceiver extends BroadcastReceiver {
...
@@ -51,15 +50,10 @@ class TaskerReceiver extends BroadcastReceiver {
val
settings
=
TaskerSettings
.
fromIntent
(
intent
)
val
settings
=
TaskerSettings
.
fromIntent
(
intent
)
val
switched
=
ShadowsocksApplication
.
profileManager
.
getProfile
(
settings
.
profileId
)
match
{
val
switched
=
ShadowsocksApplication
.
profileManager
.
getProfile
(
settings
.
profileId
)
match
{
case
Some
(
p
)
=>
case
Some
(
p
)
=>
Utils
.
stopSsService
(
context
)
ShadowsocksApplication
.
switchProfile
(
settings
.
profileId
)
ShadowsocksApplication
.
switchProfile
(
settings
.
profileId
)
true
true
case
_
=>
false
case
_
=>
false
}
}
val
handler
=
new
Handler
(
context
.
getMainLooper
)
if
(
settings
.
switchOn
)
Utils
.
startSsService
(
context
)
else
Utils
.
stopSsService
(
context
)
handler
.
postDelayed
(()
=>
{
if
(
settings
.
switchOn
)
Utils
.
startSsService
(
context
)
else
if
(!
switched
)
Utils
.
stopSsService
(
context
)
},
3000
)
}
}
}
}
src/main/scala/com/github/shadowsocks/utils/Constants.scala
View file @
ee48c077
...
@@ -72,8 +72,8 @@ object Key {
...
@@ -72,8 +72,8 @@ object Key {
val
isProxyApps
=
"isProxyApps"
val
isProxyApps
=
"isProxyApps"
val
isBypassApps
=
"isBypassApps"
val
isBypassApps
=
"isBypassApps"
val
isUdpDns
=
"isUdpDns"
val
isUdpDns
=
"isUdpDns"
val
isAuth
=
"isAuth"
val
isAuth
=
"isAuth"
val
isIpv6
=
"isIpv6"
val
isIpv6
=
"isIpv6"
val
proxy
=
"proxy"
val
proxy
=
"proxy"
val
sitekey
=
"sitekey"
val
sitekey
=
"sitekey"
...
...
src/main/scala/com/github/shadowsocks/utils/TrafficMonitor.scala
View file @
ee48c077
package
com.github.shadowsocks.utils
package
com.github.shadowsocks.utils
import
java.lang.System
import
java.text.DecimalFormat
import
java.text.DecimalFormat
import
com.github.shadowsocks.
{
R
,
ShadowsocksApplication
}
import
com.github.shadowsocks.
{
R
,
ShadowsocksApplication
}
...
@@ -81,4 +80,3 @@ object TrafficMonitor {
...
@@ -81,4 +80,3 @@ object TrafficMonitor {
dirty
=
true
dirty
=
true
}
}
}
}
src/main/scala/com/github/shadowsocks/utils/Utils.scala
View file @
ee48c077
...
@@ -42,7 +42,7 @@ import java.io._
...
@@ -42,7 +42,7 @@ import java.io._
import
java.net._
import
java.net._
import
java.security.MessageDigest
import
java.security.MessageDigest
import
android.animation.
{
Animator
ListenerAdapter
,
Animato
r
}
import
android.animation.
{
Animator
,
AnimatorListenerAdapte
r
}
import
android.app.ActivityManager
import
android.app.ActivityManager
import
android.content.pm.
{
ApplicationInfo
,
PackageManager
}
import
android.content.pm.
{
ApplicationInfo
,
PackageManager
}
import
android.content.
{
Context
,
Intent
}
import
android.content.
{
Context
,
Intent
}
...
@@ -51,11 +51,11 @@ import android.graphics.drawable.{BitmapDrawable, Drawable}
...
@@ -51,11 +51,11 @@ import android.graphics.drawable.{BitmapDrawable, Drawable}
import
android.os.Build
import
android.os.Build
import
android.provider.Settings
import
android.provider.Settings
import
android.support.v4.content.ContextCompat
import
android.support.v4.content.ContextCompat
import
android.util.
{
DisplayMetrics
,
Base64
,
Log
}
import
android.util.
{
Base64
,
DisplayMetrics
,
Log
}
import
android.view.View.MeasureSpec
import
android.view.View.MeasureSpec
import
android.view.
{
Gravity
,
View
,
Window
}
import
android.view.
{
Gravity
,
View
,
Window
}
import
android.widget.Toast
import
android.widget.Toast
import
com.github.shadowsocks.
{
ShadowsocksRunnerService
,
ShadowsocksApplication
,
BuildConfig
}
import
com.github.shadowsocks.
{
BuildConfig
,
ShadowsocksApplication
,
ShadowsocksRunnerService
}
import
org.xbill.DNS._
import
org.xbill.DNS._
...
@@ -401,7 +401,7 @@ object Utils {
...
@@ -401,7 +401,7 @@ object Utils {
}
}
}
}
def
startSsService
(
context
:
Context
)
:
Unit
=
{
def
startSsService
(
context
:
Context
)
{
val
isInstalled
:
Boolean
=
ShadowsocksApplication
.
settings
.
getBoolean
(
ShadowsocksApplication
.
getVersionName
,
false
)
val
isInstalled
:
Boolean
=
ShadowsocksApplication
.
settings
.
getBoolean
(
ShadowsocksApplication
.
getVersionName
,
false
)
if
(!
isInstalled
)
return
if
(!
isInstalled
)
return
...
@@ -409,8 +409,9 @@ object Utils {
...
@@ -409,8 +409,9 @@ object Utils {
context
.
startService
(
intent
)
context
.
startService
(
intent
)
}
}
def
stopSsService
(
context
:
Context
)
:
Unit
=
{
def
stopSsService
(
context
:
Context
)
{
context
.
sendBroadcast
(
new
Intent
(
Action
.
CLOSE
))
val
intent
=
new
Intent
(
Action
.
CLOSE
)
context
.
sendBroadcast
(
intent
)
}
}
}
}
...
...
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