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