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
984a0e8f
Commit
984a0e8f
authored
Mar 21, 2022
by
chenhuaqing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code refinement
parent
2677cee4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
36 deletions
+37
-36
app/src/main/java/com/ccwangluo/accelerator/utils/AcceleratorUtils.kt
.../java/com/ccwangluo/accelerator/utils/AcceleratorUtils.kt
+33
-36
core/src/main/java/com/github/shadowsocks/aidl/ShadowsocksConnection.kt
...java/com/github/shadowsocks/aidl/ShadowsocksConnection.kt
+4
-0
No files found.
app/src/main/java/com/ccwangluo/accelerator/utils/AcceleratorUtils.kt
View file @
984a0e8f
...
@@ -2,10 +2,12 @@ package com.ccwangluo.accelerator.utils
...
@@ -2,10 +2,12 @@ package com.ccwangluo.accelerator.utils
import
android.annotation.SuppressLint
import
android.annotation.SuppressLint
import
android.content.Context
import
android.content.Context
import
android.net.Network
import
android.os.RemoteException
import
android.os.RemoteException
import
androidx.activity.result.ActivityResultLauncher
import
androidx.activity.result.ActivityResultLauncher
import
androidx.lifecycle.lifecycleScope
import
androidx.lifecycle.lifecycleScope
import
com.ccnet.acc.NetworkAdapter
import
com.ccnet.acc.NetworkAdapter
import
com.ccnet.acc.aidl.NetworkMode
import
com.ccwangluo.accelerator.model.Game
import
com.ccwangluo.accelerator.model.Game
import
com.ccwangluo.accelerator.model.GameInfo
import
com.ccwangluo.accelerator.model.GameInfo
import
com.ccwangluo.accelerator.model.NetState
import
com.ccwangluo.accelerator.model.NetState
...
@@ -28,12 +30,11 @@ import com.hjq.toast.ToastUtils
...
@@ -28,12 +30,11 @@ import com.hjq.toast.ToastUtils
import
com.xuexiang.xpage.base.XPageActivity
import
com.xuexiang.xpage.base.XPageActivity
import
com.xuexiang.xpage.base.XPageFragment
import
com.xuexiang.xpage.base.XPageFragment
import
com.xuexiang.xutil.common.StringUtils
import
com.xuexiang.xutil.common.StringUtils
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.*
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withContext
import
timber.log.Timber
import
timber.log.Timber
import
java.net.InetAddress
import
java.net.InetSocketAddress
import
java.net.Socket
import
java.net.SocketAddress
import
java.util.concurrent.TimeUnit
import
java.util.concurrent.TimeUnit
...
@@ -327,43 +328,39 @@ object AcceleratorUtils {
...
@@ -327,43 +328,39 @@ object AcceleratorUtils {
connection
.
disconnect
(
context
)
connection
.
disconnect
(
context
)
}
}
private
fun
testLatency
()
{
private
suspend
fun
testLatency
()
{
val
networkAutoSwitch
=
false
val
networkAutoSwitch
=
true
// TODO: 根据用户设置测试延迟 ,过高时切换 connection.bindNetwork(NetworkMode.CELLULAR.code)
if
(
networkAutoSwitch
)
{
if
(
networkAutoSwitch
)
{
val
wifiLatency
:
Long
=
NetworkAdapter
.
wifiNetwork
?.
let
{
wifi
->
val
wifiLatency
:
Int
=
doTestLatency
(
DataStore
.
pingAccHost
,
DataStore
.
pingAccPort
,
NetworkAdapter
.
wifiNetwork
)
try
{
val
cellularLatency
:
Int
=
doTestLatency
(
DataStore
.
pingAccHost
,
DataStore
.
pingAccPort
,
NetworkAdapter
.
cellularNetwork
)
val
pingAddress
=
wifi
.
getByName
(
DataStore
.
pingNetReachableHost
)
// DataStore.pingAccHost
Timber
.
d
(
"wifi latency: $wifiLatency, cellular latency: $cellularLatency"
)
val
start
=
System
.
currentTimeMillis
()
}
else
{
pingAddress
.
isReachable
(
DataStore
.
pingTimeoutMillis
)
val
currentNetworkLatency
=
doTestLatency
(
DataStore
.
pingAccHost
,
DataStore
.
pingAccPort
,
null
,
true
)
System
.
currentTimeMillis
()
-
start
Timber
.
d
(
"network latency: $currentNetworkLatency"
)
}
catch
(
_
:
Exception
)
{
}
-
1L
}
}
}
?:
-
1
val
cellularLatency
:
Long
=
NetworkAdapter
.
cellularNetwork
?.
let
{
wifi
->
private
suspend
fun
doTestLatency
(
pingHost
:
String
,
pingPort
:
Int
,
network
:
Network
?,
systemNetwork
:
Boolean
=
false
):
Int
{
return
withTimeoutOrNull
(
DataStore
.
pingTimeoutMillis
.
toLong
())
{
try
{
try
{
val
pingAddress
=
wifi
.
getByName
(
DataStore
.
pingNetReachableHost
)
// DataStore.pingAccHost
val
socketAddress
:
Socket
=
when
{
val
start
=
System
.
currentTimeMillis
()
network
!=
null
->
{
pingAddress
.
isReachable
(
DataStore
.
pingTimeoutMillis
)
network
.
socketFactory
.
createSocket
()
System
.
currentTimeMillis
()
-
start
}
}
catch
(
_
:
Exception
)
{
systemNetwork
->
{
-
1L
Socket
()
}
else
->
{
return
@withTimeoutOrNull
-
1
}
}
}
}
?:
-
1
Timber
.
d
(
"wifi latency: $wifiLatency, cellular latency: $cellularLatency"
)
}
else
{
val
currentNetworkLatency
=
try
{
val
defaultNetAddress
=
InetAddress
.
getByName
(
DataStore
.
pingNetReachableHost
)
// DataStore.pingAccHost
val
start
=
System
.
currentTimeMillis
()
val
start
=
System
.
currentTimeMillis
()
defaultNetAddress
.
isReachable
(
DataStore
.
pingTimeoutMillis
)
socketAddress
.
connect
(
InetSocketAddress
(
pingHost
,
pingPort
),
DataStore
.
pingTimeoutMillis
)
System
.
currentTimeMillis
()
-
start
(
System
.
currentTimeMillis
()
-
start
).
toInt
()
}
catch
(
_
:
Exception
)
{
}
catch
(
_
:
Exception
)
{
-
1L
-
1
}
Timber
.
d
(
"network latency: $currentNetworkLatency"
)
}
}
}
?:
-
1
}
}
}
}
\ No newline at end of file
core/src/main/java/com/github/shadowsocks/aidl/ShadowsocksConnection.kt
View file @
984a0e8f
...
@@ -153,4 +153,8 @@ class ShadowsocksConnection(private var listenForDeath: Boolean = false) : Servi
...
@@ -153,4 +153,8 @@ class ShadowsocksConnection(private var listenForDeath: Boolean = false) : Servi
service
=
null
service
=
null
callback
=
null
callback
=
null
}
}
fun
bindNetwork
(
networkMode
:
Int
)
{
service
?.
bindNetwork
(
networkMode
)
}
}
}
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