Commit c9921bec authored by sheteng's avatar sheteng

加速器调试

parent f0acd09f
...@@ -9,6 +9,7 @@ import com.ccwangluo.accelerator.utils.PhoneUtils ...@@ -9,6 +9,7 @@ import com.ccwangluo.accelerator.utils.PhoneUtils
import com.github.shadowsocks.Core import com.github.shadowsocks.Core
import com.hjq.toast.ToastUtils import com.hjq.toast.ToastUtils
import com.tencent.map.geolocation.TencentLocationManager import com.tencent.map.geolocation.TencentLocationManager
import com.tencent.mmkv.MMKV
import com.xuexiang.xpage.PageConfig import com.xuexiang.xpage.PageConfig
import com.xuexiang.xpage.base.XPageActivity import com.xuexiang.xpage.base.XPageActivity
...@@ -26,6 +27,7 @@ class App : Application(), androidx.work.Configuration.Provider by Core { ...@@ -26,6 +27,7 @@ class App : Application(), androidx.work.Configuration.Provider by Core {
ToastUtils.init(this) ToastUtils.init(this)
MultiDex.install(this) MultiDex.install(this)
Core.init(this, MainActivity::class) Core.init(this, MainActivity::class)
MMKV.initialize(this)
} }
override fun onConfigurationChanged(newConfig: Configuration) { override fun onConfigurationChanged(newConfig: Configuration) {
......
package com.ccwangluo.accelerator.model
data class Game(
val list: List<GameInfo>?,
val total: Int?
)
data class GameInfo(
val anotherName: String,
val createdDate: String,
val gameName: String,
val greatNum: Int,
val icon: String,
val id: Int,
val imgs: String,
val introduction: String,
val packageName: String
)
\ No newline at end of file
...@@ -9,6 +9,7 @@ import com.ccwangluo.accelerator.ui.home.AccelertorFragment ...@@ -9,6 +9,7 @@ import com.ccwangluo.accelerator.ui.home.AccelertorFragment
import com.ccwangluo.accelerator.ui.home.AccelertorViewModel import com.ccwangluo.accelerator.ui.home.AccelertorViewModel
import com.ccwangluo.accelerator.ui.home.MineFragment import com.ccwangluo.accelerator.ui.home.MineFragment
import com.ccwangluo.accelerator.ui.home.NewsFragment import com.ccwangluo.accelerator.ui.home.NewsFragment
import com.ccwangluo.accelerator.utils.AcceleratorUtils
import com.ccwangluo.accelerator.utils.LoginUtils import com.ccwangluo.accelerator.utils.LoginUtils
import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomnavigation.BottomNavigationView
import com.xuexiang.xpage.annotation.Page import com.xuexiang.xpage.annotation.Page
...@@ -54,6 +55,7 @@ class BottomNavigationFragment : XPageFragment(), ViewPager.OnPageChangeListener ...@@ -54,6 +55,7 @@ class BottomNavigationFragment : XPageFragment(), ViewPager.OnPageChangeListener
binding.viewPager.setOffscreenPageLimit(titles.size - 1); binding.viewPager.setOffscreenPageLimit(titles.size - 1);
binding.viewPager.adapter = adapter binding.viewPager.adapter = adapter
AcceleratorUtils.getGameList(this,{})
} }
override fun initListeners() { override fun initListeners() {
......
...@@ -11,8 +11,9 @@ import com.ccwangluo.accelerator.ui.home.AccelertorViewModel ...@@ -11,8 +11,9 @@ import com.ccwangluo.accelerator.ui.home.AccelertorViewModel
import com.ccwangluo.accelerator.ui.login.SplashFragment import com.ccwangluo.accelerator.ui.login.SplashFragment
import com.ccwangluo.accelerator.utils.AcceleratorUtils import com.ccwangluo.accelerator.utils.AcceleratorUtils
import com.ccwangluo.accelerator.utils.PhoneUtils import com.ccwangluo.accelerator.utils.PhoneUtils
import com.github.shadowsocks.HttpConfig import com.github.shadowsocks.http.HttpConfig
import com.ccwangluo.cc_quickly.utils.SettingSPUtils import com.ccwangluo.cc_quickly.utils.SettingSPUtils
import com.github.shadowsocks.bg.AuthManager
import com.github.shadowsocks.utils.StartService import com.github.shadowsocks.utils.StartService
import com.hjq.toast.ToastUtils import com.hjq.toast.ToastUtils
import com.karumi.dexter.Dexter import com.karumi.dexter.Dexter
...@@ -44,7 +45,6 @@ class MainActivity() : XPageActivity(), TencentLocationListener { ...@@ -44,7 +45,6 @@ class MainActivity() : XPageActivity(), TencentLocationListener {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
accelertorViewModel = accelertorViewModel =
ViewModelProvider(this).get(AccelertorViewModel::class.java) ViewModelProvider(this).get(AccelertorViewModel::class.java)
MMKV.initialize(this)
initPhoneUtils() initPhoneUtils()
//获取权限 //获取权限
Dexter.withContext(this) Dexter.withContext(this)
...@@ -95,7 +95,6 @@ class MainActivity() : XPageActivity(), TencentLocationListener { ...@@ -95,7 +95,6 @@ class MainActivity() : XPageActivity(), TencentLocationListener {
} }
AcceleratorUtils.initConnect(this, connect) AcceleratorUtils.initConnect(this, connect)
} }
private fun initPhoneUtils() { private fun initPhoneUtils() {
...@@ -136,7 +135,11 @@ class MainActivity() : XPageActivity(), TencentLocationListener { ...@@ -136,7 +135,11 @@ class MainActivity() : XPageActivity(), TencentLocationListener {
} }
override fun onLocationChanged(p0: TencentLocation?, p1: Int, p2: String?) { override fun onLocationChanged(p0: TencentLocation?, p1: Int, p2: String?) {
println(p0) if (p1 == 0){
p0?.province?.let {
AuthManager.area = it
}
}
} }
override fun onStatusUpdate(p0: String?, p1: Int, p2: String?) { override fun onStatusUpdate(p0: String?, p1: Int, p2: String?) {
......
...@@ -5,7 +5,7 @@ import android.os.Bundle ...@@ -5,7 +5,7 @@ import android.os.Bundle
import android.widget.ImageView import android.widget.ImageView
import com.ccwangluo.accelerator.R import com.ccwangluo.accelerator.R
import com.ccwangluo.accelerator.ui.web.CommonWebViewFragment import com.ccwangluo.accelerator.ui.web.CommonWebViewFragment
import com.github.shadowsocks.HttpConfig import com.github.shadowsocks.http.HttpConfig
import com.xuexiang.xpage.base.XPageFragment import com.xuexiang.xpage.base.XPageFragment
import com.xuexiang.xui.widget.dialog.materialdialog.CustomMaterialDialog import com.xuexiang.xui.widget.dialog.materialdialog.CustomMaterialDialog
import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
......
package com.ccwangluo.accelerator.ui.home package com.ccwangluo.accelerator.ui.home
import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
...@@ -18,11 +17,12 @@ import com.ccwangluo.accelerator.utils.AcceleratorUtils ...@@ -18,11 +17,12 @@ import com.ccwangluo.accelerator.utils.AcceleratorUtils
import com.ccwangluo.accelerator.utils.LoginUtils import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.utils.SysUtils import com.ccwangluo.accelerator.utils.SysUtils
import com.ccwangluo.cc_quickly.utils.SettingSPUtils import com.ccwangluo.cc_quickly.utils.SettingSPUtils
import com.github.shadowsocks.HttpConfig import com.github.shadowsocks.http.HttpConfig
import com.github.shadowsocks.bg.BaseService import com.github.shadowsocks.bg.BaseService
import com.hjq.toast.ToastUtils import com.hjq.toast.ToastUtils
import com.xuexiang.xpage.base.XPageFragment import com.xuexiang.xpage.base.XPageFragment
import com.xuexiang.xpage.utils.TitleBar import com.xuexiang.xpage.utils.TitleBar
import com.xuexiang.xutil.app.AppUtils
class AccelertorFragment : XPageFragment() { class AccelertorFragment : XPageFragment() {
private lateinit var binding: FragmentQuickBinding private lateinit var binding: FragmentQuickBinding
...@@ -86,13 +86,13 @@ class AccelertorFragment : XPageFragment() { ...@@ -86,13 +86,13 @@ class AccelertorFragment : XPageFragment() {
} }
binding.activeNetwork.setText(SysUtils.getActiveNet()) binding.activeNetwork.setText(SysUtils.getActiveNet())
if (SettingSPUtils.isSmartAccOpen) { if (SettingSPUtils.isSmartAccOpen) {
binding.smartAccOpen.setText("已开启") binding.smartAccOpen.setText("已开启 >")
binding.smartAccOpen.setTextColor(resources.getColor(R.color.open_acc_enable)) binding.smartAccOpen.setTextColor(resources.getColor(R.color.open_acc_enable))
binding.smartAccOpenBtn.visibility = View.GONE binding.smartAccOpenArea.visibility = View.GONE
} else { } else {
binding.smartAccOpen.setText("未开启 >") binding.smartAccOpen.setText("未开启 >")
binding.smartAccOpen.setTextColor(resources.getColor(R.color.white)) binding.smartAccOpen.setTextColor(resources.getColor(R.color.white))
binding.smartAccOpenBtn.visibility = View.VISIBLE binding.smartAccOpenArea.visibility = View.VISIBLE
} }
}) })
...@@ -112,33 +112,32 @@ class AccelertorFragment : XPageFragment() { ...@@ -112,33 +112,32 @@ class AccelertorFragment : XPageFragment() {
override fun initListeners() { override fun initListeners() {
binding.iconNotice.setOnClickListener { binding.iconNotice.setOnClickListener {
openToWebview("/message") openToWebview(HttpConfig.UI_MESSAGE_URL)
} }
binding.gamePage.setOnClickListener { binding.gamePage.setOnClickListener {
openToWebview("/game") openToWebview(HttpConfig.UI_GAME_URL)
} }
binding.smartAccOpen.setOnClickListener { binding.smartAccOpen.setOnClickListener {
if (!SettingSPUtils.isSmartAccOpen) { if (!SettingSPUtils.isSmartAccOpen) {
openToWebview("/setting") openToWebview(HttpConfig.UI_SETTING_URL)
} }
} }
binding.smartAccOpenBtn.setOnClickListener { binding.smartAccOpenBtn.setOnClickListener {
if (!SettingSPUtils.isSmartAccOpen) { if (!SettingSPUtils.isSmartAccOpen) {
openToWebview("/setting") openToWebview(HttpConfig.UI_SETTING_URL)
} }
} }
binding.preventAccLost.setOnClickListener { binding.preventAccLost.setOnClickListener {
openToWebview("/questionDetail") openToWebview(HttpConfig.UI_QUESTION_URL)
} }
binding.preventAccInvalid.setOnClickListener { binding.preventAccInvalid.setOnClickListener {
openToWebview("/speed") openToWebview(HttpConfig.UI_SPEED_URL)
} }
binding.btnExpend.setOnClickListener { binding.btnExpend.setOnClickListener {
if (binding.expandableLayout1.isExpanded) { if (binding.expandableLayout1.isExpanded) {
binding.expandableLayout1.toggle() binding.expandableLayout1.toggle()
...@@ -176,17 +175,33 @@ class AccelertorFragment : XPageFragment() { ...@@ -176,17 +175,33 @@ class AccelertorFragment : XPageFragment() {
}, 2000) }, 2000)
return@setOnClickListener return@setOnClickListener
} }
// TODO: 2022/2/16 是否安装了这个包 AcceleratorUtils.getGameList(this) {
if (it) {
//
AcceleratorUtils.game?.let {
if (AppUtils.isInstallApp(it.packageName)) {
binding.quickTopToastTx.setText("请先安装游戏后加速")
binding.quickTopToastTx.postDelayed({
binding.quickTopToastTx.visibility = View.GONE
}, 2000)
return@getGameList
}
}
//用户是否有使用时长 //用户是否有使用时长
LoginUtils.getUserHasTimer(this) { LoginUtils.getUserHasTimer(this) {
if (it) { if (it) {
binding.btnQuick.isEnabled = false binding.btnQuick.isEnabled = false
AcceleratorUtils.startAccelerator() AcceleratorUtils.startAccelerator(this)
startAnim() startAnim()
} else { } else {
MemberDialog(this).show<MemberDialog>() MemberDialog(this).show<MemberDialog>()
} }
} }
} else {
ToastUtils.show("获取游戏配置异常")
}
}
} }
} }
...@@ -225,6 +240,14 @@ class AccelertorFragment : XPageFragment() { ...@@ -225,6 +240,14 @@ class AccelertorFragment : XPageFragment() {
binding.accStateTx.setText(SysUtils.getAccTimeString(time)) binding.accStateTx.setText(SysUtils.getAccTimeString(time))
binding.accStateTx.visibility = View.VISIBLE binding.accStateTx.visibility = View.VISIBLE
binding.btnQuick.setBackgroundResource(R.mipmap.quick_stop) binding.btnQuick.setBackgroundResource(R.mipmap.quick_stop)
if (SettingSPUtils.isFirstAccSuccess) {
CommonDialog(this).setTitle("防止加速掉线")
.setContent("为了防止加速进程被手机系统中断,影响游戏加速,请确保完成相关设置")
.setBtnLeft("取消", {}).setBtnRight("去设置", {
openToWebview(HttpConfig.UI_SETTING_URL)
}).show<CommonDialog>()
SettingSPUtils.isFirstAccSuccess = false
}
} else if (state == BaseService.State.Stopped) { } else if (state == BaseService.State.Stopped) {
stopAnim() stopAnim()
binding.accStateTx.visibility = View.GONE binding.accStateTx.visibility = View.GONE
......
...@@ -2,20 +2,9 @@ package com.ccwangluo.accelerator.ui.home ...@@ -2,20 +2,9 @@ package com.ccwangluo.accelerator.ui.home
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ccwangluo.accelerator.model.LoginRes
import com.ccwangluo.accelerator.model.NetState import com.ccwangluo.accelerator.model.NetState
import com.ccwangluo.accelerator.model.UserProfile import com.ccwangluo.accelerator.model.UserProfile
import com.ccwangluo.accelerator.utils.LoginUtils
import com.ccwangluo.accelerator.utils.SysUtils
import com.ccwangluo.accelerator.utils.http.HttpGo
import com.github.shadowsocks.bg.BaseService import com.github.shadowsocks.bg.BaseService
import com.hjq.toast.ToastUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.io.BufferedReader
import java.io.InputStreamReader
class AccelertorViewModel : ViewModel() { class AccelertorViewModel : ViewModel() {
...@@ -28,4 +17,7 @@ class AccelertorViewModel : ViewModel() { ...@@ -28,4 +17,7 @@ class AccelertorViewModel : ViewModel() {
//用户状态 //用户状态
var userProfile = MutableLiveData<UserProfile>() var userProfile = MutableLiveData<UserProfile>()
//加速配置
// var gameConfig = MutableLiveData<GameConfig>()
} }
\ No newline at end of file
package com.ccwangluo.accelerator.ui.home package com.ccwangluo.accelerator.ui.home
import android.content.Intent
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
...@@ -9,7 +8,7 @@ import androidx.fragment.app.Fragment ...@@ -9,7 +8,7 @@ import androidx.fragment.app.Fragment
import com.ccwangluo.accelerator.databinding.FragmentMineBinding import com.ccwangluo.accelerator.databinding.FragmentMineBinding
import com.ccwangluo.accelerator.ui.web.AndroidInterface import com.ccwangluo.accelerator.ui.web.AndroidInterface
import com.ccwangluo.accelerator.utils.LoginUtils import com.ccwangluo.accelerator.utils.LoginUtils
import com.github.shadowsocks.HttpConfig import com.github.shadowsocks.http.HttpConfig
import com.just.agentweb.core.AgentWeb import com.just.agentweb.core.AgentWeb
import com.just.agentweb.core.client.DefaultWebClient import com.just.agentweb.core.client.DefaultWebClient
import com.xuexiang.xpage.base.XPageFragment import com.xuexiang.xpage.base.XPageFragment
...@@ -69,19 +68,6 @@ class MineFragment : XPageFragment() { ...@@ -69,19 +68,6 @@ class MineFragment : XPageFragment() {
.go(url) .go(url)
} }
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
super.setUserVisibleHint(isVisibleToUser)
if (isVisibleToUser) {
LoginUtils.token?.let {
agentWeb?.getJsAccessEntrace()
?.quickCallJs("userToken", it)
} ?: let {
agentWeb?.getJsAccessEntrace()
?.quickCallJs("clearToken")
}
}
}
override fun onHiddenChanged(hidden: Boolean) { override fun onHiddenChanged(hidden: Boolean) {
super.onHiddenChanged(hidden) super.onHiddenChanged(hidden)
if (!hidden) { if (!hidden) {
......
...@@ -2,9 +2,8 @@ package com.ccwangluo.accelerator.ui.web ...@@ -2,9 +2,8 @@ package com.ccwangluo.accelerator.ui.web
import android.os.Bundle import android.os.Bundle
import android.webkit.JavascriptInterface import android.webkit.JavascriptInterface
import androidx.core.content.ContextCompat.checkSelfPermission
import com.ccwangluo.accelerator.utils.LoginUtils import com.ccwangluo.accelerator.utils.LoginUtils
import com.github.shadowsocks.HttpConfig import com.github.shadowsocks.http.HttpConfig
import com.ccwangluo.cc_quickly.utils.SettingSPUtils import com.ccwangluo.cc_quickly.utils.SettingSPUtils
import com.ccwangluo.cc_quickly.utils.XToastUtils import com.ccwangluo.cc_quickly.utils.XToastUtils
import com.just.agentweb.core.AgentWeb import com.just.agentweb.core.AgentWeb
......
...@@ -6,15 +6,27 @@ import android.os.RemoteException ...@@ -6,15 +6,27 @@ import android.os.RemoteException
import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.ActivityResultLauncher
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.ccwangluo.accelerator.model.NetState import com.ccwangluo.accelerator.model.*
import com.ccwangluo.accelerator.utils.http.HttpGo
import com.ccwangluo.cc_quickly.utils.SettingSPUtils
import com.github.shadowsocks.Core import com.github.shadowsocks.Core
import com.github.shadowsocks.acl.Acl
import com.github.shadowsocks.aidl.IShadowsocksService import com.github.shadowsocks.aidl.IShadowsocksService
import com.github.shadowsocks.aidl.IShadowsocksServiceCallback
import com.github.shadowsocks.aidl.ShadowsocksConnection import com.github.shadowsocks.aidl.ShadowsocksConnection
import com.github.shadowsocks.bg.AuthManager
import com.github.shadowsocks.bg.AuthManager.ACC_TIME
import com.github.shadowsocks.bg.BaseService import com.github.shadowsocks.bg.BaseService
import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.database.ProfileManager import com.github.shadowsocks.database.ProfileManager
import com.github.shadowsocks.http.LineConfig
import com.hjq.toast.ToastUtils
import com.tencent.mmkv.MMKV
import com.xuexiang.xpage.base.XPageFragment
import com.xuexiang.xutil.net.NetworkUtils import com.xuexiang.xutil.net.NetworkUtils
import kotlinx.coroutines.* import kotlinx.coroutines.*
import timber.log.Timber
import java.util.concurrent.Executors import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
...@@ -34,21 +46,37 @@ object AcceleratorUtils { ...@@ -34,21 +46,37 @@ object AcceleratorUtils {
// service // service
var state = BaseService.State.Idle var state = BaseService.State.Idle
//游戏
var game: GameInfo? = null
//加速前延迟 //加速前延迟
var pre_net = -1 var pre_net = -1
//加速后延迟 //加速后延迟
var acc_net = -1 var acc_net = -1
//
var count = 0
// 加速时长
var ACC_TIME = 0L
var stateListener: (BaseService.State, Long, NetState?) -> Unit = { state, l, net -> var stateListener: (BaseService.State, Long, NetState?) -> Unit = { state, l, net ->
} }
fun getGameList(xPageFragment: XPageFragment, callback: (Boolean) -> Unit) {
game?.let {
callback(true)
} ?: let {
xPageFragment.lifecycleScope.launch(Dispatchers.IO) {
val res = HttpGo.getSync<Game>("/api/new/game/list?id=1&page=1&size=1")
res?.let {
game = it.data?.list?.get(0)
callback(true)
game?.let {
AuthManager.gameId = it.id.toString()
}
}
}
}
}
fun initConnect(context: AppCompatActivity, connect: ActivityResultLauncher<Void?>) { fun initConnect(context: AppCompatActivity, connect: ActivityResultLauncher<Void?>) {
this.context = context this.context = context
...@@ -57,7 +85,7 @@ object AcceleratorUtils { ...@@ -57,7 +85,7 @@ object AcceleratorUtils {
ProfileManager.ensureNotEmpty() ProfileManager.ensureNotEmpty()
context.lifecycleScope.launch(Dispatchers.IO) { context.lifecycleScope.launch(Dispatchers.IO) {
while (true) { while (true) {
val net = SysUtils.getNetPing("10.3.0.34") val net = SysUtils.getNetPing("10.3.0.229")
if (state != BaseService.State.Connected) { if (state != BaseService.State.Connected) {
pre_net = net.delay pre_net = net.delay
acc_net = -1 acc_net = -1
...@@ -72,6 +100,8 @@ object AcceleratorUtils { ...@@ -72,6 +100,8 @@ object AcceleratorUtils {
net.preNetDelay = pre_net net.preNetDelay = pre_net
net.accNetDelay = acc_net net.accNetDelay = acc_net
stateListener(state, getAccTime(), net) stateListener(state, getAccTime(), net)
delay(1000) delay(1000)
} }
} }
...@@ -83,9 +113,55 @@ object AcceleratorUtils { ...@@ -83,9 +113,55 @@ object AcceleratorUtils {
} }
} }
fun startAccelerator() { fun startAccelerator(xPageFragment: XPageFragment) {
game?.let {
initAuthProfile(xPageFragment)
}
}
fun initAuthProfile(xPageFragment: XPageFragment) {
xPageFragment.lifecycleScope.launch(Dispatchers.IO) {
AuthManager.getLineConfig()?.let {
if (it.code != 200){
return@let
}
val profileId = 1L
val profile = ProfileManager.getProfile(profileId) ?: Profile()
profile.host = it.data.host
profile.token = it.data.token
profile.remotePort = it.data.port
profile.proxyApps = true
val proxyGames = mutableSetOf(
"com.sec.android.app.sbrowser",
"com.nexon.maplem.global",
"jp.co.cygames.umamusume",
"com.ea.gp.apexlegendsmobilefps",
"jp.konami.duellinks",
"com.riotgames.league.wildrift",
"com.garena.game.codm",
"com.google.android.configupdater",
"com.miHoYo.GenshinImpact",
"com.rekoo.pubgm",
"com.pubg.krmobile",
"com.tgc.sky.android",
"com.YoStarJP.Arknights",
"com.riotgames.league.wildrifttw"
)
proxyGames.addAll(profile.individual.split("\n"))
Timber.d("start vpn with games: $proxyGames")
profile.individual = proxyGames.joinToString("\n")
profile.route = Acl.BYPASS_LAN
profile.password = "barfoo!"
profile.method = "none"
profile.beatsInterval = 60
withContext(Dispatchers.Main){
ProfileManager.updateProfile(profile)
connect.launch(null) connect.launch(null)
} }
}
}
}
fun registerStateListener(listener: (BaseService.State, Long, NetState?) -> Unit) { fun registerStateListener(listener: (BaseService.State, Long, NetState?) -> Unit) {
stateListener = listener stateListener = listener
...@@ -105,9 +181,6 @@ object AcceleratorUtils { ...@@ -105,9 +181,6 @@ object AcceleratorUtils {
private val shadowsocksConnection = object : ShadowsocksConnection.Callback { private val shadowsocksConnection = object : ShadowsocksConnection.Callback {
override fun stateChanged(state: BaseService.State, profileName: String?, msg: String?) { override fun stateChanged(state: BaseService.State, profileName: String?, msg: String?) {
AcceleratorUtils.state = state AcceleratorUtils.state = state
if (state == BaseService.State.Connected) {
ACC_TIME = System.currentTimeMillis()
}
stateListener(state, getAccTime(), null) stateListener(state, getAccTime(), null)
} }
......
...@@ -8,6 +8,7 @@ import com.ccwangluo.accelerator.model.UserProfile ...@@ -8,6 +8,7 @@ import com.ccwangluo.accelerator.model.UserProfile
import com.ccwangluo.accelerator.ui.login.PhoneLoginFragment import com.ccwangluo.accelerator.ui.login.PhoneLoginFragment
import com.ccwangluo.accelerator.utils.http.HttpGo import com.ccwangluo.accelerator.utils.http.HttpGo
import com.chuanglan.shanyan_sdk.OneKeyLoginManager import com.chuanglan.shanyan_sdk.OneKeyLoginManager
import com.github.shadowsocks.bg.AuthManager
import com.hjq.toast.ToastUtils import com.hjq.toast.ToastUtils
import com.tencent.mmkv.MMKV import com.tencent.mmkv.MMKV
import com.xuexiang.xpage.base.XPageFragment import com.xuexiang.xpage.base.XPageFragment
...@@ -107,6 +108,7 @@ object LoginUtils { ...@@ -107,6 +108,7 @@ object LoginUtils {
res?.let { res?.let {
if (it.code == 200) { if (it.code == 200) {
token = it.data?.token token = it.data?.token
AuthManager.authToken = token
ToastUtils.show("登录成功") ToastUtils.show("登录成功")
OneKeyLoginManager.getInstance().finishAuthActivity() OneKeyLoginManager.getInstance().finishAuthActivity()
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
......
...@@ -9,18 +9,18 @@ import com.tencent.mmkv.MMKV ...@@ -9,18 +9,18 @@ import com.tencent.mmkv.MMKV
* @since 2018/11/27 下午5:16 * @since 2018/11/27 下午5:16
*/ */
object SettingSPUtils { object SettingSPUtils {
private val IS_FIRST_OPEN_KEY = "is_first_open_key" private val IS_FIRST_ACC_SUCCESS = "is_first_acc_success"
private val IS_AGREE_PRIVACY_KEY = "is_agree_privacy_key" private val IS_AGREE_PRIVACY_KEY = "is_agree_privacy_key"
private val IS_SMART_ACC_OPEN = "is_smart_acc_open" private val IS_SMART_ACC_OPEN = "is_smart_acc_open"
/** /**
* 设置是否是第一次启动 * 设置是否是第一次启动加速
*/ */
var isFirstOpen: Boolean var isFirstAccSuccess: Boolean
get() = MMKV.defaultMMKV().decodeBool(IS_FIRST_OPEN_KEY, true) get() = MMKV.defaultMMKV().decodeBool(IS_FIRST_ACC_SUCCESS, true)
set(isFirstOpen) { set(isFirstOpen) {
MMKV.defaultMMKV().putBoolean(IS_FIRST_OPEN_KEY, isFirstOpen) MMKV.defaultMMKV().putBoolean(IS_FIRST_ACC_SUCCESS, isFirstOpen)
} }
/** /**
...@@ -40,4 +40,6 @@ object SettingSPUtils { ...@@ -40,4 +40,6 @@ object SettingSPUtils {
set(isSmartAccOpen) { set(isSmartAccOpen) {
MMKV.defaultMMKV().putBoolean(IS_SMART_ACC_OPEN, isSmartAccOpen) MMKV.defaultMMKV().putBoolean(IS_SMART_ACC_OPEN, isSmartAccOpen)
} }
} }
\ No newline at end of file
...@@ -2,11 +2,12 @@ package com.ccwangluo.accelerator.utils.http ...@@ -2,11 +2,12 @@ package com.ccwangluo.accelerator.utils.http
import com.ccwangluo.accelerator.model.BaseModel import com.ccwangluo.accelerator.model.BaseModel
import com.ccwangluo.accelerator.utils.LoginUtils import com.ccwangluo.accelerator.utils.LoginUtils
import com.github.shadowsocks.HttpConfig import com.github.shadowsocks.http.HttpConfig
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.hjq.toast.ToastUtils import com.hjq.toast.ToastUtils
import okhttp3.* import okhttp3.*
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.RequestBody.Companion.toRequestBody
import timber.log.Timber import timber.log.Timber
...@@ -129,4 +130,5 @@ object HttpGo { ...@@ -129,4 +130,5 @@ object HttpGo {
} }
} }
} }
} }
...@@ -509,6 +509,7 @@ ...@@ -509,6 +509,7 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/smart_acc_open_area"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="11dp" android:layout_marginTop="11dp"
......
...@@ -17,5 +17,6 @@ ...@@ -17,5 +17,6 @@
<item name="tabSelectedTextColor">@color/black</item> <item name="tabSelectedTextColor">@color/black</item>
<item name="android:textSize">16sp</item> <item name="android:textSize">16sp</item>
<item name="android:textColor">#FF9E9E9E</item> <item name="android:textColor">#FF9E9E9E</item>
<item name="tabBackground">@color/white</item>
</style> </style>
</resources> </resources>
\ No newline at end of file
...@@ -33,9 +33,7 @@ dependencies { ...@@ -33,9 +33,7 @@ dependencies {
api("androidx.drawerlayout:drawerlayout:1.1.1") api("androidx.drawerlayout:drawerlayout:1.1.1")
api("androidx.fragment:fragment-ktx:1.3.5") api("androidx.fragment:fragment-ktx:1.3.5")
api("com.google.android.material:material:1.4.0") api("com.google.android.material:material:1.4.0")
implementation("com.squareup.okhttp3:okhttp:4.9.0")
api("com.android.volley:volley:1.2.0")
api("androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion") api("androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion")
api("androidx.lifecycle:lifecycle-livedata-core-ktx:$lifecycleVersion") api("androidx.lifecycle:lifecycle-livedata-core-ktx:$lifecycleVersion")
api("androidx.preference:preference:1.1.1") api("androidx.preference:preference:1.1.1")
...@@ -44,12 +42,11 @@ dependencies { ...@@ -44,12 +42,11 @@ dependencies {
api("androidx.work:work-runtime-ktx:$workVersion") api("androidx.work:work-runtime-ktx:$workVersion")
api("com.google.android.gms:play-services-oss-licenses:17.0.0") api("com.google.android.gms:play-services-oss-licenses:17.0.0")
api("com.google.code.gson:gson:2.8.7") api("com.google.code.gson:gson:2.8.7")
// api("com.google.firebase:firebase-analytics-ktx:19.0.0")
// api("com.google.firebase:firebase-crashlytics:18.1.0")
api("com.jakewharton.timber:timber:4.7.1") api("com.jakewharton.timber:timber:4.7.1")
api("dnsjava:dnsjava:3.4.0") api("dnsjava:dnsjava:3.4.0")
api("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion") api("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion")
api("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutinesVersion") api("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutinesVersion")
implementation("com.tencent:mmkv:1.2.10")
kapt("androidx.room:room-compiler:$roomVersion") kapt("androidx.room:room-compiler:$roomVersion")
androidTestImplementation("androidx.room:room-testing:$roomVersion") androidTestImplementation("androidx.room:room-testing:$roomVersion")
androidTestImplementation("androidx.test.ext:junit-ktx:1.1.3") androidTestImplementation("androidx.test.ext:junit-ktx:1.1.3")
......
package com.github.shadowsocks
object HttpConfig {
//app后端
val baseUrl = "http://test-cc-tt-api.orangenet.org.cn"
/**
* 主页h5
*/
val UI_MAIN_URL = "http://10.3.0.217:8080/#"
//隐私协议地址
val privacy_url = "http:wwww.baidu.com"
}
\ No newline at end of file
...@@ -26,6 +26,7 @@ import android.content.Intent ...@@ -26,6 +26,7 @@ import android.content.Intent
import android.content.ServiceConnection import android.content.ServiceConnection
import android.os.IBinder import android.os.IBinder
import android.os.RemoteException import android.os.RemoteException
import com.github.shadowsocks.bg.AuthManager.ACC_TIME
import com.github.shadowsocks.bg.BaseService import com.github.shadowsocks.bg.BaseService
import com.github.shadowsocks.bg.VpnService import com.github.shadowsocks.bg.VpnService
import com.github.shadowsocks.utils.Action import com.github.shadowsocks.utils.Action
...@@ -68,6 +69,11 @@ class ShadowsocksConnection(private var listenForDeath: Boolean = false) : Servi ...@@ -68,6 +69,11 @@ class ShadowsocksConnection(private var listenForDeath: Boolean = false) : Servi
val callback = callback ?: return val callback = callback ?: return
GlobalScope.launch(Dispatchers.Main.immediate) { GlobalScope.launch(Dispatchers.Main.immediate) {
callback.stateChanged(BaseService.State.values()[state], profileName, msg) callback.stateChanged(BaseService.State.values()[state], profileName, msg)
if (BaseService.State.values()[state] == BaseService.State.Connected) {
ACC_TIME = System.currentTimeMillis()
} else {
ACC_TIME = 0L
}
} }
} }
override fun trafficUpdated(profileId: Long, stats: TrafficStats) { override fun trafficUpdated(profileId: Long, stats: TrafficStats) {
......
package com.github.shadowsocks.bg package com.github.shadowsocks.bg
import android.os.Build import android.os.Build
import com.android.volley.Request
import com.android.volley.RequestQueue
import com.android.volley.toolbox.RequestFuture
import com.android.volley.toolbox.StringRequest
import com.android.volley.toolbox.Volley
import com.github.shadowsocks.Core import com.github.shadowsocks.Core
import com.github.shadowsocks.HttpConfig import com.github.shadowsocks.http.HttpConfig
import com.github.shadowsocks.acl.Acl import com.github.shadowsocks.acl.Acl
import com.github.shadowsocks.database.Profile import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.database.ProfileManager import com.github.shadowsocks.database.ProfileManager
import com.github.shadowsocks.http.FreshToken
import com.github.shadowsocks.http.LineConfig
import com.google.gson.Gson
import com.google.gson.JsonStreamParser import com.google.gson.JsonStreamParser
import com.google.gson.reflect.TypeToken
import com.tencent.mmkv.MMKV
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.Response
import timber.log.Timber import timber.log.Timber
import java.io.File import java.io.File
import java.security.SecureRandom
import java.security.cert.X509Certificate
import java.util.concurrent.Executors import java.util.concurrent.Executors
import java.util.concurrent.ScheduledFuture import java.util.concurrent.ScheduledFuture
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlin.concurrent.thread import javax.net.ssl.SSLContext
import javax.net.ssl.SSLSocketFactory
import javax.net.ssl.X509TrustManager
object AuthManager { object AuthManager {
private val queue: RequestQueue = Volley.newRequestQueue(Core.app.applicationContext)
val executor = Executors.newScheduledThreadPool(1) val executor = Executors.newScheduledThreadPool(1)
var scheduleAtFixedRate: ScheduledFuture<*>? = null var scheduleAtFixedRate: ScheduledFuture<*>? = null
val okHttpClient: OkHttpClient
val gson: Gson
init {
okHttpClient = OkHttpClient().newBuilder()
.readTimeout(60, TimeUnit.SECONDS)//设置读取超时时间
.writeTimeout(60, TimeUnit.SECONDS)//设置写的超时时间
.connectTimeout(60, TimeUnit.SECONDS)//设置连接超时时间
//https支持
.hostnameVerifier { hostname, session -> true }
.sslSocketFactory(initSSLSocketFactory(), initTrustManager())
.build()
gson = Gson()
}
var gameId: String?
get() = MMKV.defaultMMKV().decodeString("CONFIG_GAMEID", null)
set(gameId) {
MMKV.defaultMMKV().putString("CONFIG_GAMEID", gameId)
}
var area: String?
get() = MMKV.defaultMMKV().decodeString("CONFIG_AREA", null)
set(gameId) {
MMKV.defaultMMKV().putString("CONFIG_AREA", gameId)
}
var authToken: String?
get() = MMKV.defaultMMKV().decodeString("CONFIG_AUTHTOKEN", null)
set(token) {
MMKV.defaultMMKV().putString("CONFIG_AUTHTOKEN", token)
}
// 加速时长
var ACC_TIME :Long
get() = MMKV.defaultMMKV().decodeLong("ACC_TIME", 0L)
set(acc_time) {
MMKV.defaultMMKV().putLong("ACC_TIME", acc_time)
}
fun initAuthProfile() { fun initAuthProfile() {
GlobalScope.launch { GlobalScope.launch(Dispatchers.Main) {
getToken()?.let { withContext(Dispatchers.IO){
getLineConfig()?.let {
if (it.code != 200){
return@withContext
}
val profileId = 1L val profileId = 1L
val profile = ProfileManager.getProfile(profileId) ?: Profile() val profile = ProfileManager.getProfile(profileId) ?: Profile()
profile.host = "10.3.0.34" profile.host = it.data.host
profile.token = it profile.token = it.data.token
profile.remotePort = 8398 profile.remotePort = it.data.port
profile.proxyApps = true profile.proxyApps = true
val proxyGames = mutableSetOf( val proxyGames = mutableSetOf(
"com.sec.android.app.sbrowser", "com.sec.android.app.sbrowser",
...@@ -61,14 +114,11 @@ object AuthManager { ...@@ -61,14 +114,11 @@ object AuthManager {
profile.method = "none" profile.method = "none"
profile.beatsInterval = 60 profile.beatsInterval = 60
ProfileManager.updateProfile(profile) ProfileManager.updateProfile(profile)
Timber.d("init auth config: ${profile.toJson()}")
} }
} }
}
} }
var reqCount = 1
fun updateConfig(data: BaseService.Data) { fun updateConfig(data: BaseService.Data) {
if (data.state != BaseService.State.Connected) { if (data.state != BaseService.State.Connected) {
return return
...@@ -82,10 +132,9 @@ object AuthManager { ...@@ -82,10 +132,9 @@ object AuthManager {
.single().asJsonObject .single().asJsonObject
if (data.state == BaseService.State.Connected) { if (data.state == BaseService.State.Connected) {
val token = getToken()
token?.let { getToken()?.let {
configJson.addProperty("token", token) configJson.addProperty("token", it.data.token)
Timber.d("recv latest config: $configJson")
configFile.writeText(configJson.toString()) configFile.writeText(configJson.toString())
} }
...@@ -94,30 +143,86 @@ object AuthManager { ...@@ -94,30 +143,86 @@ object AuthManager {
}, 3, 3, TimeUnit.MINUTES) }, 3, 3, TimeUnit.MINUTES)
} }
fun getToken(): String? { fun getToken(): FreshToken? {
val retryLimit = 0 ProfileManager.getProfile(1L)?.let {
val map = mutableMapOf<String, String>()
it.token?.let { it1 -> map.put("token", it1) }
return postSync<FreshToken>("/api/acc/line/refresh", map)
}
return null
}
val tokenFuture: RequestFuture<String> = RequestFuture.newFuture() val jsonType get() = "application/json; charset=utf-8".toMediaTypeOrNull()
val tokenRequest =
StringRequest( fun getLineConfig(
Request.Method.GET, ): LineConfig? {
HttpConfig.baseUrl, val map = mutableMapOf<String, String>()
tokenFuture, area?.let { map.put("area", it) }
tokenFuture gameId?.let {
) map.put("gameId", it)
queue.add(tokenRequest) }
return postSync<LineConfig>("/api/acc/line", map)
}
inline fun <reified T> postSync(
url: String,
map: Map<String, String>
): T? {
try { try {
reqCount = 0 val body: RequestBody = gson.toJson(map).toString().toRequestBody(jsonType)
return tokenFuture.get() val request = Request.Builder()
} catch (e: Exception) { .url(HttpConfig.baseUrl + url)
Timber.e(e, "get latest config failed") .post(body)
if (reqCount == retryLimit) {
Core.stopService() authToken?.let {
scheduleAtFixedRate?.cancel(true) request.addHeader("Authorization", it)
}
val call = okHttpClient.newCall(request.build())
val response: Response = call.execute()
if (response.isSuccessful) {
val string = response.body?.string()
println(string)
val type = object : TypeToken<T>() {}.type
return gson.fromJson(string, type)
} }
reqCount++ return null
} catch (e: java.lang.Exception) {
println(e)
} }
return null return null
} }
private fun initSSLSocketFactory(): SSLSocketFactory {
var sslContext: SSLContext? = null
try {
sslContext = SSLContext.getInstance("SSL")
val xTrustArray = arrayOf(initTrustManager())
sslContext.init(
null,
xTrustArray, SecureRandom()
)
} catch (e: Exception) {
e.printStackTrace()
}
return sslContext!!.socketFactory
}
private fun initTrustManager(): X509TrustManager {
return object : X509TrustManager {
override fun getAcceptedIssuers(): Array<X509Certificate> {
return arrayOf()
}
override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?) {
}
override fun checkClientTrusted(chain: Array<out X509Certificate>?, authType: String?) {
}
}
}
} }
\ No newline at end of file
package com.github.shadowsocks.http
data class FreshToken(
val code: Int,
val error:String?,
val `data`: Token
)
data class Token(
val token: String?
)
\ No newline at end of file
package com.github.shadowsocks.http
object HttpConfig {
//app后端
val baseUrl = "https://test-cc-tt-api.orangenet.org.cn"
/**
* 主页h5
*/
val UI_MAIN_URL = "https://test-cc-tt-front.orangenet.org.cn/#"
//隐私协议地址
val privacy_url = "http:wwww.baidu.com"
val UI_MESSAGE_URL = "/message"
val UI_GAME_URL = "/game"
val UI_SETTING_URL = "/setting"
val UI_QUESTION_URL = "/questionDetail"
val UI_SPEED_URL = "/speed"
}
\ No newline at end of file
package com.github.shadowsocks.http
data class LineConfig(
val code: Int,
val `data`: Data
)
data class Data(
val host: String,
val method: String,
val port: Int,
val token: String
)
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<network-security-config> <network-security-config>
<domain-config cleartextTrafficPermitted="true"> <domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">192.168.137.1</domain>
<domain includeSubdomains="true">10.3.0.34</domain>
</domain-config> </domain-config>
</network-security-config> </network-security-config>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment