Update CPU Info overlay
Change-Id: I11fcc77a3708c710b6ad7c58988bf44bbaeb22af Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
@@ -63,10 +63,12 @@ public class CPUInfoService extends Service {
|
||||
private String CPU_TEMP_SENSOR = "";
|
||||
private String GPU_TEMP_SENSOR = "";
|
||||
private String BATTERY_TEMP_SENSOR = "";
|
||||
private String FPS_SENSOR = "";
|
||||
private String DISPLAY_CPUS = "";
|
||||
private boolean mCpuTempAvail;
|
||||
private boolean mGpuTempAvail;
|
||||
private boolean mBatTempAvail;
|
||||
private boolean mFpsAvail;
|
||||
|
||||
private static final String NUM_OF_CPUS_PATH = "/sys/devices/system/cpu/present";
|
||||
private static final String CURRENT_CPU = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq";
|
||||
@@ -88,6 +90,7 @@ public class CPUInfoService extends Service {
|
||||
|
||||
private int mNeededWidth;
|
||||
private int mNeededHeight;
|
||||
private String mFps;
|
||||
private String mCpuTemp;
|
||||
private String mGpuTemp;
|
||||
private String mBatTemp;
|
||||
@@ -105,13 +108,14 @@ public class CPUInfoService extends Service {
|
||||
String msgData = (String) msg.obj;
|
||||
try {
|
||||
String[] parts=msgData.split(";");
|
||||
mCpuTemp = parts[0];
|
||||
mGpuTemp = parts[1];
|
||||
mBatTemp = parts[2];
|
||||
mGpuFreq = parts[3];
|
||||
mGpuLoad = parts[4];
|
||||
mFps = parts[0];
|
||||
mCpuTemp = parts[1];
|
||||
mGpuTemp = parts[2];
|
||||
mBatTemp = parts[3];
|
||||
mGpuFreq = parts[4];
|
||||
mGpuLoad = parts[5];
|
||||
|
||||
String[] cpuParts=parts[5].split("\\|");
|
||||
String[] cpuParts=parts[6].split("\\|");
|
||||
for(int i=0; i<cpuParts.length; i++){
|
||||
String cpuInfo=cpuParts[i];
|
||||
String cpuInfoParts[]=cpuInfo.split(":");
|
||||
@@ -141,7 +145,7 @@ public class CPUInfoService extends Service {
|
||||
setPadding(paddingPx, paddingPx, paddingPx, paddingPx);
|
||||
setBackgroundColor(Color.argb(0x60, 0, 0, 0));
|
||||
|
||||
final int textSize = Math.round(12 * density);
|
||||
final int textSize = Math.round(10 * density);
|
||||
|
||||
Typeface typeface = Typeface.create("monospace", Typeface.NORMAL);
|
||||
|
||||
@@ -190,7 +194,7 @@ public class CPUInfoService extends Service {
|
||||
String freq=mCurrFreq[i];
|
||||
String gov=mCurrGov[i];
|
||||
String load=mCurrLoad[i];
|
||||
return "cpu" + cpu + ": " + String.format("%3s", load) + " " + gov + " " + String.format("%8s", toMHz(freq));
|
||||
return "Core " + cpu + ": " + String.format("%3s", load) + " " + gov + " " + String.format("%8s", toMHz(freq));
|
||||
}
|
||||
|
||||
private String getTemp(String rawTemp) {
|
||||
@@ -219,6 +223,12 @@ public class CPUInfoService extends Service {
|
||||
final int RIGHT = getWidth()-1;
|
||||
int y = mPaddingTop - (int)mAscent;
|
||||
|
||||
if(mFpsAvail) {
|
||||
canvas.drawText("FPS: " + mFps,
|
||||
RIGHT-mPaddingRight-mMaxWidth, y-1, mOnlinePaint);
|
||||
y += mFH;
|
||||
}
|
||||
|
||||
if(!mCpuTemp.equals("0")) {
|
||||
canvas.drawText("CPU: " + getTemp(mCpuTemp) + " °C",
|
||||
RIGHT-mPaddingRight-mMaxWidth, y-1, mOnlinePaint);
|
||||
@@ -264,22 +274,23 @@ public class CPUInfoService extends Service {
|
||||
final int NW = mNumCpus;
|
||||
|
||||
int maxW = 0;
|
||||
if(!mCpuTemp.equals("0")) maxW = Math.max(maxW, (int)mOnlinePaint.measureText("CPU: " + getTemp(mCpuTemp) + "°C"));
|
||||
if(!mGpuTemp.equals("0")) maxW = Math.max(maxW, (int)mOnlinePaint.measureText("GPU: " + getTemp(mGpuTemp) + "°C"));
|
||||
if(!mBatTemp.equals("0")) maxW = Math.max(maxW, (int)mOnlinePaint.measureText("BAT: " + getTemp(mBatTemp) + "°C"));
|
||||
if(mFpsAvail) maxW = Math.max(maxW, (int)mOnlinePaint.measureText("FPS: " + mFps));
|
||||
if(!mCpuTemp.equals("0")) maxW = Math.max(maxW, (int)mOnlinePaint.measureText("CPU: " + getTemp(mCpuTemp) + " °C"));
|
||||
if(!mGpuTemp.equals("0")) maxW = Math.max(maxW, (int)mOnlinePaint.measureText("GPU: " + getTemp(mGpuTemp) + " °C"));
|
||||
if(!mBatTemp.equals("0")) maxW = Math.max(maxW, (int)mOnlinePaint.measureText("BAT: " + getTemp(mBatTemp) + " °C"));
|
||||
|
||||
for(int i=0; i<mCurrFreq.length; i++){
|
||||
String s = getCPUInfoString(i);
|
||||
maxW = Math.max(maxW, (int)mOnlinePaint.measureText(s));
|
||||
}
|
||||
|
||||
String gpuStats = "gpu: " + mGpuLoad + " " + mGpuFreq + " MHz";
|
||||
String gpuStats = "GPU: " + mGpuLoad + " " + mGpuFreq + " MHz";
|
||||
maxW = Math.max(maxW, (int)mOnlinePaint.measureText(gpuStats));
|
||||
|
||||
mMaxWidth = maxW;
|
||||
|
||||
int neededWidth = mPaddingLeft + mPaddingRight + mMaxWidth;
|
||||
int numTempLines = (mCpuTempAvail?1:0) + (mGpuTempAvail?1:0) + (mBatTempAvail?1:0);
|
||||
int numTempLines = (mFpsAvail?1:0) + (mCpuTempAvail?1:0) + (mGpuTempAvail?1:0) + (mBatTempAvail?1:0);
|
||||
int neededHeight = mPaddingTop + mPaddingBottom + (mFH * (numTempLines + NW + 1));
|
||||
if (neededWidth != mNeededWidth || neededHeight != mNeededHeight) {
|
||||
mNeededWidth = neededWidth;
|
||||
@@ -327,6 +338,27 @@ public class CPUInfoService extends Service {
|
||||
sleep(500);
|
||||
StringBuffer sb=new StringBuffer();
|
||||
|
||||
String fpsVal = "0";
|
||||
if (mFpsAvail) {
|
||||
String rawFps = CPUInfoService.readOneLine(FPS_SENSOR);
|
||||
if (rawFps != null) {
|
||||
String trimmed = rawFps.trim();
|
||||
if (trimmed.contains(": ")) {
|
||||
String[] parts = trimmed.split("\\s+");
|
||||
if (parts.length > 1) {
|
||||
trimmed = parts[1];
|
||||
}
|
||||
}
|
||||
try {
|
||||
float fpsFloat = Float.parseFloat(trimmed);
|
||||
fpsVal = String.valueOf(Math.round(fpsFloat));
|
||||
} catch (NumberFormatException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append(fpsVal).append(";");
|
||||
|
||||
String cpuTemp = CPUInfoService.readOneLine(CPU_TEMP_SENSOR);
|
||||
sb.append(cpuTemp == null ? "0" : cpuTemp).append(";");
|
||||
|
||||
@@ -418,6 +450,7 @@ public class CPUInfoService extends Service {
|
||||
|
||||
CPU_TEMP_DIVIDER = getResources().getInteger(R.integer.config_cpuTempDivider);
|
||||
DISPLAY_CPUS = getResources().getString(R.string.config_displayCpus);
|
||||
FPS_SENSOR = getResources().getString(R.string.config_fpsInfoSysNode);
|
||||
|
||||
String autoBat = findThermalZoneByType(BATTERY_TYPES);
|
||||
if (autoBat != null) {
|
||||
@@ -446,6 +479,9 @@ public class CPUInfoService extends Service {
|
||||
mGpuTempAvail = readOneLine(GPU_TEMP_SENSOR) != null;
|
||||
mBatTempAvail = readOneLine(BATTERY_TEMP_SENSOR) != null;
|
||||
|
||||
File fpsFile = new File(FPS_SENSOR);
|
||||
mFpsAvail = fpsFile.exists() && fpsFile.canRead();
|
||||
|
||||
mView = new CPUView(this);
|
||||
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
|
||||
Reference in New Issue
Block a user