Compare commits

...
18 Commits
Author SHA1 Message Date
Kr328 50d73ad498 update version & dependencies 2020-04-21 22:38:43 +08:00
Kr328 d1f8bc3062 fix delete profile not cancel auto update 2020-04-21 22:32:16 +08:00
Kr328 d3353b1aa5 fix update interval reset 2020-04-21 22:29:21 +08:00
Kr328 cd48fb4e08 fix dialer hook 2020-04-21 22:27:09 +08:00
Kr328 f70738ecf5 update clash core 2020-04-21 22:18:40 +08:00
Kr328 2d63466597 update tun2socket 2020-04-21 21:43:35 +08:00
Kr328 ecf67443fb remove reduce zero ip detect 2020-04-20 12:35:07 +08:00
Kr328 43987ad111 remove reduce zero ip detect 2020-04-20 12:34:27 +08:00
Kr328 5fbd6c6196 Update bug report issue 2020-04-19 02:06:12 +08:00
Kr328 1ec7f1f7e9 Merge branch 'master' into dev 2020-04-19 02:01:39 +08:00
Kr328 c5104c241a add basic url auth support 2020-04-18 20:41:20 +08:00
Kr328 021ba3519d format export log file entry 2020-04-17 13:50:10 +08:00
Kr328 119f74cd05 fix profile edit fragment cast crash 2020-04-17 00:19:39 +08:00
Kr328 f0b61c9e1f cleanup code 2020-04-16 22:40:27 +08:00
Kr328 a573631068 use set directly instead of toList 2020-04-16 22:36:45 +08:00
Kr328 a12444b258 add tun start failure detect 2020-04-16 21:52:11 +08:00
Kr328 e958e7f675 Update 03-bug-report-zh-cn.md 2020-03-22 20:45:20 +08:00
Kr328 68113e694e update issue template 2020-03-22 13:04:50 +08:00
17 changed files with 134 additions and 82 deletions

No files matched your search

+2 -2
View File
@@ -31,7 +31,7 @@ if applicable, add logs to help detect problem
- Device: [e.g. Pixel 4]
- ROM: [e.g: AOSP]
- ROM Version:
- Android Version [e.g. Oreo]
- Android Version [e.g. 10]
**Application Info (please complete the following information):**
@@ -40,4 +40,4 @@ if applicable, add logs to help detect problem
- Distribution Channel: [e.g. Google Play]
**Additional context**
Add any other context about the problem here.
Add any other context about the problem here.
@@ -24,13 +24,12 @@ assignees: ''
如果适用, 上传屏幕截图以帮助描述错误
**日志**
如果适用, 上传日志以帮助侦测错误
**设备信息 (请完成一下信息):**
**设备信息 (请完成以下信息):**
- 机型: [例如: Pixel 4]
- 系统/ROM: [例如: MIUI 11]
- Android 版本 [例如: Oreo]
- Android 版本 [例如: 10]
- ROM版本 [例如: 20.3.19]
**应用信息**
+1
View File
@@ -0,0 +1 @@
blank_issues_enabled: false
@@ -16,7 +16,6 @@ import kotlinx.android.synthetic.main.activity_log_viewer.*
import kotlinx.coroutines.*
import kotlinx.coroutines.sync.Mutex
import java.io.File
import kotlin.streams.toList
class LogViewerActivity : BaseActivity() {
private val pauseMutex = Mutex()
@@ -92,15 +91,15 @@ class LogViewerActivity : BaseActivity() {
launch {
val items = withContext(Dispatchers.IO) {
try {
file.readText()
.split("\n")
.parallelStream()
.map { it.trim() }
.filter { it.isNotEmpty() && !it.startsWith("#") }
.map { it.split(" ", limit = 3) }
.filter { it.size == 3 }
.map { LogEvent(LogEvent.Level.valueOf(it[1]), it[2], it[0].toLong()) }
.toList()
file.bufferedReader().useLines { lines ->
lines
.map { it.trim() }
.filter { it.isNotEmpty() && !it.startsWith("#") }
.map { it.split(" ", limit = 3) }
.filter { it.size == 3 }
.map { LogEvent(LogEvent.Level.valueOf(it[1]), it[2], it[0].toLong()) }
.toList()
}
} catch (e: Exception) {
showSnackbarException(getString(R.string.open_log_failure), e.message)
@@ -13,6 +13,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.github.kr328.clash.adapter.LogFileAdapter
import com.github.kr328.clash.common.utils.intent
import com.github.kr328.clash.common.utils.startForegroundServiceCompat
import com.github.kr328.clash.core.event.LogEvent
import com.github.kr328.clash.design.common.Category
import com.github.kr328.clash.design.view.CommonUiLayout
import com.github.kr328.clash.model.LogFile
@@ -24,12 +25,15 @@ import kotlinx.android.synthetic.main.activity_logs.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.FileInputStream
import java.text.SimpleDateFormat
import java.util.*
class LogsActivity : BaseActivity() {
companion object {
const val REQUEST_CODE = 50000
private val LOG_EXPORT_DATE_FORMAT = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH)
private val LOG_EXPORT_TIME_FORMAT = SimpleDateFormat("HH:mm:ss", Locale.ENGLISH)
}
private var lastWriteFile: LogFile? = null
@@ -102,9 +106,31 @@ class LogsActivity : BaseActivity() {
launch {
withContext(Dispatchers.IO) {
contentResolver.openOutputStream(url)?.use { output ->
FileInputStream(logsDir.resolve(file.fileName)).use { input ->
input.copyTo(output)
contentResolver.openOutputStream(url)?.bufferedWriter()?.use { output ->
output.write("# Logcat on " + LOG_EXPORT_DATE_FORMAT.format(Date(file.date)) + "\n")
logsDir.resolve(file.fileName).bufferedReader().useLines { lines ->
lines.map { it.trim() }
.filter { it.isNotEmpty() && !it.startsWith("#") }
.map { it.split(" ", limit = 3) }
.filter { it.size == 3 }
.map {
LogEvent(
LogEvent.Level.valueOf(it[1]),
it[2],
it[0].toLong()
)
}
.forEach {
output.write(
String.format(
"%s |%s| %s\n",
LOG_EXPORT_TIME_FORMAT.format(Date(it.time)),
it.level.toString(),
it.message
)
)
}
}
}
}
@@ -27,6 +27,8 @@ class ProfileEditFragment(
private val type: Type,
private val source: String?
) : Fragment() {
private var root: CommonUiLayout? = null
var isModified = false
companion object {
@@ -46,6 +48,7 @@ class ProfileEditFragment(
savedInstanceState: Bundle?
): View? {
return CommonUiLayout(requireContext()).apply {
root = this
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
build {
@@ -111,12 +114,14 @@ class ProfileEditFragment(
if (s.isBlank()) {
content = ""
interval = 0
return@onTextChanged
}
val value = s.toIntOrNull()
if (value == null || value < 15) {
content = ""
interval = 0
Snackbar.make(view, R.string.invalid_interval, Snackbar.LENGTH_LONG)
.show()
return@onTextChanged
@@ -143,16 +148,16 @@ class ProfileEditFragment(
if (resultCode != Activity.RESULT_OK || data == null)
return
val layout = view as CommonUiLayout
root?.apply {
data.data?.apply {
screen.requireElement<TextInput>(KEY_URL).content = this.toString()
}
data.data?.apply {
layout.screen.requireElement<TextInput>(KEY_URL).content = this.toString()
}
data.getStringExtra(Constants.URL_PROVIDER_INTENT_EXTRA_NAME)?.also {
layout.screen.requireElement<TextInput>(KEY_NAME).apply {
if (content.isBlank())
content = it
data.getStringExtra(Constants.URL_PROVIDER_INTENT_EXTRA_NAME)?.also {
screen.requireElement<TextInput>(KEY_NAME).apply {
if (content.isBlank())
content = it
}
}
}
}
@@ -163,7 +168,9 @@ class ProfileEditFragment(
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
(view as CommonUiLayout?)?.screen?.saveState(outState)
root?.apply {
screen.saveState(outState)
}
}
private fun openUrlProvider(): Boolean {
@@ -182,11 +189,13 @@ class ProfileEditFragment(
else -> return false
}
} catch (e: Exception) {
Snackbar.make(
view as ViewGroup,
R.string.start_url_provider_failure,
Snackbar.LENGTH_LONG
).show()
root?.apply {
Snackbar.make(
this,
R.string.start_url_provider_failure,
Snackbar.LENGTH_LONG
).show()
}
}
return true
+3 -3
View File
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
val kotlinVersion = "1.3.71"
val kotlinVersion = "1.3.72"
rootProject.extra.apply {
this["gBuildToolsVersion"] = "29.0.3"
@@ -10,8 +10,8 @@ buildscript {
this["gMinSdkVersion"] = 24
this["gTargetSdkVersion"] = 29
this["gVersionCode"] = 10205
this["gVersionName"] = "1.2.5"
this["gVersionCode"] = 10207
this["gVersionName"] = "1.2.7"
this["gKotlinVersion"] = kotlinVersion
this["gKotlinCoroutineVersion"] = "1.3.5"
+4 -2
View File
@@ -20,12 +20,14 @@ func init() {
dialer.ListenConfigHook = onNewListenConfig
}
func onNewDialer(dialer *net.Dialer) {
func onNewDialer(dialer *net.Dialer) error {
dialer.Control = onNewSocket
return nil
}
func onNewListenConfig(listen *net.ListenConfig) {
func onNewListenConfig(listen *net.ListenConfig) error {
listen.Control = onNewSocket
return nil
}
func onNewSocket(_, _ string, c syscall.RawConn) error {
+12 -2
View File
@@ -7,6 +7,7 @@ import (
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"syscall"
@@ -36,13 +37,22 @@ var client = &http.Client{
},
}
func fetchRemote(url string) ([]byte, error) {
request, err := http.NewRequest("GET", url, nil)
func fetchRemote(sUrl string) ([]byte, error) {
uri, err := url.Parse(sUrl)
if err != nil {
return nil, err
}
request, err := http.NewRequest("GET", uri.String(), nil)
if err != nil {
return nil, err
}
request.Header.Set("User-Agent", "ClashForAndroid/"+ApplicationVersion)
if user := uri.User; user != nil {
password, _ := user.Password()
request.SetBasicAuth(user.Username(), password)
}
response, err := client.Do(request)
if err != nil {
+1 -1
View File
@@ -4,7 +4,7 @@ go 1.13
require (
github.com/Dreamacro/clash v0.0.0 // local
github.com/kr328/tun2socket v0.0.0-20200415021819-256b721ac9a4
github.com/kr328/tun2socket v0.0.0-20200421133501-c8848c95a7ca
github.com/miekg/dns v1.1.29
)
+1 -1
View File
@@ -8,7 +8,7 @@ github.com/go-chi/render v1.0.1/go.mod h1:pq4Rr7HbnsdaeHagklXub+p6Wd16Af5l9koip1
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr328/tun2socket v0.0.0-20200415021819-256b721ac9a4/go.mod h1:FWfSixjrLgtK+dHkDoN6lHMNhvER24gnjUZd/wt8Z9o=
github.com/kr328/tun2socket v0.0.0-20200421133501-c8848c95a7ca/go.mod h1:FWfSixjrLgtK+dHkDoN6lHMNhvER24gnjUZd/wt8Z9o=
github.com/miekg/dns v1.1.29/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
github.com/oschwald/geoip2-golang v1.4.0/go.mod h1:8QwxJvRImBH+Zl6Aa6MaIcs5YdlZSTKtzmPGzQqi9ng=
github.com/oschwald/maxminddb-golang v1.6.0/go.mod h1:DUJFucBg2cvqx42YmDa/+xHvb0elJtOm3o4aFQ/nb/w=
+2 -2
View File
@@ -56,7 +56,7 @@ func hijackTCPDNS(conn net.Conn, endpoint *binding.Endpoint) bool {
return false
}
if !hijackAddress.Equal(net.IPv4zero) && !hijackAddress.Equal(net.IPv6zero) && !hijackAddress.Equal(endpoint.Target.IP) {
if !hijackAddress.Equal(net.IPv4zero) && !hijackAddress.Equal(endpoint.Target.IP) {
return false
}
@@ -109,7 +109,7 @@ func hijackDNS(payload []byte, endpoint *binding.Endpoint, sender redirect.UDPSe
return false
}
if !hijackAddress.Equal(net.IPv4zero) && !hijackAddress.Equal(net.IPv6zero) && !hijackAddress.Equal(endpoint.Target.IP) {
if !hijackAddress.Equal(net.IPv4zero) && !hijackAddress.Equal(endpoint.Target.IP) {
return false
}
@@ -4,10 +4,7 @@ import android.content.Intent
import android.os.Binder
import android.os.IBinder
import com.github.kr328.clash.service.clash.ClashRuntime
import com.github.kr328.clash.service.clash.module.CloseModule
import com.github.kr328.clash.service.clash.module.DynamicNotificationModule
import com.github.kr328.clash.service.clash.module.ReloadModule
import com.github.kr328.clash.service.clash.module.StaticNotificationModule
import com.github.kr328.clash.service.clash.module.*
import com.github.kr328.clash.service.settings.ServiceSettings
import com.github.kr328.clash.service.util.broadcastClashStarted
import com.github.kr328.clash.service.util.broadcastClashStopped
@@ -36,9 +33,7 @@ class ClashService : BaseService() {
runtime.install(ReloadModule(service)) {
onLoaded {
if (it != null) {
reason = it.message
stopSelf()
service.stopSelfForReason(it.message)
} else {
service.broadcastProfileLoaded()
}
@@ -46,9 +41,7 @@ class ClashService : BaseService() {
}
runtime.install(CloseModule()) {
onClosed {
reason = null
stopSelf()
service.stopSelfForReason(null)
}
}
@@ -78,4 +71,10 @@ class ClashService : BaseService() {
super.onDestroy()
}
private fun stopSelfForReason(reason: String?) {
this.reason = reason
stopSelf()
}
}
@@ -108,6 +108,8 @@ class ProfileService : BaseService() {
ProfileDao.remove(id)
}
ProfileReceiver.cancelNextUpdate(service, id)
service.resolveProfileFile(id).delete()
service.resolveTempProfileFile(id).delete()
service.resolveBaseDir(id).deleteRecursively()
@@ -19,6 +19,7 @@ class TunService : VpnService(), CoroutineScope by MainScope() {
private const val PRIVATE_VLAN4_CLIENT = "172.31.255.253"
private const val PRIVATE_VLAN4_MIRROR = "172.31.255.254"
private const val PRIVATE_VLAN_DNS = "198.18.0.1"
private const val VLAN_ANY = "0.0.0.0/0"
}
private val service = this
@@ -47,25 +48,15 @@ class TunService : VpnService(), CoroutineScope by MainScope() {
runtime.install(ReloadModule(service)) {
onLoaded {
if (it != null) {
reason = it.message
stopSelf()
TunModule.requestStop()
service.stopSelfForReason(it.message)
} else {
broadcastProfileLoaded()
service.broadcastProfileLoaded()
}
}
}
runtime.install(CloseModule()) {
onClosed {
launch {
reason = null
stopSelf()
TunModule.requestStop()
}
service.stopSelfForReason(null)
}
}
@@ -99,7 +90,7 @@ class TunService : VpnService(), CoroutineScope by MainScope() {
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
broadcastClashStarted()
service.broadcastClashStarted()
return super.onStartCommand(intent, flags, startId)
}
@@ -107,7 +98,7 @@ class TunService : VpnService(), CoroutineScope by MainScope() {
override fun onDestroy() {
ServiceStatusProvider.serviceRunning = false
broadcastClashStopped(reason)
service.broadcastClashStopped(reason)
cancel()
@@ -128,23 +119,35 @@ class TunService : VpnService(), CoroutineScope by MainScope() {
return if (settings.get(ServiceSettings.BYPASS_PRIVATE_NETWORK))
resources.getStringArray(R.array.bypass_private_route).toList()
else
listOf("0.0.0.0/0")
listOf(VLAN_ANY)
}
override val dnsAddress: String
get() = PRIVATE_VLAN_DNS
override val dnsHijacking: Boolean
get() = settings.get(ServiceSettings.DNS_HIJACKING)
override val allowApplications: List<String>
override val allowApplications: Collection<String>
get() {
return if (settings.get(ServiceSettings.ACCESS_CONTROL_MODE) == ServiceSettings.ACCESS_CONTROL_MODE_WHITELIST) {
(settings.get(ServiceSettings.ACCESS_CONTROL_PACKAGES) + packageName).toList()
} else emptyList()
(settings.get(ServiceSettings.ACCESS_CONTROL_PACKAGES) + packageName)
} else emptySet()
}
override val disallowApplication: List<String>
override val disallowApplication: Collection<String>
get() {
return if (settings.get(ServiceSettings.ACCESS_CONTROL_MODE) == ServiceSettings.ACCESS_CONTROL_MODE_BLACKLIST) {
(settings.get(ServiceSettings.ACCESS_CONTROL_PACKAGES) - packageName).toList()
} else emptyList()
(settings.get(ServiceSettings.ACCESS_CONTROL_PACKAGES) - packageName)
} else emptySet()
}
override fun onCreateTunFailure() {
stopSelfForReason("Start VPN rejected by the system")
}
}
private fun stopSelfForReason(reason: String?) {
this.reason = reason
stopSelf()
TunModule.requestStop()
}
}
@@ -1,7 +1,6 @@
package com.github.kr328.clash.service.clash.module
import android.app.PendingIntent
import android.content.Intent
import android.net.VpnService
import android.os.Build
import com.github.kr328.clash.common.Global
@@ -20,8 +19,10 @@ class TunModule(private val service: VpnService) : Module() {
val route: List<String>
val dnsAddress: String
val dnsHijacking: Boolean
val allowApplications: List<String>
val disallowApplication: List<String>
val allowApplications: Collection<String>
val disallowApplication: Collection<String>
fun onCreateTunFailure()
}
var configure: Configure? = null
@@ -62,7 +63,8 @@ class TunModule(private val service: VpnService) : Module() {
builder.setMetered(false)
}
val fd = builder.establish() ?: throw NullPointerException("Unable to create vpn")
val fd = builder.establish()
?: return@withContext c.onCreateTunFailure()
if (c.dnsHijacking) {
Clash.startTunDevice(