Commit f381ad63 authored by Mygod's avatar Mygod

Fix crash when no profile is selected

parent b25e9a09
...@@ -258,7 +258,7 @@ object BaseService { ...@@ -258,7 +258,7 @@ object BaseService {
data.sslocalProcess = GuardedProcess(cmd).start() data.sslocalProcess = GuardedProcess(cmd).start()
} }
fun createNotification(): ServiceNotification fun createNotification(profileName: String): ServiceNotification
fun startRunner() { fun startRunner() {
this as Context this as Context
...@@ -318,11 +318,11 @@ object BaseService { ...@@ -318,11 +318,11 @@ object BaseService {
val profile = app.currentProfile val profile = app.currentProfile
this as Context this as Context
if (profile == null) { 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)) stopRunner(true, getString(R.string.profile_empty))
return Service.START_NOT_STICKY return Service.START_NOT_STICKY
} }
data.profile = profile data.profile = profile
profile.name = profile.formattedName
TrafficMonitor.reset() TrafficMonitor.reset()
val thread = TrafficMonitorThread() val thread = TrafficMonitorThread()
...@@ -339,7 +339,7 @@ object BaseService { ...@@ -339,7 +339,7 @@ object BaseService {
data.closeReceiverRegistered = true data.closeReceiverRegistered = true
} }
data.notification = createNotification() data.notification = createNotification(profile.formattedName)
app.track(tag, "start") app.track(tag, "start")
data.changeState(CONNECTING) data.changeState(CONNECTING)
......
...@@ -23,6 +23,7 @@ package com.github.shadowsocks.bg ...@@ -23,6 +23,7 @@ package com.github.shadowsocks.bg
import android.app.Service import android.app.Service
import android.content.Intent import android.content.Intent
import android.os.IBinder import android.os.IBinder
import com.github.shadowsocks.database.Profile
/** /**
* Shadowsocks service at its minimum. * Shadowsocks service at its minimum.
...@@ -33,8 +34,8 @@ class ProxyService : Service(), BaseService.Interface { ...@@ -33,8 +34,8 @@ class ProxyService : Service(), BaseService.Interface {
} }
override val tag: String get() = "ShadowsocksProxyService" override val tag: String get() = "ShadowsocksProxyService"
override fun createNotification(): ServiceNotification = override fun createNotification(profileName: String): ServiceNotification =
ServiceNotification(this, data.profile!!.formattedName, "service-proxy", true) ServiceNotification(this, profileName, "service-proxy", true)
override fun onBind(intent: Intent): IBinder? = super.onBind(intent) override fun onBind(intent: Intent): IBinder? = super.onBind(intent)
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int = override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int =
......
...@@ -33,8 +33,8 @@ class TransproxyService : Service(), LocalDnsService.Interface { ...@@ -33,8 +33,8 @@ class TransproxyService : Service(), LocalDnsService.Interface {
} }
override val tag: String get() = "ShadowsocksTransproxyService" override val tag: String get() = "ShadowsocksTransproxyService"
override fun createNotification(): ServiceNotification = override fun createNotification(profileName: String): ServiceNotification =
ServiceNotification(this, data.profile!!.formattedName, "service-transproxy", true) ServiceNotification(this, profileName, "service-transproxy", true)
override fun onBind(intent: Intent): IBinder? = super.onBind(intent) override fun onBind(intent: Intent): IBinder? = super.onBind(intent)
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int = override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int =
......
...@@ -76,8 +76,8 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { ...@@ -76,8 +76,8 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
} }
override val tag: String get() = "ShadowsocksVpnService" override val tag: String get() = "ShadowsocksVpnService"
override fun createNotification(): ServiceNotification = override fun createNotification(profileName: String): ServiceNotification =
ServiceNotification(this, data.profile!!.formattedName, "service-vpn") ServiceNotification(this, profileName, "service-vpn")
private var conn: ParcelFileDescriptor? = null private var conn: ParcelFileDescriptor? = null
private var worker: ProtectWorker? = null private var worker: ProtectWorker? = null
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment