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
86f32ea6
Commit
86f32ea6
authored
May 24, 2016
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add app.isNatEnabled for performance and readability
Warning: This is a boring commit.
parent
461a0bda
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
23 additions
and
34 deletions
+23
-34
src/main/scala/com/github/shadowsocks/ServiceBoundContext.scala
...in/scala/com/github/shadowsocks/ServiceBoundContext.scala
+1
-2
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+14
-23
src/main/scala/com/github/shadowsocks/ShadowsocksApplication.scala
...scala/com/github/shadowsocks/ShadowsocksApplication.scala
+2
-1
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
...la/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
+4
-4
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala
...ala/com/github/shadowsocks/ShadowsocksRunnerService.scala
+1
-3
src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala
...in/scala/com/github/shadowsocks/ShadowsocksSettings.scala
+1
-1
No files found.
src/main/scala/com/github/shadowsocks/ServiceBoundContext.scala
View file @
86f32ea6
...
@@ -55,8 +55,7 @@ trait ServiceBoundContext extends Context with IBinder.DeathRecipient {
...
@@ -55,8 +55,7 @@ trait ServiceBoundContext extends Context with IBinder.DeathRecipient {
def
attachService
(
callback
:
IShadowsocksServiceCallback.Stub
=
null
)
{
def
attachService
(
callback
:
IShadowsocksServiceCallback.Stub
=
null
)
{
this
.
callback
=
callback
this
.
callback
=
callback
if
(
bgService
==
null
)
{
if
(
bgService
==
null
)
{
val
s
=
val
s
=
if
(
app
.
isNatEnabled
)
classOf
[
ShadowsocksNatService
]
else
classOf
[
ShadowsocksVpnService
]
if
(
app
.
isVpnEnabled
)
classOf
[
ShadowsocksVpnService
]
else
classOf
[
ShadowsocksNatService
]
val
intent
=
new
Intent
(
this
,
s
)
val
intent
=
new
Intent
(
this
,
s
)
intent
.
setAction
(
Action
.
SERVICE
)
intent
.
setAction
(
Action
.
SERVICE
)
...
...
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
86f32ea6
...
@@ -130,10 +130,10 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
...
@@ -130,10 +130,10 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
changeSwitch
(
checked
=
true
)
changeSwitch
(
checked
=
true
)
preferences
.
setEnabled
(
false
)
preferences
.
setEnabled
(
false
)
stat
.
setVisibility
(
View
.
VISIBLE
)
stat
.
setVisibility
(
View
.
VISIBLE
)
if
(
app
.
is
VpnEnabled
)
{
if
(
app
.
is
NatEnabled
)
connectionTestText
.
setVisibility
(
View
.
GONE
)
else
{
connectionTestText
.
setVisibility
(
View
.
VISIBLE
)
connectionTestText
.
setVisibility
(
View
.
VISIBLE
)
connectionTestText
.
setText
(
getString
(
R
.
string
.
connection_test_pending
))
connectionTestText
.
setText
(
getString
(
R
.
string
.
connection_test_pending
))
}
else
connectionTestText
.
setVisibility
(
View
.
GONE
)
}
case
State
.
STOPPED
=>
case
State
.
STOPPED
=>
fab
.
setBackgroundTintList
(
greyTint
)
fab
.
setBackgroundTintList
(
greyTint
)
fabProgressCircle
.
postDelayed
(
hideCircle
,
1000
)
fabProgressCircle
.
postDelayed
(
hideCircle
,
1000
)
...
@@ -178,7 +178,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
...
@@ -178,7 +178,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
// Update the UI
// Update the UI
if
(
fab
!=
null
)
fab
.
setEnabled
(
true
)
if
(
fab
!=
null
)
fab
.
setEnabled
(
true
)
updateState
()
updateState
()
if
(
Build
.
VERSION
.
SDK_INT
>=
21
&&
!
app
.
isVpn
Enabled
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
21
&&
app
.
isNat
Enabled
)
{
val
snackbar
=
Snackbar
.
make
(
findViewById
(
android
.
R
.
id
.
content
),
R
.
string
.
nat_deprecated
,
Snackbar
.
LENGTH_LONG
)
val
snackbar
=
Snackbar
.
make
(
findViewById
(
android
.
R
.
id
.
content
),
R
.
string
.
nat_deprecated
,
Snackbar
.
LENGTH_LONG
)
snackbar
.
setAction
(
R
.
string
.
switch_to_vpn
,
(
_
=>
preferences
.
natSwitch
.
setChecked
(
false
))
:
View.OnClickListener
)
snackbar
.
setAction
(
R
.
string
.
switch_to_vpn
,
(
_
=>
preferences
.
natSwitch
.
setChecked
(
false
))
:
View.OnClickListener
)
snackbar
.
show
snackbar
.
show
...
@@ -307,11 +307,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
...
@@ -307,11 +307,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
cmd
.
append
(
"chmod 666 %s/%s-vpn.pid"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
.
dataDir
,
task
))
cmd
.
append
(
"chmod 666 %s/%s-vpn.pid"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
.
dataDir
,
task
))
}
}
if
(
app
.
isVpnEnabled
)
{
if
(
app
.
isNatEnabled
)
Console
.
runRootCommand
(
cmd
.
toArray
)
else
Console
.
runCommand
(
cmd
.
toArray
)
Console
.
runCommand
(
cmd
.
toArray
)
}
else
{
Console
.
runRootCommand
(
cmd
.
toArray
)
}
cmd
.
clear
()
cmd
.
clear
()
...
@@ -331,10 +327,10 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
...
@@ -331,10 +327,10 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
cmd
.
append
(
"rm -f %s/%s-vpn.pid"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
.
dataDir
,
task
))
cmd
.
append
(
"rm -f %s/%s-vpn.pid"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
.
dataDir
,
task
))
cmd
.
append
(
"rm -f %s/%s-vpn.conf"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
.
dataDir
,
task
))
cmd
.
append
(
"rm -f %s/%s-vpn.conf"
.
formatLocal
(
Locale
.
ENGLISH
,
getApplicationInfo
.
dataDir
,
task
))
}
}
if
(
app
.
is
VpnEnabled
)
Console
.
runCommand
(
cmd
.
toArray
)
else
{
if
(
app
.
is
NatEnabled
)
{
Console
.
runRootCommand
(
cmd
.
toArray
)
Console
.
runRootCommand
(
cmd
.
toArray
)
Console
.
runRootCommand
(
Utils
.
iptables
+
" -t nat -F OUTPUT"
)
Console
.
runRootCommand
(
Utils
.
iptables
+
" -t nat -F OUTPUT"
)
}
}
else
Console
.
runCommand
(
cmd
.
toArray
)
}
}
def
cancelStart
()
{
def
cancelStart
()
{
...
@@ -344,15 +340,13 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
...
@@ -344,15 +340,13 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
def
prepareStartService
()
{
def
prepareStartService
()
{
Utils
.
ThrowableFuture
{
Utils
.
ThrowableFuture
{
if
(
app
.
is
VpnEnabled
)
{
if
(
app
.
is
NatEnabled
)
serviceLoad
()
else
{
val
intent
=
VpnService
.
prepare
(
this
)
val
intent
=
VpnService
.
prepare
(
this
)
if
(
intent
!=
null
)
{
if
(
intent
!=
null
)
{
startActivityForResult
(
intent
,
REQUEST_CONNECT
)
startActivityForResult
(
intent
,
REQUEST_CONNECT
)
}
else
{
}
else
{
handler
.
post
(()
=>
onActivityResult
(
REQUEST_CONNECT
,
Activity
.
RESULT_OK
,
null
))
handler
.
post
(()
=>
onActivityResult
(
REQUEST_CONNECT
,
Activity
.
RESULT_OK
,
null
))
}
}
}
else
{
serviceLoad
()
}
}
}
}
}
}
...
@@ -412,14 +406,11 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
...
@@ -412,14 +406,11 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
success
=
false
success
=
false
result
=
getString
(
R
.
string
.
connection_test_error
,
e
.
getMessage
)
result
=
getString
(
R
.
string
.
connection_test_error
,
e
.
getMessage
)
}
}
synchronized
(
if
(
testCount
==
id
)
{
synchronized
(
if
(
testCount
==
id
&&
app
.
isVpnEnabled
)
handler
.
post
(()
=>
if
(
app
.
isVpnEnabled
)
handler
.
post
(()
=>
{
if
(
success
)
connectionTestText
.
setText
(
result
)
else
{
if
(
success
)
connectionTestText
.
setText
(
result
)
else
{
connectionTestText
.
setText
(
R
.
string
.
connection_test_fail
)
connectionTestText
.
setText
(
R
.
string
.
connection_test_fail
)
Snackbar
.
make
(
findViewById
(
android
.
R
.
id
.
content
),
result
,
Snackbar
.
LENGTH_LONG
).
show
Snackbar
.
make
(
findViewById
(
android
.
R
.
id
.
content
),
result
,
Snackbar
.
LENGTH_LONG
).
show
}))
}
})
})
}
}
}
}
}
}
...
@@ -470,10 +461,10 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
...
@@ -470,10 +461,10 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
preferences
.
setEnabled
(
false
)
preferences
.
setEnabled
(
false
)
fabProgressCircle
.
postDelayed
(
hideCircle
,
100
)
fabProgressCircle
.
postDelayed
(
hideCircle
,
100
)
stat
.
setVisibility
(
View
.
VISIBLE
)
stat
.
setVisibility
(
View
.
VISIBLE
)
if
(
app
.
is
VpnEnabled
)
{
if
(
app
.
is
NatEnabled
)
connectionTestText
.
setVisibility
(
View
.
GONE
)
else
{
connectionTestText
.
setVisibility
(
View
.
VISIBLE
)
connectionTestText
.
setVisibility
(
View
.
VISIBLE
)
connectionTestText
.
setText
(
getString
(
R
.
string
.
connection_test_pending
))
connectionTestText
.
setText
(
getString
(
R
.
string
.
connection_test_pending
))
}
else
connectionTestText
.
setVisibility
(
View
.
GONE
)
}
case
State
.
STOPPING
=>
case
State
.
STOPPING
=>
fab
.
setBackgroundTintList
(
greyTint
)
fab
.
setBackgroundTintList
(
greyTint
)
serviceStarted
=
false
serviceStarted
=
false
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksApplication.scala
View file @
86f32ea6
...
@@ -67,7 +67,8 @@ class ShadowsocksApplication extends Application {
...
@@ -67,7 +67,8 @@ class ShadowsocksApplication extends Application {
lazy
val
editor
=
settings
.
edit
lazy
val
editor
=
settings
.
edit
lazy
val
profileManager
=
new
ProfileManager
(
settings
,
dbHelper
)
lazy
val
profileManager
=
new
ProfileManager
(
settings
,
dbHelper
)
def
isVpnEnabled
=
!
settings
.
getBoolean
(
Key
.
isNAT
,
false
)
def
isNatEnabled
=
settings
.
getBoolean
(
Key
.
isNAT
,
false
)
def
isVpnEnabled
=
!
isNatEnabled
def
getVersionName
=
try
{
def
getVersionName
=
try
{
getPackageManager
.
getPackageInfo
(
getPackageName
,
0
).
versionName
getPackageManager
.
getPackageInfo
(
getPackageName
,
0
).
versionName
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
View file @
86f32ea6
...
@@ -65,16 +65,16 @@ class ShadowsocksRunnerActivity extends Activity with ServiceBoundContext {
...
@@ -65,16 +65,16 @@ class ShadowsocksRunnerActivity extends Activity with ServiceBoundContext {
}
}
def
startBackgroundService
()
{
def
startBackgroundService
()
{
if
(
app
.
isVpnEnabled
)
{
if
(
app
.
isNatEnabled
)
{
bgService
.
use
(
ConfigUtils
.
loadFromSharedPreferences
)
finish
()
}
else
{
val
intent
=
VpnService
.
prepare
(
ShadowsocksRunnerActivity
.
this
)
val
intent
=
VpnService
.
prepare
(
ShadowsocksRunnerActivity
.
this
)
if
(
intent
!=
null
)
{
if
(
intent
!=
null
)
{
startActivityForResult
(
intent
,
REQUEST_CONNECT
)
startActivityForResult
(
intent
,
REQUEST_CONNECT
)
}
else
{
}
else
{
onActivityResult
(
REQUEST_CONNECT
,
Activity
.
RESULT_OK
,
null
)
onActivityResult
(
REQUEST_CONNECT
,
Activity
.
RESULT_OK
,
null
)
}
}
}
else
{
bgService
.
use
(
ConfigUtils
.
loadFromSharedPreferences
)
finish
()
}
}
}
}
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerService.scala
View file @
86f32ea6
...
@@ -58,15 +58,13 @@ class ShadowsocksRunnerService extends Service with ServiceBoundContext {
...
@@ -58,15 +58,13 @@ class ShadowsocksRunnerService extends Service with ServiceBoundContext {
}
}
def
startBackgroundService
()
{
def
startBackgroundService
()
{
if
(
app
.
is
VpnEnabled
)
{
if
(
app
.
is
NatEnabled
)
bgService
.
use
(
ConfigUtils
.
loadFromSharedPreferences
)
else
{
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
.
use
(
ConfigUtils
.
loadFromSharedPreferences
)
bgService
.
use
(
ConfigUtils
.
loadFromSharedPreferences
)
}
}
}
}
}
else
{
bgService
.
use
(
ConfigUtils
.
loadFromSharedPreferences
)
}
}
stopSelf
()
stopSelf
()
}
}
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksSettings.scala
View file @
86f32ea6
...
@@ -156,7 +156,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
...
@@ -156,7 +156,7 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
for
(
name
<-
Key
.
isNAT
#::
PROXY_PREFS
.
toStream
#:::
FEATURE_PREFS
.
toStream
)
{
for
(
name
<-
Key
.
isNAT
#::
PROXY_PREFS
.
toStream
#:::
FEATURE_PREFS
.
toStream
)
{
val
pref
=
findPreference
(
name
)
val
pref
=
findPreference
(
name
)
if
(
pref
!=
null
)
pref
.
setEnabled
(
enabled
&&
if
(
pref
!=
null
)
pref
.
setEnabled
(
enabled
&&
(
name
!=
Key
.
isProxyApps
||
Utils
.
isLollipopOrAbove
||
!
app
.
isVpn
Enabled
))
(
name
!=
Key
.
isProxyApps
||
Utils
.
isLollipopOrAbove
||
app
.
isNat
Enabled
))
}
}
}
}
...
...
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