3

I am making a Core management app for rooted android dual-core phones and up ... So what this app shall do is modify a file in the /sys directory , so it surely needs to use root or "su" . So what i am doing is that when i execute the command chmod 7777 /sys/devices/system/cpu/cpu1/online OR echo \"0\" > /sys/devices/system/cpu/cpu1/online from my app it gives me back "No such file or directory" , however , if I copy paste the command from my code to the terminal it self , the command goes flawless and completes my point ...

For sending the command , I am using a library that i made for my own , specifically I am using the su(String) method , which executes the commands you want as ROOT , and it works fine (I can see that from the SuperSU logs) , and I have used it before !

Here are some of the code that I am using :

Method to start ready everything up :

static public void ready_cores(){

        Shells.Start();//Starts the root shell so it could be used with su(String) method
        Shells.su("chmod 7777 /sys/devices/system/cpu/cpu3/online");//I have a dual-core so this one is normal to give me "No such file or directory"
        Shells.su("chmod 7777 /sys/devices/system/cpu/cpu2/online");//This one too
        Shells.su("chmod 7777 /sys/devices/system/cpu/cpu1/online");//This one should return no output and get executed successfully, more like in the terminal , but still returns NO such file or directory








    }

MY on click listener for the button that runs the stuff :

Executable.ready_cores();//This is the above method

                D2.setOnClickListener(new View.OnClickListener() {//D2 is my button (obviously :p)

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub

                        Executable.disable_core(1);//It sends the following command as root : echo "0" > /sys/devices/system/cpu/cpu1/online
                        refresh(); //refreshes everything , don't bother with it , it causes no harm ...
                    }
                });

My Shells.su(String) method :

static public void su(String ssu){//BTW , the variable psu is defined at Start() as : psu = Runtime.getRuntime().exec("su")

cmd = ssu + "\r";


try {


    su = new DataOutputStream(psu.getOutputStream());
    su.flush();



    if (bool = true){
        su.writeBytes(cmd+ "\n");
        su.flush();
        bool = false;
    }else if (bool = false){
        su.writeBytes(cmd+ "\n");
        su.flush();
        bool = true;
    }else {
        su.writeBytes("\n" + cmd+ "\n");
        su.flush();
        bool = true;
    }


    if (ssu.contains("echo") &! ssu.contains(">")){
        su.close();
        su = new DataOutputStream(psu.getOutputStream());
    }



} catch (Exception ex) {
    // TODO Auto-generated catch block
    ex.printStackTrace();

}









}

I also added the permissions to read and write external storage !

4

0 回答 0