Commit 27589723 authored by Mygod's avatar Mygod

Fix leaks after service switches

parent 24bd70a4
...@@ -27,10 +27,7 @@ import android.content.Intent ...@@ -27,10 +27,7 @@ import android.content.Intent
* Shadowsocks service at its minimum. * Shadowsocks service at its minimum.
*/ */
class ProxyService : Service(), BaseService.Interface { class ProxyService : Service(), BaseService.Interface {
init { override val data = BaseService.Data(this)
BaseService.register(this)
}
override val tag: String get() = "ShadowsocksProxyService" override val tag: String get() = "ShadowsocksProxyService"
override fun createNotification(profileName: String): ServiceNotification = override fun createNotification(profileName: String): ServiceNotification =
ServiceNotification(this, profileName, "service-proxy", true) ServiceNotification(this, profileName, "service-proxy", true)
...@@ -39,7 +36,7 @@ class ProxyService : Service(), BaseService.Interface { ...@@ -39,7 +36,7 @@ class ProxyService : Service(), BaseService.Interface {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int = override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int =
super<BaseService.Interface>.onStartCommand(intent, flags, startId) super<BaseService.Interface>.onStartCommand(intent, flags, startId)
override fun onDestroy() { override fun onDestroy() {
super<Service>.onDestroy() super.onDestroy()
super<BaseService.Interface>.onDestroy() data.binder.close()
} }
} }
...@@ -27,10 +27,7 @@ import com.github.shadowsocks.preference.DataStore ...@@ -27,10 +27,7 @@ import com.github.shadowsocks.preference.DataStore
import java.io.File import java.io.File
class TransproxyService : Service(), LocalDnsService.Interface { class TransproxyService : Service(), LocalDnsService.Interface {
init { override val data = BaseService.Data(this)
BaseService.register(this)
}
override val tag: String get() = "ShadowsocksTransproxyService" override val tag: String get() = "ShadowsocksTransproxyService"
override fun createNotification(profileName: String): ServiceNotification = override fun createNotification(profileName: String): ServiceNotification =
ServiceNotification(this, profileName, "service-transproxy", true) ServiceNotification(this, profileName, "service-transproxy", true)
...@@ -79,7 +76,7 @@ redsocks { ...@@ -79,7 +76,7 @@ redsocks {
} }
override fun onDestroy() { override fun onDestroy() {
super<Service>.onDestroy() super.onDestroy()
super<LocalDnsService.Interface>.onDestroy() data.binder.close()
} }
} }
...@@ -108,10 +108,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { ...@@ -108,10 +108,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
override fun getLocalizedMessage() = getString(R.string.reboot_required) override fun getLocalizedMessage() = getString(R.string.reboot_required)
} }
init { override val data = BaseService.Data(this)
BaseService.register(this)
}
override val tag: String get() = "ShadowsocksVpnService" override val tag: String get() = "ShadowsocksVpnService"
override fun createNotification(profileName: String): ServiceNotification = override fun createNotification(profileName: String): ServiceNotification =
ServiceNotification(this, profileName, "service-vpn") ServiceNotification(this, profileName, "service-vpn")
...@@ -282,7 +279,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { ...@@ -282,7 +279,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
} }
override fun onDestroy() { override fun onDestroy() {
super<BaseVpnService>.onDestroy() super.onDestroy()
super<LocalDnsService.Interface>.onDestroy() data.binder.close()
} }
} }
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