1,cpu频率可在/sys下读取
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_cur_freq
/sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_cur_freq
/sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_cur_freq
/sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq
/sys/devices/system/cpu/cpu5/cpufreq/cpuinfo_cur_freq
默认权限为400,需要修改权限为444
修改位置在内核中:
kernel/drivers/cpufreq/cpufreq.c
@@ -649,7 +649,7 @@ static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
return sprintf(buf, "%u\n", policy->cpuinfo.max_freq);
}
-cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0400);
+cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0444);
2,apk开发
循环读取文件中的频率数值然后显示到界面
//cpufreq_path 为cpufreq在sys中对应的节点路径
public String readCpuCurFreq(String cpufreq_path) {
String prop = "";
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(cpufreq_path));
prop = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
Log.e(TAG, "error:" + e.getMessage());
} finally {
if(reader != null){
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return prop;
}