本文介绍了错误设置CPU通过应用缩放省长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建一个简单的Andr​​oid应用程序应该设置CPU缩放省长。

I'm creating a simple Android app that should set the CPU Scaling Governor.

要做到这一点我做了这个功能:

To achieve this I made this function:

public static void setCurrentGovernor(String governor){
    Process process;
    try{
        String cpufreq_path= "/sys/devices/system/cpu/cpu0/cpufreq";
        String cmd = "echo `"+governor+"` > "+cpufreq_path+"/scaling_governor ";
        process = Runtime.getRuntime().exec(new String[] {"su","-c",cmd});
    } catch(IOException e){
        e.printStackTrace();
    }
}

我的问题是,这个功能将无法正常工作,再加上超级用户总是提示我要的权限,有没有办法给它超级用户权限仅在第一个应用程序启动?

My problem is that this function won't work, plus superuser always prompts me for permissions, is there a way to give it root permission only at first app boot?

此功能被称为微调的onitemselectedlistener里面,这个功能之后还有另外一个从CPU频率文件中获取数据来更新视图,但如果我这样做猫scaling_governor 我得到老州长,所以它不是一个错误的更新功能。

This function is called inside an onitemselectedlistener of a spinner, right after this function there's another one which fetches data from cpufreq files to update the view, but if i do cat scaling_governor i get the old governor, so it is not a faulty update function.

推荐答案

这更坚实code解决我的问题:

This more solid code solved my problem: Link

这篇关于错误设置CPU通过应用缩放省长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 17:30