Cyanogenmod change permission to system files

599 views Asked by At

I have built an application for ROOT android devices. It's open source and the source code is here. My problem is that, when the code tries to read the file "/sys/block/mmcblk0/queue/scheduler" i get this error

06-20 16:17:10.190: W/System.err(7458): java.io.FileNotFoundException: /sys/block/mmcblk0/queue/scheduler: open failed: EACCES (Permission denied)

That happens only in cyanogenmod OS, i have tried with carbon OS also and works fine! Please note that i cannot read the file even so when i change the permissions via adb.

When i do a connection to my device via adb shell as root and hit the below command

cat /sys/block/mmcblk0/queue/scheduler

i get this output

noop deadline [row] cfq 

Manifest

...
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--These permissions needed for ads-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
...

Function which read the content file

public static String getStringOfFile(String file) {
    String cpuFreq = "";
    RandomAccessFile reader;
    try {
        reader = new RandomAccessFile(file, "r");
        cpuFreq = reader.readLine();
        reader.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return cpuFreq;
}
1

There are 1 answers

3
k1slay On

You get the error simply because the file does not exist. Looks like you are trying to access some scheduler files, but the location of these files often depend upon the kernel implementation. You can stay sure that you won't find that particular file at the same place on all kernels, and also will not be present on every device.