feat: Add VPN network mode toggle with permission handling, resolve Android 10 black screen issues, and remove Xposed framework support.

This commit is contained in:
alex5402
2026-01-31 14:03:56 +05:30
parent f613f730dd
commit 272e8cfe6e
8 changed files with 195 additions and 62 deletions
@@ -25,6 +25,9 @@ class BlackBoxLoader {
private var mDaemonEnable by AppSharedPreferenceDelegate(App.getContext(), false)
private var mShowShortcutPermissionDialog by AppSharedPreferenceDelegate(App.getContext(), true)
// VPN network mode: true = use VPN, false = normal network
private var mUseVpnNetwork by AppSharedPreferenceDelegate(App.getContext(), false)
fun hideRoot(): Boolean {
return try {
mHideRoot
@@ -76,6 +79,23 @@ class BlackBoxLoader {
}
}
fun useVpnNetwork(): Boolean {
return try {
mUseVpnNetwork
} catch (e: Exception) {
Log.e(TAG, "Error getting useVpnNetwork: ${e.message}")
false
}
}
fun invalidUseVpnNetwork(enable: Boolean) {
try {
this.mUseVpnNetwork = enable
} catch (e: Exception) {
Log.e(TAG, "Error setting useVpnNetwork: ${e.message}")
}
}
fun getBlackBoxCore(): BlackBoxCore {
return try {
BlackBoxCore.get()
@@ -219,6 +239,15 @@ class BlackBoxLoader {
}
}
override fun isUseVpnNetwork(): Boolean {
return try {
mUseVpnNetwork
} catch (e: Exception) {
Log.e(TAG, "Error checking useVpnNetwork: ${e.message}")
false
}
}
override fun requestInstallPackage(
file: File?,
userId: Int
@@ -3,6 +3,7 @@ package top.niunaijun.blackboxa.view.main
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.net.VpnService
import android.os.Bundle
import android.util.Log
import android.view.Menu
@@ -38,6 +39,7 @@ class MainActivity : LoadingActivity() {
companion object {
private const val TAG = "MainActivity"
private const val STORAGE_PERMISSION_REQUEST_CODE = 1001
private const val VPN_PERMISSION_REQUEST_CODE = 1002
fun start(context: Context) {
val intent = Intent(context, MainActivity::class.java)
@@ -64,6 +66,9 @@ class MainActivity : LoadingActivity() {
// Check and request storage permission on Android 11+
checkStoragePermission()
// Check and request VPN permission
checkVpnPermission()
try {
BlackBoxCore.get().onAfterMainActivityOnCreate(this)
} catch (e: Exception) {
@@ -197,6 +202,40 @@ class MainActivity : LoadingActivity() {
}
}
/**
* Check and request VPN permission if needed. VpnService.prepare() must be called from an
* Activity before VPN can be established.
*/
private fun checkVpnPermission() {
try {
val vpnIntent = VpnService.prepare(this)
if (vpnIntent != null) {
// User needs to grant VPN permission
Log.d(TAG, "VPN permission not granted, requesting...")
vpnPermissionResult.launch(vpnIntent)
} else {
// VPN permission already granted
Log.d(TAG, "VPN permission already granted")
}
} catch (e: Exception) {
Log.e(TAG, "Error checking VPN permission: ${e.message}")
}
}
private val vpnPermissionResult =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
try {
if (result.resultCode == RESULT_OK) {
Log.d(TAG, "VPN permission granted!")
// VPN service will now be able to establish connection
} else {
Log.w(TAG, "VPN permission denied by user")
}
} catch (e: Exception) {
Log.e(TAG, "Error handling VPN permission result: ${e.message}")
}
}
private fun showErrorDialog(message: String) {
try {
MaterialDialog(this).show {
@@ -9,12 +9,6 @@ import top.niunaijun.blackboxa.app.AppManager
import top.niunaijun.blackboxa.util.toast
import top.niunaijun.blackboxa.view.gms.GmsManagerActivity
/**
*
* @Description:
* @Author: wukaicheng
* @CreateDate: 2021/5/6 22:13
*/
class SettingFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
@@ -35,6 +29,13 @@ class SettingFragment : PreferenceFragmentCompat() {
daemonPreference.setDefaultValue(mDaemonEnable)
daemonPreference
}
invalidHideState {
val vpnPreference: Preference = (findPreference("use_vpn_network")!!)
val mUseVpnNetwork = AppManager.mBlackBoxLoader.useVpnNetwork()
vpnPreference.setDefaultValue(mUseVpnNetwork)
vpnPreference
}
}
private fun initGms() {
@@ -64,6 +65,9 @@ class SettingFragment : PreferenceFragmentCompat() {
"daemon_enable" -> {
AppManager.mBlackBoxLoader.invalidDaemonEnable(tmpHide)
}
"use_vpn_network" -> {
AppManager.mBlackBoxLoader.invalidUseVpnNetwork(tmpHide)
}
}
toast(R.string.restart_module)