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
Show 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 @@
...
@@ -16,24 +16,18 @@
package
com.github.shadowsocks.utils
;
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.annotation.TargetApi
;
import
android.
util.Log
;
import
android.
content.Context
;
import
android.net.ConnectivityManager
;
import
android.net.ConnectivityManager
;
import
android.net.LinkProperties
;
import
android.net.LinkProperties
;
import
android.os.Build
;
import
android.os.Build
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.
lang.reflect.InvocationTargetException
;
import
java.
net.InetAddress
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.net.InetAddress
;
public
class
Dns
{
public
class
Dns
{
public
static
String
getDnsResolver
(
Context
context
)
throws
Exception
{
public
static
String
getDnsResolver
(
Context
context
)
throws
Exception
{
Collection
<
InetAddress
>
dnsResolvers
=
getDnsResolvers
(
context
);
Collection
<
InetAddress
>
dnsResolvers
=
getDnsResolvers
(
context
);
if
(
dnsResolvers
.
isEmpty
())
{
if
(
dnsResolvers
.
isEmpty
())
{
...
@@ -46,25 +40,22 @@ public class Dns {
...
@@ -46,25 +40,22 @@ public class Dns {
return
dnsResolver
;
return
dnsResolver
;
}
}
@TargetApi
(
Build
.
VERSION_CODES
.
LOLLIPOP
)
private
static
Collection
<
InetAddress
>
getDnsResolvers
(
Context
context
)
throws
Exception
{
private
static
Collection
<
InetAddress
>
getDnsResolvers
(
Context
context
)
throws
Exception
{
ArrayList
<
InetAddress
>
addresses
=
new
ArrayList
<
InetAddress
>();
ArrayList
<
InetAddress
>
addresses
=
new
ArrayList
<
InetAddress
>();
ConnectivityManager
connectivityManager
=
ConnectivityManager
connectivityManager
=
(
ConnectivityManager
)
context
.
getSystemService
(
Context
.
CONNECTIVITY_SERVICE
);
(
ConnectivityManager
)
context
.
getSystemService
(
Context
.
CONNECTIVITY_SERVICE
);
Class
<?>
LinkPropertiesClass
=
Class
.
forName
(
"android.net.LinkProperties"
);
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
);
Object
linkProperties
=
getActiveLinkPropertiesMethod
.
invoke
(
connectivityManager
);
if
(
linkProperties
!=
null
)
{
if
(
linkProperties
!=
null
)
{
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
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
);
Collection
<?>
dnses
=
(
Collection
<?>)
getDnsesMethod
.
invoke
(
linkProperties
);
for
(
Object
dns
:
dnses
)
{
for
(
Object
dns
:
dnses
)
{
addresses
.
add
((
InetAddress
)
dns
);
addresses
.
add
((
InetAddress
)
dns
);
}
}
}
else
{
}
else
{
for
(
InetAddress
dns
:
((
LinkProperties
)
linkProperties
).
getDnsServers
())
{
addresses
.
addAll
(((
LinkProperties
)
linkProperties
).
getDnsServers
());
addresses
.
add
(
dns
);
}
}
}
}
}
...
...
mobile/src/main/scala/com/github/shadowsocks/acl/Acl.scala
View file @
8b57b537
...
@@ -26,26 +26,6 @@ class Acl {
...
@@ -26,26 +26,6 @@ class Acl {
@DatabaseField
@DatabaseField
var
bypass
:
Boolean
=
_
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
=
{
def
fromAcl
(
other
:
Acl
)
:
Acl
=
{
bypassHostnames
.
clear
()
bypassHostnames
.
clear
()
bypassHostnames
++=
other
.
bypassHostnames
bypassHostnames
++=
other
.
bypassHostnames
...
@@ -71,17 +51,10 @@ class Acl {
...
@@ -71,17 +51,10 @@ class Acl {
var
in_urls
=
false
var
in_urls
=
false
for
(
line
<-
value
.
getLines
())
(
line
.
indexOf
(
'#'
)
match
{
for
(
line
<-
value
.
getLines
())
(
line
.
indexOf
(
'#'
)
match
{
case
-
1
=>
if
(!
in_urls
)
line
else
""
case
-
1
=>
if
(!
in_urls
)
line
else
""
case
index
=>
{
case
index
=>
line
.
indexOf
(
"URLS_BEGIN"
)
match
{
if
(
line
.
contains
(
"URLS_BEGIN"
))
in_urls
=
true
case
-
1
=>
if
(
line
.
contains
(
"URLS_END"
))
in_urls
=
false
case
index
=>
in_urls
=
true
line
.
substring
(
0
,
index
)
// trim comments
}
line
.
indexOf
(
"URLS_END"
)
match
{
case
-
1
=>
case
index
=>
in_urls
=
false
}
""
// ignore any comment lines
}
}).
trim
match
{
}).
trim
match
{
case
"[outbound_block_list]"
=>
case
"[outbound_block_list]"
=>
hostnames
=
null
hostnames
=
null
...
@@ -95,10 +68,8 @@ class Acl {
...
@@ -95,10 +68,8 @@ class Acl {
case
"[reject_all]"
|
"[bypass_all]"
=>
bypass
=
true
case
"[reject_all]"
|
"[bypass_all]"
=>
bypass
=
true
case
"[accept_all]"
|
"[proxy_all]"
=>
bypass
=
false
case
"[accept_all]"
|
"[proxy_all]"
=>
bypass
=
false
case
input
if
subnets
!=
null
&&
input
.
nonEmpty
=>
try
subnets
+=
Subnet
.
fromString
(
input
)
catch
{
case
input
if
subnets
!=
null
&&
input
.
nonEmpty
=>
try
subnets
+=
Subnet
.
fromString
(
input
)
catch
{
case
_:
IllegalArgumentException
=>
if
(
input
.
startsWith
(
"http://"
)
||
input
.
startsWith
(
"https://"
))
{
case
_:
IllegalArgumentException
=>
if
(
input
.
startsWith
(
"http://"
)
||
input
.
startsWith
(
"https://"
))
urls
+=
input
urls
+=
input
else
hostnames
+=
input
}
hostnames
+=
input
}
}
case
_
=>
case
_
=>
}
}
...
@@ -116,7 +87,7 @@ class Acl {
...
@@ -116,7 +87,7 @@ class Acl {
try
{
try
{
urls
.
foreach
((
url
:
String
)
=>
result
.
append
(
Source
.
fromURL
(
url
).
mkString
))
urls
.
foreach
((
url
:
String
)
=>
result
.
append
(
Source
.
fromURL
(
url
).
mkString
))
}
catch
{
}
catch
{
case
e
:
IOException
=>
// ignore
case
_
:
IOException
=>
// ignore
}
}
}
}
result
.
append
(
"#URLS_END\n"
)
result
.
append
(
"#URLS_END\n"
)
...
@@ -141,9 +112,7 @@ class Acl {
...
@@ -141,9 +112,7 @@ class Acl {
result
.
toString
result
.
toString
}
}
override
def
toString
:
String
=
{
override
def
toString
:
String
=
getAclString
(
false
)
getAclString
(
false
)
}
def
isValidCustomRules
:
Boolean
=
bypass
&&
bypassHostnames
.
isEmpty
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