Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
35 changes: 34 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
tags:
- "v*.*.*"

# Maintainers may opt the official APK into EasyTier without changing normal builds.
env:
ORG_GRADLE_PROJECT_easyTier: ${{ vars.CODEG_EASYTIER == 'true' && 'true' || 'false' }}

permissions:
contents: write

Expand All @@ -15,7 +19,7 @@ concurrency:
jobs:
android:
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: ${{ vars.CODEG_EASYTIER == 'true' && 120 || 30 }}
steps:
- name: Check out source
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
Expand All @@ -34,6 +38,19 @@ jobs:
- name: Set up Gradle
uses: gradle/actions/setup-gradle@0b6dd653ba04f4f93bf581ec31e66cbd7dcb644d # v4

- name: Build optional EasyTier transport and notices
if: vars.CODEG_EASYTIER == 'true'
shell: bash
run: |
rustup toolchain install 1.95.0 --profile minimal
rustup default 1.95.0
rustup target add aarch64-linux-android x86_64-linux-android armv7-linux-androideabi i686-linux-android
sudo apt-get update
sudo apt-get install -y protobuf-compiler
sdkmanager "ndk;27.2.12479018"
export ANDROID_NDK_HOME="$ANDROID_HOME/ndk/27.2.12479018"
python3 scripts/build-easytier.py --abi arm64-v8a --abi x86_64 --abi armeabi-v7a --abi x86

- name: Validate release tag
shell: bash
run: |
Expand Down Expand Up @@ -114,6 +131,13 @@ jobs:
sha256sum "$(basename "$release_apk")" > "$(basename "$checksum")"
)
printf 'apk=%s\nchecksum=%s\n' "$release_apk" "$checksum" >> "$GITHUB_OUTPUT"
if [[ "$ORG_GRADLE_PROJECT_easyTier" == true ]]; then
native_source="$release_dir/easytier-corresponding-source.tar.gz"
native_notices="$release_dir/easytier-dependency-notices.tar.gz"
tar --exclude=.git -czf "$native_source" -C build/easytier/source .
tar -czf "$native_notices" -C build/easytier licenses build-info.json
printf 'native_source=%s\nnative_notices=%s\n' "$native_source" "$native_notices" >> "$GITHUB_OUTPUT"
fi

- name: Remove signing material
if: always()
Expand All @@ -126,6 +150,8 @@ jobs:
path: |
${{ steps.package.outputs.apk }}
${{ steps.package.outputs.checksum }}
${{ steps.package.outputs.native_source }}
${{ steps.package.outputs.native_notices }}
if-no-files-found: error
retention-days: 30

Expand Down Expand Up @@ -153,8 +179,15 @@ jobs:
GH_TOKEN: ${{ github.token }}
APK_PATH: ${{ steps.package.outputs.apk }}
CHECKSUM_PATH: ${{ steps.package.outputs.checksum }}
NATIVE_SOURCE: ${{ steps.package.outputs.native_source }}
NATIVE_NOTICES: ${{ steps.package.outputs.native_notices }}
run: |
native_assets=()
if [[ -n "$NATIVE_SOURCE" ]]; then
native_assets+=("$NATIVE_SOURCE#EasyTier corresponding source" "$NATIVE_NOTICES#EasyTier dependency notices")
fi
gh release upload "$GITHUB_REF_NAME" \
"${native_assets[@]}" \
"$APK_PATH#Android APK" \
"$CHECKSUM_PATH#SHA-256 checksum" \
--repo "$GITHUB_REPOSITORY" \
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ jobs:
- name: Set up Gradle
uses: gradle/actions/setup-gradle@0b6dd653ba04f4f93bf581ec31e66cbd7dcb644d # v4

- name: Verify pinned native license sources
run: python3 -m unittest discover -s scripts -p 'test_*.py'

- name: Check, test, and assemble the app
run: ./gradlew :app:check :app:assembleDebug :app:assembleRelease --no-daemon
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ service-account*.json
# Release signing — local only, never commit
/codeg-release.jks
/keystore.properties

# Local Python verification helpers
__pycache__/
*.pyc
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ release APK.
2. Open the Android app and add a server profile.
3. Enter the server URL and token, test the connection, and save the profile.

The selected server is restored automatically the next time the app starts.
An optional EasyTier-enabled build also supports a userspace mesh connection per
profile: enter your network name, password, peer URLs, and the Codeg server's mesh
HTTP address. The password is encrypted separately from the profile. A connection
screen offers retry and server selection if the mesh cannot reach Codeg.

The standard build stays a direct client; it does not display an unavailable mesh
option. See [the optional native build instructions](docs/easytier-native-build.md)
for `-PeasyTier=true`, supported ABIs, source pinning, and dependency notices.

For a server on the same local network, a URL might look like
`http://192.168.1.10:3080`.

Expand Down
55 changes: 55 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import com.github.jk1.license.render.InventoryMarkdownReportRenderer
import com.github.jk1.license.render.JsonReportRenderer
import com.github.jk1.license.render.ReportRenderer
import java.util.Properties
import java.security.MessageDigest
import groovy.json.JsonSlurper
import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.Sync
Expand All @@ -28,6 +30,8 @@ val checkedInThirdPartyLicensesDir = rootProject.layout.projectDirectory.dir("th
val generatedThirdPartyLicensesDir = layout.buildDirectory.dir("reports/dependency-license")
val supplementalLicensesDir = rootProject.layout.projectDirectory.dir("config/licenses")

val easyTierEnabled = providers.gradleProperty("easyTier").map(String::toBoolean).getOrElse(false)

android {
namespace = "app.codeg.android"
compileSdk = 36
Expand All @@ -38,6 +42,13 @@ android {
targetSdk = 36
versionCode = 2
versionName = "1.0.1"
buildConfigField("boolean", "EASYTIER_ENABLED", easyTierEnabled.toString())
if (easyTierEnabled) {
// Other AndroidX dependencies ship native libraries too. Restrict the whole APK
// to the ABIs that also have EasyTier, so Android cannot select a partial ABI.
ndk.abiFilters += rootProject.file("build/easytier/jniLibs")
.listFiles().orEmpty().filter(File::isDirectory).map(File::getName)
}

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -92,6 +103,11 @@ android {

sourceSets {
getByName("main").assets.srcDir(checkedInThirdPartyLicensesDir)
if (easyTierEnabled) {
getByName("main").jniLibs.srcDir(rootProject.file("build/easytier/jniLibs"))
getByName("main").assets.srcDir(rootProject.file("config/easytier"))
getByName("main").assets.srcDir(rootProject.file("build/easytier/licenses"))
}
}

packaging {
Expand Down Expand Up @@ -288,3 +304,42 @@ dependencies {
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.androidx.espresso.core)
}

// Native artifacts are built from the pinned public source by the explicit script.
// Never silently ship an enabled picker without its transport implementation.
if (easyTierEnabled) {
tasks.named("preBuild") {
doFirst {
val libraries = rootProject.file("build/easytier/jniLibs")
.walkTopDown().filter { it.name == "libeasytier_android_jni.so" }.toList()
check(libraries.isNotEmpty()) {
"EasyTier is enabled but its JNI library is missing. Run scripts/build-easytier.py first."
}
val metadata = JsonSlurper().parse(rootProject.file("build/easytier/build-info.json")) as Map<*, *>
val records = metadata["libraries"] as List<*>
val hashes = records.associate { item ->
val record = item as Map<*, *>
record["abi"] as String to record["sha256"] as String
}
check(libraries.map { it.parentFile.name }.toSet() == hashes.keys) {
"EasyTier ABI outputs do not match this build's manifest. Rebuild the complete requested ABI set."
}
libraries.forEach { library ->
val digest = MessageDigest.getInstance("SHA-256").digest(library.readBytes())
.joinToString("") { "%02x".format(it) }
check(digest == hashes[library.parentFile.name]) { "EasyTier library differs from its build manifest." }
}
val notices = JsonSlurper().parse(rootProject.file("build/easytier/licenses/EASYTIER_DEPENDENCIES.json")) as Map<*, *>
val targets = mapOf("arm64-v8a" to "aarch64-linux-android", "x86_64" to "x86_64-linux-android",
"armeabi-v7a" to "armv7-linux-androideabi", "x86" to "i686-linux-android")
check((notices["targets"] as List<*>).toSet() == hashes.keys.map { targets.getValue(it) }.toSet() &&
(notices["packages"] as List<*>).isNotEmpty() && (notices["missing_notice_packages"] as List<*>).isEmpty() &&
(notices["pointer_notice_files"] as List<*>).isEmpty()) {
"EasyTier dependency notices are incomplete or belong to another ABI set."
}
check(rootProject.file("build/easytier/licenses/THIRD_PARTY_NOTICES.txt").isFile) {
"EasyTier dependency notices are missing. Run scripts/easytier-license-report.py first."
}
}
}
}
3 changes: 3 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
-dontwarn org.slf4j.**
-dontwarn io.ktor.**
-keep class io.ktor.** { *; }

# EasyTier exports JNI symbols using this exact class and native method names.
-keep class com.easytier.jni.EasyTierJNI { native <methods>; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package app.codeg.android.mesh

import android.content.Intent
import android.os.Bundle
import android.view.accessibility.AccessibilityNodeInfo
import androidx.lifecycle.ViewModelProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import app.codeg.android.BuildConfig
import app.codeg.android.MainActivity
import app.codeg.android.app.AppViewModel
import app.codeg.android.app.ConnectionState
import app.codeg.android.core.datastore.MeshSettings
import app.codeg.android.core.datastore.ServerProfile
import app.codeg.android.core.network.StreamFrame
import dagger.hilt.android.EntryPointAccessors
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import org.junit.Assert.*
import org.junit.Assume.assumeTrue
import org.junit.Test
import org.junit.runner.RunWith

/** Opt-in test against a synthetic peer; never run against a user's live server. */
@RunWith(AndroidJUnit4::class)
class MeshAppIntegrationTest {
@Test fun selectedMeshReachesTheMainShellAndProductionHttpAndWebSocketClients() = runBlocking {
val arguments = InstrumentationRegistry.getArguments()
assumeTrue(BuildConfig.EASYTIER_ENABLED && arguments.containsKey("meshPeer"))
val instrumentation = InstrumentationRegistry.getInstrumentation()
val context = instrumentation.targetContext
val repository = EntryPointAccessors.fromApplication(context, MeshTestServices::class.java).serverRepository()
val profile = ServerProfile("instrumented-mesh", "Instrumented mesh", arguments.getString("meshServer")!!,
MeshSettings(arguments.getString("meshNetwork")!!, listOf(arguments.getString("meshPeer")!!)))
repository.save(profile, "codeg-fixture-token", "codeg-fixture-network-password")
repository.select(profile.id)
val activity = instrumentation.startActivitySync(Intent(context, MainActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)) as MainActivity
lateinit var model: AppViewModel
instrumentation.runOnMainSync { model = ViewModelProvider(activity)[AppViewModel::class.java] }
val ready = withTimeout(60_000) {
model.connection.filterIsInstance<ConnectionState.Ready>().first { it.profile?.id == profile.id }
}
val selected = requireNotNull(ready.profile)
assertEquals("Instrumented mesh", selected.name)
val client = requireNotNull(repository.client(selected))
assertTrue(client.baseUrl.startsWith("http://127.0.0.1:"))
assertEquals("codeg-mesh-fixture", client.health().version)
assertEquals("fixture-project", client.listFolders().single().name)
instrumentation.sendStatus(0, Bundle().apply { putString("stream", "mesh HTTP and profile restoration passed\n") })
val stream = requireNotNull(repository.eventStream(selected))
stream.ping()
assertEquals(StreamFrame.Pong, withTimeout(10_000) { stream.frames().first { it == StreamFrame.Pong } })
instrumentation.sendStatus(0, Bundle().apply { putString("stream", "mesh WebSocket pong passed\n") })
// The real root gate has transitioned to MainShell; check a rendered tab via accessibility.
withTimeout(10_000) {
while (true) {
val root = instrumentation.uiAutomation.rootInActiveWindow
if (root != null && hasChatsTab(root)) break
kotlinx.coroutines.delay(100)
}
}
// Leave only this synthetic profile for a separate force-stop/cold-start acceptance check.
}

private fun hasChatsTab(node: AccessibilityNodeInfo): Boolean {
// Compose exposes virtual children, but its provider need not implement
// findAccessibilityNodeInfosByText. Walk the same tree UIAutomator reads.
if (node.text?.toString() in setOf("Chats", "会话")) return true
return (0 until node.childCount).any { index -> node.getChild(index)?.let(::hasChatsTab) == true }
}
}
13 changes: 13 additions & 0 deletions app/src/debug/java/app/codeg/android/mesh/MeshTestServices.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package app.codeg.android.mesh

import app.codeg.android.core.data.ServerRepository
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

/** Debug-only access to the production graph for the opt-in local mesh fixture test. */
@EntryPoint
@InstallIn(SingletonComponent::class)
interface MeshTestServices {
fun serverRepository(): ServerRepository
}
48 changes: 47 additions & 1 deletion app/src/main/java/app/codeg/android/app/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import app.codeg.android.core.datastore.AppSettingsStore
import app.codeg.android.core.datastore.ServerProfile
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
Expand All @@ -33,11 +39,51 @@ class AppViewModel @Inject constructor(
val selectedProfile: StateFlow<ServerProfile?> = serverRepository.selectedProfile
.stateIn(viewModelScope, SharingStarted.Eagerly, null)

val connection = MutableStateFlow<ConnectionState>(ConnectionState.Loading)
private val retry = MutableStateFlow(0)
val managingServers = MutableStateFlow(false)

init {
viewModelScope.launch {
combine(serverRepository.selectedProfile, retry, managingServers) { profile, _, managing -> profile to managing }
.collectLatest { (profile, managing) ->
if (managing) {
runCatching { serverRepository.disconnect() }
connection.value = ConnectionState.Loading
return@collectLatest
}
connection.value = ConnectionState.Connecting(profile)
try {
serverRepository.prepare(profile)
connection.value = ConnectionState.Ready(profile)
} catch (error: TimeoutCancellationException) {
runCatching { serverRepository.disconnect() }
connection.value = ConnectionState.Failed(profile)
} catch (error: CancellationException) {
runCatching { serverRepository.disconnect() }
throw error
} catch (_: Exception) {
runCatching { serverRepository.disconnect() }
connection.value = ConnectionState.Failed(profile)
}
}
}
}

fun retryConnection() { retry.update { it + 1 } }

fun selectServer(id: String) {
viewModelScope.launch { serverRepository.select(id) }
viewModelScope.launch { serverRepository.select(id); managingServers.value = false }
}

fun deleteServer(id: String) {
viewModelScope.launch { serverRepository.delete(id) }
}
}

sealed interface ConnectionState {
data object Loading : ConnectionState
data class Connecting(val profile: ServerProfile?) : ConnectionState
data class Ready(val profile: ServerProfile?) : ConnectionState
data class Failed(val profile: ServerProfile?) : ConnectionState
}
Loading