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
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ dependencies {

// Xposed API for self-hooking VPN hide module
compileOnly("de.robv.android.xposed:api:82")
compileOnly(project(":libxposed-api"))
compileOnly("io.github.libxposed:api:101.0.1")
}

val playCredentialsJSON = rootProject.file("service-account-credentials.json")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.nekohasekai.sfa.bg;

import io.nekohasekai.sfa.bg.ParceledListSlice;

interface INeighborTableCallback {
oneway void onNeighborTableUpdated(in ParceledListSlice entries);
}
5 changes: 5 additions & 0 deletions app/src/main/aidl/io/nekohasekai/sfa/bg/IRootService.aidl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.nekohasekai.sfa.bg;

import android.os.ParcelFileDescriptor;
import io.nekohasekai.sfa.bg.INeighborTableCallback;
import io.nekohasekai.sfa.bg.ParceledListSlice;

interface IRootService {
Expand All @@ -11,4 +12,8 @@ interface IRootService {
void installPackage(in ParcelFileDescriptor apk, long size, int userId) = 2;

String exportDebugInfo(String outputPath) = 3;

void registerNeighborTableCallback(in INeighborTableCallback callback) = 4;

oneway void unregisterNeighborTableCallback(in INeighborTableCallback callback) = 5;
}
3 changes: 3 additions & 0 deletions app/src/main/aidl/io/nekohasekai/sfa/bg/NeighborEntry.aidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.nekohasekai.sfa.bg;

parcelable NeighborEntry;
63 changes: 45 additions & 18 deletions app/src/main/java/io/nekohasekai/sfa/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import android.content.IntentFilter
import android.net.ConnectivityManager
import android.net.wifi.WifiManager
import android.os.PowerManager
import android.util.Log
import androidx.core.content.getSystemService
import go.Seq
import io.nekohasekai.libbox.Libbox
import io.nekohasekai.libbox.SetupOptions
import io.nekohasekai.sfa.bg.AppChangeReceiver
import io.nekohasekai.sfa.bg.CrashReportManager
import io.nekohasekai.sfa.bg.OOMReportManager
import io.nekohasekai.sfa.bg.UpdateProfileWork
import io.nekohasekai.sfa.constant.Bugs
import io.nekohasekai.sfa.database.Settings
import io.nekohasekai.sfa.utils.AppLifecycleObserver
import io.nekohasekai.sfa.utils.HookModuleUpdateNotifier
import io.nekohasekai.sfa.utils.HookStatusClient
Expand All @@ -39,13 +42,28 @@ class Application : Application() {
AppLifecycleObserver.register(this)

// Seq.setContext(this)
Libbox.setLocale(Locale.getDefault().toLanguageTag().replace("-", "_"))
runCatching {
Libbox.setLocale(Locale.getDefault().toLanguageTag().replace("-", "_"))
}.onFailure {
Log.d("Application", "set locale: ${it.message}")
}
HookStatusClient.register(this)
PrivilegeSettingsClient.register(this)

val baseDir = filesDir
baseDir.mkdirs()
val workingDir = getExternalFilesDir(null)
val tempDir = cacheDir
tempDir.mkdirs()
if (workingDir != null) {
workingDir.mkdirs()
CrashReportManager.install(workingDir, baseDir)
OOMReportManager.install(workingDir)
}

@Suppress("OPT_IN_USAGE")
GlobalScope.launch(Dispatchers.IO) {
initialize()
initialize(baseDir, workingDir, tempDir)
UpdateProfileWork.reconfigureUpdater()
HookModuleUpdateNotifier.sync(this@Application)
}
Expand All @@ -62,24 +80,33 @@ class Application : Application() {
}
}

private fun initialize() {
private fun initialize(baseDir: File, workingDir: File?, tempDir: File) {
val actualWorkingDir = workingDir ?: return
setupLibbox(baseDir, actualWorkingDir, tempDir)
}

fun reloadSetupOptions() {
val baseDir = filesDir
baseDir.mkdirs()
val workingDir = getExternalFilesDir(null) ?: return
workingDir.mkdirs()
val tempDir = cacheDir
tempDir.mkdirs()
Libbox.setup(
SetupOptions().also {
it.basePath = baseDir.path
it.workingPath = workingDir.path
it.tempPath = tempDir.path
it.fixAndroidStack = Bugs.fixAndroidStack
it.logMaxLines = 3000
it.debug = BuildConfig.DEBUG
},
)
Libbox.redirectStderr(File(workingDir, "stderr.log").path)
Libbox.reloadSetupOptions(createSetupOptions(baseDir, workingDir, tempDir))
}

private fun setupLibbox(baseDir: File, workingDir: File, tempDir: File) {
Libbox.setup(createSetupOptions(baseDir, workingDir, tempDir))
}

private fun createSetupOptions(baseDir: File, workingDir: File, tempDir: File): SetupOptions = SetupOptions().also {
it.basePath = baseDir.path
it.workingPath = workingDir.path
it.tempPath = tempDir.path
it.fixAndroidStack = Bugs.fixAndroidStack
it.logMaxLines = 3000
it.debug = BuildConfig.DEBUG
it.crashReportSource = "Application"
it.oomKillerEnabled = Settings.oomKillerEnabled
it.oomKillerDisabled = Settings.oomKillerDisabled
it.oomMemoryLimit = Settings.oomMemoryLimitMB.toLong() * 1024L * 1024L
}

companion object {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/io/nekohasekai/sfa/bg/BootReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class BootReceiver : BroadcastReceiver() {
}
GlobalScope.launch(Dispatchers.IO) {
if (Settings.startedByUser) {
CrashReportManager.refresh()
if (CrashReportManager.unreadCount.value > 0) {
Settings.startedByUser = false
return@launch
}
withContext(Dispatchers.Main) {
BoxService.start()
}
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/io/nekohasekai/sfa/bg/BoxService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,13 @@ class BoxService(private val service: Service, private val platformInterface: Pl
}
}

override fun triggerNativeCrash() {
Thread {
Thread.sleep(200)
throw RuntimeException("debug native crash")
}.start()
}

override fun writeDebugMessage(message: String?) {
Log.d("sing-box", message!!)
}
Expand Down
Loading