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
36cdcdac
Commit
36cdcdac
authored
Feb 09, 2014
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix some issues
parent
c4833ddb
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
147 additions
and
102 deletions
+147
-102
src/main/AndroidManifest.xml
src/main/AndroidManifest.xml
+1
-1
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+29
-17
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
.../scala/com/github/shadowsocks/ShadowsocksNatService.scala
+38
-35
src/main/scala/com/github/shadowsocks/ShadowsocksReceiver.scala
...in/scala/com/github/shadowsocks/ShadowsocksReceiver.scala
+1
-2
src/main/scala/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
...la/com/github/shadowsocks/ShadowsocksRunnerActivity.scala
+37
-10
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
.../scala/com/github/shadowsocks/ShadowsocksVpnService.scala
+41
-37
No files found.
src/main/AndroidManifest.xml
View file @
36cdcdac
...
...
@@ -54,7 +54,7 @@
</activity>
<activity
android:name=
".Shadow
Vpn
Activity"
android:name=
".Shadow
socksRunner
Activity"
android:theme=
"@style/PopupTheme"
android:launchMode=
"singleTask"
>
</activity>
...
...
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
36cdcdac
...
...
@@ -531,7 +531,6 @@ class Shadowsocks
onContentChanged
()
}
/** Called when the activity is first created. */
override
def
onCreate
(
savedInstanceState
:
Bundle
)
{
// Initialize the preference
...
...
@@ -580,17 +579,22 @@ class Shadowsocks
// Register broadcast receiver
registerReceiver
(
preferenceReceiver
,
new
IntentFilter
(
Action
.
UPDATE_PREFS
))
// Bind to the service
spawn
{
status
.
edit
.
putBoolean
(
Key
.
isRoot
,
Utils
.
getRoot
).
apply
()
handler
.
post
(
new
Runnable
{
override
def
run
()
{
}
def
attachService
()
{
if
(
bgService
==
null
)
{
val
isRoot
=
status
.
getBoolean
(
Key
.
isRoot
,
false
)
val
s
=
if
(
isRoot
)
classOf
[
ShadowsocksNatService
]
else
classOf
[
ShadowsocksVpnService
]
bindService
(
new
Intent
(
s
.
getName
),
connection
,
Context
.
BIND_AUTO_CREATE
)
startService
(
new
Intent
(
Shadowsocks
.
this
,
s
))
}
})
}
def
deattachService
()
{
if
(
bgService
!=
null
)
{
bgService
.
unregisterCallback
(
callback
)
unbindService
(
connection
)
bgService
=
null
}
}
...
...
@@ -806,11 +810,22 @@ class Shadowsocks
protected
override
def
onPause
()
{
super
.
onPause
()
deattachService
()
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
()
}
})
}
ConfigUtils
.
refresh
(
this
)
}
...
...
@@ -860,10 +875,6 @@ class Shadowsocks
override
def
onDestroy
()
{
super
.
onDestroy
()
if
(
bgService
!=
null
)
{
bgService
.
unregisterCallback
(
callback
)
unbindService
(
connection
)
}
Crouton
.
cancelAllCroutons
()
unregisterReceiver
(
preferenceReceiver
)
new
BackupManager
(
this
).
dataChanged
()
...
...
@@ -913,6 +924,7 @@ class Shadowsocks
}
case
_
=>
clearDialog
()
switchButton
.
setChecked
(
false
)
Log
.
e
(
Shadowsocks
.
TAG
,
"Failed to start VpnService"
)
}
}
...
...
@@ -921,7 +933,7 @@ class Shadowsocks
def
isVpnEnabled
:
Boolean
=
{
if
(
Shadowsocks
.
vpnEnabled
<
0
)
{
Shadowsocks
.
vpnEnabled
=
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
ICE_CREAM_SANDWICH
&&
!
Utils
.
getRoot
)
{
>=
Build
.
VERSION_CODES
.
ICE_CREAM_SANDWICH
&&
!
status
.
getBoolean
(
Key
.
isRoot
,
false
)
)
{
1
}
else
{
0
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
View file @
36cdcdac
...
...
@@ -57,6 +57,7 @@ import org.apache.http.conn.util.InetAddressUtils
import
scala.collection._
import
java.util.
{
TimerTask
,
Timer
}
import
android.net.TrafficStats
import
scala.concurrent.ops._
import
com.github.shadowsocks.utils._
import
scala.Some
import
android.graphics.Color
...
...
@@ -421,7 +422,7 @@ class ShadowsocksNatService extends Service with BaseService {
override
def
startRunner
(
c
:
Config
)
{
var
config
=
c
config
=
c
// register close receiver
val
filter
=
new
IntentFilter
()
...
...
@@ -474,6 +475,7 @@ class ShadowsocksNatService extends Service with BaseService {
timer
.
schedule
(
task
,
TIMER_INTERVAL
*
1000
,
TIMER_INTERVAL
*
1000
)
}
spawn
{
if
(
config
.
proxy
==
"198.199.101.152"
)
{
val
container
=
getApplication
.
asInstanceOf
[
ShadowsocksApplication
].
tagContainer
try
{
...
...
@@ -515,6 +517,7 @@ class ShadowsocksNatService extends Service with BaseService {
}
handler
.
sendEmptyMessageDelayed
(
Msg
.
CONNECT_FINISH
,
500
)
}
}
override
def
stopRunner
()
{
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksReceiver.scala
View file @
36cdcdac
...
...
@@ -64,8 +64,7 @@ class ShadowsocksReceiver extends BroadcastReceiver {
val
isAutoConnect
:
Boolean
=
settings
.
getBoolean
(
Key
.
isAutoConnect
,
false
)
val
isInstalled
:
Boolean
=
status
.
getBoolean
(
versionName
,
false
)
if
(
isAutoConnect
&&
isInstalled
)
{
if
(
Utils
.
getRoot
)
{
}
context
.
startActivity
(
new
Intent
(
context
,
classOf
[
ShadowsocksRunnerActivity
]))
}
}
}
src/main/scala/com/github/shadowsocks/Shadow
Vpn
Activity.scala
→
src/main/scala/com/github/shadowsocks/Shadow
socksRunner
Activity.scala
View file @
36cdcdac
...
...
@@ -42,41 +42,68 @@ package com.github.shadowsocks
import
android.app.Activity
import
android.os.
{
IBinder
,
Bundle
}
import
android.net.VpnService
import
android.content.
{
ComponentName
,
ServiceConnection
,
Intent
}
import
android.content.
{
Co
ntext
,
Co
mponentName
,
ServiceConnection
,
Intent
}
import
android.util.Log
import
android.preference.PreferenceManager
import
com.github.shadowsocks.utils._
import
com.github.shadowsocks.aidl.IShadowsocksService
class
ShadowVpnActivity
extends
Activity
{
class
ShadowsocksRunnerActivity
extends
Activity
{
lazy
val
settings
=
PreferenceManager
.
getDefaultSharedPreferences
(
this
)
lazy
val
isRoot
=
Utils
.
getRoot
// Services
var
bgService
:
IShadowsocksService
=
null
val
connection
=
new
ServiceConnection
{
override
def
onServiceConnected
(
name
:
ComponentName
,
service
:
IBinder
)
{
bgService
=
IShadowsocksService
.
Stub
.
asInterface
(
service
)
if
(!
isRoot
)
{
val
intent
=
VpnService
.
prepare
(
ShadowsocksRunnerActivity
.
this
)
if
(
intent
!=
null
)
{
startActivityForResult
(
intent
,
Shadowsocks
.
REQUEST_CONNECT
)
}
else
{
onActivityResult
(
Shadowsocks
.
REQUEST_CONNECT
,
Activity
.
RESULT_OK
,
null
)
}
}
else
{
bgService
.
start
(
ConfigUtils
.
load
(
settings
))
}
}
override
def
onServiceDisconnected
(
name
:
ComponentName
)
{
bgService
=
null
}
}
def
attachService
()
{
if
(
bgService
==
null
)
{
val
s
=
if
(
isRoot
)
classOf
[
ShadowsocksNatService
]
else
classOf
[
ShadowsocksVpnService
]
bindService
(
new
Intent
(
s
.
getName
),
connection
,
Context
.
BIND_AUTO_CREATE
)
startService
(
new
Intent
(
this
,
s
))
}
}
def
deattachService
()
{
if
(
bgService
!=
null
)
{
unbindService
(
connection
)
bgService
=
null
}
}
override
def
onCreate
(
savedInstanceState
:
Bundle
)
{
super
.
onCreate
(
savedInstanceState
)
val
intent
=
VpnService
.
prepare
(
this
)
if
(
intent
!=
null
)
{
startActivityForResult
(
intent
,
Shadowsocks
.
REQUEST_CONNECT
)
}
else
{
onActivityResult
(
Shadowsocks
.
REQUEST_CONNECT
,
Activity
.
RESULT_OK
,
null
)
attachService
()
}
override
def
onDestroy
()
{
super
.
onDestroy
()
deattachService
()
}
override
def
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
)
{
resultCode
match
{
case
Activity
.
RESULT_OK
=>
if
(
bgService
!=
null
)
{
bgService
.
start
(
ConfigUtils
.
load
(
PreferenceManager
.
getDefaultSharedPreferences
(
this
)
))
bgService
.
start
(
ConfigUtils
.
load
(
settings
))
}
case
_
=>
Log
.
e
(
Shadowsocks
.
TAG
,
"Failed to start VpnService"
)
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
View file @
36cdcdac
...
...
@@ -51,11 +51,12 @@ import java.io._
import
android.net.VpnService
import
org.apache.http.conn.util.InetAddressUtils
import
android.os.Message
import
scala.concurrent.ops._
import
org.apache.commons.net.util.SubnetUtils
import
java.net.InetAddress
import
com.github.shadowsocks.utils._
import
scala.Some
import
com.github.shadowsocks.aidl.
Config
import
com.github.shadowsocks.aidl.
{
IShadowsocksService
,
Config
}
class
ShadowsocksVpnService
extends
VpnService
with
BaseService
{
...
...
@@ -266,6 +267,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
notificationManager
=
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
.
asInstanceOf
[
NotificationManager
]
}
def
killProcesses
()
{
...
...
@@ -291,11 +293,11 @@ class ShadowsocksVpnService extends VpnService with BaseService {
override
def
startRunner
(
c
:
Config
)
{
var
config
=
c
config
=
c
// ensure the VPNService is prepared
if
(
VpnService
.
prepare
(
this
)
!=
null
)
{
val
i
=
new
Intent
(
this
,
classOf
[
Shadow
Vpn
Activity
])
val
i
=
new
Intent
(
this
,
classOf
[
Shadow
socksRunner
Activity
])
i
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
)
startActivity
(
i
)
return
...
...
@@ -321,6 +323,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
changeState
(
State
.
CONNECTING
)
spawn
{
if
(
config
.
proxy
==
"198.199.101.152"
)
{
val
container
=
getApplication
.
asInstanceOf
[
ShadowsocksApplication
].
tagContainer
try
{
...
...
@@ -360,6 +363,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
}
handler
.
sendEmptyMessageDelayed
(
Msg
.
CONNECT_FINISH
,
300
)
}
}
override
def
stopRunner
()
{
...
...
@@ -394,6 +398,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
}
override
def
getTag
=
TAG
override
def
getServiceMode
=
Mode
.
VPN
}
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