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
4906ce8a
Commit
4906ce8a
authored
Nov 08, 2015
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support switching to NAT/VPN without restarting the app
parent
1f0f9211
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
58 deletions
+31
-58
src/main/scala/com/github/shadowsocks/AppManager.scala
src/main/scala/com/github/shadowsocks/AppManager.scala
+4
-4
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+15
-23
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
...la/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
+6
-11
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala
...ala/com/github/shadowsocks/ShadowsocksRunnerService.scala
+4
-10
src/main/scala/com/github/shadowsocks/database/ProfileManager.scala
...cala/com/github/shadowsocks/database/ProfileManager.scala
+1
-1
src/main/scala/com/github/shadowsocks/utils/Constants.scala
src/main/scala/com/github/shadowsocks/utils/Constants.scala
+0
-1
src/main/scala/com/github/shadowsocks/utils/Utils.scala
src/main/scala/com/github/shadowsocks/utils/Utils.scala
+1
-8
No files found.
src/main/scala/com/github/shadowsocks/AppManager.scala
View file @
4906ce8a
...
@@ -247,8 +247,8 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe
...
@@ -247,8 +247,8 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe
val
array
=
proxiedAppString
.
split
(
" "
)
val
array
=
proxiedAppString
.
split
(
" "
)
val
bypass
=
array
(
0
).
toBoolean
val
bypass
=
array
(
0
).
toBoolean
val
apps
=
if
(
array
.
size
>
1
)
array
(
1
)
else
""
val
apps
=
if
(
array
.
size
>
1
)
array
(
1
)
else
""
prefs
.
edit
.
putBoolean
(
Key
.
isBypassApps
,
bypass
).
commit
()
prefs
.
edit
.
putBoolean
(
Key
.
isBypassApps
,
bypass
).
apply
()
prefs
.
edit
.
putString
(
Key
.
proxied
,
apps
).
commit
()
prefs
.
edit
.
putString
(
Key
.
proxied
,
apps
).
apply
()
Toast
.
makeText
(
this
,
R
.
string
.
action_import_msg
,
Toast
.
LENGTH_SHORT
).
show
()
Toast
.
makeText
(
this
,
R
.
string
.
action_import_msg
,
Toast
.
LENGTH_SHORT
).
show
()
// Restart activity
// Restart activity
val
intent
=
getIntent
val
intent
=
getIntent
...
@@ -299,7 +299,7 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe
...
@@ -299,7 +299,7 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe
val
bypassSwitch
=
findViewById
(
R
.
id
.
bypassSwitch
).
asInstanceOf
[
Switch
]
val
bypassSwitch
=
findViewById
(
R
.
id
.
bypassSwitch
).
asInstanceOf
[
Switch
]
val
prefs
=
PreferenceManager
.
getDefaultSharedPreferences
(
getBaseContext
)
val
prefs
=
PreferenceManager
.
getDefaultSharedPreferences
(
getBaseContext
)
bypassSwitch
.
setOnCheckedChangeListener
((
button
:
CompoundButton
,
checked
:
Boolean
)
=>
bypassSwitch
.
setOnCheckedChangeListener
((
button
:
CompoundButton
,
checked
:
Boolean
)
=>
prefs
.
edit
().
putBoolean
(
Key
.
isBypassApps
,
checked
).
commit
())
prefs
.
edit
().
putBoolean
(
Key
.
isBypassApps
,
checked
).
apply
())
bypassSwitch
.
setChecked
(
prefs
.
getBoolean
(
Key
.
isBypassApps
,
false
))
bypassSwitch
.
setChecked
(
prefs
.
getBoolean
(
Key
.
isBypassApps
,
false
))
appListView
=
findViewById
(
R
.
id
.
applistview
).
asInstanceOf
[
ListView
]
appListView
=
findViewById
(
R
.
id
.
applistview
).
asInstanceOf
[
ListView
]
...
@@ -325,7 +325,7 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe
...
@@ -325,7 +325,7 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe
})
})
val
edit
:
SharedPreferences.Editor
=
prefs
.
edit
val
edit
:
SharedPreferences.Editor
=
prefs
.
edit
edit
.
putString
(
Key
.
proxied
,
proxiedApps
.
toString
())
edit
.
putString
(
Key
.
proxied
,
proxiedApps
.
toString
())
edit
.
commit
edit
.
apply
}
}
val
loadStartRunnable
=
new
Runnable
{
val
loadStartRunnable
=
new
Runnable
{
...
...
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
4906ce8a
...
@@ -223,7 +223,7 @@ class Shadowsocks
...
@@ -223,7 +223,7 @@ class Shadowsocks
state
=
bgService
.
getState
state
=
bgService
.
getState
if
(!
status
.
getBoolean
(
getVersionName
,
false
))
{
if
(!
status
.
getBoolean
(
getVersionName
,
false
))
{
status
.
edit
.
putBoolean
(
getVersionName
,
true
).
commit
()
status
.
edit
.
putBoolean
(
getVersionName
,
true
).
apply
()
recovery
()
recovery
()
}
}
}
}
...
@@ -515,13 +515,13 @@ class Shadowsocks
...
@@ -515,13 +515,13 @@ class Shadowsocks
title
.
setOnLongClickListener
((
v
:
View
)
=>
{
title
.
setOnLongClickListener
((
v
:
View
)
=>
{
if
(
Utils
.
isLollipopOrAbove
&&
bgService
!=
null
if
(
Utils
.
isLollipopOrAbove
&&
bgService
!=
null
&&
(
bgService
.
getState
==
State
.
INIT
||
bgService
.
getState
==
State
.
STOPPED
))
{
&&
(
bgService
.
getState
==
State
.
INIT
||
bgService
.
getState
==
State
.
STOPPED
))
{
val
natEnabled
=
status
.
getBoolean
(
Key
.
isNAT
,
fals
e
)
val
natEnabled
=
!
status
.
getBoolean
(
Key
.
isNAT
,
!
Utils
.
isLollipopOrAbov
e
)
status
.
edit
().
putBoolean
(
Key
.
isNAT
,
!
natEnabled
).
commit
()
status
.
edit
().
putBoolean
(
Key
.
isNAT
,
natEnabled
).
apply
()
if
(!
natEnabled
)
{
deattachService
()
Toast
.
makeText
(
getBaseContext
,
R
.
string
.
enable_nat
,
Toast
.
LENGTH_LONG
).
show
()
attachService
()
}
else
{
if
(!
Utils
.
isLollipopOrAbove
)
setPreferenceEnabled
(
State
.
isAvailable
(
bgService
.
getState
))
Toast
.
makeText
(
getBaseContext
,
R
.
string
.
disable_nat
,
Toast
.
LENGTH_LONG
).
show
(
)
Toast
.
makeText
(
getBaseContext
,
if
(
natEnabled
)
R
.
string
.
enable_nat
else
R
.
string
.
disable_nat
,
Toast
.
LENGTH_LONG
)
}
.
show
()
true
true
}
else
{
}
else
{
false
false
...
@@ -532,13 +532,9 @@ class Shadowsocks
...
@@ -532,13 +532,9 @@ class Shadowsocks
registerReceiver
(
preferenceReceiver
,
new
IntentFilter
(
Action
.
UPDATE_PREFS
))
registerReceiver
(
preferenceReceiver
,
new
IntentFilter
(
Action
.
UPDATE_PREFS
))
// Bind to the service
// Bind to the service
Future
{
handler
.
post
(()
=>
{
val
isRoot
=
(!
Utils
.
isLollipopOrAbove
||
status
.
getBoolean
(
Key
.
isNAT
,
false
))
&&
Console
.
isRoot
attachService
()
handler
.
post
(()
=>
{
})
status
.
edit
.
putBoolean
(
Key
.
isRoot
,
isRoot
).
commit
()
attachService
()
})
}
}
}
def
attachService
()
{
def
attachService
()
{
...
@@ -942,15 +938,10 @@ class Shadowsocks
...
@@ -942,15 +938,10 @@ class Shadowsocks
}
}
}
}
var
isRoot
:
Option
[
Boolean
]
=
None
def
isVpnEnabled
:
Boolean
=
{
def
isVpnEnabled
:
Boolean
=
{
if
(
vpnEnabled
<
0
)
{
if
(
isRoot
.
isEmpty
)
isRoot
=
Some
(
Console
.
isRoot
)
vpnEnabled
=
if
(!
status
.
getBoolean
(
Key
.
isRoot
,
false
))
{
!(
isRoot
.
get
&&
status
.
getBoolean
(
Key
.
isNAT
,
!
Utils
.
isLollipopOrAbove
))
1
}
else
{
0
}
}
if
(
vpnEnabled
==
1
)
true
else
false
}
}
def
serviceStop
()
{
def
serviceStop
()
{
...
@@ -1051,6 +1042,7 @@ class Shadowsocks
...
@@ -1051,6 +1042,7 @@ class Shadowsocks
fab
.
setImageResource
(
R
.
drawable
.
ic_cloud_queue
)
fab
.
setImageResource
(
R
.
drawable
.
ic_cloud_queue
)
fab
.
setEnabled
(
false
)
fab
.
setEnabled
(
false
)
fabProgressCircle
.
show
()
fabProgressCircle
.
show
()
setPreferenceEnabled
(
enabled
=
false
)
}
}
state
=
s
state
=
s
})
})
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
View file @
4906ce8a
...
@@ -65,19 +65,13 @@ class ShadowsocksRunnerActivity extends Activity {
...
@@ -65,19 +65,13 @@ class ShadowsocksRunnerActivity extends Activity {
}
}
// Variables
// Variables
var
vpnEnabled
=
-
1
var
isRoot
:
Option
[
Boolean
]
=
None
var
bgService
:
IShadowsocksService
=
null
var
bgService
:
IShadowsocksService
=
_
var
receiver
:
BroadcastReceiver
=
null
var
receiver
:
BroadcastReceiver
=
_
def
isVpnEnabled
:
Boolean
=
{
def
isVpnEnabled
:
Boolean
=
{
if
(
vpnEnabled
<
0
)
{
if
(
isRoot
.
isEmpty
)
isRoot
=
Some
(
Console
.
isRoot
)
vpnEnabled
=
if
((!
Utils
.
isLollipopOrAbove
||
status
.
getBoolean
(
Key
.
isNAT
,
false
))
&&
Console
.
isRoot
)
{
!(
isRoot
.
get
&&
status
.
getBoolean
(
Key
.
isNAT
,
!
Utils
.
isLollipopOrAbove
))
0
}
else
{
1
}
}
if
(
vpnEnabled
==
1
)
true
else
false
}
}
...
@@ -127,6 +121,7 @@ class ShadowsocksRunnerActivity extends Activity {
...
@@ -127,6 +121,7 @@ class ShadowsocksRunnerActivity extends Activity {
}
else
{
}
else
{
attachService
()
attachService
()
}
}
finish
}
}
override
def
onDestroy
()
{
override
def
onDestroy
()
{
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala
View file @
4906ce8a
...
@@ -64,18 +64,12 @@ class ShadowsocksRunnerService extends Service {
...
@@ -64,18 +64,12 @@ class ShadowsocksRunnerService extends Service {
}
}
// Variables
// Variables
var
vpnEnabled
=
-
1
var
isRoot
:
Option
[
Boolean
]
=
None
var
bgService
:
IShadowsocksService
=
null
var
bgService
:
IShadowsocksService
=
_
def
isVpnEnabled
:
Boolean
=
{
def
isVpnEnabled
:
Boolean
=
{
if
(
vpnEnabled
<
0
)
{
if
(
isRoot
.
isEmpty
)
isRoot
=
Some
(
Console
.
isRoot
)
vpnEnabled
=
if
((!
Utils
.
isLollipopOrAbove
||
status
.
getBoolean
(
Key
.
isNAT
,
false
))
&&
Console
.
isRoot
)
{
!(
isRoot
.
get
&&
status
.
getBoolean
(
Key
.
isNAT
,
!
Utils
.
isLollipopOrAbove
))
0
}
else
{
1
}
}
if
(
vpnEnabled
==
1
)
true
else
false
}
}
override
def
onBind
(
intent
:
Intent
)
:
IBinder
=
{
override
def
onBind
(
intent
:
Intent
)
:
IBinder
=
{
...
...
src/main/scala/com/github/shadowsocks/database/ProfileManager.scala
View file @
4906ce8a
...
@@ -133,7 +133,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
...
@@ -133,7 +133,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
edit
.
putString
(
Key
.
proxied
,
profile
.
individual
)
edit
.
putString
(
Key
.
proxied
,
profile
.
individual
)
edit
.
putInt
(
Key
.
profileId
,
profile
.
id
)
edit
.
putInt
(
Key
.
profileId
,
profile
.
id
)
edit
.
putString
(
Key
.
route
,
profile
.
route
)
edit
.
putString
(
Key
.
route
,
profile
.
route
)
edit
.
commit
()
edit
.
apply
()
profile
profile
}
}
...
...
src/main/scala/com/github/shadowsocks/utils/Constants.scala
View file @
4906ce8a
...
@@ -66,7 +66,6 @@ object Key {
...
@@ -66,7 +66,6 @@ object Key {
val
proxied
=
"Proxyed"
val
proxied
=
"Proxyed"
val
isNAT
=
"isNAT"
val
isNAT
=
"isNAT"
val
isRoot
=
"isRoot"
val
status
=
"status"
val
status
=
"status"
val
proxyedApps
=
"proxyedApps"
val
proxyedApps
=
"proxyedApps"
val
route
=
"route"
val
route
=
"route"
...
...
src/main/scala/com/github/shadowsocks/utils/Utils.scala
View file @
4906ce8a
...
@@ -75,20 +75,13 @@ object Utils {
...
@@ -75,20 +75,13 @@ object Utils {
val
TIME_OUT
:
Int
=
-
99
val
TIME_OUT
:
Int
=
-
99
var
initialized
:
Boolean
=
false
var
initialized
:
Boolean
=
false
var
hasRedirectSupport
:
Int
=
-
1
var
hasRedirectSupport
:
Int
=
-
1
var
isRoot
:
Int
=
-
1
var
shell
:
String
=
null
var
shell
:
String
=
null
var
root_shell
:
String
=
null
var
root_shell
:
String
=
null
var
iptables
:
String
=
null
var
iptables
:
String
=
null
var
data_path
:
String
=
null
var
data_path
:
String
=
null
var
rootTries
=
0
var
rootTries
=
0
def
isLollipopOrAbove
:
Boolean
=
{
def
isLollipopOrAbove
:
Boolean
=
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
true
}
else
{
false
}
}
def
getSignature
(
context
:
Context
)
:
String
=
{
def
getSignature
(
context
:
Context
)
:
String
=
{
val
info
=
context
val
info
=
context
...
...
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