Fix crash when no profile is selected
This commit is contained in:
@@ -258,7 +258,7 @@ object BaseService {
|
||||
data.sslocalProcess = GuardedProcess(cmd).start()
|
||||
}
|
||||
|
||||
fun createNotification(): ServiceNotification
|
||||
fun createNotification(profileName: String): ServiceNotification
|
||||
|
||||
fun startRunner() {
|
||||
this as Context
|
||||
@@ -318,11 +318,11 @@ object BaseService {
|
||||
val profile = app.currentProfile
|
||||
this as Context
|
||||
if (profile == null) {
|
||||
data.notification = createNotification("") // gracefully shutdown: https://stackoverflow.com/questions/47337857/context-startforegroundservice-did-not-then-call-service-startforeground-eve
|
||||
stopRunner(true, getString(R.string.profile_empty))
|
||||
return Service.START_NOT_STICKY
|
||||
}
|
||||
data.profile = profile
|
||||
profile.name = profile.formattedName
|
||||
|
||||
TrafficMonitor.reset()
|
||||
val thread = TrafficMonitorThread()
|
||||
@@ -339,7 +339,7 @@ object BaseService {
|
||||
data.closeReceiverRegistered = true
|
||||
}
|
||||
|
||||
data.notification = createNotification()
|
||||
data.notification = createNotification(profile.formattedName)
|
||||
app.track(tag, "start")
|
||||
|
||||
data.changeState(CONNECTING)
|
||||
|
||||
@@ -23,6 +23,7 @@ package com.github.shadowsocks.bg
|
||||
import android.app.Service
|
||||
import android.content.Intent
|
||||
import android.os.IBinder
|
||||
import com.github.shadowsocks.database.Profile
|
||||
|
||||
/**
|
||||
* Shadowsocks service at its minimum.
|
||||
@@ -33,8 +34,8 @@ class ProxyService : Service(), BaseService.Interface {
|
||||
}
|
||||
|
||||
override val tag: String get() = "ShadowsocksProxyService"
|
||||
override fun createNotification(): ServiceNotification =
|
||||
ServiceNotification(this, data.profile!!.formattedName, "service-proxy", true)
|
||||
override fun createNotification(profileName: String): ServiceNotification =
|
||||
ServiceNotification(this, profileName, "service-proxy", true)
|
||||
|
||||
override fun onBind(intent: Intent): IBinder? = super.onBind(intent)
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int =
|
||||
|
||||
@@ -33,8 +33,8 @@ class TransproxyService : Service(), LocalDnsService.Interface {
|
||||
}
|
||||
|
||||
override val tag: String get() = "ShadowsocksTransproxyService"
|
||||
override fun createNotification(): ServiceNotification =
|
||||
ServiceNotification(this, data.profile!!.formattedName, "service-transproxy", true)
|
||||
override fun createNotification(profileName: String): ServiceNotification =
|
||||
ServiceNotification(this, profileName, "service-transproxy", true)
|
||||
|
||||
override fun onBind(intent: Intent): IBinder? = super.onBind(intent)
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int =
|
||||
|
||||
@@ -76,8 +76,8 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
|
||||
}
|
||||
|
||||
override val tag: String get() = "ShadowsocksVpnService"
|
||||
override fun createNotification(): ServiceNotification =
|
||||
ServiceNotification(this, data.profile!!.formattedName, "service-vpn")
|
||||
override fun createNotification(profileName: String): ServiceNotification =
|
||||
ServiceNotification(this, profileName, "service-vpn")
|
||||
|
||||
private var conn: ParcelFileDescriptor? = null
|
||||
private var worker: ProtectWorker? = null
|
||||
|
||||
Reference in New Issue
Block a user