Fix android bugs

This commit is contained in:
problematicconsumer
2024-02-09 14:12:41 +03:30
parent 7394f7c4c3
commit 8a7a907fd3
4 changed files with 29 additions and 23 deletions

View File

@@ -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

View File

@@ -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,25 +80,27 @@ 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(
notificationChannel, "hiddify service", NotificationManager.IMPORTANCE_LOW
)
NotificationChannel(
notificationChannel, "hiddify service", NotificationManager.IMPORTANCE_LOW
)
)
}
service.startForeground(
notificationId, notificationBuilder
notificationId, notificationBuilder
.setContentTitle(profileName.takeIf { it.isNotBlank() } ?: "Hiddify Next")
.setContentText("service started").build()
.setContentText(service.getString(contentTextId)).build()
)
withContext(Dispatchers.IO) {
if (Settings.dynamicNotification) {
commandClient.connect()
withContext(Dispatchers.Main) {
registerReceiver()
}
}
suspend fun start() {
if (Settings.dynamicNotification) {
commandClient.connect()
withContext(Dispatchers.Main) {
registerReceiver()
}
}
}

View File

@@ -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
)
if (systemProxyEnabled) builder.setHttpProxy(
ProxyInfo.buildDirectProxy(
options.httpProxyServer, options.httpProxyServerPort
)
} else {
error("android: tun.platform.http_proxy requires android 10 or higher")
}
)
} else {
systemProxyAvailable = false
systemProxyEnabled = false

View File

@@ -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>