Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target Android 14 #3165

Merged
merged 19 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ jobs:
build:
working_directory: ~/code
docker:
- image: cimg/android:2022.12.1-ndk
- image: cimg/android:2024.08.1-ndk
environment:
GRADLE_OPTS: -Dorg.gradle.workers.max=1 -Dorg.gradle.daemon=false -Dkotlin.compiler.execution.strategy="in-process"
RUST_VERSION: 1.67.0
RUST_VERSION: 1.80.0
steps:
- checkout
- run: git submodule update --init --recursive
Expand Down
11 changes: 6 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

plugins {
id("com.github.ben-manes.versions") version "0.45.0"
id("com.github.ben-manes.versions") version "0.51.0"
id("com.google.devtools.ksp") version "2.0.10-1.0.24" apply false
}

buildscript {
Expand All @@ -18,11 +19,11 @@ buildscript {
classpath(rootProject.extra["androidPlugin"].toString())
classpath(kotlin("gradle-plugin", kotlinVersion))
classpath("com.google.android.gms:oss-licenses-plugin:0.10.6")
classpath("com.google.firebase:firebase-crashlytics-gradle:2.9.2")
classpath("com.google.gms:google-services:4.3.15")
classpath("com.google.firebase:firebase-crashlytics-gradle:3.0.2")
classpath("com.google.gms:google-services:4.4.2")
classpath("com.vanniktech:gradle-maven-publish-plugin:0.24.0")
classpath("org.jetbrains.dokka:dokka-gradle-plugin:1.7.20")
classpath("org.mozilla.rust-android-gradle:plugin:0.9.3")
classpath("org.mozilla.rust-android-gradle:plugin:0.9.4")
}
}

Expand All @@ -31,7 +32,7 @@ allprojects {
}

tasks.register<Delete>("clean") {
delete(rootProject.buildDir)
delete(rootProject.layout.buildDirectory)
}

// skip uploading the mapping to Crashlytics
Expand Down
14 changes: 6 additions & 8 deletions buildSrc/src/main/kotlin/Helpers.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import com.android.build.VariantOutput
import com.android.build.api.dsl.CommonExtension
import com.android.build.gradle.AbstractAppExtension
Expand All @@ -15,7 +14,7 @@ import java.util.*
const val lifecycleVersion = "2.5.1"

private val Project.android get() = extensions.getByName<BaseExtension>("android")
private val BaseExtension.lint get() = (this as CommonExtension<*, *, *, *>).lint
private val BaseExtension.lint get() = (this as CommonExtension<*, *, *, *, *, *>).lint

private val flavorRegex = "(assemble|generate)\\w*(Release|Debug)".toRegex()
val Project.currentFlavor get() = gradle.startParameter.taskRequests.toString().let { task ->
Expand All @@ -26,11 +25,10 @@ val Project.currentFlavor get() = gradle.startParameter.taskRequests.toString().

fun Project.setupCommon() {
android.apply {
buildToolsVersion("33.0.1")
compileSdkVersion(33)
compileSdkVersion(34)
defaultConfig {
minSdk = 23
targetSdk = 33
targetSdk = 34
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
val javaVersion = JavaVersion.VERSION_11
Expand All @@ -50,8 +48,8 @@ fun Project.setupCommon() {

dependencies {
add("testImplementation", "junit:junit:4.13.2")
add("androidTestImplementation", "androidx.test:runner:1.5.2")
add("androidTestImplementation", "androidx.test.espresso:espresso-core:3.5.1")
add("androidTestImplementation", "androidx.test:runner:1.6.2")
add("androidTestImplementation", "androidx.test.espresso:espresso-core:3.6.1")
}
}

Expand All @@ -70,7 +68,7 @@ fun Project.setupCore() {
}
ndkVersion = "27.0.12077973"
}
dependencies.add("coreLibraryDesugaring", "com.android.tools:desugar_jdk_libs:2.0.2")
dependencies.add("coreLibraryDesugaring", "com.android.tools:desugar_jdk_libs:2.0.4")
}

private val abiCodes = mapOf("armeabi-v7a" to 1, "arm64-v8a" to 2, "x86" to 3, "x86_64" to 4)
Expand Down
30 changes: 15 additions & 15 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import com.android.build.gradle.internal.tasks.factory.dependsOn

plugins {
id("com.android.library")
id("org.mozilla.rust-android-gradle.rust-android")
id("com.android.library")
id("com.google.devtools.ksp")
kotlin("android")
kotlin("kapt")
id("kotlin-parcelize")
}

Expand All @@ -21,8 +21,8 @@ android {
arguments("-j${Runtime.getRuntime().availableProcessors()}")
}

kapt.arguments {
arg("room.incremental", true)
ksp {
arg("room.incremental", "true")
arg("room.schemaLocation", "$projectDir/schemas")
}
}
Expand Down Expand Up @@ -85,27 +85,27 @@ tasks.clean.dependsOn("cargoClean")

dependencies {
val coroutinesVersion = "1.6.4"
val roomVersion = "2.5.0"
val workVersion = "2.7.1"
val roomVersion = "2.6.1"
val workVersion = "2.9.1"

api(project(":plugin"))
api("androidx.core:core-ktx:1.9.0")
api("com.google.android.material:material:1.8.0")
api("androidx.core:core-ktx:1.13.1")
api("com.google.android.material:material:1.12.0")

api("androidx.lifecycle:lifecycle-livedata-core-ktx:$lifecycleVersion")
api("androidx.preference:preference:1.2.0")
api("androidx.preference:preference:1.2.1")
api("androidx.room:room-runtime:$roomVersion")
api("androidx.work:work-multiprocess:$workVersion")
api("androidx.work:work-runtime-ktx:$workVersion")
api("com.google.android.gms:play-services-oss-licenses:17.0.0")
api("com.google.code.gson:gson:2.10.1")
api("com.google.firebase:firebase-analytics-ktx:21.2.0")
api("com.google.firebase:firebase-crashlytics:18.3.3")
api("com.google.code.gson:gson:2.11.0")
api("com.google.firebase:firebase-analytics-ktx:22.1.0")
api("com.google.firebase:firebase-crashlytics:19.0.3")
api("com.jakewharton.timber:timber:5.0.1")
api("dnsjava:dnsjava:3.5.2")
api("dnsjava:dnsjava:3.6.1")
api("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion")
api("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutinesVersion")
kapt("androidx.room:room-compiler:$roomVersion")
ksp("androidx.room:room-compiler:$roomVersion")
androidTestImplementation("androidx.room:room-testing:$roomVersion")
androidTestImplementation("androidx.test.ext:junit-ktx:1.1.5")
androidTestImplementation("androidx.test.ext:junit-ktx:1.2.1")
}
15 changes: 15 additions & 0 deletions core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission
android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"
android:minSdkVersion="34" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Expand Down Expand Up @@ -43,24 +46,36 @@
android:directBootAware="true"
android:label="@string/app_name"
android:permission="android.permission.BIND_VPN_SERVICE"
android:foregroundServiceType="specialUse"
android:exported="false">
<intent-filter>
<action android:name="android.net.VpnService"/>
</intent-filter>
<property
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="Vpn" />
AaronChen0 marked this conversation as resolved.
Show resolved Hide resolved
</service>

<service
android:name="com.github.shadowsocks.bg.TransproxyService"
android:process=":bg"
android:directBootAware="true"
android:foregroundServiceType="specialUse"
android:exported="false">
<property
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="Transproxy" />
</service>

<service
android:name="com.github.shadowsocks.bg.ProxyService"
android:process=":bg"
android:directBootAware="true"
android:foregroundServiceType="specialUse"
android:exported="false">
<property
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="Proxy" />
</service>

<service
Expand Down
18 changes: 9 additions & 9 deletions core/src/main/java/com/github/shadowsocks/Core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ import com.github.shadowsocks.utils.DeviceStorageApp
import com.github.shadowsocks.utils.DirectBoot
import com.github.shadowsocks.utils.Key
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.ktx.Firebase
import com.google.firebase.ktx.initialize
import com.google.firebase.FirebaseApp
import kotlinx.coroutines.DEBUG_PROPERTY_NAME
import kotlinx.coroutines.DEBUG_PROPERTY_VALUE_ON
import kotlinx.coroutines.GlobalScope
Expand Down Expand Up @@ -111,7 +110,7 @@ object Core : Configuration.Provider {

// overhead of debug mode is minimal: https://github.com/Kotlin/kotlinx.coroutines/blob/f528898/docs/debugging.md#debug-mode
System.setProperty(DEBUG_PROPERTY_NAME, DEBUG_PROPERTY_VALUE_ON)
Firebase.initialize(deviceStorage) // multiple processes needs manual set-up
FirebaseApp.initializeApp(deviceStorage) // multiple processes needs manual set-up
Timber.plant(object : Timber.DebugTree() {
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
if (t == null) {
Expand Down Expand Up @@ -142,12 +141,13 @@ object Core : Configuration.Provider {
updateNotificationChannels()
}

override fun getWorkManagerConfiguration() = Configuration.Builder().apply {
setDefaultProcessName(app.packageName + ":bg")
setMinimumLoggingLevel(if (BuildConfig.DEBUG) Log.VERBOSE else Log.INFO)
setExecutor { GlobalScope.launch { it.run() } }
setTaskExecutor { GlobalScope.launch { it.run() } }
}.build()
override val workManagerConfiguration : Configuration
get() = Configuration.Builder().apply {
setDefaultProcessName(app.packageName + ":bg")
setMinimumLoggingLevel(if (BuildConfig.DEBUG) Log.VERBOSE else Log.INFO)
setExecutor { GlobalScope.launch { it.run() } }
setTaskExecutor { GlobalScope.launch { it.run() } }
}.build()

fun updateNotificationChannels() {
if (Build.VERSION.SDK_INT >= 26) @RequiresApi(26) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class UrlImportActivity : AppCompatActivity() {
}

override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
requireActivity().finish()
}
}
Expand Down
13 changes: 10 additions & 3 deletions core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,16 @@ class VpnService : BaseVpnService(), BaseService.Interface {
network.bindSocket(fd)
return@let true
} catch (e: IOException) {
when ((e.cause as? ErrnoException)?.errno) {
OsConstants.EPERM, OsConstants.EACCES, OsConstants.ENONET -> Timber.d(e)
else -> Timber.w(e)
if (Build.VERSION.SDK_INT >= 31) {
when ((e.cause as? ErrnoException)?.errno) {
OsConstants.EPERM, OsConstants.EACCES, OsConstants.ENONET -> Timber.d(e)
else -> Timber.w(e)
}
} else {
when ((e.cause as? ErrnoException)?.errno) {
OsConstants.EPERM, OsConstants.EACCES -> Timber.d(e)
else -> Timber.w(e)
}
}
return@let false
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/rust/shadowsocks-rust
Submodule shadowsocks-rust updated 177 files
7 changes: 3 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.enableR8.fullMode=true
android.enableResourceOptimizations=false
android.useAndroidX=true
kapt.incremental.apt=true
android.nonTransitiveRClass=false
android.defaults.buildfeatures.aidl=true
android.defaults.buildfeatures.buildconfig=true

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 4 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
38 changes: 25 additions & 13 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +82,12 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +134,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,11 +201,15 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
Loading