Make notification permission optional if real-time speeds notification is disabled
This commit is contained in:
@@ -95,7 +95,7 @@ class ServiceNotification(
|
||||
}
|
||||
|
||||
suspend fun start() {
|
||||
if (Settings.dynamicNotification) {
|
||||
if (Settings.dynamicNotification && checkPermission()) {
|
||||
commandClient.connect()
|
||||
withContext(Dispatchers.Main) {
|
||||
registerReceiver()
|
||||
|
||||
@@ -221,7 +221,10 @@ class MainActivity : AbstractActivity<ActivityMainBinding>(),
|
||||
notificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
|
||||
return
|
||||
}
|
||||
startService0()
|
||||
}
|
||||
|
||||
private fun startService0() {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
if (Settings.rebuildServiceMode()) {
|
||||
reconnect()
|
||||
@@ -241,10 +244,10 @@ class MainActivity : AbstractActivity<ActivityMainBinding>(),
|
||||
private val notificationPermissionLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
) {
|
||||
if (it) {
|
||||
startService()
|
||||
} else {
|
||||
if (Settings.dynamicNotification && !it) {
|
||||
onServiceAlert(Alert.RequestNotificationPermission, null)
|
||||
} else {
|
||||
startService0()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,6 +307,8 @@ class MainActivity : AbstractActivity<ActivityMainBinding>(),
|
||||
}
|
||||
|
||||
override fun onServiceAlert(type: Alert, message: String?) {
|
||||
serviceStatus.value = Status.Stopped
|
||||
|
||||
when (type) {
|
||||
Alert.RequestLocationPermission -> {
|
||||
return requestLocationPermission()
|
||||
@@ -320,7 +325,8 @@ class MainActivity : AbstractActivity<ActivityMainBinding>(),
|
||||
}
|
||||
|
||||
Alert.RequestNotificationPermission -> {
|
||||
builder.setMessage(getString(R.string.service_error_missing_notification_permission))
|
||||
builder.setTitle(R.string.notification_permission_title)
|
||||
builder.setMessage(R.string.notification_permission_required_description)
|
||||
}
|
||||
|
||||
Alert.EmptyConfiguration -> {
|
||||
|
||||
@@ -161,4 +161,6 @@
|
||||
<string name="location_permission_description"><![CDATA[您的个人资料包含 <strong><tt>wifi_ssid</tt> 或 <tt>wifi_bssid</tt> 路由规则</strong>。为了使它们正常工作,sing-box 在<strong>后台</strong>使用 <strong>位置</strong> 权限来获取有关所连接 Wi-Fi 网络的信息。该信息将<strong>仅用于路由目的</strong>。]]></string>
|
||||
<string name="location_permission_background_description"><![CDATA[在 Android 10 及更高版本中,需要<strong>后台位置</strong>权限。选择<strong>始终允许</strong>以授予权限。]]></string>
|
||||
<string name="open_settings">打开设置</string>
|
||||
<string name="notification_permission_title">通知权限</string>
|
||||
<string name="notification_permission_required_description">sing-box 无法在没有发送通知权限的情况下显示实时网速。请授予权限或禁用实时网速通知后再启动服务。</string>
|
||||
</resources>
|
||||
@@ -188,6 +188,6 @@
|
||||
<string name="location_permission_description"><![CDATA[Your profile contains <strong><tt>wifi_ssid</tt> or <tt>wifi_bssid</tt> routing rules</strong>. To make them work, sing-box uses the <strong>location</strong> permission <strong>in the background</strong> to get information about the connected Wi-Fi network. The information will be used <strong>for routing purposes only</strong>.]]></string>
|
||||
<string name="location_permission_background_description"><![CDATA[On Android 10 and up, <strong>background location</strong> permission is required. Select <strong>Allow all the time</strong> to grant the permission.]]></string>
|
||||
<string name="open_settings">Open Settings</string>
|
||||
|
||||
|
||||
<string name="notification_permission_title">Notification permission</string>
|
||||
<string name="notification_permission_required_description">sing-box is unable to show real-time network speeds without the permission to send notifications. Please grant the permission or disable real-time network speeds notification before starting the service.</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user