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
59d304ea
Commit
59d304ea
authored
Feb 09, 2014
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix the service toggle issue in VPN mode
parent
ba8b5162
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
40 deletions
+47
-40
src/main/scala/com/github/shadowsocks/BaseService.scala
src/main/scala/com/github/shadowsocks/BaseService.scala
+15
-8
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+30
-30
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
.../scala/com/github/shadowsocks/ShadowsocksNatService.scala
+1
-1
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 @
59d304ea
package
com.github.shadowsocks
import
android.os.
RemoteCallbackList
import
android.os.
{
Handler
,
RemoteCallbackList
}
import
com.github.shadowsocks.aidl.
{
Config
,
IShadowsocksService
,
IShadowsocksServiceCallback
}
import
com.github.shadowsocks.utils.
{
Path
,
State
}
import
java.io.
{
IOException
,
FileNotFoundException
,
FileReader
,
BufferedReader
}
import
android.util.Log
import
android.app.Notification
import
android.content.Context
trait
BaseService
{
...
...
@@ -43,12 +44,16 @@ trait BaseService {
def
stopRunner
()
def
getServiceMode
:
Int
def
getTag
:
String
def
getContext
:
Context
def
changeState
(
s
:
Int
)
{
changeState
(
s
,
null
)
}
protected
def
changeState
(
s
:
Int
,
msg
:
String
)
{
val
handler
=
new
Handler
(
getContext
.
getMainLooper
)
handler
.
post
(
new
Runnable
{
override
def
run
()
{
if
(
state
!=
s
)
{
val
n
=
callbacks
.
beginBroadcast
()
for
(
i
<-
0
to
n
-
1
)
{
...
...
@@ -58,6 +63,8 @@ trait BaseService {
state
=
s
}
}
})
}
def
getPid
(
name
:
String
)
:
Int
=
{
try
{
...
...
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
59d304ea
...
...
@@ -324,24 +324,12 @@ class Shadowsocks
}
}
Crouton
.
cancelAllCroutons
()
onStateChanged
(
State
.
STOPPED
,
null
)
setPreferenceEnabled
(
enabled
=
true
)
}
else
{
if
(
bgService
.
getMode
==
Mode
.
VPN
)
{
val
style
=
new
Style
.
Builder
().
setBackgroundColorValue
(
Style
.
holoBlueLight
).
build
()
val
config
=
new
Configuration
.
Builder
().
setDuration
(
Configuration
.
DURATION_LONG
).
build
()
Crouton
.
makeText
(
Shadowsocks
.
this
,
R
.
string
.
vpn_status
,
style
)
.
setConfiguration
(
config
)
.
show
()
switchButton
.
setEnabled
(
false
)
}
changeSwitch
(
checked
=
true
)
onStateChanged
(
bgService
.
getState
,
null
)
setPreferenceEnabled
(
enabled
=
false
)
}
// set the listener
switchButton
.
setOnCheckedChangeListener
(
Shadowsocks
.
this
)
state
=
bgService
.
getState
}
override
def
onServiceDisconnected
(
name
:
ComponentName
)
{
...
...
@@ -371,6 +359,7 @@ class Shadowsocks
}
private
def
changeSwitch
(
checked
:
Boolean
)
{
switchButton
.
setOnCheckedChangeListener
(
null
)
switchButton
.
setChecked
(
checked
)
if
(
switchButton
.
isEnabled
)
{
switchButton
.
setEnabled
(
false
)
...
...
@@ -378,6 +367,7 @@ class Shadowsocks
override
def
run
()
{
switchButton
.
setEnabled
(
true
)
}
},
1000
)
}
switchButton
.
setOnCheckedChangeListener
(
this
)
}
private
def
showProgress
(
msg
:
String
)
:
Handler
=
{
...
...
@@ -604,6 +594,16 @@ class Shadowsocks
// Register broadcast receiver
registerReceiver
(
preferenceReceiver
,
new
IntentFilter
(
Action
.
UPDATE_PREFS
))
// Bind to the service
spawn
{
val
isRoot
=
Utils
.
getRoot
handler
.
post
(
new
Runnable
{
override
def
run
()
{
status
.
edit
.
putBoolean
(
Key
.
isRoot
,
isRoot
).
commit
()
attachService
()
}
})
}
}
def
attachService
()
{
...
...
@@ -835,22 +835,25 @@ class Shadowsocks
protected
override
def
onPause
()
{
super
.
onPause
()
deattachService
(
)
switchButton
.
setOnCheckedChangeListener
(
null
)
prepared
=
false
}
protected
override
def
onResume
()
{
super
.
onResume
()
// Bind to the service
spawn
{
val
isRoot
=
Utils
.
getRoot
handler
.
post
(
new
Runnable
{
override
def
run
()
{
status
.
edit
.
putBoolean
(
Key
.
isRoot
,
isRoot
).
commit
()
attachService
()
if
(
bgService
!=
null
)
{
bgService
.
getState
match
{
case
State
.
CONNECTED
=>
changeSwitch
(
checked
=
true
)
case
State
.
CONNECTING
=>
changeSwitch
(
checked
=
true
)
case
_
=>
changeSwitch
(
checked
=
false
)
}
})
state
=
bgService
.
getState
}
// set the listener
switchButton
.
setOnCheckedChangeListener
(
Shadowsocks
.
this
)
ConfigUtils
.
refresh
(
this
)
}
...
...
@@ -900,6 +903,7 @@ class Shadowsocks
override
def
onDestroy
()
{
super
.
onDestroy
()
deattachService
()
Crouton
.
cancelAllCroutons
()
unregisterReceiver
(
preferenceReceiver
)
new
BackupManager
(
this
).
dataChanged
()
...
...
@@ -917,7 +921,6 @@ class Shadowsocks
private
def
recovery
()
{
val
h
=
showProgress
(
getString
(
R
.
string
.
recovering
))
serviceStop
()
spawn
{
reset
()
...
...
@@ -1066,15 +1069,12 @@ class Shadowsocks
setPreferenceEnabled
(
enabled
=
false
)
case
State
.
CONNECTED
=>
clearDialog
()
if
(!
switchButton
.
isChecked
)
changeSwitch
(
checked
=
true
)
changeSwitch
(
checked
=
true
)
setPreferenceEnabled
(
enabled
=
false
)
case
State
.
STOPPED
=>
clearDialog
()
if
(
switchButton
.
isChecked
)
{
switchButton
.
setEnabled
(
true
)
changeSwitch
(
checked
=
false
)
Crouton
.
cancelAllCroutons
()
}
if
(
m
!=
null
)
{
Crouton
.
cancelAllCroutons
()
val
style
=
new
Style
.
Builder
().
setBackgroundColorValue
(
Style
.
holoRedLight
).
build
()
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
View file @
59d304ea
...
...
@@ -550,6 +550,6 @@ class ShadowsocksNatService extends Service with BaseService {
}
override
def
getTag
=
TAG
override
def
getServiceMode
=
Mode
.
NAT
override
def
getContext
=
getBaseContext
}
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
View file @
59d304ea
...
...
@@ -399,5 +399,5 @@ class ShadowsocksVpnService extends VpnService with BaseService {
override
def
getTag
=
TAG
override
def
getServiceMode
=
Mode
.
VPN
override
def
getContext
=
getBaseContext
}
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