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.room.AppDatabase
|
||||||
import be.mygod.vpnhotspot.util.DeviceStorageApp
|
import be.mygod.vpnhotspot.util.DeviceStorageApp
|
||||||
import be.mygod.vpnhotspot.util.RootSession
|
import be.mygod.vpnhotspot.util.RootSession
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -62,7 +64,7 @@ class App : Application() {
|
|||||||
|
|
||||||
override fun onTrimMemory(level: Int) {
|
override fun onTrimMemory(level: Int) {
|
||||||
super.onTrimMemory(level)
|
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
|
lateinit var deviceStorage: Application
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package be.mygod.vpnhotspot.util
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.HandlerThread
|
import android.os.HandlerThread
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import androidx.annotation.WorkerThread
|
||||||
import androidx.core.os.postDelayed
|
import androidx.core.os.postDelayed
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
@@ -50,6 +51,7 @@ class RootSession : AutoCloseable {
|
|||||||
return instance.Transaction()
|
return instance.Transaction()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
fun trimMemory() = monitor.withLock {
|
fun trimMemory() = monitor.withLock {
|
||||||
val instance = instance ?: return
|
val instance = instance ?: return
|
||||||
instance.haltTimeout()
|
instance.haltTimeout()
|
||||||
|
|||||||
Reference in New Issue
Block a user