mirror of
https://github.com/MetaCubeX/ClashMetaForAndroid.git
synced 2026-05-09 18:11:26 +08:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5104c241a | ||
|
|
021ba3519d | ||
|
|
119f74cd05 | ||
|
|
f0b61c9e1f | ||
|
|
a573631068 | ||
|
|
a12444b258 | ||
|
|
17257228a9 | ||
|
|
53b6a9dfc1 | ||
|
|
c45f8ddfc3 | ||
|
|
e04c9c15ff | ||
|
|
d5cb363579 | ||
|
|
0748021ffa |
@@ -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 {
|
||||
@@ -143,16 +146,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 +166,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 +187,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
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.os.Handler
|
||||
import android.os.IBinder
|
||||
import androidx.core.content.edit
|
||||
import com.github.kr328.clash.ApkBrokenActivity
|
||||
import com.github.kr328.clash.BuildConfig
|
||||
import com.github.kr328.clash.Constants
|
||||
import com.github.kr328.clash.common.Global
|
||||
import com.github.kr328.clash.common.utils.intent
|
||||
@@ -152,6 +153,9 @@ object Remote {
|
||||
if (sp.getLong(Constants.PREFERENCE_KEY_LAST_INSTALL, 0) == pkg.lastUpdateTime)
|
||||
return true
|
||||
|
||||
if ( application.packageName != BuildConfig.APPLICATION_ID )
|
||||
return false
|
||||
|
||||
val info = application.applicationInfo
|
||||
val sources =
|
||||
info.splitSourceDirs ?: arrayOf(info.sourceDir) ?: return false
|
||||
|
||||
@@ -10,8 +10,8 @@ buildscript {
|
||||
this["gMinSdkVersion"] = 24
|
||||
this["gTargetSdkVersion"] = 29
|
||||
|
||||
this["gVersionCode"] = 10204
|
||||
this["gVersionName"] = "1.2.4"
|
||||
this["gVersionCode"] = 10206
|
||||
this["gVersionName"] = "1.2.6"
|
||||
|
||||
this["gKotlinVersion"] = kotlinVersion
|
||||
this["gKotlinCoroutineVersion"] = "1.3.5"
|
||||
|
||||
@@ -77,6 +77,6 @@ repositories {
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
tasks["clean"].dependsOn(tasks["resetGolangMode"])
|
||||
tasks["clean"].dependsOn(tasks["resetGolangPathMode"])
|
||||
tasks["preBuild"].dependsOn(tasks["extractSources"], tasks["downloadGeoipDatabase"])
|
||||
}
|
||||
@@ -145,7 +145,7 @@ task("generateClashBindSources") {
|
||||
}
|
||||
}
|
||||
|
||||
task("bindClashCore") {
|
||||
task("assembleClashCore") {
|
||||
dependsOn(tasks["generateClashBindSources"])
|
||||
|
||||
onlyIf {
|
||||
@@ -169,14 +169,8 @@ task("bindClashCore") {
|
||||
}
|
||||
|
||||
task("extractSources", type = Copy::class) {
|
||||
dependsOn(tasks["bindClashCore"])
|
||||
dependsOn(tasks["assembleClashCore"])
|
||||
|
||||
doFirst {
|
||||
buildDir.resolve(Constants.OUTPUT_PATH).apply {
|
||||
resolve("jniLibs").deleteRecursively()
|
||||
resolve("classes").deleteRecursively()
|
||||
}
|
||||
}
|
||||
from(zipTree(buildDir.resolve(Constants.GOLANG_OUTPUT))) {
|
||||
include("**/*.so")
|
||||
eachFile {
|
||||
@@ -192,6 +186,8 @@ task("extractSources", type = Copy::class) {
|
||||
}
|
||||
|
||||
task("downloadGeoipDatabase") {
|
||||
dependsOn(tasks["extractSources"])
|
||||
|
||||
onlyIf {
|
||||
val file = buildDir.resolve(Constants.OUTPUT_PATH).resolve("assets/Country.mmdb")
|
||||
|
||||
@@ -211,7 +207,7 @@ task("downloadGeoipDatabase") {
|
||||
}
|
||||
}
|
||||
|
||||
task("resetGolangMode", type = Exec::class) {
|
||||
task("resetGolangPathMode", type = Exec::class) {
|
||||
onlyIf {
|
||||
!Os.isFamily(Os.FAMILY_WINDOWS)
|
||||
}
|
||||
|
||||
Submodule core/src/main/golang/clash updated: f48ce6fc8e...a3850e54ae
@@ -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 {
|
||||
|
||||
@@ -2,7 +2,7 @@ package tun
|
||||
|
||||
import "github.com/Dreamacro/clash/log"
|
||||
|
||||
type ClashLogger struct {}
|
||||
type ClashLogger struct{}
|
||||
|
||||
func (c *ClashLogger) D(format string, args ...interface{}) {
|
||||
log.Debugln(format, args)
|
||||
@@ -19,4 +19,3 @@ func (c *ClashLogger) W(format string, args ...interface{}) {
|
||||
func (c *ClashLogger) E(format string, args ...interface{}) {
|
||||
log.Errorln(format, args)
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,8 @@ func StartTunDevice(fd, mtu int, gateway, mirror, dnsAddress string) error {
|
||||
pkt := &udpPacket{
|
||||
payload: payload,
|
||||
endpoint: endpoint,
|
||||
sender: sender,
|
||||
send: sender,
|
||||
recycle: udpRecycle,
|
||||
}
|
||||
|
||||
tunnel.AddPacket(adapters.NewPacket(addr, pkt, C.SOCKS))
|
||||
|
||||
@@ -10,7 +10,8 @@ import (
|
||||
type udpPacket struct {
|
||||
payload []byte
|
||||
endpoint *binding.Endpoint
|
||||
sender redirect.UDPSender
|
||||
send redirect.UDPSender
|
||||
recycle func([]byte)
|
||||
}
|
||||
|
||||
func (conn *udpPacket) Data() []byte {
|
||||
@@ -39,11 +40,7 @@ func (conn *udpPacket) WriteBack(b []byte, addr net.Addr) (n int, err error) {
|
||||
Target: conn.endpoint.Source,
|
||||
}
|
||||
|
||||
return len(b), conn.sender(b, ep)
|
||||
}
|
||||
|
||||
func (conn *udpPacket) Close() error {
|
||||
return nil
|
||||
return len(b), conn.send(b, ep)
|
||||
}
|
||||
|
||||
func (conn *udpPacket) LocalAddr() net.Addr {
|
||||
@@ -53,3 +50,7 @@ func (conn *udpPacket) LocalAddr() net.Addr {
|
||||
Zone: "",
|
||||
}
|
||||
}
|
||||
|
||||
func (conn *udpPacket) Drop() {
|
||||
conn.recycle(conn.payload)
|
||||
}
|
||||
|
||||
@@ -20,4 +20,6 @@ android.enableJetifier=true
|
||||
# Kotlin code style for this project: "official" or "obsolete":
|
||||
kotlin.code.style=official
|
||||
|
||||
kapt.incremental.apt=false
|
||||
kapt.incremental.apt=false
|
||||
|
||||
org.gradle.parallel=true
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
@@ -83,8 +83,12 @@ class ProfileService : BaseService() {
|
||||
val clonedId = generateNextId()
|
||||
|
||||
pending[clonedId] =
|
||||
queryMetadataById(id)?.copy(id = clonedId, active = false, lastModified = 0)
|
||||
?: return@runBlocking -1L
|
||||
queryMetadataById(id)?.copy(
|
||||
id = clonedId,
|
||||
active = false,
|
||||
lastModified = 0,
|
||||
type = Profile.Type.FILE
|
||||
) ?: return@runBlocking -1L
|
||||
|
||||
clonedId
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -223,7 +223,6 @@ object DatabaseMigrations {
|
||||
}
|
||||
|
||||
NotificationManagerCompat.from(Global.application).apply {
|
||||
deleteNotificationChannel("clash_status_channel")
|
||||
deleteNotificationChannel("profile_service_status")
|
||||
deleteNotificationChannel("profile_service_result")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user