|
|
@@ -1,16 +1,25 @@
|
|
|
package org.mjdev.desktop.helpers.system.meminfo
|
|
|
|
|
|
-import okio.Path.Companion.toPath
|
|
|
-import org.mjdev.desktop.extensions.PathExt.lines
|
|
|
+import android.app.ActivityManager
|
|
|
+import android.content.Context
|
|
|
+import android.content.Context.ACTIVITY_SERVICE
|
|
|
+import org.mjdev.desktop.context.DesktopContext
|
|
|
+import org.mjdev.desktop.interfaces.IDesktopContext
|
|
|
|
|
|
-class MemInfoAndroid: MemInfoStub() {
|
|
|
- private val runtime = Runtime.getRuntime()
|
|
|
-
|
|
|
- override val free: Double = runtime.freeMemory().toDouble().times(KB)
|
|
|
+class MemInfoAndroid(
|
|
|
+ context: IDesktopContext
|
|
|
+) : MemInfoStub(context) {
|
|
|
+ val aContext: Context?
|
|
|
+ get() = (context as? DesktopContext)?.context
|
|
|
+ val activityManager: ActivityManager? by lazy {
|
|
|
+ aContext?.getSystemService(ACTIVITY_SERVICE) as ActivityManager
|
|
|
+ }
|
|
|
+ private val meminfo: ActivityManager.MemoryInfo
|
|
|
+ get() = ActivityManager.MemoryInfo().apply {
|
|
|
+ activityManager?.getMemoryInfo(this)
|
|
|
+ }
|
|
|
|
|
|
- override val total: Double = runtime.totalMemory().toDouble().times(KB)
|
|
|
+ override val free: Double = meminfo.availMem.toDouble()
|
|
|
|
|
|
- companion object {
|
|
|
- const val KB = 1024
|
|
|
- }
|
|
|
+ override val total: Double = meminfo.totalMem.toDouble()
|
|
|
}
|