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
569 changes: 569 additions & 0 deletions SHIZUKU_TETHERING.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions V2rayNG/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ android {
buildFeatures {
buildConfig = true
compose = true
aidl = true
}

androidResources {
Expand Down Expand Up @@ -170,6 +171,8 @@ dependencies {
// AndroidX Core Libraries
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.shizuku.api)
implementation(libs.shizuku.provider)

// Compose Libraries
implementation(platform(libs.androidx.compose.bom))
Expand Down

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions V2rayNG/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,29 @@
<activity
android:name=".ui.backup.BackupActivity"
android:exported="false" />
<activity
android:name=".ui.ShizukuActivity"
android:enabled="@bool/shizuku_tethering_enabled"
android:exported="false" />
<receiver
android:name=".shizuku.ShizukuRoutingSyncReceiver"
android:enabled="@bool/shizuku_tethering_enabled"
android:exported="false" />
<activity
android:name=".ui.AboutActivity"
android:exported="false" />
<activity
android:name=".ui.TranslatorsActivity"
android:exported="false" />

<provider
android:name="rikka.shizuku.ShizukuProvider"
android:authorities="${applicationId}.shizuku"
android:enabled="@bool/shizuku_tethering_enabled"
android:exported="true"
android:multiprocess="false"
android:permission="android.permission.INTERACT_ACROSS_USERS_FULL" />

<service
android:name=".service.CoreVpnService"
android:enabled="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.v2ray.ang.shizuku;

import android.os.ParcelFileDescriptor;

/** Exposes private core inputs and keeps the protected test network alive. */
interface ICoreTetheringLease {
ParcelFileDescriptor openEngineConfig(String launchId);
boolean isCurrentLaunch(String launchId);
void holdTestNetwork(in ParcelFileDescriptor tun);
void releaseTestNetwork();
String assetFingerprint();
String[] listAssetFiles();
ParcelFileDescriptor openAssetFile(String name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.v2ray.ang.shizuku;

import com.v2ray.ang.shizuku.ICoreTetheringLease;
import com.v2ray.ang.shizuku.ITetheringStatusListener;
import com.v2ray.ang.shizuku.TetheringStatusSnapshot;

interface IShizukuTetheringService {
int setWifiHotspotEnabled(boolean enabled) = 2;
int startRouting(boolean useHev, String profileName, in String[] dnsServers, boolean ipv6Enabled, String xudpKey, String syncToken, String launchId, ICoreTetheringLease coreLease) = 6;
int stopRouting() = 7;
oneway void notifyCoreStopping(String syncToken) = 9;
oneway void synchronizeRouting(String syncToken, boolean useHev, String profileName, in String[] dnsServers, boolean ipv6Enabled, String xudpKey, String launchId, ICoreTetheringLease coreLease) = 10;
oneway void notifyCoreStartFailed(String syncToken, String detail) = 11;
TetheringStatusSnapshot getStatus(boolean includeIpv6) = 14;
oneway void setStatusListener(ITetheringStatusListener listener) = 15;
void destroy() = 16777114;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.v2ray.ang.shizuku;

oneway interface ITetheringStatusListener {
void onStatusChanged();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.v2ray.ang.shizuku;

parcelable TetheringStatusSnapshot;
9 changes: 9 additions & 0 deletions V2rayNG/app/src/main/java/com/v2ray/ang/AngApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package com.v2ray.ang

import android.app.Application
import android.content.Context
import android.os.Build
import androidx.core.content.ContextCompat
import androidx.work.Configuration
import androidx.work.WorkManager
import com.v2ray.ang.AppConfig.ANG_PACKAGE
import com.v2ray.ang.handler.AppLocaleManager
import com.v2ray.ang.handler.MmkvManager
import com.v2ray.ang.handler.SettingsManager
import com.v2ray.ang.shizuku.ShizukuForegroundRecovery
import com.v2ray.ang.ui.compose.ThemeManager
import rikka.shizuku.ShizukuProvider

class AngApplication : Application() {
companion object {
Expand All @@ -23,6 +26,10 @@ class AngApplication : Application() {
override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base?.let(ContextCompat::getContextForLanguage))
application = this
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
// The VPN core process must receive replacement Shizuku Binders after a server restart.
ShizukuProvider.enableMultiProcessSupport(Application.getProcessName() == packageName)
}
}

private val workManagerConfiguration: Configuration = Configuration.Builder()
Expand All @@ -47,5 +54,7 @@ class AngApplication : Application() {

// Initialize theme state from MMKV
ThemeManager.refresh()

ShizukuForegroundRecovery.register(this)
}
}
15 changes: 15 additions & 0 deletions V2rayNG/app/src/main/java/com/v2ray/ang/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ object AppConfig {
const val PREF_HEV_TUNNEL_RW_TIMEOUT = "pref_hev_tunnel_rw_timeout_v2"
const val PREF_UPDATE_SUBSCRIPTION = "pref_update_subscription"
const val PREF_AUTO_TEST_AFTER_UPDATE_SUBSCRIPTION = "pref_auto_test_after_update_subscription"
const val PREF_SHIZUKU_SYNC_TOKEN = "pref_shizuku_sync_token"
const val PREF_AUTO_REMOVE_INVALID_AFTER_TEST = "pref_auto_remove_invalid_after_test"
const val PREF_AUTO_SORT_AFTER_TEST = "pref_auto_sort_after_test"
const val PREF_REAL_PING_CONCURRENCY = "pref_real_ping_concurrency"
Expand Down Expand Up @@ -199,6 +200,9 @@ object AppConfig {
const val MSG_MEASURE_CONFIG_SUCCESS = 72
const val MSG_MEASURE_CONFIG_NOTIFY = 73
const val MSG_MEASURE_CONFIG_FINISH = 74
const val MSG_QUERY_HOTSPOT_CONFIG = 91
const val MSG_HOTSPOT_CONFIG_RESPONSE = 92
const val MSG_SHIZUKU_APP_FOREGROUND = 93

const val MSG_SUB_UPDATE_START = 8
const val MSG_SUB_UPDATE_CANCEL = 81
Expand Down Expand Up @@ -252,6 +256,17 @@ object AppConfig {
const val ROOT_LAN_DNS = "1.1.1.1" // fallback resolver for tethered clients when no plain-IPv4 DNS is configured
const val ROOT_OOM_SCORE = "-1000" // oom_score_adj that makes the LMK never kill us

/** Shizuku test-network TUN used as Android tethering's preferred upstream. */
const val SHIZUKU_TUN_ADDR_V4 = "192.0.2.2/24"
/**
* Android only delegates a /64 that it considers globally scoped. The documentation
* prefix satisfies that platform requirement without claiming a real public network.
*/
const val SHIZUKU_TUN_ADDR_V6 = "2001:db8:9877::1/64"

/** IPv6-shaped DNS hint required by Android; configured app resolvers remain first. */
const val SHIZUKU_TUN_DNS_HINT_V6 = "fdfe:dcba:9877::53"

/** hev-sock5-tunnel read-write-timeout value */
const val HEVTUN_RW_TIMEOUT = "300,60"

Expand Down
Loading
Loading