Fix trimming memory from main
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user