Fix android bugs
This commit is contained in:
@@ -14,6 +14,7 @@ import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.hiddify.hiddify.Application
|
||||
import com.hiddify.hiddify.R
|
||||
import com.hiddify.hiddify.Settings
|
||||
import com.hiddify.hiddify.constant.Action
|
||||
import com.hiddify.hiddify.constant.Alert
|
||||
@@ -140,6 +141,9 @@ class BoxService(
|
||||
private suspend fun startService(delayStart: Boolean = false) {
|
||||
try {
|
||||
Log.d(TAG, "starting service")
|
||||
withContext(Dispatchers.Main) {
|
||||
notification.show(activeProfileName, R.string.status_starting)
|
||||
}
|
||||
|
||||
val selectedConfigPath = Settings.activeConfigPath
|
||||
if (selectedConfigPath.isBlank()) {
|
||||
@@ -168,6 +172,7 @@ class BoxService(
|
||||
}
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
notification.show(activeProfileName, R.string.status_starting)
|
||||
binder.broadcast {
|
||||
it.onServiceResetLogs(listOf())
|
||||
}
|
||||
@@ -194,8 +199,9 @@ class BoxService(
|
||||
status.postValue(Status.Started)
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
notification.show(activeProfileName)
|
||||
notification.show(activeProfileName, R.string.status_started)
|
||||
}
|
||||
notification.start()
|
||||
} catch (e: Exception) {
|
||||
stopAndAlert(Alert.StartService, e.message)
|
||||
return
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.os.Build
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.ServiceCompat
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
@@ -79,7 +80,7 @@ class ServiceNotification(private val status: MutableLiveData<Status>, private v
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun show(profileName: String) {
|
||||
fun show(profileName: String, @StringRes contentTextId: Int) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
Application.notification.createNotificationChannel(
|
||||
NotificationChannel(
|
||||
@@ -90,9 +91,12 @@ class ServiceNotification(private val status: MutableLiveData<Status>, private v
|
||||
service.startForeground(
|
||||
notificationId, notificationBuilder
|
||||
.setContentTitle(profileName.takeIf { it.isNotBlank() } ?: "Hiddify Next")
|
||||
.setContentText("service started").build()
|
||||
.setContentText(service.getString(contentTextId)).build()
|
||||
)
|
||||
withContext(Dispatchers.IO) {
|
||||
}
|
||||
|
||||
|
||||
suspend fun start() {
|
||||
if (Settings.dynamicNotification) {
|
||||
commandClient.connect()
|
||||
withContext(Dispatchers.Main) {
|
||||
@@ -100,7 +104,6 @@ class ServiceNotification(private val status: MutableLiveData<Status>, private v
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun registerReceiver() {
|
||||
service.registerReceiver(this, IntentFilter().apply {
|
||||
|
||||
@@ -165,19 +165,14 @@ class VPNService : VpnService(), PlatformInterfaceWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
if (options.isHTTPProxyEnabled) {
|
||||
if (options.isHTTPProxyEnabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
systemProxyAvailable = true
|
||||
systemProxyEnabled = Settings.systemProxyEnabled
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
if (systemProxyEnabled) builder.setHttpProxy(
|
||||
ProxyInfo.buildDirectProxy(
|
||||
options.httpProxyServer,
|
||||
options.httpProxyServerPort
|
||||
options.httpProxyServer, options.httpProxyServerPort
|
||||
)
|
||||
)
|
||||
} else {
|
||||
error("android: tun.platform.http_proxy requires android 10 or higher")
|
||||
}
|
||||
} else {
|
||||
systemProxyAvailable = false
|
||||
systemProxyEnabled = false
|
||||
|
||||
@@ -2,4 +2,6 @@
|
||||
<resources>
|
||||
<string name="stop">Stop</string>
|
||||
<string name="quick_toggle">Toggle</string>
|
||||
<string name="status_starting">Service starting…</string>
|
||||
<string name="status_started">Service started</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user