Kill RootSession on low memory
This commit is contained in:
@@ -12,6 +12,7 @@ import android.preference.PreferenceManager
|
||||
import androidx.core.content.getSystemService
|
||||
import be.mygod.vpnhotspot.util.DeviceStorageApp
|
||||
import be.mygod.vpnhotspot.util.Event0
|
||||
import be.mygod.vpnhotspot.util.RootSession
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import io.fabric.sdk.android.Fabric
|
||||
|
||||
@@ -39,6 +40,11 @@ class App : Application() {
|
||||
ServiceNotification.updateNotificationChannels()
|
||||
}
|
||||
|
||||
override fun onTrimMemory(level: Int) {
|
||||
super.onTrimMemory(level)
|
||||
if (level >= TRIM_MEMORY_RUNNING_CRITICAL) RootSession.trimMemory()
|
||||
}
|
||||
|
||||
lateinit var deviceStorage: Application
|
||||
val handler = Handler()
|
||||
val pref: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(deviceStorage) }
|
||||
|
||||
@@ -46,6 +46,12 @@ class RootSession : AutoCloseable {
|
||||
instance.haltTimeout()
|
||||
return instance.Transaction()
|
||||
}
|
||||
|
||||
fun trimMemory() = monitor.withLock {
|
||||
val instance = instance ?: return
|
||||
instance.haltTimeout()
|
||||
instance.close()
|
||||
}
|
||||
}
|
||||
|
||||
class UnexpectedOutputException(msg: String) : RuntimeException(msg)
|
||||
|
||||
Reference in New Issue
Block a user