mirror of
https://github.com/SagerNet/sing-box-for-android.git
synced 2025-04-03 20:07:38 +03:00
Fix WIFI state permission
This commit is contained in:
parent
f6b3fd9907
commit
3224f56f89
8 changed files with 50 additions and 18 deletions
|
@ -12,6 +12,7 @@
|
|||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.QUERY_ALL_PACKAGES"
|
||||
|
@ -143,7 +144,7 @@
|
|||
<service
|
||||
android:name=".bg.VPNService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="specialUse"
|
||||
android:foregroundServiceType="specialUse|location"
|
||||
android:permission="android.permission.BIND_VPN_SERVICE">
|
||||
<intent-filter>
|
||||
<action android:name="android.net.VpnService" />
|
||||
|
@ -155,7 +156,7 @@
|
|||
<service
|
||||
android:name=".bg.ProxyService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="specialUse">
|
||||
android:foregroundServiceType="specialUse|location">
|
||||
<property
|
||||
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
|
||||
android:value="proxy" />
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.net.Network
|
|||
import android.os.Build
|
||||
import io.nekohasekai.libbox.InterfaceUpdateListener
|
||||
import io.nekohasekai.sfa.Application
|
||||
import java.net.NetworkInterface
|
||||
|
||||
object DefaultNetworkMonitor {
|
||||
|
||||
|
@ -35,8 +36,22 @@ object DefaultNetworkMonitor {
|
|||
newNetwork: Network?
|
||||
) {
|
||||
val listener = listener ?: return
|
||||
val link = Application.connectivity.getLinkProperties(newNetwork ?: return) ?: return
|
||||
listener.updateDefaultInterface(link.interfaceName, -1)
|
||||
if (newNetwork != null) {
|
||||
val interfaceName =
|
||||
(Application.connectivity.getLinkProperties(newNetwork) ?: return).interfaceName
|
||||
for (times in 0 until 10) {
|
||||
var interfaceIndex: Int
|
||||
try {
|
||||
interfaceIndex = NetworkInterface.getByName(interfaceName).index
|
||||
} catch (e: Exception) {
|
||||
Thread.sleep(100)
|
||||
continue
|
||||
}
|
||||
listener.updateDefaultInterface(interfaceName, interfaceIndex)
|
||||
}
|
||||
} else {
|
||||
listener.updateDefaultInterface("", -1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ class MainActivity : AbstractActivity(), ServiceConnection.Callback {
|
|||
profile.host
|
||||
)
|
||||
)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
.setPositiveButton(R.string.ok) { _, _ ->
|
||||
startActivity(Intent(this, NewProfileActivity::class.java).apply {
|
||||
putExtra("importName", profile.name)
|
||||
putExtra("importURL", profile.url)
|
||||
|
@ -121,7 +121,7 @@ class MainActivity : AbstractActivity(), ServiceConnection.Callback {
|
|||
content.name
|
||||
)
|
||||
)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
.setPositiveButton(R.string.ok) { _, _ ->
|
||||
lifecycleScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
runCatching {
|
||||
|
@ -186,14 +186,14 @@ class MainActivity : AbstractActivity(), ServiceConnection.Callback {
|
|||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
fun startService(skipRequestFineLocation: Boolean = false) {
|
||||
fun startService(skipRequestLocation: Boolean = false) {
|
||||
if (!ServiceNotification.checkPermission()) {
|
||||
notificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
|
||||
return
|
||||
}
|
||||
|
||||
// MIUI always return false for shouldShowRequestPermissionRationale
|
||||
if (!skipRequestFineLocation && ContextCompat.checkSelfPermission(
|
||||
if (!skipRequestLocation && ContextCompat.checkSelfPermission(
|
||||
this, Manifest.permission.ACCESS_FINE_LOCATION
|
||||
) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
|
@ -201,9 +201,20 @@ class MainActivity : AbstractActivity(), ServiceConnection.Callback {
|
|||
this, Manifest.permission.ACCESS_FINE_LOCATION
|
||||
)
|
||||
) {
|
||||
fineLocationPermissionLauncher.launch(
|
||||
Manifest.permission.ACCESS_FINE_LOCATION
|
||||
)
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.location_permission_title)
|
||||
.setMessage(R.string.location_permission_description)
|
||||
.setPositiveButton(R.string.ok) { _, _ ->
|
||||
locationPermissionLauncher.launch(
|
||||
arrayOf(
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION,
|
||||
)
|
||||
)
|
||||
}
|
||||
.setCancelable(false)
|
||||
.show()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,8 +244,8 @@ class MainActivity : AbstractActivity(), ServiceConnection.Callback {
|
|||
}
|
||||
}
|
||||
|
||||
private val fineLocationPermissionLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
private val locationPermissionLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.RequestMultiplePermissions()
|
||||
) {
|
||||
startService(true)
|
||||
}
|
||||
|
@ -278,7 +289,7 @@ class MainActivity : AbstractActivity(), ServiceConnection.Callback {
|
|||
|
||||
override fun onServiceAlert(type: Alert, message: String?) {
|
||||
val builder = MaterialAlertDialogBuilder(this)
|
||||
builder.setPositiveButton(android.R.string.ok, null)
|
||||
builder.setPositiveButton(R.string.ok, null)
|
||||
when (type) {
|
||||
Alert.RequestVPNPermission -> {
|
||||
builder.setMessage(getString(R.string.service_error_missing_permission))
|
||||
|
|
|
@ -48,7 +48,7 @@ class EditProfileActivity : AbstractActivity() {
|
|||
}.onFailure {
|
||||
withContext(Dispatchers.Main) {
|
||||
errorDialogBuilder(it)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ -> finish() }
|
||||
.setPositiveButton(R.string.ok) { _, _ -> finish() }
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ class EditProfileContentActivity : AbstractActivity() {
|
|||
}.onFailure {
|
||||
withContext(Dispatchers.Main) {
|
||||
errorDialogBuilder(it)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ -> finish() }
|
||||
.setPositiveButton(R.string.ok) { _, _ -> finish() }
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@ class PerAppProxyActivity : AbstractActivity() {
|
|||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.menu_import_from_clipboard)
|
||||
.setMessage(R.string.message_import_from_clipboard)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
.setPositiveButton(R.string.ok) { _, _ ->
|
||||
importFromClipboard()
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
|
@ -284,7 +284,7 @@ class PerAppProxyActivity : AbstractActivity() {
|
|||
MaterialAlertDialogBuilder(this@PerAppProxyActivity)
|
||||
.setTitle(R.string.title_scan_result)
|
||||
.setMessage(R.string.message_scan_app_no_apps_found)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show()
|
||||
return@launch
|
||||
}
|
||||
|
|
3
app/src/main/res/values-zh-rCN/strings.xml
Normal file
3
app/src/main/res/values-zh-rCN/strings.xml
Normal file
|
@ -0,0 +1,3 @@
|
|||
<resources>
|
||||
<string name="ok">好</string>
|
||||
</resources>
|
|
@ -145,5 +145,7 @@
|
|||
<string name="sponsor_message">If I\'ve defended your modern life, please consider sponsoring me.</string>
|
||||
<string name="other_methods">Other methods</string>
|
||||
<string name="action_start">Start</string>
|
||||
<string name="location_permission_title">Location permission</string>
|
||||
<string name="location_permission_description">sing-box uses the location permission to provide `wifi_ssid` and `wifi_bssid` routing rule entries, deny it if you don\'t need this feature.</string>
|
||||
|
||||
</resources>
|
Loading…
Add table
Add a link
Reference in a new issue