diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index fc27dde..3bb3cf3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -12,6 +12,7 @@
+
@@ -155,7 +156,7 @@
+ android:foregroundServiceType="specialUse|location">
diff --git a/app/src/main/java/io/nekohasekai/sfa/bg/DefaultNetworkMonitor.kt b/app/src/main/java/io/nekohasekai/sfa/bg/DefaultNetworkMonitor.kt
index 8b918ff..0e04e3c 100644
--- a/app/src/main/java/io/nekohasekai/sfa/bg/DefaultNetworkMonitor.kt
+++ b/app/src/main/java/io/nekohasekai/sfa/bg/DefaultNetworkMonitor.kt
@@ -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)
+ }
}
diff --git a/app/src/main/java/io/nekohasekai/sfa/ui/MainActivity.kt b/app/src/main/java/io/nekohasekai/sfa/ui/MainActivity.kt
index a8d2073..9dc612b 100644
--- a/app/src/main/java/io/nekohasekai/sfa/ui/MainActivity.kt
+++ b/app/src/main/java/io/nekohasekai/sfa/ui/MainActivity.kt
@@ -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))
diff --git a/app/src/main/java/io/nekohasekai/sfa/ui/profile/EditProfileActivity.kt b/app/src/main/java/io/nekohasekai/sfa/ui/profile/EditProfileActivity.kt
index 5fc16c2..44fcf98 100644
--- a/app/src/main/java/io/nekohasekai/sfa/ui/profile/EditProfileActivity.kt
+++ b/app/src/main/java/io/nekohasekai/sfa/ui/profile/EditProfileActivity.kt
@@ -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()
}
}
diff --git a/app/src/main/java/io/nekohasekai/sfa/ui/profile/EditProfileContentActivity.kt b/app/src/main/java/io/nekohasekai/sfa/ui/profile/EditProfileContentActivity.kt
index 917c180..0657972 100644
--- a/app/src/main/java/io/nekohasekai/sfa/ui/profile/EditProfileContentActivity.kt
+++ b/app/src/main/java/io/nekohasekai/sfa/ui/profile/EditProfileContentActivity.kt
@@ -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()
}
}
diff --git a/app/src/main/java/io/nekohasekai/sfa/ui/profileoverride/PerAppProxyActivity.kt b/app/src/main/java/io/nekohasekai/sfa/ui/profileoverride/PerAppProxyActivity.kt
index bd8b8c8..ccf9553 100644
--- a/app/src/main/java/io/nekohasekai/sfa/ui/profileoverride/PerAppProxyActivity.kt
+++ b/app/src/main/java/io/nekohasekai/sfa/ui/profileoverride/PerAppProxyActivity.kt
@@ -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
}
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
new file mode 100644
index 0000000..1098170
--- /dev/null
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -0,0 +1,3 @@
+
+ 好
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a29d84e..f0c5846 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -145,5 +145,7 @@
If I\'ve defended your modern life, please consider sponsoring me.
Other methods
Start
+ Location permission
+ 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.
\ No newline at end of file