Bug 773021 - sutagent info('memory') should return free memory, not just physical memory. r=wlach

This commit is contained in:
Joel Maher 2012-07-23 15:52:34 -04:00
parent 6ffa748981
commit 539b16fe00

View File

@ -18,6 +18,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
@ -106,7 +107,7 @@ public class DoCommand {
String ffxProvider = "org.mozilla.ffxcp";
String fenProvider = "org.mozilla.fencp";
private final String prgVersion = "SUTAgentAndroid Version 1.09";
private final String prgVersion = "SUTAgentAndroid Version 1.10";
public enum Command
{
@ -2571,7 +2572,7 @@ private void CancelNotification()
public String GetMemoryInfo()
{
String sRet = "PA:" + GetMemoryConfig();
String sRet = "PA:" + GetMemoryConfig() + ", FREE: " + GetMemoryUsage();
return (sRet);
}
@ -2585,6 +2586,33 @@ private void CancelNotification()
return (lMem);
}
public long GetMemoryUsage()
{
String load = "";
try {
RandomAccessFile reader = new RandomAccessFile("/proc/meminfo", "r");
load = reader.readLine(); // Read in the MemTotal
load = reader.readLine(); // Read in the MemFree
} catch (IOException ex) {
return (0);
}
String[] toks = load.split(" ");
int i = 1;
for (i=1; i < toks.length; i++) {
String val = toks[i].trim();
if (!val.equals("")) {
break;
}
}
if (i <= toks.length) {
long lMem = Long.parseLong(toks[i].trim());
return (lMem * 1024);
}
return (0);
}
public String UpdateCallBack(String sFileName)
{
String sRet = sErrorPrefix + "No file specified";