Kill RootSession on low memory

This commit is contained in:
Mygod
2018-09-07 10:43:40 +08:00
parent 9bc59ac270
commit 22b4dd6438
2 changed files with 12 additions and 0 deletions

View File

@@ -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) }

View File

@@ -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)