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
8b57b537
Commit
8b57b537
authored
Jul 29, 2017
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Misc refinements
parent
1db2d81a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
53 deletions
+13
-53
mobile/src/main/java/com/github/shadowsocks/utils/Dns.java
mobile/src/main/java/com/github/shadowsocks/utils/Dns.java
+5
-14
mobile/src/main/scala/com/github/shadowsocks/acl/Acl.scala
mobile/src/main/scala/com/github/shadowsocks/acl/Acl.scala
+8
-39
No files found.
mobile/src/main/java/com/github/shadowsocks/utils/Dns.java
View file @
8b57b537
...
...
@@ -16,24 +16,18 @@
package
com.github.shadowsocks.utils
;
import
android.annotation.SuppressLint
;
import
android.app.PendingIntent
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.annotation.TargetApi
;
import
android.
util.Log
;
import
android.
content.Context
;
import
android.net.ConnectivityManager
;
import
android.net.LinkProperties
;
import
android.os.Build
;
import
java.lang.reflect.Method
;
import
java.
lang.reflect.InvocationTargetException
;
import
java.
net.InetAddress
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.net.InetAddress
;
public
class
Dns
{
public
static
String
getDnsResolver
(
Context
context
)
throws
Exception
{
Collection
<
InetAddress
>
dnsResolvers
=
getDnsResolvers
(
context
);
if
(
dnsResolvers
.
isEmpty
())
{
...
...
@@ -46,25 +40,22 @@ public class Dns {
return
dnsResolver
;
}
@TargetApi
(
Build
.
VERSION_CODES
.
LOLLIPOP
)
private
static
Collection
<
InetAddress
>
getDnsResolvers
(
Context
context
)
throws
Exception
{
ArrayList
<
InetAddress
>
addresses
=
new
ArrayList
<
InetAddress
>();
ConnectivityManager
connectivityManager
=
(
ConnectivityManager
)
context
.
getSystemService
(
Context
.
CONNECTIVITY_SERVICE
);
Class
<?>
LinkPropertiesClass
=
Class
.
forName
(
"android.net.LinkProperties"
);
Method
getActiveLinkPropertiesMethod
=
ConnectivityManager
.
class
.
getMethod
(
"getActiveLinkProperties"
,
new
Class
[]{}
);
Method
getActiveLinkPropertiesMethod
=
ConnectivityManager
.
class
.
getMethod
(
"getActiveLinkProperties"
);
Object
linkProperties
=
getActiveLinkPropertiesMethod
.
invoke
(
connectivityManager
);
if
(
linkProperties
!=
null
)
{
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
Method
getDnsesMethod
=
LinkPropertiesClass
.
getMethod
(
"getDnses"
,
new
Class
[]{}
);
Method
getDnsesMethod
=
LinkPropertiesClass
.
getMethod
(
"getDnses"
);
Collection
<?>
dnses
=
(
Collection
<?>)
getDnsesMethod
.
invoke
(
linkProperties
);
for
(
Object
dns
:
dnses
)
{
addresses
.
add
((
InetAddress
)
dns
);
}
}
else
{
for
(
InetAddress
dns
:
((
LinkProperties
)
linkProperties
).
getDnsServers
())
{
addresses
.
add
(
dns
);
}
addresses
.
addAll
(((
LinkProperties
)
linkProperties
).
getDnsServers
());
}
}
...
...
mobile/src/main/scala/com/github/shadowsocks/acl/Acl.scala
View file @
8b57b537
...
...
@@ -26,26 +26,6 @@ class Acl {
@DatabaseField
var
bypass
:
Boolean
=
_
def
getBypassHostnamesString
:
String
=
bypassHostnames
.
mkString
(
"\n"
)
def
getProxyHostnamesString
:
String
=
proxyHostnames
.
mkString
(
"\n"
)
def
getSubnetsString
:
String
=
subnets
.
mkString
(
"\n"
)
def
setBypassHostnamesString
(
value
:
String
)
{
bypassHostnames
.
clear
()
bypassHostnames
++=
value
.
split
(
"\n"
)
}
def
setProxyHostnamesString
(
value
:
String
)
{
proxyHostnames
.
clear
()
proxyHostnames
++=
value
.
split
(
"\n"
)
}
def
setSubnetsString
(
value
:
String
)
{
subnets
.
clear
()
subnets
++=
value
.
split
(
"\n"
).
map
(
Subnet
.
fromString
)
}
def
setUrlRules
(
value
:
String
)
{
urls
.
clear
()
urls
++=
value
.
split
(
"\n"
)
}
def
fromAcl
(
other
:
Acl
)
:
Acl
=
{
bypassHostnames
.
clear
()
bypassHostnames
++=
other
.
bypassHostnames
...
...
@@ -71,17 +51,10 @@ class Acl {
var
in_urls
=
false
for
(
line
<-
value
.
getLines
())
(
line
.
indexOf
(
'#'
)
match
{
case
-
1
=>
if
(!
in_urls
)
line
else
""
case
index
=>
{
line
.
indexOf
(
"URLS_BEGIN"
)
match
{
case
-
1
=>
case
index
=>
in_urls
=
true
}
line
.
indexOf
(
"URLS_END"
)
match
{
case
-
1
=>
case
index
=>
in_urls
=
false
}
""
// ignore any comment lines
}
case
index
=>
if
(
line
.
contains
(
"URLS_BEGIN"
))
in_urls
=
true
if
(
line
.
contains
(
"URLS_END"
))
in_urls
=
false
line
.
substring
(
0
,
index
)
// trim comments
}).
trim
match
{
case
"[outbound_block_list]"
=>
hostnames
=
null
...
...
@@ -95,10 +68,8 @@ class Acl {
case
"[reject_all]"
|
"[bypass_all]"
=>
bypass
=
true
case
"[accept_all]"
|
"[proxy_all]"
=>
bypass
=
false
case
input
if
subnets
!=
null
&&
input
.
nonEmpty
=>
try
subnets
+=
Subnet
.
fromString
(
input
)
catch
{
case
_:
IllegalArgumentException
=>
if
(
input
.
startsWith
(
"http://"
)
||
input
.
startsWith
(
"https://"
))
{
urls
+=
input
}
hostnames
+=
input
case
_:
IllegalArgumentException
=>
if
(
input
.
startsWith
(
"http://"
)
||
input
.
startsWith
(
"https://"
))
urls
+=
input
else
hostnames
+=
input
}
case
_
=>
}
...
...
@@ -116,7 +87,7 @@ class Acl {
try
{
urls
.
foreach
((
url
:
String
)
=>
result
.
append
(
Source
.
fromURL
(
url
).
mkString
))
}
catch
{
case
e
:
IOException
=>
// ignore
case
_
:
IOException
=>
// ignore
}
}
result
.
append
(
"#URLS_END\n"
)
...
...
@@ -141,9 +112,7 @@ class Acl {
result
.
toString
}
override
def
toString
:
String
=
{
getAclString
(
false
)
}
override
def
toString
:
String
=
getAclString
(
false
)
def
isValidCustomRules
:
Boolean
=
bypass
&&
bypassHostnames
.
isEmpty
...
...
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