diff --git a/mobile/src/main/java/com/github/shadowsocks/bg/BaseService.kt b/mobile/src/main/java/com/github/shadowsocks/bg/BaseService.kt index 470a016b..822d0241 100644 --- a/mobile/src/main/java/com/github/shadowsocks/bg/BaseService.kt +++ b/mobile/src/main/java/com/github/shadowsocks/bg/BaseService.kt @@ -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) diff --git a/mobile/src/main/java/com/github/shadowsocks/bg/ProxyService.kt b/mobile/src/main/java/com/github/shadowsocks/bg/ProxyService.kt index 73dc4dcc..6f6d0cf1 100644 --- a/mobile/src/main/java/com/github/shadowsocks/bg/ProxyService.kt +++ b/mobile/src/main/java/com/github/shadowsocks/bg/ProxyService.kt @@ -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 = diff --git a/mobile/src/main/java/com/github/shadowsocks/bg/TransproxyService.kt b/mobile/src/main/java/com/github/shadowsocks/bg/TransproxyService.kt index a04d39e7..d9f713c2 100644 --- a/mobile/src/main/java/com/github/shadowsocks/bg/TransproxyService.kt +++ b/mobile/src/main/java/com/github/shadowsocks/bg/TransproxyService.kt @@ -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 = diff --git a/mobile/src/main/java/com/github/shadowsocks/bg/VpnService.kt b/mobile/src/main/java/com/github/shadowsocks/bg/VpnService.kt index 85572c51..4a456d5a 100644 --- a/mobile/src/main/java/com/github/shadowsocks/bg/VpnService.kt +++ b/mobile/src/main/java/com/github/shadowsocks/bg/VpnService.kt @@ -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