提交 def4df80 编写于 作者: A andrewleo

Fixed: cpu name of arm and refine fps

上级 a24e18d7
...@@ -141,19 +141,14 @@ public class CpuInfo { ...@@ -141,19 +141,14 @@ public class CpuInfo {
try { try {
RandomAccessFile cpuStat = new RandomAccessFile(CPU_INFO_PATH, "r"); RandomAccessFile cpuStat = new RandomAccessFile(CPU_INFO_PATH, "r");
// check cpu type // check cpu type
if (Build.CPU_ABI.equalsIgnoreCase(CPU_X86)) { String line;
String line; while (null != (line = cpuStat.readLine())) {
while (null != (line = cpuStat.readLine())) { String[] values = line.split(":");
String[] values = line.split(":"); if (values[0].contains(INTEL_CPU_NAME) || values[0].contains("Processor")) {
if (values[0].contains(INTEL_CPU_NAME)) { cpuStat.close();
cpuStat.close(); Log.d(LOG_TAG, "CPU name="+values[1]);
return values[1]; return values[1];
}
} }
} else {
String[] cpu = cpuStat.readLine().split(":"); // cpu信息的前一段是含有processor字符串,此处替换为不显示
cpuStat.close();
return cpu[1];
} }
} catch (IOException e) { } catch (IOException e) {
Log.e(LOG_TAG, "IOException: " + e.getMessage()); Log.e(LOG_TAG, "IOException: " + e.getMessage());
......
...@@ -12,19 +12,27 @@ public class FpsInfo { ...@@ -12,19 +12,27 @@ public class FpsInfo {
private static DataOutputStream os = null; private static DataOutputStream os = null;
private static long startTime = 0L; private static long startTime = 0L;
private static int lastFrameNum = 0; private static int lastFrameNum = 0;
private static boolean ok = true;
/** /**
* get frame per second * get frame per second
*
* @return frame per second * @return frame per second
*/ */
public static float fps() { public static float fps() {
long nowTime = System.nanoTime(); if (ok) {
float f = (float) (nowTime - startTime) / 1000000.0F; long nowTime = System.nanoTime();
startTime = nowTime; float f = (float) (nowTime - startTime) / 1000000.0F;
int nowFrameNum = getFrameNum(); startTime = nowTime;
final float fps = Math.round((nowFrameNum - lastFrameNum) * 1000 / f); int nowFrameNum = getFrameNum();
lastFrameNum = nowFrameNum; final float fps = Math.round((nowFrameNum - lastFrameNum) * 1000
return fps; / f);
lastFrameNum = nowFrameNum;
return fps;
} else {
return -1;
}
} }
/** /**
...@@ -43,19 +51,18 @@ public class FpsInfo { ...@@ -43,19 +51,18 @@ public class FpsInfo {
os.writeBytes("service call SurfaceFlinger 1013" + "\n"); os.writeBytes("service call SurfaceFlinger 1013" + "\n");
os.flush(); os.flush();
String str1 = ir.readLine(); String str1 = ir.readLine();
if (str1 == null) { if (str1 != null) {
return -1; int start = str1.indexOf("(");
int end = str1.indexOf(" ");
if ((start != -1) & (end > start)) {
String str2 = str1.substring(start + 1, end);
return Integer.parseInt((String) str2, 16);
}
} }
int start = str1.indexOf("(");
int end = str1.indexOf(" ");
if ((start != -1) & (end > start)) {
String str2 = str1.substring(start + 1, end);
return Integer.parseInt((String) str2, 16);
}
return -1;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
return -1;
} }
ok = false;
return -1;
} }
} }
...@@ -97,6 +97,7 @@ public class ProcessInfo { ...@@ -97,6 +97,7 @@ public class ProcessInfo {
Log.i(LOG_TAG, "start getLaunchedPid"); Log.i(LOG_TAG, "start getLaunchedPid");
ActivityManager am = (ActivityManager) context ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE); .getSystemService(Context.ACTIVITY_SERVICE);
// Note: getRunningAppProcesses return itself in API 22
if (Build.VERSION.SDK_INT < ANDROID_M) { if (Build.VERSION.SDK_INT < ANDROID_M) {
List<RunningAppProcessInfo> run = am.getRunningAppProcesses(); List<RunningAppProcessInfo> run = am.getRunningAppProcesses();
for (RunningAppProcessInfo runningProcess : run) { for (RunningAppProcessInfo runningProcess : run) {
...@@ -208,6 +209,7 @@ public class ProcessInfo { ...@@ -208,6 +209,7 @@ public class ProcessInfo {
public static String getTopActivity(Context context) { public static String getTopActivity(Context context) {
ActivityManager manager = (ActivityManager) context ActivityManager manager = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE); .getSystemService(Context.ACTIVITY_SERVICE);
// Note: getRunningTasks is deprecated in API 21(Official)
List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1); List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);
if (runningTaskInfos != null) if (runningTaskInfos != null)
return (runningTaskInfos.get(0).topActivity).toString(); return (runningTaskInfos.get(0).topActivity).toString();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册