Fix trimming memory from main

This commit is contained in:
Mygod
2019-08-12 13:17:30 +08:00
parent 3770acf561
commit 9ad7d25501
2 changed files with 5 additions and 1 deletions

View File

@@ -20,6 +20,8 @@ import be.mygod.vpnhotspot.net.DhcpWorkaround
import be.mygod.vpnhotspot.room.AppDatabase
import be.mygod.vpnhotspot.util.DeviceStorageApp
import be.mygod.vpnhotspot.util.RootSession
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import timber.log.Timber
import java.util.*
@@ -62,7 +64,7 @@ class App : Application() {
override fun onTrimMemory(level: Int) {
super.onTrimMemory(level)
if (level >= TRIM_MEMORY_RUNNING_CRITICAL) RootSession.trimMemory()
if (level >= TRIM_MEMORY_RUNNING_CRITICAL) GlobalScope.launch { RootSession.trimMemory() }
}
lateinit var deviceStorage: Application

View File

@@ -3,6 +3,7 @@ package be.mygod.vpnhotspot.util
import android.os.Handler
import android.os.HandlerThread
import android.os.Looper
import androidx.annotation.WorkerThread
import androidx.core.os.postDelayed
import com.topjohnwu.superuser.Shell
import timber.log.Timber
@@ -50,6 +51,7 @@ class RootSession : AutoCloseable {
return instance.Transaction()
}
@WorkerThread
fun trimMemory() = monitor.withLock {
val instance = instance ?: return
instance.haltTimeout()