I am attempting to set the min/max clock speeds on a rooted phone programmatically. Following on from a suggestion made in response to this question, I found some documentation which suggests that I write the data to:
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq
and
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
I already have
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
in my manifest. Also I can successfully read both files. When I tried to write to the files, I got open failed: EACCES (Permission denied)
. So I tried...
Runtime.getRuntime().exec("su -c \"chmod 777 /sys/devices/system/cpu/cpu0/cpufreq/*\"");
...which executed without error, but this made no difference. The error occurs when I execute the second of these two lines:
File file = new File("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq");
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
I'm not sure what I can try next.
EDIT: Following mrPjer's advice, I ran adb shell. I typed su
and the navigated to /sys/devices/system/cpu/cpu0/cpufreq
. I then typed
chmod 777 scaling_max_freq
and confirmed that the permissions had been accepted by typing
ls -l scaling_max_freq
and sure enough it was listed as -rwxrwxrwx
. I then typed
echo 124200 > scaling_max_freq
and then
cat scaling_max_freq
sadly this reported that the file was unchanged as "1512000".
EDIT: This question has now drifted away somewhat from the original title, so I'm going to post the last edit as a new question altogether.
Instead of changing the permissions on the system files to globally readable / writable (which you really shouldn't do), try writing the files directly using root access.
You can easily do this by using echo instead of chmod in your su call. E.g.
The exec call should also return a Process object on which you can call waitFor() which will give you the return code of the call. If that is any different than zero, something went wrong.
Finally, confirm that you actually do get root access - when executing the su request, does a dialog pop up asking you to allow the action?
Also, since you are writing root enabled apps, take a look at the RootTools library: https://code.google.com/p/roottools/wiki/Usage.