Update CPU Info overlay

Change-Id: Ib401dfeaecf8dcaf4a15834fd5ccf36790fa8973
Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
2025-12-31 09:17:41 +07:00
parent 8aef3b97e7
commit 4af33960a7
2 changed files with 21 additions and 69 deletions

View File

@@ -17,8 +17,8 @@
<!-- The CPU temperature sensor path, defaults to empty -->
<string name="config_cpuTempSensor" translatable="false">/sys/class/thermal/thermal_zone0/temp</string>
<string name="config_gpuTempSensor" translatable="false">/sys/class/thermal/thermal_zone24/temp</string>
<string name="config_batteryTempSensor" translatable="false">/sys/class/thermal/thermal_zone65/temp</string>
<string name="config_gpuTempSensor" translatable="false">/sys/class/kgsl/kgsl-3d0/temp</string>
<string name="config_batteryTempSensor" translatable="false">/sys/class/power_supply/battery/temp</string>
<!-- The CPU temperature divider, if needed -->
<integer name="config_cpuTempDivider" translatable="false">1</integer>

View File

@@ -25,12 +25,10 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
@@ -40,14 +38,8 @@ import com.android.systemui.res.R;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.StringBuffer;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class CPUInfoService extends Service {
private View mView;
@@ -71,15 +63,11 @@ public class CPUInfoService extends Service {
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";
private static final String CPU_ROOT = "/sys/devices/system/cpu/cpu";
private static final String CPU_CUR_TAIL = "/cpufreq/scaling_cur_freq";
private static final String CPU_GOV_TAIL = "/cpufreq/scaling_governor";
private static final String GPU_FREQ_PATH = "/sys/class/kgsl/kgsl-3d0/clock_mhz";
private static final String GPU_LOAD_PATH = "/sys/class/kgsl/kgsl-3d0/gpu_busy_percentage";
private static final String THERMAL_DIR = "/sys/class/thermal/";
private static final String[] BATTERY_TYPES = {"battery"};
private static final String[] GPU_TYPES = {"gpu-0"};
private class CPUView extends View {
private Paint mOnlinePaint;
@@ -172,11 +160,6 @@ public class CPUInfoService extends Service {
updateDisplay();
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
@@ -189,12 +172,13 @@ public class CPUInfoService extends Service {
resolveSize(mNeededHeight, heightMeasureSpec));
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
}
private String getCPUInfoString(int i) {
String cpu=mCpu[i];
String freq=mCurrFreq[i];
String gov=mCurrGov[i];
String load=mCurrLoad[i];
return "Core " + cpu + ": " + String.format("%3s", load) + " " + gov + " " + String.format("%8s", toMHz(freq));
return "Core " + mCpu[i] + ": " + String.format("%3s", mCurrLoad[i]) + " " + mCurrGov[i] + " " + String.format("%8s", toMHz(mCurrFreq[i]));
}
private String getTemp(String rawTemp) {
@@ -249,8 +233,7 @@ public class CPUInfoService extends Service {
for(int i=0; i<mCurrFreq.length; i++){
String s=getCPUInfoString(i);
String freq=mCurrFreq[i];
if(!freq.equals("0")){
if(!mCurrFreq[i].equals("0")){
canvas.drawText(s, RIGHT-mPaddingRight-mMaxWidth,
y-1, mOnlinePaint);
} else {
@@ -338,23 +321,22 @@ public class CPUInfoService extends Service {
sleep(500);
StringBuffer sb=new StringBuffer();
String fpsVal = "0";
String fpsVal = "0.0";
if (mFpsAvail) {
String rawFps = CPUInfoService.readOneLine(FPS_SENSOR);
if (rawFps != null) {
String trimmed = rawFps.trim();
if (trimmed.contains(": ")) {
if (trimmed.startsWith("fps:")) {
String[] parts = trimmed.split("\\s+");
if (parts.length > 1) {
trimmed = parts[1];
if (parts.length >= 2) {
try {
float fpsFloat = Float.parseFloat(parts[1]);
fpsVal = String.format("%.1f", fpsFloat);
} catch (NumberFormatException e) {
// ignore
}
}
}
try {
float fpsFloat = Float.parseFloat(trimmed);
fpsVal = String.valueOf(Math.round(fpsFloat));
} catch (NumberFormatException e) {
// ignore
}
}
}
sb.append(fpsVal).append(";");
@@ -451,23 +433,8 @@ 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) {
BATTERY_TEMP_SENSOR = autoBat;
Log.d(TAG, "Auto-detected Battery zone: " + autoBat);
} else {
BATTERY_TEMP_SENSOR = getResources().getString(R.string.config_batteryTempSensor);
}
String autoGpu = findThermalZoneByType(GPU_TYPES);
if (autoGpu != null) {
GPU_TEMP_SENSOR = autoGpu;
Log.d(TAG, "Auto-detected GPU zone: " + autoGpu);
} else {
GPU_TEMP_SENSOR = getResources().getString(R.string.config_gpuTempSensor);
}
BATTERY_TEMP_SENSOR = getResources().getString(R.string.config_batteryTempSensor);
GPU_TEMP_SENSOR = getResources().getString(R.string.config_gpuTempSensor);
CPU_TEMP_SENSOR = getResources().getString(R.string.config_cpuTempSensor);
mNumCpus = getCpus(DISPLAY_CPUS);
@@ -517,21 +484,6 @@ public class CPUInfoService extends Service {
return null;
}
private static String findThermalZoneByType(String[] typeNames) {
for (String target : typeNames) {
for (int i = 0; i < 100; i++) {
String zonePath = THERMAL_DIR + "thermal_zone" + i;
String typePath = zonePath + "/type";
String typeValue = readOneLine(typePath);
if (typeValue != null && typeValue.trim().equalsIgnoreCase(target)) {
return zonePath + "/temp";
}
}
}
return null;
}
private static String readOneLine(String fname) {
BufferedReader br;
String line = null;
@@ -560,7 +512,7 @@ public class CPUInfoService extends Service {
for (int i = 0; i < numOfCpu; i++) {
try {
int cpu = Integer.parseInt(cpuList[i]);
Integer.parseInt(cpuList[i]);
mCpu[i] = cpuList[i];
} catch (NumberFormatException ex) {
// derped overlay