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
5c2d548d
Commit
5c2d548d
authored
Dec 14, 2017
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce the number of default methods
parent
2fa8bc7f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
29 deletions
+27
-29
mobile/src/main/java/com/github/shadowsocks/bg/BaseService.kt
...le/src/main/java/com/github/shadowsocks/bg/BaseService.kt
+25
-28
mobile/src/main/java/com/github/shadowsocks/bg/LocalDnsService.kt
...rc/main/java/com/github/shadowsocks/bg/LocalDnsService.kt
+2
-1
No files found.
mobile/src/main/java/com/github/shadowsocks/bg/BaseService.kt
View file @
5c2d548d
...
...
@@ -91,10 +91,8 @@ object BaseService {
}
var
closeReceiverRegistered
=
false
private
fun
state
()
=
state
val
binder
=
object
:
IShadowsocksService
.
Stub
()
{
override
fun
getState
():
Int
=
state
()
override
fun
getState
():
Int
=
this
@Data
.
state
override
fun
getProfileName
():
String
=
profile
?.
formattedName
?:
"Idle"
override
fun
registerCallback
(
cb
:
IShadowsocksServiceCallback
)
{
...
...
@@ -182,6 +180,24 @@ object BaseService {
}
File
(
app
.
filesDir
,
"shadowsocks.json"
).
bufferedWriter
().
use
{
it
.
write
(
config
.
toString
())
}
}
val
aclFile
:
File
?
get
()
{
val
route
=
profile
!!
.
route
return
if
(
route
==
Acl
.
ALL
)
null
else
Acl
.
getFile
(
if
(
route
==
Acl
.
CUSTOM_RULES
)
Acl
.
CUSTOM_RULES_FLATTENED
else
route
)
}
fun
changeState
(
s
:
Int
,
msg
:
String
?
=
null
)
{
if
(
state
==
s
&&
msg
==
null
)
return
if
(
callbacks
.
registeredCallbackCount
>
0
)
app
.
handler
.
post
{
val
n
=
callbacks
.
beginBroadcast
()
for
(
i
in
0
until
n
)
try
{
callbacks
.
getBroadcastItem
(
i
).
stateChanged
(
s
,
binder
.
profileName
,
msg
)
}
catch
(
_
:
Exception
)
{
}
// ignore
callbacks
.
finishBroadcast
()
}
state
=
s
}
}
interface
Interface
{
val
tag
:
String
...
...
@@ -221,7 +237,7 @@ object BaseService {
"-t"
,
"600"
,
"-c"
,
"shadowsocks.json"
))
val
acl
=
getAclFile
()
val
acl
=
data
.
aclFile
if
(
acl
!=
null
)
{
cmd
+=
"--acl"
cmd
+=
acl
.
absolutePath
...
...
@@ -232,12 +248,6 @@ object BaseService {
data
.
sslocalProcess
=
GuardedProcess
(
cmd
).
start
()
}
fun
getAclFile
():
File
?
{
val
route
=
data
.
profile
!!
.
route
return
if
(
route
==
Acl
.
ALL
)
null
else
Acl
.
getFile
(
if
(
route
==
Acl
.
CUSTOM_RULES
)
Acl
.
CUSTOM_RULES_FLATTENED
else
route
)
}
fun
createNotification
():
ServiceNotification
fun
startRunner
()
{
...
...
@@ -254,14 +264,14 @@ object BaseService {
fun
stopRunner
(
stopService
:
Boolean
,
msg
:
String
?
=
null
)
{
// channge the state
changeState
(
STOPPING
)
val
data
=
data
data
.
changeState
(
STOPPING
)
app
.
track
(
tag
,
"stop"
)
killProcesses
()
// clean up recevier
val
data
=
data
this
as
Service
if
(
data
.
closeReceiverRegistered
)
{
unregisterReceiver
(
data
.
closeReceiver
)
...
...
@@ -279,7 +289,7 @@ object BaseService {
data
.
trafficMonitorThread
=
null
// change the state
changeState
(
STOPPED
,
msg
)
data
.
changeState
(
STOPPED
,
msg
)
// stop the service if nothing has bound to it
if
(
stopService
)
stopSelf
()
...
...
@@ -318,7 +328,7 @@ object BaseService {
data
.
notification
=
createNotification
()
app
.
track
(
tag
,
"start"
)
changeState
(
CONNECTING
)
data
.
changeState
(
CONNECTING
)
thread
{
this
as
Context
...
...
@@ -369,7 +379,7 @@ object BaseService {
if
(
profile
.
route
!
in
arrayOf
(
Acl
.
ALL
,
Acl
.
CUSTOM_RULES
))
AclSyncJob
.
schedule
(
profile
.
route
)
changeState
(
CONNECTED
)
data
.
changeState
(
CONNECTED
)
}
catch
(
_
:
UnknownHostException
)
{
stopRunner
(
true
,
getString
(
R
.
string
.
invalid_server
))
}
catch
(
_
:
VpnService
.
NullConnectionException
)
{
...
...
@@ -381,19 +391,6 @@ object BaseService {
}
return
Service
.
START_NOT_STICKY
}
fun
changeState
(
s
:
Int
,
msg
:
String
?
=
null
)
{
val
data
=
instances
[
this
]
!!
if
(
data
.
state
==
s
&&
msg
==
null
)
return
if
(
data
.
callbacks
.
registeredCallbackCount
>
0
)
app
.
handler
.
post
{
val
n
=
data
.
callbacks
.
beginBroadcast
()
for
(
i
in
0
until
n
)
try
{
data
.
callbacks
.
getBroadcastItem
(
i
).
stateChanged
(
s
,
data
.
binder
.
profileName
,
msg
)
}
catch
(
_
:
Exception
)
{
}
// ignore
data
.
callbacks
.
finishBroadcast
()
}
data
.
state
=
s
}
}
private
val
instances
=
WeakHashMap
<
Interface
,
Data
>()
...
...
mobile/src/main/java/com/github/shadowsocks/bg/LocalDnsService.kt
View file @
5c2d548d
...
...
@@ -44,6 +44,7 @@ object LocalDnsService {
override
fun
startNativeProcesses
()
{
super
.
startNativeProcesses
()
val
data
=
data
val
profile
=
data
.
profile
!!
fun
makeDns
(
name
:
String
,
address
:
String
,
edns
:
Boolean
=
true
):
JSONObject
{
...
...
@@ -89,7 +90,7 @@ object LocalDnsService {
.
put
(
"PrimaryDNS"
,
localDns
)
.
put
(
"AlternativeDNS"
,
remoteDns
)
.
put
(
"IPNetworkFile"
,
"china_ip_list.txt"
)
.
put
(
"DomainFile"
,
getAclFile
()
!!
.
absolutePath
)
.
put
(
"DomainFile"
,
data
.
aclFile
!!
.
absolutePath
)
Acl
.
CHINALIST
->
config
.
put
(
"PrimaryDNS"
,
localDns
)
.
put
(
"AlternativeDNS"
,
remoteDns
)
...
...
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