MSOS Library
This library contains many OS functions from the Activity Manager.
This library is constantly evolving.
It consists of 2 librarys now. MSOS is java code, OSStats is B4A code. Both are packed jars.
Requirements:
At the moment getSystemTotalMemorySize works only on API 16+ thanks to google for implementing incomplete API. Courtesy testing (read bashing) of NJDude.
MSOS
Author: thedesolatesoul
Version: 0.01
It calculated the CPU Usage and Memory Usage.
You can start/stop tracking the OSStats.
This is stored in a buffer for graphing/smoothing etc.
I am trying to figure out out how to get which app is in the foreground or is visible.
This is so that I can use either a transparent activity or a service, and find out which app is on top.
//Ignore
getRunningApps: Uses this to find which apps have IMPORTANCE_FOREGROUND or IMPORTANCE_VISIBLE set
getRunningTasks: Uses this to find running tasks. tasks(0) will be the most recent one.
You can run these in a service and see what values they return.
I am still not sure which method is more accurate depending on what a 'task' and what an 'app' is.
For instance the last 'task' may have ended itself, whereas IMPORTANCE_VISIBLE will return whatever the user is viewing however this returns a number of items.
If someone could test this, and figure out what is doing what it would be great!
//
This library contains many OS functions from the Activity Manager.
This library is constantly evolving.
It consists of 2 librarys now. MSOS is java code, OSStats is B4A code. Both are packed jars.
Requirements:
At the moment getSystemTotalMemorySize works only on API 16+ thanks to google for implementing incomplete API. Courtesy testing (read bashing) of NJDude.
MSOS
Author: thedesolatesoul
Version: 0.01
- MSOS
Fields:- IMPORTANCE_FOREGROUND As Int
- IMPORTANCE_VISIBLE As Int
- getForegroundApp (pImportance As Int) As List
- getForegroundTask As List
- getFormattedSystemAvailabeMemorySize As String
- getFormattedSystemTotalMemorySize As String
- getProcessMemoryInfo (pid As Int) As Int
- getSystemAvailabeMemorySize As Long
- getSystemTotalMemorySize As Long
- android.permission.GET_TASKS
- NumCores As Int [read only]
Gets the number of cores available in this device, across all processors.
Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
- Class_Globals
Class module - EndStats
Stop collecting the stats
Call this in Activity_Pause - Initialize (Interval As Int, BufferSize As Int, Module As Object, EventName As String)
Initializes the object.
Interval is the gap to keep between capturing stats
Buffer size is size of buffer to store stats (for graphing etc)
Module is the parent object where the events will be delivered
Eventname is th prefix of the events raised - StartStats
Start collecting stats
The eventname_Update(CpuEfficientcy() as Float,RAMUsage as Float) will be raised - getNumCores As Int
Returns the number of CPU cores
It calculated the CPU Usage and Memory Usage.
You can start/stop tracking the OSStats.
This is stored in a buffer for graphing/smoothing etc.
I am trying to figure out out how to get which app is in the foreground or is visible.
This is so that I can use either a transparent activity or a service, and find out which app is on top.
//Ignore
getRunningApps: Uses this to find which apps have IMPORTANCE_FOREGROUND or IMPORTANCE_VISIBLE set
getRunningTasks: Uses this to find running tasks. tasks(0) will be the most recent one.
You can run these in a service and see what values they return.
I am still not sure which method is more accurate depending on what a 'task' and what an 'app' is.
For instance the last 'task' may have ended itself, whereas IMPORTANCE_VISIBLE will return whatever the user is viewing however this returns a number of items.
If someone could test this, and figure out what is doing what it would be great!
//
Attachments
Last edited: