Skip to content

Commit 61465f5

Browse files
committed
Add android separates the core process
Support core status check and force restart Update flutter and pub dependencies
1 parent e956373 commit 61465f5

File tree

234 files changed

+37232
-43230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+37232
-43230
lines changed

analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
include: package:flutter_lints/flutter.yaml
22
analyzer:
3+
plugins:
4+
- custom_lint
35
exclude:
46
- lib/l10n/intl/**
57

android/app/build.gradle.kts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
12
import java.util.Properties
23

34
plugins {
@@ -24,22 +25,19 @@ val isRelease = mStoreFile.exists()
2425

2526
android {
2627
namespace = "com.follow.clash"
27-
compileSdk = 35
28-
ndkVersion = "28.0.13004108"
28+
compileSdk = libs.versions.compileSdk.get().toInt()
29+
ndkVersion = libs.versions.ndkVersion.get()
30+
2931

3032
compileOptions {
3133
sourceCompatibility = JavaVersion.VERSION_17
3234
targetCompatibility = JavaVersion.VERSION_17
3335
}
3436

35-
kotlinOptions {
36-
jvmTarget = JavaVersion.VERSION_17.toString()
37-
}
38-
3937
defaultConfig {
4038
applicationId = "com.follow.clash"
4139
minSdk = flutter.minSdkVersion
42-
targetSdk = flutter.targetSdkVersion
40+
targetSdk = libs.versions.targetSdk.get().toInt()
4341
versionCode = flutter.versionCode
4442
versionName = flutter.versionName
4543
}
@@ -63,8 +61,7 @@ android {
6361

6462
release {
6563
isMinifyEnabled = true
66-
isDebuggable = false
67-
64+
isShrinkResources = true
6865
signingConfig = if (isRelease) {
6966
signingConfigs.getByName("release")
7067
} else {
@@ -79,15 +76,22 @@ android {
7976
}
8077
}
8178

79+
kotlin {
80+
compilerOptions {
81+
jvmTarget.set(JvmTarget.JVM_17)
82+
}
83+
}
84+
8285
flutter {
8386
source = "../.."
8487
}
8588

8689
dependencies {
87-
implementation(project(":core"))
88-
implementation("androidx.core:core-splashscreen:1.0.1")
89-
implementation("com.google.code.gson:gson:2.10.1")
90-
implementation("com.android.tools.smali:smali-dexlib2:3.0.9") {
90+
implementation(project(":service"))
91+
implementation(project(":common"))
92+
implementation(libs.core.splashscreen)
93+
implementation(libs.gson)
94+
implementation(libs.smali.dexlib2) {
9195
exclude(group = "com.google.guava", module = "guava")
9296
}
9397
}

android/app/proguard-rules.pro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11

2-
-keep class com.follow.clash.models.**{ *; }
2+
-keep class com.follow.clash.models.**{ *; }
3+
4+
-keep class com.follow.clash.service.models.**{ *; }

android/app/src/debug/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
android:label="FlClash Debug"
1010
tools:replace="android:label">
1111
<service
12-
android:name=".services.FlClashTileService"
12+
android:name=".TileService"
1313
android:label="FlClash Debug"
1414
tools:replace="android:label"
1515
tools:targetApi="24" />

android/app/src/main/AndroidManifest.xml

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
12
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
23
xmlns:tools="http://schemas.android.com/tools">
34

5+
<permission
6+
android:name="${applicationId}.permission.RECEIVE_BROADCASTS"
7+
android:protectionLevel="signature" />
8+
49
<uses-feature
510
android:name="android.hardware.touchscreen"
611
android:required="false" />
@@ -13,19 +18,19 @@
1318

1419
<uses-permission android:name="android.permission.INTERNET" />
1520
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
16-
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
1721
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
1822
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
1923
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
20-
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
21-
2224
<uses-permission
2325
android:name="android.permission.QUERY_ALL_PACKAGES"
2426
tools:ignore="QueryAllPackagesPermission" />
27+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
28+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
2529

2630
<application
27-
android:name=".FlClashApplication"
31+
android:name=".Application"
2832
android:banner="@mipmap/ic_banner"
33+
android:extractNativeLibs="true"
2934
android:hardwareAccelerated="true"
3035
android:icon="@mipmap/ic_launcher"
3136
android:label="FlClash">
@@ -47,6 +52,7 @@
4752

4853
<intent-filter>
4954
<action android:name="android.intent.action.MAIN" />
55+
5056
<category android:name="android.intent.category.LAUNCHER" />
5157
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
5258
</intent-filter>
@@ -67,12 +73,9 @@
6773
</intent-filter>
6874
</activity>
6975

70-
<meta-data
71-
android:name="io.flutter.embedding.android.EnableImpeller"
72-
android:value="false" />
73-
7476
<activity
7577
android:name=".TempActivity"
78+
android:excludeFromRecents="true"
7679
android:exported="true"
7780
android:theme="@style/TransparentTheme">
7881
<intent-filter>
@@ -85,17 +88,16 @@
8588
</intent-filter>
8689
<intent-filter>
8790
<category android:name="android.intent.category.DEFAULT" />
88-
<action android:name="${applicationId}.action.CHANGE" />
91+
<action android:name="${applicationId}.action.TOGGLE" />
8992
</intent-filter>
9093
</activity>
9194

9295
<service
93-
android:name=".services.FlClashTileService"
96+
android:name=".TileService"
9497
android:exported="true"
9598
android:icon="@drawable/ic"
9699
android:label="FlClash"
97-
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
98-
tools:targetApi="n">
100+
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
99101
<intent-filter>
100102
<action android:name="android.service.quicksettings.action.QS_TILE" />
101103
</intent-filter>
@@ -104,6 +106,19 @@
104106
android:value="true" />
105107
</service>
106108

109+
<receiver
110+
android:name=".BroadcastReceiver"
111+
android:enabled="true"
112+
android:exported="true"
113+
android:permission="${applicationId}.permission.RECEIVE_BROADCASTS">
114+
<intent-filter>
115+
<action android:name="${applicationId}.intent.action.START" />
116+
<action android:name="${applicationId}.intent.action.STOP" />
117+
<action android:name="${applicationId}.intent.action.TOGGLE" />
118+
</intent-filter>
119+
</receiver>
120+
121+
107122
<provider
108123
android:name=".FilesProvider"
109124
android:authorities="${applicationId}.files"
@@ -126,28 +141,6 @@
126141
android:resource="@xml/file_paths" />
127142
</provider>
128143

129-
<service
130-
android:name=".services.FlClashVpnService"
131-
android:exported="false"
132-
android:foregroundServiceType="dataSync"
133-
android:permission="android.permission.BIND_VPN_SERVICE">
134-
<intent-filter>
135-
<action android:name="android.net.VpnService" />
136-
</intent-filter>
137-
<property
138-
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
139-
android:value="vpn" />
140-
</service>
141-
142-
<service
143-
android:name=".services.FlClashService"
144-
android:exported="false"
145-
android:foregroundServiceType="dataSync">
146-
<property
147-
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
148-
android:value="service" />
149-
</service>
150-
151144
<meta-data
152145
android:name="flutterEmbedding"
153146
android:value="2" />
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.follow.clash
2+
3+
import android.app.Application
4+
import android.content.Context
5+
import com.follow.clash.common.GlobalState
6+
7+
class Application : Application() {
8+
9+
override fun attachBaseContext(base: Context?) {
10+
super.attachBaseContext(base)
11+
GlobalState.init(this)
12+
}
13+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.follow.clash
2+
3+
import android.content.BroadcastReceiver
4+
import android.content.Context
5+
import android.content.Intent
6+
import com.follow.clash.common.BroadcastAction
7+
import com.follow.clash.common.action
8+
import kotlinx.coroutines.CoroutineScope
9+
import kotlinx.coroutines.Dispatchers
10+
import kotlinx.coroutines.SupervisorJob
11+
import kotlinx.coroutines.launch
12+
13+
class BroadcastReceiver : BroadcastReceiver(),
14+
CoroutineScope by CoroutineScope(SupervisorJob() + Dispatchers.Default) {
15+
override fun onReceive(context: Context?, intent: Intent?) {
16+
when (intent?.action) {
17+
BroadcastAction.START.action -> {
18+
launch {
19+
State.handleStartServiceAction()
20+
}
21+
}
22+
23+
BroadcastAction.STOP.action -> {
24+
State.handleStopServiceAction()
25+
}
26+
27+
BroadcastAction.TOGGLE.action -> {
28+
launch {
29+
State.handleToggleAction()
30+
}
31+
}
32+
}
33+
}
34+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.follow.clash
2+
3+
import android.graphics.Bitmap
4+
import android.graphics.drawable.Drawable
5+
import android.os.Handler
6+
import android.os.Looper
7+
import android.util.Base64
8+
import androidx.core.graphics.drawable.toBitmap
9+
import io.flutter.embedding.engine.FlutterEngine
10+
import io.flutter.embedding.engine.plugins.FlutterPlugin
11+
import io.flutter.plugin.common.MethodChannel
12+
import kotlinx.coroutines.Dispatchers
13+
import kotlinx.coroutines.suspendCancellableCoroutine
14+
import kotlinx.coroutines.withContext
15+
import java.io.ByteArrayOutputStream
16+
import kotlin.coroutines.resume
17+
18+
suspend fun Drawable.getBase64(): String {
19+
val drawable = this
20+
return withContext(Dispatchers.IO) {
21+
val bitmap = drawable.toBitmap()
22+
val byteArrayOutputStream = ByteArrayOutputStream()
23+
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream)
24+
Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.NO_WRAP)
25+
}
26+
}
27+
28+
suspend fun <T> MethodChannel.awaitResult(
29+
method: String, arguments: Any? = null
30+
): T? = withContext(Dispatchers.Main) {
31+
suspendCancellableCoroutine { continuation ->
32+
invokeMethod(method, arguments, object : MethodChannel.Result {
33+
override fun success(result: Any?) {
34+
@Suppress("UNCHECKED_CAST") continuation.resume(result as T?)
35+
}
36+
37+
override fun error(code: String, message: String?, details: Any?) {
38+
continuation.resume(null)
39+
}
40+
41+
override fun notImplemented() {
42+
continuation.resume(null)
43+
}
44+
})
45+
}
46+
}
47+
48+
inline fun <reified T : FlutterPlugin> FlutterEngine.plugin(): T? {
49+
return plugins.get(T::class.java) as T?
50+
}
51+
52+
53+
fun <T> MethodChannel.invokeMethodOnMainThread(
54+
method: String,
55+
arguments: Any? = null,
56+
callback: ((Result<T>) -> Unit)? = null
57+
) {
58+
Handler(Looper.getMainLooper()).post {
59+
invokeMethod(method, arguments, object : MethodChannel.Result {
60+
override fun success(result: Any?) {
61+
@Suppress("UNCHECKED_CAST")
62+
callback?.invoke(Result.success(result as T))
63+
}
64+
65+
override fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) {
66+
val exception = Exception("MethodChannel error: $errorCode - $errorMessage")
67+
callback?.invoke(Result.failure(exception))
68+
}
69+
70+
override fun notImplemented() {
71+
val exception = NotImplementedError("Method not implemented: $method")
72+
callback?.invoke(Result.failure(exception))
73+
}
74+
})
75+
}
76+
}

android/app/src/main/kotlin/com/follow/clash/FilesProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class FilesProvider : DocumentsProvider() {
4343
add(Root.COLUMN_ROOT_ID, DEFAULT_ROOT_ID)
4444
add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY)
4545
add(Root.COLUMN_ICON, R.mipmap.ic_launcher)
46-
add(Root.COLUMN_TITLE, context!!.getString(R.string.fl_clash))
46+
add(Root.COLUMN_TITLE, "FlClash")
4747
add(Root.COLUMN_SUMMARY, "Data")
4848
add(Root.COLUMN_DOCUMENT_ID, "/")
4949
}

android/app/src/main/kotlin/com/follow/clash/FlClashApplication.kt

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)